Skip to content

Commit

Permalink
Image extent zero length (#1893)
Browse files Browse the repository at this point in the history
* Updating examples and SwapchainCreationError enum to resolve #1892 and related discussion

* Slightly better documentation
  • Loading branch information
ryco117 authored May 9, 2022
1 parent 5c6bbe0 commit a893590
Show file tree
Hide file tree
Showing 22 changed files with 143 additions and 24 deletions.
7 changes: 6 additions & 1 deletion examples/src/bin/buffer-pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,17 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) =
match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/clear_attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/deferred/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/image-self-copy-blit/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/image/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,11 +266,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/immutable-sampler/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/indirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,17 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) =
match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/instancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,17 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) =
match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
10 changes: 10 additions & 0 deletions examples/src/bin/interactive_fractal/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ fn main() {
if !handle_events(&mut event_loop, &mut renderer, &mut app) {
break;
}

match renderer.window_size() {
[w, h] => {
// Skip this frame when minimized
if w == 0 || h == 0 {
continue;
}
}
}

app.update_state_after_inputs(&mut renderer);
compute_then_render(&mut renderer, &mut app, render_target_id);
app.reset_input_state();
Expand Down
1 change: 0 additions & 1 deletion examples/src/bin/interactive_fractal/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ impl Renderer {
}

/// Winit window size
#[allow(unused)]
pub fn window_size(&self) -> [u32; 2] {
let size = self.window().inner_size();
[size.width, size.height]
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/multi-window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,11 +352,16 @@ fn main() {
ref mut previous_frame_end,
} = window_surfaces.get_mut(&window_id).unwrap();

let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if *recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
9 changes: 9 additions & 0 deletions examples/src/bin/multi_window_game_of_life/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ fn compute_then_render(
life_color: [f32; 4],
dead_color: [f32; 4],
) {
// Skip this window when minimized
match vulkano_window.window_size() {
[w, h] => {
if w == 0 || h == 0 {
return;
}
}
}

// Start frame
let before_pipeline_future = match vulkano_window.start_frame() {
Err(e) => {
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/occlusion-query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/push-descriptors/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/runtime-shader/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/runtime_array/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
4 changes: 2 additions & 2 deletions examples/src/bin/simple-particles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ fn main() {
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 && dimensions.height == 0 {
return; // On Windows, minimizing sets surface to 0x0. Do not draw frame.
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

// Update per-frame variables.
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/teapot/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,17 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) =
match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/tessellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,11 +349,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
7 changes: 6 additions & 1 deletion examples/src/bin/texture_array/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,16 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

previous_frame_end.as_mut().unwrap().cleanup_finished();

if recreate_swapchain {
let (new_swapchain, new_images) = match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
11 changes: 9 additions & 2 deletions examples/src/bin/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ fn main() {
recreate_swapchain = true;
}
Event::RedrawEventsCleared => {
// Do not draw frame when screen dimensions are zero.
// On Windows, this can occur from minimizing the application.
let dimensions = surface.window().inner_size();
if dimensions.width == 0 || dimensions.height == 0 {
return;
}

// It is important to call this function from time to time, otherwise resources will keep
// accumulating and you will eventually reach an out of memory error.
// Calling this function polls various fences in order to determine what the GPU has
Expand All @@ -425,11 +432,11 @@ fn main() {
// 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.
if recreate_swapchain {
// Get the new dimensions of the window.
// Use the new dimensions of the window.

let (new_swapchain, new_images) =
match swapchain.recreate(SwapchainCreateInfo {
image_extent: surface.window().inner_size().into(),
image_extent: dimensions.into(),
..swapchain.create_info()
}) {
Ok(r) => r,
Expand Down
Loading

0 comments on commit a893590

Please # to comment.