MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Buffers::BuoyancyProcessor Class Reference

VolumeFieldProcessor accumulating a Boussinesq body force into a velocity field from a temperature field and a density field. More...

#include <BuoyancyProcessor.hpp>

+ Inheritance diagram for MayaFlux::Buffers::BuoyancyProcessor:
+ Collaboration diagram for MayaFlux::Buffers::BuoyancyProcessor:

Classes

struct  BuoyancyParams
 Push constant block the buoyancy shader receives. More...
 

Public Member Functions

 BuoyancyProcessor (std::string temperature_field, std::string density_field, std::string velocity_field, const glm::vec3 &direction, const Portal::Graphics::ShaderSpec &spec)
 Construct a buoyancy stage from a generated ShaderSpec.
 
 BuoyancyProcessor (std::string temperature_field, std::string density_field, std::string velocity_field, const glm::vec3 &direction, const std::string &shader_path)
 Construct a buoyancy stage.
 
const std::string & get_density_field () const
 Name of the field driving fall.
 
const glm::vec3 & get_direction () const
 Force axis and magnitude.
 
const std::string & get_temperature_field () const
 Name of the field driving rise.
 
float get_time_step () const
 Seconds per step.
 
const std::string & get_velocity_field () const
 Name of the field accumulated into.
 
void set_ambient (float ambient)
 Set the temperature at which the rise term vanishes.
 
void set_density_gain (float gain)
 Set the coefficient on the density value.
 
void set_direction (const glm::vec3 &direction)
 Set the force axis and magnitude.
 
void set_temperature_gain (float gain)
 Set the coefficient on the temperature difference.
 
void set_time_step (float dt)
 Set the integration step passed to the shader each cycle.
 
- Public Member Functions inherited from MayaFlux::Buffers::VolumeFieldProcessor
const std::shared_ptr< VolumeGridBuffer > & get_volume () const
 The attached volume, or null if attachment failed validation.
 
- Public Member Functions inherited from MayaFlux::Buffers::ComputeProcessor
 ComputeProcessor (const Portal::Graphics::ShaderSpec &spec)
 Construct processor from a generated ShaderSpec.
 
 ComputeProcessor (const std::string &shader_path, uint32_t workgroup_x=256)
 Construct processor with shader path.
 
const ShaderDispatchConfigget_dispatch_config () const
 Get current dispatch configuration.
 
uint32_t get_iteration_count () const
 Dispatches recorded per execute cycle.
 
bool is_pipeline_ready () const
 Check if pipeline is created.
 
void set_custom_dispatch (std::function< std::array< uint32_t, 3 >(const std::shared_ptr< VKBuffer > &)> calculator)
 Set custom dispatch calculator.
 
void set_dispatch_mode (ShaderDispatchConfig::DispatchMode mode)
 Set dispatch mode.
 
void set_iteration_count (uint32_t count)
 Set how many dispatches are recorded per execute cycle.
 
void set_manual_dispatch (uint32_t x, uint32_t y=1, uint32_t z=1)
 Set manual dispatch group counts.
 
void set_workgroup_size (uint32_t x, uint32_t y=1, uint32_t z=1)
 Set workgroup size (should match shader local_size)
 
- Public Member Functions inherited from MayaFlux::Buffers::ShaderProcessor
void add_binding (const std::string &descriptor_name, const ShaderBinding &binding)
 Add descriptor binding configuration.
 
bool are_bindings_complete () const
 Check if all required bindings are satisfied.
 
bool are_descriptors_ready () const
 Check if descriptors are initialized.
 
void auto_bind_buffer (const std::shared_ptr< VKBuffer > &buffer)
 Auto-bind buffer based on attachment order.
 
void bind_buffer (const std::string &descriptor_name, const std::shared_ptr< VKBuffer > &buffer)
 Bind a VKBuffer to a named shader descriptor.
 
void clear_specialization_constants ()
 Clear all specialization constants.
 
template<typename T >
bool download_bound (const std::string &descriptor_name, std::vector< T > &data) const
 
bool download_bound (const std::string &descriptor_name, void *data, size_t size, const std::shared_ptr< VKBuffer > &staging=nullptr) const
 Download the buffer currently bound to a named descriptor.
 
void feed (const std::string &name, FeedSource source)
 Supply a shader input from a callable, resolved by name.
 
void feed (const std::string &name, FeedSource source, uint32_t offset, size_t size=sizeof(float))
 Supply a push constant from a callable at an explicit offset.
 
std::vector< std::string > get_binding_names () const
 Get all configured descriptor names.
 
std::shared_ptr< VKBufferget_bound_buffer (const std::string &descriptor_name) const
 Get bound buffer for a descriptor name.
 
size_t get_bound_buffer_count () const
 Get number of bound buffers.
 
virtual BufferUsageHint get_buffer_usage_hint (const std::string &descriptor_name) const
 Get buffer usage hint for a descriptor.
 
const ShaderConfigget_config () const
 Get current configuration.
 
std::vector< std::string > get_feed_names () const
 Names of every registered feed.
 
virtual std::shared_ptr< VKBufferget_output_buffer () const
 Get the output buffer after compute dispatch.
 
std::vector< uint8_t > & get_push_constant_data ()
 
const std::vector< uint8_t > & get_push_constant_data () const
 Get current push constant data.
 
const std::string & get_shader_path () const
 Get current shader path.
 
bool has_binding (const std::string &descriptor_name) const
 Check if a descriptor binding exists.
 
virtual bool has_executed () const
 Check if compute has been executed at least once.
 
bool has_feed (const std::string &name) const
 Whether a feed of this name is registered.
 
bool hot_reload_shader ()
 Hot-reload shader from ShaderFoundry.
 
bool is_compatible_with (const std::shared_ptr< Buffer > &buffer) const override
 Checks if this processor can handle the specified buffer type.
 
bool is_deferred_submission () const
 Whether this processor submits asynchronously.
 
bool is_dispatch_pending () const
 True while an asynchronous submission is outstanding.
 
virtual bool is_in_place_operation (const std::string &descriptor_name) const
 Check if shader modifies a specific buffer in-place.
 
bool is_shader_loaded () const
 Check if shader is loaded.
 
void on_detach (const std::shared_ptr< Buffer > &buffer) override
 Called when this processor is detached from a buffer.
 
void remove_feed (const std::string &name)
 Remove a feed.
 
bool resolve_pending_dispatch (bool block)
 Resolve an outstanding asynchronous submission.
 
void set_config (const ShaderConfig &config)
 Update entire configuration.
 
void set_deferred_submission (bool deferred)
 Submit asynchronously and resolve at the top of a later cycle.
 
template<typename T >
void set_push_constant_data (const T &data)
 Update push constant data (type-safe)
 
virtual void set_push_constant_data_raw (const void *data, size_t size)
 Update push constant data (raw bytes)
 
template<typename T >
void set_push_constant_size ()
 Set push constant size from type.
 
void set_push_constant_size (size_t size)
 Set push constant size.
 
void set_shader (const std::string &shader_path)
 Update shader path and reload.
 
void set_specialization_constant (uint32_t constant_id, uint32_t value)
 Set specialization constant.
 
 ShaderProcessor (const std::string &shader_path)
 Construct processor with shader path.
 
 ShaderProcessor (ShaderConfig config)
 Construct processor with full configuration.
 
void unbind_buffer (const std::string &descriptor_name)
 Unbind a buffer from a descriptor.
 
 ~ShaderProcessor () override
 
- Public Member Functions inherited from MayaFlux::Buffers::BufferProcessor
virtual ProcessingToken get_processing_token () const
 Gets the current processing token for this buffer.
 
void process (const std::shared_ptr< Buffer > &buffer)
 Applies a computational transformation to the data in the provided buffer.
 
virtual void set_processing_token (ProcessingToken token)
 Gets the preferred processing backend for this processor.
 
virtual ~BufferProcessor ()=default
 Virtual destructor for proper cleanup of derived classes.
 

Protected Member Functions

void on_volume_ready () override
 Raise the parameter block and write the tail.
 
- Protected Member Functions inherited from MayaFlux::Buffers::VolumeFieldProcessor
void add_swap_field (std::string field)
 Register a field to swap after each dispatch.
 
void on_attach (const std::shared_ptr< Buffer > &buffer) override
 Cache and validate the volume, size the dispatch, write the shared parameter prefix, then call on_volume_ready.
 
bool on_before_execute (Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
 Reject buffers that are not the validated volume.
 
void on_descriptors_created () override
 Write every binding in the table for the current slot assignment.
 
void processing_function (const std::shared_ptr< Buffer > &buffer) override
 Rewrite field descriptors, run the shader, then swap.
 
void reserve_param_size (size_t size)
 Raise the push constant block to at least this size.
 
 VolumeFieldProcessor (std::vector< FieldBinding > bindings, const Portal::Graphics::ShaderSpec &spec)
 Construct from a generated ShaderSpec.
 
 VolumeFieldProcessor (std::vector< FieldBinding > bindings, const std::string &shader_path)
 Construct from a shader path.
 
virtual bool wants_swap () const
 Whether this cycle's dispatch should be followed by a swap.
 
void write_lattice_params ()
 Write the lattice dimensions and cell size into the staged push constant block, preserving word three.
 
void write_lattice_word3 (uint32_t value)
 Write word three of the shared prefix.
 
void write_lattice_word7 (float value)
 Write word seven of the parameter prefix, at byte offset 28.
 
void write_param_tail (size_t offset, const void *data, size_t size)
 Write subclass parameters past the shared prefix.
 
- Protected Member Functions inherited from MayaFlux::Buffers::ComputeProcessor
virtual std::array< uint32_t, 3 > calculate_dispatch_size (const std::shared_ptr< VKBuffer > &buffer)
 Calculate dispatch size from buffer.
 
void cleanup () override
 
void initialize_descriptors (const std::shared_ptr< VKBuffer > &buffer) override
 
void initialize_pipeline (const std::shared_ptr< VKBuffer > &buffer) override
 
virtual bool on_iteration (Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer, uint32_t index)
 Called before each iteration's push constants and dispatch.
 
virtual void on_iteration_barrier (Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer, uint32_t index)
 Called after each iteration except the last.
 
- Protected Member Functions inherited from MayaFlux::Buffers::ShaderProcessor
virtual void on_after_execute (Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
 Called after each process callback.
 
virtual void on_before_compile (const std::string &shader_path)
 Called before shader compilation.
 
virtual void on_before_descriptors_create ()
 Called before descriptor sets are created.
 
virtual void on_before_pipeline_create (Portal::Graphics::ComputePipelineID pipeline_id)
 Called before pipeline creation.
 
virtual void on_dispatch_complete (const std::shared_ptr< VKBuffer > &buffer)
 Called once when an asynchronous submission is observed complete.
 
virtual void on_pipeline_created (Portal::Graphics::ComputePipelineID pipeline_id)
 Called after pipeline is created.
 
virtual void on_shader_loaded (Portal::Graphics::ShaderID shader_id)
 Called after shader is loaded.
 
void pump_feeds ()
 Pull every feed and write its result.
 
std::optional< uint32_t > resolve_ds_index (uint32_t set) const
 Resolve logical descriptor set index to actual index.
 
size_t resolve_push_constant_size (const std::shared_ptr< VKBuffer > &buffer) const
 Byte width of this processor's push constant block, extended to cover any fragment staged on the buffer.
 
std::vector< uint8_t > resolve_push_constants (const std::shared_ptr< VKBuffer > &buffer) const
 This processor's push constant data with buffer-staged fragments overlaid at their declared offsets.
 
void submit_recorded (Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
 Submit a recorded command buffer honoring the submission mode.
 
virtual void update_descriptors (const std::shared_ptr< VKBuffer > &buffer)
 
- Protected Member Functions inherited from MayaFlux::Buffers::VKBufferProcessor
void ensure_initialized (const std::shared_ptr< VKBuffer > &buffer)
 
void initialize_buffer_service ()
 
void initialize_compute_service ()
 

Private Member Functions

void write_tail ()
 Write every parameter past the shared prefix.
 

Static Private Member Functions

static std::vector< FieldBindingmake_bindings (const std::string &temperature_field, const std::string &density_field, const std::string &velocity_field)
 Build the binding table for the three field names.
 

Private Attributes

float m_ambient { 0.0F }
 
std::string m_density_field
 
float m_density_gain { 0.0F }
 
glm::vec3 m_direction { 0.0F, 1.0F, 0.0F }
 
std::string m_temperature_field
 
float m_temperature_gain { 1.0F }
 
float m_time_step { 1.0F / 60.0F }
 
std::string m_velocity_field
 

Additional Inherited Members

- Public Types inherited from MayaFlux::Buffers::VolumeFieldProcessor
enum class  FieldAccess { READ , WRITE }
 Which slot of a field a binding resolves to. More...
 
- Public Types inherited from MayaFlux::Buffers::ShaderProcessor
enum class  BufferUsageHint : uint8_t { NONE = 0 , INPUT_READ = 1 << 0 , OUTPUT_WRITE = 1 << 1 , BIDIRECTIONAL = INPUT_READ | OUTPUT_WRITE }
 Get buffer usage characteristics needed for safe data flow. More...
 
using FeedSource = std::function< FeedValue()>
 A callable pulled once per processing cycle.
 
using FeedValue = std::variant< double, Kakshya::DataVariant >
 What a feed callable returns.
 
- Protected Attributes inherited from MayaFlux::Buffers::ShaderProcessor
size_t m_auto_bind_index {}
 
std::unordered_map< std::string, std::shared_ptr< VKBuffer > > m_bound_buffers
 
ShaderConfig m_config
 
bool m_deferred_submission {}
 False submits synchronously, preserving pre-existing behaviour.
 
std::vector< Portal::Graphics::DescriptorSetIDm_descriptor_set_ids
 
bool m_engine_owns_set_zero {}
 Whether the engine reserves set=0 for global resources.
 
bool m_initialized {}
 
Portal::Graphics::CommandBufferID m_last_command_buffer = Portal::Graphics::INVALID_COMMAND_BUFFER
 
std::shared_ptr< VKBufferm_last_processed_buffer
 
bool m_needs_descriptor_rebuild = true
 
bool m_needs_pipeline_rebuild = true
 
std::shared_ptr< VKBufferm_pending_buffer
 Buffer retained for the outstanding submission.
 
Portal::Graphics::FenceID m_pending_fence { Portal::Graphics::INVALID_FENCE }
 Outstanding async submission, if any.
 
std::vector< uint8_t > m_push_constant_data
 
Portal::Graphics::ShaderID m_shader_id = Portal::Graphics::INVALID_SHADER
 
- Protected Attributes inherited from MayaFlux::Buffers::VKBufferProcessor
Registry::Service::BufferServicem_buffer_service = nullptr
 
Registry::Service::ComputeServicem_compute_service = nullptr
 
- Protected Attributes inherited from MayaFlux::Buffers::BufferProcessor
ProcessingToken m_processing_token { ProcessingToken::AUDIO_BACKEND }
 

Detailed Description

VolumeFieldProcessor accumulating a Boussinesq body force into a velocity field from a temperature field and a density field.

Each cell adds dt * (temperature_gain * (T - ambient) - density_gain * d) scaled by the direction vector into its own velocity, writing the write slot and swapping. No neighbourhood is read, so the stencil is local and the boundary needs no special case.

The direction vector carries both axis and magnitude: passing (0, 9.81, 0) and unit gains is equivalent to passing (0, 1, 0) and gains of 9.81. Nothing in the stage assumes an up axis.

Naming the same field for temperature and density is valid and gives a single-quantity buoyancy: set the gain for the unwanted term to zero. The stage does not require a distinct temperature field to exist.

Placement is after advection and before divergence. Running it after the pressure solve injects divergence the solve has already removed.

Definition at line 28 of file BuoyancyProcessor.hpp.


The documentation for this class was generated from the following files: