1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Random Shader Generator
3 * ----------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * \brief Shader Evaluation Context.
22 *//*--------------------------------------------------------------------*/
24 #include "rsgExecutionContext.hpp"
29 ExecMaskStorage::ExecMaskStorage (bool initVal)
31 for (int i = 0; i < EXEC_VEC_WIDTH; i++)
32 m_data[i].as<bool>() = initVal;
35 ExecValueAccess ExecMaskStorage::getValue (void)
37 return ExecValueAccess(VariableType::getScalarType(VariableType::TYPE_BOOL), m_data);
40 ExecConstValueAccess ExecMaskStorage::getValue (void) const
42 return ExecConstValueAccess(VariableType::getScalarType(VariableType::TYPE_BOOL), m_data);
45 ExecutionContext::ExecutionContext (const Sampler2DMap& samplers2D, const SamplerCubeMap& samplersCube)
46 : m_samplers2D (samplers2D)
47 , m_samplersCube (samplersCube)
49 // Initialize execution mask to true
50 ExecMaskStorage initVal(true);
51 pushExecutionMask(initVal.getValue());
54 ExecutionContext::~ExecutionContext (void)
56 for (VarValueMap::iterator i = m_varValues.begin(); i != m_varValues.end(); i++)
61 ExecValueAccess ExecutionContext::getValue (const Variable* variable)
63 ExecValueStorage* storage = m_varValues[variable];
67 storage = new ExecValueStorage(variable->getType());
68 m_varValues[variable] = storage;
71 return storage->getValue(variable->getType());
74 const Sampler2D& ExecutionContext::getSampler2D (const Variable* sampler) const
76 const ExecValueStorage* samplerVal = m_varValues.find(sampler)->second;
78 int samplerNdx = samplerVal->getValue(sampler->getType()).asInt(0);
80 return m_samplers2D.find(samplerNdx)->second;
83 const SamplerCube& ExecutionContext::getSamplerCube (const Variable* sampler) const
85 const ExecValueStorage* samplerVal = m_varValues.find(sampler)->second;
87 int samplerNdx = samplerVal->getValue(sampler->getType()).asInt(0);
89 return m_samplersCube.find(samplerNdx)->second;
92 void ExecutionContext::andExecutionMask (ExecConstValueAccess value)
95 ExecValueAccess newValue = tmp.getValue();
96 ExecConstValueAccess oldValue = getExecutionMask();
98 for (int i = 0; i < EXEC_VEC_WIDTH; i++)
99 newValue.asBool(i) = oldValue.asBool(i) && value.asBool(i);
101 pushExecutionMask(newValue);
104 void ExecutionContext::pushExecutionMask (ExecConstValueAccess value)
107 tmp.getValue() = value.value();
108 m_execMaskStack.push_back(tmp);
111 void ExecutionContext::popExecutionMask (void)
113 m_execMaskStack.pop_back();
116 ExecConstValueAccess ExecutionContext::getExecutionMask (void) const
118 return m_execMaskStack[m_execMaskStack.size()-1].getValue();
121 void assignMasked (ExecValueAccess dst, ExecConstValueAccess src, ExecConstValueAccess mask)
123 const VariableType& type = dst.getType();
125 switch (type.getBaseType())
127 case VariableType::TYPE_ARRAY:
129 int numElems = type.getNumElements();
130 for (int elemNdx = 0; elemNdx < numElems; elemNdx++)
131 assignMasked(dst.arrayElement(elemNdx), src.arrayElement(elemNdx), mask);
136 case VariableType::TYPE_STRUCT:
138 int numMembers = (int)type.getMembers().size();
139 for (int memberNdx = 0; memberNdx < numMembers; memberNdx++)
140 assignMasked(dst.member(memberNdx), src.member(memberNdx), mask);
145 case VariableType::TYPE_FLOAT:
146 case VariableType::TYPE_INT:
147 case VariableType::TYPE_BOOL:
148 case VariableType::TYPE_SAMPLER_2D:
149 case VariableType::TYPE_SAMPLER_CUBE:
151 for (int elemNdx = 0; elemNdx < type.getNumElements(); elemNdx++)
153 ExecValueAccess dstElem = dst.component(elemNdx);
154 ExecConstValueAccess srcElem = src.component(elemNdx);
156 for (int compNdx = 0; compNdx < EXEC_VEC_WIDTH; compNdx++)
158 if (mask.asBool(compNdx))
159 dstElem.asScalar(compNdx) = srcElem.asScalar(compNdx);
167 DE_FATAL("Unsupported");