MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
AdvectProcessor.cpp
Go to the documentation of this file.
1#include "AdvectProcessor.hpp"
2
3namespace MayaFlux::Buffers {
4
5namespace {
6 constexpr size_t k_dissipation_offset = 32;
7 constexpr size_t k_param_size = 48;
8}
9
10std::vector<VolumeFieldProcessor::FieldBinding> AdvectProcessor::make_bindings(
11 const std::string& velocity_field, const std::string& carried_field)
12{
13 return {
14 { .name = "velocity_in", .binding = 0, .field = velocity_field, .access = FieldAccess::READ },
15 { .name = "carried_in", .binding = 1, .field = carried_field, .access = FieldAccess::READ },
16 { .name = "carried_out", .binding = 2, .field = carried_field, .access = FieldAccess::WRITE },
17 };
18}
19
21 std::string velocity_field,
22 std::string carried_field,
23 const std::string& shader_path)
24 : VolumeFieldProcessor(make_bindings(velocity_field, carried_field), shader_path)
25 , m_velocity_field(std::move(velocity_field))
26 , m_carried_field(std::move(carried_field))
27{
29}
30
32 std::string velocity_field,
33 std::string carried_field,
35 : VolumeFieldProcessor(make_bindings(velocity_field, carried_field), spec)
36 , m_velocity_field(std::move(velocity_field))
37 , m_carried_field(std::move(carried_field))
38{
40}
41
48
50{
52 write_param_tail(k_dissipation_offset, &m_dissipation, sizeof(float));
53}
54
56{
57 m_time_step = dt;
58 if (get_volume()) {
59 write_tail();
60 }
61}
62
63void AdvectProcessor::set_dissipation(float dissipation)
64{
65 m_dissipation = dissipation;
66 if (get_volume()) {
67 write_tail();
68 }
69}
70
71} // namespace MayaFlux::Buffers
AdvectProcessor(std::string velocity_field, std::string carried_field, const std::string &shader_path)
Construct an advection stage.
void on_volume_ready() override
Reserve the full parameter block and write the step and dissipation words.
void write_tail()
Write time step and dissipation past the shared prefix.
static std::vector< FieldBinding > make_bindings(const std::string &velocity_field, const std::string &carried_field)
Build the binding table for the two field names.
void set_time_step(float dt)
Set the integration step passed to the shader each cycle.
void set_dissipation(float dissipation)
Set the multiplicative decay applied to the carried value.
void write_param_tail(size_t offset, const void *data, size_t size)
Write subclass parameters past the shared prefix.
void reserve_param_size(size_t size)
Raise the push constant block to at least this size.
void write_lattice_word7(float value)
Write word seven of the parameter prefix, at byte offset 28.
@ READ
Resolves to VolumeGridBuffer::read_handle.
@ WRITE
Resolves to VolumeGridBuffer::write_handle.
void write_lattice_params()
Write the lattice dimensions and cell size into the staged push constant block, preserving word three...
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.
Complete declarative description of a generated compute shader.