MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ComputeOutNode.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "GpuSync.hpp"
4
5namespace MayaFlux::Buffers {
6class VKBuffer;
7} // namespace MayaFlux::Buffers
8
10
11/**
12 * @class ComputeOutNode
13 * @brief Node that reads back data from GPU buffer to CPU
14 *
15 * Facilitates GPU → CPU data transfer by downloading compute shader results
16 * into a CPU-accessible vector. Useful for feedback loops where GPU computation
17 * results need to influence CPU-side node processing or decision-making.
18 *
19 * Usage:
20 * // GPU computes particle collisions
21 * auto collision_buffer = std::make_shared<VKBuffer>(...);
22 * auto collision_node = std::make_shared<ComputeOutNode>(collision_buffer, 1);
23 *
24 * // Node reads collision count from GPU
25 * double collision_count = collision_node->process_sample();
26 */
27class MAYAFLUX_API ComputeOutNode : public GpuSync {
28public:
29 /**
30 * @brief Construct with GPU buffer and element count
31 * @param buffer GPU buffer to read from
32 * @param element_count Number of double elements to read
33 */
34 ComputeOutNode(const std::shared_ptr<Buffers::VKBuffer>& buffer, size_t element_count);
35
36 void compute_frame() override;
37
38 /**
39 * @brief Get full readback array
40 * @return Reference to downloaded data
41 */
42 [[nodiscard]] const std::vector<double>& get_readback_data() const { return m_readback_data; }
43
44 /**
45 * @brief Get specific element from readback data
46 * @param index Element index
47 * @return Element value
48 */
49 [[nodiscard]] double get_element(size_t index) const;
50
51 /**
52 * @brief Get number of elements
53 * @return Element count
54 */
55 [[nodiscard]] size_t get_element_count() const { return m_element_count; }
56
57 /**
58 * @brief Get GPU buffer
59 * @return GPU buffer reference
60 */
61 [[nodiscard]] std::shared_ptr<Buffers::VKBuffer> get_gpu_buffer() const { return m_gpu_buffer; }
62
63 [[nodiscard]] bool needs_gpu_update() const override
64 {
65 return false; // Readback nodes don't trigger GPU updates
66 }
67
68 void clear_gpu_update_flag() override { }
69
70private:
71 std::shared_ptr<Buffers::VKBuffer> m_gpu_buffer;
72 std::vector<double> m_readback_data;
74};
75
76} // namespace MayaFlux::Nodes
void clear_gpu_update_flag() override
Clear the "needs update" flag after GPU binding.
bool needs_gpu_update() const override
Mark if this node needs GPU binding update.
const std::vector< double > & get_readback_data() const
Get full readback array.
std::shared_ptr< Buffers::VKBuffer > m_gpu_buffer
std::shared_ptr< Buffers::VKBuffer > get_gpu_buffer() const
Get GPU buffer.
size_t get_element_count() const
Get number of elements.
Node that reads back data from GPU buffer to CPU.