Add a frame fence
This commit is contained in:
parent
656406f121
commit
059fa90096
1 changed files with 15 additions and 2 deletions
|
@ -70,6 +70,7 @@ pub const VulkanRenderer = struct {
|
|||
// Synchronisation
|
||||
image_available: vk.Semaphore,
|
||||
render_finished: vk.Semaphore,
|
||||
frame_fence: vk.Fence,
|
||||
|
||||
debug_utils: ?vk.DebugUtilsMessengerEXT,
|
||||
|
||||
|
@ -102,9 +103,16 @@ pub const VulkanRenderer = struct {
|
|||
}
|
||||
|
||||
pub fn draw(self: *Self) !void {
|
||||
_ = try self.device.waitForFences(1, @ptrCast(&self.frame_fence), vk.TRUE, std.math.maxInt(u64));
|
||||
_ = try self.device.resetFences(1, @ptrCast(&self.frame_fence));
|
||||
// -- Get next image
|
||||
// Get index of next image to be drawn to, and signal semaphore when ready to be drawn to
|
||||
const image_index_result = try self.device.acquireNextImageKHR(self.swapchain, std.math.maxInt(u64), self.image_available, .null_handle);
|
||||
const image_index_result = try self.device.acquireNextImageKHR(
|
||||
self.swapchain,
|
||||
std.math.maxInt(u64),
|
||||
self.image_available,
|
||||
.null_handle,
|
||||
);
|
||||
|
||||
// -- Submit command buffer to render
|
||||
// Queue submission information
|
||||
|
@ -121,7 +129,7 @@ pub const VulkanRenderer = struct {
|
|||
};
|
||||
|
||||
// Submit command buffer to queue
|
||||
try self.device.queueSubmit(self.graphics_queue.handle, 1, @ptrCast(&submit_info), .null_handle);
|
||||
try self.device.queueSubmit(self.graphics_queue.handle, 1, @ptrCast(&submit_info), self.frame_fence);
|
||||
|
||||
// -- Present rendered image to screen
|
||||
const present_info: vk.PresentInfoKHR = .{
|
||||
|
@ -141,6 +149,8 @@ pub const VulkanRenderer = struct {
|
|||
self.instance.destroyDebugUtilsMessengerEXT(self.debug_utils.?, null);
|
||||
}
|
||||
|
||||
_ = self.device.waitForFences(1, @ptrCast(&self.frame_fence), vk.TRUE, std.math.maxInt(u64)) catch undefined;
|
||||
self.device.destroyFence(self.frame_fence, null);
|
||||
self.device.destroySemaphore(self.render_finished, null);
|
||||
self.device.destroySemaphore(self.image_available, null);
|
||||
|
||||
|
@ -631,6 +641,9 @@ pub const VulkanRenderer = struct {
|
|||
// Semaphore creation information
|
||||
self.image_available = try self.device.createSemaphore(&.{}, null);
|
||||
self.render_finished = try self.device.createSemaphore(&.{}, null);
|
||||
|
||||
const fence_create_info: vk.FenceCreateInfo = .{ .flags = .{ .signaled_bit = true } };
|
||||
self.frame_fence = try self.device.createFence(&fence_create_info, null);
|
||||
}
|
||||
|
||||
fn recordCommands(self: *Self) !void {
|
||||
|
|
Loading…
Reference in a new issue