mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-10-29 21:42:26 +00:00
Pass timeout to acquire (#2503)
* Pass timeout to acquire * Changelog * Fix examples * Switch input order
This commit is contained in:
parent
93b6e9401f
commit
15f60f02c9
@ -98,6 +98,7 @@ Changes to vulkano-shaders:
|
||||
|
||||
Changes to vulkano-util:
|
||||
- `VulkanoWindowRenderer::acquire` now takes in an `FnOnce(&[Arc<ImageView>])`. This means that a closure can be called when the swapchain gets recreated.
|
||||
- `VulkanoWindowRenderer::acquire` now also takes in `Option<Duration>` for the swapchain acquire timeout.
|
||||
|
||||
### Additions
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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(),
|
||||
|
@ -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<Duration>,
|
||||
on_recreate_swapchain: impl FnOnce(&[Arc<ImageView>]),
|
||||
) -> Result<Box<dyn GpuFuture>, 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,
|
||||
|
Loading…
Reference in New Issue
Block a user