MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
PressureProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6
7/**
8 * @class PressureProcessor
9 * @brief VolumeFieldProcessor solving the pressure Poisson equation by
10 * Jacobi iteration.
11 *
12 * Records every iteration into one command buffer via
13 * ComputeProcessor::iteration_count, so a forty-pass solve costs one
14 * submission rather than forty. Between consecutive passes a
15 * compute-to-compute barrier is issued on both pressure slots, since the
16 * attached volume's own handle is not what the passes touch.
17 *
18 * Both pressure slots are bound simultaneously rather than ping-ponged
19 * through descriptor updates: a descriptor set bound into an open command
20 * buffer cannot be rewritten mid-recording. Which slot a pass reads and
21 * which it writes is carried in word three of the shared parameter
22 * prefix, re-pushed before every dispatch.
23 *
24 * After an odd iteration count the result sits in the slot that started
25 * as the write target, so the pressure field is swapped once. After an
26 * even count it sits where it started and wants_swap returns false.
27 */
28class MAYAFLUX_API PressureProcessor : public VolumeFieldProcessor {
29public:
30 /**
31 * @brief Construct a pressure solve stage.
32 * @param divergence_field Name of the scalar field read as the
33 * right-hand side. Must have stride sizeof(float).
34 * @param pressure_field Name of the scalar field solved. Must have
35 * stride sizeof(float) and be double-buffered.
36 * @param shader_path Path to the compute shader.
37 * @param iterations Jacobi passes per cycle. Values below 1 clamp to 1.
38 */
40 std::string divergence_field,
41 std::string pressure_field,
42 const std::string& shader_path,
43 uint32_t iterations = 40);
44
45 /**
46 * @brief Construct a pressure solve stage from a generated ShaderSpec.
47 * @param divergence_field Name of the scalar field read.
48 * @param pressure_field Name of the scalar field solved.
49 * @param spec ShaderSpec implementing one Jacobi pass.
50 * @param iterations Jacobi passes per cycle.
51 */
53 std::string divergence_field,
54 std::string pressure_field,
56 uint32_t iterations = 40);
57
58 /** @brief Name of the field read as the right-hand side. */
59 [[nodiscard]] const std::string& get_divergence_field() const { return m_divergence_field; }
60
61 /** @brief Name of the field solved. */
62 [[nodiscard]] const std::string& get_pressure_field() const { return m_pressure_field; }
63
64protected:
65 /**
66 * @brief Write this pass's read/write parity into the parameter block.
67 * @param cmd_id Command buffer being recorded into.
68 * @param buffer Buffer under processing.
69 * @param index Zero-based iteration index.
70 * @return Always true. Every pass dispatches.
71 */
72 bool on_iteration(
74 const std::shared_ptr<VKBuffer>& buffer,
75 uint32_t index) override;
76
77 /**
78 * @brief Barrier both pressure slots between consecutive passes.
79 * @param cmd_id Command buffer being recorded into.
80 * @param buffer Buffer under processing.
81 * @param index Zero-based index of the pass just recorded.
82 *
83 * The default implementation barriers the attached buffer's own
84 * handle, which these passes never touch.
85 */
86 void on_iteration_barrier(
88 const std::shared_ptr<VKBuffer>& buffer,
89 uint32_t index) override;
90
91 /**
92 * @brief Swap only when the pass count leaves the result in the write slot.
93 * @return True when the iteration count is odd.
94 */
95 [[nodiscard]] bool wants_swap() const override;
96
97private:
98 /**
99 * @brief Build the binding table for the two field names.
100 * @param divergence_field Field read as the right-hand side.
101 * @param pressure_field Field solved, bound in both slots.
102 * @return Table binding divergence read and both pressure slots.
103 */
104 static std::vector<FieldBinding> make_bindings(
105 const std::string& divergence_field, const std::string& pressure_field);
106
108 std::string m_pressure_field;
109};
110
111} // namespace MayaFlux::Buffers
const std::string & get_pressure_field() const
Name of the field solved.
const std::string & get_divergence_field() const
Name of the field read as the right-hand side.
VolumeFieldProcessor solving the pressure Poisson equation by Jacobi iteration.
ComputeProcessor operating on named fields of a VolumeGridBuffer.
Complete declarative description of a generated compute shader.