diff --git a/include/tz/gpu/resource.hpp b/include/tz/gpu/resource.hpp index 81b4cd0dfc..0cf378fdd6 100644 --- a/include/tz/gpu/resource.hpp +++ b/include/tz/gpu/resource.hpp @@ -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. * diff --git a/src/tz/gpu/rhi_vulkan.cpp b/src/tz/gpu/rhi_vulkan.cpp index 4036ee685f..a7161fe00b 100644 --- a/src/tz/gpu/rhi_vulkan.cpp +++ b/src/tz/gpu/rhi_vulkan.cpp @@ -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++) { diff --git a/src/tz/ren/quad.cpp b/src/tz/ren/quad.cpp index 3c395917e1..1734a4cf58 100644 --- a/src/tz/ren/quad.cpp +++ b/src/tz/ren/quad.cpp @@ -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 renderers; + tz::gpu::shader_handle main_pass_shader = tz::nullhand; std::expected 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 initial_quad_data; + ren.data_buffer = tz_must(tz::gpu::create_buffer + ({ + .data = std::as_bytes(std::span(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(id); } diff --git a/test/tz/ren_quad_test.cpp b/test/tz/ren_quad_test.cpp index 7328e5e1ee..61ec53bf86 100644 --- a/test/tz/ren_quad_test.cpp +++ b/test/tz/ren_quad_test.cpp @@ -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(); } \ No newline at end of file