Call glFinish right after swap_buffers on X11

On X11 `swap_buffers` does not block for vsync. However the next OpenGl command
will block to synchronize (this is `glClear` in Alacritty), which causes a
permanent one frame delay.

Calling `glFinish` after swapping buffers forces Alacritty to finish the buffer
swap before returning control to the event loop.

Fixes #3061.
This commit is contained in:
Kirill Chibisov 2020-05-01 23:57:25 +03:00 committed by GitHub
parent 6b45780f3a
commit 38d20d0c39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 2 deletions

View File

@ -30,6 +30,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Tabstops not being reset with `reset`
- Selection not cleared when switching between main and alt grid
- Fallback to `LC_CTYPE=UTF-8` on macOS without valid system locale
- Resize lag on launch under some X11 wms
- Increased input latency due to vsync behavior on X11
## 0.4.2

View File

@ -118,6 +118,8 @@ pub struct Display {
renderer: QuadRenderer,
glyph_cache: GlyphCache,
meter: Meter,
#[cfg(not(any(target_os = "macos", windows)))]
is_x11: bool,
}
impl Display {
@ -198,14 +200,20 @@ impl Display {
api.clear(background_color);
});
#[cfg(not(any(target_os = "macos", windows)))]
let is_x11 = event_loop.is_x11();
// We should call `clear` when window is offscreen, so when `window.show()` happens it
// would be with background color instead of uninitialized surface.
#[cfg(not(any(target_os = "macos", windows)))]
{
// On Wayland we can safely ignore this call, since the window isn't visible until you
// actually draw something into it.
if event_loop.is_x11() {
window.swap_buffers()
if is_x11 {
window.swap_buffers();
renderer.with_api(&config, &size_info, |api| {
api.finish();
});
}
}
@ -237,6 +245,8 @@ impl Display {
size_info,
urls: Urls::new(),
highlighted_url: None,
#[cfg(not(any(target_os = "macos", windows)))]
is_x11,
})
}
@ -499,6 +509,18 @@ impl Display {
}
self.window.swap_buffers();
#[cfg(not(any(target_os = "macos", windows)))]
{
if self.is_x11 {
// On X11 `swap_buffers` does not block for vsync. However the next OpenGl command
// will block to synchronize (this is `glClear` in Alacritty), which causes a
// permanent one frame delay.
self.renderer.with_api(&config, &size_info, |api| {
api.finish();
});
}
}
}
}

View File

@ -923,6 +923,12 @@ impl<'a, C> RenderApi<'a, C> {
}
}
pub fn finish(&self) {
unsafe {
gl::Finish();
}
}
fn render_batch(&mut self) {
unsafe {
gl::BufferSubData(