xref: /aosp_15_r20/external/deqp/framework/randomshaders/rsgFunctionGenerator.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program Random Shader Generator
3*35238bceSAndroid Build Coastguard Worker  * ----------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  *
5*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 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 Expression generator.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "rsgFunctionGenerator.hpp"
25*35238bceSAndroid Build Coastguard Worker #include "rsgUtils.hpp"
26*35238bceSAndroid Build Coastguard Worker 
27*35238bceSAndroid Build Coastguard Worker using std::vector;
28*35238bceSAndroid Build Coastguard Worker 
29*35238bceSAndroid Build Coastguard Worker namespace rsg
30*35238bceSAndroid Build Coastguard Worker {
31*35238bceSAndroid Build Coastguard Worker 
FunctionGenerator(GeneratorState & state,Function & function)32*35238bceSAndroid Build Coastguard Worker FunctionGenerator::FunctionGenerator(GeneratorState &state, Function &function) : m_state(state), m_function(function)
33*35238bceSAndroid Build Coastguard Worker {
34*35238bceSAndroid Build Coastguard Worker }
35*35238bceSAndroid Build Coastguard Worker 
~FunctionGenerator(void)36*35238bceSAndroid Build Coastguard Worker FunctionGenerator::~FunctionGenerator(void)
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker }
39*35238bceSAndroid Build Coastguard Worker 
generate(void)40*35238bceSAndroid Build Coastguard Worker void FunctionGenerator::generate(void)
41*35238bceSAndroid Build Coastguard Worker {
42*35238bceSAndroid Build Coastguard Worker     std::vector<Statement *> statementStack;
43*35238bceSAndroid Build Coastguard Worker 
44*35238bceSAndroid Build Coastguard Worker     // Initialize
45*35238bceSAndroid Build Coastguard Worker     m_state.setStatementStack(statementStack);
46*35238bceSAndroid Build Coastguard Worker     statementStack.push_back(&m_function.getBody());
47*35238bceSAndroid Build Coastguard Worker     m_function.getBody().init(m_state);
48*35238bceSAndroid Build Coastguard Worker 
49*35238bceSAndroid Build Coastguard Worker     // Process until statement stack is empty
50*35238bceSAndroid Build Coastguard Worker     while (!statementStack.empty())
51*35238bceSAndroid Build Coastguard Worker     {
52*35238bceSAndroid Build Coastguard Worker         DE_ASSERT((int)statementStack.size() <= m_state.getShaderParameters().maxStatementDepth);
53*35238bceSAndroid Build Coastguard Worker 
54*35238bceSAndroid Build Coastguard Worker         Statement *curStatement   = statementStack.back();
55*35238bceSAndroid Build Coastguard Worker         Statement *childStatement = curStatement->createNextChild(m_state);
56*35238bceSAndroid Build Coastguard Worker 
57*35238bceSAndroid Build Coastguard Worker         if (childStatement)
58*35238bceSAndroid Build Coastguard Worker             statementStack.push_back(childStatement);
59*35238bceSAndroid Build Coastguard Worker         else
60*35238bceSAndroid Build Coastguard Worker             statementStack.pop_back();
61*35238bceSAndroid Build Coastguard Worker     }
62*35238bceSAndroid Build Coastguard Worker 
63*35238bceSAndroid Build Coastguard Worker     // Create assignments if variables have bound value range
64*35238bceSAndroid Build Coastguard Worker     for (vector<Variable *>::iterator i = m_requiredAssignments.begin(); i != m_requiredAssignments.end(); i++)
65*35238bceSAndroid Build Coastguard Worker     {
66*35238bceSAndroid Build Coastguard Worker         Variable *variable      = *i;
67*35238bceSAndroid Build Coastguard Worker         const ValueEntry *entry = m_state.getVariableManager().getValue(variable);
68*35238bceSAndroid Build Coastguard Worker         ValueRange valueRange(variable->getType());
69*35238bceSAndroid Build Coastguard Worker 
70*35238bceSAndroid Build Coastguard Worker         valueRange.getMin() = entry->getValueRange().getMin().value();
71*35238bceSAndroid Build Coastguard Worker         valueRange.getMax() = entry->getValueRange().getMax().value();
72*35238bceSAndroid Build Coastguard Worker 
73*35238bceSAndroid Build Coastguard Worker         // Remove value entry from this scope. After this entry ptr is invalid.
74*35238bceSAndroid Build Coastguard Worker         m_state.getVariableManager().removeValueFromCurrentScope(variable);
75*35238bceSAndroid Build Coastguard Worker 
76*35238bceSAndroid Build Coastguard Worker         if (!isUndefinedValueRange(valueRange.asAccess()))
77*35238bceSAndroid Build Coastguard Worker             m_function.getBody().addChild(new AssignStatement(m_state, variable, valueRange.asAccess()));
78*35238bceSAndroid Build Coastguard Worker     }
79*35238bceSAndroid Build Coastguard Worker }
80*35238bceSAndroid Build Coastguard Worker 
81*35238bceSAndroid Build Coastguard Worker } // namespace rsg
82