Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 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 "libANGLE/renderer/ProgramImpl.h" |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 14 | #include "libANGLE/renderer/vulkan/renderervk_utils.h" |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 15 | |
| 16 | namespace rx |
| 17 | { |
| 18 | |
| 19 | class ProgramVk : public ProgramImpl |
| 20 | { |
| 21 | public: |
| 22 | ProgramVk(const gl::ProgramState &state); |
| 23 | ~ProgramVk() override; |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 24 | void destroy(const gl::Context *context) override; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 25 | |
Jamie Madill | 9cf9e87 | 2017-06-05 12:59:25 -0400 | [diff] [blame] | 26 | gl::LinkResult load(const gl::Context *context, |
| 27 | gl::InfoLog &infoLog, |
| 28 | gl::BinaryInputStream *stream) override; |
Jamie Madill | 27a6063 | 2017-06-30 15:12:01 -0400 | [diff] [blame] | 29 | void save(const gl::Context *context, gl::BinaryOutputStream *stream) override; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 30 | void setBinaryRetrievableHint(bool retrievable) override; |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 31 | void setSeparable(bool separable) override; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 32 | |
Jamie Madill | 9cf9e87 | 2017-06-05 12:59:25 -0400 | [diff] [blame] | 33 | gl::LinkResult link(const gl::Context *context, |
| 34 | const gl::VaryingPacking &packing, |
| 35 | gl::InfoLog &infoLog) override; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 36 | GLboolean validate(const gl::Caps &caps, gl::InfoLog *infoLog) override; |
| 37 | |
| 38 | void setUniform1fv(GLint location, GLsizei count, const GLfloat *v) override; |
| 39 | void setUniform2fv(GLint location, GLsizei count, const GLfloat *v) override; |
| 40 | void setUniform3fv(GLint location, GLsizei count, const GLfloat *v) override; |
| 41 | void setUniform4fv(GLint location, GLsizei count, const GLfloat *v) override; |
| 42 | void setUniform1iv(GLint location, GLsizei count, const GLint *v) override; |
| 43 | void setUniform2iv(GLint location, GLsizei count, const GLint *v) override; |
| 44 | void setUniform3iv(GLint location, GLsizei count, const GLint *v) override; |
| 45 | void setUniform4iv(GLint location, GLsizei count, const GLint *v) override; |
| 46 | void setUniform1uiv(GLint location, GLsizei count, const GLuint *v) override; |
| 47 | void setUniform2uiv(GLint location, GLsizei count, const GLuint *v) override; |
| 48 | void setUniform3uiv(GLint location, GLsizei count, const GLuint *v) override; |
| 49 | void setUniform4uiv(GLint location, GLsizei count, const GLuint *v) override; |
| 50 | void setUniformMatrix2fv(GLint location, |
| 51 | GLsizei count, |
| 52 | GLboolean transpose, |
| 53 | const GLfloat *value) override; |
| 54 | void setUniformMatrix3fv(GLint location, |
| 55 | GLsizei count, |
| 56 | GLboolean transpose, |
| 57 | const GLfloat *value) override; |
| 58 | void setUniformMatrix4fv(GLint location, |
| 59 | GLsizei count, |
| 60 | GLboolean transpose, |
| 61 | const GLfloat *value) override; |
| 62 | void setUniformMatrix2x3fv(GLint location, |
| 63 | GLsizei count, |
| 64 | GLboolean transpose, |
| 65 | const GLfloat *value) override; |
| 66 | void setUniformMatrix3x2fv(GLint location, |
| 67 | GLsizei count, |
| 68 | GLboolean transpose, |
| 69 | const GLfloat *value) override; |
| 70 | void setUniformMatrix2x4fv(GLint location, |
| 71 | GLsizei count, |
| 72 | GLboolean transpose, |
| 73 | const GLfloat *value) override; |
| 74 | void setUniformMatrix4x2fv(GLint location, |
| 75 | GLsizei count, |
| 76 | GLboolean transpose, |
| 77 | const GLfloat *value) override; |
| 78 | void setUniformMatrix3x4fv(GLint location, |
| 79 | GLsizei count, |
| 80 | GLboolean transpose, |
| 81 | const GLfloat *value) override; |
| 82 | void setUniformMatrix4x3fv(GLint location, |
| 83 | GLsizei count, |
| 84 | GLboolean transpose, |
| 85 | const GLfloat *value) override; |
| 86 | |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 87 | void getUniformfv(const gl::Context *context, GLint location, GLfloat *params) const override; |
| 88 | void getUniformiv(const gl::Context *context, GLint location, GLint *params) const override; |
| 89 | void getUniformuiv(const gl::Context *context, GLint location, GLuint *params) const override; |
| 90 | |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 91 | // TODO: synchronize in syncState when dirty bits exist. |
| 92 | void setUniformBlockBinding(GLuint uniformBlockIndex, GLuint uniformBlockBinding) override; |
| 93 | |
| 94 | // May only be called after a successful link operation. |
| 95 | // Return false for inactive blocks. |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 96 | bool getUniformBlockSize(const std::string &blockName, |
| 97 | const std::string &blockMappedName, |
| 98 | size_t *sizeOut) const override; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 99 | |
| 100 | // May only be called after a successful link operation. |
| 101 | // Returns false for inactive members. |
| 102 | bool getUniformBlockMemberInfo(const std::string &memberUniformName, |
Olli Etuaho | 855d964 | 2017-05-17 14:05:06 +0300 | [diff] [blame] | 103 | const std::string &memberUniformMappedName, |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 104 | sh::BlockMemberInfo *memberInfoOut) const override; |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 105 | |
| 106 | void setPathFragmentInputGen(const std::string &inputName, |
| 107 | GLenum genMode, |
| 108 | GLint components, |
| 109 | const GLfloat *coeffs) override; |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 110 | |
| 111 | const vk::ShaderModule &getLinkedVertexModule() const; |
| 112 | const vk::ShaderModule &getLinkedFragmentModule() const; |
Jamie Madill | c514348 | 2017-10-15 20:20:06 -0400 | [diff] [blame] | 113 | const vk::PipelineLayout &getPipelineLayout() const; |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 114 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 115 | vk::Error updateUniforms(ContextVk *contextVk); |
| 116 | |
| 117 | VkDescriptorSet getDescriptorSet() const; |
| 118 | |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 119 | private: |
Jamie Madill | c514348 | 2017-10-15 20:20:06 -0400 | [diff] [blame] | 120 | void reset(VkDevice device); |
| 121 | vk::Error initPipelineLayout(ContextVk *context); |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 122 | vk::Error initDescriptorSets(ContextVk *contextVk); |
| 123 | gl::Error initDefaultUniformBlocks(const gl::Context *glContext); |
| 124 | vk::Error updateDefaultUniformsDescriptorSet(ContextVk *contextVk); |
| 125 | |
| 126 | template <typename T> |
| 127 | void setUniformImpl(GLint location, GLsizei count, const T *v, GLenum entryPointType); |
Jamie Madill | c514348 | 2017-10-15 20:20:06 -0400 | [diff] [blame] | 128 | |
Jamie Madill | 8ecf7f9 | 2017-01-13 17:29:52 -0500 | [diff] [blame] | 129 | vk::ShaderModule mLinkedVertexModule; |
| 130 | vk::ShaderModule mLinkedFragmentModule; |
Jamie Madill | df68a6f | 2017-01-13 17:29:53 -0500 | [diff] [blame] | 131 | vk::PipelineLayout mPipelineLayout; |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 132 | std::vector<vk::DescriptorSetLayout> mDescriptorSetLayouts; |
| 133 | |
| 134 | // State for the default uniform blocks. |
| 135 | struct DefaultUniformBlock final : private angle::NonCopyable |
| 136 | { |
| 137 | DefaultUniformBlock(); |
| 138 | |
| 139 | vk::BufferAndMemory storage; |
| 140 | |
| 141 | // Shadow copies of the shader uniform data. |
| 142 | angle::MemoryBuffer uniformData; |
| 143 | bool uniformsDirty; |
| 144 | |
| 145 | // Since the default blocks are laid out in std140, this tells us where to write on a call |
| 146 | // to a setUniform method. They are arranged in uniform location order. |
| 147 | std::vector<sh::BlockMemberInfo> uniformLayout; |
| 148 | }; |
| 149 | |
| 150 | std::array<DefaultUniformBlock, 2> mDefaultUniformBlocks; |
| 151 | |
| 152 | // This is a special "empty" placeholder buffer for when a shader has no uniforms. |
| 153 | // It is necessary because we want to keep a compatible pipeline layout in all cases, |
| 154 | // and Vulkan does not tolerate having null handles in a descriptor set. |
| 155 | vk::BufferAndMemory mEmptyUniformBlockStorage; |
| 156 | |
| 157 | // Descriptor set for the uniform blocks for this program. |
| 158 | VkDescriptorSet mDescriptorSet; |
Jamie Madill | 9e54b5a | 2016-05-25 12:57:39 -0400 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | } // namespace rx |
| 162 | |
| 163 | #endif // LIBANGLE_RENDERER_VULKAN_PROGRAMVK_H_ |