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