Unwritten shader output variables should not crash.
BUG=angle:862
Change-Id: I8e7fa9b0d00bb1b2a32a8d60d8ceda998cea8e8c
Reviewed-on: https://chromium-review.googlesource.com/239160
Tested-by: Gregoire Payen de La Garanderie <Gregory.Payen@imgtec.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/renderer/d3d/DynamicHLSL.cpp b/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
index 215c71f..d64e676 100644
--- a/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
+++ b/src/libANGLE/renderer/d3d/DynamicHLSL.cpp
@@ -72,19 +72,18 @@
return HLSLComponentTypeString(gl::VariableComponentType(type), gl::VariableComponentCount(type));
}
-const PixelShaderOutputVariable &GetOutputAtLocation(const std::vector<PixelShaderOutputVariable> &outputVariables,
+const PixelShaderOutputVariable *FindOutputAtLocation(const std::vector<PixelShaderOutputVariable> &outputVariables,
unsigned int location)
{
for (size_t variableIndex = 0; variableIndex < outputVariables.size(); ++variableIndex)
{
if (outputVariables[variableIndex].outputIndex == location)
{
- return outputVariables[variableIndex];
+ return &outputVariables[variableIndex];
}
}
- UNREACHABLE();
- return outputVariables[0];
+ return NULL;
}
const std::string VERTEX_ATTRIBUTE_STUB_STRING = "@@ VERTEX ATTRIBUTES @@";
@@ -457,12 +456,18 @@
{
unsigned int location = (binding - GL_COLOR_ATTACHMENT0);
- const PixelShaderOutputVariable &outputVariable = GetOutputAtLocation(outputVariables, location);
+ const PixelShaderOutputVariable *outputVariable = FindOutputAtLocation(outputVariables, location);
- declarationHLSL += " " + HLSLTypeString(outputVariable.type) + " " + outputVariable.name +
- " : " + targetSemantic + Str(layoutIndex) + ";\n";
+ // OpenGL ES 3.0 spec $4.2.1
+ // If [...] not all user-defined output variables are written, the values of fragment colors
+ // corresponding to unwritten variables are similarly undefined.
+ if (outputVariable)
+ {
+ declarationHLSL += " " + HLSLTypeString(outputVariable->type) + " " + outputVariable->name +
+ " : " + targetSemantic + Str(layoutIndex) + ";\n";
- copyHLSL += " output." + outputVariable.name + " = " + outputVariable.source + ";\n";
+ copyHLSL += " output." + outputVariable->name + " = " + outputVariable->source + ";\n";
+ }
}
}