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