MayaFlux 1.0.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
81
83 "GpuComputeNode: dispatch complete, {} primary floats, {} aux bindings",
84 m_last_result.primary.size(), m_last_result.aux.size());
85}
86
87void GpuComputeNode::update_context(double /*value*/)
88{
89 m_context_storage = std::make_unique<GpuComputeContext>(m_last_result);
90
91 if (!m_context_storage) {
93 "GpuComputeNode: failed to create GpuComputeContext");
94 }
95}
96
97} // namespace MayaFlux::Nodes::GpuSync
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
Core::GlobalInputConfig input
Definition Config.cpp:42
PickCallback callback
Definition Picker.cpp:22
HookId on_complete(const TypedHook< GpuComputeContext > &callback)
Register a callback fired once per completed dispatch.
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 compute_frame() override
Drive the async dispatch lifecycle.
void notify_tick(double value) override
Notifies all registered callbacks with the current context.
void update_context(double value) override
Updates the context object with the current node state.
bool remove_by_key(const std::type_info &key)
Removes every entry registered with this callable type.
void fire(NodeContext &ctx) const
Calls every entry whose condition, if any, holds.
Definition NodeUtils.cpp:68
HookId add_unique(NodeHook hook, const std::type_info &key, uint8_t tag=0, std::array< double, 2 > params={})
Appends unless an entry with the same key and params exists, in which case that entry's id is returne...
HookList m_conditional_callbacks
Hooks fired on a tick only while their condition holds.
Definition Node.hpp:485
HookList m_callbacks
Hooks fired on every tick.
Definition Node.hpp:478
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.
uint64_t HookId
Identifies one registration inside a HookList.
Definition NodeUtils.hpp:60
std::function< void(ContextT &)> TypedHook
Callback function type for node processing events, parameterised on context type.
Definition NodeUtils.hpp:28
NodeHook adapt_hook(const TypedHook< ContextT > &hook)
Wraps a context-typed hook into a NodeHook.
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:26
std::unordered_map< size_t, std::vector< uint8_t > > aux