blob: 4f9e58d9b6df02705eb653b4cf83ab2e8929d019 [file] [log] [blame]
Jamie Madill9e54b5a2016-05-25 12:57:39 -04001//
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
Luc Ferron7a06ac12018-03-15 10:17:04 -040013#include <array>
14
Jamie Madill9e54b5a2016-05-25 12:57:39 -040015#include "libANGLE/renderer/ProgramImpl.h"
Luc Ferron6ea1b412018-03-21 16:13:01 -040016#include "libANGLE/renderer/vulkan/RendererVk.h"
Jamie Madill6c7ab7f2018-03-31 14:19:15 -040017#include "libANGLE/renderer/vulkan/vk_helpers.h"
Jamie Madill9e54b5a2016-05-25 12:57:39 -040018
19namespace rx
20{
Jamie Madill9e54b5a2016-05-25 12:57:39 -040021class ProgramVk : public ProgramImpl
22{
23 public:
24 ProgramVk(const gl::ProgramState &state);
25 ~ProgramVk() override;
Jamie Madillb7d924a2018-03-10 11:16:54 -050026 gl::Error destroy(const gl::Context *context) override;
Jamie Madill9e54b5a2016-05-25 12:57:39 -040027
Jamie Madill9cf9e872017-06-05 12:59:25 -040028 gl::LinkResult load(const gl::Context *context,
29 gl::InfoLog &infoLog,
30 gl::BinaryInputStream *stream) override;
Jamie Madill27a60632017-06-30 15:12:01 -040031 void save(const gl::Context *context, gl::BinaryOutputStream *stream) override;
Jamie Madill9e54b5a2016-05-25 12:57:39 -040032 void setBinaryRetrievableHint(bool retrievable) override;
Yunchao He61afff12017-03-14 15:34:03 +080033 void setSeparable(bool separable) override;
Jamie Madill9e54b5a2016-05-25 12:57:39 -040034
jchen107ae70d82018-07-06 13:47:01 +080035 std::unique_ptr<LinkEvent> link(const gl::Context *context,
36 const gl::ProgramLinkedResources &resources,
37 gl::InfoLog &infoLog) override;
Jamie Madill9e54b5a2016-05-25 12:57:39 -040038 GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) override;
39
40 void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override;
41 void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override;
42 void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override;
43 void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) override;
44 void setUniform1iv(GLint location, GLsizei count, const GLint *v) override;
45 void setUniform2iv(GLint location, GLsizei count, const GLint *v) override;
46 void setUniform3iv(GLint location, GLsizei count, const GLint *v) override;
47 void setUniform4iv(GLint location, GLsizei count, const GLint *v) override;
48 void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) override;
49 void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) override;
50 void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) override;
51 void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) override;
52 void setUniformMatrix2fv(GLint location,
53 GLsizei count,
54 GLboolean transpose,
55 const GLfloat *value) override;
56 void setUniformMatrix3fv(GLint location,
57 GLsizei count,
58 GLboolean transpose,
59 const GLfloat *value) override;
60 void setUniformMatrix4fv(GLint location,
61 GLsizei count,
62 GLboolean transpose,
63 const GLfloat *value) override;
64 void setUniformMatrix2x3fv(GLint location,
65 GLsizei count,
66 GLboolean transpose,
67 const GLfloat *value) override;
68 void setUniformMatrix3x2fv(GLint location,
69 GLsizei count,
70 GLboolean transpose,
71 const GLfloat *value) override;
72 void setUniformMatrix2x4fv(GLint location,
73 GLsizei count,
74 GLboolean transpose,
75 const GLfloat *value) override;
76 void setUniformMatrix4x2fv(GLint location,
77 GLsizei count,
78 GLboolean transpose,
79 const GLfloat *value) override;
80 void setUniformMatrix3x4fv(GLint location,
81 GLsizei count,
82 GLboolean transpose,
83 const GLfloat *value) override;
84 void setUniformMatrix4x3fv(GLint location,
85 GLsizei count,
86 GLboolean transpose,
87 const GLfloat *value) override;
88
Jamie Madill54164b02017-08-28 15:17:37 -040089 void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override;
90 void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override;
91 void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override;
92
Jamie Madill9e54b5a2016-05-25 12:57:39 -040093 // TODO: synchronize in syncState when dirty bits exist.
94 void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) override;
95
Sami Väisänen46eaa942016-06-29 10:26:37 +030096 void setPathFragmentInputGen(const std::string &inputName,
97 GLenum genMode,
98 GLint components,
99 const GLfloat *coeffs) override;
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500100
Jamie Madill06ca6342018-07-12 15:56:53 -0400101 // Also initializes the pipeline layout, descriptor set layouts, and used descriptor ranges.
Jamie Madill242c4fe2018-07-12 15:56:56 -0400102 angle::Result initShaders(ContextVk *contextVk,
103 const gl::DrawCallParams &drawCallParams,
104 const vk::ShaderAndSerial **vertexShaderAndSerialOut,
105 const vk::ShaderAndSerial **fragmentShaderAndSerialOut,
106 const vk::PipelineLayout **pipelineLayoutOut);
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500107
Jamie Madill21061022018-07-12 23:56:30 -0400108 angle::Result updateUniforms(ContextVk *contextVk);
Jamie Madill76e471e2017-10-21 09:56:01 -0400109
Jamie Madill5547b382017-10-23 18:16:01 -0400110 void invalidateTextures();
Jamie Madill76e471e2017-10-21 09:56:01 -0400111
Jamie Madill242c4fe2018-07-12 15:56:56 -0400112 angle::Result updateDescriptorSets(ContextVk *contextVk,
113 const gl::DrawCallParams &drawCallParams,
114 VkDescriptorSet driverUniformsDescriptorSet,
115 vk::CommandBuffer *commandBuffer);
Jamie Madill9b168d02018-06-13 13:25:32 -0400116
Luc Ferron7a06ac12018-03-15 10:17:04 -0400117 // For testing only.
118 void setDefaultUniformBlocksMinSizeForTesting(size_t minSize);
119
Jamie Madill8ecf7f92017-01-13 17:29:52 -0500120 private:
Luc Ferron48cdc2e2018-05-31 09:58:34 -0400121 template <int cols, int rows>
122 void setUniformMatrixfv(GLint location,
123 GLsizei count,
124 GLboolean transpose,
125 const GLfloat *value);
126
Jamie Madill21061022018-07-12 23:56:30 -0400127 angle::Result reset(ContextVk *contextVk);
128 angle::Result allocateDescriptorSet(ContextVk *contextVk, uint32_t descriptorSetIndex);
Jamie Madill242c4fe2018-07-12 15:56:56 -0400129 angle::Result initDefaultUniformBlocks(const gl::Context *glContext);
130
Jamie Madill21061022018-07-12 23:56:30 -0400131 angle::Result updateDefaultUniformsDescriptorSet(ContextVk *contextVk);
Jamie Madill242c4fe2018-07-12 15:56:56 -0400132 angle::Result updateTexturesDescriptorSet(ContextVk *contextVk);
Jamie Madill76e471e2017-10-21 09:56:01 -0400133
Luc Ferron7cec3352018-03-13 13:29:34 -0400134 template <class T>
135 void getUniformImpl(GLint location, T *v, GLenum entryPointType) const;
136
Jamie Madill76e471e2017-10-21 09:56:01 -0400137 template <typename T>
138 void setUniformImpl(GLint location, GLsizei count, const T *v, GLenum entryPointType);
jchen107ae70d82018-07-06 13:47:01 +0800139 gl::LinkResult linkImpl(const gl::Context *context,
140 const gl::ProgramLinkedResources &resources,
141 gl::InfoLog &infoLog);
Jamie Madillc5143482017-10-15 20:20:06 -0400142
Jamie Madill76e471e2017-10-21 09:56:01 -0400143 // State for the default uniform blocks.
144 struct DefaultUniformBlock final : private angle::NonCopyable
145 {
146 DefaultUniformBlock();
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500147 ~DefaultUniformBlock();
Jamie Madill76e471e2017-10-21 09:56:01 -0400148
Jamie Madill6c7ab7f2018-03-31 14:19:15 -0400149 vk::DynamicBuffer storage;
Jamie Madill76e471e2017-10-21 09:56:01 -0400150
151 // Shadow copies of the shader uniform data.
152 angle::MemoryBuffer uniformData;
153 bool uniformsDirty;
154
155 // Since the default blocks are laid out in std140, this tells us where to write on a call
156 // to a setUniform method. They are arranged in uniform location order.
157 std::vector<sh::BlockMemberInfo> uniformLayout;
158 };
159
Jamie Madill33318de2018-05-01 11:22:54 -0400160 vk::ShaderMap<DefaultUniformBlock> mDefaultUniformBlocks;
161 vk::ShaderMap<uint32_t> mUniformBlocksOffsets;
Jamie Madill76e471e2017-10-21 09:56:01 -0400162
163 // This is a special "empty" placeholder buffer for when a shader has no uniforms.
164 // It is necessary because we want to keep a compatible pipeline layout in all cases,
165 // and Vulkan does not tolerate having null handles in a descriptor set.
166 vk::BufferAndMemory mEmptyUniformBlockStorage;
167
Jamie Madill5547b382017-10-23 18:16:01 -0400168 // Descriptor sets for uniform blocks and textures for this program.
169 std::vector<VkDescriptorSet> mDescriptorSets;
Jamie Madill8c3988c2017-12-21 14:44:56 -0500170 gl::RangeUI mUsedDescriptorSetRange;
Jamie Madill5547b382017-10-23 18:16:01 -0400171 bool mDirtyTextures;
172
Jamie Madill9b168d02018-06-13 13:25:32 -0400173 // We keep a reference to the pipeline and descriptor set layouts. This ensures they don't get
174 // deleted while this program is in use.
175 vk::BindingPointer<vk::PipelineLayout> mPipelineLayout;
176 vk::DescriptorSetLayoutPointerArray mDescriptorSetLayouts;
Jamie Madill242c4fe2018-07-12 15:56:56 -0400177
178 class ShaderInfo final : angle::NonCopyable
179 {
180 public:
181 ShaderInfo();
182 ~ShaderInfo();
183
184 angle::Result getShaders(ContextVk *contextVk,
185 const std::string &vertexSource,
186 const std::string &fragmentSource,
187 const vk::ShaderAndSerial **vertexShaderAndSerialOut,
188 const vk::ShaderAndSerial **fragmentShaderAndSerialOut);
189 void destroy(VkDevice device);
190 bool valid() const;
191
192 private:
193 vk::ShaderAndSerial mVertexShaderAndSerial;
194 vk::ShaderAndSerial mFragmentShaderAndSerial;
195 };
196
197 // TODO(jmadill): Line rasterization emulation shaders. http://anglebug.com/2598
198 ShaderInfo mDefaultShaderInfo;
199
200 // We keep the translated linked shader sources to use with shader draw call patching.
201 std::string mVertexSource;
202 std::string mFragmentSource;
Jamie Madill9e54b5a2016-05-25 12:57:39 -0400203};
204
205} // namespace rx
206
207#endif // LIBANGLE_RENDERER_VULKAN_PROGRAMVK_H_