ProgramImpl.h (7795B)
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: 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: 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 62 inline angle::Result LinkEventDone::wait(const gl::Context *context) 63 { 64 return mResult; 65 } 66 inline bool LinkEventDone::isLinking() 67 { 68 return false; 69 } 70 71 class ProgramImpl : angle::NonCopyable 72 { 73 public: 74 ProgramImpl(const gl::ProgramState &state) : mState(state) {} 75 virtual ~ProgramImpl() {} 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, 88 const gl::ProgramMergedVaryings &mergedVaryings) = 0; 89 virtual GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) = 0; 90 91 virtual void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) = 0; 92 virtual void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) = 0; 93 virtual void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) = 0; 94 virtual void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) = 0; 95 virtual void setUniform1iv(GLint location, GLsizei count, const GLint *v) = 0; 96 virtual void setUniform2iv(GLint location, GLsizei count, const GLint *v) = 0; 97 virtual void setUniform3iv(GLint location, GLsizei count, const GLint *v) = 0; 98 virtual void setUniform4iv(GLint location, GLsizei count, const GLint *v) = 0; 99 virtual void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) = 0; 100 virtual void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) = 0; 101 virtual void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) = 0; 102 virtual void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) = 0; 103 virtual void setUniformMatrix2fv(GLint location, 104 GLsizei count, 105 GLboolean transpose, 106 const GLfloat *value) = 0; 107 virtual void setUniformMatrix3fv(GLint location, 108 GLsizei count, 109 GLboolean transpose, 110 const GLfloat *value) = 0; 111 virtual void setUniformMatrix4fv(GLint location, 112 GLsizei count, 113 GLboolean transpose, 114 const GLfloat *value) = 0; 115 virtual void setUniformMatrix2x3fv(GLint location, 116 GLsizei count, 117 GLboolean transpose, 118 const GLfloat *value) = 0; 119 virtual void setUniformMatrix3x2fv(GLint location, 120 GLsizei count, 121 GLboolean transpose, 122 const GLfloat *value) = 0; 123 virtual void setUniformMatrix2x4fv(GLint location, 124 GLsizei count, 125 GLboolean transpose, 126 const GLfloat *value) = 0; 127 virtual void setUniformMatrix4x2fv(GLint location, 128 GLsizei count, 129 GLboolean transpose, 130 const GLfloat *value) = 0; 131 virtual void setUniformMatrix3x4fv(GLint location, 132 GLsizei count, 133 GLboolean transpose, 134 const GLfloat *value) = 0; 135 virtual void setUniformMatrix4x3fv(GLint location, 136 GLsizei count, 137 GLboolean transpose, 138 const GLfloat *value) = 0; 139 140 // Done in the back-end to avoid having to keep a system copy of uniform data. 141 virtual void getUniformfv(const gl::Context *context, 142 GLint location, 143 GLfloat *params) const = 0; 144 virtual void getUniformiv(const gl::Context *context, GLint location, GLint *params) const = 0; 145 virtual void getUniformuiv(const gl::Context *context, 146 GLint location, 147 GLuint *params) const = 0; 148 149 // Implementation-specific method for ignoring unreferenced uniforms. Some implementations may 150 // perform more extensive analysis and ignore some locations that ANGLE doesn't detect as 151 // unreferenced. This method is not required to be overriden by a back-end. 152 virtual void markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations, 153 std::vector<gl::SamplerBinding> *samplerBindings, 154 std::vector<gl::ImageBinding> *imageBindings) 155 {} 156 157 const gl::ProgramState &getState() const { return mState; } 158 159 virtual angle::Result syncState(const gl::Context *context, 160 const gl::Program::DirtyBits &dirtyBits); 161 162 virtual angle::Result onLabelUpdate(const gl::Context *context); 163 164 protected: 165 const gl::ProgramState &mState; 166 }; 167 168 inline angle::Result ProgramImpl::syncState(const gl::Context *context, 169 const gl::Program::DirtyBits &dirtyBits) 170 { 171 return angle::Result::Continue; 172 } 173 174 } // namespace rx 175 176 #endif // LIBANGLE_RENDERER_PROGRAMIMPL_H_