WIP: Vulkan: Workbench #107886

Closed
Jeroen Bakker wants to merge 88 commits from Jeroen-Bakker:vulkan-draw-manager-workbench into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
6 changed files with 31 additions and 7 deletions
Showing only changes of commit ab725fddd4 - Show all commits

View File

@ -66,6 +66,8 @@ class VKBuffer {
*
* VKImmediate mode uses a single VKBuffer with multiple vertex layouts. Those layouts are send to
* the command buffer containing an offset.
*
* VKIndexBuffer uses this when it is a subrange of another buffer.
*/
struct VKBufferWithOffset {
VKBuffer &buffer;

View File

@ -116,12 +116,12 @@ 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)
void VKCommandBuffer::bind(const VKBufferWithOffset &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);
vkCmdBindIndexBuffer(
vk_command_buffer_, index_buffer.buffer.vk_handle(), index_buffer.offset, index_type);
}
void VKCommandBuffer::begin_render_pass(const VKFrameBuffer &framebuffer)

View File

@ -144,7 +144,8 @@ class VKCommandBuffer : NonCopyable, NonMovable {
/* Bind the given buffer as a vertex buffer. */
void bind(const uint32_t binding, const VKBufferWithOffset &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);
/* Bind the given buffer as an index buffer. */
void bind(const VKBufferWithOffset &index_buffer, VkIndexType index_type);
void begin_render_pass(const VKFrameBuffer &framebuffer);
void end_render_pass(const VKFrameBuffer &framebuffer);

View File

@ -97,4 +97,6 @@ template<typename T> VkObjectType to_vk_object_type(T /*vk_obj*/)
return VK_OBJECT_TYPE_UNKNOWN;
}
#define NOT_YET_IMPLEMENTED printf("%s not implemented yet\n", __func__);
} // namespace blender::gpu

View File

@ -35,7 +35,7 @@ void VKIndexBuffer::upload_data()
void VKIndexBuffer::bind(VKContext &context)
{
context.command_buffer_get().bind(*this, to_vk_index_type(index_type_));
context.command_buffer_get().bind(buffer_with_offset(), to_vk_index_type(index_type_));
}
void VKIndexBuffer::bind_as_ssbo(uint binding)
@ -61,9 +61,15 @@ void VKIndexBuffer::read(uint32_t *data) const
buffer_.read(data);
}
void VKIndexBuffer::update_sub(uint /*start*/, uint /*len*/, const void * /*data*/) {}
void VKIndexBuffer::update_sub(uint /*start*/, uint /*len*/, const void * /*data*/)
{
NOT_YET_IMPLEMENTED
}
void VKIndexBuffer::strip_restart_indices() {}
void VKIndexBuffer::strip_restart_indices()
{
NOT_YET_IMPLEMENTED
}
void VKIndexBuffer::allocate()
{
@ -75,4 +81,16 @@ void VKIndexBuffer::allocate()
debug::object_label(buffer_.vk_handle(), "IndexBuffer");
}
VKBufferWithOffset VKIndexBuffer::buffer_with_offset()
{
VKIndexBuffer *src = unwrap(src_);
VKBufferWithOffset result{is_subrange_ ? src->buffer_ : buffer_, index_start_};
BLI_assert_msg(is_subrange_ || result.offset == 0,
"According to design index_start should always be zero when index buffer isn't "
"a subrange");
return result;
}
} // namespace blender::gpu

View File

@ -35,6 +35,7 @@ class VKIndexBuffer : public IndexBuf {
void strip_restart_indices() override;
void allocate();
void ensure_updated();
VKBufferWithOffset buffer_with_offset();
};
static inline VKIndexBuffer *unwrap(IndexBuf *index_buffer)