diff --git a/src/libANGLE/renderer/d3d/ProgramExecutableD3D.cpp b/src/libANGLE/renderer/d3d/ProgramExecutableD3D.cpp index 5d545a61bf..1a23e849db 100644 --- a/src/libANGLE/renderer/d3d/ProgramExecutableD3D.cpp +++ b/src/libANGLE/renderer/d3d/ProgramExecutableD3D.cpp @@ -1809,6 +1809,18 @@ void ProgramExecutableD3D::defineUniformBase(gl::ShaderType shaderType, } const SharedCompiledShaderStateD3D &shaderD3D = mAttachedShaders[shaderType]; + if (!shaderD3D->hasUniform(uniform.name)) + { + // The translator can mark a uniform active (CollectVariables) and then + // drop its only reference in a later HLSL-only pass (e.g. + // SeparateArrayConstructorStatements), leaving it absent from + // uniformRegisterMap. Mirror the sampler path and skip it instead of + // dereferencing end()->second in getUniformRegister(). + UniformEncodingVisitorD3D visitor(shaderType, HLSLRegisterType::None, &stubEncoder, + uniformMap); + sh::TraverseShaderVariable(uniform, false, &visitor); + return; + } unsigned int startRegister = shaderD3D->getUniformRegister(uniform.name); ShShaderOutput outputType = shaderD3D->compilerOutputType; sh::HLSLBlockEncoder encoder(sh::HLSLBlockEncoder::GetStrategyFor(outputType), true); diff --git a/src/libANGLE/renderer/d3d/ShaderD3D.cpp b/src/libANGLE/renderer/d3d/ShaderD3D.cpp index 67d573d777..d95597ccfc 100644 --- a/src/libANGLE/renderer/d3d/ShaderD3D.cpp +++ b/src/libANGLE/renderer/d3d/ShaderD3D.cpp @@ -230,8 +230,16 @@ void CompiledShaderStateD3D::generateWorkarounds(CompilerWorkaroundsD3D *workaro unsigned int CompiledShaderStateD3D::getUniformRegister(const std::string &uniformName) const { - ASSERT(uniformRegisterMap.count(uniformName) > 0); - return uniformRegisterMap.find(uniformName)->second; + auto it = uniformRegisterMap.find(uniformName); + ASSERT(it != uniformRegisterMap.end()); + if (it == uniformRegisterMap.end()) + { + // Defensive: callers are expected to gate on hasUniform(), but if they + // don't, returning GL_INVALID_INDEX keeps isReferencedByShader() false + // instead of letting end()->second flow into register-index arithmetic. + return GL_INVALID_INDEX; + } + return it->second; } unsigned int CompiledShaderStateD3D::getUniformBlockRegister(const std::string &blockName) const