From 43eb6c99b047ff811f0b050b6ceddb1856683b4b Mon Sep 17 00:00:00 2001 From: Kamil Jarosz Date: Mon, 10 Feb 2025 09:19:54 +0100 Subject: [PATCH] examples: Call pre_present_notify before presenting (#7074) According to winit docs, pre_present_notify() should be called right before calling present(). This actually prevents some issues on Wayland, like freezing the whole application when the window is not visible (ask me how I know). --- CHANGELOG.md | 4 ++++ examples/features/src/framework.rs | 1 + examples/features/src/hello_triangle/mod.rs | 1 + examples/features/src/hello_windows/mod.rs | 1 + examples/features/src/uniform_values/mod.rs | 3 ++- examples/standalone/02_hello_window/src/main.rs | 1 + 6 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0eb50318..c9391b2b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -112,6 +112,10 @@ By @brodycj in [#6924](https://github.com/gfx-rs/wgpu/pull/6924). - Added a hello window example. By @laycookie in [#6992](https://github.com/gfx-rs/wgpu/pull/6992). +### Examples + +- Call `pre_present_notify()` before presenting. By @kjarosh in [#7074](https://github.com/gfx-rs/wgpu/pull/7074). + ## v24.0.0 (2025-01-15) ### Major changes diff --git a/examples/features/src/framework.rs b/examples/features/src/framework.rs index 927a5fe12..be113f7aa 100644 --- a/examples/features/src/framework.rs +++ b/examples/features/src/framework.rs @@ -438,6 +438,7 @@ async fn start(title: &str) { .unwrap() .render(&view, &context.device, &context.queue); + window_loop.window.pre_present_notify(); frame.present(); window_loop.window.request_redraw(); diff --git a/examples/features/src/hello_triangle/mod.rs b/examples/features/src/hello_triangle/mod.rs index 935f353e4..cc65c3a89 100644 --- a/examples/features/src/hello_triangle/mod.rs +++ b/examples/features/src/hello_triangle/mod.rs @@ -135,6 +135,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { } queue.submit(Some(encoder.finish())); + window.pre_present_notify(); frame.present(); } WindowEvent::CloseRequested => target.exit(), diff --git a/examples/features/src/hello_windows/mod.rs b/examples/features/src/hello_windows/mod.rs index b568f35d3..d4aa994ab 100644 --- a/examples/features/src/hello_windows/mod.rs +++ b/examples/features/src/hello_windows/mod.rs @@ -137,6 +137,7 @@ async fn run(event_loop: EventLoop<()>, viewports: Vec<(Arc, wgpu::Color } queue.submit(Some(encoder.finish())); + viewport.desc.window.pre_present_notify(); frame.present(); } } diff --git a/examples/features/src/uniform_values/mod.rs b/examples/features/src/uniform_values/mod.rs index 8e9f7d14a..72bac0fa5 100644 --- a/examples/features/src/uniform_values/mod.rs +++ b/examples/features/src/uniform_values/mod.rs @@ -217,7 +217,7 @@ impl WgpuContext { } async fn run(event_loop: EventLoop<()>, window: Arc) { - let mut wgpu_context = Some(WgpuContext::new(window).await); + let mut wgpu_context = Some(WgpuContext::new(window.clone()).await); // (6) let mut state = Some(AppState::default()); let main_window_id = wgpu_context.as_ref().unwrap().window.id(); @@ -330,6 +330,7 @@ async fn run(event_loop: EventLoop<()>, window: Arc) { render_pass.draw(0..3, 0..1); } wgpu_context_ref.queue.submit(Some(encoder.finish())); + window.pre_present_notify(); frame.present(); } _ => {} diff --git a/examples/standalone/02_hello_window/src/main.rs b/examples/standalone/02_hello_window/src/main.rs index 4385aa5a2..07f90d1fa 100644 --- a/examples/standalone/02_hello_window/src/main.rs +++ b/examples/standalone/02_hello_window/src/main.rs @@ -118,6 +118,7 @@ impl State { // Submit the command in the queue to execute self.queue.submit([encoder.finish()]); + self.window.pre_present_notify(); surface_texture.present(); } }