Factor out command pool allocation
This commit is contained in:
@@ -100,6 +100,10 @@ graphics_queue: Queue,
|
||||
compute_queue: Queue,
|
||||
transfer_queue: Queue,
|
||||
|
||||
graphics_command_pool: vk.CommandPool,
|
||||
compute_command_pool: vk.CommandPool,
|
||||
transfer_command_pool: vk.CommandPool,
|
||||
|
||||
const debug = @import("builtin").mode == .Debug;
|
||||
|
||||
const vk_application_info: vk.ApplicationInfo = .{
|
||||
@@ -292,12 +296,35 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
|
||||
const device = vk.DeviceProxy.init(device_handle, device_wrapper_ptr);
|
||||
errdefer device.destroyDevice(&vk_allocator.interface);
|
||||
|
||||
// --- GET QUEUES, CREATE COMMAND POOLS ------------------------------------
|
||||
// --- CREATE COMMAND POOLS, GET QUEUES ------------------------------------
|
||||
|
||||
const graphics_queue = try Queue.initAllocation(device, queue_allocations.graphics_queue, false, &vk_allocator.interface);
|
||||
const compute_queue = try Queue.initAllocation(device, queue_allocations.compute_queue, true, &vk_allocator.interface);
|
||||
const transfer_queue = try Queue.initAllocation(device, queue_allocations.transfer_queue, true, &vk_allocator.interface);
|
||||
const presentation_queue = if (maybe_window != null) try Queue.initAllocation(device, queue_allocations.presentation_queue, false, &vk_allocator.interface) else undefined;
|
||||
const command_pool_create_flags: vk.CommandPoolCreateFlags = .{
|
||||
.transient_bit = true,
|
||||
.reset_command_buffer_bit = true,
|
||||
};
|
||||
|
||||
const graphics_command_pool = try device.createCommandPool(&.{
|
||||
.flags = command_pool_create_flags,
|
||||
.queue_family_index = queue_allocations.graphics_queue.family,
|
||||
}, &vk_allocator.interface);
|
||||
errdefer device.destroyCommandPool(graphics_command_pool, &vk_allocator.interface);
|
||||
|
||||
const compute_command_pool = try device.createCommandPool(&.{
|
||||
.flags = command_pool_create_flags,
|
||||
.queue_family_index = queue_allocations.compute_queue.family,
|
||||
}, &vk_allocator.interface);
|
||||
errdefer device.destroyCommandPool(compute_command_pool, &vk_allocator.interface);
|
||||
|
||||
const transfer_command_pool = try device.createCommandPool(&.{
|
||||
.flags = command_pool_create_flags,
|
||||
.queue_family_index = queue_allocations.transfer_queue.family,
|
||||
}, &vk_allocator.interface);
|
||||
errdefer device.destroyCommandPool(transfer_command_pool, &vk_allocator.interface);
|
||||
|
||||
const graphics_queue: Queue = .initAllocation(device, queue_allocations.graphics_queue);
|
||||
const compute_queue: Queue = .initAllocation(device, queue_allocations.compute_queue);
|
||||
const transfer_queue: Queue = .initAllocation(device, queue_allocations.transfer_queue);
|
||||
const presentation_queue: Queue = if (maybe_window != null) .initAllocation(device, queue_allocations.presentation_queue) else undefined;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -321,18 +348,19 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
|
||||
.graphics_queue = graphics_queue,
|
||||
.compute_queue = compute_queue,
|
||||
.transfer_queue = transfer_queue,
|
||||
|
||||
.graphics_command_pool = graphics_command_pool,
|
||||
.compute_command_pool = compute_command_pool,
|
||||
.transfer_command_pool = transfer_command_pool,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn deinit(self: *Engine) void {
|
||||
const allocator = self.vk_allocator.allocator;
|
||||
|
||||
if (std.meta.activeTag(self.mode) == .surface) {
|
||||
self.mode.surface.presentation_queue.deinit(self.device, &self.vk_allocator.interface);
|
||||
}
|
||||
self.transfer_queue.deinit(self.device, &self.vk_allocator.interface);
|
||||
self.compute_queue.deinit(self.device, &self.vk_allocator.interface);
|
||||
self.graphics_queue.deinit(self.device, &self.vk_allocator.interface);
|
||||
self.device.destroyCommandPool(self.graphics_command_pool, &self.vk_allocator.interface);
|
||||
self.device.destroyCommandPool(self.compute_command_pool, &self.vk_allocator.interface);
|
||||
self.device.destroyCommandPool(self.transfer_command_pool, &self.vk_allocator.interface);
|
||||
|
||||
self.device.destroyDevice(&self.vk_allocator.interface);
|
||||
allocator.destroy(self.device.wrapper);
|
||||
@@ -372,7 +400,7 @@ pub fn allocate(self: *const Engine, memory_requirements: vk.MemoryRequirements,
|
||||
pub fn allocateTransferCommandBuffer(self: *const Engine) !vk.CommandBufferProxy {
|
||||
var command_buffer: vk.CommandBuffer = undefined;
|
||||
try self.device.allocateCommandBuffers(&.{
|
||||
.command_pool = self.transfer_queue.command_pool,
|
||||
.command_pool = self.transfer_command_pool,
|
||||
.level = .primary,
|
||||
.command_buffer_count = 1,
|
||||
}, @ptrCast(&command_buffer));
|
||||
@@ -382,7 +410,7 @@ pub fn allocateTransferCommandBuffer(self: *const Engine) !vk.CommandBufferProxy
|
||||
pub fn allocateGraphicsCommandBuffer(self: *const Engine) !vk.CommandBufferProxy {
|
||||
var command_buffer: vk.CommandBuffer = undefined;
|
||||
try self.device.allocateCommandBuffers(&.{
|
||||
.command_pool = self.graphics_queue.command_pool,
|
||||
.command_pool = self.graphics_command_pool,
|
||||
.level = .primary,
|
||||
.command_buffer_count = 1,
|
||||
}, @ptrCast(&command_buffer));
|
||||
@@ -390,11 +418,11 @@ pub fn allocateGraphicsCommandBuffer(self: *const Engine) !vk.CommandBufferProxy
|
||||
}
|
||||
|
||||
pub fn freeTransferCommandBuffer(self: *const Engine, command_buffer: vk.CommandBufferProxy) void {
|
||||
self.device.freeCommandBuffers(self.transfer_queue.command_pool, 1, @ptrCast(&command_buffer));
|
||||
self.device.freeCommandBuffers(self.transfer_command_pool, 1, @ptrCast(&command_buffer));
|
||||
}
|
||||
|
||||
pub fn freeGraphicsCommandBuffer(self: *const Engine, command_buffer: vk.CommandBufferProxy) void {
|
||||
self.device.freeCommandBuffers(self.graphics_queue.command_pool, 1, @ptrCast(&command_buffer));
|
||||
self.device.freeCommandBuffers(self.graphics_command_pool, 1, @ptrCast(&command_buffer));
|
||||
}
|
||||
|
||||
pub fn submitTransferCommandBuffer(self: *const Engine, command_buffer: vk.CommandBufferProxy, fence: vk.Fence) !void {
|
||||
|
||||
Reference in New Issue
Block a user