From 813a4f2abccc83bcd46873dd3c46e8111063c772 Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Tue, 25 Apr 2023 14:49:33 +0200 Subject: [PATCH] Vulkan: Uniform Buffer Add implementation to clear and bind uniform buffers. --- .../blender/gpu/vulkan/vk_uniform_buffer.cc | 37 +++++++++++++++++-- .../blender/gpu/vulkan/vk_uniform_buffer.hh | 1 + 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/source/blender/gpu/vulkan/vk_uniform_buffer.cc b/source/blender/gpu/vulkan/vk_uniform_buffer.cc index 5add8679d27..2ec593a5fd8 100644 --- a/source/blender/gpu/vulkan/vk_uniform_buffer.cc +++ b/source/blender/gpu/vulkan/vk_uniform_buffer.cc @@ -7,6 +7,8 @@ #include "vk_uniform_buffer.hh" #include "vk_context.hh" +#include "vk_shader.hh" +#include "vk_shader_interface.hh" namespace blender::gpu { @@ -22,13 +24,42 @@ void VKUniformBuffer::update(const void *data) void VKUniformBuffer::allocate(VKContext &context) { buffer_.create(context, size_in_bytes_, GPU_USAGE_STATIC, VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT); + debug::object_label(&context, buffer_.vk_handle(), name_); } -void VKUniformBuffer::clear_to_zero() {} +void VKUniformBuffer::clear_to_zero() +{ + VKContext &context = *VKContext::get(); + if (!buffer_.is_allocated()) { + allocate(context); + } + buffer_.clear(context, 0); +} -void VKUniformBuffer::bind(int /*slot*/) {} +void VKUniformBuffer::bind(int slot, shader::ShaderCreateInfo::Resource::BindType bind_type) +{ + VKContext &context = *VKContext::get(); + if (!buffer_.is_allocated()) { + allocate(context); + } -void VKUniformBuffer::bind_as_ssbo(int /*slot*/) {} + VKShader *shader = static_cast(context.shader); + const VKShaderInterface &shader_interface = shader->interface_get(); + const VKDescriptorSet::Location location = shader_interface.descriptor_set_location(bind_type, + slot); + VKDescriptorSetTracker &descriptor_set = shader->pipeline_get().descriptor_set_get(); + descriptor_set.bind(*this, location); +} + +void VKUniformBuffer::bind(int slot) +{ + bind(slot, shader::ShaderCreateInfo::Resource::BindType::UNIFORM_BUFFER); +} + +void VKUniformBuffer::bind_as_ssbo(int slot) +{ + bind(slot, shader::ShaderCreateInfo::Resource::BindType::STORAGE_BUFFER); +} void VKUniformBuffer::unbind() {} diff --git a/source/blender/gpu/vulkan/vk_uniform_buffer.hh b/source/blender/gpu/vulkan/vk_uniform_buffer.hh index 6e2115229db..ee0f763578b 100644 --- a/source/blender/gpu/vulkan/vk_uniform_buffer.hh +++ b/source/blender/gpu/vulkan/vk_uniform_buffer.hh @@ -39,6 +39,7 @@ class VKUniformBuffer : public UniformBuf, NonCopyable { private: void allocate(VKContext &context); + void bind(int slot, shader::ShaderCreateInfo::Resource::BindType bind_type); }; } // namespace blender::gpu -- 2.30.2