From 64d1705730e0c7ca57e7f10afd9b181002a9311f Mon Sep 17 00:00:00 2001 From: Sebastian Aaltonen Date: Sat, 3 Oct 2020 01:08:42 +0300 Subject: [PATCH] Optimized example fences. Waited immediately. Now waits before reuse (next frame) (#327) * Optimized example fences. Waited immediately. Now waits before reuse (next frame). * rust fmt + clippy warning silenced * Add comments for record_submit_commandbuffer Co-authored-by: Sebastian Aaltonen Co-authored-by: Maik Klein --- examples/src/bin/texture.rs | 2 ++ examples/src/bin/triangle.rs | 1 + examples/src/lib.rs | 49 ++++++++++++++++++++++++++++-------- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/examples/src/bin/texture.rs b/examples/src/bin/texture.rs index a8ffd91..0377159 100644 --- a/examples/src/bin/texture.rs +++ b/examples/src/bin/texture.rs @@ -355,6 +355,7 @@ fn main() { record_submit_commandbuffer( &base.device, base.setup_command_buffer, + base.setup_commands_reuse_fence, base.present_queue, &[], &[], @@ -736,6 +737,7 @@ fn main() { record_submit_commandbuffer( &base.device, base.draw_command_buffer, + base.draw_commands_reuse_fence, base.present_queue, &[vk::PipelineStageFlags::BOTTOM_OF_PIPE], &[base.present_complete_semaphore], diff --git a/examples/src/bin/triangle.rs b/examples/src/bin/triangle.rs index 86ca5ed..9e5ed96 100644 --- a/examples/src/bin/triangle.rs +++ b/examples/src/bin/triangle.rs @@ -394,6 +394,7 @@ fn main() { record_submit_commandbuffer( &base.device, base.draw_command_buffer, + base.draw_commands_reuse_fence, base.present_queue, &[vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT], &[base.present_complete_semaphore], diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 6f54b07..d350c3d 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -25,10 +25,14 @@ macro_rules! offset_of { } }}; } - +/// Helper function for submitting command buffers. Immediately waits for the fence before the command buffer +/// is executed. That way we can delay the waiting for the fences by 1 frame which is good for performance. +/// Make sure to create the fence in a signaled state on the first use. +#[allow(clippy::too_many_arguments)] pub fn record_submit_commandbuffer( device: &D, command_buffer: vk::CommandBuffer, + command_buffer_reuse_fence: vk::Fence, submit_queue: vk::Queue, wait_mask: &[vk::PipelineStageFlags], wait_semaphores: &[vk::Semaphore], @@ -36,6 +40,14 @@ pub fn record_submit_commandbuffer