diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp index 75828189cd..787ff9f75b 100644 --- a/src/compiler/translator/ParseContext.cpp +++ b/src/compiler/translator/ParseContext.cpp @@ -7087,6 +7087,22 @@ TIntermTyped *TParseContext::addIndexExpression(TIntermTyped *baseExpression, "[]"); safeIndex = 0; } + // When EXT_blend_func_extended is enabled, gl_FragData (and its + // backend replacement webgl_FragData) is sized to + // MaxDualSourceDrawBuffers, not MaxDrawBuffers (see + // EmulateFragColorData / TranslatorGLSL). Enforce that bound here so + // we never emit an OOB constant index into the shrunk array to the + // native driver. + else if (isExtensionEnabled(TExtension::EXT_blend_func_extended) && + index >= mResources.MaxDualSourceDrawBuffers) + { + outOfRangeError(outOfRangeIndexIsError, location, + "array index for gl_FragData must be less than " + "GL_MAX_DUAL_SOURCE_DRAW_BUFFERS_EXT when " + "GL_EXT_blend_func_extended is enabled", + "[]"); + safeIndex = mResources.MaxDualSourceDrawBuffers - 1; + } } } // Only do generic out-of-range check if similar error hasn't already been reported.