Fix transfer semaphore fiasco
This commit is contained in:
33
src/Game.zig
33
src/Game.zig
@@ -116,7 +116,7 @@ index_buffer: IndexBuffer,
|
||||
global_uniforms: GlobalUniformsBuffer,
|
||||
global_uniforms_staging_buffer: StagingBuffer,
|
||||
global_uniforms_transfer_command_buffer: vk.CommandBuffer,
|
||||
global_uniforms_transfer_semaphore: vk.Semaphore,
|
||||
global_uniforms_transfer_semaphores: []vk.Semaphore,
|
||||
point_lights: PointLightBuffer,
|
||||
directional_lights: DirectionalLightBuffer,
|
||||
object_uniforms: ObjectUniformsBuffer,
|
||||
@@ -326,6 +326,25 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
);
|
||||
try global_uniforms_transfer_command_buffer.endCommandBuffer();
|
||||
|
||||
const global_uniforms_transfer_semaphores = blk: {
|
||||
var semaphores: std.ArrayList(vk.Semaphore) = try .initCapacity(allocator, swapchain.swapchain_images.len);
|
||||
errdefer semaphores.deinit(allocator);
|
||||
|
||||
errdefer for (semaphores.items) |x| engine.destroySemaphore(x);
|
||||
|
||||
for (0..swapchain.swapchain_images.len) |_| {
|
||||
semaphores.appendAssumeCapacity(try engine.createSemaphore());
|
||||
}
|
||||
|
||||
break :blk try semaphores.toOwnedSlice(allocator);
|
||||
};
|
||||
errdefer {
|
||||
for (global_uniforms_transfer_semaphores) |semaphore| {
|
||||
engine.destroySemaphore(semaphore);
|
||||
}
|
||||
allocator.free(global_uniforms_transfer_semaphores);
|
||||
}
|
||||
|
||||
const global_uniforms_transfer_semaphore = try engine.createSemaphore();
|
||||
errdefer engine.destroySemaphore(global_uniforms_transfer_semaphore);
|
||||
|
||||
@@ -659,7 +678,7 @@ pub fn init(allocator: std.mem.Allocator, engine: *Engine, swapchain: *Swapchain
|
||||
.global_uniforms = global_uniforms,
|
||||
.global_uniforms_staging_buffer = global_uniforms_staging_buffer,
|
||||
.global_uniforms_transfer_command_buffer = global_uniforms_transfer_command_buffer.handle,
|
||||
.global_uniforms_transfer_semaphore = global_uniforms_transfer_semaphore,
|
||||
.global_uniforms_transfer_semaphores = global_uniforms_transfer_semaphores,
|
||||
.point_lights = point_lights,
|
||||
.directional_lights = directional_lights,
|
||||
.object_uniforms = object_uniforms,
|
||||
@@ -683,7 +702,11 @@ pub fn deinit(self: *Game) void {
|
||||
self.directional_lights.deinit(self.engine);
|
||||
self.object_uniforms.deinit(self.engine);
|
||||
|
||||
self.engine.destroySemaphore(self.global_uniforms_transfer_semaphore);
|
||||
for (self.global_uniforms_transfer_semaphores) |semaphore| {
|
||||
self.engine.destroySemaphore(semaphore);
|
||||
}
|
||||
self.allocator.free(self.global_uniforms_transfer_semaphores);
|
||||
|
||||
self.engine.destroyDescriptorPool(self.descriptor_pool);
|
||||
self.engine.destroySampler(self.sampler);
|
||||
self.engine.destroyPipeline(self.pipeline);
|
||||
@@ -756,7 +779,7 @@ pub fn update(self: *Game, dt: f32) void {
|
||||
.command_buffer_count = 1,
|
||||
.p_command_buffers = @ptrCast(&self.global_uniforms_transfer_command_buffer),
|
||||
.signal_semaphore_count = 1,
|
||||
.p_signal_semaphores = @ptrCast(&self.global_uniforms_transfer_semaphore),
|
||||
.p_signal_semaphores = @ptrCast(&self.global_uniforms_transfer_semaphores[self.swapchain.image_index]),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -892,7 +915,7 @@ fn render(self: *Game) !void {
|
||||
.command_buffer = command_buffer.handle,
|
||||
.wait_semaphores = &.{
|
||||
.{
|
||||
.semaphore = self.global_uniforms_transfer_semaphore,
|
||||
.semaphore = self.global_uniforms_transfer_semaphores[self.swapchain.image_index],
|
||||
.stage_flags = .{ .vertex_shader_bit = true },
|
||||
},
|
||||
},
|
||||
|
||||
@@ -83,10 +83,9 @@ pub fn main() !void {
|
||||
}
|
||||
|
||||
std.log.debug("Exitted the game loop", .{});
|
||||
std.posix.abort();
|
||||
|
||||
//for (swapchain.swapchain_images) |x| engine.waitForFence(x.fence) catch {};
|
||||
//engine.device.deviceWaitIdle() catch {};
|
||||
for (swapchain.swapchain_images) |x| engine.waitForFence(x.fence) catch {};
|
||||
engine.device.deviceWaitIdle() catch {};
|
||||
}
|
||||
|
||||
const CallbackContext = struct {
|
||||
|
||||
Reference in New Issue
Block a user