[Fix] (Espryt): redeclare clip/cull distance outputs inside gl_PerVertex for ESSL

This commit is contained in:
2026-10-12 03:55:46 -04:00
parent b4f35cd67d
commit 2a1920adce
4 changed files with 298 additions and 0 deletions
@@ -12079,6 +12079,9 @@ namespace MobileGL::MG_Backend::DirectGLES {
? PointSizeExtensionName(g_GLESCapabilities.TessellationPointSizeSupport, /*tessellation=*/true)
: nullptr;
source = RequestPointSizeExtension(Move(source), passthroughPointSizeExtension);
// Same for gl_ClipDistance/gl_CullDistance mirrored out of a vertex stage that
// writes them: the neighbour could only compile with the extension, so it exists.
source = RequestClipCullDistanceExtension(Move(source));
const GLuint backendShaderId = g_GLESFuncs.glCreateShader(GL_TESS_CONTROL_SHADER);
if (backendShaderId == 0) {
@@ -12636,6 +12639,14 @@ namespace MobileGL::MG_Backend::DirectGLES {
stageAtomicCounterGlBindings.begin(),
stageAtomicCounterGlBindings.end());
// SPIRV-Cross sizes written clip/cull distances with a standalone
// `out float gl_ClipDistance[N];`, which an ES compiler may refuse as a reserved
// name and so lose the whole program. Redeclared as gl_PerVertex members instead.
// BEFORE the gl_PointSize extension probe below (the block can name it) and
// before vertexStageEssl is captured, so a synthesized pass-through control
// stage mirrors the block this produces.
source = RedeclareClipCullDistancesInPerVertexBlock(std::move(source), glShaderType);
// Position in the chain is arbitrary: this is the only header-level rewrite, it
// edits #extension directives and never the body, and the replacement is the
// same length and stays an #extension line - so it commutes with every pass