MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GpuComputeNode.cpp
Go to the documentation of this file.
1#include "GpuComputeNode.hpp"
2
5
7
9 std::shared_ptr<Yantra::ShaderExecutionContext<>> executor,
10 bool continuous)
11 : m_executor(std::move(executor))
12 , m_continuous(continuous)
13{
14 if (!m_executor) {
15 error<std::invalid_argument>(
17 std::source_location::current(),
18 "GpuComputeNode: null ShaderExecutionContext");
19 }
20}
21
22// =============================================================================
23// GpuSync interface
24// =============================================================================
25
27{
29
31 if (!foundry.is_fence_signaled(m_pending_fence))
32 return;
33
34 const auto result = m_executor->collect_result();
35
37 m_ready = true;
38
39 m_last_result = result;
40 notify_tick(0.0);
41
42 if (m_continuous)
43 m_dirty = true;
44
45 return;
46 }
47
48 if (!m_dirty)
49 return;
50
51 m_dirty = false;
52 m_ready = false;
53
55 m_pending_fence = m_executor->dispatch_async(input);
56
59 "GpuComputeNode: dispatch_async returned INVALID_FENCE");
60 m_dirty = true;
61 }
62}
63
68
73
74void GpuComputeNode::notify_tick(double /*value*/)
75{
76 update_context(0.0);
77
78 for (auto& cb : m_complete_callbacks)
80
82 "GpuComputeNode: dispatch complete, {} primary floats, {} aux bindings",
83 m_last_result.primary.size(), m_last_result.aux.size());
84}
85
86void GpuComputeNode::update_context(double /*value*/)
87{
88 m_context_storage = std::make_unique<GpuComputeContext>(m_last_result);
89
90 if (!m_context_storage) {
92 "GpuComputeNode: failed to create GpuComputeContext");
93 }
94}
95
96} // namespace MayaFlux::Nodes::GpuSync
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
Core::GlobalInputConfig input
Definition Config.cpp:36
std::shared_ptr< Yantra::ShaderExecutionContext<> > m_executor
bool remove_complete_hook(const TypedHook< GpuComputeContext > &callback)
Remove a previously registered on_complete callback.
GpuComputeNode(std::shared_ptr< Yantra::ShaderExecutionContext<> > executor, bool continuous=false)
Construct with a configured ShaderExecutionContext.
std::unique_ptr< GpuComputeContext > m_context_storage
void on_complete(const TypedHook< GpuComputeContext > &callback)
Register a callback fired once per completed dispatch.
void compute_frame() override
Drive the async dispatch lifecycle.
void notify_tick(double value) override
Notifies all registered callbacks with the current context.
std::vector< TypedHook< GpuComputeContext > > m_complete_callbacks
void update_context(double value) override
Updates the context object with the current node state.
Concrete GpuExecutionContext for a single fixed shader with fixed bindings.
@ NodeProcessing
Node graph processing (Nodes::NodeGraphManager)
@ Init
Engine/subsystem initialization.
@ Nodes
DSP Generator and Filter Nodes, graph pipeline, node management.
std::function< void(ContextT &)> TypedHook
Callback function type for node processing events, parameterised on context type.
Definition NodeUtils.hpp:28
bool safe_remove_callback(std::vector< TypedHook< ContextT > > &callbacks, const TypedHook< ContextT > &callback)
Removes all callbacks whose target_type() matches that of the supplied callback.
Definition NodeUtils.hpp:92
bool safe_add_callback(std::vector< TypedHook< ContextT > > &callbacks, const TypedHook< ContextT > &callback)
Adds a callback to the collection if an equivalent one is not already present.
Definition NodeUtils.hpp:77
constexpr FenceID INVALID_FENCE
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
Input/Output container for computation pipeline data flow with structure preservation.
Definition DataIO.hpp:24
std::unordered_map< size_t, std::vector< uint8_t > > aux