Skip to content

Commit

Permalink
vello_editor: Use PresentMode::Mailbox when available. (#144)
Browse files Browse the repository at this point in the history
AutoVsync/FIFO introduces unnecessary latency, especially on X11. There
aren't animations in vello_editor so the downside (extra work) is not
significant.
  • Loading branch information
xorgy authored Oct 23, 2024
1 parent 03dc361 commit 91b47a3
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions examples/vello_editor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,43 @@ impl ApplicationHandler for SimpleVelloApp<'_> {
.take()
.unwrap_or_else(|| create_winit_window(event_loop));

// Create a vello Surface
let size = window.inner_size();
let surface_future = self.context.create_surface(
window.clone(),
size.width,
size.height,
wgpu::PresentMode::AutoVsync,
);
let surface = pollster::block_on(surface_future).expect("Error creating surface");

self.editor.transact([
PlainEditorOp::SetScale(1.0),
PlainEditorOp::SetWidth(Some(size.width as f32 - 2f32 * text::INSET)),
PlainEditorOp::SetText(text::LOREM.into()),
]);

// Create a vello Surface
let surface_future = {
let surface = self
.context
.instance
.create_surface(wgpu::SurfaceTarget::from(window.clone()))
.expect("Error creating surface");
let dev_id = pollster::block_on(self.context.device(Some(&surface)))
.expect("No compatible device");
let device_handle = &self.context.devices[dev_id];
let capabilities = surface.get_capabilities(device_handle.adapter());
let present_mode = if capabilities
.present_modes
.contains(&wgpu::PresentMode::Mailbox)
{
wgpu::PresentMode::Mailbox
} else {
wgpu::PresentMode::AutoVsync
};

self.context
.create_render_surface(surface, size.width, size.height, present_mode)
};
let surface = pollster::block_on(surface_future).expect("Error creating surface");

// Create a vello Renderer for the surface (using its device id)
self.renderers
.resize_with(self.context.devices.len(), || None);

self.renderers[surface.dev_id]
.get_or_insert_with(|| create_vello_renderer(&self.context, &surface));

Expand Down

0 comments on commit 91b47a3

Please sign in to comment.