MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
RelaxationEmitProcessor.cpp
Go to the documentation of this file.
3
4namespace MayaFlux::Buffers {
5
6RelaxationEmitProcessor::RelaxationEmitProcessor(const std::string& shader_path, uint32_t workgroup_x)
7 : ComputeProcessor(shader_path, workgroup_x)
8{
9 m_config.bindings["cell_state"] = ShaderBinding(0, 0, vk::DescriptorType::eStorageBuffer);
10 m_config.bindings["vertices"] = ShaderBinding(0, 1, vk::DescriptorType::eStorageBuffer);
11}
12
14 : ComputeProcessor(spec)
15{
16 m_config.bindings["cell_state"] = ShaderBinding(0, 0, vk::DescriptorType::eStorageBuffer);
17 m_config.bindings["vertices"] = ShaderBinding(0, 1, vk::DescriptorType::eStorageBuffer);
18}
19
20void RelaxationEmitProcessor::on_attach(const std::shared_ptr<Buffer>& buffer)
21{
23 auto grid = std::dynamic_pointer_cast<RelaxationGridBuffer>(buffer);
24 if (grid) {
25 m_grid = grid;
26 constexpr uint32_t k_workgroup_size = 256;
27 set_workgroup_size(k_workgroup_size, 1, 1);
30 (grid->get_cell_count() + k_workgroup_size - 1) / k_workgroup_size,
31 1, 1);
33 }
34}
35
38 const std::shared_ptr<VKBuffer>& buffer)
39{
40 auto* grid = dynamic_cast<RelaxationGridBuffer*>(buffer.get());
41 if (!grid) {
42 return false;
43 }
44
45 if (!are_descriptors_ready()) {
46 return true;
47 }
48
50 auto& resources = grid->get_buffer_resources();
51
52 foundry.update_descriptor_buffer(
53 m_descriptor_set_ids[0], 0, vk::DescriptorType::eStorageBuffer,
54 resources.back_buffers[grid->front_index()].buffer, 0, grid->get_state_bytes());
55
56 foundry.update_descriptor_buffer(
57 m_descriptor_set_ids[0], 1, vk::DescriptorType::eStorageBuffer,
58 buffer->get_buffer(), 0, buffer->get_size_bytes());
59
60 return true;
61}
62
63void RelaxationEmitProcessor::processing_function(const std::shared_ptr<Buffer>& buffer)
64{
65 auto grid = std::dynamic_pointer_cast<RelaxationGridBuffer>(buffer);
66 if (grid && are_descriptors_ready()) {
68 auto& resources = grid->get_buffer_resources();
69
70 foundry.update_descriptor_buffer(
71 m_descriptor_set_ids[0], 0, vk::DescriptorType::eStorageBuffer,
72 resources.back_buffers[grid->front_index()].buffer, 0, grid->get_state_bytes());
73
74 foundry.update_descriptor_buffer(
75 m_descriptor_set_ids[0], 1, vk::DescriptorType::eStorageBuffer,
76 grid->get_buffer(), 0, grid->get_size_bytes());
77 }
78
80}
81
83{
84 if (!m_grid) {
85 return;
86 }
87
88 m_params.width = m_grid->get_grid_width();
89 m_params.height = m_grid->get_grid_height();
90
91 auto& data = get_push_constant_data();
92 if (data.size() < sizeof(EmitParams)) {
94 }
95 std::memcpy(data.data(), &m_params, sizeof(EmitParams));
96}
97
99{
100 m_params.extent = extent;
102}
103
109
110} // namespace MayaFlux::Buffers
virtual void on_attach(const std::shared_ptr< Buffer > &)
Called when this processor is attached to a buffer.
virtual void processing_function(const std::shared_ptr< Buffer > &buffer)=0
The core processing function that must be implemented by derived classes.
void set_workgroup_size(uint32_t x, uint32_t y=1, uint32_t z=1)
Set workgroup size (should match shader local_size)
void set_dispatch_mode(ShaderDispatchConfig::DispatchMode mode)
Set dispatch mode.
void set_manual_dispatch(uint32_t x, uint32_t y=1, uint32_t z=1)
Set manual dispatch group counts.
Specialized ShaderProcessor for Compute Pipelines.
void set_extent(float extent)
Set the NDC half-span the grid occupies.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
Write the cell_state and vertices descriptors for the grid's current front generation,...
void on_attach(const std::shared_ptr< Buffer > &buffer) override
When attached to a RelaxationGridBuffer, sets up the dispatch configuration to cover the entire grid ...
void set_point_size(float size)
Set the per-point size written to the vertex scalar field.
void write_emit_constants()
Size the push constant block to EmitParams and upload the current parameters.
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Write the cell_state and vertices descriptor bindings for this cycle's dispatch.
std::shared_ptr< RelaxationGridBuffer > m_grid
RelaxationEmitProcessor(const std::string &shader_path, uint32_t workgroup_x=16)
Construct an emit processor for the given shader file.
GPU-resident, double-buffered SSBO state for synchronous local-rule systems evaluated over a fixed 2D...
const std::vector< uint8_t > & get_push_constant_data() const
Get current push constant data.
void set_push_constant_size()
Set push constant size from type.
bool are_descriptors_ready() const
Check if descriptors are initialized.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
Push constant block for the packed-vertex emit shader.
Describes how a VKBuffer binds to a shader descriptor.
std::unordered_map< std::string, ShaderBinding > bindings
Complete declarative description of a generated compute shader.