Vertical movement, deinit logs, persistent global uniform transfers

This commit is contained in:
2025-11-27 17:07:22 +01:00
parent b9a804ead6
commit 6069249bf8
11 changed files with 212 additions and 82 deletions

View File

@@ -17,6 +17,7 @@ pub const Mode = union(enum) {
},
pub fn deinit(self: *Mode, instance: vk.InstanceProxy, vk_allocator: *VkAllocator) void {
std.log.debug("Deinitializing {*} with InstanceProxy@{{{X},{*}}} and {*}", .{ self, instance.handle, instance.wrapper, vk_allocator });
switch (self.*) {
.headless => {},
.surface => |x| {
@@ -103,6 +104,7 @@ transfer_queue: Queue,
graphics_command_pool: vk.CommandPool,
compute_command_pool: vk.CommandPool,
transfer_command_pool: vk.CommandPool,
transient_transfer_command_pool: vk.CommandPool,
prng_ptr: *std.Random.Pcg,
random: std.Random,
@@ -320,29 +322,27 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
// --- CREATE COMMAND POOLS, GET QUEUES ------------------------------------
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 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 = .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);
@@ -383,6 +383,7 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
.graphics_command_pool = graphics_command_pool,
.compute_command_pool = compute_command_pool,
.transfer_command_pool = transfer_command_pool,
.transient_transfer_command_pool = transient_transfer_command_pool,
.prng_ptr = prng_ptr,
.random = random,
@@ -390,6 +391,8 @@ pub fn init(allocator: std.mem.Allocator, maybe_window: ?*glfw.Window) !Engine {
}
pub fn deinit(self: *Engine) void {
std.log.debug("Deinitializing {*}", .{self});
const allocator = self.vk_allocator.allocator;
allocator.destroy(self.prng_ptr);
@@ -397,6 +400,7 @@ pub fn deinit(self: *Engine) void {
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.destroyCommandPool(self.transient_transfer_command_pool, &self.vk_allocator.interface);
self.device.destroyDevice(&self.vk_allocator.interface);
allocator.destroy(self.device.wrapper);
@@ -433,6 +437,16 @@ pub fn allocate(self: *const Engine, memory_requirements: vk.MemoryRequirements,
return error.NoSuitableMemoryType;
}
pub fn allocateTransientTransferCommandBuffer(self: *const Engine) !vk.CommandBufferProxy {
var command_buffer: vk.CommandBuffer = undefined;
try self.device.allocateCommandBuffers(&.{
.command_pool = self.transient_transfer_command_pool,
.level = .primary,
.command_buffer_count = 1,
}, @ptrCast(&command_buffer));
return .init(command_buffer, self.device.wrapper);
}
pub fn allocateTransferCommandBuffer(self: *const Engine) !vk.CommandBufferProxy {
var command_buffer: vk.CommandBuffer = undefined;
try self.device.allocateCommandBuffers(&.{
@@ -457,6 +471,10 @@ pub fn freeTransferCommandBuffer(self: *const Engine, command_buffer: vk.Command
self.device.freeCommandBuffers(self.transfer_command_pool, 1, @ptrCast(&command_buffer));
}
pub fn freeTransientTransferCommandBuffer(self: *const Engine, command_buffer: vk.CommandBufferProxy) void {
self.device.freeCommandBuffers(self.transient_transfer_command_pool, 1, @ptrCast(&command_buffer));
}
pub fn freeGraphicsCommandBuffer(self: *const Engine, command_buffer: vk.CommandBufferProxy) void {
self.device.freeCommandBuffers(self.graphics_command_pool, 1, @ptrCast(&command_buffer));
}
@@ -1125,5 +1143,5 @@ pub fn updateDescriptorSets(self: *Engine, update_info: DescriptorSetsUpdateInfo
}
pub fn waitForFence(self: *Engine, fence: vk.Fence) !void {
_ = try self.device.waitForFences(1, @ptrCast(&fence), .true, std.math.maxInt(u64));
_ = try self.device.waitForFences(1, @ptrCast(&fence), .true, 1 * std.time.ns_per_s);
}