From f95a5ec4ce50fba94645d5bc3e66a33b3a90936d Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Fri, 5 Aug 2022 10:50:26 +0200 Subject: [PATCH] rhi: gl: Unify end/finish behavior Issue a glFlush in endOffscreenFrame. This matches endFrame which flushes either implicitly (swapBuffers) or explicitly with SkipPresent (glFlush). This will then benefit producer-consumer setups where a context renders into a texture using begin/endOffscreenFrame and then the texture is consumed in another context. In addition, make finish() issue a glFinish(). Change-Id: I0a3115255ad2ac82b730e26d1ca7e88377c5a28c Reviewed-by: Piotr Srebrny Reviewed-by: Andy Nichols (cherry picked from commit cb139dbdb8d7ff1f9e9be24623697035677c9774) Reviewed-by: Qt Cherry-pick Bot --- src/gui/rhi/qrhigles2.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gui/rhi/qrhigles2.cpp b/src/gui/rhi/qrhigles2.cpp index 2fb6ad13831..074ed65882c 100644 --- a/src/gui/rhi/qrhigles2.cpp +++ b/src/gui/rhi/qrhigles2.cpp @@ -1942,6 +1942,12 @@ QRhi::FrameOpResult QRhiGles2::endOffscreenFrame(QRhi::EndFrameFlags flags) executeCommandBuffer(&ofr.cbWrapper); + // Just as endFrame() does a flush when skipping the swapBuffers(), do it + // here as well. This has the added benefit of playing nice when rendering + // to a texture from a context and then consuming that texture from + // another, sharing context. + f->glFlush(); + return QRhi::FrameOpSuccess; } @@ -1963,6 +1969,12 @@ QRhi::FrameOpResult QRhiGles2::finish() executeCommandBuffer(¤tSwapChain->cb); currentSwapChain->cb.resetCommands(); } + // Do an actual glFinish(). May seem superfluous, but this is what + // matches most other backends e.g. Vulkan/Metal that do a heavyweight + // wait-for-idle blocking in their finish(). More importantly, this + // allows clients simply call finish() in threaded or shared context + // situations where one explicitly needs to do a glFlush or Finish. + f->glFinish(); } return QRhi::FrameOpSuccess; }