1 // 2 // Copyright 2016 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // ConstantFoldingTest.cpp: 7 // Utilities for constant folding tests. 8 // 9 10 #include "tests/test_utils/ConstantFoldingTest.h" 11 12 #include "GLSLANG/ShaderLang.h" 13 #include "angle_gl.h" 14 #include "compiler/translator/TranslatorESSL.h" 15 16 using namespace sh; 17 evaluateFloat(const std::string & floatExpression)18void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpression) 19 { 20 // We first assign the expression into a const variable so we can also verify that it gets 21 // qualified as a constant expression. We then assign that constant expression into my_FragColor 22 // to make sure that the value is not pruned. 23 std::stringstream shaderStream; 24 shaderStream << "#version 310 es\n" 25 "precision mediump float;\n" 26 "out float my_FragColor;\n" 27 "void main()\n" 28 "{\n" 29 << " const float f = " << floatExpression << ";\n" 30 << " my_FragColor = f;\n" 31 "}\n"; 32 compileAssumeSuccess(shaderStream.str()); 33 } 34 evaluateInt(const std::string & intExpression)35void ConstantFoldingExpressionTest::evaluateInt(const std::string &intExpression) 36 { 37 // We first assign the expression into a const variable so we can also verify that it gets 38 // qualified as a constant expression. We then assign that constant expression into my_FragColor 39 // to make sure that the value is not pruned. 40 std::stringstream shaderStream; 41 shaderStream << "#version 310 es\n" 42 "precision mediump int;\n" 43 "out int my_FragColor;\n" 44 "void main()\n" 45 "{\n" 46 << " const int i = " << intExpression << ";\n" 47 << " my_FragColor = i;\n" 48 "}\n"; 49 compileAssumeSuccess(shaderStream.str()); 50 } 51 evaluateUint(const std::string & uintExpression)52void ConstantFoldingExpressionTest::evaluateUint(const std::string &uintExpression) 53 { 54 // We first assign the expression into a const variable so we can also verify that it gets 55 // qualified as a constant expression. We then assign that constant expression into my_FragColor 56 // to make sure that the value is not pruned. 57 std::stringstream shaderStream; 58 shaderStream << "#version 310 es\n" 59 "precision mediump int;\n" 60 "out uint my_FragColor;\n" 61 "void main()\n" 62 "{\n" 63 << " const uint u = " << uintExpression << ";\n" 64 << " my_FragColor = u;\n" 65 "}\n"; 66 compileAssumeSuccess(shaderStream.str()); 67 } 68