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

◆ ensure_cluster_ids()

bool MayaFlux::Buffers::NetworkGeometryBuffer::ensure_cluster_ids ( )

Ensure the hash_cluster_id state field exists, declaring and populating it from the network's own primary GraphicsOperator if nothing has already done so.

Returns
True if hash_cluster_id exists by the time this returns (already did, or was just created); false if there is no primary GraphicsOperator to size it from, or it reports zero vertices.

Sized to get_vertex_count(), not get_point_count(): a GPU consumer indexes this field in lockstep with the vertex buffer itself, and for an operator whose rendered vertex count differs from its source point count (TopologyOperator/PathOperator after interpolation) those are two different numbers. Coincide for PhysicsOperator's point-sprite geometry, so this changes nothing for the particle path.

has_state-guarded, so whichever caller reaches this first (a this buffer's own field-operator wiring, or a VertexFieldProcessor attaching with a cluster-scoped GpuFieldOperator binding) does the real work and the other finds it already done. Values come from GraphicsOperator::build_cluster_ids(): every entry 0 for any operator that has never overridden it, which is every one except PhysicsOperator today, so calling this against a PointCloudNetwork or plain FieldOperator-driven network is safe and simply declares a field whose only value is 0.

Definition at line 429 of file NetworkGeometryBuffer.cpp.

430{
431 if (has_state("hash_cluster_id")) {
432 return true;
433 }
434
435 auto* graphics_op = m_network
436 ? dynamic_cast<Nodes::Network::GraphicsOperator*>(m_network->get_operator())
437 : nullptr;
438 if (!graphics_op) {
439 return false;
440 }
441
442 const size_t vertex_count = graphics_op->get_vertex_count();
443 if (vertex_count == 0) {
444 return false;
445 }
446
447 if (!declare_state("hash_cluster_id", vertex_count, sizeof(uint32_t), false)) {
448 return false;
449 }
450
451 auto cluster_ids = graphics_op->build_cluster_ids();
452 if (cluster_ids.size() != vertex_count) {
453 cluster_ids.assign(vertex_count, 0U);
454 }
455
456 std::shared_ptr<VKBuffer> staging;
458 write_state_slot("hash_cluster_id"),
459 cluster_ids.data(),
460 cluster_ids.size() * sizeof(uint32_t),
461 staging);
462
463 return true;
464}
bool declare_state(const std::string &name, size_t element_count, size_t stride_bytes, bool double_buffered=true)
Declare a named auxiliary state field alongside the vertex data.
std::shared_ptr< Nodes::Network::NodeNetwork > m_network
bool has_state(const std::string &name) const
Whether a state field of this name was declared.
VKBufferResources::GenerationSlot write_state_slot(const std::string &name) const
Full back_buffers slot a stage should write the named state field to.
void upload_back_buffer(const VKBufferResources::GenerationSlot &slot, const void *data, size_t size, std::shared_ptr< VKBuffer > &staging)
Upload host memory into a raw back_buffers slot.

References declare_state(), has_state(), m_network, MayaFlux::Buffers::upload_back_buffer(), and write_state_slot().

+ Here is the call graph for this function: