From b70ebad5bae738aece21f35c334b36f5ef8a9fe2 Mon Sep 17 00:00:00 2001 From: Katt <51190960+coolcatcoder@users.noreply.github.com> Date: Sun, 20 Oct 2024 09:11:15 +0800 Subject: [PATCH 1/5] fix triangle-util and viewport extent docs --- examples/triangle-util/main.rs | 22 ++++++---------------- vulkano/src/pipeline/graphics/viewport.rs | 3 +-- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/examples/triangle-util/main.rs b/examples/triangle-util/main.rs index db297d7101..cc3f55ab3f 100644 --- a/examples/triangle-util/main.rs +++ b/examples/triangle-util/main.rs @@ -62,7 +62,6 @@ struct RenderContext { render_pass: Arc, framebuffers: Vec>, pipeline: Arc, - viewport: Viewport, } impl App { @@ -133,7 +132,6 @@ impl ApplicationHandler for App { self.windows .create_window(event_loop, &self.context, &Default::default(), |_| {}); let window_renderer = self.windows.get_primary_renderer_mut().unwrap(); - let window_size = window_renderer.window().inner_size(); // The next step is to create the shaders. // @@ -315,14 +313,6 @@ impl ApplicationHandler for App { .unwrap() }; - // Dynamic viewports allow us to recreate just the viewport when the window is resized. - // Otherwise we would have to recreate the whole pipeline. - let viewport = Viewport { - offset: [0.0, 0.0], - extent: window_size.into(), - depth_range: 0.0..=1.0, - }; - // In the `window_event` handler below we are going to submit commands to the GPU. // Submitting a command produces an object that implements the `GpuFuture` trait, which // holds the resources for as long as they are in use by the GPU. @@ -331,7 +321,6 @@ impl ApplicationHandler for App { render_pass, framebuffers, pipeline, - viewport, }); } @@ -363,10 +352,8 @@ impl ApplicationHandler for App { // Begin rendering by acquiring the gpu future from the window renderer. let previous_frame_end = window_renderer .acquire(Some(Duration::from_millis(1000)), |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. + // Whenever the swapchain gets recreated, we need to recreate everything dependent upon it. + // In this example, that is only the framebuffers. rcx.framebuffers = window_size_dependent_setup(swapchain_images, &rcx.render_pass); }) @@ -416,7 +403,10 @@ impl ApplicationHandler for App { // We are now inside the first subpass of the render pass. // // TODO: Document state setting and how it affects subsequent draw commands. - .set_viewport(0, [rcx.viewport.clone()].into_iter().collect()) + .set_viewport(0, [Viewport { + extent: window_size.into(), + ..Default::default() + }].into_iter().collect()) .unwrap() .bind_pipeline_graphics(rcx.pipeline.clone()) .unwrap() diff --git a/vulkano/src/pipeline/graphics/viewport.rs b/vulkano/src/pipeline/graphics/viewport.rs index ab12c71bb8..9138a6ef0b 100644 --- a/vulkano/src/pipeline/graphics/viewport.rs +++ b/vulkano/src/pipeline/graphics/viewport.rs @@ -281,8 +281,7 @@ pub struct Viewport { /// Dimensions in pixels of the viewport. /// - /// The default value is `[1.0; 2]`, which you probably want to override if you are not - /// using dynamic state. + /// The default value is `[1.0; 2]`, which you probably want to override. pub extent: [f32; 2], /// Minimum and maximum values of the depth. From 516b11b3ee4916853a4abb71504ea8bf50a9c847 Mon Sep 17 00:00:00 2001 From: Katt <51190960+coolcatcoder@users.noreply.github.com> Date: Sun, 20 Oct 2024 09:15:46 +0800 Subject: [PATCH 2/5] fmt --- examples/triangle-util/main.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/triangle-util/main.rs b/examples/triangle-util/main.rs index cc3f55ab3f..f110f0e667 100644 --- a/examples/triangle-util/main.rs +++ b/examples/triangle-util/main.rs @@ -352,8 +352,9 @@ impl ApplicationHandler for App { // Begin rendering by acquiring the gpu future from the window renderer. let previous_frame_end = window_renderer .acquire(Some(Duration::from_millis(1000)), |swapchain_images| { - // Whenever the swapchain gets recreated, we need to recreate everything dependent upon it. - // In this example, that is only the framebuffers. + // Whenever the swapchain gets recreated, we need to recreate everything + // dependent upon it. In this example, that is only + // the framebuffers. rcx.framebuffers = window_size_dependent_setup(swapchain_images, &rcx.render_pass); }) @@ -403,10 +404,15 @@ impl ApplicationHandler for App { // We are now inside the first subpass of the render pass. // // TODO: Document state setting and how it affects subsequent draw commands. - .set_viewport(0, [Viewport { - extent: window_size.into(), - ..Default::default() - }].into_iter().collect()) + .set_viewport( + 0, + [Viewport { + extent: window_size.into(), + ..Default::default() + }] + .into_iter() + .collect(), + ) .unwrap() .bind_pipeline_graphics(rcx.pipeline.clone()) .unwrap() From ca90b9a16e0bb73ce9a373e057b23935b041d8ce Mon Sep 17 00:00:00 2001 From: Katt <51190960+coolcatcoder@users.noreply.github.com> Date: Sun, 20 Oct 2024 12:57:56 +0800 Subject: [PATCH 3/5] Revert "fmt" This reverts commit 516b11b3ee4916853a4abb71504ea8bf50a9c847. --- examples/triangle-util/main.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/examples/triangle-util/main.rs b/examples/triangle-util/main.rs index f110f0e667..cc3f55ab3f 100644 --- a/examples/triangle-util/main.rs +++ b/examples/triangle-util/main.rs @@ -352,9 +352,8 @@ impl ApplicationHandler for App { // Begin rendering by acquiring the gpu future from the window renderer. let previous_frame_end = window_renderer .acquire(Some(Duration::from_millis(1000)), |swapchain_images| { - // Whenever the swapchain gets recreated, we need to recreate everything - // dependent upon it. In this example, that is only - // the framebuffers. + // Whenever the swapchain gets recreated, we need to recreate everything dependent upon it. + // In this example, that is only the framebuffers. rcx.framebuffers = window_size_dependent_setup(swapchain_images, &rcx.render_pass); }) @@ -404,15 +403,10 @@ impl ApplicationHandler for App { // We are now inside the first subpass of the render pass. // // TODO: Document state setting and how it affects subsequent draw commands. - .set_viewport( - 0, - [Viewport { - extent: window_size.into(), - ..Default::default() - }] - .into_iter() - .collect(), - ) + .set_viewport(0, [Viewport { + extent: window_size.into(), + ..Default::default() + }].into_iter().collect()) .unwrap() .bind_pipeline_graphics(rcx.pipeline.clone()) .unwrap() From aca38d55473678bc866934601d9d76cb17b38214 Mon Sep 17 00:00:00 2001 From: Katt <51190960+coolcatcoder@users.noreply.github.com> Date: Sun, 20 Oct 2024 12:58:03 +0800 Subject: [PATCH 4/5] Revert "fix triangle-util and viewport extent docs" This reverts commit b70ebad5bae738aece21f35c334b36f5ef8a9fe2. --- examples/triangle-util/main.rs | 22 ++++++++++++++++------ vulkano/src/pipeline/graphics/viewport.rs | 3 ++- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/examples/triangle-util/main.rs b/examples/triangle-util/main.rs index cc3f55ab3f..db297d7101 100644 --- a/examples/triangle-util/main.rs +++ b/examples/triangle-util/main.rs @@ -62,6 +62,7 @@ struct RenderContext { render_pass: Arc, framebuffers: Vec>, pipeline: Arc, + viewport: Viewport, } impl App { @@ -132,6 +133,7 @@ impl ApplicationHandler for App { self.windows .create_window(event_loop, &self.context, &Default::default(), |_| {}); let window_renderer = self.windows.get_primary_renderer_mut().unwrap(); + let window_size = window_renderer.window().inner_size(); // The next step is to create the shaders. // @@ -313,6 +315,14 @@ impl ApplicationHandler for App { .unwrap() }; + // Dynamic viewports allow us to recreate just the viewport when the window is resized. + // Otherwise we would have to recreate the whole pipeline. + let viewport = Viewport { + offset: [0.0, 0.0], + extent: window_size.into(), + depth_range: 0.0..=1.0, + }; + // In the `window_event` handler below we are going to submit commands to the GPU. // Submitting a command produces an object that implements the `GpuFuture` trait, which // holds the resources for as long as they are in use by the GPU. @@ -321,6 +331,7 @@ impl ApplicationHandler for App { render_pass, framebuffers, pipeline, + viewport, }); } @@ -352,8 +363,10 @@ impl ApplicationHandler for App { // Begin rendering by acquiring the gpu future from the window renderer. let previous_frame_end = window_renderer .acquire(Some(Duration::from_millis(1000)), |swapchain_images| { - // Whenever the swapchain gets recreated, we need to recreate everything dependent upon it. - // In this example, that is only the framebuffers. + // 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. rcx.framebuffers = window_size_dependent_setup(swapchain_images, &rcx.render_pass); }) @@ -403,10 +416,7 @@ impl ApplicationHandler for App { // We are now inside the first subpass of the render pass. // // TODO: Document state setting and how it affects subsequent draw commands. - .set_viewport(0, [Viewport { - extent: window_size.into(), - ..Default::default() - }].into_iter().collect()) + .set_viewport(0, [rcx.viewport.clone()].into_iter().collect()) .unwrap() .bind_pipeline_graphics(rcx.pipeline.clone()) .unwrap() diff --git a/vulkano/src/pipeline/graphics/viewport.rs b/vulkano/src/pipeline/graphics/viewport.rs index 9138a6ef0b..ab12c71bb8 100644 --- a/vulkano/src/pipeline/graphics/viewport.rs +++ b/vulkano/src/pipeline/graphics/viewport.rs @@ -281,7 +281,8 @@ pub struct Viewport { /// Dimensions in pixels of the viewport. /// - /// The default value is `[1.0; 2]`, which you probably want to override. + /// The default value is `[1.0; 2]`, which you probably want to override if you are not + /// using dynamic state. pub extent: [f32; 2], /// Minimum and maximum values of the depth. From cf7a69580ef10b9dd622db7d7e9b3c82509567d3 Mon Sep 17 00:00:00 2001 From: Katt <51190960+coolcatcoder@users.noreply.github.com> Date: Sun, 20 Oct 2024 13:01:52 +0800 Subject: [PATCH 5/5] Marc's better way. --- examples/triangle-util/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/triangle-util/main.rs b/examples/triangle-util/main.rs index db297d7101..2a566ab957 100644 --- a/examples/triangle-util/main.rs +++ b/examples/triangle-util/main.rs @@ -369,6 +369,7 @@ impl ApplicationHandler for App { // and the dynamic state viewport. rcx.framebuffers = window_size_dependent_setup(swapchain_images, &rcx.render_pass); + rcx.viewport.extent = window_size.into(); }) .unwrap();