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 | // |
Olli Etuaho | 78ed6cd | 2017-08-09 16:19:00 +0300 | [diff] [blame] | 6 | // CollectVariables.cpp: Collect lists of shader interface variables based on the AST. |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 7 | |
Olli Etuaho | 78ed6cd | 2017-08-09 16:19:00 +0300 | [diff] [blame] | 8 | #include "compiler/translator/CollectVariables.h" |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 9 | |
| 10 | #include "angle_gl.h" |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 11 | #include "common/utilities.h" |
Olli Etuaho | cccf2b0 | 2017-07-05 14:50:54 +0300 | [diff] [blame] | 12 | #include "compiler/translator/HashNames.h" |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 13 | #include "compiler/translator/SymbolTable.h" |
Olli Etuaho | c26214d | 2018-03-16 10:43:11 +0200 | [diff] [blame] | 14 | #include "compiler/translator/tree_util/IntermTraverse.h" |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 15 | #include "compiler/translator/util.h" |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 16 | |
Jamie Madill | a2fbb84 | 2014-09-03 09:40:47 -0400 | [diff] [blame] | 17 | namespace sh |
| 18 | { |
| 19 | |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 20 | namespace |
| 21 | { |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 22 | |
Jamie Madill | a2fbb84 | 2014-09-03 09:40:47 -0400 | [diff] [blame] | 23 | BlockLayoutType GetBlockLayoutType(TLayoutBlockStorage blockStorage) |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 24 | { |
| 25 | switch (blockStorage) |
| 26 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 27 | case EbsPacked: |
| 28 | return BLOCKLAYOUT_PACKED; |
| 29 | case EbsShared: |
| 30 | return BLOCKLAYOUT_SHARED; |
| 31 | case EbsStd140: |
Qin Jiajia | ca68d98 | 2017-09-18 16:41:56 +0800 | [diff] [blame] | 32 | return BLOCKLAYOUT_STD140; |
| 33 | case EbsStd430: |
| 34 | return BLOCKLAYOUT_STD430; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 35 | default: |
| 36 | UNREACHABLE(); |
| 37 | return BLOCKLAYOUT_SHARED; |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 38 | } |
| 39 | } |
| 40 | |
Jiawei Shao | bd924af | 2017-11-16 15:28:04 +0800 | [diff] [blame] | 41 | // TODO(jiawei.shao@intel.com): implement GL_EXT_shader_io_blocks. |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 42 | BlockType GetBlockType(TQualifier qualifier) |
| 43 | { |
| 44 | switch (qualifier) |
| 45 | { |
| 46 | case EvqUniform: |
| 47 | return BlockType::BLOCK_UNIFORM; |
| 48 | case EvqBuffer: |
| 49 | return BlockType::BLOCK_BUFFER; |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 50 | case EvqPerVertexIn: |
| 51 | return BlockType::BLOCK_IN; |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 52 | default: |
| 53 | UNREACHABLE(); |
| 54 | return BlockType::BLOCK_UNIFORM; |
| 55 | } |
| 56 | } |
| 57 | |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 58 | template <class VarT> |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 59 | VarT *FindVariable(const ImmutableString &name, std::vector<VarT> *infoList) |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 60 | { |
| 61 | // TODO(zmo): optimize this function. |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 62 | for (size_t ii = 0; ii < infoList->size(); ++ii) |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 63 | { |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 64 | if (name == (*infoList)[ii].name) |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 65 | return &((*infoList)[ii]); |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 66 | } |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 67 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 68 | return nullptr; |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 69 | } |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 70 | |
Olli Etuaho | 06a06f5 | 2017-07-12 12:22:15 +0300 | [diff] [blame] | 71 | // Note that this shouldn't be called for interface blocks - static use information is collected for |
| 72 | // individual fields in case of interface blocks. |
| 73 | void MarkStaticallyUsed(ShaderVariable *variable) |
| 74 | { |
| 75 | if (!variable->staticUse) |
| 76 | { |
| 77 | if (variable->isStruct()) |
| 78 | { |
| 79 | // Conservatively assume all fields are statically used as well. |
| 80 | for (auto &field : variable->fields) |
| 81 | { |
| 82 | MarkStaticallyUsed(&field); |
| 83 | } |
| 84 | } |
| 85 | variable->staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 86 | variable->active = true; |
Olli Etuaho | 06a06f5 | 2017-07-12 12:22:15 +0300 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 90 | ShaderVariable *FindVariableInInterfaceBlock(const ImmutableString &name, |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 91 | const TInterfaceBlock *interfaceBlock, |
| 92 | std::vector<InterfaceBlock> *infoList) |
| 93 | { |
| 94 | ASSERT(interfaceBlock); |
Olli Etuaho | bed35d7 | 2017-12-20 16:36:26 +0200 | [diff] [blame] | 95 | InterfaceBlock *namedBlock = FindVariable(interfaceBlock->name(), infoList); |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 96 | ASSERT(namedBlock); |
| 97 | |
| 98 | // Set static use on the parent interface block here |
| 99 | namedBlock->staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 100 | namedBlock->active = true; |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 101 | return FindVariable(name, &namedBlock->fields); |
| 102 | } |
| 103 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 104 | // Traverses the intermediate tree to collect all attributes, uniforms, varyings, fragment outputs, |
| 105 | // and interface blocks. |
| 106 | class CollectVariablesTraverser : public TIntermTraverser |
| 107 | { |
| 108 | public: |
| 109 | CollectVariablesTraverser(std::vector<Attribute> *attribs, |
| 110 | std::vector<OutputVariable> *outputVariables, |
| 111 | std::vector<Uniform> *uniforms, |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 112 | std::vector<Varying> *inputVaryings, |
| 113 | std::vector<Varying> *outputVaryings, |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 114 | std::vector<InterfaceBlock> *uniformBlocks, |
| 115 | std::vector<InterfaceBlock> *shaderStorageBlocks, |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 116 | std::vector<InterfaceBlock> *inBlocks, |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 117 | ShHashFunction64 hashFunction, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 118 | TSymbolTable *symbolTable, |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 119 | GLenum shaderType, |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 120 | const TExtensionBehavior &extensionBehavior); |
| 121 | |
| 122 | void visitSymbol(TIntermSymbol *symbol) override; |
| 123 | bool visitDeclaration(Visit, TIntermDeclaration *node) override; |
| 124 | bool visitBinary(Visit visit, TIntermBinary *binaryNode) override; |
| 125 | |
| 126 | private: |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 127 | std::string getMappedName(const TSymbol *symbol) const; |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 128 | |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 129 | void setFieldOrVariableProperties(const TType &type, ShaderVariable *variableOut) const; |
| 130 | void setFieldProperties(const TType &type, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 131 | const ImmutableString &name, |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 132 | ShaderVariable *variableOut) const; |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 133 | void setCommonVariableProperties(const TType &type, |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 134 | const TVariable &variable, |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 135 | ShaderVariable *variableOut) const; |
| 136 | |
| 137 | Attribute recordAttribute(const TIntermSymbol &variable) const; |
| 138 | OutputVariable recordOutputVariable(const TIntermSymbol &variable) const; |
| 139 | Varying recordVarying(const TIntermSymbol &variable) const; |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 140 | void recordInterfaceBlock(const char *instanceName, |
Olli Etuaho | 12a18ad | 2017-12-01 16:59:47 +0200 | [diff] [blame] | 141 | const TType &interfaceBlockType, |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 142 | InterfaceBlock *interfaceBlock) const; |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 143 | Uniform recordUniform(const TIntermSymbol &variable) const; |
| 144 | |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 145 | void setBuiltInInfoFromSymbol(const TVariable &variable, ShaderVariable *info); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 146 | |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 147 | void recordBuiltInVaryingUsed(const TVariable &variable, |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 148 | bool *addedFlag, |
| 149 | std::vector<Varying> *varyings); |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 150 | void recordBuiltInFragmentOutputUsed(const TVariable &variable, bool *addedFlag); |
| 151 | void recordBuiltInAttributeUsed(const TVariable &variable, bool *addedFlag); |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 152 | InterfaceBlock *recordGLInUsed(const TType &glInType); |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 153 | InterfaceBlock *findNamedInterfaceBlock(const ImmutableString &name) const; |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 154 | |
| 155 | std::vector<Attribute> *mAttribs; |
| 156 | std::vector<OutputVariable> *mOutputVariables; |
| 157 | std::vector<Uniform> *mUniforms; |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 158 | std::vector<Varying> *mInputVaryings; |
| 159 | std::vector<Varying> *mOutputVaryings; |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 160 | std::vector<InterfaceBlock> *mUniformBlocks; |
| 161 | std::vector<InterfaceBlock> *mShaderStorageBlocks; |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 162 | std::vector<InterfaceBlock> *mInBlocks; |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 163 | |
| 164 | std::map<std::string, InterfaceBlockField *> mInterfaceBlockFields; |
| 165 | |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 166 | // Shader uniforms |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 167 | bool mDepthRangeAdded; |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 168 | |
| 169 | // Vertex Shader builtins |
| 170 | bool mInstanceIDAdded; |
| 171 | bool mVertexIDAdded; |
| 172 | bool mPointSizeAdded; |
| 173 | |
| 174 | // Vertex Shader and Geometry Shader builtins |
| 175 | bool mPositionAdded; |
| 176 | |
| 177 | // Fragment Shader builtins |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 178 | bool mPointCoordAdded; |
| 179 | bool mFrontFacingAdded; |
| 180 | bool mFragCoordAdded; |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 181 | bool mLastFragDataAdded; |
| 182 | bool mFragColorAdded; |
| 183 | bool mFragDataAdded; |
| 184 | bool mFragDepthEXTAdded; |
| 185 | bool mFragDepthAdded; |
| 186 | bool mSecondaryFragColorEXTAdded; |
| 187 | bool mSecondaryFragDataEXTAdded; |
| 188 | |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 189 | // Geometry Shader builtins |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 190 | bool mPerVertexInAdded; |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 191 | bool mPrimitiveIDInAdded; |
| 192 | bool mInvocationIDAdded; |
| 193 | |
| 194 | // Geometry Shader and Fragment Shader builtins |
| 195 | bool mPrimitiveIDAdded; |
| 196 | bool mLayerAdded; |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 197 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 198 | ShHashFunction64 mHashFunction; |
| 199 | |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 200 | GLenum mShaderType; |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 201 | const TExtensionBehavior &mExtensionBehavior; |
| 202 | }; |
| 203 | |
| 204 | CollectVariablesTraverser::CollectVariablesTraverser( |
| 205 | std::vector<sh::Attribute> *attribs, |
| 206 | std::vector<sh::OutputVariable> *outputVariables, |
| 207 | std::vector<sh::Uniform> *uniforms, |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 208 | std::vector<sh::Varying> *inputVaryings, |
| 209 | std::vector<sh::Varying> *outputVaryings, |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 210 | std::vector<sh::InterfaceBlock> *uniformBlocks, |
| 211 | std::vector<sh::InterfaceBlock> *shaderStorageBlocks, |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 212 | std::vector<sh::InterfaceBlock> *inBlocks, |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 213 | ShHashFunction64 hashFunction, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 214 | TSymbolTable *symbolTable, |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 215 | GLenum shaderType, |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 216 | const TExtensionBehavior &extensionBehavior) |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 217 | : TIntermTraverser(true, false, false, symbolTable), |
Olli Etuaho | 3d0d9a4 | 2015-06-01 12:16:36 +0300 | [diff] [blame] | 218 | mAttribs(attribs), |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 219 | mOutputVariables(outputVariables), |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 220 | mUniforms(uniforms), |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 221 | mInputVaryings(inputVaryings), |
| 222 | mOutputVaryings(outputVaryings), |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 223 | mUniformBlocks(uniformBlocks), |
| 224 | mShaderStorageBlocks(shaderStorageBlocks), |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 225 | mInBlocks(inBlocks), |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 226 | mDepthRangeAdded(false), |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 227 | mInstanceIDAdded(false), |
| 228 | mVertexIDAdded(false), |
| 229 | mPointSizeAdded(false), |
| 230 | mPositionAdded(false), |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 231 | mPointCoordAdded(false), |
| 232 | mFrontFacingAdded(false), |
| 233 | mFragCoordAdded(false), |
Erik Dahlström | ea7a212 | 2014-11-17 16:15:57 +0100 | [diff] [blame] | 234 | mLastFragDataAdded(false), |
Kimmo Kinnunen | 0932df6 | 2015-07-21 14:35:11 +0300 | [diff] [blame] | 235 | mFragColorAdded(false), |
| 236 | mFragDataAdded(false), |
Kimmo Kinnunen | 5f0246c | 2015-07-22 10:30:35 +0300 | [diff] [blame] | 237 | mFragDepthEXTAdded(false), |
Kimmo Kinnunen | 0932df6 | 2015-07-21 14:35:11 +0300 | [diff] [blame] | 238 | mFragDepthAdded(false), |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 239 | mSecondaryFragColorEXTAdded(false), |
| 240 | mSecondaryFragDataEXTAdded(false), |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 241 | mPerVertexInAdded(false), |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 242 | mPrimitiveIDInAdded(false), |
| 243 | mInvocationIDAdded(false), |
| 244 | mPrimitiveIDAdded(false), |
| 245 | mLayerAdded(false), |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 246 | mHashFunction(hashFunction), |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 247 | mShaderType(shaderType), |
Zhenyao Mo | f178d0b | 2016-07-23 06:59:00 -0700 | [diff] [blame] | 248 | mExtensionBehavior(extensionBehavior) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 249 | { |
| 250 | } |
| 251 | |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 252 | std::string CollectVariablesTraverser::getMappedName(const TSymbol *symbol) const |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 253 | { |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 254 | return HashName(symbol, mHashFunction, nullptr).data(); |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 255 | } |
| 256 | |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 257 | void CollectVariablesTraverser::setBuiltInInfoFromSymbol(const TVariable &variable, |
| 258 | ShaderVariable *info) |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 259 | { |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 260 | const TType &type = variable.getType(); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 261 | |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 262 | info->name = variable.name().data(); |
| 263 | info->mappedName = variable.name().data(); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 264 | info->type = GLVariableType(type); |
Olli Etuaho | 96f6adf | 2017-08-16 11:18:54 +0300 | [diff] [blame] | 265 | info->precision = GLVariablePrecision(type); |
Kai Ninomiya | 57ea533 | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 266 | if (auto *arraySizes = type.getArraySizes()) |
| 267 | { |
| 268 | info->arraySizes.assign(arraySizes->begin(), arraySizes->end()); |
| 269 | } |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 270 | } |
| 271 | |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 272 | void CollectVariablesTraverser::recordBuiltInVaryingUsed(const TVariable &variable, |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 273 | bool *addedFlag, |
| 274 | std::vector<Varying> *varyings) |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 275 | { |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 276 | ASSERT(varyings); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 277 | if (!(*addedFlag)) |
| 278 | { |
| 279 | Varying info; |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 280 | setBuiltInInfoFromSymbol(variable, &info); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 281 | info.staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 282 | info.active = true; |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 283 | info.isInvariant = mSymbolTable->isVaryingInvariant(variable.name()); |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 284 | varyings->push_back(info); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 285 | (*addedFlag) = true; |
| 286 | } |
| 287 | } |
| 288 | |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 289 | void CollectVariablesTraverser::recordBuiltInFragmentOutputUsed(const TVariable &variable, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 290 | bool *addedFlag) |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 291 | { |
| 292 | if (!(*addedFlag)) |
| 293 | { |
| 294 | OutputVariable info; |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 295 | setBuiltInInfoFromSymbol(variable, &info); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 296 | info.staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 297 | info.active = true; |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 298 | mOutputVariables->push_back(info); |
| 299 | (*addedFlag) = true; |
| 300 | } |
| 301 | } |
| 302 | |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 303 | void CollectVariablesTraverser::recordBuiltInAttributeUsed(const TVariable &variable, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 304 | bool *addedFlag) |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 305 | { |
| 306 | if (!(*addedFlag)) |
| 307 | { |
| 308 | Attribute info; |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 309 | setBuiltInInfoFromSymbol(variable, &info); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 310 | info.staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 311 | info.active = true; |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 312 | info.location = -1; |
| 313 | mAttribs->push_back(info); |
| 314 | (*addedFlag) = true; |
| 315 | } |
| 316 | } |
| 317 | |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 318 | InterfaceBlock *CollectVariablesTraverser::recordGLInUsed(const TType &glInType) |
| 319 | { |
| 320 | if (!mPerVertexInAdded) |
| 321 | { |
| 322 | ASSERT(glInType.getQualifier() == EvqPerVertexIn); |
| 323 | InterfaceBlock info; |
Olli Etuaho | 12a18ad | 2017-12-01 16:59:47 +0200 | [diff] [blame] | 324 | recordInterfaceBlock("gl_in", glInType, &info); |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 325 | info.staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 326 | info.active = true; |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 327 | |
| 328 | mPerVertexInAdded = true; |
| 329 | mInBlocks->push_back(info); |
| 330 | return &mInBlocks->back(); |
| 331 | } |
| 332 | else |
| 333 | { |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 334 | return FindVariable(ImmutableString("gl_PerVertex"), mInBlocks); |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 338 | // We want to check whether a uniform/varying is statically used |
| 339 | // because we only count the used ones in packing computing. |
| 340 | // Also, gl_FragCoord, gl_PointCoord, and gl_FrontFacing count |
| 341 | // toward varying counting if they are statically used in a fragment |
| 342 | // shader. |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 343 | void CollectVariablesTraverser::visitSymbol(TIntermSymbol *symbol) |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 344 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 345 | ASSERT(symbol != nullptr); |
Olli Etuaho | 34d2007 | 2017-07-18 20:07:18 +0300 | [diff] [blame] | 346 | |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 347 | if (symbol->variable().symbolType() == SymbolType::AngleInternal || |
| 348 | symbol->variable().symbolType() == SymbolType::Empty) |
Olli Etuaho | 34d2007 | 2017-07-18 20:07:18 +0300 | [diff] [blame] | 349 | { |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 350 | // Internal variables or nameless variables are not collected. |
Olli Etuaho | 34d2007 | 2017-07-18 20:07:18 +0300 | [diff] [blame] | 351 | return; |
| 352 | } |
| 353 | |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 354 | ShaderVariable *var = nullptr; |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 355 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 356 | const ImmutableString &symbolName = symbol->getName(); |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 357 | |
Olli Etuaho | b8cb939 | 2017-12-20 14:23:19 +0200 | [diff] [blame] | 358 | // Check the qualifier from the variable, not from the symbol node. The node may have a |
| 359 | // different qualifier if it's the result of a folded ternary node. |
| 360 | TQualifier qualifier = symbol->variable().getType().getQualifier(); |
| 361 | |
| 362 | if (IsVaryingIn(qualifier)) |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 363 | { |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 364 | var = FindVariable(symbolName, mInputVaryings); |
| 365 | } |
Olli Etuaho | b8cb939 | 2017-12-20 14:23:19 +0200 | [diff] [blame] | 366 | else if (IsVaryingOut(qualifier)) |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 367 | { |
| 368 | var = FindVariable(symbolName, mOutputVaryings); |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 369 | } |
Jamie Madill | b547ddf | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 370 | else if (symbol->getType().getBasicType() == EbtInterfaceBlock) |
| 371 | { |
| 372 | UNREACHABLE(); |
| 373 | } |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 374 | else if (symbolName == "gl_DepthRange") |
| 375 | { |
Olli Etuaho | b8cb939 | 2017-12-20 14:23:19 +0200 | [diff] [blame] | 376 | ASSERT(qualifier == EvqUniform); |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 377 | |
| 378 | if (!mDepthRangeAdded) |
| 379 | { |
| 380 | Uniform info; |
| 381 | const char kName[] = "gl_DepthRange"; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 382 | info.name = kName; |
| 383 | info.mappedName = kName; |
Jamie Madill | f00f7ff | 2017-08-31 14:39:15 -0400 | [diff] [blame] | 384 | info.type = GL_NONE; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 385 | info.precision = GL_NONE; |
| 386 | info.staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 387 | info.active = true; |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 388 | |
Olli Etuaho | e7c2857 | 2017-10-23 16:29:33 +0300 | [diff] [blame] | 389 | ShaderVariable nearInfo(GL_FLOAT); |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 390 | const char kNearName[] = "near"; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 391 | nearInfo.name = kNearName; |
| 392 | nearInfo.mappedName = kNearName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 393 | nearInfo.precision = GL_HIGH_FLOAT; |
| 394 | nearInfo.staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 395 | nearInfo.active = true; |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 396 | |
Olli Etuaho | e7c2857 | 2017-10-23 16:29:33 +0300 | [diff] [blame] | 397 | ShaderVariable farInfo(GL_FLOAT); |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 398 | const char kFarName[] = "far"; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 399 | farInfo.name = kFarName; |
| 400 | farInfo.mappedName = kFarName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 401 | farInfo.precision = GL_HIGH_FLOAT; |
| 402 | farInfo.staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 403 | farInfo.active = true; |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 404 | |
Olli Etuaho | e7c2857 | 2017-10-23 16:29:33 +0300 | [diff] [blame] | 405 | ShaderVariable diffInfo(GL_FLOAT); |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 406 | const char kDiffName[] = "diff"; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 407 | diffInfo.name = kDiffName; |
| 408 | diffInfo.mappedName = kDiffName; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 409 | diffInfo.precision = GL_HIGH_FLOAT; |
| 410 | diffInfo.staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 411 | diffInfo.active = true; |
Jamie Madill | 55def58 | 2015-05-04 11:24:57 -0400 | [diff] [blame] | 412 | |
| 413 | info.fields.push_back(nearInfo); |
| 414 | info.fields.push_back(farInfo); |
| 415 | info.fields.push_back(diffInfo); |
| 416 | |
| 417 | mUniforms->push_back(info); |
| 418 | mDepthRangeAdded = true; |
| 419 | } |
| 420 | } |
Jamie Madill | b547ddf | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 421 | else |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 422 | { |
Olli Etuaho | b8cb939 | 2017-12-20 14:23:19 +0200 | [diff] [blame] | 423 | switch (qualifier) |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 424 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 425 | case EvqAttribute: |
| 426 | case EvqVertexIn: |
| 427 | var = FindVariable(symbolName, mAttribs); |
| 428 | break; |
| 429 | case EvqFragmentOut: |
| 430 | var = FindVariable(symbolName, mOutputVariables); |
| 431 | break; |
| 432 | case EvqUniform: |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 433 | { |
| 434 | const TInterfaceBlock *interfaceBlock = symbol->getType().getInterfaceBlock(); |
| 435 | if (interfaceBlock) |
| 436 | { |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 437 | var = FindVariableInInterfaceBlock(symbolName, interfaceBlock, mUniformBlocks); |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 438 | } |
| 439 | else |
| 440 | { |
| 441 | var = FindVariable(symbolName, mUniforms); |
| 442 | } |
| 443 | |
| 444 | // It's an internal error to reference an undefined user uniform |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 445 | ASSERT(!symbolName.beginsWith("gl_") || var); |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 446 | } |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 447 | break; |
Jiajia Qin | 3a9090f | 2017-09-27 14:37:04 +0800 | [diff] [blame] | 448 | case EvqBuffer: |
| 449 | { |
| 450 | const TInterfaceBlock *interfaceBlock = symbol->getType().getInterfaceBlock(); |
| 451 | var = |
| 452 | FindVariableInInterfaceBlock(symbolName, interfaceBlock, mShaderStorageBlocks); |
| 453 | } |
| 454 | break; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 455 | case EvqFragCoord: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 456 | recordBuiltInVaryingUsed(symbol->variable(), &mFragCoordAdded, mInputVaryings); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 457 | return; |
| 458 | case EvqFrontFacing: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 459 | recordBuiltInVaryingUsed(symbol->variable(), &mFrontFacingAdded, mInputVaryings); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 460 | return; |
| 461 | case EvqPointCoord: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 462 | recordBuiltInVaryingUsed(symbol->variable(), &mPointCoordAdded, mInputVaryings); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 463 | return; |
| 464 | case EvqInstanceID: |
Martin Radev | 115fc55 | 2017-07-05 17:11:06 +0300 | [diff] [blame] | 465 | // Whenever the SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW option is set, |
| 466 | // gl_InstanceID is added inside expressions to initialize ViewID_OVR and |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 467 | // InstanceID. Note that gl_InstanceID is not added to the symbol table for ESSL1 |
| 468 | // shaders. |
| 469 | recordBuiltInAttributeUsed(symbol->variable(), &mInstanceIDAdded); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 470 | return; |
| 471 | case EvqVertexID: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 472 | recordBuiltInAttributeUsed(symbol->variable(), &mVertexIDAdded); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 473 | return; |
| 474 | case EvqPosition: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 475 | recordBuiltInVaryingUsed(symbol->variable(), &mPositionAdded, mOutputVaryings); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 476 | return; |
| 477 | case EvqPointSize: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 478 | recordBuiltInVaryingUsed(symbol->variable(), &mPointSizeAdded, mOutputVaryings); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 479 | return; |
| 480 | case EvqLastFragData: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 481 | recordBuiltInVaryingUsed(symbol->variable(), &mLastFragDataAdded, mInputVaryings); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 482 | return; |
| 483 | case EvqFragColor: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 484 | recordBuiltInFragmentOutputUsed(symbol->variable(), &mFragColorAdded); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 485 | return; |
| 486 | case EvqFragData: |
| 487 | if (!mFragDataAdded) |
| 488 | { |
| 489 | OutputVariable info; |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 490 | setBuiltInInfoFromSymbol(symbol->variable(), &info); |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 491 | if (!IsExtensionEnabled(mExtensionBehavior, TExtension::EXT_draw_buffers)) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 492 | { |
Olli Etuaho | 465835d | 2017-09-26 13:34:10 +0300 | [diff] [blame] | 493 | ASSERT(info.arraySizes.size() == 1u); |
| 494 | info.arraySizes.back() = 1u; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 495 | } |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 496 | info.staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 497 | info.active = true; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 498 | mOutputVariables->push_back(info); |
| 499 | mFragDataAdded = true; |
| 500 | } |
| 501 | return; |
| 502 | case EvqFragDepthEXT: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 503 | recordBuiltInFragmentOutputUsed(symbol->variable(), &mFragDepthEXTAdded); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 504 | return; |
| 505 | case EvqFragDepth: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 506 | recordBuiltInFragmentOutputUsed(symbol->variable(), &mFragDepthAdded); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 507 | return; |
| 508 | case EvqSecondaryFragColorEXT: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 509 | recordBuiltInFragmentOutputUsed(symbol->variable(), &mSecondaryFragColorEXTAdded); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 510 | return; |
| 511 | case EvqSecondaryFragDataEXT: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 512 | recordBuiltInFragmentOutputUsed(symbol->variable(), &mSecondaryFragDataEXTAdded); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 513 | return; |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 514 | case EvqInvocationID: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 515 | recordBuiltInVaryingUsed(symbol->variable(), &mInvocationIDAdded, mInputVaryings); |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 516 | break; |
| 517 | case EvqPrimitiveIDIn: |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 518 | recordBuiltInVaryingUsed(symbol->variable(), &mPrimitiveIDInAdded, mInputVaryings); |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 519 | break; |
| 520 | case EvqPrimitiveID: |
Jiawei Shao | bd924af | 2017-11-16 15:28:04 +0800 | [diff] [blame] | 521 | if (mShaderType == GL_GEOMETRY_SHADER_EXT) |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 522 | { |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 523 | recordBuiltInVaryingUsed(symbol->variable(), &mPrimitiveIDAdded, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 524 | mOutputVaryings); |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 525 | } |
| 526 | else |
| 527 | { |
| 528 | ASSERT(mShaderType == GL_FRAGMENT_SHADER); |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 529 | recordBuiltInVaryingUsed(symbol->variable(), &mPrimitiveIDAdded, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 530 | mInputVaryings); |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 531 | } |
| 532 | break; |
| 533 | case EvqLayer: |
Jiawei Shao | bd924af | 2017-11-16 15:28:04 +0800 | [diff] [blame] | 534 | if (mShaderType == GL_GEOMETRY_SHADER_EXT) |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 535 | { |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 536 | recordBuiltInVaryingUsed(symbol->variable(), &mLayerAdded, mOutputVaryings); |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 537 | } |
| 538 | else if (mShaderType == GL_FRAGMENT_SHADER) |
| 539 | { |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 540 | recordBuiltInVaryingUsed(symbol->variable(), &mLayerAdded, mInputVaryings); |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 541 | } |
| 542 | else |
| 543 | { |
| 544 | ASSERT(mShaderType == GL_VERTEX_SHADER && |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 545 | IsExtensionEnabled(mExtensionBehavior, TExtension::OVR_multiview)); |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 546 | } |
| 547 | break; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 548 | default: |
| 549 | break; |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 550 | } |
Zhenyao Mo | d2d340b | 2013-09-23 14:57:05 -0400 | [diff] [blame] | 551 | } |
| 552 | if (var) |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 553 | { |
Olli Etuaho | 06a06f5 | 2017-07-12 12:22:15 +0300 | [diff] [blame] | 554 | MarkStaticallyUsed(var); |
Jamie Madill | a718c1e | 2014-07-02 15:31:22 -0400 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 558 | void CollectVariablesTraverser::setFieldOrVariableProperties(const TType &type, |
| 559 | ShaderVariable *variableOut) const |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 560 | { |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 561 | ASSERT(variableOut); |
| 562 | |
| 563 | const TStructure *structure = type.getStruct(); |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 564 | if (!structure) |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 565 | { |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 566 | variableOut->type = GLVariableType(type); |
| 567 | variableOut->precision = GLVariablePrecision(type); |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 568 | } |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 569 | else |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 570 | { |
Jamie Madill | f00f7ff | 2017-08-31 14:39:15 -0400 | [diff] [blame] | 571 | // Structures use a NONE type that isn't exposed outside ANGLE. |
| 572 | variableOut->type = GL_NONE; |
Olli Etuaho | ae4dbf3 | 2017-12-08 20:49:00 +0100 | [diff] [blame] | 573 | if (structure->symbolType() != SymbolType::Empty) |
| 574 | { |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 575 | variableOut->structName = structure->name().data(); |
Olli Etuaho | ae4dbf3 | 2017-12-08 20:49:00 +0100 | [diff] [blame] | 576 | } |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 577 | |
| 578 | const TFieldList &fields = structure->fields(); |
| 579 | |
Olli Etuaho | 378c3a5 | 2017-12-04 11:32:13 +0200 | [diff] [blame] | 580 | for (const TField *field : fields) |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 581 | { |
| 582 | // Regardless of the variable type (uniform, in/out etc.) its fields are always plain |
| 583 | // ShaderVariable objects. |
| 584 | ShaderVariable fieldVariable; |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 585 | setFieldProperties(*field->type(), field->name(), &fieldVariable); |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 586 | variableOut->fields.push_back(fieldVariable); |
| 587 | } |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 588 | } |
Kai Ninomiya | 57ea533 | 2017-11-22 14:04:48 -0800 | [diff] [blame] | 589 | if (auto *arraySizes = type.getArraySizes()) |
| 590 | { |
| 591 | variableOut->arraySizes.assign(arraySizes->begin(), arraySizes->end()); |
| 592 | } |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 593 | } |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 594 | |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 595 | void CollectVariablesTraverser::setFieldProperties(const TType &type, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 596 | const ImmutableString &name, |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 597 | ShaderVariable *variableOut) const |
| 598 | { |
| 599 | ASSERT(variableOut); |
| 600 | setFieldOrVariableProperties(type, variableOut); |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 601 | variableOut->name.assign(name.data(), name.length()); |
| 602 | variableOut->mappedName = HashName(name, mHashFunction, nullptr).data(); |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | void CollectVariablesTraverser::setCommonVariableProperties(const TType &type, |
| 606 | const TVariable &variable, |
| 607 | ShaderVariable *variableOut) const |
| 608 | { |
| 609 | ASSERT(variableOut); |
| 610 | |
| 611 | setFieldOrVariableProperties(type, variableOut); |
| 612 | ASSERT(variable.symbolType() != SymbolType::Empty); |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 613 | variableOut->name.assign(variable.name().data(), variable.name().length()); |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 614 | variableOut->mappedName = getMappedName(&variable); |
| 615 | } |
| 616 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 617 | Attribute CollectVariablesTraverser::recordAttribute(const TIntermSymbol &variable) const |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 618 | { |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 619 | const TType &type = variable.getType(); |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 620 | ASSERT(!type.getStruct()); |
| 621 | |
Jamie Madill | a2fbb84 | 2014-09-03 09:40:47 -0400 | [diff] [blame] | 622 | Attribute attribute; |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 623 | setCommonVariableProperties(type, variable.variable(), &attribute); |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 624 | |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 625 | attribute.location = type.getLayoutQualifier().location; |
| 626 | return attribute; |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 627 | } |
| 628 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 629 | OutputVariable CollectVariablesTraverser::recordOutputVariable(const TIntermSymbol &variable) const |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 630 | { |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 631 | const TType &type = variable.getType(); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 632 | ASSERT(!type.getStruct()); |
| 633 | |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 634 | OutputVariable outputVariable; |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 635 | setCommonVariableProperties(type, variable.variable(), &outputVariable); |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 636 | |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 637 | outputVariable.location = type.getLayoutQualifier().location; |
| 638 | return outputVariable; |
Jamie Madill | a0a9e12 | 2015-09-02 15:54:30 -0400 | [diff] [blame] | 639 | } |
| 640 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 641 | Varying CollectVariablesTraverser::recordVarying(const TIntermSymbol &variable) const |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 642 | { |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 643 | const TType &type = variable.getType(); |
| 644 | |
| 645 | Varying varying; |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 646 | setCommonVariableProperties(type, variable.variable(), &varying); |
Jiawei Shao | 4cc89e2 | 2017-08-31 14:25:54 +0800 | [diff] [blame] | 647 | varying.location = type.getLayoutQualifier().location; |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 648 | |
| 649 | switch (type.getQualifier()) |
| 650 | { |
| 651 | case EvqVaryingIn: |
| 652 | case EvqVaryingOut: |
| 653 | case EvqVertexOut: |
| 654 | case EvqSmoothOut: |
| 655 | case EvqFlatOut: |
| 656 | case EvqCentroidOut: |
Jiawei Shao | 8e4b355 | 2017-08-30 14:20:58 +0800 | [diff] [blame] | 657 | case EvqGeometryOut: |
Olli Etuaho | defe393 | 2018-02-13 11:56:09 +0200 | [diff] [blame] | 658 | if (mSymbolTable->isVaryingInvariant(variable.getName()) || type.isInvariant()) |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 659 | { |
| 660 | varying.isInvariant = true; |
| 661 | } |
| 662 | break; |
| 663 | default: |
| 664 | break; |
| 665 | } |
| 666 | |
| 667 | varying.interpolation = GetInterpolationType(type.getQualifier()); |
| 668 | return varying; |
| 669 | } |
| 670 | |
Jiawei Shao | bd924af | 2017-11-16 15:28:04 +0800 | [diff] [blame] | 671 | // TODO(jiawei.shao@intel.com): implement GL_EXT_shader_io_blocks. |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 672 | void CollectVariablesTraverser::recordInterfaceBlock(const char *instanceName, |
Olli Etuaho | 12a18ad | 2017-12-01 16:59:47 +0200 | [diff] [blame] | 673 | const TType &interfaceBlockType, |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 674 | InterfaceBlock *interfaceBlock) const |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 675 | { |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 676 | ASSERT(interfaceBlockType.getBasicType() == EbtInterfaceBlock); |
| 677 | ASSERT(interfaceBlock); |
| 678 | |
| 679 | const TInterfaceBlock *blockType = interfaceBlockType.getInterfaceBlock(); |
Jamie Madill | 42bcf32 | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 680 | ASSERT(blockType); |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 681 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 682 | interfaceBlock->name = blockType->name().data(); |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 683 | interfaceBlock->mappedName = getMappedName(blockType); |
| 684 | if (instanceName != nullptr) |
| 685 | { |
| 686 | interfaceBlock->instanceName = instanceName; |
| 687 | } |
Olli Etuaho | 96f6adf | 2017-08-16 11:18:54 +0300 | [diff] [blame] | 688 | ASSERT(!interfaceBlockType.isArrayOfArrays()); // Disallowed by GLSL ES 3.10 section 4.3.9 |
| 689 | interfaceBlock->arraySize = interfaceBlockType.isArray() ? interfaceBlockType.getOutermostArraySize() : 0; |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 690 | |
| 691 | interfaceBlock->blockType = GetBlockType(interfaceBlockType.getQualifier()); |
| 692 | if (interfaceBlock->blockType == BlockType::BLOCK_UNIFORM || |
| 693 | interfaceBlock->blockType == BlockType::BLOCK_BUFFER) |
| 694 | { |
Olli Etuaho | 3de2703 | 2017-11-30 12:16:47 +0200 | [diff] [blame] | 695 | // TODO(oetuaho): Remove setting isRowMajorLayout. |
| 696 | interfaceBlock->isRowMajorLayout = false; |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 697 | interfaceBlock->binding = blockType->blockBinding(); |
| 698 | interfaceBlock->layout = GetBlockLayoutType(blockType->blockStorage()); |
| 699 | } |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 700 | |
Jamie Madill | a6f267f | 2014-08-27 11:44:15 -0400 | [diff] [blame] | 701 | // Gather field information |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 702 | for (const TField *field : blockType->fields()) |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 703 | { |
Jamie Madill | 3904616 | 2016-02-08 15:05:17 -0500 | [diff] [blame] | 704 | const TType &fieldType = *field->type(); |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 705 | |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 706 | InterfaceBlockField fieldVariable; |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 707 | setFieldProperties(fieldType, field->name(), &fieldVariable); |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 708 | fieldVariable.isRowMajorLayout = |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 709 | (fieldType.getLayoutQualifier().matrixPacking == EmpRowMajor); |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 710 | interfaceBlock->fields.push_back(fieldVariable); |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 711 | } |
Jamie Madill | d5512cd | 2014-07-10 17:50:08 -0400 | [diff] [blame] | 712 | } |
| 713 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 714 | Uniform CollectVariablesTraverser::recordUniform(const TIntermSymbol &variable) const |
Jamie Madill | 4667c45 | 2014-07-08 15:02:36 -0400 | [diff] [blame] | 715 | { |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 716 | Uniform uniform; |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 717 | setCommonVariableProperties(variable.getType(), variable.variable(), &uniform); |
Olli Etuaho | 78ed6cd | 2017-08-09 16:19:00 +0300 | [diff] [blame] | 718 | uniform.binding = variable.getType().getLayoutQualifier().binding; |
Olli Etuaho | 6ca2b65 | 2017-02-19 18:05:10 +0000 | [diff] [blame] | 719 | uniform.location = variable.getType().getLayoutQualifier().location; |
jchen10 | 4cdac9e | 2017-05-08 11:01:20 +0800 | [diff] [blame] | 720 | uniform.offset = variable.getType().getLayoutQualifier().offset; |
Xinghua Cao | 26143fd | 2017-11-01 18:19:05 +0800 | [diff] [blame] | 721 | uniform.readonly = variable.getType().getMemoryQualifier().readonly; |
| 722 | uniform.writeonly = variable.getType().getMemoryQualifier().writeonly; |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 723 | return uniform; |
alokp@chromium.org | 07620a5 | 2010-09-23 17:53:56 +0000 | [diff] [blame] | 724 | } |
| 725 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 726 | bool CollectVariablesTraverser::visitDeclaration(Visit, TIntermDeclaration *node) |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 727 | { |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 728 | const TIntermSequence &sequence = *(node->getSequence()); |
| 729 | ASSERT(!sequence.empty()); |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 730 | |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 731 | const TIntermTyped &typedNode = *(sequence.front()->getAsTyped()); |
| 732 | TQualifier qualifier = typedNode.getQualifier(); |
| 733 | |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 734 | bool isShaderVariable = qualifier == EvqAttribute || qualifier == EvqVertexIn || |
| 735 | qualifier == EvqFragmentOut || qualifier == EvqUniform || |
| 736 | IsVarying(qualifier); |
| 737 | |
| 738 | if (typedNode.getBasicType() != EbtInterfaceBlock && !isShaderVariable) |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 739 | { |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 740 | return true; |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 741 | } |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 742 | |
| 743 | for (TIntermNode *variableNode : sequence) |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 744 | { |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 745 | // The only case in which the sequence will not contain a TIntermSymbol node is |
| 746 | // initialization. It will contain a TInterBinary node in that case. Since attributes, |
| 747 | // uniforms, varyings, outputs and interface blocks cannot be initialized in a shader, we |
| 748 | // must have only TIntermSymbol nodes in the sequence in the cases we are interested in. |
| 749 | const TIntermSymbol &variable = *variableNode->getAsSymbolNode(); |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 750 | if (variable.variable().symbolType() == SymbolType::AngleInternal) |
Olli Etuaho | 34d2007 | 2017-07-18 20:07:18 +0300 | [diff] [blame] | 751 | { |
| 752 | // Internal variables are not collected. |
| 753 | continue; |
| 754 | } |
| 755 | |
Jiawei Shao | bd924af | 2017-11-16 15:28:04 +0800 | [diff] [blame] | 756 | // TODO(jiawei.shao@intel.com): implement GL_EXT_shader_io_blocks. |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 757 | if (typedNode.getBasicType() == EbtInterfaceBlock) |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 758 | { |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 759 | InterfaceBlock interfaceBlock; |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 760 | recordInterfaceBlock(variable.variable().symbolType() != SymbolType::Empty |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 761 | ? variable.getName().data() |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 762 | : nullptr, |
| 763 | variable.getType(), &interfaceBlock); |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 764 | |
| 765 | switch (qualifier) |
Jiajia Qin | bc58515 | 2017-06-23 15:42:17 +0800 | [diff] [blame] | 766 | { |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 767 | case EvqUniform: |
| 768 | mUniformBlocks->push_back(interfaceBlock); |
| 769 | break; |
| 770 | case EvqBuffer: |
| 771 | mShaderStorageBlocks->push_back(interfaceBlock); |
| 772 | break; |
| 773 | default: |
| 774 | UNREACHABLE(); |
Jiajia Qin | bc58515 | 2017-06-23 15:42:17 +0800 | [diff] [blame] | 775 | } |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 776 | } |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 777 | else |
| 778 | { |
Olli Etuaho | 8b5e8fd | 2017-12-15 14:59:15 +0200 | [diff] [blame] | 779 | ASSERT(variable.variable().symbolType() != SymbolType::Empty); |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 780 | switch (qualifier) |
| 781 | { |
| 782 | case EvqAttribute: |
| 783 | case EvqVertexIn: |
| 784 | mAttribs->push_back(recordAttribute(variable)); |
| 785 | break; |
| 786 | case EvqFragmentOut: |
| 787 | mOutputVariables->push_back(recordOutputVariable(variable)); |
| 788 | break; |
| 789 | case EvqUniform: |
| 790 | mUniforms->push_back(recordUniform(variable)); |
| 791 | break; |
| 792 | default: |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 793 | if (IsVaryingIn(qualifier)) |
| 794 | { |
| 795 | mInputVaryings->push_back(recordVarying(variable)); |
| 796 | } |
| 797 | else |
| 798 | { |
| 799 | ASSERT(IsVaryingOut(qualifier)); |
| 800 | mOutputVaryings->push_back(recordVarying(variable)); |
| 801 | } |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 802 | break; |
| 803 | } |
| 804 | } |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 805 | } |
| 806 | |
Olli Etuaho | a55102c | 2017-02-24 12:36:50 +0000 | [diff] [blame] | 807 | // None of the recorded variables can have initializers, so we don't need to traverse the |
| 808 | // declarators. |
| 809 | return false; |
alokp@chromium.org | ee76f6a | 2010-09-27 19:28:55 +0000 | [diff] [blame] | 810 | } |
Jamie Madill | 23a8a43 | 2014-07-09 13:27:42 -0400 | [diff] [blame] | 811 | |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 812 | // TODO(jiawei.shao@intel.com): add search on mInBlocks and mOutBlocks when implementing |
Jiawei Shao | bd924af | 2017-11-16 15:28:04 +0800 | [diff] [blame] | 813 | // GL_EXT_shader_io_blocks. |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame] | 814 | InterfaceBlock *CollectVariablesTraverser::findNamedInterfaceBlock( |
| 815 | const ImmutableString &blockName) const |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 816 | { |
| 817 | InterfaceBlock *namedBlock = FindVariable(blockName, mUniformBlocks); |
| 818 | if (!namedBlock) |
| 819 | { |
| 820 | namedBlock = FindVariable(blockName, mShaderStorageBlocks); |
| 821 | } |
| 822 | return namedBlock; |
| 823 | } |
| 824 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 825 | bool CollectVariablesTraverser::visitBinary(Visit, TIntermBinary *binaryNode) |
Jamie Madill | b547ddf | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 826 | { |
| 827 | if (binaryNode->getOp() == EOpIndexDirectInterfaceBlock) |
| 828 | { |
Jamie Madill | a6f267f | 2014-08-27 11:44:15 -0400 | [diff] [blame] | 829 | // NOTE: we do not determine static use for individual blocks of an array |
| 830 | TIntermTyped *blockNode = binaryNode->getLeft()->getAsTyped(); |
| 831 | ASSERT(blockNode); |
Jamie Madill | b547ddf | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 832 | |
| 833 | TIntermConstantUnion *constantUnion = binaryNode->getRight()->getAsConstantUnion(); |
| 834 | ASSERT(constantUnion); |
| 835 | |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 836 | InterfaceBlock *namedBlock = nullptr; |
| 837 | |
| 838 | bool traverseIndexExpression = false; |
| 839 | TIntermBinary *interfaceIndexingNode = blockNode->getAsBinaryNode(); |
| 840 | if (interfaceIndexingNode) |
| 841 | { |
| 842 | TIntermTyped *interfaceNode = interfaceIndexingNode->getLeft()->getAsTyped(); |
| 843 | ASSERT(interfaceNode); |
| 844 | |
| 845 | const TType &interfaceType = interfaceNode->getType(); |
| 846 | if (interfaceType.getQualifier() == EvqPerVertexIn) |
| 847 | { |
| 848 | namedBlock = recordGLInUsed(interfaceType); |
| 849 | ASSERT(namedBlock); |
| 850 | |
| 851 | // We need to continue traversing to collect useful variables in the index |
| 852 | // expression of gl_in. |
| 853 | traverseIndexExpression = true; |
| 854 | } |
| 855 | } |
| 856 | |
Jamie Madill | a6f267f | 2014-08-27 11:44:15 -0400 | [diff] [blame] | 857 | const TInterfaceBlock *interfaceBlock = blockNode->getType().getInterfaceBlock(); |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 858 | if (!namedBlock) |
Jiajia Qin | bc58515 | 2017-06-23 15:42:17 +0800 | [diff] [blame] | 859 | { |
Olli Etuaho | bed35d7 | 2017-12-20 16:36:26 +0200 | [diff] [blame] | 860 | namedBlock = findNamedInterfaceBlock(interfaceBlock->name()); |
Jiajia Qin | bc58515 | 2017-06-23 15:42:17 +0800 | [diff] [blame] | 861 | } |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 862 | ASSERT(namedBlock); |
| 863 | namedBlock->staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 864 | namedBlock->active = true; |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 865 | unsigned int fieldIndex = static_cast<unsigned int>(constantUnion->getIConst(0)); |
| 866 | ASSERT(fieldIndex < namedBlock->fields.size()); |
| 867 | namedBlock->fields[fieldIndex].staticUse = true; |
Olli Etuaho | 107c724 | 2018-03-20 15:45:35 +0200 | [diff] [blame] | 868 | namedBlock->fields[fieldIndex].active = true; |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 869 | |
| 870 | if (traverseIndexExpression) |
| 871 | { |
| 872 | ASSERT(interfaceIndexingNode); |
| 873 | interfaceIndexingNode->getRight()->traverse(this); |
| 874 | } |
Jamie Madill | b547ddf | 2014-08-25 16:20:46 -0400 | [diff] [blame] | 875 | return false; |
| 876 | } |
| 877 | |
| 878 | return true; |
| 879 | } |
| 880 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 881 | } // anonymous namespace |
| 882 | |
| 883 | void CollectVariables(TIntermBlock *root, |
| 884 | std::vector<Attribute> *attributes, |
| 885 | std::vector<OutputVariable> *outputVariables, |
| 886 | std::vector<Uniform> *uniforms, |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 887 | std::vector<Varying> *inputVaryings, |
| 888 | std::vector<Varying> *outputVaryings, |
Jiajia Qin | 9b11ea4 | 2017-07-11 16:50:08 +0800 | [diff] [blame] | 889 | std::vector<InterfaceBlock> *uniformBlocks, |
| 890 | std::vector<InterfaceBlock> *shaderStorageBlocks, |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 891 | std::vector<InterfaceBlock> *inBlocks, |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 892 | ShHashFunction64 hashFunction, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 893 | TSymbolTable *symbolTable, |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 894 | GLenum shaderType, |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 895 | const TExtensionBehavior &extensionBehavior) |
| 896 | { |
Jiawei-Shao | df7d7c9 | 2017-07-31 09:34:04 +0800 | [diff] [blame] | 897 | CollectVariablesTraverser collect(attributes, outputVariables, uniforms, inputVaryings, |
Jiawei Shao | d8105a0 | 2017-08-08 09:54:36 +0800 | [diff] [blame] | 898 | outputVaryings, uniformBlocks, shaderStorageBlocks, inBlocks, |
Olli Etuaho | 822a84b | 2018-03-23 12:30:18 +0200 | [diff] [blame^] | 899 | hashFunction, symbolTable, shaderType, extensionBehavior); |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 900 | root->traverse(&collect); |
| 901 | } |
| 902 | |
Olli Etuaho | 1951501 | 2017-06-26 18:00:17 +0300 | [diff] [blame] | 903 | } // namespace sh |