MUDA
Loading...
Searching...
No Matches
compute_graph_builder.inl
1#include <muda/compute_graph/compute_graph.h>
2
3namespace muda
4{
5MUDA_INLINE ComputeGraphPhase ComputeGraphBuilder::current_phase()
6{
7 auto ins = instance().m_current_graph;
8 if(ins)
9 return ins->current_graph_phase();
10 else
11 return ComputeGraphPhase::None;
12}
13
14MUDA_INLINE void ComputeGraphBuilder::capture(CaptureAction&& cap)
15{
16 MUDA_ASSERT(instance().current_graph(), "Error current graph = nullptr!");
17 instance().current_graph()->capture(std::move(cap));
18}
19
20MUDA_INLINE void ComputeGraphBuilder::capture(std::string_view name, CaptureAction&& cap)
21{
22 MUDA_ASSERT(instance().current_graph(), "Error current graph = nullptr!");
23 instance().current_graph()->capture(name, std::move(cap));
24}
25
26MUDA_INLINE bool ComputeGraphBuilder::is_phase_none()
27{
28 return current_phase() == ComputeGraphPhase::None;
29}
30
31MUDA_INLINE bool ComputeGraphBuilder::is_phase_serial_launching()
32{
33 return current_phase() == ComputeGraphPhase::SerialLaunching;
34}
35
36MUDA_INLINE bool ComputeGraphBuilder::is_topo_building()
37{
38 return current_phase() == ComputeGraphPhase::TopoBuilding;
39}
40
41MUDA_INLINE bool ComputeGraphBuilder::is_building()
42{
43 return current_phase() == ComputeGraphPhase::Building;
44}
45
46MUDA_INLINE bool ComputeGraphBuilder::is_direct_launching()
47{
48 return is_phase_serial_launching() || is_phase_none();
49}
50
51MUDA_INLINE bool ComputeGraphBuilder::is_caturing()
52{
53 return is_building() && instance().m_current_graph->m_is_capturing;
54}
55
56MUDA_INLINE void ComputeGraphBuilder::invoke_phase_actions(PhaseAction&& do_when_direct_launching,
57 PhaseAction&& do_when_set_node,
58 PhaseAction&& do_when_topo_building)
59{
60 MUDA_ASSERT(do_when_direct_launching, "do_when_direct_launching is null");
61 MUDA_ASSERT(do_when_set_node, "do_when_set_node is null");
62 MUDA_ASSERT(do_when_topo_building, "do_when_topo_building is null");
63 if(is_direct_launching())
64 do_when_direct_launching();
65 else if(is_building())
66 do_when_set_node();
67 else if(is_topo_building())
68 do_when_topo_building();
69}
70
71MUDA_INLINE void ComputeGraphBuilder::invoke_phase_actions(PhaseAction&& do_when_direct_launching,
72 PhaseAction&& do_when_set_node)
73{
74 MUDA_ASSERT(do_when_direct_launching, "do_when_direct_launching is null");
75 MUDA_ASSERT(do_when_set_node, "do_when_set_node is null");
76
77 if(is_direct_launching())
78 do_when_direct_launching();
79 else if(is_building() || is_topo_building())
80 do_when_set_node();
81}
82
83MUDA_INLINE void ComputeGraphBuilder::invoke_phase_actions(PhaseAction&& do_in_every_phase)
84{
85 if(is_direct_launching() || is_building() || is_topo_building())
86 do_in_every_phase();
87}
88
89MUDA_INLINE void ComputeGraphBuilder::current_graph(ComputeGraph* graph)
90{
91 instance().m_current_graph = graph;
92}
93
94MUDA_INLINE ComputeGraphBuilder& muda::ComputeGraphBuilder::instance()
95{
96 thread_local static ComputeGraphBuilder builder;
97 return builder;
98}
99} // namespace muda