xref: /aosp_15_r20/external/deqp/framework/randomshaders/rsgProgramGenerator.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Random Shader Generator
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 Program generator.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "rsgProgramGenerator.hpp"
25 #include "rsgShaderGenerator.hpp"
26 #include "rsgGeneratorState.hpp"
27 
28 using std::vector;
29 
30 namespace rsg
31 {
32 
ProgramGenerator(void)33 ProgramGenerator::ProgramGenerator(void)
34 {
35 }
36 
~ProgramGenerator(void)37 ProgramGenerator::~ProgramGenerator(void)
38 {
39 }
40 
generate(const ProgramParameters & programParams,Shader & vertexShader,Shader & fragmentShader)41 void ProgramGenerator::generate(const ProgramParameters &programParams, Shader &vertexShader, Shader &fragmentShader)
42 {
43     // Random number generator
44     de::Random rnd(programParams.seed);
45 
46     GeneratorState state(programParams, rnd);
47 
48     // Fragment shader
49     {
50         ShaderGenerator shaderGen(state);
51         vector<ShaderInput *> emptyOutputs; // \note [pyry] gl_FragColor is added in ShaderGenerator
52         shaderGen.generate(programParams.fragmentParameters, fragmentShader, emptyOutputs);
53     }
54 
55     // Vertex shader
56     {
57         ShaderGenerator shaderGen(state);
58 
59         // Initialize outputs from fragment shader inputs
60         const vector<ShaderInput *> &fragmentInputs =
61             fragmentShader.getInputs(); // \note gl_Position and dEQP_Position are handled in ShaderGenerator
62 
63         shaderGen.generate(programParams.vertexParameters, vertexShader, fragmentInputs);
64     }
65 
66     // Allocate samplers \todo [pyry] Randomize allocation.
67     {
68         const vector<ShaderInput *> &vertexUniforms   = vertexShader.getUniforms();
69         const vector<ShaderInput *> &fragmentUniforms = fragmentShader.getUniforms();
70         vector<ShaderInput *> unifiedSamplers;
71         int curSamplerNdx = 0;
72 
73         // Build unified sampler list.
74         for (vector<ShaderInput *>::const_iterator i = vertexUniforms.begin(); i != vertexUniforms.end(); i++)
75         {
76             if ((*i)->getVariable()->getType().isSampler())
77                 unifiedSamplers.push_back(*i);
78         }
79 
80         for (vector<ShaderInput *>::const_iterator i = fragmentUniforms.begin(); i != fragmentUniforms.end(); i++)
81         {
82             if ((*i)->getVariable()->getType().isSampler())
83                 unifiedSamplers.push_back(*i);
84         }
85 
86         // Assign sampler indices.
87         for (vector<ShaderInput *>::const_iterator i = unifiedSamplers.begin(); i != unifiedSamplers.end(); i++)
88         {
89             ShaderInput *input = *i;
90             if (input->getVariable()->getType().isSampler())
91             {
92                 input->getValueRange().getMin() = curSamplerNdx;
93                 input->getValueRange().getMax() = curSamplerNdx;
94                 curSamplerNdx += 1;
95             }
96         }
97     }
98 }
99 
100 } // namespace rsg
101