• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2020 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 // ProgramExecutable.h: Collects the information and interfaces common to both Programs and
7 // ProgramPipelines in order to execute/draw with either.
8 
9 #ifndef LIBANGLE_PROGRAMEXECUTABLE_H_
10 #define LIBANGLE_PROGRAMEXECUTABLE_H_
11 
12 #include "libANGLE/Caps.h"
13 #include "libANGLE/InfoLog.h"
14 #include "libANGLE/VaryingPacking.h"
15 #include "libANGLE/angletypes.h"
16 
17 namespace gl
18 {
19 
20 // This small structure encapsulates binding sampler uniforms to active GL textures.
21 struct SamplerBinding
22 {
23     SamplerBinding(TextureType textureTypeIn,
24                    SamplerFormat formatIn,
25                    size_t elementCount,
26                    bool unreferenced);
27     SamplerBinding(const SamplerBinding &other);
28     ~SamplerBinding();
29 
30     // Necessary for retrieving active textures from the GL state.
31     TextureType textureType;
32 
33     SamplerFormat format;
34 
35     // List of all textures bound to this sampler, of type textureType.
36     std::vector<GLuint> boundTextureUnits;
37 
38     // A note if this sampler is an unreferenced uniform.
39     bool unreferenced;
40 };
41 
42 struct ImageBinding
43 {
44     ImageBinding(size_t count);
45     ImageBinding(GLuint imageUnit, size_t count, bool unreferenced);
46     ImageBinding(const ImageBinding &other);
47     ~ImageBinding();
48 
49     std::vector<GLuint> boundImageUnits;
50 
51     // A note if this image unit is an unreferenced uniform.
52     bool unreferenced;
53 };
54 
55 class ProgramState;
56 class ProgramPipelineState;
57 
58 class ProgramExecutable
59 {
60   public:
61     ProgramExecutable();
62     virtual ~ProgramExecutable();
63 
64     void reset();
65 
66     const ProgramState *getProgramState(ShaderType shaderType) const;
67 
68     int getInfoLogLength() const;
getInfoLog()69     InfoLog &getInfoLog() { return mInfoLog; }
70     void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const;
71     std::string getInfoLogString() const;
resetInfoLog()72     void resetInfoLog() { mInfoLog.reset(); }
73 
getLinkedShaderStages()74     const ShaderBitSet &getLinkedShaderStages() const { return mLinkedShaderStages; }
getLinkedShaderStages()75     ShaderBitSet &getLinkedShaderStages() { return mLinkedShaderStages; }
hasLinkedShaderStage(ShaderType shaderType)76     bool hasLinkedShaderStage(ShaderType shaderType) const
77     {
78         ASSERT(shaderType != ShaderType::InvalidEnum);
79         return mLinkedShaderStages[shaderType];
80     }
getLinkedShaderStageCount()81     size_t getLinkedShaderStageCount() const { return mLinkedShaderStages.count(); }
isCompute()82     bool isCompute() const { return hasLinkedShaderStage(ShaderType::Compute); }
83 
getActiveAttribLocationsMask()84     const AttributesMask &getActiveAttribLocationsMask() const
85     {
86         return mActiveAttribLocationsMask;
87     }
88     bool isAttribLocationActive(size_t attribLocation) const;
getNonBuiltinAttribLocationsMask()89     const AttributesMask &getNonBuiltinAttribLocationsMask() const { return mAttributesMask; }
getMaxActiveAttribLocation()90     unsigned int getMaxActiveAttribLocation() const { return mMaxActiveAttribLocation; }
getAttributesTypeMask()91     const ComponentTypeMask &getAttributesTypeMask() const { return mAttributesTypeMask; }
92     AttributesMask getAttributesMask() const;
93 
getActiveSamplersMask()94     const ActiveTextureMask &getActiveSamplersMask() const { return mActiveSamplersMask; }
getSamplerFormatForTextureUnitIndex(size_t textureUnitIndex)95     SamplerFormat getSamplerFormatForTextureUnitIndex(size_t textureUnitIndex) const
96     {
97         return mActiveSamplerFormats[textureUnitIndex];
98     }
getSamplerShaderBitsForTextureUnitIndex(size_t textureUnitIndex)99     const ShaderBitSet getSamplerShaderBitsForTextureUnitIndex(size_t textureUnitIndex) const
100     {
101         return mActiveSamplerShaderBits[textureUnitIndex];
102     }
getActiveImagesMask()103     const ActiveTextureMask &getActiveImagesMask() const { return mActiveImagesMask; }
getActiveImageShaderBits()104     const ActiveTextureArray<ShaderBitSet> &getActiveImageShaderBits() const
105     {
106         return mActiveImageShaderBits;
107     }
108 
getActiveSamplerTypes()109     const ActiveTextureArray<TextureType> &getActiveSamplerTypes() const
110     {
111         return mActiveSamplerTypes;
112     }
113 
114     bool hasDefaultUniforms() const;
115     bool hasTextures() const;
116     bool hasUniformBuffers() const;
117     bool hasStorageBuffers() const;
118     bool hasAtomicCounterBuffers() const;
119     bool hasImages() const;
120     bool hasTransformFeedbackOutput() const;
121 
122     // Count the number of uniform and storage buffer declarations, counting arrays as one.
123     size_t getTransformFeedbackBufferCount(const gl::State &glState) const;
124 
125     bool linkValidateGlobalNames(InfoLog &infoLog) const;
126 
127     // TODO: http://anglebug.com/4520: Remove mProgramState/mProgramPipelineState
setProgramState(ProgramState * state)128     void setProgramState(ProgramState *state)
129     {
130         ASSERT(!mProgramState && !mProgramPipelineState);
131         mProgramState = state;
132     }
setProgramPipelineState(ProgramPipelineState * state)133     void setProgramPipelineState(ProgramPipelineState *state)
134     {
135         ASSERT(!mProgramState && !mProgramPipelineState);
136         mProgramPipelineState = state;
137     }
138 
139   private:
140     // TODO(timvp): http://anglebug.com/3570: Investigate removing these friend
141     // class declarations and accessing the necessary members with getters/setters.
142     friend class Program;
143     friend class ProgramPipeline;
144     friend class ProgramState;
145 
146     void updateActiveSamplers(const ProgramState &programState);
147     void updateActiveImages(std::vector<ImageBinding> &imageBindings);
148 
149     // Scans the sampler bindings for type conflicts with sampler 'textureUnitIndex'.
150     void setSamplerUniformTextureTypeAndFormat(size_t textureUnitIndex,
151                                                std::vector<SamplerBinding> &samplerBindings);
152 
153     // TODO: http://anglebug.com/4520: Remove mProgramState/mProgramPipelineState
154     ProgramState *mProgramState;
155     ProgramPipelineState *mProgramPipelineState;
156 
157     InfoLog mInfoLog;
158 
159     ShaderBitSet mLinkedShaderStages;
160 
161     angle::BitSet<MAX_VERTEX_ATTRIBS> mActiveAttribLocationsMask;
162     unsigned int mMaxActiveAttribLocation;
163     ComponentTypeMask mAttributesTypeMask;
164     // mAttributesMask is identical to mActiveAttribLocationsMask with built-in attributes removed.
165     AttributesMask mAttributesMask;
166 
167     // Cached mask of active samplers and sampler types.
168     ActiveTextureMask mActiveSamplersMask;
169     ActiveTextureArray<uint32_t> mActiveSamplerRefCounts;
170     ActiveTextureArray<TextureType> mActiveSamplerTypes;
171     ActiveTextureArray<SamplerFormat> mActiveSamplerFormats;
172     ActiveTextureArray<ShaderBitSet> mActiveSamplerShaderBits;
173 
174     // Cached mask of active images.
175     ActiveTextureMask mActiveImagesMask;
176     ActiveTextureArray<ShaderBitSet> mActiveImageShaderBits;
177 };
178 
179 }  // namespace gl
180 
181 #endif  // LIBANGLE_PROGRAMEXECUTABLE_H_
182