xref: /aosp_15_r20/external/deqp/modules/gles31/functional/es31fNegativeAtomicCounterTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program OpenGL ES 3.1 Module
3*35238bceSAndroid Build Coastguard Worker  * -------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2015 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker  *
11*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker  *
19*35238bceSAndroid Build Coastguard Worker  *//*!
20*35238bceSAndroid Build Coastguard Worker  * \file
21*35238bceSAndroid Build Coastguard Worker  * \brief Negative Atomic Counter Tests
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "es31fNegativeAtomicCounterTests.hpp"
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "deUniquePtr.hpp"
27*35238bceSAndroid Build Coastguard Worker 
28*35238bceSAndroid Build Coastguard Worker #include "glwEnums.hpp"
29*35238bceSAndroid Build Coastguard Worker #include "gluShaderProgram.hpp"
30*35238bceSAndroid Build Coastguard Worker 
31*35238bceSAndroid Build Coastguard Worker #include "tcuTestLog.hpp"
32*35238bceSAndroid Build Coastguard Worker 
33*35238bceSAndroid Build Coastguard Worker namespace deqp
34*35238bceSAndroid Build Coastguard Worker {
35*35238bceSAndroid Build Coastguard Worker namespace gles31
36*35238bceSAndroid Build Coastguard Worker {
37*35238bceSAndroid Build Coastguard Worker namespace Functional
38*35238bceSAndroid Build Coastguard Worker {
39*35238bceSAndroid Build Coastguard Worker namespace NegativeTestShared
40*35238bceSAndroid Build Coastguard Worker {
41*35238bceSAndroid Build Coastguard Worker namespace
42*35238bceSAndroid Build Coastguard Worker {
43*35238bceSAndroid Build Coastguard Worker 
44*35238bceSAndroid Build Coastguard Worker enum TestCase
45*35238bceSAndroid Build Coastguard Worker {
46*35238bceSAndroid Build Coastguard Worker     TESTCASE_LAYOUT_LARGE_BINDING = 0,
47*35238bceSAndroid Build Coastguard Worker     TESTCASE_LAYOUT_MEDIUMP_PRECISION,
48*35238bceSAndroid Build Coastguard Worker     TESTCASE_LAYOUT_LOWP_PRECISION,
49*35238bceSAndroid Build Coastguard Worker     TESTCASE_LAYOUT_BINDING_OFFSET_OVERLAP,
50*35238bceSAndroid Build Coastguard Worker     TESTCASE_LAYOUT_BINDING_OMITTED,
51*35238bceSAndroid Build Coastguard Worker     TESTCASE_STRUCT,
52*35238bceSAndroid Build Coastguard Worker     TESTCASE_BODY_WRITE,
53*35238bceSAndroid Build Coastguard Worker     TESTCASE_BODY_DECLARE,
54*35238bceSAndroid Build Coastguard Worker 
55*35238bceSAndroid Build Coastguard Worker     TESTCASE_LAST
56*35238bceSAndroid Build Coastguard Worker };
57*35238bceSAndroid Build Coastguard Worker 
58*35238bceSAndroid Build Coastguard Worker static const glu::ShaderType s_shaders[] = {glu::SHADERTYPE_VERTEX,
59*35238bceSAndroid Build Coastguard Worker                                             glu::SHADERTYPE_FRAGMENT,
60*35238bceSAndroid Build Coastguard Worker                                             glu::SHADERTYPE_GEOMETRY,
61*35238bceSAndroid Build Coastguard Worker                                             glu::SHADERTYPE_TESSELLATION_CONTROL,
62*35238bceSAndroid Build Coastguard Worker                                             glu::SHADERTYPE_TESSELLATION_EVALUATION,
63*35238bceSAndroid Build Coastguard Worker                                             glu::SHADERTYPE_COMPUTE};
64*35238bceSAndroid Build Coastguard Worker 
genShaderSource(NegativeTestContext & ctx,TestCase test,glu::ShaderType type)65*35238bceSAndroid Build Coastguard Worker std::string genShaderSource(NegativeTestContext &ctx, TestCase test, glu::ShaderType type)
66*35238bceSAndroid Build Coastguard Worker {
67*35238bceSAndroid Build Coastguard Worker     DE_ASSERT(test < TESTCASE_LAST && type < glu::SHADERTYPE_LAST);
68*35238bceSAndroid Build Coastguard Worker 
69*35238bceSAndroid Build Coastguard Worker     glw::GLint maxBuffers = -1;
70*35238bceSAndroid Build Coastguard Worker     std::ostringstream shader;
71*35238bceSAndroid Build Coastguard Worker 
72*35238bceSAndroid Build Coastguard Worker     ctx.glGetIntegerv(GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS, &maxBuffers);
73*35238bceSAndroid Build Coastguard Worker 
74*35238bceSAndroid Build Coastguard Worker     shader << getGLSLVersionDeclaration(glu::GLSL_VERSION_310_ES) << "\n";
75*35238bceSAndroid Build Coastguard Worker 
76*35238bceSAndroid Build Coastguard Worker     switch (type)
77*35238bceSAndroid Build Coastguard Worker     {
78*35238bceSAndroid Build Coastguard Worker     case glu::SHADERTYPE_GEOMETRY:
79*35238bceSAndroid Build Coastguard Worker         shader << "#extension GL_EXT_geometry_shader : enable\n";
80*35238bceSAndroid Build Coastguard Worker         shader << "layout(max_vertices = 3) out;\n";
81*35238bceSAndroid Build Coastguard Worker         break;
82*35238bceSAndroid Build Coastguard Worker 
83*35238bceSAndroid Build Coastguard Worker     case glu::SHADERTYPE_TESSELLATION_CONTROL:
84*35238bceSAndroid Build Coastguard Worker     case glu::SHADERTYPE_TESSELLATION_EVALUATION:
85*35238bceSAndroid Build Coastguard Worker         shader << "#extension GL_EXT_tessellation_shader : enable\n";
86*35238bceSAndroid Build Coastguard Worker         break;
87*35238bceSAndroid Build Coastguard Worker 
88*35238bceSAndroid Build Coastguard Worker     default:
89*35238bceSAndroid Build Coastguard Worker         break;
90*35238bceSAndroid Build Coastguard Worker     }
91*35238bceSAndroid Build Coastguard Worker 
92*35238bceSAndroid Build Coastguard Worker     switch (test)
93*35238bceSAndroid Build Coastguard Worker     {
94*35238bceSAndroid Build Coastguard Worker     case TESTCASE_LAYOUT_LARGE_BINDING:
95*35238bceSAndroid Build Coastguard Worker         shader << "layout (binding = " << maxBuffers << ", offset = 0) uniform atomic_uint counter0;\n";
96*35238bceSAndroid Build Coastguard Worker         break;
97*35238bceSAndroid Build Coastguard Worker 
98*35238bceSAndroid Build Coastguard Worker     case TESTCASE_LAYOUT_MEDIUMP_PRECISION:
99*35238bceSAndroid Build Coastguard Worker         shader << "layout (binding = 1, offset = 0) " << glu::getPrecisionName(glu::PRECISION_MEDIUMP)
100*35238bceSAndroid Build Coastguard Worker                << " uniform atomic_uint counter0;\n";
101*35238bceSAndroid Build Coastguard Worker         break;
102*35238bceSAndroid Build Coastguard Worker 
103*35238bceSAndroid Build Coastguard Worker     case TESTCASE_LAYOUT_LOWP_PRECISION:
104*35238bceSAndroid Build Coastguard Worker         shader << "layout (binding = 1, offset = 0) " << glu::getPrecisionName(glu::PRECISION_LOWP)
105*35238bceSAndroid Build Coastguard Worker                << " uniform atomic_uint counter0;\n";
106*35238bceSAndroid Build Coastguard Worker         break;
107*35238bceSAndroid Build Coastguard Worker 
108*35238bceSAndroid Build Coastguard Worker     case TESTCASE_LAYOUT_BINDING_OFFSET_OVERLAP:
109*35238bceSAndroid Build Coastguard Worker         shader << "layout (binding = 1, offset = 0) uniform atomic_uint counter0;\n"
110*35238bceSAndroid Build Coastguard Worker                << "layout (binding = 1, offset = 2) uniform atomic_uint counter1;\n";
111*35238bceSAndroid Build Coastguard Worker         break;
112*35238bceSAndroid Build Coastguard Worker 
113*35238bceSAndroid Build Coastguard Worker     case TESTCASE_LAYOUT_BINDING_OMITTED:
114*35238bceSAndroid Build Coastguard Worker         shader << "layout (offset = 0) uniform atomic_uint counter0;\n";
115*35238bceSAndroid Build Coastguard Worker         break;
116*35238bceSAndroid Build Coastguard Worker 
117*35238bceSAndroid Build Coastguard Worker     case TESTCASE_STRUCT:
118*35238bceSAndroid Build Coastguard Worker         shader << "struct\n"
119*35238bceSAndroid Build Coastguard Worker                << "{\n"
120*35238bceSAndroid Build Coastguard Worker                << "  int a;\n"
121*35238bceSAndroid Build Coastguard Worker                << "  atomic_uint counter;\n"
122*35238bceSAndroid Build Coastguard Worker                << "} S;\n";
123*35238bceSAndroid Build Coastguard Worker         break;
124*35238bceSAndroid Build Coastguard Worker 
125*35238bceSAndroid Build Coastguard Worker     case TESTCASE_BODY_WRITE:
126*35238bceSAndroid Build Coastguard Worker         shader << "layout (binding = 1) uniform atomic_uint counter;\n";
127*35238bceSAndroid Build Coastguard Worker         break;
128*35238bceSAndroid Build Coastguard Worker 
129*35238bceSAndroid Build Coastguard Worker     default:
130*35238bceSAndroid Build Coastguard Worker         break;
131*35238bceSAndroid Build Coastguard Worker     }
132*35238bceSAndroid Build Coastguard Worker 
133*35238bceSAndroid Build Coastguard Worker     shader << "void main (void)\n"
134*35238bceSAndroid Build Coastguard Worker            << "{\n";
135*35238bceSAndroid Build Coastguard Worker 
136*35238bceSAndroid Build Coastguard Worker     switch (test)
137*35238bceSAndroid Build Coastguard Worker     {
138*35238bceSAndroid Build Coastguard Worker     case TESTCASE_BODY_WRITE:
139*35238bceSAndroid Build Coastguard Worker         shader << "counter = 1;\n";
140*35238bceSAndroid Build Coastguard Worker         break;
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker     case TESTCASE_BODY_DECLARE:
143*35238bceSAndroid Build Coastguard Worker         shader << "atomic_uint counter;\n";
144*35238bceSAndroid Build Coastguard Worker         break;
145*35238bceSAndroid Build Coastguard Worker 
146*35238bceSAndroid Build Coastguard Worker     default:
147*35238bceSAndroid Build Coastguard Worker         break;
148*35238bceSAndroid Build Coastguard Worker     }
149*35238bceSAndroid Build Coastguard Worker 
150*35238bceSAndroid Build Coastguard Worker     shader << "}\n";
151*35238bceSAndroid Build Coastguard Worker 
152*35238bceSAndroid Build Coastguard Worker     return shader.str();
153*35238bceSAndroid Build Coastguard Worker }
154*35238bceSAndroid Build Coastguard Worker 
iterateShaders(NegativeTestContext & ctx,TestCase testCase)155*35238bceSAndroid Build Coastguard Worker void iterateShaders(NegativeTestContext &ctx, TestCase testCase)
156*35238bceSAndroid Build Coastguard Worker {
157*35238bceSAndroid Build Coastguard Worker     tcu::TestLog &log = ctx.getLog();
158*35238bceSAndroid Build Coastguard Worker     for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_shaders); ndx++)
159*35238bceSAndroid Build Coastguard Worker     {
160*35238bceSAndroid Build Coastguard Worker         if (ctx.isShaderSupported(s_shaders[ndx]))
161*35238bceSAndroid Build Coastguard Worker         {
162*35238bceSAndroid Build Coastguard Worker             ctx.beginSection(std::string("Verify shader: ") + glu::getShaderTypeName(s_shaders[ndx]));
163*35238bceSAndroid Build Coastguard Worker             const glu::ShaderProgram program(ctx.getRenderContext(),
164*35238bceSAndroid Build Coastguard Worker                                              glu::ProgramSources() << glu::ShaderSource(
165*35238bceSAndroid Build Coastguard Worker                                                  s_shaders[ndx], genShaderSource(ctx, testCase, s_shaders[ndx])));
166*35238bceSAndroid Build Coastguard Worker             if (program.getShaderInfo(s_shaders[ndx]).compileOk)
167*35238bceSAndroid Build Coastguard Worker             {
168*35238bceSAndroid Build Coastguard Worker                 log << program;
169*35238bceSAndroid Build Coastguard Worker                 log << tcu::TestLog::Message << "Expected program to fail, but compilation passed."
170*35238bceSAndroid Build Coastguard Worker                     << tcu::TestLog::EndMessage;
171*35238bceSAndroid Build Coastguard Worker                 ctx.fail("Shader was not expected to compile.");
172*35238bceSAndroid Build Coastguard Worker             }
173*35238bceSAndroid Build Coastguard Worker             ctx.endSection();
174*35238bceSAndroid Build Coastguard Worker         }
175*35238bceSAndroid Build Coastguard Worker     }
176*35238bceSAndroid Build Coastguard Worker }
177*35238bceSAndroid Build Coastguard Worker 
atomic_max_counter_bindings(NegativeTestContext & ctx)178*35238bceSAndroid Build Coastguard Worker void atomic_max_counter_bindings(NegativeTestContext &ctx)
179*35238bceSAndroid Build Coastguard Worker {
180*35238bceSAndroid Build Coastguard Worker     ctx.beginSection("It is a compile-time error to bind an atomic counter with a binding value greater than or equal "
181*35238bceSAndroid Build Coastguard Worker                      "to gl_MaxAtomicCounterBindings.");
182*35238bceSAndroid Build Coastguard Worker     iterateShaders(ctx, TESTCASE_LAYOUT_LARGE_BINDING);
183*35238bceSAndroid Build Coastguard Worker     ctx.endSection();
184*35238bceSAndroid Build Coastguard Worker }
185*35238bceSAndroid Build Coastguard Worker 
atomic_precision(NegativeTestContext & ctx)186*35238bceSAndroid Build Coastguard Worker void atomic_precision(NegativeTestContext &ctx)
187*35238bceSAndroid Build Coastguard Worker {
188*35238bceSAndroid Build Coastguard Worker     ctx.beginSection("It is an error to declare an atomic type with a lowp or mediump precision.");
189*35238bceSAndroid Build Coastguard Worker     iterateShaders(ctx, TESTCASE_LAYOUT_MEDIUMP_PRECISION);
190*35238bceSAndroid Build Coastguard Worker     iterateShaders(ctx, TESTCASE_LAYOUT_LOWP_PRECISION);
191*35238bceSAndroid Build Coastguard Worker     ctx.endSection();
192*35238bceSAndroid Build Coastguard Worker }
193*35238bceSAndroid Build Coastguard Worker 
atomic_binding_offset_overlap(NegativeTestContext & ctx)194*35238bceSAndroid Build Coastguard Worker void atomic_binding_offset_overlap(NegativeTestContext &ctx)
195*35238bceSAndroid Build Coastguard Worker {
196*35238bceSAndroid Build Coastguard Worker     ctx.beginSection("Atomic counters may not have overlapping offsets in the same binding.");
197*35238bceSAndroid Build Coastguard Worker     iterateShaders(ctx, TESTCASE_LAYOUT_BINDING_OFFSET_OVERLAP);
198*35238bceSAndroid Build Coastguard Worker     ctx.endSection();
199*35238bceSAndroid Build Coastguard Worker }
200*35238bceSAndroid Build Coastguard Worker 
atomic_binding_omitted(NegativeTestContext & ctx)201*35238bceSAndroid Build Coastguard Worker void atomic_binding_omitted(NegativeTestContext &ctx)
202*35238bceSAndroid Build Coastguard Worker {
203*35238bceSAndroid Build Coastguard Worker     ctx.beginSection("Atomic counters must specify a binding point");
204*35238bceSAndroid Build Coastguard Worker     iterateShaders(ctx, TESTCASE_LAYOUT_BINDING_OMITTED);
205*35238bceSAndroid Build Coastguard Worker     ctx.endSection();
206*35238bceSAndroid Build Coastguard Worker }
207*35238bceSAndroid Build Coastguard Worker 
atomic_struct(NegativeTestContext & ctx)208*35238bceSAndroid Build Coastguard Worker void atomic_struct(NegativeTestContext &ctx)
209*35238bceSAndroid Build Coastguard Worker {
210*35238bceSAndroid Build Coastguard Worker     ctx.beginSection("Structures may not have an atomic_uint variable.");
211*35238bceSAndroid Build Coastguard Worker     iterateShaders(ctx, TESTCASE_STRUCT);
212*35238bceSAndroid Build Coastguard Worker     ctx.endSection();
213*35238bceSAndroid Build Coastguard Worker }
214*35238bceSAndroid Build Coastguard Worker 
atomic_body_write(NegativeTestContext & ctx)215*35238bceSAndroid Build Coastguard Worker void atomic_body_write(NegativeTestContext &ctx)
216*35238bceSAndroid Build Coastguard Worker {
217*35238bceSAndroid Build Coastguard Worker     ctx.beginSection("An atomic_uint variable cannot be directly written to.");
218*35238bceSAndroid Build Coastguard Worker     iterateShaders(ctx, TESTCASE_BODY_WRITE);
219*35238bceSAndroid Build Coastguard Worker     ctx.endSection();
220*35238bceSAndroid Build Coastguard Worker }
221*35238bceSAndroid Build Coastguard Worker 
atomic_body_declare(NegativeTestContext & ctx)222*35238bceSAndroid Build Coastguard Worker void atomic_body_declare(NegativeTestContext &ctx)
223*35238bceSAndroid Build Coastguard Worker {
224*35238bceSAndroid Build Coastguard Worker     ctx.beginSection("An atomic_uint variable cannot be declared in local scope");
225*35238bceSAndroid Build Coastguard Worker     iterateShaders(ctx, TESTCASE_BODY_DECLARE);
226*35238bceSAndroid Build Coastguard Worker     ctx.endSection();
227*35238bceSAndroid Build Coastguard Worker }
228*35238bceSAndroid Build Coastguard Worker 
229*35238bceSAndroid Build Coastguard Worker } // namespace
230*35238bceSAndroid Build Coastguard Worker 
getNegativeAtomicCounterTestFunctions()231*35238bceSAndroid Build Coastguard Worker std::vector<FunctionContainer> getNegativeAtomicCounterTestFunctions()
232*35238bceSAndroid Build Coastguard Worker {
233*35238bceSAndroid Build Coastguard Worker     const FunctionContainer funcs[] = {
234*35238bceSAndroid Build Coastguard Worker         {atomic_max_counter_bindings, "atomic_max_counter_bindings", "Invalid atomic counter buffer binding."},
235*35238bceSAndroid Build Coastguard Worker         {atomic_precision, "atomic_precision", "Invalid precision qualifier."},
236*35238bceSAndroid Build Coastguard Worker         {atomic_binding_offset_overlap, "atomic_binding_offset_overlap", "Invalid offset."},
237*35238bceSAndroid Build Coastguard Worker         {atomic_binding_omitted, "atomic_binding_omitted", "Binding not specified."},
238*35238bceSAndroid Build Coastguard Worker         {atomic_struct, "atomic_struct", "Invalid atomic_uint usage in struct."},
239*35238bceSAndroid Build Coastguard Worker         {atomic_body_write, "atomic_body_write", "Invalid write access to atomic_uint."},
240*35238bceSAndroid Build Coastguard Worker         {atomic_body_declare, "atomic_body_declare", "Invalid precision qualifier."},
241*35238bceSAndroid Build Coastguard Worker     };
242*35238bceSAndroid Build Coastguard Worker 
243*35238bceSAndroid Build Coastguard Worker     return std::vector<FunctionContainer>(DE_ARRAY_BEGIN(funcs), DE_ARRAY_END(funcs));
244*35238bceSAndroid Build Coastguard Worker }
245*35238bceSAndroid Build Coastguard Worker 
246*35238bceSAndroid Build Coastguard Worker } // namespace NegativeTestShared
247*35238bceSAndroid Build Coastguard Worker } // namespace Functional
248*35238bceSAndroid Build Coastguard Worker } // namespace gles31
249*35238bceSAndroid Build Coastguard Worker } // namespace deqp
250