MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GpuSync.hpp
Go to the documentation of this file.
1#pragma once
2
4
6
7/**
8 * @class GpuSyncNode
9 * @brief Base abstraction for CPU-GPU coordinated nodes
10 *
11 * Captures the common pattern of "CPU computation at VISUAL_RATE
12 * that produces GPU-bindable data". Provides:
13 * - Frame synchronization (`compute_frame()` pure virtual)
14 * - Unified process_sample/batch interface
15 * - Error logging and state management
16 * - Optional layout caching for Kakshya bindings
17 *
18 * Does NOT own data storage (too heterogeneous).
19 * Subclasses (TextureNode, GeometryWriterNode) own their buffers.
20 */
21class MAYAFLUX_API GpuSync : public Node {
22public:
23 ~GpuSync() override = default;
24
25 /**
26 * @brief Compute GPU data for this frame
27 *
28 * Called once per VISUAL_RATE tick. Subclasses populate their
29 * respective buffers (pixel_buffer, vertex_buffer, readback_data).
30 */
31 virtual void compute_frame() = 0;
32
33 /**
34 * @brief Single sample processing hook
35 * @param input Unused for most GPU sync nodes
36 * @return Always 0.0 (GPU nodes don't produce scalar audio output)
37 */
38 double process_sample(double /*input*/) override
39 {
40 compute_frame();
41 return 0.0;
42 }
43
44 /**
45 * @brief Batch processing for GPU nodes
46 * @param num_samples Number of frames to process
47 * @return Zero-filled vector (no audio output)
48 */
49 std::vector<double> process_batch(unsigned int num_samples) override
50 {
51 for (unsigned int i = 0; i < num_samples; ++i) {
52 compute_frame();
53 }
54 return std::vector<double>(num_samples, 0.0);
55 }
56
57 /**
58 * @brief Mark if this node needs GPU binding update
59 * @return True if data layout or count changed
60 */
61 [[nodiscard]] virtual bool needs_gpu_update() const = 0;
62
63 /**
64 * @brief Clear the "needs update" flag after GPU binding
65 */
66 virtual void clear_gpu_update_flag() = 0;
67
68protected:
69 /**
70 * @brief GPU sync nodes don't produce scalar contexts
71 */
72 std::unique_ptr<NodeContext> create_context(double /*value*/) override
73 {
74 return nullptr;
75 }
76
77 /**
78 * @brief GPU sync nodes don't emit tick callbacks
79 */
80 void notify_tick(double /*value*/) override { }
81};
82
83} // namespace MayaFlux::Nodes::GpuSync
virtual void compute_frame()=0
Compute GPU data for this frame.
virtual bool needs_gpu_update() const =0
Mark if this node needs GPU binding update.
void notify_tick(double) override
GPU sync nodes don't emit tick callbacks.
Definition GpuSync.hpp:80
virtual void clear_gpu_update_flag()=0
Clear the "needs update" flag after GPU binding.
double process_sample(double) override
Single sample processing hook.
Definition GpuSync.hpp:38
std::unique_ptr< NodeContext > create_context(double) override
GPU sync nodes don't produce scalar contexts.
Definition GpuSync.hpp:72
std::vector< double > process_batch(unsigned int num_samples) override
Batch processing for GPU nodes.
Definition GpuSync.hpp:49
Base interface for all computational processing nodes.
Definition Node.hpp:109