mirror of
https://github.com/vulkano-rs/vulkano.git
synced 2024-11-22 06:45:23 +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:
|
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 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
|
### Additions
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
// - A simple `InputState` to interact with the application.
|
// - A simple `InputState` to interact with the application.
|
||||||
|
|
||||||
use crate::app::FractalApp;
|
use crate::app::FractalApp;
|
||||||
use std::error::Error;
|
use std::{error::Error, time::Duration};
|
||||||
use vulkano::{image::ImageUsage, swapchain::PresentMode, sync::GpuFuture};
|
use vulkano::{image::ImageUsage, swapchain::PresentMode, sync::GpuFuture};
|
||||||
use vulkano_util::{
|
use vulkano_util::{
|
||||||
context::{VulkanoConfig, VulkanoContext},
|
context::{VulkanoConfig, VulkanoContext},
|
||||||
@ -145,7 +145,8 @@ fn compute_then_render(
|
|||||||
target_image_id: usize,
|
target_image_id: usize,
|
||||||
) {
|
) {
|
||||||
// Start the frame.
|
// Start the frame.
|
||||||
let before_pipeline_future = match renderer.acquire(|swapchain_image_views| {
|
let before_pipeline_future =
|
||||||
|
match renderer.acquire(Some(Duration::from_millis(1)), |swapchain_image_views| {
|
||||||
app.place_over_frame
|
app.place_over_frame
|
||||||
.recreate_framebuffers(swapchain_image_views)
|
.recreate_framebuffers(swapchain_image_views)
|
||||||
}) {
|
}) {
|
||||||
|
@ -14,7 +14,10 @@ mod render_pass;
|
|||||||
|
|
||||||
use crate::app::{App, RenderPipeline};
|
use crate::app::{App, RenderPipeline};
|
||||||
use glam::{f32::Vec2, IVec2};
|
use glam::{f32::Vec2, IVec2};
|
||||||
use std::{error::Error, time::Instant};
|
use std::{
|
||||||
|
error::Error,
|
||||||
|
time::{Duration, Instant},
|
||||||
|
};
|
||||||
use vulkano_util::renderer::VulkanoWindowRenderer;
|
use vulkano_util::renderer::VulkanoWindowRenderer;
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{ElementState, Event, MouseButton, WindowEvent},
|
event::{ElementState, Event, MouseButton, WindowEvent},
|
||||||
@ -194,7 +197,8 @@ fn compute_then_render(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start the frame.
|
// Start the frame.
|
||||||
let before_pipeline_future = match window_renderer.acquire(|swapchain_image_views| {
|
let before_pipeline_future =
|
||||||
|
match window_renderer.acquire(Some(Duration::from_millis(1)), |swapchain_image_views| {
|
||||||
pipeline
|
pipeline
|
||||||
.place_over_frame
|
.place_over_frame
|
||||||
.recreate_framebuffers(swapchain_image_views)
|
.recreate_framebuffers(swapchain_image_views)
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
// that you want to learn Vulkan. This means that for example it won't go into details about what a
|
// 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.
|
// vertex or a shader is.
|
||||||
|
|
||||||
use std::{error::Error, sync::Arc};
|
use std::{error::Error, sync::Arc, time::Duration};
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage},
|
buffer::{Buffer, BufferContents, BufferCreateInfo, BufferUsage},
|
||||||
command_buffer::{
|
command_buffer::{
|
||||||
@ -331,11 +331,11 @@ fn main() -> Result<(), impl Error> {
|
|||||||
|
|
||||||
// Begin rendering by acquiring the gpu future from the window renderer.
|
// Begin rendering by acquiring the gpu future from the window renderer.
|
||||||
let previous_frame_end = window_renderer
|
let previous_frame_end = window_renderer
|
||||||
.acquire(|swapchain_images| {
|
.acquire(Some(Duration::from_millis(1)), |swapchain_images| {
|
||||||
// Whenever the window resizes we need to recreate everything dependent on
|
// Whenever the window resizes we need to recreate everything dependent
|
||||||
// the window size. In this example that includes
|
// on the window size. In this example that
|
||||||
// the swapchain, the framebuffers and the dynamic
|
// includes the swapchain, the framebuffers
|
||||||
// state viewport.
|
// and the dynamic state viewport.
|
||||||
framebuffers = window_size_dependent_setup(
|
framebuffers = window_size_dependent_setup(
|
||||||
swapchain_images,
|
swapchain_images,
|
||||||
render_pass.clone(),
|
render_pass.clone(),
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use crate::{context::VulkanoContext, window::WindowDescriptor};
|
use crate::{context::VulkanoContext, window::WindowDescriptor};
|
||||||
use ahash::HashMap;
|
use ahash::HashMap;
|
||||||
use std::sync::Arc;
|
use std::{sync::Arc, time::Duration};
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
device::{Device, Queue},
|
device::{Device, Queue},
|
||||||
format::Format,
|
format::Format,
|
||||||
@ -263,6 +263,7 @@ impl VulkanoWindowRenderer {
|
|||||||
#[inline]
|
#[inline]
|
||||||
pub fn acquire(
|
pub fn acquire(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
timeout: Option<Duration>,
|
||||||
on_recreate_swapchain: impl FnOnce(&[Arc<ImageView>]),
|
on_recreate_swapchain: impl FnOnce(&[Arc<ImageView>]),
|
||||||
) -> Result<Box<dyn GpuFuture>, VulkanError> {
|
) -> Result<Box<dyn GpuFuture>, VulkanError> {
|
||||||
// Recreate swap chain if needed (when resizing of window occurs or swapchain is outdated)
|
// 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
|
// Acquire next image in the swapchain
|
||||||
let (image_index, suboptimal, acquire_future) =
|
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)
|
.map_err(Validated::unwrap)
|
||||||
{
|
{
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
|
Loading…
Reference in New Issue
Block a user