Transient CB only, validation fixes

This commit is contained in:
2025-12-20 18:11:24 +01:00
parent 71015874a9
commit 8f19b16130
7 changed files with 116 additions and 122 deletions

View File

@@ -7,7 +7,6 @@ const vk = @import("vulkan");
const Queue = @import("Queue.zig");
const QueueType = @import("QueueType.zig").QueueType;
const Transient = @import("Transient.zig").Transient;
const VkAllocator = @import("VkAllocator.zig");
const WaitSemaphore = @import("WaitSemaphore.zig");
@@ -96,10 +95,6 @@ graphics_command_pool: vk.CommandPool,
compute_command_pool: vk.CommandPool,
transfer_command_pool: vk.CommandPool,
transient_graphics_command_pool: vk.CommandPool,
transient_compute_command_pool: vk.CommandPool,
transient_transfer_command_pool: vk.CommandPool,
prng_ptr: *std.Random.Pcg,
random: std.Random,
@@ -110,7 +105,7 @@ const vk_application_info: vk.ApplicationInfo = .{
.application_version = @bitCast(vk_version),
.p_engine_name = c.app_name,
.engine_version = @bitCast(vk_version),
.api_version = @bitCast(vk.API_VERSION_1_2),
.api_version = @bitCast(vk.API_VERSION_1_4),
};
const vk_debug_utils_messenger_create_info: vk.DebugUtilsMessengerCreateInfoEXT = .{
@@ -163,7 +158,7 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
break :blk try base.createInstance(&.{
.p_application_info = &vk_application_info,
.enabled_layer_count = 0, //enabled_layers.len,
.enabled_layer_count = enabled_layers.len,
.pp_enabled_layer_names = enabled_layers.ptr,
.enabled_extension_count = @intCast(enabled_extensions.items.len),
.pp_enabled_extension_names = enabled_extensions.items.ptr,
@@ -291,14 +286,32 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
var enabled_features_vulkan12: vk.PhysicalDeviceVulkan12Features = .{
.p_next = &enabled_features_vulkan11,
.descriptor_indexing = .true,
.descriptor_binding_partially_bound = .true,
.descriptor_binding_variable_descriptor_count = .true,
.runtime_descriptor_array = .true,
.scalar_block_layout = .true,
.imageless_framebuffer = .true,
.timeline_semaphore = .true,
};
var enabled_features_vulkan13: vk.PhysicalDeviceVulkan13Features = .{
.p_next = &enabled_features_vulkan12,
.robust_image_access = .true,
.inline_uniform_block = .true,
.synchronization_2 = .true,
.dynamic_rendering = .true,
.maintenance_4 = .true,
};
var enabled_features_vulkan14: vk.PhysicalDeviceVulkan14Features = .{
.p_next = &enabled_features_vulkan13,
.maintenance_5 = .true,
.maintenance_6 = .true,
};
break :blk try instance.createDevice(physical_device, &.{
.p_next = &enabled_features_vulkan12,
.p_next = &enabled_features_vulkan14,
.queue_create_info_count = @intCast(queue_create_info.items.len),
.p_queue_create_infos = queue_create_info.items.ptr,
.enabled_extension_count = @intCast(enabled_extensions.items.len),
@@ -317,38 +330,23 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
// --- CREATE COMMAND POOLS, GET QUEUES ------------------------------------
const graphics_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true },
.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 = .{ .transient_bit = true },
.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 = .{ .transient_bit = true },
.queue_family_index = queue_allocations.transfer_queue.family,
}, &vk_allocator.interface);
errdefer device.destroyCommandPool(transfer_command_pool, &vk_allocator.interface);
const transient_graphics_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true },
.queue_family_index = queue_allocations.graphics_queue.family,
}, &vk_allocator.interface);
errdefer device.destroyCommandPool(transient_graphics_command_pool, &vk_allocator.interface);
const transient_compute_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true },
.queue_family_index = queue_allocations.compute_queue.family,
}, &vk_allocator.interface);
errdefer device.destroyCommandPool(transient_compute_command_pool, &vk_allocator.interface);
const transient_transfer_command_pool = try device.createCommandPool(&.{
.flags = .{ .transient_bit = true },
.queue_family_index = queue_allocations.transfer_queue.family,
}, &vk_allocator.interface);
errdefer device.destroyCommandPool(transient_transfer_command_pool, &vk_allocator.interface);
const graphics_queue: Queue = .init(
device.getDeviceQueue(
queue_allocations.graphics_queue.family,
@@ -414,10 +412,6 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
.compute_command_pool = compute_command_pool,
.transfer_command_pool = transfer_command_pool,
.transient_graphics_command_pool = transient_graphics_command_pool,
.transient_compute_command_pool = transient_compute_command_pool,
.transient_transfer_command_pool = transient_transfer_command_pool,
.prng_ptr = prng_ptr,
.random = random,
};
@@ -434,10 +428,6 @@ pub fn deinit(self: *Engine) void {
self.device.destroyCommandPool(self.compute_command_pool, &self.vk_allocator.interface);
self.device.destroyCommandPool(self.transfer_command_pool, &self.vk_allocator.interface);
self.device.destroyCommandPool(self.transient_graphics_command_pool, &self.vk_allocator.interface);
self.device.destroyCommandPool(self.transient_compute_command_pool, &self.vk_allocator.interface);
self.device.destroyCommandPool(self.transient_transfer_command_pool, &self.vk_allocator.interface);
self.device.destroyDevice(&self.vk_allocator.interface);
allocator.destroy(self.device.wrapper);
@@ -702,20 +692,11 @@ fn findPresentationQueueFamily(queue_families_properties: []const vk.QueueFamily
return null;
}
fn resolveCommandPool(self: *const Engine, queue_type: QueueType, transient: Transient) vk.CommandPool {
fn resolveCommandPool(self: *const Engine, queue_type: QueueType) vk.CommandPool {
return switch (queue_type) {
.graphics => switch (transient) {
.persistent => self.graphics_command_pool,
.transient => self.transient_graphics_command_pool,
},
.compute => switch (transient) {
.persistent => self.compute_command_pool,
.transient => self.transient_compute_command_pool,
},
.transfer => switch (transient) {
.persistent => self.transfer_command_pool,
.transient => self.transient_transfer_command_pool,
},
.graphics => self.graphics_command_pool,
.compute => self.compute_command_pool,
.transfer => self.transfer_command_pool,
};
}
@@ -736,13 +717,11 @@ pub const BufferCreateInfo = struct {
pub const CommandBufferAllocateInfo = struct {
queue_type: QueueType,
transient: Transient,
level: vk.CommandBufferLevel,
};
pub const CommandBufferFreeInfo = struct {
queue_type: QueueType,
transient: Transient,
command_buffer: vk.CommandBuffer,
};
@@ -944,7 +923,7 @@ pub fn acquireNextImage(self: *Engine, swapchain: vk.SwapchainKHR, acquire_info:
}
pub fn allocateCommandBuffer(self: *Engine, allocate_info: CommandBufferAllocateInfo) !vk.CommandBuffer {
const command_pool = self.resolveCommandPool(allocate_info.queue_type, allocate_info.transient);
const command_pool = self.resolveCommandPool(allocate_info.queue_type);
var command_buffers: [1]vk.CommandBuffer = undefined;
try self.device.allocateCommandBuffers(&.{
.command_pool = command_pool,
@@ -1372,7 +1351,7 @@ pub fn deviceWaitIdle(self: *Engine) !void {
}
pub fn freeCommandBuffer(self: *Engine, free_info: CommandBufferFreeInfo) void {
const command_pool = self.resolveCommandPool(free_info.queue_type, free_info.transient);
const command_pool = self.resolveCommandPool(free_info.queue_type);
const command_buffers = [_]vk.CommandBuffer{free_info.command_buffer};
self.device.freeCommandBuffers(command_pool, command_buffers.len, &command_buffers);
}