xref: /aosp_15_r20/external/angle/src/tests/compiler_tests/SamplerMultisample_test.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 // SamplerMultisample_test.cpp:
7 // Tests compiling shaders that use gsampler2DMS types
8 //
9 
10 #include "GLSLANG/ShaderLang.h"
11 #include "angle_gl.h"
12 #include "gtest/gtest.h"
13 #include "tests/test_utils/ShaderCompileTreeTest.h"
14 
15 using namespace sh;
16 
17 class SamplerMultisampleTest : public ShaderCompileTreeTest
18 {
19   public:
SamplerMultisampleTest()20     SamplerMultisampleTest() {}
21 
22   protected:
getShaderType() const23     ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
getShaderSpec() const24     ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
25 };
26 
27 class SamplerMultisampleArrayTest : public ShaderCompileTreeTest
28 {
29   public:
SamplerMultisampleArrayTest()30     SamplerMultisampleArrayTest() {}
31 
initResources(ShBuiltInResources * resources)32     void initResources(ShBuiltInResources *resources) override
33     {
34         resources->OES_texture_storage_multisample_2d_array = 1;
35     }
36 
37   protected:
getShaderType() const38     ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
getShaderSpec() const39     ShShaderSpec getShaderSpec() const override { return SH_GLES3_1_SPEC; }
40 };
41 
42 // Checks whether compiler has parsed the gsampler2DMS, texelfetch correctly.
TEST_F(SamplerMultisampleTest,TexelFetchSampler2DMS)43 TEST_F(SamplerMultisampleTest, TexelFetchSampler2DMS)
44 {
45     constexpr char kShaderString[] =
46         R"(#version 310 es
47         precision highp float;
48         uniform highp sampler2DMS s;
49         uniform highp isampler2DMS is;
50         uniform highp usampler2DMS us;
51 
52         void main() {
53             vec4 tex1 = texelFetch(s, ivec2(0, 0), 0);
54             ivec4 tex2 = texelFetch(is, ivec2(0, 0), 0);
55             uvec4 tex3 = texelFetch(us, ivec2(0, 0), 0);
56         })";
57 
58     if (!compile(kShaderString))
59     {
60         FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
61     }
62 }
63 
64 // Checks whether compiler has parsed the gsampler2DMS, textureSize correctly.
TEST_F(SamplerMultisampleTest,TextureSizeSampler2DMS)65 TEST_F(SamplerMultisampleTest, TextureSizeSampler2DMS)
66 {
67     constexpr char kShaderString[] =
68         R"(#version 310 es
69         precision highp float;
70         uniform highp sampler2DMS s;
71         uniform highp isampler2DMS is;
72         uniform highp usampler2DMS us;
73 
74         void main() {
75             ivec2 size = textureSize(s);
76             size = textureSize(is);
77             size = textureSize(us);
78         })";
79 
80     if (!compile(kShaderString))
81     {
82         FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
83     }
84 }
85 
86 // Check that sampler2DMS has no default precision.
TEST_F(SamplerMultisampleTest,NoPrecisionSampler2DMS)87 TEST_F(SamplerMultisampleTest, NoPrecisionSampler2DMS)
88 {
89     constexpr char kShaderString[] =
90         R"(#version 310 es
91         precision highp float;
92         uniform sampler2DMS s;
93 
94         void main() {})";
95 
96     if (compile(kShaderString))
97     {
98         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
99     }
100 }
101 
102 // Check that isampler2DMS has no default precision.
TEST_F(SamplerMultisampleTest,NoPrecisionISampler2DMS)103 TEST_F(SamplerMultisampleTest, NoPrecisionISampler2DMS)
104 {
105     constexpr char kShaderString[] =
106         R"(#version 310 es
107         precision highp float;
108         uniform isampler2DMS s;
109 
110         void main() {})";
111 
112     if (compile(kShaderString))
113     {
114         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
115     }
116 }
117 
118 // Check that usampler2DMS has no default precision.
TEST_F(SamplerMultisampleTest,NoPrecisionUSampler2DMS)119 TEST_F(SamplerMultisampleTest, NoPrecisionUSampler2DMS)
120 {
121     constexpr char kShaderString[] =
122         R"(#version 310 es
123         precision highp float;
124         uniform usampler2DMS s;
125 
126         void main() {})";
127 
128     if (compile(kShaderString))
129     {
130         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
131     }
132 }
133 
134 // Negative test: checks that sampler2DMS is not usable in ESSL 3.00.
TEST_F(SamplerMultisampleTest,Sampler2DMSESSL300)135 TEST_F(SamplerMultisampleTest, Sampler2DMSESSL300)
136 {
137     constexpr char kShaderString[] =
138         R"(#version 300 es
139         precision highp float;
140         uniform highp sampler2DMS s;
141 
142         void main() {
143         })";
144 
145     if (compile(kShaderString))
146     {
147         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
148     }
149 }
150 
151 // Negative test: checks that isampler2DMS is not usable in ESSL 3.00.
TEST_F(SamplerMultisampleTest,ISampler2DMSESSL300)152 TEST_F(SamplerMultisampleTest, ISampler2DMSESSL300)
153 {
154     constexpr char kShaderString[] =
155         R"(#version 300 es
156         precision highp float;
157         uniform highp isampler2DMS s;
158 
159         void main() {
160         })";
161 
162     if (compile(kShaderString))
163     {
164         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
165     }
166 }
167 
168 // Negative test: checks that usampler2DMS is not usable in ESSL 3.00.
TEST_F(SamplerMultisampleTest,USampler2DMSESSL300)169 TEST_F(SamplerMultisampleTest, USampler2DMSESSL300)
170 {
171     constexpr char kShaderString[] =
172         R"(#version 300 es
173         precision highp float;
174         uniform highp usampler2DMS s;
175 
176         void main() {
177         })";
178 
179     if (compile(kShaderString))
180     {
181         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
182     }
183 }
184 
185 // Negative test: checks that sampler2DMSArray is not usable in ESSL 3.10 without extensions.
TEST_F(SamplerMultisampleTest,Sampler2DMSArrayNotSupported)186 TEST_F(SamplerMultisampleTest, Sampler2DMSArrayNotSupported)
187 {
188     constexpr char kShaderString[] =
189         R"(#version 310 es
190         precision highp float;
191         uniform highp sampler2DMSArray s;
192 
193         void main() {
194         })";
195 
196     if (compile(kShaderString))
197     {
198         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
199     }
200 }
201 
202 // Negative test: checks that isampler2DMSArray is not usable in ESSL 3.10 without extensions.
TEST_F(SamplerMultisampleTest,ISampler2DMSArrayNotSupported)203 TEST_F(SamplerMultisampleTest, ISampler2DMSArrayNotSupported)
204 {
205     constexpr char kShaderString[] =
206         R"(#version 310 es
207         precision highp float;
208         uniform highp isampler2DMSArray s;
209 
210         void main() {
211         })";
212 
213     if (compile(kShaderString))
214     {
215         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
216     }
217 }
218 
219 // Negative test: checks that usampler2DMSArray is not usable in ESSL 3.10 without extensions.
TEST_F(SamplerMultisampleTest,USampler2DMSArrayNotSupported)220 TEST_F(SamplerMultisampleTest, USampler2DMSArrayNotSupported)
221 {
222     constexpr char kShaderString[] =
223         R"(#version 310 es
224         precision highp float;
225         uniform highp usampler2DMSArray s;
226 
227         void main() {
228         })";
229 
230     if (compile(kShaderString))
231     {
232         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
233     }
234 }
235 
236 // Checks whether compiler has parsed the gsampler2DMSArray, texelfetch correctly.
TEST_F(SamplerMultisampleArrayTest,TexelFetchSampler2DMSArray)237 TEST_F(SamplerMultisampleArrayTest, TexelFetchSampler2DMSArray)
238 {
239     constexpr char kShaderString[] =
240         R"(#version 310 es
241         #extension GL_OES_texture_storage_multisample_2d_array : require
242         precision highp float;
243         uniform highp sampler2DMSArray s;
244         uniform highp isampler2DMSArray is;
245         uniform highp usampler2DMSArray us;
246 
247         void main() {
248             vec4 tex1 = texelFetch(s, ivec3(0, 0, 0), 0);
249             ivec4 tex2 = texelFetch(is, ivec3(0, 0, 0), 0);
250             uvec4 tex3 = texelFetch(us, ivec3(0, 0, 0), 0);
251         })";
252 
253     if (!compile(kShaderString))
254     {
255         FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
256     }
257 }
258 
259 // Checks whether compiler has parsed the gsampler2DMSArray, textureSize correctly.
TEST_F(SamplerMultisampleArrayTest,TextureSizeSampler2DMSArray)260 TEST_F(SamplerMultisampleArrayTest, TextureSizeSampler2DMSArray)
261 {
262     constexpr char kShaderString[] =
263         R"(#version 310 es
264         #extension GL_OES_texture_storage_multisample_2d_array : require
265         precision highp float;
266         uniform highp sampler2DMSArray s;
267         uniform highp isampler2DMSArray is;
268         uniform highp usampler2DMSArray us;
269 
270         void main() {
271             ivec3 size = textureSize(s);
272             size = textureSize(is);
273             size = textureSize(us);
274         })";
275 
276     if (!compile(kShaderString))
277     {
278         FAIL() << "Shader compilation failed, expecting success:\n" << mInfoLog;
279     }
280 }
281 
282 // Check that sampler2DMSArray has no default precision.
TEST_F(SamplerMultisampleArrayTest,NoPrecisionSampler2DMSArray)283 TEST_F(SamplerMultisampleArrayTest, NoPrecisionSampler2DMSArray)
284 {
285     constexpr char kShaderString[] =
286         R"(#version 310 es
287         #extension GL_OES_texture_storage_multisample_2d_array : require
288         precision highp float;
289         uniform sampler2DMSArray s;
290 
291         void main() {})";
292 
293     if (compile(kShaderString))
294     {
295         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
296     }
297 }
298 
299 // Check that isampler2DMSArray has no default precision.
TEST_F(SamplerMultisampleArrayTest,NoPrecisionISampler2DMSArray)300 TEST_F(SamplerMultisampleArrayTest, NoPrecisionISampler2DMSArray)
301 {
302     constexpr char kShaderString[] =
303         R"(#version 310 es
304         #extension GL_OES_texture_storage_multisample_2d_array : require
305         precision highp float;
306         uniform isampler2DMSArray s;
307 
308         void main() {})";
309 
310     if (compile(kShaderString))
311     {
312         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
313     }
314 }
315 
316 // Check that usampler2DMSArray has no default precision.
TEST_F(SamplerMultisampleArrayTest,NoPrecisionUSampler2DMSArray)317 TEST_F(SamplerMultisampleArrayTest, NoPrecisionUSampler2DMSArray)
318 {
319     constexpr char kShaderString[] =
320         R"(#version 310 es
321         #extension GL_OES_texture_storage_multisample_2d_array : require
322         precision highp float;
323         uniform usampler2DMSArray s;
324 
325         void main() {})";
326 
327     if (compile(kShaderString))
328     {
329         FAIL() << "Shader compilation succeeded, expecting failure:\n" << mInfoLog;
330     }
331 }
332 
333 class SamplerMultisampleEXTTest : public SamplerMultisampleTest
334 {
335   public:
SamplerMultisampleEXTTest()336     SamplerMultisampleEXTTest() {}
337 
338   protected:
initResources(ShBuiltInResources * resources)339     void initResources(ShBuiltInResources *resources) override
340     {
341         resources->ANGLE_texture_multisample = 1;
342     }
343 
getShaderType() const344     ::GLenum getShaderType() const override { return GL_FRAGMENT_SHADER; }
getShaderSpec() const345     ShShaderSpec getShaderSpec() const override { return SH_GLES3_SPEC; }
346 };
347 
348 // checks ANGLE_texture_multisample is supported in es 3.0
TEST_F(SamplerMultisampleEXTTest,TextureMultisampleEXTEnabled)349 TEST_F(SamplerMultisampleEXTTest, TextureMultisampleEXTEnabled)
350 {
351     constexpr char kShaderString[] =
352         R"(#version 300 es
353         #extension GL_ANGLE_texture_multisample : require
354         precision highp float;
355         uniform highp sampler2DMS s;
356         uniform highp isampler2DMS is;
357         uniform highp usampler2DMS us;
358 
359         void main() {
360             ivec2 size = textureSize(s);
361             size = textureSize(is);
362             size = textureSize(us);
363             vec4 tex1 = texelFetch(s, ivec2(0, 0), 0);
364             ivec4 tex2 = texelFetch(is, ivec2(0, 0), 0);
365             uvec4 tex3 = texelFetch(us, ivec2(0, 0), 0);
366         })";
367 
368     if (!compile(kShaderString))
369     {
370         FAIL() << "Shader compilation failure, expecting success:\n" << mInfoLog;
371     }
372 }
373 
374 // checks that multisample texture is not supported without ANGLE_texture_multisample in es 3.0
TEST_F(SamplerMultisampleEXTTest,TextureMultisampleEXTDisabled)375 TEST_F(SamplerMultisampleEXTTest, TextureMultisampleEXTDisabled)
376 {
377     constexpr char kShaderString[] =
378         R"(#version 300 es
379         precision highp float;
380         uniform highp sampler2DMS s;
381         uniform highp isampler2DMS is;
382         uniform highp usampler2DMS us;
383 
384         void main() {
385             ivec2 size = textureSize(s);
386             size = textureSize(is);
387             size = textureSize(us);
388             vec4 tex1 = texelFetch(s, ivec2(0, 0), 0);
389             ivec4 tex2 = texelFetch(is, ivec2(0, 0), 0);
390             uvec4 tex3 = texelFetch(us, ivec2(0, 0), 0);
391         })";
392 
393     if (compile(kShaderString))
394     {
395         FAIL() << "Shader compilation success, expecting failure:\n" << mInfoLog;
396     }
397 }
398