diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /gfx/angle/src/tests/compiler_tests/RecordConstantPrecision_test.cpp | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'gfx/angle/src/tests/compiler_tests/RecordConstantPrecision_test.cpp')
-rwxr-xr-x | gfx/angle/src/tests/compiler_tests/RecordConstantPrecision_test.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/gfx/angle/src/tests/compiler_tests/RecordConstantPrecision_test.cpp b/gfx/angle/src/tests/compiler_tests/RecordConstantPrecision_test.cpp new file mode 100755 index 000000000..2cd2bfdf4 --- /dev/null +++ b/gfx/angle/src/tests/compiler_tests/RecordConstantPrecision_test.cpp @@ -0,0 +1,95 @@ +// +// Copyright (c) 2015 The ANGLE Project Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// +// RecordConstantPrecision_test.cpp: +// Test for recording constant variable precision when it affects consuming expression. +// + +#include "angle_gl.h" +#include "gtest/gtest.h" +#include "GLSLANG/ShaderLang.h" +#include "tests/test_utils/compiler_test.h" + +using namespace sh; + +class RecordConstantPrecisionTest : public MatchOutputCodeTest +{ + public: + RecordConstantPrecisionTest() : MatchOutputCodeTest(GL_FRAGMENT_SHADER, 0, SH_ESSL_OUTPUT) {} +}; + +// The constant cannot be folded if its precision is higher than the other operands, since it +// increases the precision of the consuming expression. +TEST_F(RecordConstantPrecisionTest, HigherPrecisionConstantAsParameter) +{ + const std::string &shaderString = + "uniform mediump float u;" + "void main()\n" + "{\n" + " const highp float a = 4096.5;\n" + " mediump float b = fract(a + u);\n" + " gl_FragColor = vec4(b);\n" + "}\n"; + compile(shaderString); + ASSERT_TRUE(foundInCode("const highp float webgl_angle_s")); + ASSERT_FALSE(foundInCode("fract(4096.5")); + ASSERT_FALSE(foundInCode("fract((4096.5")); +} + +// The constant can be folded if its precision is equal to the other operands, as it does not +// increase the precision of the consuming expression. +TEST_F(RecordConstantPrecisionTest, EqualPrecisionConstantAsParameter) +{ + const std::string &shaderString = + "uniform mediump float u;" + "void main()\n" + "{\n" + " const mediump float a = 4096.5;\n" + " mediump float b = fract(a + u);\n" + " gl_FragColor = vec4(b);\n" + "}\n"; + compile(shaderString); + ASSERT_FALSE(foundInCode("const mediump float webgl_angle_s")); + ASSERT_TRUE(foundInCode("fract((4096.5")); +} + +// The constant cannot be folded if its precision is higher than the other operands, since it +// increases the precision of the consuming expression. This applies also when the constant is +// part of a constant expression that can be folded. +TEST_F(RecordConstantPrecisionTest, FoldedBinaryConstantPrecisionIsHigher) +{ + const std::string &shaderString = + "uniform mediump float u;" + "void main()\n" + "{\n" + " const highp float a = 4095.5;\n" + " mediump float b = fract((a + 1.0) + u);\n" + " gl_FragColor = vec4(b);\n" + "}\n"; + compile(shaderString); + ASSERT_TRUE(foundInCode("const highp float webgl_angle_s")); + ASSERT_FALSE(foundInCode("fract(4096.5")); + ASSERT_FALSE(foundInCode("fract((4096.5")); +} + + +// The constant cannot be folded if its precision is higher than the other operands, since it +// increases the precision of the consuming expression. This applies also when the constant is +// part of a constant expression that can be folded. +TEST_F(RecordConstantPrecisionTest, FoldedUnaryConstantPrecisionIsHigher) +{ + const std::string &shaderString = + "uniform mediump float u;" + "void main()\n" + "{\n" + " const highp float a = 0.5;\n" + " mediump float b = sin(fract(a) + u);\n" + " gl_FragColor = vec4(b);\n" + "}\n"; + compile(shaderString); + ASSERT_TRUE(foundInCode("const highp float webgl_angle_s")); + ASSERT_FALSE(foundInCode("sin(0.5")); + ASSERT_FALSE(foundInCode("sin((0.5")); +} |