Merge pull request #551 from tomaka/acquire-sc-timeout

The timeout of acquire_next_image is now optional
This commit is contained in:
tomaka 2017-06-27 07:48:11 +02:00 committed by GitHub
commit d7c9d08f76
5 changed files with 14 additions and 11 deletions

View File

@ -154,7 +154,7 @@ fn main() {
loop { loop {
previous_frame_end.cleanup_finished(); 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()) let cb = vulkano::command_buffer::AutoCommandBufferBuilder::new(device.clone(), queue.family())
.unwrap() .unwrap()

View File

@ -166,7 +166,7 @@ fn main() {
buffer_content.world = cgmath::Matrix4::from(rotation).into(); 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() let command_buffer = vulkano::command_buffer::AutoCommandBufferBuilder::new(device.clone(), queue.family()).unwrap()
.begin_render_pass( .begin_render_pass(

View File

@ -329,10 +329,10 @@ void main() {
// function will block. // function will block.
// This operation returns the index of the image that we are allowed to draw upon. // 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 // This function can block if no image is available. The parameter is an optional timeout
// which the function call will return an error. // after which the function call will return an error.
let (image_num, acquire_future) = swapchain::acquire_next_image(swapchain.clone(), 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 // 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. // the list of commands that are going to be executed.

View File

@ -136,7 +136,7 @@
//! //!
//! TODO: add example here //! TODO: add example here
//! loop { //! loop {
//! let index = swapchain::acquire_next_image(Duration::from_millis(500)).unwrap(); //! let index = swapchain::acquire_next_image(None).unwrap();
//! draw(images[index]); //! draw(images[index]);
//! swapchain::present(queue, index).unwrap(); //! swapchain::present(queue, index).unwrap();
//! } //! }
@ -173,7 +173,7 @@
//! //!
//! let (ref swapchain, ref _images) = swapchain; //! 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, //! Ok(r) => r,
//! Err(AcquireError::OutOfDate) => { recreate_swapchain = true; continue; }, //! Err(AcquireError::OutOfDate) => { recreate_swapchain = true; continue; },
//! Err(err) => panic!("{:?}", err) //! Err(err) => panic!("{:?}", err)

View File

@ -65,8 +65,7 @@ use vk;
/// behavior may change). /// behavior may change).
// TODO: has to make sure vkQueuePresent is called, because calling acquire_next_image many // TODO: has to make sure vkQueuePresent is called, because calling acquire_next_image many
// times in a row is an error // times in a row is an error
// TODO: change timeout to `Option<Duration>`. pub fn acquire_next_image(swapchain: Arc<Swapchain>, timeout: Option<Duration>)
pub fn acquire_next_image(swapchain: Arc<Swapchain>, timeout: Duration)
-> Result<(usize, SwapchainAcquireFuture), AcquireError> -> Result<(usize, SwapchainAcquireFuture), AcquireError>
{ {
unsafe { unsafe {
@ -82,8 +81,12 @@ pub fn acquire_next_image(swapchain: Arc<Swapchain>, timeout: Duration)
let semaphore = try!(Semaphore::new(swapchain.device.clone())); let semaphore = try!(Semaphore::new(swapchain.device.clone()));
let timeout_ns = timeout.as_secs().saturating_mul(1_000_000_000) let timeout_ns = if let Some(timeout) = timeout {
.saturating_add(timeout.subsec_nanos() as u64); 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 mut out = mem::uninitialized();
let r = try!(check_errors(vk.AcquireNextImageKHR(swapchain.device.internal_object(), let r = try!(check_errors(vk.AcquireNextImageKHR(swapchain.device.internal_object(),