Skip to content

Commit

Permalink
[gpu.graph] added graph_info.on_execute so that the user has a CPU ca…
Browse files Browse the repository at this point in the history
…llback function when the graph is executed. this is pretty pointless right now, but will be useful for the imgui render backend and also for when subgraphs are implemented
  • Loading branch information
harrand committed Nov 14, 2024
1 parent b74d0d2 commit 5d929c1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
4 changes: 3 additions & 1 deletion include/tz/gpu/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace tz::gpu
return static_cast<int>(lhs) & static_cast<int>(rhs);
}

using graph_handle = tz::handle<pass_handle>;

/**
* @ingroup tz_gpu_graph
Expand All @@ -45,9 +46,10 @@ namespace tz::gpu
std::span<std::span<const pass_handle>> dependencies = {};
/// Specifies extra optional behaviour for the graph.
graph_flag flags = static_cast<graph_flag>(0);
/// Optional. Executed when the graph is executed.
void(*on_execute)(graph_handle graph) = nullptr;
};

using graph_handle = tz::handle<pass_handle>;
/**
* @ingroup tz_gpu_graph
* @brief Helper struct for creating a new graph. Follows the builder pattern.
Expand Down
3 changes: 3 additions & 0 deletions include/tz/imgui.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include "imgui.h"
#include "tz/gpu/graph.hpp"

namespace tz::detail
{
void imgui_initialise();
void imgui_terminate();

tz::gpu::graph_handle imgui_render_graph();
}
8 changes: 6 additions & 2 deletions src/tz/gpu/rhi_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1614,16 +1614,20 @@ namespace tz::gpu

void execute(graph_handle graphh)
{
const auto& graph = graphs[graphh.peek()];
if(graph.info.on_execute != nullptr)
{
graph.info.on_execute(graphh);
}

impl_check_for_resize();
if(swapchain_width == 0 || swapchain_height == 0)
{
return;
}
const auto& frame = frames[current_frame];
const auto& graph = graphs[graphh.peek()];
auto present_pass_iter = std::find(graph.timeline.begin(), graph.timeline.end(), tz::gpu::present_pass);
const bool will_present = present_pass_iter != graph.timeline.end();


std::uint32_t image_index;
if(will_present)
Expand Down
17 changes: 17 additions & 0 deletions src/tz/imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ namespace tz::detail
tz::gpu::shader_handle shader = tz::nullhand;

std::vector<tz::gpu::pass_handle> passes = {};
tz::gpu::graph_handle graph = tz::nullhand;
} render;

void impl_write_vertices_and_indices(ImDrawData* draw);
void impl_add_new_pass();
void impl_on_render(tz::gpu::graph_handle graph);

void imgui_initialise()
{
Expand Down Expand Up @@ -76,6 +78,8 @@ namespace tz::detail
ImportedShaderSource(imgui, fragment)
));

// empty graph for now, because we dont know what imgui wants to draw until we end the frame.
render.graph = tz_must(tz::gpu::create_graph(tz::gpu::graph_info{.on_execute = impl_on_render}));
}

void imgui_terminate()
Expand All @@ -90,9 +94,22 @@ namespace tz::detail
tz::gpu::destroy_shader(render.shader);
ImGui::DestroyContext();
}

tz::gpu::graph_handle imgui_render_graph()
{
return render.graph;
}

// impl bits

void impl_on_render(gpu::graph_handle graph)
{
(void)graph;
// we have a graph that could be completely wrong.
ImDrawData* draws = ImGui::GetDrawData();
(void)draws;
}

void impl_write_vertices_and_indices(ImDrawData* draw)
{
const auto req_idx_size = static_cast<std::size_t>(draw->TotalIdxCount) * sizeof(ImDrawIdx);
Expand Down

0 comments on commit 5d929c1

Please sign in to comment.