MayaFlux 1.0.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
36void RelaxationEmitProcessor::write_state_descriptors(const std::shared_ptr<RelaxationGridBuffer>& grid)
37{
38 if (m_descriptor_set_ids.empty()) {
39 return;
40 }
41
43 auto& resources = grid->get_buffer_resources();
44
45 foundry.update_descriptor_buffer(
46 m_descriptor_set_ids[0], 0, vk::DescriptorType::eStorageBuffer,
47 resources.back_buffers[grid->front_index()].buffer, 0, grid->get_state_bytes());
48
49 foundry.update_descriptor_buffer(
50 m_descriptor_set_ids[0], 1, vk::DescriptorType::eStorageBuffer,
51 grid->get_buffer(), 0, grid->get_size_bytes());
52}
53
60
63 const std::shared_ptr<VKBuffer>& buffer)
64{
65 return std::dynamic_pointer_cast<RelaxationGridBuffer>(buffer) != nullptr;
66}
67
76
78{
79 if (!m_grid) {
80 return;
81 }
82
83 m_params.width = m_grid->get_grid_width();
84 m_params.height = m_grid->get_grid_height();
85
86 auto& data = get_push_constant_data();
87 if (data.size() < sizeof(EmitParams)) {
89 }
90 std::memcpy(data.data(), &m_params, sizeof(EmitParams));
91}
92
94{
95 m_params.extent = extent;
97}
98
104
105} // namespace MayaFlux::Buffers
bool size
std::shared_ptr< NetworkGeometryBuffer > buffer
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_descriptors_created() override
Write the cell_state and vertices descriptors when the descriptor set is created or rebuilt.
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Cover the grid with a 1D dispatch and write EmitParams.
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.
void write_state_descriptors(const std::shared_ptr< RelaxationGridBuffer > &grid)
Point cell_state at the grid's front generation and vertices at the grid's own vertex storage.
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Accept only a RelaxationGridBuffer.
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.
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.