Path: blob/main_old/src/tests/test_utils/ConstantFoldingTest.cpp
1693 views
//1// Copyright 2016 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//5// ConstantFoldingTest.cpp:6// Utilities for constant folding tests.7//89#include "tests/test_utils/ConstantFoldingTest.h"1011#include "GLSLANG/ShaderLang.h"12#include "angle_gl.h"13#include "compiler/translator/TranslatorESSL.h"1415using namespace sh;1617void ConstantFoldingExpressionTest::evaluateFloat(const std::string &floatExpression)18{19// We first assign the expression into a const variable so we can also verify that it gets20// qualified as a constant expression. We then assign that constant expression into my_FragColor21// to make sure that the value is not pruned.22std::stringstream shaderStream;23shaderStream << "#version 310 es\n"24"precision mediump float;\n"25"out float my_FragColor;\n"26"void main()\n"27"{\n"28<< " const float f = " << floatExpression << ";\n"29<< " my_FragColor = f;\n"30"}\n";31compileAssumeSuccess(shaderStream.str());32}3334void ConstantFoldingExpressionTest::evaluateInt(const std::string &intExpression)35{36// We first assign the expression into a const variable so we can also verify that it gets37// qualified as a constant expression. We then assign that constant expression into my_FragColor38// to make sure that the value is not pruned.39std::stringstream shaderStream;40shaderStream << "#version 310 es\n"41"precision mediump int;\n"42"out int my_FragColor;\n"43"void main()\n"44"{\n"45<< " const int i = " << intExpression << ";\n"46<< " my_FragColor = i;\n"47"}\n";48compileAssumeSuccess(shaderStream.str());49}5051void ConstantFoldingExpressionTest::evaluateUint(const std::string &uintExpression)52{53// We first assign the expression into a const variable so we can also verify that it gets54// qualified as a constant expression. We then assign that constant expression into my_FragColor55// to make sure that the value is not pruned.56std::stringstream shaderStream;57shaderStream << "#version 310 es\n"58"precision mediump int;\n"59"out uint my_FragColor;\n"60"void main()\n"61"{\n"62<< " const uint u = " << uintExpression << ";\n"63<< " my_FragColor = u;\n"64"}\n";65compileAssumeSuccess(shaderStream.str());66}676869