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