MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ execute_shader()

void MayaFlux::Buffers::ComputeProcessor::execute_shader ( const std::shared_ptr< VKBuffer > &  buffer)
overrideprivatevirtual

Implements MayaFlux::Buffers::ShaderProcessor.

Definition at line 216 of file ComputeProcessor.cpp.

217{
220 "Cannot dispatch without pipeline and descriptors");
221 return;
222 }
223
224 if (m_descriptor_set_ids.empty()) {
226 "Descriptor sets not initialized");
227 return;
228 }
229
230 auto& foundry = Portal::Graphics::get_shader_foundry();
231 auto& compute_press = Portal::Graphics::get_compute_press();
232
233 auto cmd_id = foundry.begin_commands(Portal::Graphics::ShaderFoundry::CommandBufferType::COMPUTE);
234
235 m_last_command_buffer = cmd_id;
237
238 compute_press.bind_pipeline(cmd_id, m_pipeline_id);
239
240 auto& descriptor_bindings = buffer->get_pipeline_context().descriptor_buffer_bindings;
241 if (!descriptor_bindings.empty()) {
242 for (const auto& binding : descriptor_bindings) {
243 if (binding.set >= m_descriptor_set_ids.size()) {
245 "Descriptor set index {} out of range", binding.set);
246 continue;
247 }
248
249 foundry.update_descriptor_buffer(
250 m_descriptor_set_ids[binding.set],
251 binding.binding,
252 binding.type,
253 binding.buffer_info.buffer,
254 binding.buffer_info.offset,
255 binding.buffer_info.range);
256 }
257 }
258
259 if (!m_descriptor_set_ids.empty()) {
260 compute_press.bind_descriptor_sets(cmd_id, m_pipeline_id, m_descriptor_set_ids);
261 }
262
263 on_before_execute(cmd_id, buffer);
264 pump_feeds(false);
265
266 const uint32_t iterations = std::max(1U, m_dispatch_config.iteration_count);
267 const auto dispatch_size = calculate_dispatch_size(buffer);
268
269 for (uint32_t i = 0; i < iterations; ++i) {
270 if (!on_iteration(cmd_id, buffer, i)) {
271 continue;
272 }
273
275
276 if (!m_push_constant_scratch.empty()) {
277 compute_press.push_constants(
278 cmd_id, m_pipeline_id,
281 }
282
283 compute_press.dispatch(cmd_id, dispatch_size[0], dispatch_size[1], dispatch_size[2]);
284
285 if (i + 1 < iterations) {
286 on_iteration_barrier(cmd_id, buffer, i);
287 }
288 }
289
290 on_after_execute(cmd_id, buffer);
291
292 foundry.buffer_barrier(
293 cmd_id,
294 buffer->get_buffer(),
295 vk::AccessFlagBits::eShaderWrite,
296 vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eTransferRead,
297 vk::PipelineStageFlagBits::eComputeShader,
298 vk::PipelineStageFlagBits::eComputeShader | vk::PipelineStageFlagBits::eTransfer);
299
300 submit_recorded(cmd_id, buffer);
301}
#define MF_ERROR(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
std::shared_ptr< NetworkGeometryBuffer > buffer
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.
std::vector< uint8_t > m_push_constant_scratch
Merged push constant block, reused across iterations.
Portal::Graphics::ComputePipelineID m_pipeline_id
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 std::array< uint32_t, 3 > calculate_dispatch_size(const std::shared_ptr< VKBuffer > &buffer)
Calculate dispatch size from buffer.
Portal::Graphics::CommandBufferID m_last_command_buffer
virtual void on_after_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
Called after each process callback.
void resolve_push_constants_into(std::vector< uint8_t > &out, const std::shared_ptr< VKBuffer > &buffer) const
resolve_push_constants() written into out, reusing its storage.
virtual bool on_before_execute(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
Called before each process callback.
std::shared_ptr< VKBuffer > m_last_processed_buffer
void submit_recorded(Portal::Graphics::CommandBufferID cmd_id, const std::shared_ptr< VKBuffer > &buffer)
Submit a recorded command buffer honoring the submission mode.
void pump_feeds(bool early=true)
Pull every feed and write its result.
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
constexpr ComputePipelineID INVALID_COMPUTE_PIPELINE
MAYAFLUX_API ComputePress & get_compute_press()
uint32_t iteration_count
Dispatches recorded per execute cycle.

References buffer, MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, calculate_dispatch_size(), MayaFlux::Portal::Graphics::ShaderFoundry::COMPUTE, MayaFlux::Portal::Graphics::get_compute_press(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Portal::Graphics::INVALID_COMPUTE_PIPELINE, MayaFlux::Buffers::ShaderDispatchConfig::iteration_count, MayaFlux::Buffers::ShaderProcessor::m_descriptor_set_ids, m_dispatch_config, MayaFlux::Buffers::ShaderProcessor::m_last_command_buffer, MayaFlux::Buffers::ShaderProcessor::m_last_processed_buffer, m_pipeline_id, m_push_constant_scratch, MF_ERROR, MF_RT_ERROR, MayaFlux::Buffers::ShaderProcessor::on_after_execute(), MayaFlux::Buffers::ShaderProcessor::on_before_execute(), on_iteration(), on_iteration_barrier(), MayaFlux::Buffers::ShaderProcessor::pump_feeds(), MayaFlux::Buffers::ShaderProcessor::resolve_push_constants_into(), and MayaFlux::Buffers::ShaderProcessor::submit_recorded().

+ Here is the call graph for this function: