fixing CTS issues, improving logger

This commit is contained in:
2025-12-05 23:01:17 +01:00
parent 96f69de54f
commit 453d965d0c
12 changed files with 168 additions and 83 deletions

View File

@@ -11,12 +11,14 @@ const Self = @This();
callbacks: ?vk.AllocationCallbacks,
scope: vk.SystemAllocationScope,
fallback_allocator: std.heap.ThreadSafeAllocator,
pub fn init(callbacks: ?*const vk.AllocationCallbacks, scope: vk.SystemAllocationScope) Self {
const deref_callbacks = if (callbacks) |c| c.* else null;
return .{
.callbacks = deref_callbacks,
.scope = scope,
.fallback_allocator = .{ .child_allocator = std.heap.c_allocator },
};
}
@@ -45,6 +47,7 @@ pub fn cloneWithScope(self: *Self, scope: vk.SystemAllocationScope) Self {
return .{
.callbacks = self.callbacks,
.scope = scope,
.fallback_allocator = self.fallback_allocator,
};
}
@@ -57,7 +60,7 @@ fn alloc(context: *anyopaque, len: usize, alignment: Alignment, ret_addr: usize)
}
}
return getFallbackAllocator().rawAlloc(len, alignment, ret_addr);
return self.getFallbackAllocator().rawAlloc(len, alignment, ret_addr);
}
fn resize(context: *anyopaque, ptr: []u8, alignment: Alignment, new_len: usize, ret_addr: usize) bool {
@@ -65,7 +68,7 @@ fn resize(context: *anyopaque, ptr: []u8, alignment: Alignment, new_len: usize,
return if (self.callbacks != null)
new_len <= ptr.len
else
getFallbackAllocator().rawResize(ptr, alignment, new_len, ret_addr);
self.getFallbackAllocator().rawResize(ptr, alignment, new_len, ret_addr);
}
fn remap(context: *anyopaque, ptr: []u8, alignment: Alignment, new_len: usize, ret_addr: usize) ?[*]u8 {
@@ -75,7 +78,7 @@ fn remap(context: *anyopaque, ptr: []u8, alignment: Alignment, new_len: usize, r
return @ptrCast(pfn_reallocation(self.callbacks.?.p_user_data, ptr.ptr, new_len, alignment.toByteUnits(), self.scope));
}
}
return getFallbackAllocator().rawRemap(ptr, alignment, new_len, ret_addr);
return self.getFallbackAllocator().rawRemap(ptr, alignment, new_len, ret_addr);
}
fn free(context: *anyopaque, ptr: []u8, alignment: Alignment, ret_addr: usize) void {
@@ -83,12 +86,12 @@ fn free(context: *anyopaque, ptr: []u8, alignment: Alignment, ret_addr: usize) v
if (self.callbacks) |callbacks| {
if (callbacks.pfn_free) |pfn_free| {
pfn_free(self.callbacks.?.p_user_data, ptr.ptr);
return;
}
}
getFallbackAllocator().rawFree(ptr, alignment, ret_addr);
self.getFallbackAllocator().rawFree(ptr, alignment, ret_addr);
}
inline fn getFallbackAllocator() std.mem.Allocator {
var fallback_allocator: std.heap.ThreadSafeAllocator = .{ .child_allocator = std.heap.c_allocator };
return fallback_allocator.allocator();
inline fn getFallbackAllocator(self: *Self) std.mem.Allocator {
return self.fallback_allocator.allocator();
}