Merge pull request #275 from cmeissl/renderer/v4-workaround-delayed-rendering

Workaround for screen flickering on drm/kms
This commit is contained in:
Victor Brekenfeld 2021-05-21 17:26:33 +02:00 committed by GitHub
commit a9209c7ae0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -1069,6 +1069,21 @@ impl Renderer for Gles2Renderer {
self.make_current()?; self.make_current()?;
unsafe { unsafe {
self.gl.Flush(); self.gl.Flush();
// We need to wait for the previously submitted GL commands to complete
// or otherwise the buffer could be submitted to the drm surface while
// still writing to the buffer which results in flickering on the screen.
// The proper solution would be to create a fence just before calling
// glFlush that the backend can use to wait for the commands to be finished.
// In case of a drm atomic backend the fence could be supplied by using the
// IN_FENCE_FD property.
// See https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-kms.html#explicit-fencing-properties for
// the topic on submitting a IN_FENCE_FD and the mesa kmskube example
// https://gitlab.freedesktop.org/mesa/kmscube/-/blob/9f63f359fab1b5d8e862508e4e51c9dfe339ccb0/drm-atomic.c
// especially here
// https://gitlab.freedesktop.org/mesa/kmscube/-/blob/9f63f359fab1b5d8e862508e4e51c9dfe339ccb0/drm-atomic.c#L147
// and here
// https://gitlab.freedesktop.org/mesa/kmscube/-/blob/9f63f359fab1b5d8e862508e4e51c9dfe339ccb0/drm-atomic.c#L235
self.gl.Finish();
self.gl.Disable(ffi::BLEND); self.gl.Disable(ffi::BLEND);
} }