• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
42     {
43         ASSERT(mExecutable);
44         return *mExecutable;
45     }
getProgramExecutable()46     ProgramExecutable &getProgramExecutable()
47     {
48         ASSERT(mExecutable);
49         return *mExecutable;
50     }
51 
52     void activeShaderProgram(Program *shaderProgram);
53     void useProgramStages(const Context *context,
54                           GLbitfield stages,
55                           Program *shaderProgram,
56                           std::vector<angle::ObserverBinding> *programObserverBindings);
57 
getActiveShaderProgram()58     Program *getActiveShaderProgram() { return mActiveShaderProgram; }
59 
isValid()60     GLboolean isValid() const { return mValid; }
61 
getShaderProgram(ShaderType shaderType)62     const Program *getShaderProgram(ShaderType shaderType) const { return mPrograms[shaderType]; }
63 
64     bool usesShaderProgram(ShaderProgramID program) const;
65 
66     void updateExecutableTextures();
67 
68     rx::SpecConstUsageBits getSpecConstUsageBits() const;
69 
70   private:
71     void useProgramStage(const Context *context,
72                          ShaderType shaderType,
73                          Program *shaderProgram,
74                          angle::ObserverBinding *programObserverBindings);
75 
76     friend class ProgramPipeline;
77 
78     std::string mLabel;
79 
80     // The active shader program
81     Program *mActiveShaderProgram;
82     // The shader programs for each stage.
83     ShaderMap<Program *> mPrograms;
84 
85     GLboolean mValid;
86 
87     ProgramExecutable *mExecutable;
88 
89     bool mIsLinked;
90 };
91 
92 class ProgramPipeline final : public RefCountObject<ProgramPipelineID>,
93                               public LabeledObject,
94                               public angle::ObserverInterface,
95                               public HasAttachedShaders
96 {
97   public:
98     ProgramPipeline(rx::GLImplFactory *factory, ProgramPipelineID handle);
99     ~ProgramPipeline() override;
100 
101     void onDestroy(const Context *context) override;
102 
103     void setLabel(const Context *context, const std::string &label) override;
104     const std::string &getLabel() const override;
105 
getState()106     const ProgramPipelineState &getState() const { return mState; }
getState()107     ProgramPipelineState &getState() { return mState; }
108 
getExecutable()109     const ProgramExecutable &getExecutable() const { return mState.getProgramExecutable(); }
getExecutable()110     ProgramExecutable &getExecutable() { return mState.getProgramExecutable(); }
111 
112     rx::ProgramPipelineImpl *getImplementation() const;
113 
getActiveShaderProgram()114     Program *getActiveShaderProgram() { return mState.getActiveShaderProgram(); }
115     void activeShaderProgram(Program *shaderProgram);
getLinkedActiveShaderProgram(const Context * context)116     Program *getLinkedActiveShaderProgram(const Context *context)
117     {
118         Program *program = mState.getActiveShaderProgram();
119         if (program)
120         {
121             program->resolveLink(context);
122         }
123         return program;
124     }
125 
126     void useProgramStages(const Context *context, GLbitfield stages, Program *shaderProgram);
127 
getShaderProgram(ShaderType shaderType)128     Program *getShaderProgram(ShaderType shaderType) const { return mState.mPrograms[shaderType]; }
129 
resetIsLinked()130     void resetIsLinked() { mState.mIsLinked = false; }
131     angle::Result link(const gl::Context *context);
132     bool linkVaryings(InfoLog &infoLog) const;
133     void validate(const gl::Context *context);
isValid()134     GLboolean isValid() const { return mState.isValid(); }
135 
136     // ObserverInterface implementation.
137     void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
138 
139     // HasAttachedShaders implementation
140     Shader *getAttachedShader(ShaderType shaderType) const override;
141 
142   private:
143     void updateLinkedShaderStages();
144     void updateExecutableAttributes();
145     void updateTransformFeedbackMembers();
146     void updateShaderStorageBlocks();
147     void updateImageBindings();
148     void updateExecutableGeometryProperties();
149     void updateExecutableTessellationProperties();
150     void updateFragmentInoutRange();
151     void updateLinkedVaryings();
152     void updateHasBooleans();
153     void updateExecutable();
154 
155     std::unique_ptr<rx::ProgramPipelineImpl> mProgramPipelineImpl;
156 
157     ProgramPipelineState mState;
158 
159     std::vector<angle::ObserverBinding> mProgramObserverBindings;
160     angle::ObserverBinding mExecutableObserverBinding;
161 };
162 }  // namespace gl
163 
164 #endif  // LIBANGLE_PROGRAMPIPELINE_H_
165