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/glsl/TranslatorESSL.h" 15 16 using namespace sh; 17 evaluate(const std::string & type,const std::string & expression)18void ConstantFoldingExpressionTest::evaluate(const std::string &type, const std::string &expression) 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 " << type << " my_FragColor;\n" 27 << "void main()\n" 28 "{\n" 29 << " const " << type << " v = " << expression << ";\n" 30 << " my_FragColor = v;\n" 31 "}\n"; 32 compileAssumeSuccess(shaderStream.str()); 33 } 34 evaluateIvec4(const std::string & ivec4Expression)35void ConstantFoldingExpressionTest::evaluateIvec4(const std::string &ivec4Expression) 36 { 37 evaluate("ivec4", ivec4Expression); 38 } 39 evaluateVec4(const std::string & ivec4Expression)40void ConstantFoldingExpressionTest::evaluateVec4(const std::string &ivec4Expression) 41 { 42 evaluate("vec4", ivec4Expression); 43 } 44 evaluateFloat(const std::string & floatExpression)45void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpression) 46 { 47 evaluate("float", floatExpression); 48 } 49 evaluateInt(const std::string & intExpression)50void ConstantFoldingExpressionTest::evaluateInt(const std::string &intExpression) 51 { 52 evaluate("int", intExpression); 53 } 54 evaluateUint(const std::string & uintExpression)55void ConstantFoldingExpressionTest::evaluateUint(const std::string &uintExpression) 56 { 57 evaluate("uint", uintExpression); 58 } 59