Skip to content

Commit

Permalink
[gpu.pass] graphics_state new members: index_buffer, draw_buffer and …
Browse files Browse the repository at this point in the history
…triangle_count. note that only the latter is actually implemented
  • Loading branch information
harrand committed Oct 19, 2024
1 parent 1ae33e4 commit 1878333
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion demo/tz/tz_triangle_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ int main()
{
.clear_colour = {0.0f, 0.0f, 0.0f, 1.0f},
.colour_targets = colour_targets,
.depth_target = tz::gpu::window_resource
.depth_target = tz::gpu::window_resource,
.triangle_count = 1
},
.shader = graphics,
}));
Expand Down
6 changes: 6 additions & 0 deletions include/tz/gpu/pass.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ namespace tz::gpu
std::span<const resource_handle> colour_targets = {};
/// Optional depth target. This will act as the depth image when performing depth testing/writes.
resource_handle depth_target = tz::nullhand;
/// Buffer containing indices used for every frame.
resource_handle index_buffer = tz::nullhand;
/// Buffer containing an initial count and draw commands for every frame.
resource_handle draw_buffer = tz::nullhand;
/// Describe which faces will be culled during rendering.
cull culling = cull::back;
/// Specifies extra optional behaviour for the pass.
graphics_flag flags = static_cast<graphics_flag>(0);
/// Number of triangles to draw in a frame. @note This is ignored if you are using a draw buffer.
std::size_t triangle_count = 0;
};

struct pass_compute_state
Expand Down
10 changes: 9 additions & 1 deletion src/tz/gpu/rhi_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,14 @@ namespace tz::gpu
{
UNERR(tz::error_code::precondition_failure, "no shader program provided when creating pass. you must provide a valid shader program.");
}
if(info.graphics.index_buffer != tz::nullhand)
{
UNERR(tz::error_code::engine_bug, "support for index buffers is not yet implemented.");
}
if(info.graphics.draw_buffer != tz::nullhand)
{
UNERR(tz::error_code::engine_bug, "support for draw buffers is not yet implemented.");
}
std::size_t ret_id = passes.size();
auto& pass = passes.emplace_back();
std::size_t buffer_count = 0;
Expand Down Expand Up @@ -2386,7 +2394,7 @@ namespace tz::gpu
vkCmdSetScissor(frame.cmds, 0, 1, &sci);
// maybe bind index buffer
// draw[_indexed]/draw_[indexed_]indirect/draw_[indexed_]indirect_count
vkCmdDraw(frame.cmds, 3, 1, 0, 0); // todo: dont hardcode this IDIOT
vkCmdDraw(frame.cmds, pass.info.graphics.triangle_count * 3, 1, 0, 0); // todo: dont hardcode this IDIOT
vkCmdEndRendering(frame.cmds);
if(render_into_system_image)
{
Expand Down

0 comments on commit 1878333

Please sign in to comment.