xref: /aosp_15_r20/external/deqp/framework/randomshaders/rsgUtils.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _RSGUTILS_HPP
2 #define _RSGUTILS_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Random Shader Generator
5  * ----------------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "rsgDefs.hpp"
27 #include "rsgShader.hpp"
28 #include "rsgVariableValue.hpp"
29 #include "deRandom.hpp"
30 #include "rsgGeneratorState.hpp"
31 #include "deMath.h"
32 
33 #include <vector>
34 
35 namespace rsg
36 {
37 
38 void computeUnifiedUniforms(const Shader &vertexShader, const Shader &fragmentShader,
39                             std::vector<const ShaderInput *> &uniforms);
40 void computeUniformValues(de::Random &rnd, std::vector<VariableValue> &values,
41                           const std::vector<const ShaderInput *> &uniforms);
42 
43 // \todo [2011-03-26 pyry] Move to ExpressionUtils!
44 
45 bool isUndefinedValueRange(ConstValueRangeAccess valueRange);
46 
47 int getConservativeValueExprDepth(const GeneratorState &state, ConstValueRangeAccess valueRange);
48 int getTypeConstructorDepth(const VariableType &type);
49 
50 VariableType computeRandomType(GeneratorState &state, int maxScalars);
51 void computeRandomValueRange(GeneratorState &state, ValueRangeAccess valueRange);
52 
53 float computeDynamicRangeWeight(ConstValueRangeAccess valueRange);
54 
getQuantizedFloat(de::Random & rnd,float min,float max,float step)55 inline float getQuantizedFloat(de::Random &rnd, float min, float max, float step)
56 {
57     int numSteps = (int)((max - min) / step);
58     return min + step * (float)rnd.getInt(0, numSteps);
59 }
60 
quantizeFloatRange(float & min,float & max)61 inline bool quantizeFloatRange(float &min, float &max)
62 {
63     const float subdiv = 8;
64 
65     float newMin = deFloatCeil(min * subdiv) / subdiv;
66     if (newMin <= max)
67         min = newMin; // Minimum value quantized
68     else
69         return false;
70 
71     float newMax = deFloatFloor(max * subdiv) / subdiv;
72     if (min <= newMax)
73         max = newMax;
74     else
75         return false;
76 
77     return true;
78 }
79 
80 } // namespace rsg
81 
82 #endif // _RSGUTILS_HPP
83