1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-03 15:20:05 -04:00

Add WgpuConfiguration::desired_maximum_frame_latency (#3874)

Setting `desired_maximum_frame_latency` to a low value should
theoretically lead to lower latency in winit apps using `egui-wgpu`
(e.g. in `eframe` with `wgpu` backend).

* Replaces https://github.com/emilk/egui/pull/3714
* See also https://github.com/gfx-rs/wgpu/pull/4899

----

It seems like `desired_maximum_frame_latency` has no effect on my Mac. I
lowered my monitor refresh-rate to 30Hz to test, and can see no
difference between `desired_maximum_frame_latency` of `0` or `3`.

Before when experimenting with changing the global `DESIRED_NUM_FRAMES`
in `wgpu` I saw a huge difference, so I wonder what has changed.

I verified that `set_maximum_drawable_count` is being called with either
`1` or `2`, but I perceive no difference between the two.
This commit is contained in:
Emil Ernerfeldt
2024-01-24 09:36:17 +01:00
committed by GitHub
parent 11c89125f7
commit 4d1a736016
4 changed files with 51 additions and 28 deletions

View File

@@ -228,6 +228,15 @@ pub struct WgpuConfiguration {
/// Present mode used for the primary surface.
pub present_mode: wgpu::PresentMode,
/// Desired maximum number of frames that the presentation engine should queue in advance.
///
/// Use `1` for low-latency, and `2` for high-throughput.
///
/// See [`wgpu::SurfaceConfiguration::desired_maximum_frame_latency`] for details.
///
/// `None` = `wgpu` default.
pub desired_maximum_frame_latency: Option<u32>,
/// Power preference for the adapter.
pub power_preference: wgpu::PowerPreference,
@@ -237,10 +246,22 @@ pub struct WgpuConfiguration {
impl std::fmt::Debug for WgpuConfiguration {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self {
supported_backends,
device_descriptor: _,
present_mode,
desired_maximum_frame_latency,
power_preference,
on_surface_error: _,
} = self;
f.debug_struct("WgpuConfiguration")
.field("supported_backends", &self.supported_backends)
.field("present_mode", &self.present_mode)
.field("power_preference", &self.power_preference)
.field("supported_backends", &supported_backends)
.field("present_mode", &present_mode)
.field(
"desired_maximum_frame_latency",
&desired_maximum_frame_latency,
)
.field("power_preference", &power_preference)
.finish_non_exhaustive()
}
}
@@ -274,6 +295,8 @@ impl Default for WgpuConfiguration {
present_mode: wgpu::PresentMode::AutoVsync,
desired_maximum_frame_latency: None,
power_preference: wgpu::util::power_preference_from_env()
.unwrap_or(wgpu::PowerPreference::HighPerformance),