MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
DiffuseProcessor.cpp
Go to the documentation of this file.
3
4namespace MayaFlux::Buffers {
5
6std::vector<VolumeFieldProcessor::FieldBinding> DiffuseProcessor::make_bindings(
7 const std::string& target_field, const std::string& scratch_field)
8{
9 return {
10 { .name = "source", .binding = 0, .field = scratch_field, .access = FieldAccess::WRITE },
11 { .name = "target_a", .binding = 1, .field = target_field, .access = FieldAccess::READ },
12 { .name = "target_b", .binding = 2, .field = target_field, .access = FieldAccess::WRITE },
13 };
14}
15
17 std::string target_field,
18 std::string scratch_field,
19 const std::string& shader_path,
20 uint32_t iterations)
21 : VolumeFieldProcessor(make_bindings(target_field, scratch_field), shader_path)
22 , m_target_field(std::move(target_field))
23 , m_scratch_field(std::move(scratch_field))
24{
26 set_iteration_count(iterations);
27}
28
30 std::string target_field,
31 std::string scratch_field,
33 uint32_t iterations)
34 : VolumeFieldProcessor(make_bindings(target_field, scratch_field), spec)
35 , m_target_field(std::move(target_field))
36 , m_scratch_field(std::move(scratch_field))
37{
39 set_iteration_count(iterations);
40}
41
46
51
53{
54 m_rate = rate;
55 if (get_volume()) {
57 }
58}
59
61{
62 m_time_step = dt;
63 if (get_volume()) {
65 }
66}
67
69{
70 return (get_iteration_count() % 2) == 1;
71}
72
75 const std::shared_ptr<VKBuffer>& /*buffer*/,
76 uint32_t index)
77{
78 write_lattice_word3((index % 2) | (index == 0 ? 2U : 0U));
79 return true;
80}
81
84 const std::shared_ptr<VKBuffer>& /*buffer*/,
85 uint32_t /*index*/)
86{
87 const auto& volume = get_volume();
88 if (!volume) {
89 return;
90 }
91
93
94 const auto src = vk::AccessFlagBits::eShaderWrite;
95 const auto dst = vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite;
96 const auto stage = vk::PipelineStageFlagBits::eComputeShader;
97
98 foundry.buffer_barrier(cmd_id, volume->read_handle(m_target_field), src, dst, stage, stage);
99 foundry.buffer_barrier(cmd_id, volume->write_handle(m_target_field), src, dst, stage, stage);
100 foundry.buffer_barrier(cmd_id, volume->write_handle(m_scratch_field), src, dst, stage, stage);
101}
102
103} // namespace MayaFlux::Buffers
float rate
void set_iteration_count(uint32_t count)
Set how many dispatches are recorded per execute cycle.
uint32_t get_iteration_count() const
Dispatches recorded per execute cycle.
void write_coefficient()
Write the product of rate and time step into word seven.
bool on_iteration(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer, uint32_t index) override
Write this pass's parity and first-pass flag.
void on_volume_ready() override
Write the coefficient into the shared prefix.
void on_iteration_barrier(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer, uint32_t index) override
Barrier both target slots and the scratch between passes.
static std::vector< FieldBinding > make_bindings(const std::string &target_field, const std::string &scratch_field)
Build the binding table for the two field names.
DiffuseProcessor(std::string target_field, std::string scratch_field, const std::string &shader_path, uint32_t iterations=20)
Construct a diffusion stage.
bool wants_swap() const override
Swap only when the pass count leaves the result in the write slot.
void set_time_step(float dt)
Set the integration step.
void set_rate(float rate)
Set the diffusion rate.
void write_lattice_word7(float value)
Write word seven of the parameter prefix, at byte offset 28.
void write_lattice_word3(uint32_t value)
Write word three of the shared prefix.
@ READ
Resolves to VolumeGridBuffer::read_handle.
@ WRITE
Resolves to VolumeGridBuffer::write_handle.
const std::shared_ptr< VolumeGridBuffer > & get_volume() const
The attached volume, or null if attachment failed validation.
void add_swap_field(std::string field)
Register a field to swap after each dispatch.
ComputeProcessor operating on named fields of a VolumeGridBuffer.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
Complete declarative description of a generated compute shader.