Fix compound assignment precision emulation
Precision emulation for compound assignment used to set the wrong type
for the compound assignment nodes, which could cause an assert to
trigger. The wrong rounding function was also being called in the lowp
rounded compound assignment function.
BUG=chromium:699479
TEST=angle_unittests
Change-Id: I60b4cb3bf1830e8249511c13037348bb2423e5b9
Reviewed-on: https://chromium-review.googlesource.com/514045
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/EmulatePrecision.cpp b/src/compiler/translator/EmulatePrecision.cpp
index aebcce6..4662929 100644
--- a/src/compiler/translator/EmulatePrecision.cpp
+++ b/src/compiler/translator/EmulatePrecision.cpp
@@ -157,7 +157,7 @@
"}\n";
sink <<
lTypeStr << " angle_compound_" << opNameStr << "_frl(inout " << lTypeStr << " x, in " << rTypeStr << " y) {\n"
- " x = angle_frl(angle_frm(x) " << opStr << " y);\n"
+ " x = angle_frl(angle_frl(x) " << opStr << " y);\n"
" return x;\n"
"}\n";
// clang-format on
@@ -464,7 +464,7 @@
TIntermSequence *arguments = new TIntermSequence();
arguments->push_back(left);
arguments->push_back(right);
- return createInternalFunctionCallNode(TType(EbtVoid), functionName, arguments);
+ return createInternalFunctionCallNode(left->getType(), functionName, arguments);
}
bool ParentUsesResult(TIntermNode *parent, TIntermTyped *node)
diff --git a/src/tests/compiler_tests/DebugShaderPrecision_test.cpp b/src/tests/compiler_tests/DebugShaderPrecision_test.cpp
index 52f77c7..acc0930 100644
--- a/src/tests/compiler_tests/DebugShaderPrecision_test.cpp
+++ b/src/tests/compiler_tests/DebugShaderPrecision_test.cpp
@@ -1042,3 +1042,20 @@
shaderString, &resources, 0, &translatedCode, &infoLog));
}
#endif // defined(ANGLE_ENABLE_HLSL)
+
+// Test that compound assignment inside an expression compiles correctly. This is a test for a bug
+// where incorrect type information on the compound assignment call node caused an assert to trigger
+// in the debug build.
+TEST_F(DebugShaderPrecisionTest, CompoundAssignmentInsideExpression)
+{
+ const std::string &shaderString =
+ "#version 300 es\n"
+ "precision mediump float;\n"
+ "out vec4 my_FragColor;\n"
+ "void main() {\n"
+ " float f = 0.0;\n"
+ " my_FragColor = vec4(abs(f += 1.0), 0, 0, 1);\n"
+ "}\n";
+ compile(shaderString);
+ ASSERT_TRUE(foundInAllGLSLCode("abs(angle_compound_add_frm(f, 1.0))"));
+}