adding queues and debug allocators

This commit is contained in:
2025-11-11 23:55:44 +01:00
parent c6db045bbc
commit c1ed06945e
12 changed files with 128 additions and 43 deletions

View File

@@ -3,12 +3,16 @@
const std = @import("std");
const vk = @import("vulkan");
const builtin = @import("builtin");
const DRIVER_DEBUG_ALLOCATOR_ENV_NAME = @import("lib.zig").DRIVER_DEBUG_ALLOCATOR_ENV_NAME;
const Allocator = std.mem.Allocator;
const Alignment = std.mem.Alignment;
const Self = @This();
pub var debug_allocator: std.heap.DebugAllocator(.{}) = .init;
callbacks: ?vk.AllocationCallbacks,
scope: vk.SystemAllocationScope,
@@ -21,22 +25,22 @@ pub fn init(callbacks: ?*const vk.AllocationCallbacks, scope: vk.SystemAllocatio
}
pub fn allocator(self: *const Self) Allocator {
if (self.callbacks == null) {
if (self.callbacks != null) {
return .{
.ptr = @constCast(self),
.vtable = std.heap.c_allocator.vtable,
.vtable = &.{
.alloc = alloc,
.resize = resize,
.remap = remap,
.free = free,
},
};
}
return .{
.ptr = @constCast(self),
.vtable = &.{
.alloc = alloc,
.resize = resize,
.remap = remap,
.free = free,
},
};
return if (std.process.hasEnvVarConstant(DRIVER_DEBUG_ALLOCATOR_ENV_NAME) or builtin.mode == std.builtin.OptimizeMode.Debug)
debug_allocator.allocator()
else
std.heap.c_allocator;
}
fn alloc(context: *anyopaque, len: usize, alignment: Alignment, _: usize) ?[*]u8 {