From 1994a2ea2d8723a884341239e5b28ae854c16bbe Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 21 Mar 2021 10:28:17 -0700 Subject: [PATCH] gui: improve vertex buffer map/write/release performance Switches from using a dynamic vertex buffer to an immutable vertex buffer. This feels counter-intuitive to me; the purpose of dynamic is to sustain frequent updates, but mapping the buffer needs to synchronize with the GPU, and if we are rapidly invalidating the window that can stall painting by tens of milliseconds. Switching to an immutable buffer avoids the stall and makes quad mapping more consistently < 10ms, but its still not ideal. refs: https://github.com/wez/wezterm/issues/546 --- wezterm-gui/src/renderstate.rs | 2 +- wezterm-gui/src/termwindow/render.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/wezterm-gui/src/renderstate.rs b/wezterm-gui/src/renderstate.rs index 97caf6dee..e350a4c3f 100644 --- a/wezterm-gui/src/renderstate.rs +++ b/wezterm-gui/src/renderstate.rs @@ -286,7 +286,7 @@ impl RenderState { quads.scroll_thumb = define_quad(0.0, 0.0, 0.0, 0.0) as usize; Ok(( - VertexBuffer::dynamic(context, &verts)?, + VertexBuffer::immutable(context, &verts)?, IndexBuffer::new( context, glium::index::PrimitiveType::TrianglesList, diff --git a/wezterm-gui/src/termwindow/render.rs b/wezterm-gui/src/termwindow/render.rs index d8bf46554..10a29fa09 100644 --- a/wezterm-gui/src/termwindow/render.rs +++ b/wezterm-gui/src/termwindow/render.rs @@ -167,7 +167,10 @@ impl super::TermWindow { let gl_state = self.render_state.as_ref().unwrap(); let mut vb = gl_state.glyph_vertex_buffer.borrow_mut(); + + let start = Instant::now(); let mut quads = gl_state.quads.map(&mut vb); + log::trace!("quad map elapsed {:?}", start.elapsed()); let cursor_border_color = rgbcolor_to_window_color(palette.cursor_border); let foreground = rgbcolor_to_window_color(palette.foreground); @@ -299,6 +302,10 @@ impl super::TermWindow { )?; } + let start = Instant::now(); + drop(quads); + log::trace!("quad drop elapsed {:?}", start.elapsed()); + Ok(()) }