MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MeshNetworkProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
6class MeshNetwork;
7}
8
9namespace MayaFlux::Buffers {
10
11/**
12 * @class MeshNetworkProcessor
13 * @brief Uploads concatenated vertex and index data from all MeshNetwork slots.
14 *
15 * Mirrors MeshProcessor but operates over the full slot list of a MeshNetwork
16 * rather than a single MeshBuffer. Each cycle:
17 *
18 * 1. Checks whether any slot is dirty (slot.dirty || node->needs_gpu_update()).
19 * If nothing is dirty the processor is a no-op.
20 * 2. Concatenates vertex bytes from all slots in topological order into a
21 * single aggregate vertex staging buffer.
22 * 3. Concatenates index data with each slot's indices rebased by the running
23 * vertex count so all slots share one index buffer and one draw call.
24 * 4. Uploads both streams to their respective GPU buffers via staging.
25 * 5. Calls set_index_resources() on the vertex VKBuffer to link the index
26 * handle so RenderProcessor can issue an indexed draw.
27 * 6. Clears dirty flags on all uploaded slots and their nodes.
28 *
29 * The attached VKBuffer (Usage::VERTEX) is the combined vertex buffer.
30 * A separate Usage::INDEX VKBuffer is owned by this processor and sized
31 * to fit the total index count across all slots.
32 *
33 * Partial-range re-upload (dirty slots only) is deferred. Any dirty slot
34 * triggers a full re-concatenation, which is correct and cheap for moderate
35 * slot counts.
36 */
37class MAYAFLUX_API MeshNetworkProcessor : public VKBufferProcessor {
38public:
39 explicit MeshNetworkProcessor(
40 std::shared_ptr<Nodes::Network::MeshNetwork> network);
41
42 ~MeshNetworkProcessor() override = default;
43
44protected:
45 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
46 void on_detach(const std::shared_ptr<Buffer>& buffer) override;
47 void processing_function(const std::shared_ptr<Buffer>& buffer) override;
48
49private:
50 std::shared_ptr<Nodes::Network::MeshNetwork> m_network;
51
52 std::shared_ptr<VKBuffer> m_gpu_index_buffer;
53 std::shared_ptr<VKBuffer> m_vertex_staging;
54 std::shared_ptr<VKBuffer> m_index_staging;
55
56 /// @brief Aggregate scratch buffers reused each cycle to avoid allocation.
57 std::vector<uint8_t> m_vertex_aggregate;
58 std::vector<uint32_t> m_index_aggregate;
59
60 /// @brief Per-slot world matrices in sorted_indices order. One mat4 per slot.
61 std::shared_ptr<VKBuffer> m_model_ssbo;
62 /// @brief Per-vertex slot index. One uint32_t per concatenated vertex.
63 std::shared_ptr<VKBuffer> m_slot_index_ssbo;
64
65 /// @brief CPU-side scratch for model matrices, reused each cycle.
66 std::vector<glm::mat4> m_model_aggregate;
67 /// @brief CPU-side scratch for per-vertex slot indices, reused each cycle.
68 std::vector<uint32_t> m_slot_index_aggregate;
69
70 void allocate_gpu_buffers(const std::shared_ptr<VKBuffer>& vertex_buf);
71 void upload_combined(const std::shared_ptr<VKBuffer>& vertex_buf);
72 void link_index_resources(const std::shared_ptr<VKBuffer>& vertex_buf);
73
74 [[nodiscard]] bool any_slot_dirty() const;
75 void clear_slot_dirty_flags();
76
77 [[nodiscard]] size_t total_vertex_bytes() const;
78 [[nodiscard]] size_t total_index_count() const;
79
80 void allocate_ssbo_buffers();
81 void upload_ssbos();
82 void push_ssbo_bindings(const std::shared_ptr<VKBuffer>& buffer);
83};
84
85} // namespace MayaFlux::Buffers
std::shared_ptr< VKBuffer > m_slot_index_ssbo
Per-vertex slot index. One uint32_t per concatenated vertex.
std::vector< uint32_t > m_slot_index_aggregate
CPU-side scratch for per-vertex slot indices, reused each cycle.
std::vector< uint8_t > m_vertex_aggregate
Aggregate scratch buffers reused each cycle to avoid allocation.
std::shared_ptr< Nodes::Network::MeshNetwork > m_network
std::shared_ptr< VKBuffer > m_model_ssbo
Per-slot world matrices in sorted_indices order. One mat4 per slot.
std::vector< glm::mat4 > m_model_aggregate
CPU-side scratch for model matrices, reused each cycle.
Uploads concatenated vertex and index data from all MeshNetwork slots.