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).
This commit is contained in:
Kamil Jarosz authored and GitHub committed 2025-02-10 08:19:54 +00:00
1 parent e5e7138169
commit 43eb6c99b0
6 files changed
+10 -1

No files matched your search

+4
View File
@@ -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
+1
View File
@@ -438,6 +438,7 @@ async fn start<E: Example>(title: &str) {
.unwrap()
.render(&view, &context.device, &context.queue);
window_loop.window.pre_present_notify();
frame.present();
window_loop.window.request_redraw();
@@ -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(),
@@ -137,6 +137,7 @@ async fn run(event_loop: EventLoop<()>, viewports: Vec<(Arc<Window>, wgpu::Color
}
queue.submit(Some(encoder.finish()));
viewport.desc.window.pre_present_notify();
frame.present();
}
}
+2 -1
View File
@@ -217,7 +217,7 @@ impl WgpuContext {
}
async fn run(event_loop: EventLoop<()>, window: Arc<Window>) {
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<Window>) {
render_pass.draw(0..3, 0..1);
}
wgpu_context_ref.queue.submit(Some(encoder.finish()));
window.pre_present_notify();
frame.present();
}
_ => {}
@@ -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();
}
}