• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2017 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 // VectorizeVectorScalarArithmetic_test.cpp:
7 //  Tests shader compilation with SH_REWRITE_VECTOR_SCALAR_ARITHMETIC workaround on.
8 
9 #include "GLSLANG/ShaderLang.h"
10 #include "angle_gl.h"
11 #include "gtest/gtest.h"
12 #include "tests/test_utils/ShaderCompileTreeTest.h"
13 
14 using namespace sh;
15 
16 class VectorizeVectorScalarArithmeticTest : public ShaderCompileTreeTest
17 {
18   public:
VectorizeVectorScalarArithmeticTest()19     VectorizeVectorScalarArithmeticTest() : ShaderCompileTreeTest()
20     {
21         mExtraCompileOptions = SH_REWRITE_VECTOR_SCALAR_ARITHMETIC;
22     }
23 
24   protected:
getShaderType() const25     ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
getShaderSpec() const26     ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
27 };
28 
29 // Test that two ops that generate statements in the parent block inside the same statement don't
30 // trigger an assert.
TEST_F(VectorizeVectorScalarArithmeticTest,TwoMutatedOpsWithSideEffectsInsideSameStatement)31 TEST_F(VectorizeVectorScalarArithmeticTest, TwoMutatedOpsWithSideEffectsInsideSameStatement)
32 {
33     const std::string &shaderString =
34         R"(#version 300 es
35         precision highp float;
36 
37         out vec4 res;
38         uniform float uf;
39 
40         void main()
41         {
42             res = vec4(0.0);
43             float f = uf;
44             res += f *= f, res += f *= f;
45         })";
46     if (!compile(shaderString))
47     {
48         FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
49     }
50 }
51