• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 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 // ProgramGL.h: Defines the class interface for ProgramGL.
8 
9 #ifndef LIBANGLE_RENDERER_GL_PROGRAMGL_H_
10 #define LIBANGLE_RENDERER_GL_PROGRAMGL_H_
11 
12 #include <string>
13 #include <vector>
14 
15 #include "libANGLE/renderer/ProgramImpl.h"
16 
17 namespace angle
18 {
19 struct FeaturesGL;
20 }  // namespace angle
21 
22 namespace rx
23 {
24 
25 class FunctionsGL;
26 class RendererGL;
27 class StateManagerGL;
28 
29 class ProgramGL : public ProgramImpl
30 {
31   public:
32     ProgramGL(const gl::ProgramState &data,
33               const FunctionsGL *functions,
34               const angle::FeaturesGL &features,
35               StateManagerGL *stateManager,
36               const std::shared_ptr<RendererGL> &renderer);
37     ~ProgramGL() override;
38 
39     std::unique_ptr<LinkEvent> load(const gl::Context *context,
40                                     gl::BinaryInputStream *stream,
41                                     gl::InfoLog &infoLog) override;
42     void save(const gl::Context *context, gl::BinaryOutputStream *stream) override;
43     void setBinaryRetrievableHint(bool retrievable) override;
44     void setSeparable(bool separable) override;
45 
46     std::unique_ptr<LinkEvent> link(const gl::Context *contextImpl,
47                                     const gl::ProgramLinkedResources &resources,
48                                     gl::InfoLog &infoLog) override;
49     GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) override;
50 
51     void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override;
52     void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override;
53     void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override;
54     void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) override;
55     void setUniform1iv(GLint location, GLsizei count, const GLint *v) override;
56     void setUniform2iv(GLint location, GLsizei count, const GLint *v) override;
57     void setUniform3iv(GLint location, GLsizei count, const GLint *v) override;
58     void setUniform4iv(GLint location, GLsizei count, const GLint *v) override;
59     void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) override;
60     void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) override;
61     void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) override;
62     void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) override;
63     void setUniformMatrix2fv(GLint location,
64                              GLsizei count,
65                              GLboolean transpose,
66                              const GLfloat *value) override;
67     void setUniformMatrix3fv(GLint location,
68                              GLsizei count,
69                              GLboolean transpose,
70                              const GLfloat *value) override;
71     void setUniformMatrix4fv(GLint location,
72                              GLsizei count,
73                              GLboolean transpose,
74                              const GLfloat *value) override;
75     void setUniformMatrix2x3fv(GLint location,
76                                GLsizei count,
77                                GLboolean transpose,
78                                const GLfloat *value) override;
79     void setUniformMatrix3x2fv(GLint location,
80                                GLsizei count,
81                                GLboolean transpose,
82                                const GLfloat *value) override;
83     void setUniformMatrix2x4fv(GLint location,
84                                GLsizei count,
85                                GLboolean transpose,
86                                const GLfloat *value) override;
87     void setUniformMatrix4x2fv(GLint location,
88                                GLsizei count,
89                                GLboolean transpose,
90                                const GLfloat *value) override;
91     void setUniformMatrix3x4fv(GLint location,
92                                GLsizei count,
93                                GLboolean transpose,
94                                const GLfloat *value) override;
95     void setUniformMatrix4x3fv(GLint location,
96                                GLsizei count,
97                                GLboolean transpose,
98                                const GLfloat *value) override;
99 
100     void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override;
101     void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override;
102     void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override;
103 
104     void markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations,
105                                     std::vector<gl::SamplerBinding> *samplerBindings,
106                                     std::vector<gl::ImageBinding> *imageBindings) override;
107 
getProgramID()108     ANGLE_INLINE GLuint getProgramID() const { return mProgramID; }
109 
110     void enableSideBySideRenderingPath() const;
111     void enableLayeredRenderingPath(int baseViewIndex) const;
112 
113     angle::Result syncState(const gl::Context *context,
114                             const gl::Program::DirtyBits &dirtyBits) override;
115 
116   private:
117     class LinkTask;
118     class LinkEventNativeParallel;
119     class LinkEventGL;
120 
121     void preLink();
122     bool checkLinkStatus(gl::InfoLog &infoLog);
123     void postLink();
124 
125     void reapplyUBOBindingsIfNeeded(const gl::Context *context);
126 
127     bool getUniformBlockSize(const std::string &blockName,
128                              const std::string &blockMappedName,
129                              size_t *sizeOut) const;
130     bool getUniformBlockMemberInfo(const std::string &memberUniformName,
131                                    const std::string &memberUniformMappedName,
132                                    sh::BlockMemberInfo *memberInfoOut) const;
133     bool getShaderStorageBlockMemberInfo(const std::string &memberName,
134                                          const std::string &memberMappedName,
135                                          sh::BlockMemberInfo *memberInfoOut) const;
136     bool getShaderStorageBlockSize(const std::string &blockName,
137                                    const std::string &blockMappedName,
138                                    size_t *sizeOut) const;
139     void getAtomicCounterBufferSizeMap(std::map<int, unsigned int> *sizeMapOut) const;
140 
141     void linkResources(const gl::ProgramLinkedResources &resources);
142     void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding);
143 
144     // Helper function, makes it simpler to type.
uniLoc(GLint glLocation)145     GLint uniLoc(GLint glLocation) const { return mUniformRealLocationMap[glLocation]; }
146 
147     const FunctionsGL *mFunctions;
148     const angle::FeaturesGL &mFeatures;
149     StateManagerGL *mStateManager;
150 
151     std::vector<GLint> mUniformRealLocationMap;
152     std::vector<GLuint> mUniformBlockRealLocationMap;
153 
154     GLint mMultiviewBaseViewLayerIndexUniformLocation;
155 
156     GLuint mProgramID;
157 
158     std::shared_ptr<RendererGL> mRenderer;
159 
160     bool mLinkedInParallel;
161 };
162 
163 }  // namespace rx
164 
165 #endif  // LIBANGLE_RENDERER_GL_PROGRAMGL_H_
166