fixing command pool
This commit is contained in:
@@ -70,20 +70,26 @@ pub fn allocateCommandBuffers(self: *Self, info: *const vk.CommandBufferAllocate
|
||||
|
||||
pub fn freeCommandBuffers(self: *Self, cmds: []*Dispatchable(CommandBuffer)) VkError!void {
|
||||
// Ugly method but it works well
|
||||
var len: usize = 0;
|
||||
for (cmds) |cmd| {
|
||||
if (std.mem.indexOf(*Dispatchable(CommandBuffer), self.buffers.items, &[_]*Dispatchable(CommandBuffer){cmd})) |i| {
|
||||
const save = self.buffers.orderedRemove(i);
|
||||
// Append the now free command buffer at the end of the pool
|
||||
self.buffers.appendAssumeCapacity(save);
|
||||
len += 1;
|
||||
}
|
||||
}
|
||||
self.first_free_buffer_index -= cmds.len;
|
||||
const new_first_free_buffer_index, const has_overflown = @subWithOverflow(self.first_free_buffer_index, len);
|
||||
if (has_overflown == 0) {
|
||||
self.first_free_buffer_index = new_first_free_buffer_index;
|
||||
} else {
|
||||
std.log.scoped(.CommandPool).warn("Avoided an underflow. This should not happen, please fill an issue.", .{});
|
||||
}
|
||||
}
|
||||
|
||||
pub fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
for (self.buffers.items) |non_dis_cmd| {
|
||||
non_dis_cmd.object.destroy(allocator);
|
||||
non_dis_cmd.destroy(allocator);
|
||||
non_dis_cmd.intrusiveDestroy(allocator);
|
||||
}
|
||||
self.buffers.deinit(allocator);
|
||||
self.vtable.destroy(self, allocator);
|
||||
@@ -91,4 +97,12 @@ pub fn destroy(self: *Self, allocator: std.mem.Allocator) void {
|
||||
|
||||
pub inline fn reset(self: *Self, flags: vk.CommandPoolResetFlags) VkError!void {
|
||||
try self.vtable.reset(self, flags);
|
||||
if (flags.release_resources_bit) {
|
||||
const allocator = self.host_allocator.allocator();
|
||||
for (self.buffers.items) |non_dis_cmd| {
|
||||
non_dis_cmd.intrusiveDestroy(allocator);
|
||||
}
|
||||
self.buffers.shrinkAndFree(allocator, BUFFER_POOL_BASE_CAPACITY);
|
||||
self.buffers.clearRetainingCapacity();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,6 @@ pub fn deinit(self: *Self) void {
|
||||
}
|
||||
}
|
||||
if (self.managers.count() == 0) {
|
||||
self.mutex.lock();
|
||||
self.mutex.unlock();
|
||||
|
||||
self.managers.deinit(self.allocator.allocator());
|
||||
self.* = .init;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user