MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ set_gpu_executor()

void MayaFlux::Nodes::Network::MeshFieldOperator::set_gpu_executor ( std::shared_ptr< Yantra::ShaderExecutionContext<> >  executor,
bool  continuous = true 
)

Attach a GPU executor and switch to async dispatch mode.

Constructs a GpuComputeNode from the executor. On process() calls, compute_frame() is driven on the node instead of the per-slot CPU FieldOperator loop.

The on_complete callback expects gpu_result.primary to contain vertex data for each slot packed sequentially: slot 0 vertices, then slot 1 vertices, etc. Vertex count per slot must match the node's current get_mesh_vertex_count() at the time the callback fires. The callback writes back via slot.node->set_mesh_vertices().

Slot vertex counts are snapshotted at set_gpu_executor() time from the current m_slots state. Call set_gpu_executor() after slots are fully populated. If slot geometry changes after attachment, call set_gpu_executor() again to rebuild the snapshot.

CPU FieldOperator bindings are preserved but ignored while a GPU executor is attached. Passing nullptr clears the GPU path.

Parameters
executorPre-configured ShaderExecutionContext. nullptr clears.
continuousIf true the node re-arms after every completed dispatch.

Definition at line 117 of file MeshFieldOperator.cpp.

119{
120 if (!executor) {
121 m_compute_node.reset();
122 m_executor.reset();
124 return;
125 }
126
128 if (m_slots) {
129 m_gpu_slot_vertex_counts.reserve(m_slots->size());
130 for (const auto& slot : *m_slots) {
131 m_gpu_slot_vertex_counts.push_back(
132 slot.node ? slot.node->get_mesh_vertex_count() : 0);
133 }
134 }
135
136 m_executor = std::move(executor);
137 m_compute_node = std::make_shared<Nodes::GpuSync::GpuComputeNode>(m_executor, continuous);
138
139 m_compute_node->on_complete([this](Nodes::GpuSync::GpuComputeContext& ctx) {
140 if (!m_slots)
141 return;
142
143 const auto& primary = ctx.gpu_result.primary;
144 constexpr size_t floats_per_vertex = sizeof(MeshVertex) / sizeof(float);
145
146 size_t offset = 0;
147 for (size_t i = 0; i < m_slots->size(); ++i) {
148 if (i >= m_gpu_slot_vertex_counts.size())
149 break;
150
151 const size_t vc = m_gpu_slot_vertex_counts[i];
152 const size_t float_count = vc * floats_per_vertex;
153
154 if (offset + float_count > primary.size())
155 break;
156
157 auto& slot = (*m_slots)[i];
158 if (!slot.node) {
159 offset += float_count;
160 continue;
161 }
162
163 std::vector<MeshVertex> verts(vc);
164 std::memcpy(verts.data(), primary.data() + offset,
165 float_count * sizeof(float));
166 slot.node->set_mesh_vertices(std::move(verts));
167
168 offset += float_count;
169 }
170 });
171
172 m_compute_node->set_dirty();
173}
std::shared_ptr< Yantra::ShaderExecutionContext<> > m_executor
std::vector< size_t > m_gpu_slot_vertex_counts
Vertex count per slot index, snapshotted at set_gpu_executor() time.
std::shared_ptr< Nodes::GpuSync::GpuComputeNode > m_compute_node
std::vector< MeshSlot > * m_slots
Kakshya::MeshVertex MeshVertex
Definition VertexSpec.hpp:9

References MayaFlux::Nodes::GpuSync::GpuComputeContext::gpu_result, m_compute_node, m_executor, m_gpu_slot_vertex_counts, MayaFlux::Nodes::Network::MeshOperator::m_slots, and MayaFlux::Yantra::GpuChannelResult::primary.