diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d9a6452..9f65d168 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -98,6 +98,7 @@ Changes to vulkano-shaders: Changes to vulkano-util: - `VulkanoWindowRenderer::acquire` now takes in an `FnOnce(&[Arc])`. This means that a closure can be called when the swapchain gets recreated. +- `VulkanoWindowRenderer::acquire` now also takes in `Option` for the swapchain acquire timeout. ### Additions diff --git a/examples/interactive-fractal/main.rs b/examples/interactive-fractal/main.rs index ed6fa4c6..92a06cd6 100644 --- a/examples/interactive-fractal/main.rs +++ b/examples/interactive-fractal/main.rs @@ -11,7 +11,7 @@ // - A simple `InputState` to interact with the application. use crate::app::FractalApp; -use std::error::Error; +use std::{error::Error, time::Duration}; use vulkano::{image::ImageUsage, swapchain::PresentMode, sync::GpuFuture}; use vulkano_util::{ context::{VulkanoConfig, VulkanoContext}, @@ -145,16 +145,17 @@ fn compute_then_render( target_image_id: usize, ) { // Start the frame. - let before_pipeline_future = match renderer.acquire(|swapchain_image_views| { - app.place_over_frame - .recreate_framebuffers(swapchain_image_views) - }) { - Err(e) => { - println!("{e}"); - return; - } - Ok(future) => future, - }; + let before_pipeline_future = + match renderer.acquire(Some(Duration::from_millis(1)), |swapchain_image_views| { + app.place_over_frame + .recreate_framebuffers(swapchain_image_views) + }) { + Err(e) => { + println!("{e}"); + return; + } + Ok(future) => future, + }; // Retrieve the target image. let image = renderer.get_additional_image_view(target_image_id); diff --git a/examples/multi-window-game-of-life/main.rs b/examples/multi-window-game-of-life/main.rs index d7813c5b..44779c2d 100644 --- a/examples/multi-window-game-of-life/main.rs +++ b/examples/multi-window-game-of-life/main.rs @@ -14,7 +14,10 @@ mod render_pass; use crate::app::{App, RenderPipeline}; use glam::{f32::Vec2, IVec2}; -use std::{error::Error, time::Instant}; +use std::{ + error::Error, + time::{Duration, Instant}, +}; use vulkano_util::renderer::VulkanoWindowRenderer; use winit::{ event::{ElementState, Event, MouseButton, WindowEvent}, @@ -194,17 +197,18 @@ fn compute_then_render( } // Start the frame. - let before_pipeline_future = match window_renderer.acquire(|swapchain_image_views| { - pipeline - .place_over_frame - .recreate_framebuffers(swapchain_image_views) - }) { - Err(e) => { - println!("{e}"); - return; - } - Ok(future) => future, - }; + let before_pipeline_future = + match window_renderer.acquire(Some(Duration::from_millis(1)), |swapchain_image_views| { + pipeline + .place_over_frame + .recreate_framebuffers(swapchain_image_views) + }) { + Err(e) => { + println!("{e}"); + return; + } + Ok(future) => future, + }; // Compute. let after_compute = pipeline diff --git a/examples/triangle-util/main.rs b/examples/triangle-util/main.rs index 249e3810..3e80a9f8 100644 --- a/examples/triangle-util/main.rs +++ b/examples/triangle-util/main.rs @@ -7,7 +7,7 @@ // that you want to learn Vulkan. This means that for example it won't go into details about what a // vertex or a shader is. -use std::{error::Error, sync::Arc}; +use std::{error::Error, sync::Arc, time::Duration}; use vulkano::{ buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage}, command_buffer::{ @@ -331,11 +331,11 @@ fn main() -> Result<(), impl Error> { // Begin rendering by acquiring the gpu future from the window renderer. let previous_frame_end = window_renderer - .acquire(|swapchain_images| { - // Whenever the window resizes we need to recreate everything dependent on - // the window size. In this example that includes - // the swapchain, the framebuffers and the dynamic - // state viewport. + .acquire(Some(Duration::from_millis(1)), |swapchain_images| { + // Whenever the window resizes we need to recreate everything dependent + // on the window size. In this example that + // includes the swapchain, the framebuffers + // and the dynamic state viewport. framebuffers = window_size_dependent_setup( swapchain_images, render_pass.clone(), diff --git a/vulkano-util/src/renderer.rs b/vulkano-util/src/renderer.rs index d36d9e13..1b188e1b 100644 --- a/vulkano-util/src/renderer.rs +++ b/vulkano-util/src/renderer.rs @@ -1,6 +1,6 @@ use crate::{context::VulkanoContext, window::WindowDescriptor}; use ahash::HashMap; -use std::sync::Arc; +use std::{sync::Arc, time::Duration}; use vulkano::{ device::{Device, Queue}, format::Format, @@ -263,6 +263,7 @@ impl VulkanoWindowRenderer { #[inline] pub fn acquire( &mut self, + timeout: Option, on_recreate_swapchain: impl FnOnce(&[Arc]), ) -> Result, VulkanError> { // Recreate swap chain if needed (when resizing of window occurs or swapchain is outdated) @@ -274,7 +275,7 @@ impl VulkanoWindowRenderer { // Acquire next image in the swapchain let (image_index, suboptimal, acquire_future) = - match swapchain::acquire_next_image(self.swapchain.clone(), None) + match swapchain::acquire_next_image(self.swapchain.clone(), timeout) .map_err(Validated::unwrap) { Ok(r) => r,