mirror of
https://github.com/emilk/egui.git
synced 2026-09-02 06:40:06 -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:
@@ -142,7 +142,7 @@ impl Painter {
|
||||
fn configure_surface(
|
||||
surface_state: &SurfaceState,
|
||||
render_state: &RenderState,
|
||||
present_mode: wgpu::PresentMode,
|
||||
config: &WgpuConfiguration,
|
||||
) {
|
||||
crate::profile_function!();
|
||||
|
||||
@@ -155,21 +155,25 @@ impl Painter {
|
||||
let width = surface_state.width;
|
||||
let height = surface_state.height;
|
||||
|
||||
surface_state.surface.configure(
|
||||
&render_state.device,
|
||||
&wgpu::SurfaceConfiguration {
|
||||
// TODO(emilk): expose `desired_maximum_frame_latency` to eframe users
|
||||
usage,
|
||||
format: render_state.target_format,
|
||||
present_mode,
|
||||
alpha_mode: surface_state.alpha_mode,
|
||||
view_formats: vec![render_state.target_format],
|
||||
..surface_state
|
||||
.surface
|
||||
.get_default_config(&render_state.adapter, width, height)
|
||||
.expect("The surface isn't supported by this adapter")
|
||||
},
|
||||
);
|
||||
let mut surf_config = wgpu::SurfaceConfiguration {
|
||||
usage,
|
||||
format: render_state.target_format,
|
||||
present_mode: config.present_mode,
|
||||
alpha_mode: surface_state.alpha_mode,
|
||||
view_formats: vec![render_state.target_format],
|
||||
..surface_state
|
||||
.surface
|
||||
.get_default_config(&render_state.adapter, width, height)
|
||||
.expect("The surface isn't supported by this adapter")
|
||||
};
|
||||
|
||||
if let Some(desired_maximum_frame_latency) = config.desired_maximum_frame_latency {
|
||||
surf_config.desired_maximum_frame_latency = desired_maximum_frame_latency;
|
||||
}
|
||||
|
||||
surface_state
|
||||
.surface
|
||||
.configure(&render_state.device, &surf_config);
|
||||
}
|
||||
|
||||
/// Updates (or clears) the [`winit::window::Window`] associated with the [`Painter`]
|
||||
@@ -328,7 +332,7 @@ impl Painter {
|
||||
surface_state.width = width;
|
||||
surface_state.height = height;
|
||||
|
||||
Self::configure_surface(surface_state, render_state, self.configuration.present_mode);
|
||||
Self::configure_surface(surface_state, render_state, &self.configuration);
|
||||
|
||||
if let Some(depth_format) = self.depth_format {
|
||||
self.depth_texture_view.insert(
|
||||
@@ -525,11 +529,7 @@ impl Painter {
|
||||
Ok(frame) => frame,
|
||||
Err(err) => match (*self.configuration.on_surface_error)(err) {
|
||||
SurfaceErrorAction::RecreateSurface => {
|
||||
Self::configure_surface(
|
||||
surface_state,
|
||||
render_state,
|
||||
self.configuration.present_mode,
|
||||
);
|
||||
Self::configure_surface(surface_state, render_state, &self.configuration);
|
||||
return None;
|
||||
}
|
||||
SurfaceErrorAction::SkipFrame => {
|
||||
|
||||
Reference in New Issue
Block a user