Vulkan: Index Buffer #107358
|
@ -9,6 +9,7 @@
|
|||
#include "vk_buffer.hh"
|
||||
#include "vk_context.hh"
|
||||
#include "vk_framebuffer.hh"
|
||||
#include "vk_index_buffer.hh"
|
||||
#include "vk_memory.hh"
|
||||
#include "vk_pipeline.hh"
|
||||
#include "vk_texture.hh"
|
||||
|
@ -103,6 +104,14 @@ void VKCommandBuffer::bind(const uint32_t binding,
|
|||
vkCmdBindVertexBuffers(vk_command_buffer_, binding, 1, &vk_vertex_buffer, &offset);
|
||||
}
|
||||
|
||||
void VKCommandBuffer::bind(const VKIndexBuffer &index_buffer, VkIndexType index_type)
|
||||
{
|
||||
validate_framebuffer_exists();
|
||||
ensure_active_framebuffer();
|
||||
VkBuffer vk_buffer = index_buffer.vk_handle();
|
||||
vkCmdBindIndexBuffer(vk_command_buffer_, vk_buffer, 0, index_type);
|
||||
}
|
||||
|
||||
void VKCommandBuffer::begin_render_pass(const VKFrameBuffer &framebuffer)
|
||||
{
|
||||
validate_framebuffer_not_exists();
|
||||
|
|
|
@ -131,6 +131,7 @@ class VKCommandBuffer : NonCopyable, NonMovable {
|
|||
void init(const VkDevice vk_device, const VkQueue vk_queue, VkCommandBuffer vk_command_buffer);
|
||||
void begin_recording();
|
||||
void end_recording();
|
||||
|
||||
void bind(const VKPipeline &vk_pipeline, VkPipelineBindPoint bind_point);
|
||||
void bind(const VKDescriptorSet &descriptor_set,
|
||||
const VkPipelineLayout vk_pipeline_layout,
|
||||
|
@ -140,6 +141,7 @@ class VKCommandBuffer : NonCopyable, NonMovable {
|
|||
const VkDeviceSize offset);
|
||||
/* Bind the given buffer as a vertex buffer. */
|
||||
void bind(const uint32_t binding, const VkBuffer &vk_vertex_buffer, const VkDeviceSize offset);
|
||||
void bind(const VKIndexBuffer &index_buffer, VkIndexType index_type);
|
||||
|
||||
void begin_render_pass(const VKFrameBuffer &framebuffer);
|
||||
void end_render_pass(const VKFrameBuffer &framebuffer);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue