From a87c93bf0b2c3a0001e1c795056836ee866b50f6 Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 24 Aug 2026 20:17:37 +0100 Subject: [PATCH] Add ultra dirty specific hack to work around mesa following GL spec * The GL spec is absolutely and maliciously unhinged and the queried stencil value will be clamped to 0 if no stencil texture is currently bound. This of course will break in so many different places that will never get fixed, but this minimal change at least allows autotests to run on mesa. --- renderdoc/driver/gl/gl_overlay.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/renderdoc/driver/gl/gl_overlay.cpp b/renderdoc/driver/gl/gl_overlay.cpp index cf03c03a5..7f32ac6dd 100644 --- a/renderdoc/driver/gl/gl_overlay.cpp +++ b/renderdoc/driver/gl/gl_overlay.cpp @@ -2162,6 +2162,18 @@ ResourceId GLReplay::RenderOverlay(ResourceId texid, FloatVector clearCol, Debug eGL_CLAMP_TO_EDGE); drv.glFramebufferTextureLayer(eGL_FRAMEBUFFER, dsAttach, overridedepth, 0, 0); + + // this is a MEGA hack for mesa's behaviour - which is spec compliant. The problem is that + // the spec is absolutely stupid. When we called CopyTex2DMSToArray() above the + // framebuffer might have been incomplete since we hadn't bound this overridedepth here + // that we are setting up. This means that the effective stencil bits available in the FBO + // is 0, and mesa then clamps the query of the current stencil reference to 0. The render + // state push + pop inside CopyTex2DMSToArray then doesn't function correctly as it leaves + // the reference at 0 instead of whatever it should be - so we reset it here + GL.glStencilFuncSeparate(eGL_FRONT, rs.StencilFront.func, rs.StencilFront.ref, + rs.StencilFront.valuemask); + GL.glStencilFuncSeparate(eGL_BACK, rs.StencilBack.func, rs.StencilBack.ref, + rs.StencilBack.valuemask); } drv.glBindFramebuffer(eGL_DRAW_FRAMEBUFFER, curdrawfbo);