1 // 2 // Copyright (c) 2010-2013 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 #ifndef LIBANGLE_UNIFORM_H_ 8 #define LIBANGLE_UNIFORM_H_ 9 10 #include <string> 11 #include <vector> 12 13 #include "angle_gl.h" 14 #include "common/debug.h" 15 #include "common/MemoryBuffer.h" 16 #include "compiler/translator/blocklayout.h" 17 #include "libANGLE/angletypes.h" 18 19 namespace gl 20 { 21 struct UniformTypeInfo; 22 23 struct StaticallyUsed 24 { 25 StaticallyUsed(); 26 StaticallyUsed(const StaticallyUsed &rhs); 27 virtual ~StaticallyUsed(); 28 29 StaticallyUsed &operator=(const StaticallyUsed &rhs); 30 31 void setStaticUse(GLenum shaderType, bool used); 32 void unionReferencesWith(const StaticallyUsed &other); 33 34 bool vertexStaticUse; 35 bool fragmentStaticUse; 36 bool computeStaticUse; 37 }; 38 39 // Helper struct representing a single shader uniform 40 struct LinkedUniform : public sh::Uniform, public StaticallyUsed 41 { 42 LinkedUniform(); 43 LinkedUniform(GLenum type, 44 GLenum precision, 45 const std::string &name, 46 const std::vector<unsigned int> &arraySizes, 47 const int binding, 48 const int offset, 49 const int location, 50 const int bufferIndex, 51 const sh::BlockMemberInfo &blockInfo); 52 LinkedUniform(const sh::Uniform &uniform); 53 LinkedUniform(const LinkedUniform &uniform); 54 LinkedUniform &operator=(const LinkedUniform &uniform); 55 ~LinkedUniform() override; 56 57 bool isSampler() const; 58 bool isImage() const; 59 bool isAtomicCounter() const; 60 bool isInDefaultBlock() const; 61 bool isField() const; 62 size_t getElementSize() const; 63 size_t getElementComponents() const; 64 65 const UniformTypeInfo *typeInfo; 66 67 // Identifies the containing buffer backed resource -- interface block or atomic counter buffer. 68 int bufferIndex; 69 sh::BlockMemberInfo blockInfo; 70 }; 71 72 struct BufferVariable : public sh::ShaderVariable, public StaticallyUsed 73 { 74 BufferVariable(); 75 BufferVariable(GLenum type, 76 GLenum precision, 77 const std::string &name, 78 const std::vector<unsigned int> &arraySizes, 79 const int bufferIndex, 80 const sh::BlockMemberInfo &blockInfo); 81 ~BufferVariable() override; 82 83 int bufferIndex; 84 sh::BlockMemberInfo blockInfo; 85 86 int topLevelArraySize; 87 }; 88 89 // Parent struct for atomic counter, uniform block, and shader storage block buffer, which all 90 // contain a group of shader variables, and have a GL buffer backed. 91 struct ShaderVariableBuffer : public StaticallyUsed 92 { 93 ShaderVariableBuffer(); 94 ShaderVariableBuffer(const ShaderVariableBuffer &other); 95 ~ShaderVariableBuffer() override; 96 int numActiveVariables() const; 97 98 int binding; 99 unsigned int dataSize; 100 std::vector<unsigned int> memberIndexes; 101 }; 102 103 using AtomicCounterBuffer = ShaderVariableBuffer; 104 105 // Helper struct representing a single shader interface block 106 struct InterfaceBlock : public ShaderVariableBuffer 107 { 108 InterfaceBlock(); 109 InterfaceBlock(const std::string &nameIn, 110 const std::string &mappedNameIn, 111 bool isArrayIn, 112 unsigned int arrayElementIn, 113 int bindingIn); 114 115 std::string nameWithArrayIndex() const; 116 std::string mappedNameWithArrayIndex() const; 117 118 std::string name; 119 std::string mappedName; 120 bool isArray; 121 unsigned int arrayElement; 122 }; 123 124 } 125 126 #endif // LIBANGLE_UNIFORM_H_ 127