MayaFlux 0.5.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 Local workgroup size along X, forwarded to ComputeProcessor.
51 */
52 explicit RelaxationEmitProcessor(const std::string& shader_path, uint32_t workgroup_x = 16);
53
54 /**
55 * @brief Construct an emit processor from a generated ShaderSpec.
56 * @param spec ShaderSpec implementing the state-to-vertex mapping,
57 * typically an Elementwise spec built from a factory such as
58 * the binary/scalar-ramp/rgba emit shaders.
59 */
61
62 /** @brief Set the NDC half-span the grid occupies. Takes effect next cycle. */
63 void set_extent(float extent);
64
65 /** @brief Set the per-point size written to the vertex scalar field. */
66 void set_point_size(float size);
67
68protected:
69 /**
70 * @brief Write the cell_state and vertices descriptor bindings for
71 * this cycle's dispatch.
72 * @param cmd_id Command buffer this cycle's dispatch will be recorded into.
73 * @param buffer The attached RelaxationGridBuffer, received as VKBuffer.
74 * @return True unconditionally; emission always runs when the buffer
75 * is a valid RelaxationGridBuffer.
76 */
77 bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr<VKBuffer>& buffer) override;
78
79 /**
80 * @brief When attached to a RelaxationGridBuffer, sets up the dispatch
81 * configuration to cover the entire grid with a single workgroup
82 * dimension along Y and Z, and a workgroup size along X that is
83 * either the default 16 or the value supplied at construction.
84 * @param buffer The attached buffer, expected to be a RelaxationGridBuffer.
85 */
86 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
87
88 /**
89 * @brief Write the cell_state and vertices descriptors for the grid's
90 * current front generation, then run the normal shader
91 * processing path.
92 */
93 void processing_function(const std::shared_ptr<Buffer>& buffer) override;
94
95private:
96 /**
97 * @brief Size the push constant block to EmitParams and upload the
98 * current parameters. Called from on_attach and from the setters.
99 */
100 void write_emit_constants();
101
102 EmitParams m_params {};
103 std::shared_ptr<RelaxationGridBuffer> m_grid;
104};
105
106} // namespace MayaFlux::Buffers
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.