Skip to content

Commit

Permalink
Make desired_maximum_frame_latency an Option
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 23, 2024
1 parent 2bb7b30 commit ba4d188
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
6 changes: 4 additions & 2 deletions crates/egui-wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ pub struct WgpuConfiguration {
/// Use `1` for low-latency, and `2` for high-throughput.
///
/// See [`wgpu::SurfaceConfiguration::desired_num_frames`] for details.
pub desired_maximum_frame_latency: u32,
///
/// `None` = `wgpu` default.
pub desired_maximum_frame_latency: Option<u32>,

/// Power preference for the adapter.
pub power_preference: wgpu::PowerPreference,
Expand Down Expand Up @@ -293,7 +295,7 @@ impl Default for WgpuConfiguration {

present_mode: wgpu::PresentMode::AutoVsync,

desired_maximum_frame_latency: 1, // 1 = low-latency; good for GUIs.
desired_maximum_frame_latency: None,

power_preference: wgpu::util::power_preference_from_env()
.unwrap_or(wgpu::PowerPreference::HighPerformance),
Expand Down
34 changes: 19 additions & 15 deletions crates/egui-wgpu/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
usage,
format: render_state.target_format,
present_mode: config.present_mode,
desired_maximum_frame_latency: config.desired_maximum_frame_latency,
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`]
Expand Down

0 comments on commit ba4d188

Please sign in to comment.