MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
InstanceSSBOProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
6class InstanceNetwork;
7}
8
9namespace MayaFlux::Buffers {
10
11class InstaneceNetworkBuffer;
12
13/**
14 * @class InstanceSSBOProcessor
15 * @brief Uploads template geometry once and packs per-slot mat4 transforms
16 * into an SSBO each frame for a single instanced draw call.
17 *
18 * Template vertex data is taken from slot 0's node. It is uploaded on
19 * on_attach and on any cycle where slot 0 reports needs_gpu_update(). If
20 * all slots share the same node this covers the shared template. If slots
21 * carry distinct nodes the vertex buffer holds slot 0's geometry only;
22 * callers are responsible for ensuring node topology is consistent across slots.
23 *
24 * Per-instance SSBO is written every cycle that any slot is dirty.
25 * RenderProcessor instance_count is set to network->slot_count() after
26 * each SSBO write.
27 *
28 * SSBO layout (one entry per slot, tightly packed):
29 * binding k_transform_ssbo_binding - mat4 transform[slot_count]
30 *
31 * The shader reads gl_InstanceIndex to index into the transform array.
32 */
33class MAYAFLUX_API InstanceSSBOProcessor : public VKBufferProcessor {
34public:
35 explicit InstanceSSBOProcessor(
36 std::shared_ptr<Nodes::Network::InstanceNetwork> network);
37
38 ~InstanceSSBOProcessor() override = default;
39
40 [[nodiscard]] std::shared_ptr<VKBuffer> get_transform_ssbo() const
41 {
42 return m_transform_ssbo;
43 }
44
45protected:
46 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
47 void on_detach(const std::shared_ptr<Buffer>& buffer) override;
48 void processing_function(const std::shared_ptr<Buffer>& buffer) override;
49
50private:
51 std::shared_ptr<Nodes::Network::InstanceNetwork> m_network;
52
53 std::shared_ptr<VKBuffer> m_vertex_staging;
54 std::shared_ptr<VKBuffer> m_transform_ssbo;
55 std::shared_ptr<VKBuffer> m_transform_staging;
56
57 std::vector<glm::mat4> m_transform_scratch;
58
59 void upload_template(const std::shared_ptr<VKBuffer>& vertex_buf);
60 void upload_transforms(const std::shared_ptr<VKBuffer>& vertex_buf);
61 void push_ssbo_binding(const std::shared_ptr<VKBuffer>& vertex_buf);
62
63 [[nodiscard]] bool any_slot_dirty() const;
64 void clear_dirty_flags();
65
66 static constexpr uint32_t k_transform_ssbo_binding = 1;
67
69};
70
71} // namespace MayaFlux::Buffers
Core::GlobalNetworkConfig network
Definition Config.cpp:37
VKBuffer that renders an InstanceNetwork as a single instanced draw call.
std::shared_ptr< Nodes::Network::InstanceNetwork > m_network
std::shared_ptr< VKBuffer > get_transform_ssbo() const
Uploads template geometry once and packs per-slot mat4 transforms into an SSBO each frame for a singl...