• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2010 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/MemoryBuffer.h"
15 #include "common/debug.h"
16 #include "common/utilities.h"
17 #include "compiler/translator/blocklayout.h"
18 #include "libANGLE/angletypes.h"
19 
20 namespace gl
21 {
22 struct UniformTypeInfo;
23 
24 struct ActiveVariable
25 {
26     ActiveVariable();
27     ActiveVariable(const ActiveVariable &rhs);
28     virtual ~ActiveVariable();
29 
30     ActiveVariable &operator=(const ActiveVariable &rhs);
31 
32     ShaderType getFirstShaderTypeWhereActive() const;
33     void setActive(ShaderType shaderType, bool used);
34     void unionReferencesWith(const ActiveVariable &other);
isActiveActiveVariable35     bool isActive(ShaderType shaderType) const
36     {
37         ASSERT(shaderType != ShaderType::InvalidEnum);
38         return mActiveUseBits[shaderType];
39     }
activeShadersActiveVariable40     ShaderBitSet activeShaders() const { return mActiveUseBits; }
41     GLuint activeShaderCount() const;
42 
43   private:
44     ShaderBitSet mActiveUseBits;
45 };
46 
47 // Helper struct representing a single shader uniform
48 struct LinkedUniform : public sh::Uniform, public ActiveVariable
49 {
50     LinkedUniform();
51     LinkedUniform(GLenum type,
52                   GLenum precision,
53                   const std::string &name,
54                   const std::vector<unsigned int> &arraySizes,
55                   const int binding,
56                   const int offset,
57                   const int location,
58                   const int bufferIndex,
59                   const sh::BlockMemberInfo &blockInfo);
60     LinkedUniform(const sh::Uniform &uniform);
61     LinkedUniform(const LinkedUniform &uniform);
62     LinkedUniform &operator=(const LinkedUniform &uniform);
63     ~LinkedUniform() override;
64 
isSamplerLinkedUniform65     bool isSampler() const { return typeInfo->isSampler; }
isImageLinkedUniform66     bool isImage() const { return typeInfo->isImageType; }
isAtomicCounterLinkedUniform67     bool isAtomicCounter() const { return IsAtomicCounterType(type); }
isInDefaultBlockLinkedUniform68     bool isInDefaultBlock() const { return bufferIndex == -1; }
isFieldLinkedUniform69     bool isField() const { return name.find('.') != std::string::npos; }
getElementSizeLinkedUniform70     size_t getElementSize() const { return typeInfo->externalSize; }
getElementComponentsLinkedUniform71     size_t getElementComponents() const { return typeInfo->componentCount; }
72 
73     const UniformTypeInfo *typeInfo;
74 
75     // Identifies the containing buffer backed resource -- interface block or atomic counter buffer.
76     int bufferIndex;
77     sh::BlockMemberInfo blockInfo;
78 };
79 
80 struct BufferVariable : public sh::ShaderVariable, public ActiveVariable
81 {
82     BufferVariable();
83     BufferVariable(GLenum type,
84                    GLenum precision,
85                    const std::string &name,
86                    const std::vector<unsigned int> &arraySizes,
87                    const int bufferIndex,
88                    const sh::BlockMemberInfo &blockInfo);
89     ~BufferVariable() override;
90 
91     int bufferIndex;
92     sh::BlockMemberInfo blockInfo;
93 
94     int topLevelArraySize;
95 };
96 
97 // Parent struct for atomic counter, uniform block, and shader storage block buffer, which all
98 // contain a group of shader variables, and have a GL buffer backed.
99 struct ShaderVariableBuffer : public ActiveVariable
100 {
101     ShaderVariableBuffer();
102     ShaderVariableBuffer(const ShaderVariableBuffer &other);
103     ~ShaderVariableBuffer() override;
104     int numActiveVariables() const;
105 
106     int binding;
107     unsigned int dataSize;
108     std::vector<unsigned int> memberIndexes;
109 };
110 
111 using AtomicCounterBuffer = ShaderVariableBuffer;
112 
113 // Helper struct representing a single shader interface block
114 struct InterfaceBlock : public ShaderVariableBuffer
115 {
116     InterfaceBlock();
117     InterfaceBlock(const std::string &nameIn,
118                    const std::string &mappedNameIn,
119                    bool isArrayIn,
120                    unsigned int arrayElementIn,
121                    int bindingIn);
122 
123     std::string nameWithArrayIndex() const;
124     std::string mappedNameWithArrayIndex() const;
125 
126     std::string name;
127     std::string mappedName;
128     bool isArray;
129     unsigned int arrayElement;
130 };
131 
132 }  // namespace gl
133 
134 #endif  // LIBANGLE_UNIFORM_H_
135