28 auto& resources = grid->get_buffer_resources();
29 if (resources.back_buffers.size() < 2) {
38 const size_t bytes = grid->get_state_bytes();
39 foundry.update_descriptor_buffer(
41 resources.back_buffers[grid->front_index()].buffer, 0, bytes);
43 foundry.update_descriptor_buffer(
45 resources.back_buffers[grid->back_index()].buffer, 0, bytes);
71 .height =
m_grid->get_grid_height()
73 std::memcpy(data.data(), &extent,
sizeof(
GridExtent));
79 m_grid = std::dynamic_pointer_cast<RelaxationGridBuffer>(buffer);
84 uint32_t gx = (
m_grid->get_grid_width() + 15) / 16;
85 uint32_t gy = (
m_grid->get_grid_height() + 15) / 16;
100 const std::shared_ptr<VKBuffer>& buffer)
102 if (!std::dynamic_pointer_cast<RelaxationGridBuffer>(buffer)) {
111 const std::shared_ptr<VKBuffer>& buffer)
113 auto grid = std::dynamic_pointer_cast<RelaxationGridBuffer>(buffer);
118 if (!grid->consume_snapshot_request()) {
122 auto& resources = grid->get_buffer_resources();
123 const auto& front = resources.back_buffers[grid->front_index()];
125 std::vector<uint8_t> bytes(grid->get_state_bytes());
134 auto handle = buffer_service->copy_buffer_fenced(
135 static_cast<void*
>(front.buffer),
139 buffer_service->wait_fenced(handle);
142 buffer_service->invalidate_range(staging_resources.memory, 0, bytes.size());
144 std::memcpy(bytes.data(), staging_resources.mapped_ptr, bytes.size());
145 buffer_service->release_fenced(handle);
147 grid->snapshot_source()->signal(bytes);
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 write_state_descriptors(const std::shared_ptr< RelaxationGridBuffer > &grid)
Issue direct ShaderFoundry descriptor writes for state_in and state_out against the grid's current fr...
void on_after_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Swap front/back generation index and, if requested, stage a snapshot download of the buffer just writ...
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 ...
StepPredicate m_step_predicate
Optional gate deciding whether a given cycle advances a generation.
std::shared_ptr< RelaxationGridBuffer > m_grid
The attached RelaxationGridBuffer, cached for descriptor writes and snapshot staging.
bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer) override
Write the state_in / state_out descriptor bindings for the current front/back assignment,...
std::shared_ptr< VKBuffer > m_snapshot_staging
Lazily-created, reused host-visible staging buffer for snapshot downloads.
RelaxationStepProcessor(const std::string &shader_path, uint32_t workgroup_x=16)
Construct a step processor for the given rule shader file.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
Write the state descriptors for the current front/back assignment, then run the normal shader process...
void on_descriptors_created() override
Write the state_in / state_out descriptor bindings for the current front/back assignment.
void write_grid_extent_constants()
Size the push constant block to at least GridExtent and write the attached grid's dimensions into its...
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
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
std::shared_ptr< VKBuffer > create_staging_buffer(size_t size)
Create staging buffer for transfers.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
Leading push constant fields every relaxation rule shader receives: grid width then height,...
Describes how a VKBuffer binds to a shader descriptor.
std::unordered_map< std::string, ShaderBinding > bindings
size_t push_constant_size
@ MANUAL
Use explicit group counts.
Complete declarative description of a generated compute shader.
Backend buffer management service interface.