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