xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fRandomShaderTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES 3.0 Module
3  * -------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Random shader tests.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "es3fRandomShaderTests.hpp"
25 #include "glsRandomShaderCase.hpp"
26 #include "deString.h"
27 #include "deStringUtil.hpp"
28 
29 namespace deqp
30 {
31 namespace gles3
32 {
33 namespace Functional
34 {
35 
36 namespace
37 {
38 
createRandomShaderCase(Context & context,const char * description,const rsg::ProgramParameters & baseParams,uint32_t seed,bool vertex,bool fragment)39 gls::RandomShaderCase *createRandomShaderCase(Context &context, const char *description,
40                                               const rsg::ProgramParameters &baseParams, uint32_t seed, bool vertex,
41                                               bool fragment)
42 {
43     rsg::ProgramParameters params = baseParams;
44 
45     params.version                      = rsg::VERSION_300;
46     params.seed                         = seed;
47     params.vertexParameters.randomize   = vertex;
48     params.fragmentParameters.randomize = fragment;
49 
50     return new gls::RandomShaderCase(context.getTestContext(), context.getRenderContext(), de::toString(seed).c_str(),
51                                      description, params);
52 }
53 
54 class BasicExpressionGroup : public TestCaseGroup
55 {
56 public:
BasicExpressionGroup(Context & context)57     BasicExpressionGroup(Context &context) : TestCaseGroup(context, "basic_expression", "Basic arithmetic expressions")
58     {
59     }
60 
init(void)61     void init(void)
62     {
63         rsg::ProgramParameters params;
64 
65         tcu::TestCaseGroup *vertexGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "Vertex-only tests");
66         addChild(vertexGroup);
67 
68         tcu::TestCaseGroup *fragmentGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "Fragment-only tests");
69         addChild(fragmentGroup);
70 
71         tcu::TestCaseGroup *combinedGroup = new tcu::TestCaseGroup(m_testCtx, "combined", "Combined tests");
72         addChild(combinedGroup);
73 
74         for (int seed = 0; seed < 100; seed++)
75         {
76             vertexGroup->addChild(
77                 createRandomShaderCase(m_context, "Random expressions in vertex shader", params, seed, true, false));
78             fragmentGroup->addChild(
79                 createRandomShaderCase(m_context, "Random expressions in fragment shader", params, seed, false, true));
80             combinedGroup->addChild(createRandomShaderCase(
81                 m_context, "Random expressions in vertex and fragment shaders", params, seed, true, true));
82         }
83     }
84 };
85 
86 class ScalarConversionGroup : public TestCaseGroup
87 {
88 public:
ScalarConversionGroup(Context & context)89     ScalarConversionGroup(Context &context) : TestCaseGroup(context, "scalar_conversion", "Scalar conversions")
90     {
91     }
92 
init(void)93     void init(void)
94     {
95         rsg::ProgramParameters params;
96         params.useScalarConversions = true;
97 
98         tcu::TestCaseGroup *vertexGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "Vertex-only tests");
99         addChild(vertexGroup);
100 
101         tcu::TestCaseGroup *fragmentGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "Fragment-only tests");
102         addChild(fragmentGroup);
103 
104         tcu::TestCaseGroup *combinedGroup = new tcu::TestCaseGroup(m_testCtx, "combined", "Combined tests");
105         addChild(combinedGroup);
106 
107         for (int seed = 0; seed < 100; seed++)
108         {
109             vertexGroup->addChild(
110                 createRandomShaderCase(m_context, "Scalar conversions in vertex shader", params, seed, true, false));
111             fragmentGroup->addChild(
112                 createRandomShaderCase(m_context, "Scalar conversions in fragment shader", params, seed, false, true));
113             combinedGroup->addChild(createRandomShaderCase(
114                 m_context, "Scalar conversions in vertex and fragment shaders", params, seed, true, true));
115         }
116     }
117 };
118 
119 class SwizzleGroup : public TestCaseGroup
120 {
121 public:
SwizzleGroup(Context & context)122     SwizzleGroup(Context &context) : TestCaseGroup(context, "swizzle", "Vector swizzles")
123     {
124     }
125 
init(void)126     void init(void)
127     {
128         rsg::ProgramParameters params;
129         params.useScalarConversions = true;
130         params.useSwizzle           = true;
131 
132         tcu::TestCaseGroup *vertexGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "Vertex-only tests");
133         addChild(vertexGroup);
134 
135         tcu::TestCaseGroup *fragmentGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "Fragment-only tests");
136         addChild(fragmentGroup);
137 
138         for (int seed = 0; seed < 50; seed++)
139         {
140             vertexGroup->addChild(
141                 createRandomShaderCase(m_context, "Vector swizzles in vertex shader", params, seed, true, false));
142             fragmentGroup->addChild(
143                 createRandomShaderCase(m_context, "Vector swizzles in fragment shader", params, seed, false, true));
144         }
145     }
146 };
147 
148 class ComparisonOpsGroup : public TestCaseGroup
149 {
150 public:
ComparisonOpsGroup(Context & context)151     ComparisonOpsGroup(Context &context) : TestCaseGroup(context, "comparison_ops", "Comparison operators")
152     {
153     }
154 
init(void)155     void init(void)
156     {
157         rsg::ProgramParameters params;
158         params.useScalarConversions = true;
159         params.useComparisonOps     = true;
160 
161         tcu::TestCaseGroup *vertexGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "Vertex-only tests");
162         addChild(vertexGroup);
163 
164         tcu::TestCaseGroup *fragmentGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "Fragment-only tests");
165         addChild(fragmentGroup);
166 
167         for (int seed = 0; seed < 50; seed++)
168         {
169             vertexGroup->addChild(
170                 createRandomShaderCase(m_context, "Comparison operators in vertex shader", params, seed, true, false));
171             fragmentGroup->addChild(createRandomShaderCase(m_context, "Comparison operators in fragment shader", params,
172                                                            seed, false, true));
173         }
174     }
175 };
176 
177 class ConditionalsGroup : public TestCaseGroup
178 {
179 public:
ConditionalsGroup(Context & context)180     ConditionalsGroup(Context &context) : TestCaseGroup(context, "conditionals", "Conditional control flow (if-else)")
181     {
182     }
183 
init(void)184     void init(void)
185     {
186         rsg::ProgramParameters params;
187         params.useScalarConversions                     = true;
188         params.useSwizzle                               = true;
189         params.useComparisonOps                         = true;
190         params.useConditionals                          = true;
191         params.vertexParameters.maxStatementDepth       = 4;
192         params.vertexParameters.maxStatementsPerBlock   = 5;
193         params.fragmentParameters.maxStatementDepth     = 4;
194         params.fragmentParameters.maxStatementsPerBlock = 5;
195 
196         tcu::TestCaseGroup *vertexGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "Vertex-only tests");
197         addChild(vertexGroup);
198 
199         tcu::TestCaseGroup *fragmentGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "Fragment-only tests");
200         addChild(fragmentGroup);
201 
202         tcu::TestCaseGroup *combinedGroup = new tcu::TestCaseGroup(m_testCtx, "combined", "Combined tests");
203         addChild(combinedGroup);
204 
205         for (int seed = 0; seed < 100; seed++)
206         {
207             vertexGroup->addChild(createRandomShaderCase(m_context, "Conditional control flow in vertex shader", params,
208                                                          seed, true, false));
209             fragmentGroup->addChild(createRandomShaderCase(m_context, "Conditional control flow in fragment shader",
210                                                            params, seed, false, true));
211             combinedGroup->addChild(createRandomShaderCase(
212                 m_context, "Conditional control flow in vertex and fragment shaders", params, seed, true, true));
213         }
214     }
215 };
216 
217 class TrigonometricGroup : public TestCaseGroup
218 {
219 public:
TrigonometricGroup(Context & context)220     TrigonometricGroup(Context &context) : TestCaseGroup(context, "trigonometric", "Trigonometric built-in functions")
221     {
222     }
223 
init(void)224     void init(void)
225     {
226         rsg::ProgramParameters params;
227         params.useScalarConversions    = true;
228         params.useSwizzle              = true;
229         params.trigonometricBaseWeight = 4.0f;
230 
231         tcu::TestCaseGroup *vertexGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "Vertex-only tests");
232         addChild(vertexGroup);
233 
234         tcu::TestCaseGroup *fragmentGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "Fragment-only tests");
235         addChild(fragmentGroup);
236 
237         for (int seed = 0; seed < 100; seed++)
238         {
239             vertexGroup->addChild(
240                 createRandomShaderCase(m_context, "Trigonometric ops in vertex shader", params, seed, true, false));
241             fragmentGroup->addChild(
242                 createRandomShaderCase(m_context, "Trigonometric ops in fragment shader", params, seed, false, true));
243         }
244     }
245 };
246 
247 class ExponentialGroup : public TestCaseGroup
248 {
249 public:
ExponentialGroup(Context & context)250     ExponentialGroup(Context &context) : TestCaseGroup(context, "exponential", "Exponential built-in functions")
251     {
252     }
253 
init(void)254     void init(void)
255     {
256         rsg::ProgramParameters params;
257         params.useScalarConversions  = true;
258         params.useSwizzle            = true;
259         params.exponentialBaseWeight = 4.0f;
260 
261         tcu::TestCaseGroup *vertexGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "Vertex-only tests");
262         addChild(vertexGroup);
263 
264         tcu::TestCaseGroup *fragmentGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "Fragment-only tests");
265         addChild(fragmentGroup);
266 
267         for (int seed = 0; seed < 100; seed++)
268         {
269             vertexGroup->addChild(
270                 createRandomShaderCase(m_context, "Exponential ops in vertex shader", params, seed, true, false));
271             fragmentGroup->addChild(
272                 createRandomShaderCase(m_context, "Exponential ops in fragment shader", params, seed, false, true));
273         }
274     }
275 };
276 
277 class TextureGroup : public TestCaseGroup
278 {
279 public:
TextureGroup(Context & context)280     TextureGroup(Context &context) : TestCaseGroup(context, "texture", "Texture lookups")
281     {
282     }
283 
init(void)284     void init(void)
285     {
286         rsg::ProgramParameters params;
287         params.useScalarConversions                   = true;
288         params.useSwizzle                             = true;
289         params.vertexParameters.texLookupBaseWeight   = 10.0f;
290         params.vertexParameters.useTexture2D          = true;
291         params.vertexParameters.useTextureCube        = true;
292         params.fragmentParameters.texLookupBaseWeight = 10.0f;
293         params.fragmentParameters.useTexture2D        = true;
294         params.fragmentParameters.useTextureCube      = true;
295 
296         tcu::TestCaseGroup *vertexGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "Vertex-only tests");
297         addChild(vertexGroup);
298 
299         tcu::TestCaseGroup *fragmentGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "Fragment-only tests");
300         addChild(fragmentGroup);
301 
302         // Do only 50 vertex cases and 150 fragment cases.
303         for (int seed = 0; seed < 50; seed++)
304             vertexGroup->addChild(
305                 createRandomShaderCase(m_context, "Texture lookups in vertex shader", params, seed, true, false));
306 
307         for (int seed = 0; seed < 150; seed++)
308             fragmentGroup->addChild(
309                 createRandomShaderCase(m_context, "Texture lookups in fragment shader", params, seed, false, true));
310     }
311 };
312 
313 class AllFeaturesGroup : public TestCaseGroup
314 {
315 public:
AllFeaturesGroup(Context & context)316     AllFeaturesGroup(Context &context) : TestCaseGroup(context, "all_features", "All features enabled")
317     {
318     }
319 
init(void)320     void init(void)
321     {
322         rsg::ProgramParameters params;
323         params.useScalarConversions    = true;
324         params.useSwizzle              = true;
325         params.useComparisonOps        = true;
326         params.useConditionals         = true;
327         params.trigonometricBaseWeight = 1.0f;
328         params.exponentialBaseWeight   = 1.0f;
329 
330         params.vertexParameters.maxStatementDepth            = 4;
331         params.vertexParameters.maxStatementsPerBlock        = 7;
332         params.vertexParameters.maxExpressionDepth           = 7;
333         params.vertexParameters.maxCombinedVariableScalars   = 64;
334         params.fragmentParameters.maxStatementDepth          = 4;
335         params.fragmentParameters.maxStatementsPerBlock      = 7;
336         params.fragmentParameters.maxExpressionDepth         = 7;
337         params.fragmentParameters.maxCombinedVariableScalars = 64;
338 
339         params.fragmentParameters.texLookupBaseWeight =
340             4.0f; // \note Texture lookups are enabled for fragment shaders only.
341         params.fragmentParameters.useTexture2D   = true;
342         params.fragmentParameters.useTextureCube = true;
343 
344         tcu::TestCaseGroup *vertexGroup = new tcu::TestCaseGroup(m_testCtx, "vertex", "Vertex-only tests");
345         addChild(vertexGroup);
346 
347         tcu::TestCaseGroup *fragmentGroup = new tcu::TestCaseGroup(m_testCtx, "fragment", "Fragment-only tests");
348         addChild(fragmentGroup);
349 
350         for (int seed = 0; seed < 100; seed++)
351         {
352             vertexGroup->addChild(
353                 createRandomShaderCase(m_context, "Texture lookups in vertex shader", params, seed, true, false));
354             fragmentGroup->addChild(
355                 createRandomShaderCase(m_context, "Texture lookups in fragment shader", params, seed, false, true));
356         }
357     }
358 };
359 
360 } // namespace
361 
RandomShaderTests(Context & context)362 RandomShaderTests::RandomShaderTests(Context &context) : TestCaseGroup(context, "random", "Random shaders")
363 {
364 }
365 
~RandomShaderTests(void)366 RandomShaderTests::~RandomShaderTests(void)
367 {
368 }
369 
370 namespace
371 {
372 
373 } // namespace
374 
init(void)375 void RandomShaderTests::init(void)
376 {
377     addChild(new BasicExpressionGroup(m_context));
378     addChild(new ScalarConversionGroup(m_context));
379     addChild(new SwizzleGroup(m_context));
380     addChild(new ComparisonOpsGroup(m_context));
381     addChild(new ConditionalsGroup(m_context));
382     addChild(new TrigonometricGroup(m_context));
383     addChild(new ExponentialGroup(m_context));
384     addChild(new TextureGroup(m_context));
385     addChild(new AllFeaturesGroup(m_context));
386 }
387 
388 } // namespace Functional
389 } // namespace gles3
390 } // namespace deqp
391