From 21b978e1dfa0b87e739d6c9e7eb6296e0cb32e75 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Fri, 17 Jul 2026 23:39:13 +1000 Subject: [PATCH] [client] egl: avoid per-frame DMABUF flushes Only fence and flush when initially attaching an EGLImage. Subsequent imports rely on framebuffer write completion, avoiding periodic driver stalls. --- client/renderers/EGL/texture_dmabuf.c | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/client/renderers/EGL/texture_dmabuf.c b/client/renderers/EGL/texture_dmabuf.c index 20cb6076..17def22b 100644 --- a/client/renderers/EGL/texture_dmabuf.c +++ b/client/renderers/EGL/texture_dmabuf.c @@ -247,6 +247,7 @@ static bool egl_texDMABUFUpdate(EGL_Texture * texture, int slot = (fdImage == &this->images[0]) ? 0 : 1; fdImage->texIndex = slot; + GLsync sync = 0; INTERLOCKED_SECTION(parent->copyLock, { egl_stateBindTexture(0, GL_TEXTURE_EXTERNAL_OES, parent->tex[slot]); @@ -256,29 +257,28 @@ static bool egl_texDMABUFUpdate(EGL_Texture * texture, glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR); g_egl_dynProcs.glEGLImageTargetTexture2DOES( GL_TEXTURE_EXTERNAL_OES, image); + + sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); + fdImage->sync = sync; }); + + if (unlikely(!sync)) + { + DEBUG_GL_ERROR("Failed to create DMABUF sync"); + return false; + } + + /* Publish the texture attachment to the shared render context once. The + * backing memory is synchronized separately by framebuffer_wait(), so + * subsequent frames do not add any GL commands to this context. */ + glFlush(); } - GLsync sync = 0; INTERLOCKED_SECTION(parent->copyLock, { - if (fdImage->sync) - glDeleteSync(fdImage->sync); - sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); - fdImage->sync = sync; this->lastIndex = (fdImage == &this->images[0]) ? 0 : 1; }); - if (unlikely(!sync)) - { - DEBUG_GL_ERROR("Failed to create DMABUF sync"); - return false; - } - - /* The fence is consumed by the shared render context. Submit it from the - * frame context now so the render context can wait without blocking the CPU. */ - glFlush(); - return true; }