• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2016 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 // ProgramVk.h:
7 //    Defines the class interface for ProgramVk, implementing ProgramImpl.
8 //
9 
10 #ifndef LIBANGLE_RENDERER_VULKAN_PROGRAMVK_H_
11 #define LIBANGLE_RENDERER_VULKAN_PROGRAMVK_H_
12 
13 #include <array>
14 
15 #include "common/utilities.h"
16 #include "libANGLE/renderer/ProgramImpl.h"
17 #include "libANGLE/renderer/vulkan/ContextVk.h"
18 #include "libANGLE/renderer/vulkan/ProgramExecutableVk.h"
19 #include "libANGLE/renderer/vulkan/RendererVk.h"
20 #include "libANGLE/renderer/vulkan/TransformFeedbackVk.h"
21 #include "libANGLE/renderer/vulkan/vk_helpers.h"
22 
23 namespace rx
24 {
25 class ProgramVk : public ProgramImpl
26 {
27   public:
28     ProgramVk(const gl::ProgramState &state);
29     ~ProgramVk() override;
30     void destroy(const gl::Context *context) override;
31 
32     std::unique_ptr<LinkEvent> load(const gl::Context *context,
33                                     gl::BinaryInputStream *stream,
34                                     gl::InfoLog &infoLog) override;
35     void save(const gl::Context *context, gl::BinaryOutputStream *stream) override;
36     void setBinaryRetrievableHint(bool retrievable) override;
37     void setSeparable(bool separable) override;
38 
39     std::unique_ptr<LinkEvent> link(const gl::Context *context,
40                                     const gl::ProgramLinkedResources &resources,
41                                     gl::InfoLog &infoLog,
42                                     const gl::ProgramMergedVaryings &mergedVaryings) override;
43     GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) override;
44 
45     angle::Result syncState(const gl::Context *context,
46                             const gl::Program::DirtyBits &dirtyBits) override;
47 
48     void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override;
49     void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override;
50     void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override;
51     void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) override;
52     void setUniform1iv(GLint location, GLsizei count, const GLint *v) override;
53     void setUniform2iv(GLint location, GLsizei count, const GLint *v) override;
54     void setUniform3iv(GLint location, GLsizei count, const GLint *v) override;
55     void setUniform4iv(GLint location, GLsizei count, const GLint *v) override;
56     void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) override;
57     void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) override;
58     void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) override;
59     void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) override;
60     void setUniformMatrix2fv(GLint location,
61                              GLsizei count,
62                              GLboolean transpose,
63                              const GLfloat *value) override;
64     void setUniformMatrix3fv(GLint location,
65                              GLsizei count,
66                              GLboolean transpose,
67                              const GLfloat *value) override;
68     void setUniformMatrix4fv(GLint location,
69                              GLsizei count,
70                              GLboolean transpose,
71                              const GLfloat *value) override;
72     void setUniformMatrix2x3fv(GLint location,
73                                GLsizei count,
74                                GLboolean transpose,
75                                const GLfloat *value) override;
76     void setUniformMatrix3x2fv(GLint location,
77                                GLsizei count,
78                                GLboolean transpose,
79                                const GLfloat *value) override;
80     void setUniformMatrix2x4fv(GLint location,
81                                GLsizei count,
82                                GLboolean transpose,
83                                const GLfloat *value) override;
84     void setUniformMatrix4x2fv(GLint location,
85                                GLsizei count,
86                                GLboolean transpose,
87                                const GLfloat *value) override;
88     void setUniformMatrix3x4fv(GLint location,
89                                GLsizei count,
90                                GLboolean transpose,
91                                const GLfloat *value) override;
92     void setUniformMatrix4x3fv(GLint location,
93                                GLsizei count,
94                                GLboolean transpose,
95                                const GLfloat *value) override;
96 
97     void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override;
98     void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override;
99     void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override;
100 
areShaderUniformsDirty(gl::ShaderType shaderType)101     bool areShaderUniformsDirty(gl::ShaderType shaderType) const
102     {
103         return mExecutable.mDefaultUniformBlocksDirty[shaderType];
104     }
setShaderUniformDirtyBit(gl::ShaderType shaderType)105     void setShaderUniformDirtyBit(gl::ShaderType shaderType)
106     {
107         if (!mExecutable.mDefaultUniformBlocks[shaderType]->uniformData.empty())
108         {
109             mExecutable.mDefaultUniformBlocksDirty.set(shaderType);
110         }
111     }
clearShaderUniformDirtyBit(gl::ShaderType shaderType)112     void clearShaderUniformDirtyBit(gl::ShaderType shaderType)
113     {
114         mExecutable.mDefaultUniformBlocksDirty.reset(shaderType);
115     }
116 
getExecutable()117     const ProgramExecutableVk &getExecutable() const { return mExecutable; }
getExecutable()118     ProgramExecutableVk &getExecutable() { return mExecutable; }
119 
getSpvProgramInterfaceInfo()120     const SpvProgramInterfaceInfo &getSpvProgramInterfaceInfo() { return mSpvProgramInterfaceInfo; }
121 
122   private:
123     template <int cols, int rows>
124     void setUniformMatrixfv(GLint location,
125                             GLsizei count,
126                             GLboolean transpose,
127                             const GLfloat *value);
128 
129     void reset(ContextVk *contextVk);
130     angle::Result initDefaultUniformBlocks(const gl::Context *glContext);
131     void generateUniformLayoutMapping(const gl::Context *context,
132                                       gl::ShaderMap<sh::BlockLayoutMap> &layoutMap,
133                                       gl::ShaderMap<size_t> &requiredBufferSize);
134     void initDefaultUniformLayoutMapping(gl::ShaderMap<sh::BlockLayoutMap> &layoutMap);
135 
136     template <class T>
137     void getUniformImpl(GLint location, T *v, GLenum entryPointType) const;
138 
139     template <typename T>
140     void setUniformImpl(GLint location, GLsizei count, const T *v, GLenum entryPointType);
141     void linkResources(const gl::Context *context, const gl::ProgramLinkedResources &resources);
142 
143     angle::Result createGraphicsPipelineWithDefaultState(const gl::Context *context,
144                                                          vk::PipelineCacheAccess *pipelineCache);
145 
146     // We keep the SPIR-V code to use for draw call pipeline creation.
147     SpvProgramInterfaceInfo mSpvProgramInterfaceInfo;
148 
149     ProgramExecutableVk mExecutable;
150 };
151 
152 }  // namespace rx
153 
154 #endif  // LIBANGLE_RENDERER_VULKAN_PROGRAMVK_H_
155