Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay call to get_current_texture (possible small performance win) #3914

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions crates/egui-wgpu/src/winit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,25 +519,6 @@ impl Painter {
let render_state = self.render_state.as_mut()?;
let surface_state = self.surfaces.get(&viewport_id)?;

let output_frame = {
crate::profile_scope!("get_current_texture");
// This is what vsync-waiting happens, at least on Mac.
surface_state.surface.get_current_texture()
};

let output_frame = match output_frame {
Ok(frame) => frame,
Err(err) => match (*self.configuration.on_surface_error)(err) {
SurfaceErrorAction::RecreateSurface => {
Self::configure_surface(surface_state, render_state, &self.configuration);
return None;
}
SurfaceErrorAction::SkipFrame => {
return None;
}
},
};

let mut encoder =
render_state
.device
Expand Down Expand Up @@ -580,6 +561,25 @@ impl Painter {
}
};

let output_frame = {
crate::profile_scope!("get_current_texture");
// This is what vsync-waiting happens everywhere except DX12
surface_state.surface.get_current_texture()
};

let output_frame = match output_frame {
Ok(frame) => frame,
Err(err) => match (*self.configuration.on_surface_error)(err) {
SurfaceErrorAction::RecreateSurface => {
Self::configure_surface(surface_state, render_state, &self.configuration);
return None;
}
SurfaceErrorAction::SkipFrame => {
return None;
}
},
};

{
let renderer = render_state.renderer.read();
let frame_view = if capture {
Expand Down Expand Up @@ -668,6 +668,7 @@ impl Painter {

{
crate::profile_scope!("present");
// This is where vsync happens in DX12
emilk marked this conversation as resolved.
Show resolved Hide resolved
output_frame.present();
}
screenshot
Expand Down
Loading