• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2014 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 // ProgramImpl.h: Defines the abstract rx::ProgramImpl class.
8 
9 #ifndef LIBANGLE_RENDERER_PROGRAMIMPL_H_
10 #define LIBANGLE_RENDERER_PROGRAMIMPL_H_
11 
12 #include "common/angleutils.h"
13 #include "libANGLE/BinaryStream.h"
14 #include "libANGLE/Constants.h"
15 #include "libANGLE/Program.h"
16 #include "libANGLE/Shader.h"
17 
18 #include <map>
19 
20 namespace gl
21 {
22 class Context;
23 struct ProgramLinkedResources;
24 }  // namespace gl
25 
26 namespace sh
27 {
28 struct BlockMemberInfo;
29 }
30 
31 namespace rx
32 {
33 
34 // Provides a mechanism to access the result of asynchronous linking.
35 class LinkEvent : angle::NonCopyable
36 {
37   public:
~LinkEvent()38     virtual ~LinkEvent() {}
39 
40     // Please be aware that these methods may be called under a gl::Context other
41     // than the one where the LinkEvent was created.
42     //
43     // Waits until the linking is actually done. Returns true if the linking
44     // succeeded, false otherwise.
45     virtual angle::Result wait(const gl::Context *context) = 0;
46     // Peeks whether the linking is still ongoing.
47     virtual bool isLinking() = 0;
48 };
49 
50 // Wraps an already done linking.
51 class LinkEventDone final : public LinkEvent
52 {
53   public:
LinkEventDone(angle::Result result)54     LinkEventDone(angle::Result result) : mResult(result) {}
55     angle::Result wait(const gl::Context *context) override;
56     bool isLinking() override;
57 
58   private:
59     angle::Result mResult;
60 };
61 
wait(const gl::Context * context)62 inline angle::Result LinkEventDone::wait(const gl::Context *context)
63 {
64     return mResult;
65 }
isLinking()66 inline bool LinkEventDone::isLinking()
67 {
68     return false;
69 }
70 
71 class ProgramImpl : angle::NonCopyable
72 {
73   public:
ProgramImpl(const gl::ProgramState & state)74     ProgramImpl(const gl::ProgramState &state) : mState(state) {}
~ProgramImpl()75     virtual ~ProgramImpl() {}
destroy(const gl::Context * context)76     virtual void destroy(const gl::Context *context) {}
77 
78     virtual std::unique_ptr<LinkEvent> load(const gl::Context *context,
79                                             gl::BinaryInputStream *stream,
80                                             gl::InfoLog &infoLog)                 = 0;
81     virtual void save(const gl::Context *context, gl::BinaryOutputStream *stream) = 0;
82     virtual void setBinaryRetrievableHint(bool retrievable)                       = 0;
83     virtual void setSeparable(bool separable)                                     = 0;
84 
85     virtual std::unique_ptr<LinkEvent> link(const gl::Context *context,
86                                             const gl::ProgramLinkedResources &resources,
87                                             gl::InfoLog &infoLog)          = 0;
88     virtual GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) = 0;
89 
90     virtual void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) = 0;
91     virtual void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) = 0;
92     virtual void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0;
93     virtual void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) = 0;
94     virtual void setUniform1iv(GLint location, GLsizei count, const GLint *v)   = 0;
95     virtual void setUniform2iv(GLint location, GLsizei count, const GLint *v)   = 0;
96     virtual void setUniform3iv(GLint location, GLsizei count, const GLint *v)   = 0;
97     virtual void setUniform4iv(GLint location, GLsizei count, const GLint *v)   = 0;
98     virtual void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) = 0;
99     virtual void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) = 0;
100     virtual void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) = 0;
101     virtual void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) = 0;
102     virtual void setUniformMatrix2fv(GLint location,
103                                      GLsizei count,
104                                      GLboolean transpose,
105                                      const GLfloat *value)                      = 0;
106     virtual void setUniformMatrix3fv(GLint location,
107                                      GLsizei count,
108                                      GLboolean transpose,
109                                      const GLfloat *value)                      = 0;
110     virtual void setUniformMatrix4fv(GLint location,
111                                      GLsizei count,
112                                      GLboolean transpose,
113                                      const GLfloat *value)                      = 0;
114     virtual void setUniformMatrix2x3fv(GLint location,
115                                        GLsizei count,
116                                        GLboolean transpose,
117                                        const GLfloat *value)                    = 0;
118     virtual void setUniformMatrix3x2fv(GLint location,
119                                        GLsizei count,
120                                        GLboolean transpose,
121                                        const GLfloat *value)                    = 0;
122     virtual void setUniformMatrix2x4fv(GLint location,
123                                        GLsizei count,
124                                        GLboolean transpose,
125                                        const GLfloat *value)                    = 0;
126     virtual void setUniformMatrix4x2fv(GLint location,
127                                        GLsizei count,
128                                        GLboolean transpose,
129                                        const GLfloat *value)                    = 0;
130     virtual void setUniformMatrix3x4fv(GLint location,
131                                        GLsizei count,
132                                        GLboolean transpose,
133                                        const GLfloat *value)                    = 0;
134     virtual void setUniformMatrix4x3fv(GLint location,
135                                        GLsizei count,
136                                        GLboolean transpose,
137                                        const GLfloat *value)                    = 0;
138 
139     // Done in the back-end to avoid having to keep a system copy of uniform data.
140     virtual void getUniformfv(const gl::Context *context,
141                               GLint location,
142                               GLfloat *params) const                                           = 0;
143     virtual void getUniformiv(const gl::Context *context, GLint location, GLint *params) const = 0;
144     virtual void getUniformuiv(const gl::Context *context,
145                                GLint location,
146                                GLuint *params) const                                           = 0;
147 
148     // Implementation-specific method for ignoring unreferenced uniforms. Some implementations may
149     // perform more extensive analysis and ignore some locations that ANGLE doesn't detect as
150     // unreferenced. This method is not required to be overriden by a back-end.
markUnusedUniformLocations(std::vector<gl::VariableLocation> * uniformLocations,std::vector<gl::SamplerBinding> * samplerBindings,std::vector<gl::ImageBinding> * imageBindings)151     virtual void markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations,
152                                             std::vector<gl::SamplerBinding> *samplerBindings,
153                                             std::vector<gl::ImageBinding> *imageBindings)
154     {}
155 
getState()156     const gl::ProgramState &getState() const { return mState; }
157 
158     virtual angle::Result syncState(const gl::Context *context,
159                                     const gl::Program::DirtyBits &dirtyBits);
160 
161   protected:
162     const gl::ProgramState &mState;
163 };
164 
syncState(const gl::Context * context,const gl::Program::DirtyBits & dirtyBits)165 inline angle::Result ProgramImpl::syncState(const gl::Context *context,
166                                             const gl::Program::DirtyBits &dirtyBits)
167 {
168     return angle::Result::Continue;
169 }
170 
171 }  // namespace rx
172 
173 #endif  // LIBANGLE_RENDERER_PROGRAMIMPL_H_
174