Skip to content

Commit 084412a

Browse files
committed
fixing command pool
1 parent a67660f commit 084412a

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/vulkan/CommandPool.zig

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,39 @@ pub fn allocateCommandBuffers(self: *Self, info: *const vk.CommandBufferAllocate
7070

7171
pub fn freeCommandBuffers(self: *Self, cmds: []*Dispatchable(CommandBuffer)) VkError!void {
7272
// Ugly method but it works well
73+
var len: usize = 0;
7374
for (cmds) |cmd| {
7475
if (std.mem.indexOf(*Dispatchable(CommandBuffer), self.buffers.items, &[_]*Dispatchable(CommandBuffer){cmd})) |i| {
7576
const save = self.buffers.orderedRemove(i);
7677
// Append the now free command buffer at the end of the pool
7778
self.buffers.appendAssumeCapacity(save);
79+
len += 1;
7880
}
7981
}
80-
self.first_free_buffer_index -= cmds.len;
82+
const new_first_free_buffer_index, const has_overflown = @subWithOverflow(self.first_free_buffer_index, len);
83+
if (has_overflown == 0) {
84+
self.first_free_buffer_index = new_first_free_buffer_index;
85+
} else {
86+
std.log.scoped(.CommandPool).warn("Avoided an underflow. This should not happen, please fill an issue.", .{});
87+
}
8188
}
8289

8390
pub fn destroy(self: *Self, allocator: std.mem.Allocator) void {
8491
for (self.buffers.items) |non_dis_cmd| {
85-
non_dis_cmd.object.destroy(allocator);
86-
non_dis_cmd.destroy(allocator);
92+
non_dis_cmd.intrusiveDestroy(allocator);
8793
}
8894
self.buffers.deinit(allocator);
8995
self.vtable.destroy(self, allocator);
9096
}
9197

9298
pub inline fn reset(self: *Self, flags: vk.CommandPoolResetFlags) VkError!void {
9399
try self.vtable.reset(self, flags);
100+
if (flags.release_resources_bit) {
101+
const allocator = self.host_allocator.allocator();
102+
for (self.buffers.items) |non_dis_cmd| {
103+
non_dis_cmd.intrusiveDestroy(allocator);
104+
}
105+
self.buffers.shrinkAndFree(allocator, BUFFER_POOL_BASE_CAPACITY);
106+
self.buffers.clearRetainingCapacity();
107+
}
94108
}

src/vulkan/logger/ThreadSafeManager.zig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ pub fn deinit(self: *Self) void {
3333
}
3434
}
3535
if (self.managers.count() == 0) {
36-
self.mutex.lock();
37-
self.mutex.unlock();
38-
3936
self.managers.deinit(self.allocator.allocator());
4037
self.* = .init;
4138
}

0 commit comments

Comments
 (0)