MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
GeometryWriteProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace MayaFlux::Buffers {
7
8/**
9 * @enum GeometryWriteMode
10 * @brief Specifies how vertex data should be interpreted for upload
11 */
12enum class GeometryWriteMode : uint8_t {
13 POINT, ///< Interpret vertex data as Nodes::PointVertex
14 LINE, ///< Interpret vertex data as Nodes::LineVertex
15 MESH ///< Interpret vertex data as Nodes::MeshVertex
16};
17
18/**
19 * @struct VertexSnapshot
20 * @brief Owned copy of pre-resolved vertex bytes and their layout.
21 */
23 std::vector<std::byte> bytes;
25};
26
27/**
28 * @class GeometryWriteProcessor
29 * @brief Accepts externally-supplied DataVariant and uploads it as vertex
30 * data to a VKBuffer each cycle.
31 *
32 * Converts the supplied DataVariant to a vertex representation via
33 * Kakshya::as_vertex_access() and uploads the result to the attached
34 * VKBuffer. The VertexLayout derived from the conversion is set on the
35 * buffer so RenderProcessor has full stride and attribute information.
36 *
37 * Dirty gating: upload occurs only when new data has been supplied via
38 * set_data() since the last cycle. No stale re-upload.
39 *
40 * Thread safety: set_data() and the graphics thread may run concurrently.
41 * Lock-free double-buffer swap via atomic_flag ensures the graphics thread
42 * never blocks on the supplier thread.
43 *
44 * Staging: if the attached VKBuffer is device-local a staging buffer is
45 * created automatically on on_attach() and reused every cycle.
46 */
47class MAYAFLUX_API GeometryWriteProcessor : public VKBufferProcessor {
48public:
50 ~GeometryWriteProcessor() override = default;
51
52 /**
53 * @brief Supply vertex data for the next cycle.
54 * @param variant Any DataVariant type accepted by as_vertex_access().
55 * Conversion to vertex representation is deferred to
56 * processing_function() on the graphics thread.
57 */
58 void set_data(Kakshya::DataVariant variant);
59
60 /**
61 * @brief Supply pre-resolved vertex bytes for the next cycle.
62 * @param data Pointer to vertex data.
63 * @param byte_count Total size in bytes.
64 * @param layout VertexLayout describing stride and attributes.
65 *
66 * Bypasses as_*_vertex_access conversion entirely. The processor
67 * copies the data and uploads it on the next graphics cycle.
68 */
69 void set_vertices(const void* data, size_t byte_count,
70 const Kakshya::VertexLayout& layout);
71
72 /**
73 * @brief Returns true if a snapshot has been set and not yet consumed.
74 */
75 [[nodiscard]] bool has_pending() const noexcept;
76
77 void set_mode(GeometryWriteMode mode) { m_mode = mode; }
78 void set_config(const Kakshya::VertexAccessConfig& config) { m_config = config; }
79
80protected:
81 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
82 void on_detach(const std::shared_ptr<Buffer>& buffer) override;
83 void processing_function(const std::shared_ptr<Buffer>& buffer) override;
84
85private:
86 std::optional<Kakshya::DataVariant> m_pending_data;
87 std::optional<Kakshya::DataVariant> m_active_data;
88 std::optional<VertexSnapshot> m_pending_vertices;
89 std::optional<VertexSnapshot> m_active_vertices;
90
92 GeometryWriteMode m_mode { GeometryWriteMode::POINT };
93
94 std::atomic_flag m_data_dirty;
95 std::atomic_flag m_vertices_dirty;
96
97 std::shared_ptr<VKBuffer> m_staging;
98};
99
100} // namespace MayaFlux::Buffers
void set_config(const Kakshya::VertexAccessConfig &config)
std::optional< Kakshya::DataVariant > m_pending_data
std::optional< Kakshya::DataVariant > m_active_data
std::optional< VertexSnapshot > m_pending_vertices
std::optional< VertexSnapshot > m_active_vertices
Accepts externally-supplied DataVariant and uploads it as vertex data to a VKBuffer each cycle.
GeometryWriteMode
Specifies how vertex data should be interpreted for upload.
@ LINE
Interpret vertex data as Nodes::LineVertex.
@ MESH
Interpret vertex data as Nodes::MeshVertex.
@ POINT
Interpret vertex data as Nodes::PointVertex.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:76
Owned copy of pre-resolved vertex bytes and their layout.
Default attribute values for shader-compatible vertex conversion.
Complete description of vertex data layout in a buffer.