mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 14:49:06 -04:00
Configure wgpu to be low-latency by default (#8203)
* initially done in https://github.com/emilk/egui/pull/8103, reverted in #8167 due to resize hangs * Related: https://github.com/emilk/egui/issues/8043 (maybe closes??) Turns out the resize hangs were caused by the present_with_transaction call. Disabling that when `desired_maximum_frame_latency == 1` causes the window to resize smoothly. Thanks @krisdigital for noticing that connection: https://github.com/emilk/egui/issues/8043#issuecomment-4154440382 --------- Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
This commit is contained in:
@@ -87,13 +87,10 @@ impl SurfaceConfig {
|
|||||||
pub const LOW_LATENCY: Self = Self {
|
pub const LOW_LATENCY: Self = Self {
|
||||||
present_mode: wgpu::PresentMode::AutoVsync,
|
present_mode: wgpu::PresentMode::AutoVsync,
|
||||||
|
|
||||||
#[expect(clippy::branches_sharing_code)]
|
|
||||||
desired_maximum_frame_latency: if cfg!(target_os = "ios") {
|
desired_maximum_frame_latency: if cfg!(target_os = "ios") {
|
||||||
None // The default is good on iOS, while `Some(1)` cuts FPS in half
|
None // The default is good on iOS, while `Some(1)` cuts FPS in half
|
||||||
} else {
|
} else {
|
||||||
// TODO(emilk): We would like yo use `Some(1)` here, but
|
Some(1)
|
||||||
// that causes bugs when resizing the window on macOS.
|
|
||||||
None
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -414,20 +414,27 @@ impl Painter {
|
|||||||
// See https://github.com/emilk/egui/issues/903
|
// See https://github.com/emilk/egui/issues/903
|
||||||
#[cfg(all(target_os = "macos", feature = "macos-window-resize-jitter-fix"))]
|
#[cfg(all(target_os = "macos", feature = "macos-window-resize-jitter-fix"))]
|
||||||
{
|
{
|
||||||
// SAFETY: The cast is checked with if condition. If the used backend is not metal
|
// setPresentsWithTransaction causes hangs when desired_maximum_frame_latency == 1
|
||||||
// it gracefully fails.
|
let is_low_latency = self
|
||||||
unsafe {
|
.render_state
|
||||||
if let Some(hal_surface) = state.surface.as_hal::<wgpu::hal::api::Metal>() {
|
.as_ref()
|
||||||
hal_surface
|
.is_some_and(|rs| rs.surface_config.desired_maximum_frame_latency == Some(1));
|
||||||
.render_layer()
|
if !is_low_latency {
|
||||||
.lock()
|
// SAFETY: The cast is checked with if condition. If the used backend is not metal
|
||||||
.setPresentsWithTransaction(resizing);
|
// it gracefully fails.
|
||||||
|
unsafe {
|
||||||
|
if let Some(hal_surface) = state.surface.as_hal::<wgpu::hal::api::Metal>() {
|
||||||
|
hal_surface
|
||||||
|
.render_layer()
|
||||||
|
.lock()
|
||||||
|
.setPresentsWithTransaction(resizing);
|
||||||
|
|
||||||
Self::configure_surface(
|
Self::configure_surface(
|
||||||
state,
|
state,
|
||||||
self.render_state.as_ref().unwrap(),
|
self.render_state.as_ref().unwrap(),
|
||||||
&self.config.surface,
|
&self.config.surface,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user