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