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