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, 49 const gl::ProgramMergedVaryings &mergedVaryings) override; 50 GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) override; 51 52 void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override; 53 void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override; 54 void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override; 55 void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) override; 56 void setUniform1iv(GLint location, GLsizei count, const GLint *v) override; 57 void setUniform2iv(GLint location, GLsizei count, const GLint *v) override; 58 void setUniform3iv(GLint location, GLsizei count, const GLint *v) override; 59 void setUniform4iv(GLint location, GLsizei count, const GLint *v) override; 60 void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) override; 61 void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) override; 62 void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) override; 63 void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) override; 64 void setUniformMatrix2fv(GLint location, 65 GLsizei count, 66 GLboolean transpose, 67 const GLfloat *value) override; 68 void setUniformMatrix3fv(GLint location, 69 GLsizei count, 70 GLboolean transpose, 71 const GLfloat *value) override; 72 void setUniformMatrix4fv(GLint location, 73 GLsizei count, 74 GLboolean transpose, 75 const GLfloat *value) override; 76 void setUniformMatrix2x3fv(GLint location, 77 GLsizei count, 78 GLboolean transpose, 79 const GLfloat *value) override; 80 void setUniformMatrix3x2fv(GLint location, 81 GLsizei count, 82 GLboolean transpose, 83 const GLfloat *value) override; 84 void setUniformMatrix2x4fv(GLint location, 85 GLsizei count, 86 GLboolean transpose, 87 const GLfloat *value) override; 88 void setUniformMatrix4x2fv(GLint location, 89 GLsizei count, 90 GLboolean transpose, 91 const GLfloat *value) override; 92 void setUniformMatrix3x4fv(GLint location, 93 GLsizei count, 94 GLboolean transpose, 95 const GLfloat *value) override; 96 void setUniformMatrix4x3fv(GLint location, 97 GLsizei count, 98 GLboolean transpose, 99 const GLfloat *value) override; 100 101 void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override; 102 void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override; 103 void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override; 104 105 void markUnusedUniformLocations(std::vector<gl::VariableLocation> *uniformLocations, 106 std::vector<gl::SamplerBinding> *samplerBindings, 107 std::vector<gl::ImageBinding> *imageBindings) override; 108 getProgramID()109 ANGLE_INLINE GLuint getProgramID() const { return mProgramID; } 110 111 void enableSideBySideRenderingPath() const; 112 void enableLayeredRenderingPath(int baseViewIndex) const; 113 114 angle::Result syncState(const gl::Context *context, 115 const gl::Program::DirtyBits &dirtyBits) override; 116 117 private: 118 class LinkTask; 119 class LinkEventNativeParallel; 120 class LinkEventGL; 121 122 void preLink(); 123 bool checkLinkStatus(gl::InfoLog &infoLog); 124 void postLink(); 125 126 void reapplyUBOBindingsIfNeeded(const gl::Context *context); 127 128 bool getUniformBlockSize(const std::string &blockName, 129 const std::string &blockMappedName, 130 size_t *sizeOut) const; 131 bool getUniformBlockMemberInfo(const std::string &memberUniformName, 132 const std::string &memberUniformMappedName, 133 sh::BlockMemberInfo *memberInfoOut) const; 134 bool getShaderStorageBlockMemberInfo(const std::string &memberName, 135 const std::string &memberMappedName, 136 sh::BlockMemberInfo *memberInfoOut) const; 137 bool getShaderStorageBlockSize(const std::string &blockName, 138 const std::string &blockMappedName, 139 size_t *sizeOut) const; 140 void getAtomicCounterBufferSizeMap(std::map<int, unsigned int> *sizeMapOut) const; 141 142 void linkResources(const gl::ProgramLinkedResources &resources); 143 void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding); 144 145 // Helper function, makes it simpler to type. uniLoc(GLint glLocation)146 GLint uniLoc(GLint glLocation) const { return mUniformRealLocationMap[glLocation]; } 147 148 const FunctionsGL *mFunctions; 149 const angle::FeaturesGL &mFeatures; 150 StateManagerGL *mStateManager; 151 152 std::vector<GLint> mUniformRealLocationMap; 153 std::vector<GLuint> mUniformBlockRealLocationMap; 154 155 GLint mMultiviewBaseViewLayerIndexUniformLocation; 156 157 GLuint mProgramID; 158 159 std::shared_ptr<RendererGL> mRenderer; 160 161 bool mLinkedInParallel; 162 }; 163 164 } // namespace rx 165 166 #endif // LIBANGLE_RENDERER_GL_PROGRAMGL_H_ 167