• 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::ShaderVariable, 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::ShaderVariable &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     std::vector<unsigned int> outerArraySizes;
79     unsigned int outerArrayOffset;
80 };
81 
82 struct BufferVariable : public sh::ShaderVariable, public ActiveVariable
83 {
84     BufferVariable();
85     BufferVariable(GLenum type,
86                    GLenum precision,
87                    const std::string &name,
88                    const std::vector<unsigned int> &arraySizes,
89                    const int bufferIndex,
90                    const sh::BlockMemberInfo &blockInfo);
91     ~BufferVariable() override;
92 
93     int bufferIndex;
94     sh::BlockMemberInfo blockInfo;
95 
96     int topLevelArraySize;
97 };
98 
99 // Parent struct for atomic counter, uniform block, and shader storage block buffer, which all
100 // contain a group of shader variables, and have a GL buffer backed.
101 struct ShaderVariableBuffer : public ActiveVariable
102 {
103     ShaderVariableBuffer();
104     ShaderVariableBuffer(const ShaderVariableBuffer &other);
105     ~ShaderVariableBuffer() override;
106     int numActiveVariables() const;
107 
108     int binding;
109     unsigned int dataSize;
110     std::vector<unsigned int> memberIndexes;
111 };
112 
113 using AtomicCounterBuffer = ShaderVariableBuffer;
114 
115 // Helper struct representing a single shader interface block
116 struct InterfaceBlock : public ShaderVariableBuffer
117 {
118     InterfaceBlock();
119     InterfaceBlock(const std::string &nameIn,
120                    const std::string &mappedNameIn,
121                    bool isArrayIn,
122                    unsigned int arrayElementIn,
123                    unsigned int firstFieldArraySizeIn,
124                    int bindingIn);
125 
126     std::string nameWithArrayIndex() const;
127     std::string mappedNameWithArrayIndex() const;
128 
129     std::string name;
130     std::string mappedName;
131     bool isArray;
132     unsigned int arrayElement;
133     unsigned int firstFieldArraySize;
134 };
135 
136 }  // namespace gl
137 
138 #endif  // LIBANGLE_UNIFORM_H_
139