Skip to content

Commit

Permalink
examples: Call pre_present_notify before presenting (#7074)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
kjarosh authored Feb 10, 2025
1 parent e5e7138 commit 43eb6c9
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/features/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions examples/features/src/hello_triangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions examples/features/src/hello_windows/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
3 changes: 2 additions & 1 deletion examples/features/src/uniform_values/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
_ => {}
Expand Down
1 change: 1 addition & 0 deletions examples/standalone/02_hello_window/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 43eb6c9

Please sign in to comment.