Vulkan: Initial VKUniformBuffer. #105129

Merged
Jeroen Bakker merged 1 commits from Jeroen-Bakker/blender:vulkan-uniform-buffer into main 2023-02-23 14:51:45 +01:00
4 changed files with 41 additions and 5 deletions

View File

@ -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);

View File

@ -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);
/**

View File

@ -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()

View File

@ -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