alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 1 | // |
shannonwoods@chromium.org | e429ab7 | 2013-05-30 00:12:52 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 7 | #include "angle_gl.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 8 | #include "compiler/translator/VariableInfo.h" |
Jamie Madill | aa72d78 | 2014-07-02 15:31:19 -0400 | [diff] [blame] | 9 | #include "compiler/translator/util.h" |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 10 | #include "common/utilities.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 11 | |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 12 | static void ExpandUserDefinedVariable(const sh::ShaderVariable &variable, |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 13 | const std::string &name, |
| 14 | const std::string &mappedName, |
| 15 | bool markStaticUse, |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 16 | std::vector<sh::ShaderVariable> *expanded); |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 17 | |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 18 | static void ExpandVariable(const sh::ShaderVariable &variable, |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 19 | const std::string &name, |
| 20 | const std::string &mappedName, |
| 21 | bool markStaticUse, |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 22 | std::vector<sh::ShaderVariable> *expanded) |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 23 | { |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 24 | if (variable.isStruct()) |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 25 | { |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 26 | if (variable.isArray()) |
| 27 | { |
| 28 | for (size_t elementIndex = 0; elementIndex < variable.elementCount(); elementIndex++) |
| 29 | { |
| 30 | std::string lname = name + ArrayString(elementIndex); |
| 31 | std::string lmappedName = mappedName + ArrayString(elementIndex); |
| 32 | ExpandUserDefinedVariable(variable, lname, lmappedName, markStaticUse, expanded); |
| 33 | } |
| 34 | } |
| 35 | else |
| 36 | { |
| 37 | ExpandUserDefinedVariable(variable, name, mappedName, markStaticUse, expanded); |
| 38 | } |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 39 | } |
| 40 | else |
| 41 | { |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 42 | sh::ShaderVariable expandedVar = variable; |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 43 | |
| 44 | expandedVar.name = name; |
| 45 | expandedVar.mappedName = mappedName; |
| 46 | |
| 47 | // Mark all expanded fields as used if the parent is used |
| 48 | if (markStaticUse) |
| 49 | { |
| 50 | expandedVar.staticUse = true; |
| 51 | } |
| 52 | |
| 53 | if (expandedVar.isArray()) |
| 54 | { |
| 55 | expandedVar.name += "[0]"; |
| 56 | expandedVar.mappedName += "[0]"; |
| 57 | } |
| 58 | |
| 59 | expanded->push_back(expandedVar); |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 60 | } |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 63 | static void ExpandUserDefinedVariable(const sh::ShaderVariable &variable, |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 64 | const std::string &name, |
| 65 | const std::string &mappedName, |
| 66 | bool markStaticUse, |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 67 | std::vector<sh::ShaderVariable> *expanded) |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 68 | { |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 69 | ASSERT(variable.isStruct()); |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 70 | |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 71 | const std::vector<sh::ShaderVariable> &fields = variable.fields; |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 72 | |
| 73 | for (size_t fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++) |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 74 | { |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 75 | const sh::ShaderVariable &field = fields[fieldIndex]; |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 76 | ExpandVariable(field, |
| 77 | name + "." + field.name, |
| 78 | mappedName + "." + field.mappedName, |
| 79 | markStaticUse, |
| 80 | expanded); |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 84 | template <class VarT> |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 85 | static VarT *FindVariable(const TString &name, |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 86 | std::vector<VarT> *infoList) |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 87 | { |
| 88 | // TODO(zmo): optimize this function. |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 89 | for (size_t ii = 0; ii < infoList->size(); ++ii) |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 90 | { |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 91 | if ((*infoList)[ii].name.c_str() == name) |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 92 | return &((*infoList)[ii]); |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 93 | } |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 94 | |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 95 | return NULL; |
| 96 | } |
| 97 | |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 98 | CollectVariables::CollectVariables(std::vector<sh::Attribute> *attribs, |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 99 | std::vector<sh::Attribute> *outputVariables, |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 100 | std::vector<sh::Uniform> *uniforms, |
| 101 | std::vector<sh::Varying> *varyings, |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 102 | std::vector<sh::InterfaceBlock> *interfaceBlocks, |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 103 | ShHashFunction64 hashFunction) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 104 | : mAttribs(attribs), |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 105 | mOutputVariables(outputVariables), |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 106 | mUniforms(uniforms), |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 107 | mVaryings(varyings), |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 108 | mInterfaceBlocks(interfaceBlocks), |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 109 | mPointCoordAdded(false), |
| 110 | mFrontFacingAdded(false), |
| 111 | mFragCoordAdded(false), |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 112 | mHashFunction(hashFunction) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 113 | { |
| 114 | } |
| 115 | |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 116 | // We want to check whether a uniform/varying is statically used |
| 117 | // because we only count the used ones in packing computing. |
| 118 | // Also, gl_FragCoord, gl_PointCoord, and gl_FrontFacing count |
| 119 | // toward varying counting if they are statically used in a fragment |
| 120 | // shader. |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 121 | void CollectVariables::visitSymbol(TIntermSymbol *symbol) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 122 | { |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 123 | ASSERT(symbol != NULL); |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 124 | sh::ShaderVariable *var = NULL; |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 125 | const TString &symbolName = symbol->getSymbol(); |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 126 | |
| 127 | if (sh::IsVarying(symbol->getQualifier())) |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 128 | { |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 129 | var = FindVariable(symbolName, mVaryings); |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 130 | } |
Jamie Madill | b547ddf | 2014-08-25 16:20:46 -0400 | [diff] [blame^] | 131 | else if (symbol->getType().getBasicType() == EbtInterfaceBlock) |
| 132 | { |
| 133 | UNREACHABLE(); |
| 134 | } |
| 135 | else |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 136 | { |
| 137 | switch (symbol->getQualifier()) |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 138 | { |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 139 | case EvqAttribute: |
| 140 | case EvqVertexIn: |
| 141 | var = FindVariable(symbolName, mAttribs); |
| 142 | break; |
| 143 | case EvqFragmentOut: |
| 144 | var = FindVariable(symbolName, mOutputVariables); |
| 145 | break; |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 146 | case EvqUniform: |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 147 | { |
| 148 | const TInterfaceBlock *interfaceBlock = symbol->getType().getInterfaceBlock(); |
| 149 | if (interfaceBlock) |
| 150 | { |
| 151 | sh::InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks); |
| 152 | ASSERT(namedBlock); |
| 153 | var = FindVariable(symbolName, &namedBlock->fields); |
| 154 | |
| 155 | // Set static use on the parent interface block here |
| 156 | namedBlock->staticUse = true; |
Jamie Madill | b547ddf | 2014-08-25 16:20:46 -0400 | [diff] [blame^] | 157 | |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 158 | } |
| 159 | else |
| 160 | { |
| 161 | var = FindVariable(symbolName, mUniforms); |
| 162 | } |
| 163 | |
| 164 | // It's an internal error to reference an undefined user uniform |
| 165 | ASSERT(symbolName.compare(0, 3, "gl_") == 0 || var); |
| 166 | } |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 167 | break; |
| 168 | case EvqFragCoord: |
| 169 | if (!mFragCoordAdded) |
| 170 | { |
| 171 | sh::Varying info; |
| 172 | info.name = "gl_FragCoord"; |
| 173 | info.mappedName = "gl_FragCoord"; |
| 174 | info.type = GL_FLOAT_VEC4; |
| 175 | info.arraySize = 0; |
| 176 | info.precision = GL_MEDIUM_FLOAT; // Use mediump as it doesn't really matter. |
| 177 | info.staticUse = true; |
| 178 | mVaryings->push_back(info); |
| 179 | mFragCoordAdded = true; |
| 180 | } |
| 181 | return; |
| 182 | case EvqFrontFacing: |
| 183 | if (!mFrontFacingAdded) |
| 184 | { |
| 185 | sh::Varying info; |
| 186 | info.name = "gl_FrontFacing"; |
| 187 | info.mappedName = "gl_FrontFacing"; |
| 188 | info.type = GL_BOOL; |
| 189 | info.arraySize = 0; |
| 190 | info.precision = GL_NONE; |
| 191 | info.staticUse = true; |
| 192 | mVaryings->push_back(info); |
| 193 | mFrontFacingAdded = true; |
| 194 | } |
| 195 | return; |
| 196 | case EvqPointCoord: |
| 197 | if (!mPointCoordAdded) |
| 198 | { |
| 199 | sh::Varying info; |
| 200 | info.name = "gl_PointCoord"; |
| 201 | info.mappedName = "gl_PointCoord"; |
| 202 | info.type = GL_FLOAT_VEC2; |
| 203 | info.arraySize = 0; |
| 204 | info.precision = GL_MEDIUM_FLOAT; // Use mediump as it doesn't really matter. |
| 205 | info.staticUse = true; |
| 206 | mVaryings->push_back(info); |
| 207 | mPointCoordAdded = true; |
| 208 | } |
| 209 | return; |
| 210 | default: |
| 211 | break; |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 212 | } |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 213 | } |
| 214 | if (var) |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 215 | { |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 216 | var->staticUse = true; |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 217 | } |
| 218 | } |
| 219 | |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 220 | class NameHashingTraverser : public sh::GetVariableTraverser |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 221 | { |
| 222 | public: |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 223 | NameHashingTraverser(ShHashFunction64 hashFunction) |
| 224 | : mHashFunction(hashFunction) |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 225 | {} |
| 226 | |
| 227 | private: |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 228 | DISALLOW_COPY_AND_ASSIGN(NameHashingTraverser); |
| 229 | |
| 230 | virtual void visitVariable(sh::ShaderVariable *variable) |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 231 | { |
| 232 | TString stringName = TString(variable->name.c_str()); |
| 233 | variable->mappedName = TIntermTraverser::hash(stringName, mHashFunction).c_str(); |
| 234 | } |
| 235 | |
| 236 | ShHashFunction64 mHashFunction; |
| 237 | }; |
| 238 | |
| 239 | // Attributes, which cannot have struct fields, are a special case |
| 240 | template <> |
| 241 | void CollectVariables::visitVariable(const TIntermSymbol *variable, |
| 242 | std::vector<sh::Attribute> *infoList) const |
| 243 | { |
| 244 | ASSERT(variable); |
| 245 | const TType &type = variable->getType(); |
| 246 | ASSERT(!type.getStruct()); |
| 247 | |
| 248 | sh::Attribute attribute; |
| 249 | |
| 250 | attribute.type = sh::GLVariableType(type); |
| 251 | attribute.precision = sh::GLVariablePrecision(type); |
| 252 | attribute.name = variable->getSymbol().c_str(); |
| 253 | attribute.arraySize = static_cast<unsigned int>(type.getArraySize()); |
| 254 | attribute.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str(); |
| 255 | attribute.location = variable->getType().getLayoutQualifier().location; |
| 256 | |
| 257 | infoList->push_back(attribute); |
| 258 | } |
| 259 | |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 260 | template <> |
| 261 | void CollectVariables::visitVariable(const TIntermSymbol *variable, |
| 262 | std::vector<sh::InterfaceBlock> *infoList) const |
| 263 | { |
| 264 | sh::InterfaceBlock interfaceBlock; |
| 265 | const TInterfaceBlock *blockType = variable->getType().getInterfaceBlock(); |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 266 | ASSERT(blockType); |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 267 | |
| 268 | interfaceBlock.name = blockType->name().c_str(); |
| 269 | interfaceBlock.mappedName = TIntermTraverser::hash(variable->getSymbol(), mHashFunction).c_str(); |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 270 | interfaceBlock.instanceName = (blockType->hasInstanceName() ? blockType->instanceName().c_str() : ""); |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 271 | interfaceBlock.arraySize = variable->getArraySize(); |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 272 | interfaceBlock.isRowMajorLayout = (blockType->matrixPacking() == EmpRowMajor); |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 273 | interfaceBlock.layout = sh::GetBlockLayoutType(blockType->blockStorage()); |
| 274 | |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 275 | sh::GetInterfaceBlockFields(*blockType, &interfaceBlock.fields); |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 276 | |
| 277 | infoList->push_back(interfaceBlock); |
| 278 | } |
| 279 | |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 280 | template <typename VarT> |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 281 | void CollectVariables::visitVariable(const TIntermSymbol *variable, |
| 282 | std::vector<VarT> *infoList) const |
| 283 | { |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 284 | NameHashingTraverser traverser(mHashFunction); |
| 285 | traverser.traverse(variable->getType(), variable->getSymbol(), infoList); |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | template <typename VarT> |
| 289 | void CollectVariables::visitInfoList(const TIntermSequence &sequence, |
| 290 | std::vector<VarT> *infoList) const |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 291 | { |
| 292 | for (size_t seqIndex = 0; seqIndex < sequence.size(); seqIndex++) |
| 293 | { |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 294 | const TIntermSymbol *variable = sequence[seqIndex]->getAsSymbolNode(); |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 295 | // The only case in which the sequence will not contain a |
| 296 | // TIntermSymbol node is initialization. It will contain a |
| 297 | // TInterBinary node in that case. Since attributes, uniforms, |
| 298 | // and varyings cannot be initialized in a shader, we must have |
| 299 | // only TIntermSymbol nodes in the sequence. |
| 300 | ASSERT(variable != NULL); |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 301 | visitVariable(variable, infoList); |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 302 | } |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 305 | bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node) |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 306 | { |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 307 | bool visitChildren = true; |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 308 | |
| 309 | switch (node->getOp()) |
| 310 | { |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 311 | case EOpDeclaration: |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 312 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 313 | const TIntermSequence &sequence = *(node->getSequence()); |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 314 | ASSERT(!sequence.empty()); |
| 315 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 316 | const TIntermTyped &typedNode = *(sequence.front()->getAsTyped()); |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 317 | TQualifier qualifier = typedNode.getQualifier(); |
| 318 | |
| 319 | if (typedNode.getBasicType() == EbtInterfaceBlock) |
| 320 | { |
| 321 | visitInfoList(sequence, mInterfaceBlocks); |
Jamie Madill | b547ddf | 2014-08-25 16:20:46 -0400 | [diff] [blame^] | 322 | visitChildren = false; |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 323 | } |
| 324 | else if (qualifier == EvqAttribute || qualifier == EvqVertexIn || |
| 325 | qualifier == EvqFragmentOut || qualifier == EvqUniform || |
| 326 | sh::IsVarying(qualifier)) |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 327 | { |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 328 | switch (qualifier) |
| 329 | { |
| 330 | case EvqAttribute: |
| 331 | case EvqVertexIn: |
| 332 | visitInfoList(sequence, mAttribs); |
| 333 | break; |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 334 | case EvqFragmentOut: |
| 335 | visitInfoList(sequence, mOutputVariables); |
| 336 | break; |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 337 | case EvqUniform: |
| 338 | visitInfoList(sequence, mUniforms); |
| 339 | break; |
| 340 | default: |
Jamie Madill | 3b5c2da | 2014-08-19 15:23:32 -0400 | [diff] [blame] | 341 | visitInfoList(sequence, mVaryings); |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 342 | break; |
| 343 | } |
Zhenyao Mo | 74da9f2 | 2013-09-23 14:57:01 -0400 | [diff] [blame] | 344 | |
Jamie Madill | 1c28e1f | 2014-08-04 11:37:54 -0400 | [diff] [blame] | 345 | visitChildren = false; |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 346 | } |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 347 | break; |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 348 | } |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 349 | default: break; |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | return visitChildren; |
| 353 | } |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 354 | |
Jamie Madill | b547ddf | 2014-08-25 16:20:46 -0400 | [diff] [blame^] | 355 | bool CollectVariables::visitBinary(Visit, TIntermBinary *binaryNode) |
| 356 | { |
| 357 | if (binaryNode->getOp() == EOpIndexDirectInterfaceBlock) |
| 358 | { |
| 359 | TIntermSymbol *symbol = binaryNode->getLeft()->getAsSymbolNode(); |
| 360 | ASSERT(symbol); |
| 361 | |
| 362 | TIntermConstantUnion *constantUnion = binaryNode->getRight()->getAsConstantUnion(); |
| 363 | ASSERT(constantUnion); |
| 364 | |
| 365 | const TInterfaceBlock *interfaceBlock = symbol->getType().getInterfaceBlock(); |
| 366 | sh::InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), mInterfaceBlocks); |
| 367 | ASSERT(namedBlock); |
| 368 | namedBlock->staticUse = true; |
| 369 | |
| 370 | unsigned int fieldIndex = constantUnion->getUConst(0); |
| 371 | ASSERT(fieldIndex < namedBlock->fields.size()); |
| 372 | namedBlock->fields[fieldIndex].staticUse = true; |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | return true; |
| 377 | } |
| 378 | |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 379 | template <typename VarT> |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 380 | void ExpandVariables(const std::vector<VarT> &compact, |
| 381 | std::vector<sh::ShaderVariable> *expanded) |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 382 | { |
| 383 | for (size_t variableIndex = 0; variableIndex < compact.size(); variableIndex++) |
| 384 | { |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 385 | const sh::ShaderVariable &variable = compact[variableIndex]; |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 386 | ExpandVariable(variable, variable.name, variable.mappedName, variable.staticUse, expanded); |
| 387 | } |
| 388 | } |
| 389 | |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 390 | template void ExpandVariables(const std::vector<sh::Uniform> &, std::vector<sh::ShaderVariable> *); |
| 391 | template void ExpandVariables(const std::vector<sh::Varying> &, std::vector<sh::ShaderVariable> *); |