diff --git a/CHANGELOG_VULKANO.md b/CHANGELOG_VULKANO.md index d96b4042..c57e17d4 100644 --- a/CHANGELOG_VULKANO.md +++ b/CHANGELOG_VULKANO.md @@ -4,6 +4,7 @@ - `dynamic-local-size` compute shader example added showing how to utilize `subgroupSize` to compute and set shader's local size in run time. - Fixed Vulkano Shaders bug when compute shader local group layout values bound to specialization constants. Now it is possible to define the layout in form of `layout(local_size_x_id = 12, local_size_y_id = 13, local_size_z = 1) in;` and then set the values as `SpecializationConstants {constant_12: 8, constant_13: 4, ...}`. - Allow applications to access the instance and device pointers +- Add a helper function '.boxed()' on the `GpuFuture` that is short for `Box::new(yourFuture) as Box` # Version 0.18.0 (2020-03-11) diff --git a/examples/src/bin/buffer-pool.rs b/examples/src/bin/buffer-pool.rs index eb787bab..5bc86db6 100644 --- a/examples/src/bin/buffer-pool.rs +++ b/examples/src/bin/buffer-pool.rs @@ -189,7 +189,7 @@ fn main() { let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut dynamic_state); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box); + let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); event_loop.run(move |event, _, control_flow| { match event { diff --git a/examples/src/bin/deferred/main.rs b/examples/src/bin/deferred/main.rs index 376f70c6..6fd326f8 100644 --- a/examples/src/bin/deferred/main.rs +++ b/examples/src/bin/deferred/main.rs @@ -113,7 +113,7 @@ fn main() { TriangleDrawSystem::new(queue.clone(), frame_system.deferred_subpass()); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box); + let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { @@ -189,15 +189,15 @@ fn main() { match future { Ok(future) => { - previous_frame_end = Some(Box::new(future) as Box<_>); + previous_frame_end = Some(future.boxed()); } Err(FlushError::OutOfDate) => { recreate_swapchain = true; - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { println!("Failed to flush future: {:?}", e); - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } } } diff --git a/examples/src/bin/image/main.rs b/examples/src/bin/image/main.rs index 854186a5..9e7732bb 100644 --- a/examples/src/bin/image/main.rs +++ b/examples/src/bin/image/main.rs @@ -220,7 +220,7 @@ fn main() { window_size_dependent_setup(&images, render_pass.clone(), &mut dynamic_state); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(Box::new(tex_future) as Box); + let mut previous_frame_end = Some(tex_future.boxed()); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { @@ -300,15 +300,15 @@ fn main() { match future { Ok(future) => { - previous_frame_end = Some(Box::new(future) as Box<_>); + previous_frame_end = Some(future.boxed()); } Err(FlushError::OutOfDate) => { recreate_swapchain = true; - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { println!("Failed to flush future: {:?}", e); - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } } } diff --git a/examples/src/bin/indirect.rs b/examples/src/bin/indirect.rs index 90f1acbb..0603f368 100644 --- a/examples/src/bin/indirect.rs +++ b/examples/src/bin/indirect.rs @@ -252,7 +252,7 @@ fn main() { let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut dynamic_state); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box); + let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); event_loop.run(move |event, _, control_flow| { match event { @@ -377,15 +377,15 @@ fn main() { match future { Ok(future) => { - previous_frame_end = Some(Box::new(future) as Box<_>); + previous_frame_end = Some(future.boxed()); } Err(FlushError::OutOfDate) => { recreate_swapchain = true; - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { println!("Failed to flush future: {:?}", e); - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } } } diff --git a/examples/src/bin/instancing.rs b/examples/src/bin/instancing.rs index 9e1a5728..a4b1927a 100644 --- a/examples/src/bin/instancing.rs +++ b/examples/src/bin/instancing.rs @@ -260,7 +260,7 @@ fn main() { let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut dynamic_state); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box); + let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); event_loop.run(move |event, _, control_flow| { match event { @@ -345,15 +345,15 @@ fn main() { match future { Ok(future) => { - previous_frame_end = Some(Box::new(future) as Box<_>); + previous_frame_end = Some(future.boxed()); } Err(FlushError::OutOfDate) => { recreate_swapchain = true; - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { println!("Failed to flush future: {:?}", e); - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } } } diff --git a/examples/src/bin/multi-window.rs b/examples/src/bin/multi-window.rs index 0bd178bd..ada6dd4d 100644 --- a/examples/src/bin/multi-window.rs +++ b/examples/src/bin/multi-window.rs @@ -237,7 +237,7 @@ fn main() { render_pass.clone(), &mut dynamic_state, ), - previous_frame_end: Some(Box::new(sync::now(device.clone())) as Box), + previous_frame_end: Some(sync::now(device.clone()).boxed()), }, ); @@ -314,9 +314,7 @@ fn main() { render_pass.clone(), &mut dynamic_state, ), - previous_frame_end: Some( - Box::new(sync::now(device.clone())) as Box - ), + previous_frame_end: Some(sync::now(device.clone()).boxed()), }, ); } @@ -399,15 +397,15 @@ fn main() { match future { Ok(future) => { - *previous_frame_end = Some(Box::new(future) as Box<_>); + *previous_frame_end = Some(future.boxed()); } Err(FlushError::OutOfDate) => { *recreate_swapchain = true; - *previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + *previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { println!("Failed to flush future: {:?}", e); - *previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + *previous_frame_end = Some(sync::now(device.clone()).boxed()); } } } diff --git a/examples/src/bin/runtime-shader/main.rs b/examples/src/bin/runtime-shader/main.rs index 9ce25aed..e629fa10 100644 --- a/examples/src/bin/runtime-shader/main.rs +++ b/examples/src/bin/runtime-shader/main.rs @@ -467,7 +467,7 @@ fn main() { }; let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone(), &mut dynamic_state); - let mut previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box); + let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); event_loop.run(move |event, _, control_flow| match event { Event::WindowEvent { @@ -546,15 +546,15 @@ fn main() { match future { Ok(future) => { - previous_frame_end = Some(Box::new(future) as Box<_>); + previous_frame_end = Some(future.boxed()); } Err(FlushError::OutOfDate) => { recreate_swapchain = true; - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { println!("Failed to flush future: {:?}", e); - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } } } diff --git a/examples/src/bin/teapot/main.rs b/examples/src/bin/teapot/main.rs index 96cb6f7f..74c1d6f0 100644 --- a/examples/src/bin/teapot/main.rs +++ b/examples/src/bin/teapot/main.rs @@ -152,7 +152,7 @@ fn main() { window_size_dependent_setup(device.clone(), &vs, &fs, &images, render_pass.clone()); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box); + let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); let rotation_start = Instant::now(); event_loop.run(move |event, _, control_flow| { @@ -284,15 +284,15 @@ fn main() { match future { Ok(future) => { - previous_frame_end = Some(Box::new(future) as Box<_>); + previous_frame_end = Some(future.boxed()); } Err(FlushError::OutOfDate) => { recreate_swapchain = true; - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { println!("Failed to flush future: {:?}", e); - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } } } diff --git a/examples/src/bin/tessellation.rs b/examples/src/bin/tessellation.rs index e74ab1a3..2e0c4e8b 100644 --- a/examples/src/bin/tessellation.rs +++ b/examples/src/bin/tessellation.rs @@ -286,7 +286,7 @@ fn main() { ); let mut recreate_swapchain = false; - let mut previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box); + let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); let mut dynamic_state = DynamicState { line_width: None, viewports: None, @@ -379,15 +379,15 @@ fn main() { match future { Ok(future) => { - previous_frame_end = Some(Box::new(future) as Box<_>); + previous_frame_end = Some(future.boxed()); } Err(FlushError::OutOfDate) => { recreate_swapchain = true; - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { println!("Failed to flush future: {:?}", e); - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } } } diff --git a/examples/src/bin/triangle.rs b/examples/src/bin/triangle.rs index f6cafd3a..05d190a1 100644 --- a/examples/src/bin/triangle.rs +++ b/examples/src/bin/triangle.rs @@ -364,7 +364,7 @@ fn main() { // // Destroying the `GpuFuture` blocks until the GPU is finished executing it. In order to avoid // that, we store the submission of the previous frame here. - let mut previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box); + let mut previous_frame_end = Some(sync::now(device.clone()).boxed()); event_loop.run(move |event, _, control_flow| { match event { @@ -500,15 +500,15 @@ fn main() { match future { Ok(future) => { - previous_frame_end = Some(Box::new(future) as Box<_>); + previous_frame_end = Some(future.boxed()); } Err(FlushError::OutOfDate) => { recreate_swapchain = true; - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } Err(e) => { println!("Failed to flush future: {:?}", e); - previous_frame_end = Some(Box::new(sync::now(device.clone())) as Box<_>); + previous_frame_end = Some(sync::now(device.clone()).boxed()); } } } diff --git a/vulkano/src/sync/future/mod.rs b/vulkano/src/sync/future/mod.rs index cd2941a9..41549612 100644 --- a/vulkano/src/sync/future/mod.rs +++ b/vulkano/src/sync/future/mod.rs @@ -283,6 +283,16 @@ pub unsafe trait GpuFuture: DeviceOwned { { swapchain::present_incremental(swapchain, self, queue, image_index, present_region) } + + /// Turn the current future into a `Box`. + /// + /// This is a helper function that calls `Box::new(yourFuture) as Box`. + fn boxed(self) -> Box + where + Self: Sized + 'static, + { + Box::new(self) as _ + } } unsafe impl GpuFuture for Box