Skip to content

Commit

Permalink
[gpu.vulkan] implemented index buffers
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Nov 12, 2024
1 parent f1ecea7 commit 04f773f
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/tz/gpu/rhi_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2617,6 +2617,15 @@ namespace tz::gpu
// first: transition swapchain image layout from undefined (trashes data) to colour attachment (if we're rendering directly into the window and we're the first pass in the timeline) OR general
vkCmdBeginRendering(frame.cmds, &render);
vkCmdBindPipeline(frame.cmds, VK_PIPELINE_BIND_POINT_GRAPHICS, pass.pipeline);
if(pass.info.graphics.index_buffer != tz::nullhand)
{
const auto& indices = resources[pass.info.graphics.index_buffer.peek()];
if(indices.is_invalid())
{
RETERR(tz::error_code::invalid_value, "Graphics pass \"{}\" uses index buffer handle {}, which is an invalid resource.", pass.info.name, pass.info.graphics.index_buffer.peek());
}
vkCmdBindIndexBuffer(frame.cmds, indices.buf, 0, VK_INDEX_TYPE_UINT32);
}
vkCmdBindDescriptorSets(frame.cmds, VK_PIPELINE_BIND_POINT_GRAPHICS, pass.layout, 0u, 1, pass.descriptor_sets.data() + id, 0, nullptr);

VkViewport vp
Expand Down Expand Up @@ -2646,9 +2655,14 @@ namespace tz::gpu

vkCmdSetViewport(frame.cmds, 0, 1, &vp);
vkCmdSetScissor(frame.cmds, 0, 1, &sci);
// maybe bind index buffer
// draw[_indexed]/draw_[indexed_]indirect/draw_[indexed_]indirect_count
vkCmdDraw(frame.cmds, pass.info.graphics.triangle_count * 3, 1, 0, 0); // todo: dont hardcode this IDIOT
if(pass.info.graphics.index_buffer != tz::nullhand)
{
vkCmdDrawIndexed(frame.cmds, pass.info.graphics.triangle_count * 3, 1, 0, 0, 0);
}
else
{
vkCmdDraw(frame.cmds, pass.info.graphics.triangle_count * 3, 1, 0, 0);
}
vkCmdEndRendering(frame.cmds);
if(render_into_system_image)
{
Expand Down

0 comments on commit 04f773f

Please sign in to comment.