MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
RelaxationEmitProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6
7class RelaxationGridBuffer;
8
9/**
10 * @class RelaxationEmitProcessor
11 * @brief ComputeProcessor that reads the current front generation's raw
12 * state buffer from a RelaxationGridBuffer and writes vertex data
13 * directly into the owning VKBuffer's own storage (Usage::VERTEX).
14 *
15 * Mirrors SDFMeshProcessor's role in ComputeMeshBuffer: dispatches into
16 * the attached buffer itself, bypassing all CPU readback. The "cell_state"
17 * binding is written directly via ShaderFoundry::update_descriptor_buffer
18 * against the grid's raw front-generation handle, since that buffer has no
19 * VKBuffer wrapper. The "vertices" binding targets the attached buffer's
20 * own vk::Buffer and is written the same way, for symmetry and to avoid
21 * mixing bind_buffer with direct descriptor writes within one processor.
22 *
23 * Runs as a flat processor after RelaxationStepProcessor in the chain, so
24 * each cycle emits vertices from whichever generation the step just
25 * finished producing.
26 */
27class MAYAFLUX_API RelaxationEmitProcessor : public ComputeProcessor {
28public:
29 /**
30 * @struct EmitParams
31 * @brief Push constant block for the packed-vertex emit shader.
32 *
33 * Grid width and height occupy the leading fields, matching the
34 * convention RelaxationStepProcessor::GridExtent establishes for the
35 * rule stage. extent scales the emitted NDC span; point_size is written
36 * to the vertex scalar field at offset 24, which point.vert reads as
37 * gl_PointSize.
38 */
39 struct EmitParams {
40 uint32_t width;
41 uint32_t height;
42 float extent { 1.0F };
43 float point_size { 2.0F };
44 };
45
46 /**
47 * @brief Construct an emit processor for the given shader file.
48 * @param shader_path Path to the compute shader that reads cell_state
49 * and writes vertices.
50 * @param workgroup_x Ignored once attached to a grid, which fixes the
51 * local size at 256.
52 */
53 explicit RelaxationEmitProcessor(const std::string& shader_path, uint32_t workgroup_x = 16);
54
55 /**
56 * @brief Construct an emit processor from a generated ShaderSpec.
57 * @param spec ShaderSpec whose kernel writes one packed Kakshya::Vertex
58 * (15 floats) per cell into "vertices" and declares EmitParams as
59 * its leading push constant fields. Its workgroup_size is not
60 * consulted once attached to a grid.
61 */
63
64 /** @brief Set the NDC half-span the grid occupies. Takes effect next cycle. */
65 void set_extent(float extent);
66
67 /** @brief Set the per-point size written to the vertex scalar field. */
68 void set_point_size(float size);
69
70protected:
71 /**
72 * @brief Accept only a RelaxationGridBuffer.
73 * @param cmd_id Command buffer, unused.
74 * @param buffer Buffer being processed.
75 * @return False for any other buffer, which skips execution.
76 *
77 * Fires twice per cycle. Writes no descriptors: a write here lands after
78 * the parent has bound the set.
79 */
80 bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr<VKBuffer>& buffer) override;
81
82 /**
83 * @brief Write the cell_state and vertices descriptors when the
84 * descriptor set is created or rebuilt.
85 */
86 void on_descriptors_created() override;
87
88 /**
89 * @brief Cover the grid with a 1D dispatch and write EmitParams.
90 * @param buffer The attached buffer, expected to be a RelaxationGridBuffer.
91 *
92 * The local size is fixed at 256 and the group count is
93 * ceil(cell_count / 256).
94 */
95 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
96
97 /**
98 * @brief Write the cell_state and vertices descriptors for the grid's
99 * current front generation, then run the parent.
100 */
101 void processing_function(const std::shared_ptr<Buffer>& buffer) override;
102
103private:
104 /**
105 * @brief Point cell_state at the grid's front generation and vertices
106 * at the grid's own vertex storage.
107 * @param grid The attached RelaxationGridBuffer.
108 */
109 void write_state_descriptors(const std::shared_ptr<RelaxationGridBuffer>& grid);
110 /**
111 * @brief Size the push constant block to EmitParams and upload the
112 * current parameters. Called from on_attach and from the setters.
113 */
114 void write_emit_constants();
115
116 EmitParams m_params {};
117 std::shared_ptr<RelaxationGridBuffer> m_grid;
118};
119
120} // namespace MayaFlux::Buffers
bool size
std::shared_ptr< NetworkGeometryBuffer > buffer
Specialized ShaderProcessor for Compute Pipelines.
std::shared_ptr< RelaxationGridBuffer > m_grid
ComputeProcessor that reads the current front generation's raw state buffer from a RelaxationGridBuff...
Push constant block for the packed-vertex emit shader.
Complete declarative description of a generated compute shader.