• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2022 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 
7 #include "test_utils/ANGLETest.h"
8 
9 #include "test_utils/gl_raii.h"
10 #include "util/shader_utils.h"
11 
12 namespace angle
13 {
14 
15 class DesktopGLSLTest : public ANGLETest<>
16 {
17   protected:
DesktopGLSLTest()18     DesktopGLSLTest()
19     {
20         setWindowWidth(128);
21         setWindowHeight(128);
22         setConfigRedBits(8);
23         setConfigGreenBits(8);
24         setConfigBlueBits(8);
25         setConfigAlphaBits(8);
26     }
27 };
28 
29 // Simple test case of compiling a desktop OpenGL shader to verify that the shader compiler
30 // initializes.
TEST_P(DesktopGLSLTest,BasicCompilation)31 TEST_P(DesktopGLSLTest, BasicCompilation)
32 {
33     constexpr char kVS[] = R"(#version 150
34 in vec4 position;
35 
36 void main()
37 {
38     gl_Position = position;
39 })";
40 
41     constexpr char kFS[] = R"(#version 150
42 out vec4 fragColor;
43 
44 void main()
45 {
46     fragColor = vec4(1.0, 0.5, 0.2, 1.0);
47 })";
48 
49     ANGLE_GL_PROGRAM(testProgram, kVS, kFS);
50 }
51 
52 // Test calling sh::Compile with fragment shader source string
TEST_P(DesktopGLSLTest,DesktopGLString)53 TEST_P(DesktopGLSLTest, DesktopGLString)
54 {
55     constexpr char kFS[] =
56         R"(#version 330
57         void main()
58         {
59         })";
60 
61     ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
62 }
63 
64 // Test calling sh::Compile with core version
TEST_P(DesktopGLSLTest,FragmentShaderCoreVersion)65 TEST_P(DesktopGLSLTest, FragmentShaderCoreVersion)
66 {
67     constexpr char kFS[] =
68         R"(#version 330 core
69         void main()
70         {
71         })";
72 
73     ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
74 }
75 
76 // Implicit conversions in basic operations
TEST_P(DesktopGLSLTest,ImplicitConversionBasicOperation)77 TEST_P(DesktopGLSLTest, ImplicitConversionBasicOperation)
78 {
79     constexpr char kFS[] =
80         R"(#version 330 core
81         void main()
82         {
83             //float a = 1 + 1.5;
84             //float b = 1 - 1.5;
85             //float c = 1 * 1.5;
86             //float d = 1 / 1.5;
87             //float e = 1.5 + 1;
88             //float f = 1.5 - 1;
89             float g = 1.5 * 1;
90             //float h = 1.5 / 1;
91         })";
92 
93     ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
94 }
95 
96 // Implicit conversions when assigning
TEST_P(DesktopGLSLTest,ImplicitConversionAssign)97 TEST_P(DesktopGLSLTest, ImplicitConversionAssign)
98 {
99     constexpr char kFS[] =
100         R"(#version 330 core
101         void main()
102         {
103             float a = 1;
104             uint b = 2u;
105             a = b;
106             a += b;
107             a -= b;
108             a *= b;
109             a /= b;
110         })";
111 
112     ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
113 }
114 
115 // Implicit conversions for vectors
TEST_P(DesktopGLSLTest,ImplicitConversionVector)116 TEST_P(DesktopGLSLTest, ImplicitConversionVector)
117 {
118     constexpr char kFS[] =
119         R"(#version 330 core
120         void main()
121         {
122             vec3 a;
123             ivec3 b = ivec3(1, 1, 1);
124             a = b;
125         })";
126 
127     ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
128 }
129 
130 // Implicit conversions should not convert between ints and uints
TEST_P(DesktopGLSLTest,ImplicitConversionAssignFailed)131 TEST_P(DesktopGLSLTest, ImplicitConversionAssignFailed)
132 {
133     constexpr char kFS[] =
134         R"(#version 330 core
135         void main()
136         {
137             int a = 1;
138             uint b = 2;
139             a = b;
140         })";
141 
142     ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
143 }
144 
145 // GL shaders use implicit conversions between types
146 // Testing internal implicit conversions
TEST_P(DesktopGLSLTest,ImplicitConversionFunction)147 TEST_P(DesktopGLSLTest, ImplicitConversionFunction)
148 {
149     constexpr char kFS[] =
150         R"(#version 330 core
151         void main()
152         {
153             float cosTheta = clamp(0.5,0,1);
154             float exp = pow(0.5,2);
155         })";
156 
157     ASSERT_NE(static_cast<unsigned int>(0), CompileShader(GL_FRAGMENT_SHADER, kFS));
158 }
159 
160 GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DesktopGLSLTest);
161 ANGLE_INSTANTIATE_TEST_GL32_CORE(DesktopGLSLTest);
162 
163 }  // namespace angle
164