From 4df639a834485090b4f43db7a557b5a4f472c1f0 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sun, 25 Jun 2017 10:28:22 +0200 Subject: [PATCH] The timeout of acquire_next_image is now optional --- examples/src/bin/image.rs | 2 +- examples/src/bin/teapot.rs | 2 +- examples/src/bin/triangle.rs | 6 +++--- vulkano/src/swapchain/mod.rs | 4 ++-- vulkano/src/swapchain/swapchain.rs | 11 +++++++---- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/src/bin/image.rs b/examples/src/bin/image.rs index 2344f66d..169a7d31 100644 --- a/examples/src/bin/image.rs +++ b/examples/src/bin/image.rs @@ -154,7 +154,7 @@ fn main() { loop { previous_frame_end.cleanup_finished(); - let (image_num, future) = vulkano::swapchain::acquire_next_image(swapchain.clone(), Duration::new(10, 0)).unwrap(); + let (image_num, future) = vulkano::swapchain::acquire_next_image(swapchain.clone(), None).unwrap(); let cb = vulkano::command_buffer::AutoCommandBufferBuilder::new(device.clone(), queue.family()) .unwrap() diff --git a/examples/src/bin/teapot.rs b/examples/src/bin/teapot.rs index f987ce8d..1d2383d5 100644 --- a/examples/src/bin/teapot.rs +++ b/examples/src/bin/teapot.rs @@ -166,7 +166,7 @@ fn main() { buffer_content.world = cgmath::Matrix4::from(rotation).into(); } - let (image_num, acquire_future) = vulkano::swapchain::acquire_next_image(swapchain.clone(), std::time::Duration::new(1, 0)).unwrap(); + let (image_num, acquire_future) = vulkano::swapchain::acquire_next_image(swapchain.clone(), None).unwrap(); let command_buffer = vulkano::command_buffer::AutoCommandBufferBuilder::new(device.clone(), queue.family()).unwrap() .begin_render_pass( diff --git a/examples/src/bin/triangle.rs b/examples/src/bin/triangle.rs index 1296621f..1e967e82 100644 --- a/examples/src/bin/triangle.rs +++ b/examples/src/bin/triangle.rs @@ -329,10 +329,10 @@ void main() { // function will block. // This operation returns the index of the image that we are allowed to draw upon. // - // This function can block if no image is available. The parameter is a timeout after - // which the function call will return an error. + // This function can block if no image is available. The parameter is an optional timeout + // after which the function call will return an error. let (image_num, acquire_future) = swapchain::acquire_next_image(swapchain.clone(), - Duration::new(1, 0)).unwrap(); + None).unwrap(); // In order to draw, we have to build a *command buffer*. The command buffer object holds // the list of commands that are going to be executed. diff --git a/vulkano/src/swapchain/mod.rs b/vulkano/src/swapchain/mod.rs index b8947b6d..7a287e1e 100644 --- a/vulkano/src/swapchain/mod.rs +++ b/vulkano/src/swapchain/mod.rs @@ -136,7 +136,7 @@ //! //! TODO: add example here //! loop { -//! let index = swapchain::acquire_next_image(Duration::from_millis(500)).unwrap(); +//! let index = swapchain::acquire_next_image(None).unwrap(); //! draw(images[index]); //! swapchain::present(queue, index).unwrap(); //! } @@ -173,7 +173,7 @@ //! //! let (ref swapchain, ref _images) = swapchain; //! -//! let (index, acq_future) = match swapchain::acquire_next_image(swapchain.clone(), Duration::from_millis(500)) { +//! let (index, acq_future) = match swapchain::acquire_next_image(swapchain.clone(), None) { //! Ok(r) => r, //! Err(AcquireError::OutOfDate) => { recreate_swapchain = true; continue; }, //! Err(err) => panic!("{:?}", err) diff --git a/vulkano/src/swapchain/swapchain.rs b/vulkano/src/swapchain/swapchain.rs index ac4ebfae..8e16b11e 100644 --- a/vulkano/src/swapchain/swapchain.rs +++ b/vulkano/src/swapchain/swapchain.rs @@ -64,8 +64,7 @@ use vk; /// behavior may change). // TODO: has to make sure vkQueuePresent is called, because calling acquire_next_image many // times in a row is an error -// TODO: change timeout to `Option`. -pub fn acquire_next_image(swapchain: Arc, timeout: Duration) +pub fn acquire_next_image(swapchain: Arc, timeout: Option) -> Result<(usize, SwapchainAcquireFuture), AcquireError> { unsafe { @@ -81,8 +80,12 @@ pub fn acquire_next_image(swapchain: Arc, timeout: Duration) let semaphore = try!(Semaphore::new(swapchain.device.clone())); - let timeout_ns = timeout.as_secs().saturating_mul(1_000_000_000) - .saturating_add(timeout.subsec_nanos() as u64); + let timeout_ns = if let Some(timeout) = timeout { + timeout.as_secs().saturating_mul(1_000_000_000) + .saturating_add(timeout.subsec_nanos() as u64) + } else { + u64::max_value() + }; let mut out = mem::uninitialized(); let r = try!(check_errors(vk.AcquireNextImageKHR(swapchain.device.internal_object(),