Vulkan: Index Buffer #107358

Merged
Jeroen Bakker merged 4 commits from Jeroen-Bakker/blender:vulkan-index-buffer into main 2023-04-26 08:09:34 +02:00
2 changed files with 36 additions and 4 deletions
Showing only changes of commit 32e8f6796e - Show all commits

View File

@ -11,15 +11,39 @@
namespace blender::gpu {
void VKIndexBuffer::upload_data() {}
void VKIndexBuffer::bind_as_ssbo(uint binding)
void VKIndexBuffer::ensure_updated()
{
if (is_subrange_) {
src_->upload_data();
return;
}
VKContext &context = *VKContext::get();
if (!buffer_.is_allocated()) {
allocate(context);
}
if (data_ != nullptr) {
buffer_.update(data_);
MEM_SAFE_FREE(data_);
}
}
void VKIndexBuffer::upload_data()
{
ensure_updated();
}
void VKIndexBuffer::bind(VKContext &context)
{
context.command_buffer_get().bind(*this, to_vk_index_type(index_type_));
}
void VKIndexBuffer::bind_as_ssbo(uint binding)
{
ensure_updated();
VKContext &context = *VKContext::get();
VKShader *shader = static_cast<VKShader *>(context.shader);
const VKShaderInterface &shader_interface = shader->interface_get();
const VKDescriptorSet::Location location = shader_interface.descriptor_set_location(
@ -48,6 +72,7 @@ void VKIndexBuffer::allocate(VKContext &context)
usage,
static_cast<VkBufferUsageFlagBits>(VK_BUFFER_USAGE_STORAGE_BUFFER_BIT |
VK_BUFFER_USAGE_INDEX_BUFFER_BIT));
debug::object_label(&context, buffer_.vk_handle(), "IndexBuffer");
}
} // namespace blender::gpu

View File

@ -20,12 +20,13 @@ class VKIndexBuffer : public IndexBuf {
void upload_data() override;
void bind_as_ssbo(uint binding) override;
void bind(VKContext &context);
void read(uint32_t *data) const override;
void update_sub(uint start, uint len, const void *data) override;
VkBuffer vk_handle()
VkBuffer vk_handle() const
{
return buffer_.vk_handle();
}
@ -33,6 +34,12 @@ class VKIndexBuffer : public IndexBuf {
private:
void strip_restart_indices() override;
void allocate(VKContext &context);
void ensure_updated();
};
static inline VKIndexBuffer *unwrap(IndexBuf *index_buffer)
{
return static_cast<VKIndexBuffer *>(index_buffer);
}
} // namespace blender::gpu