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