xref: /aosp_15_r20/external/deqp/framework/randomshaders/rsgExecutionContext.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 Shader Evaluation Context.
22*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker 
24*35238bceSAndroid Build Coastguard Worker #include "rsgExecutionContext.hpp"
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker namespace rsg
27*35238bceSAndroid Build Coastguard Worker {
28*35238bceSAndroid Build Coastguard Worker 
ExecMaskStorage(bool initVal)29*35238bceSAndroid Build Coastguard Worker ExecMaskStorage::ExecMaskStorage(bool initVal)
30*35238bceSAndroid Build Coastguard Worker {
31*35238bceSAndroid Build Coastguard Worker     for (int i = 0; i < EXEC_VEC_WIDTH; i++)
32*35238bceSAndroid Build Coastguard Worker         m_data[i].as<bool>() = initVal;
33*35238bceSAndroid Build Coastguard Worker }
34*35238bceSAndroid Build Coastguard Worker 
getValue(void)35*35238bceSAndroid Build Coastguard Worker ExecValueAccess ExecMaskStorage::getValue(void)
36*35238bceSAndroid Build Coastguard Worker {
37*35238bceSAndroid Build Coastguard Worker     return ExecValueAccess(VariableType::getScalarType(VariableType::TYPE_BOOL), m_data);
38*35238bceSAndroid Build Coastguard Worker }
39*35238bceSAndroid Build Coastguard Worker 
getValue(void) const40*35238bceSAndroid Build Coastguard Worker ExecConstValueAccess ExecMaskStorage::getValue(void) const
41*35238bceSAndroid Build Coastguard Worker {
42*35238bceSAndroid Build Coastguard Worker     return ExecConstValueAccess(VariableType::getScalarType(VariableType::TYPE_BOOL), m_data);
43*35238bceSAndroid Build Coastguard Worker }
44*35238bceSAndroid Build Coastguard Worker 
ExecutionContext(const Sampler2DMap & samplers2D,const SamplerCubeMap & samplersCube)45*35238bceSAndroid Build Coastguard Worker ExecutionContext::ExecutionContext(const Sampler2DMap &samplers2D, const SamplerCubeMap &samplersCube)
46*35238bceSAndroid Build Coastguard Worker     : m_samplers2D(samplers2D)
47*35238bceSAndroid Build Coastguard Worker     , m_samplersCube(samplersCube)
48*35238bceSAndroid Build Coastguard Worker {
49*35238bceSAndroid Build Coastguard Worker     // Initialize execution mask to true
50*35238bceSAndroid Build Coastguard Worker     ExecMaskStorage initVal(true);
51*35238bceSAndroid Build Coastguard Worker     pushExecutionMask(initVal.getValue());
52*35238bceSAndroid Build Coastguard Worker }
53*35238bceSAndroid Build Coastguard Worker 
~ExecutionContext(void)54*35238bceSAndroid Build Coastguard Worker ExecutionContext::~ExecutionContext(void)
55*35238bceSAndroid Build Coastguard Worker {
56*35238bceSAndroid Build Coastguard Worker     for (VarValueMap::iterator i = m_varValues.begin(); i != m_varValues.end(); i++)
57*35238bceSAndroid Build Coastguard Worker         delete i->second;
58*35238bceSAndroid Build Coastguard Worker     m_varValues.clear();
59*35238bceSAndroid Build Coastguard Worker }
60*35238bceSAndroid Build Coastguard Worker 
getValue(const Variable * variable)61*35238bceSAndroid Build Coastguard Worker ExecValueAccess ExecutionContext::getValue(const Variable *variable)
62*35238bceSAndroid Build Coastguard Worker {
63*35238bceSAndroid Build Coastguard Worker     ExecValueStorage *storage = m_varValues[variable];
64*35238bceSAndroid Build Coastguard Worker 
65*35238bceSAndroid Build Coastguard Worker     if (!storage)
66*35238bceSAndroid Build Coastguard Worker     {
67*35238bceSAndroid Build Coastguard Worker         storage               = new ExecValueStorage(variable->getType());
68*35238bceSAndroid Build Coastguard Worker         m_varValues[variable] = storage;
69*35238bceSAndroid Build Coastguard Worker     }
70*35238bceSAndroid Build Coastguard Worker 
71*35238bceSAndroid Build Coastguard Worker     return storage->getValue(variable->getType());
72*35238bceSAndroid Build Coastguard Worker }
73*35238bceSAndroid Build Coastguard Worker 
getSampler2D(const Variable * sampler) const74*35238bceSAndroid Build Coastguard Worker const Sampler2D &ExecutionContext::getSampler2D(const Variable *sampler) const
75*35238bceSAndroid Build Coastguard Worker {
76*35238bceSAndroid Build Coastguard Worker     const ExecValueStorage *samplerVal = m_varValues.find(sampler)->second;
77*35238bceSAndroid Build Coastguard Worker 
78*35238bceSAndroid Build Coastguard Worker     int samplerNdx = samplerVal->getValue(sampler->getType()).asInt(0);
79*35238bceSAndroid Build Coastguard Worker 
80*35238bceSAndroid Build Coastguard Worker     return m_samplers2D.find(samplerNdx)->second;
81*35238bceSAndroid Build Coastguard Worker }
82*35238bceSAndroid Build Coastguard Worker 
getSamplerCube(const Variable * sampler) const83*35238bceSAndroid Build Coastguard Worker const SamplerCube &ExecutionContext::getSamplerCube(const Variable *sampler) const
84*35238bceSAndroid Build Coastguard Worker {
85*35238bceSAndroid Build Coastguard Worker     const ExecValueStorage *samplerVal = m_varValues.find(sampler)->second;
86*35238bceSAndroid Build Coastguard Worker 
87*35238bceSAndroid Build Coastguard Worker     int samplerNdx = samplerVal->getValue(sampler->getType()).asInt(0);
88*35238bceSAndroid Build Coastguard Worker 
89*35238bceSAndroid Build Coastguard Worker     return m_samplersCube.find(samplerNdx)->second;
90*35238bceSAndroid Build Coastguard Worker }
91*35238bceSAndroid Build Coastguard Worker 
andExecutionMask(ExecConstValueAccess value)92*35238bceSAndroid Build Coastguard Worker void ExecutionContext::andExecutionMask(ExecConstValueAccess value)
93*35238bceSAndroid Build Coastguard Worker {
94*35238bceSAndroid Build Coastguard Worker     ExecMaskStorage tmp;
95*35238bceSAndroid Build Coastguard Worker     ExecValueAccess newValue      = tmp.getValue();
96*35238bceSAndroid Build Coastguard Worker     ExecConstValueAccess oldValue = getExecutionMask();
97*35238bceSAndroid Build Coastguard Worker 
98*35238bceSAndroid Build Coastguard Worker     for (int i = 0; i < EXEC_VEC_WIDTH; i++)
99*35238bceSAndroid Build Coastguard Worker         newValue.asBool(i) = oldValue.asBool(i) && value.asBool(i);
100*35238bceSAndroid Build Coastguard Worker 
101*35238bceSAndroid Build Coastguard Worker     pushExecutionMask(newValue);
102*35238bceSAndroid Build Coastguard Worker }
103*35238bceSAndroid Build Coastguard Worker 
pushExecutionMask(ExecConstValueAccess value)104*35238bceSAndroid Build Coastguard Worker void ExecutionContext::pushExecutionMask(ExecConstValueAccess value)
105*35238bceSAndroid Build Coastguard Worker {
106*35238bceSAndroid Build Coastguard Worker     ExecMaskStorage tmp;
107*35238bceSAndroid Build Coastguard Worker     tmp.getValue() = value.value();
108*35238bceSAndroid Build Coastguard Worker     m_execMaskStack.push_back(tmp);
109*35238bceSAndroid Build Coastguard Worker }
110*35238bceSAndroid Build Coastguard Worker 
popExecutionMask(void)111*35238bceSAndroid Build Coastguard Worker void ExecutionContext::popExecutionMask(void)
112*35238bceSAndroid Build Coastguard Worker {
113*35238bceSAndroid Build Coastguard Worker     m_execMaskStack.pop_back();
114*35238bceSAndroid Build Coastguard Worker }
115*35238bceSAndroid Build Coastguard Worker 
getExecutionMask(void) const116*35238bceSAndroid Build Coastguard Worker ExecConstValueAccess ExecutionContext::getExecutionMask(void) const
117*35238bceSAndroid Build Coastguard Worker {
118*35238bceSAndroid Build Coastguard Worker     return m_execMaskStack[m_execMaskStack.size() - 1].getValue();
119*35238bceSAndroid Build Coastguard Worker }
120*35238bceSAndroid Build Coastguard Worker 
assignMasked(ExecValueAccess dst,ExecConstValueAccess src,ExecConstValueAccess mask)121*35238bceSAndroid Build Coastguard Worker void assignMasked(ExecValueAccess dst, ExecConstValueAccess src, ExecConstValueAccess mask)
122*35238bceSAndroid Build Coastguard Worker {
123*35238bceSAndroid Build Coastguard Worker     const VariableType &type = dst.getType();
124*35238bceSAndroid Build Coastguard Worker 
125*35238bceSAndroid Build Coastguard Worker     switch (type.getBaseType())
126*35238bceSAndroid Build Coastguard Worker     {
127*35238bceSAndroid Build Coastguard Worker     case VariableType::TYPE_ARRAY:
128*35238bceSAndroid Build Coastguard Worker     {
129*35238bceSAndroid Build Coastguard Worker         int numElems = type.getNumElements();
130*35238bceSAndroid Build Coastguard Worker         for (int elemNdx = 0; elemNdx < numElems; elemNdx++)
131*35238bceSAndroid Build Coastguard Worker             assignMasked(dst.arrayElement(elemNdx), src.arrayElement(elemNdx), mask);
132*35238bceSAndroid Build Coastguard Worker 
133*35238bceSAndroid Build Coastguard Worker         break;
134*35238bceSAndroid Build Coastguard Worker     }
135*35238bceSAndroid Build Coastguard Worker 
136*35238bceSAndroid Build Coastguard Worker     case VariableType::TYPE_STRUCT:
137*35238bceSAndroid Build Coastguard Worker     {
138*35238bceSAndroid Build Coastguard Worker         int numMembers = (int)type.getMembers().size();
139*35238bceSAndroid Build Coastguard Worker         for (int memberNdx = 0; memberNdx < numMembers; memberNdx++)
140*35238bceSAndroid Build Coastguard Worker             assignMasked(dst.member(memberNdx), src.member(memberNdx), mask);
141*35238bceSAndroid Build Coastguard Worker 
142*35238bceSAndroid Build Coastguard Worker         break;
143*35238bceSAndroid Build Coastguard Worker     }
144*35238bceSAndroid Build Coastguard Worker 
145*35238bceSAndroid Build Coastguard Worker     case VariableType::TYPE_FLOAT:
146*35238bceSAndroid Build Coastguard Worker     case VariableType::TYPE_INT:
147*35238bceSAndroid Build Coastguard Worker     case VariableType::TYPE_BOOL:
148*35238bceSAndroid Build Coastguard Worker     case VariableType::TYPE_SAMPLER_2D:
149*35238bceSAndroid Build Coastguard Worker     case VariableType::TYPE_SAMPLER_CUBE:
150*35238bceSAndroid Build Coastguard Worker     {
151*35238bceSAndroid Build Coastguard Worker         for (int elemNdx = 0; elemNdx < type.getNumElements(); elemNdx++)
152*35238bceSAndroid Build Coastguard Worker         {
153*35238bceSAndroid Build Coastguard Worker             ExecValueAccess dstElem      = dst.component(elemNdx);
154*35238bceSAndroid Build Coastguard Worker             ExecConstValueAccess srcElem = src.component(elemNdx);
155*35238bceSAndroid Build Coastguard Worker 
156*35238bceSAndroid Build Coastguard Worker             for (int compNdx = 0; compNdx < EXEC_VEC_WIDTH; compNdx++)
157*35238bceSAndroid Build Coastguard Worker             {
158*35238bceSAndroid Build Coastguard Worker                 if (mask.asBool(compNdx))
159*35238bceSAndroid Build Coastguard Worker                     dstElem.asScalar(compNdx) = srcElem.asScalar(compNdx);
160*35238bceSAndroid Build Coastguard Worker             }
161*35238bceSAndroid Build Coastguard Worker         }
162*35238bceSAndroid Build Coastguard Worker 
163*35238bceSAndroid Build Coastguard Worker         break;
164*35238bceSAndroid Build Coastguard Worker     }
165*35238bceSAndroid Build Coastguard Worker 
166*35238bceSAndroid Build Coastguard Worker     default:
167*35238bceSAndroid Build Coastguard Worker         DE_FATAL("Unsupported");
168*35238bceSAndroid Build Coastguard Worker         break;
169*35238bceSAndroid Build Coastguard Worker     }
170*35238bceSAndroid Build Coastguard Worker }
171*35238bceSAndroid Build Coastguard Worker 
172*35238bceSAndroid Build Coastguard Worker } // namespace rsg
173