Update to zig 0.16.0, update deps, Vulkan validation fixes
This commit is contained in:
@@ -5,8 +5,9 @@ const vk = @import("vulkan");
|
||||
|
||||
allocator: std.mem.Allocator,
|
||||
allocations: std.AutoHashMapUnmanaged(*anyopaque, usize) = .empty,
|
||||
mutex: std.Thread.Mutex = .{},
|
||||
mutex: std.Io.Mutex = .init,
|
||||
allocated_bytes: usize = 0,
|
||||
io: std.Io,
|
||||
|
||||
interface: vk.AllocationCallbacks,
|
||||
|
||||
@@ -18,7 +19,7 @@ const actual_alignment: std.mem.Alignment = .@"16";
|
||||
|
||||
const log = std.log.scoped(.vk_allocator);
|
||||
|
||||
pub fn init(allocator: std.mem.Allocator) !*VkAllocator {
|
||||
pub fn init(allocator: std.mem.Allocator, io: std.Io) !*VkAllocator {
|
||||
// NOTE We allocate the structure to pin its address.
|
||||
const self = try allocator.create(VkAllocator);
|
||||
|
||||
@@ -30,6 +31,7 @@ pub fn init(allocator: std.mem.Allocator) !*VkAllocator {
|
||||
.pfn_reallocation = &reallocationFunction,
|
||||
.pfn_free = &freeFunction,
|
||||
},
|
||||
.io = io,
|
||||
};
|
||||
return self;
|
||||
}
|
||||
@@ -69,8 +71,8 @@ fn allocationFunction(
|
||||
const desired_alignment = std.mem.Alignment.fromByteUnits(alignment);
|
||||
std.debug.assert(std.mem.Alignment.compare(actual_alignment, .gte, desired_alignment));
|
||||
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
self.mutex.lock(self.io) catch return null;
|
||||
defer self.mutex.unlock(self.io);
|
||||
|
||||
self.allocations.ensureUnusedCapacity(self.allocator, 1) catch return null;
|
||||
const memory = self.allocator.alignedAlloc(u8, actual_alignment, size) catch return null;
|
||||
@@ -94,8 +96,8 @@ fn reallocationFunction(
|
||||
const desired_alignment = std.mem.Alignment.fromByteUnits(alignment);
|
||||
std.debug.assert(std.mem.Alignment.compare(actual_alignment, .gte, desired_alignment));
|
||||
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
self.mutex.lock(self.io) catch return null;
|
||||
defer self.mutex.unlock(self.io);
|
||||
|
||||
// NOTE If we were pedantic, we would consider the fact that we might not
|
||||
// need unused capacity if the memory doesn't get relocated.
|
||||
@@ -130,8 +132,8 @@ fn freeFunction(
|
||||
const self: *VkAllocator = @ptrCast(@alignCast(p_user_data.?));
|
||||
|
||||
if (maybe_p_memory) |p_memory| {
|
||||
self.mutex.lock();
|
||||
defer self.mutex.unlock();
|
||||
self.mutex.lockUncancelable();
|
||||
defer self.mutex.unlock(self.io);
|
||||
|
||||
const size = self.allocations.fetchRemove(p_memory).?.value;
|
||||
self.allocated_bytes -= size;
|
||||
|
||||
Reference in New Issue
Block a user