MayaFlux
0.2.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
5
namespace
MayaFlux::Buffers
{
6
class
VKBuffer;
7
}
// namespace MayaFlux::Buffers
8
9
namespace
MayaFlux::Nodes::GpuSync
{
10
11
/**
12
* @class ComputeOutContext
13
* @brief Context for ComputeOutNode - provides readback buffer access
14
*/
15
class
MAYAFLUX_API
ComputeOutContext
:
public
NodeContext
,
public
GpuVectorData
{
16
public
:
17
ComputeOutContext
(
double
value, std::span<const float> readback_data,
size_t
element_count)
18
:
NodeContext
(value, typeid(
ComputeOutContext
).name())
19
,
GpuVectorData
(readback_data)
20
, element_count(element_count)
21
{
22
}
23
24
size_t
element_count
;
25
26
protected
:
27
friend
class
ComputeOutNode
;
28
};
29
30
/**
31
* @class ComputeOutNode
32
* @brief Node that reads back data from GPU buffer to CPU
33
*
34
* Facilitates GPU → CPU data transfer by downloading compute shader results
35
* into a CPU-accessible vector. Useful for feedback loops where GPU computation
36
* results need to influence CPU-side node processing or decision-making.
37
*
38
* Usage:
39
* // GPU computes particle collisions
40
* auto collision_buffer = std::make_shared<VKBuffer>(...);
41
* auto collision_node = std::make_shared<ComputeOutNode>(collision_buffer, 1);
42
*
43
* // Node reads collision count from GPU
44
* double collision_count = collision_node->process_sample();
45
*/
46
class
MAYAFLUX_API
ComputeOutNode
:
public
GpuSync
{
47
public
:
48
/**
49
* @brief Construct with GPU buffer and element count
50
* @param buffer GPU buffer to read from
51
* @param element_count Number of double elements to read
52
*/
53
ComputeOutNode
(
const
std::shared_ptr<Buffers::VKBuffer>& buffer,
size_t
element_count);
54
55
void
compute_frame()
override
;
56
57
/**
58
* @brief Get full readback array
59
* @return Reference to downloaded data
60
*/
61
[[nodiscard]]
const
std::vector<double>&
get_readback_data
()
const
{
return
m_readback_data; }
62
63
/**
64
* @brief Get specific element from readback data
65
* @param index Element index
66
* @return Element value
67
*/
68
[[nodiscard]]
double
get_element(
size_t
index)
const
;
69
70
/**
71
* @brief Get number of elements
72
* @return Element count
73
*/
74
[[nodiscard]]
size_t
get_element_count
()
const
{
return
m_element_count; }
75
76
/**
77
* @brief Get GPU buffer
78
* @return GPU buffer reference
79
*/
80
[[nodiscard]] std::shared_ptr<Buffers::VKBuffer>
get_gpu_buffer
()
const
{
return
m_gpu_buffer; }
81
82
[[nodiscard]]
bool
needs_gpu_update
()
const override
83
{
84
return
false
;
// Readback nodes don't trigger GPU updates
85
}
86
87
void
clear_gpu_update_flag
()
override
{ }
88
89
/**
90
* @brief Update context with current readback data
91
* @param value Current sample value
92
*/
93
void
update_context(
double
value)
override
;
94
95
/**
96
* @brief Get last created context object
97
* @return Reference to last ComputeOutContext
98
*/
99
NodeContext
&
get_last_context
()
override
{
return
m_context; }
100
101
protected
:
102
mutable
std::vector<float>
m_readback_float_buffer
;
103
ComputeOutContext
m_context { 0.0, {}, 0 };
104
105
private
:
106
std::shared_ptr<Buffers::VKBuffer>
m_gpu_buffer
;
107
std::vector<double>
m_readback_data
;
108
size_t
m_element_count
;
109
};
110
111
}
// namespace MayaFlux::Nodes
GpuSync.hpp
MayaFlux::Nodes::GpuSync::ComputeOutContext::element_count
size_t element_count
Definition
ComputeOutNode.hpp:24
MayaFlux::Nodes::GpuSync::ComputeOutContext::ComputeOutContext
ComputeOutContext(double value, std::span< const float > readback_data, size_t element_count)
Definition
ComputeOutNode.hpp:17
MayaFlux::Nodes::GpuSync::ComputeOutContext
Context for ComputeOutNode - provides readback buffer access.
Definition
ComputeOutNode.hpp:15
MayaFlux::Nodes::GpuSync::ComputeOutNode::m_readback_data
std::vector< double > m_readback_data
Definition
ComputeOutNode.hpp:107
MayaFlux::Nodes::GpuSync::ComputeOutNode::m_readback_float_buffer
std::vector< float > m_readback_float_buffer
Definition
ComputeOutNode.hpp:102
MayaFlux::Nodes::GpuSync::ComputeOutNode::clear_gpu_update_flag
void clear_gpu_update_flag() override
Clear the "needs update" flag after GPU binding.
Definition
ComputeOutNode.hpp:87
MayaFlux::Nodes::GpuSync::ComputeOutNode::m_element_count
size_t m_element_count
Definition
ComputeOutNode.hpp:108
MayaFlux::Nodes::GpuSync::ComputeOutNode::needs_gpu_update
bool needs_gpu_update() const override
Mark if this node needs GPU binding update.
Definition
ComputeOutNode.hpp:82
MayaFlux::Nodes::GpuSync::ComputeOutNode::get_last_context
NodeContext & get_last_context() override
Get last created context object.
Definition
ComputeOutNode.hpp:99
MayaFlux::Nodes::GpuSync::ComputeOutNode::get_readback_data
const std::vector< double > & get_readback_data() const
Get full readback array.
Definition
ComputeOutNode.hpp:61
MayaFlux::Nodes::GpuSync::ComputeOutNode::m_gpu_buffer
std::shared_ptr< Buffers::VKBuffer > m_gpu_buffer
Definition
ComputeOutNode.hpp:106
MayaFlux::Nodes::GpuSync::ComputeOutNode::get_gpu_buffer
std::shared_ptr< Buffers::VKBuffer > get_gpu_buffer() const
Get GPU buffer.
Definition
ComputeOutNode.hpp:80
MayaFlux::Nodes::GpuSync::ComputeOutNode::get_element_count
size_t get_element_count() const
Get number of elements.
Definition
ComputeOutNode.hpp:74
MayaFlux::Nodes::GpuSync::ComputeOutNode
Node that reads back data from GPU buffer to CPU.
Definition
ComputeOutNode.hpp:46
MayaFlux::Nodes::GpuSync::GpuSync
Definition
GpuSync.hpp:21
MayaFlux::Nodes::GpuVectorData
GPU-uploadable 1D array data interface.
Definition
GpuContext.hpp:12
MayaFlux::Nodes::NodeContext
Base context class for node callbacks.
Definition
Node.hpp:30
MayaFlux::Buffers
Definition
Depot.hpp:23
MayaFlux::Nodes::GpuSync
Definition
Registry.hpp:21
src
MayaFlux
Nodes
Graphics
ComputeOutNode.hpp
Generated by
1.9.8