1 // 2 // Copyright 2017 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 // ProgramPipeline.h: Defines the gl::ProgramPipeline class. 8 // Implements GL program pipeline objects and related functionality. 9 // [OpenGL ES 3.1] section 7.4 page 105. 10 11 #ifndef LIBANGLE_PROGRAMPIPELINE_H_ 12 #define LIBANGLE_PROGRAMPIPELINE_H_ 13 14 #include <memory> 15 16 #include "common/angleutils.h" 17 #include "libANGLE/Debug.h" 18 #include "libANGLE/Program.h" 19 #include "libANGLE/ProgramExecutable.h" 20 #include "libANGLE/RefCountObject.h" 21 22 namespace rx 23 { 24 class GLImplFactory; 25 class ProgramPipelineImpl; 26 } // namespace rx 27 28 namespace gl 29 { 30 class Context; 31 class ProgramPipeline; 32 33 class ProgramPipelineState final : angle::NonCopyable 34 { 35 public: 36 ProgramPipelineState(); 37 ~ProgramPipelineState(); 38 39 const std::string &getLabel() const; 40 getProgramExecutable()41 const ProgramExecutable &getProgramExecutable() const { return mExecutable; } getProgramExecutable()42 ProgramExecutable &getProgramExecutable() { return mExecutable; } 43 44 void activeShaderProgram(Program *shaderProgram); 45 void useProgramStages(const Context *context, GLbitfield stages, Program *shaderProgram); 46 getActiveShaderProgram()47 Program *getActiveShaderProgram() { return mActiveShaderProgram; } 48 isValid()49 GLboolean isValid() const { return mValid; } 50 getShaderProgram(ShaderType shaderType)51 const Program *getShaderProgram(ShaderType shaderType) const { return mPrograms[shaderType]; } 52 53 bool usesShaderProgram(ShaderProgramID program) const; 54 55 bool hasDefaultUniforms() const; 56 bool hasTextures() const; 57 bool hasUniformBuffers() const; 58 bool hasStorageBuffers() const; 59 bool hasAtomicCounterBuffers() const; 60 bool hasImages() const; 61 bool hasTransformFeedbackOutput() const; 62 63 private: 64 void useProgramStage(const Context *context, ShaderType shaderType, Program *shaderProgram); 65 66 friend class ProgramPipeline; 67 68 std::string mLabel; 69 70 // The active shader program 71 Program *mActiveShaderProgram; 72 // The shader programs for each stage. 73 ShaderMap<Program *> mPrograms; 74 75 GLboolean mValid; 76 77 GLboolean mHasBeenBound; 78 79 ProgramExecutable mExecutable; 80 }; 81 82 class ProgramPipeline final : public RefCountObject<ProgramPipelineID>, public LabeledObject 83 { 84 public: 85 ProgramPipeline(rx::GLImplFactory *factory, ProgramPipelineID handle); 86 ~ProgramPipeline() override; 87 88 void onDestroy(const Context *context) override; 89 90 void setLabel(const Context *context, const std::string &label) override; 91 const std::string &getLabel() const override; 92 getState()93 const ProgramPipelineState &getState() const { return mState; } 94 getExecutable()95 const ProgramExecutable &getExecutable() const { return mState.getProgramExecutable(); } getExecutable()96 ProgramExecutable &getExecutable() { return mState.getProgramExecutable(); } 97 98 rx::ProgramPipelineImpl *getImplementation() const; 99 getActiveShaderProgram()100 Program *getActiveShaderProgram() { return mState.getActiveShaderProgram(); } 101 void activeShaderProgram(Program *shaderProgram); getLinkedActiveShaderProgram(const Context * context)102 Program *getLinkedActiveShaderProgram(const Context *context) 103 { 104 Program *program = mState.getActiveShaderProgram(); 105 if (program) 106 { 107 program->resolveLink(context); 108 } 109 return program; 110 } 111 112 void useProgramStages(const Context *context, GLbitfield stages, Program *shaderProgram); 113 114 void updateExecutableAttributes(); 115 void updateExecutableTextures(); 116 void updateExecutable(); 117 getShaderProgram(ShaderType shaderType)118 Program *getShaderProgram(ShaderType shaderType) const { return mState.mPrograms[shaderType]; } 119 120 ProgramMergedVaryings getMergedVaryings() const; 121 angle::Result link(const gl::Context *context); 122 bool linkVaryings(InfoLog &infoLog) const; 123 void validate(const gl::Context *context); 124 bool validateSamplers(InfoLog *infoLog, const Caps &caps); 125 usesShaderProgram(ShaderProgramID program)126 bool usesShaderProgram(ShaderProgramID program) const 127 { 128 return mState.usesShaderProgram(program); 129 } 130 hasAnyDirtyBit()131 bool hasAnyDirtyBit() const { return mDirtyBits.any(); } 132 isValid()133 GLboolean isValid() const { return mState.isValid(); } 134 bind()135 void bind() { mState.mHasBeenBound = true; } hasBeenBound()136 GLboolean hasBeenBound() const { return mState.mHasBeenBound; } 137 138 // Program pipeline dirty bits. 139 enum DirtyBitType 140 { 141 // One of the program stages in the PPO changed. 142 DIRTY_BIT_PROGRAM_STAGE, 143 DIRTY_BIT_DUMMY, // Used to make DIRTY_BIT_COUNT > 0 144 145 DIRTY_BIT_COUNT = DIRTY_BIT_DUMMY, 146 }; 147 148 using DirtyBits = angle::BitSet<DIRTY_BIT_COUNT>; 149 150 angle::Result syncState(const Context *context); setDirtyBit(DirtyBitType dirtyBitType)151 void setDirtyBit(DirtyBitType dirtyBitType) { mDirtyBits.set(dirtyBitType); } 152 153 private: 154 void updateLinkedShaderStages(); 155 156 std::unique_ptr<rx::ProgramPipelineImpl> mProgramPipelineImpl; 157 158 ProgramPipelineState mState; 159 160 DirtyBits mDirtyBits; 161 }; 162 } // namespace gl 163 164 #endif // LIBANGLE_PROGRAMPIPELINE_H_ 165