Skip to content

Commit

Permalink
[ren] wip quad renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Oct 31, 2024
1 parent 46a2b9e commit cde3c2d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/tz/gpu/resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ namespace tz::gpu
/**
* @ingroup tz_gpu_resource
* @brief Manually destroy a resource.
* @return @ref tz::error_code::invalid_value If you attempt to delete the null resource @ref tz::nullhand.
* @return @ref tz::error_code::invalid_value If you attempt to delete the window resource @ref tz::gpu::window_resource.
* @return @ref tz::error_code::invalid_value If the resource handle provided is invalid. This usually happens due to memory corruption or an accidental double-delete.
* @return @ref tz::error_code::concurrent_usage If the resource is being used by at least one pass.
*
Expand Down
8 changes: 8 additions & 0 deletions src/tz/gpu/rhi_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,14 @@ namespace tz::gpu

tz::error_code destroy_resource(resource_handle res)
{
if(res == tz::nullhand)
{
RETERR(tz::error_code::invalid_value, "Attempt to destroy a null resource");
}
if(res == tz::gpu::window_resource)
{
RETERR(tz::error_code::invalid_value, "Attempt to destroy the window resource");
}
auto& info = resources[res.peek()];
for(std::size_t i = 0; i < passes.size(); i++)
{
Expand Down
53 changes: 53 additions & 0 deletions src/tz/ren/quad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,67 @@ namespace tz::ren
tz::gpu::graph_handle graph = tz::nullhand;
};

struct quad_data
{

};

constexpr std::size_t initial_quad_capacity = 1024;

std::vector<quad_renderer_data> renderers;
tz::gpu::shader_handle main_pass_shader = tz::nullhand;

std::expected<quad_renderer_handle, tz::error_code> create_quad_renderer(quad_renderer_info info)
{
if(main_pass_shader == tz::nullhand)
{
main_pass_shader = tz_must(tz::gpu::create_graphics_shader(ImportedShaderSource(quad, vertex), ImportedShaderSource(quad, fragment)));
}

std::size_t id = renderers.size();
auto& ren = renderers.emplace_back();
ren.info = info;

std::array<quad_data, initial_quad_capacity> initial_quad_data;
ren.data_buffer = tz_must(tz::gpu::create_buffer
({
.data = std::as_bytes(std::span<const quad_data>(initial_quad_data)),
.name = "Quad Renderer Main Pass",
.flags = tz::gpu::buffer_flag::dynamic_access
}));

tz::gpu::resource_handle colour_targets[] =
{
tz::gpu::window_resource
};
tz::gpu::resource_handle resources[] =
{
ren.data_buffer
};
auto maybe_pass = tz::gpu::create_pass
({
.graphics =
{
.colour_targets = colour_targets,
.flags = tz::gpu::graphics_flag::no_depth_test
},
.shader = main_pass_shader,
.resources = resources
});
if(maybe_pass.has_value())
{
ren.main_pass = maybe_pass.value();
}
else
{
return std::unexpected(maybe_pass.error());
}

ren.graph = tz_must(tz::gpu::graph_builder{}
.set_flags(tz::gpu::graph_flag::present_after)
.add_pass(ren.main_pass)
.build());

return static_cast<tz::hanval>(id);
}

Expand Down
2 changes: 1 addition & 1 deletion test/tz/ren_quad_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ int main()

tz::ren::quad_renderer_handle ren = tz_must(tz::ren::create_quad_renderer({}));

//tz_must(tz::ren::destroy_quad_renderer(ren));
while(tz::os::window_is_open())
{
tz::os::window_update();
tz::gpu::execute(tz::ren::quad_renderer_graph(ren));
}

tz_must(tz::ren::destroy_quad_renderer(ren));
tz::terminate();
}

0 comments on commit cde3c2d

Please sign in to comment.