Skip to content

Commit

Permalink
* Vulkan WIP - Draw Indirect Count
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Feb 20, 2023
1 parent 934b788 commit 330133b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions demo/gl/tz_gpu_driven_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ int main()
tz::gl::renderer_info rinfo;
rinfo.debug_name("Triangle renderer");
tz::gl::resource_handle dbufh_ref = rinfo.ref_resource(ch, dbufh);
rinfo.set_options({tz::gl::renderer_option::draw_indirect_count});
rinfo.state().graphics.draw_buffer = dbufh_ref;
rinfo.shader().set_shader(tz::gl::shader_stage::vertex, ImportedShaderSource(tz_gpu_driven_demo_render, vertex));
rinfo.shader().set_shader(tz::gl::shader_stage::fragment, ImportedShaderSource(tz_gpu_driven_demo_render, fragment));
Expand Down
2 changes: 2 additions & 0 deletions src/tz/gl/api/renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ namespace tz::gl
no_clear_output,
/// - When a renderer is invoked, the output image is not presented to the screen. If the output is an image_output, this has no effect.
no_present,
/// - The renderer's `state().graphics.draw_buffer` is assumed to contain a uint32 representing the draw count at the very start of the buffer, and the draw commands appear after that count in memory.
draw_indirect_count,
// Final debug ui renderer. Do not use.
_internal_final_dbgui_renderer,
// Internal renderer. Has no effect aside from hiding it from the dbgui.
Expand Down
12 changes: 12 additions & 0 deletions src/tz/gl/impl/vulkan/detail/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,24 @@ namespace tz::gl::vk2
vkCmdDrawIndirect(this->get_command_buffer().native(), command.draw_indirect_buffer->native(), command.offset, command.draw_count, command.stride);
}

void CommandBufferRecording::draw_indirect_count(VulkanCommand::DrawIndirectCount command)
{
this->register_command(command);
vkCmdDrawIndirectCount(this->get_command_buffer().native(), command.draw_indirect_buffer->native(), command.offset, command.draw_indirect_buffer->native(), 0, command.max_draw_count, command.stride);
}

void CommandBufferRecording::draw_indexed_indirect(VulkanCommand::DrawIndexedIndirect command)
{
this->register_command(command);
vkCmdDrawIndexedIndirect(this->get_command_buffer().native(), command.draw_indirect_buffer->native(), command.offset, command.draw_count, command.stride);
}

void CommandBufferRecording::draw_indexed_indirect_count(VulkanCommand::DrawIndexedIndirectCount command)
{
this->register_command(command);
vkCmdDrawIndexedIndirectCount(this->get_command_buffer().native(), command.draw_indirect_buffer->native(), command.offset, command.draw_indirect_buffer->native(), 0, command.max_draw_count, command.stride);
}

void CommandBufferRecording::bind_index_buffer(VulkanCommand::BindIndexBuffer command)
{
this->register_command(command);
Expand Down
20 changes: 19 additions & 1 deletion src/tz/gl/impl/vulkan/detail/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ namespace tz::gl::vk2
VkDeviceSize offset = 0;
};

struct DrawIndirectCount
{
const Buffer* draw_indirect_buffer;
std::uint32_t max_draw_count;
std::uint32_t stride;
VkDeviceSize offset = sizeof(std::uint32_t);
};

/**
* Record an indexed indirect draw.
* See @ref COmmandBufferRecording::draw_indexed_indirect for usage.
Expand All @@ -73,6 +81,14 @@ namespace tz::gl::vk2
VkDeviceSize offset = 0;
};

struct DrawIndexedIndirectCount
{
const Buffer* draw_indirect_buffer;
std::uint32_t max_draw_count;
std::uint32_t stride;
VkDeviceSize offset = sizeof(std::uint32_t);
};

/**
* Bind an index buffer.
* See @ref CommandBufferRecording::bind_index_buffer for usage.
Expand Down Expand Up @@ -230,7 +246,7 @@ namespace tz::gl::vk2
struct DebugEndLabel{};

/// variant type which has alternatives for every single possible recordable command type.
using variant = std::variant<Dispatch, Draw, DrawIndexed, DrawIndirect, DrawIndexedIndirect, BindIndexBuffer, BindPipeline, BindDescriptorSets, BeginRenderPass, EndRenderPass, BufferCopyBuffer, BufferCopyImage, ImageCopyImage, BindBuffer, TransitionImageLayout, SetScissorDynamic, DebugBeginLabel, DebugEndLabel>;
using variant = std::variant<Dispatch, Draw, DrawIndexed, DrawIndirect, DrawIndirectCount, DrawIndexedIndirect, DrawIndexedIndirectCount, BindIndexBuffer, BindPipeline, BindDescriptorSets, BeginRenderPass, EndRenderPass, BufferCopyBuffer, BufferCopyImage, ImageCopyImage, BindBuffer, TransitionImageLayout, SetScissorDynamic, DebugBeginLabel, DebugEndLabel>;
};

enum class CommandPoolFlag
Expand Down Expand Up @@ -317,11 +333,13 @@ namespace tz::gl::vk2
* See @ref VulkanCommand::DrawIndirect for details.
*/
void draw_indirect(VulkanCommand::DrawIndirect draw);
void draw_indirect_count(VulkanCommand::DrawIndirectCount draw);
/**
* Perform some indirect, indexed draws.
* See @ref VulkanCommand::DrawIndexedIndirect for details.
*/
void draw_indexed_indirect(VulkanCommand::DrawIndexedIndirect draw);
void draw_indexed_indirect_count(VulkanCommand::DrawIndexedIndirectCount draw);
void bind_index_buffer(VulkanCommand::BindIndexBuffer bind);
/**
* Bind a list of @ref DescriptorSet.
Expand Down

0 comments on commit 330133b

Please sign in to comment.