diff --git a/source/blender/gpu/vulkan/vk_descriptor_set.cc b/source/blender/gpu/vulkan/vk_descriptor_set.cc index 579852088ca..81b267066a9 100644 --- a/source/blender/gpu/vulkan/vk_descriptor_set.cc +++ b/source/blender/gpu/vulkan/vk_descriptor_set.cc @@ -9,6 +9,7 @@ #include "vk_index_buffer.hh" #include "vk_storage_buffer.hh" #include "vk_texture.hh" +#include "vk_uniform_buffer.hh" #include "vk_vertex_buffer.hh" #include "BLI_assert.h" @@ -46,6 +47,14 @@ void VKDescriptorSet::bind_as_ssbo(VKVertexBuffer &buffer, const Location locati binding.buffer_size = buffer.size_used_get(); } +void VKDescriptorSet::bind(VKUniformBuffer &buffer, const Location location) +{ + Binding &binding = ensure_location(location); + binding.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + binding.vk_buffer = buffer.vk_handle(); + binding.buffer_size = buffer.size_in_bytes(); +} + void VKDescriptorSet::bind_as_ssbo(VKIndexBuffer &buffer, const Location location) { Binding &binding = ensure_location(location); diff --git a/source/blender/gpu/vulkan/vk_descriptor_set.hh b/source/blender/gpu/vulkan/vk_descriptor_set.hh index 9e2fae1d703..e81e0bfd9dc 100644 --- a/source/blender/gpu/vulkan/vk_descriptor_set.hh +++ b/source/blender/gpu/vulkan/vk_descriptor_set.hh @@ -19,6 +19,7 @@ class VKIndexBuffer; class VKShaderInterface; class VKStorageBuffer; class VKTexture; +class VKUniformBuffer; class VKVertexBuffer; /** @@ -57,9 +58,6 @@ class VKDescriptorSet : NonCopyable { public: Location() = default; - Location(const ShaderInput *shader_input) : binding(shader_input->location) - { - } bool operator==(const Location &other) const { @@ -92,7 +90,7 @@ class VKDescriptorSet : NonCopyable { bool is_buffer() const { - return ELEM(type, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER); + return ELEM(type, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER); } bool is_image() const @@ -136,6 +134,7 @@ class VKDescriptorSet : NonCopyable { void bind_as_ssbo(VKVertexBuffer &buffer, Location location); void bind_as_ssbo(VKIndexBuffer &buffer, Location location); void bind(VKStorageBuffer &buffer, Location location); + void bind(VKUniformBuffer &buffer, Location location); void image_bind(VKTexture &texture, Location location); /** diff --git a/source/blender/gpu/vulkan/vk_uniform_buffer.cc b/source/blender/gpu/vulkan/vk_uniform_buffer.cc index a5024517ce5..1aee3c3eee4 100644 --- a/source/blender/gpu/vulkan/vk_uniform_buffer.cc +++ b/source/blender/gpu/vulkan/vk_uniform_buffer.cc @@ -6,11 +6,22 @@ */ #include "vk_uniform_buffer.hh" +#include "vk_context.hh" namespace blender::gpu { -void VKUniformBuffer::update(const void * /*data*/) +void VKUniformBuffer::update(const void *data) { + VKContext &context = *VKContext::get(); + if (!buffer_.is_allocated()) { + allocate(context); + } + buffer_.update(context, data); +} + +void VKUniformBuffer::allocate(VKContext &context) +{ + buffer_.create(context, size_in_bytes_, GPU_USAGE_STATIC, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT); } void VKUniformBuffer::clear_to_zero() diff --git a/source/blender/gpu/vulkan/vk_uniform_buffer.hh b/source/blender/gpu/vulkan/vk_uniform_buffer.hh index bd5b136f249..ebacb23fed2 100644 --- a/source/blender/gpu/vulkan/vk_uniform_buffer.hh +++ b/source/blender/gpu/vulkan/vk_uniform_buffer.hh @@ -9,9 +9,13 @@ #include "gpu_uniform_buffer_private.hh" +#include "vk_buffer.hh" + namespace blender::gpu { class VKUniformBuffer : public UniformBuf { + VKBuffer buffer_; + public: VKUniformBuffer(int size, const char *name) : UniformBuf(size, name) { @@ -22,6 +26,19 @@ class VKUniformBuffer : public UniformBuf { void bind(int slot) override; void bind_as_ssbo(int slot) override; void unbind() override; + + VkBuffer vk_handle() const + { + return buffer_.vk_handle(); + } + + size_t size_in_bytes() const + { + return size_in_bytes_; + } + + private: + void allocate(VKContext &context); }; } // namespace blender::gpu