From 5e298d6bb77136b5039ba7de785892b9e596211a Mon Sep 17 00:00:00 2001 From: Okko Hakola Date: Wed, 13 Jul 2022 13:25:32 +0300 Subject: [PATCH] Allow setting present mode in vulkano util's window renderer (#1922) * Allow swapchain recreation with new present mode in utils * Add doc text * Add to changelog --- CHANGELOG.md | 1 + vulkano-util/src/renderer.rs | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cc246f6eb..3a2e396e8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,7 @@ - Added an `is_signaled` method to `FenceSignalFuture`. - Add a simple `general_purpose_image_view` method to `StorageImage` for less verbose image view creation for e.g. intermediary render targets. - Add a `vulkano_util` crate to help reduce boilerplate in many use cases. `VulkanoContext` to hold access to device & instances, `VulkanoWindows` to organize windows and their renderers. `VulkanoRenderer` to hold the window and methods to `acquire` (swapchain) and `present` between which you are intended to execute your pipelines. +- Add option to change `PresentMode` at runtime in `vulkano_util` with `set_present_mode` # Version 0.29.0 (2022-03-11) diff --git a/vulkano-util/src/renderer.rs b/vulkano-util/src/renderer.rs index 343b806b65..db4b2774b1 100644 --- a/vulkano-util/src/renderer.rs +++ b/vulkano-util/src/renderer.rs @@ -53,6 +53,7 @@ pub struct VulkanoWindowRenderer { recreate_swapchain: bool, previous_frame_end: Option>, image_index: usize, + present_mode: vulkano::swapchain::PresentMode, } impl VulkanoWindowRenderer { @@ -87,6 +88,7 @@ impl VulkanoWindowRenderer { recreate_swapchain: false, previous_frame_end, image_index: 0, + present_mode: descriptor.present_mode, } } @@ -136,6 +138,14 @@ impl VulkanoWindowRenderer { (swapchain, images) } + /// Set window renderer present mode. This triggers a swapchain recreation. + pub fn set_present_mode(&mut self, present_mode: vulkano::swapchain::PresentMode) { + if self.present_mode != present_mode { + self.present_mode = present_mode; + self.recreate_swapchain = true; + } + } + /// Return swapchain image format pub fn swapchain_format(&self) -> Format { self.final_views[self.image_index].format().unwrap() @@ -197,7 +207,7 @@ impl VulkanoWindowRenderer { dims[0] / dims[1] } - /// Resize swapchain and camera view images at the beginning of next frame + /// Resize swapchain and camera view images at the beginning of next frame based on window dimensions pub fn resize(&mut self) { self.recreate_swapchain = true; } @@ -301,6 +311,8 @@ impl VulkanoWindowRenderer { let dimensions: [u32; 2] = self.window().inner_size().into(); let (new_swapchain, new_images) = match self.swap_chain.recreate(SwapchainCreateInfo { image_extent: dimensions, + // Use present mode from current state + present_mode: self.present_mode, ..self.swap_chain.create_info() }) { Ok(r) => r,