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

◆ dispatch_batched_indirect()

void MayaFlux::Yantra::GpuResourceManager::dispatch_batched_indirect ( const std::string &  key,
uint32_t  indirect_set,
size_t  indirect_binding,
const std::array< uint32_t, 3 > &  groups,
const std::vector< GpuBufferBinding > &  bindings,
size_t  push_constant_size,
const ExecutionContext ctx 
)

Definition at line 601 of file GpuResourceManager.cpp.

607{
608 const auto& params = safe_variant_get_or_throw<ChainedIndirectParams>(ctx.parameters,
609 "GpuResourceManager: dispatch_batched_indirect requires ChainedIndirectParams");
610
611 auto& unit = unit_for(key);
612 auto& foundry = Portal::Graphics::get_shader_foundry();
613 auto& compute_press = Portal::Graphics::get_compute_press();
614
615 auto& indirect_slot = m_shared->slots.at({ indirect_set, indirect_binding });
616 const vk::Buffer indirect_buffer = indirect_slot.buffer;
617 const uint32_t init_cmd[3] = { groups[0], groups[1], groups[2] };
618 std::memcpy(indirect_slot.mapped_ptr, init_cmd, sizeof(init_cmd));
619
620 const uint32_t default_passes = std::max(1U, 65536U / std::max(1U, groups[0] * groups[1] * groups[2]));
621 const uint32_t effective_passes_per_batch = params.passes_per_batch.value_or(default_passes);
622
623 for (uint32_t base = 0; base < params.pass_count; base += effective_passes_per_batch) {
624 const uint32_t batch_end = std::min(base + effective_passes_per_batch, params.pass_count);
625 auto cmd_id = foundry.begin_commands(Portal::Graphics::ShaderFoundry::CommandBufferType::COMPUTE);
626
627 for (uint32_t pass = base; pass < batch_end; ++pass) {
628 std::vector<uint8_t> pc_data(push_constant_size);
629 params.pc_updater(pass, 1, pc_data.data());
630 compute_press.bind_all(cmd_id, unit.pipeline_id, unit.descriptor_set_ids, pc_data.data(), push_constant_size);
631 compute_press.dispatch_indirect(cmd_id, indirect_buffer);
632
633 for (const auto& b : bindings) {
634 const auto et = b.element_type;
637 const bool is_output = b.direction == GpuBufferBinding::Direction::OUTPUT
639 const bool is_shared = m_shared->slots.contains({ b.set, static_cast<size_t>(b.binding) });
640 if (is_output && !is_image && !is_shared
641 && static_cast<size_t>(b.binding) < unit.impl->buffers.size()) {
642 foundry.buffer_barrier(
643 cmd_id,
644 unit.impl->buffers[b.binding].buffer,
645 vk::AccessFlagBits::eShaderWrite,
646 vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite,
647 vk::PipelineStageFlagBits::eComputeShader,
648 vk::PipelineStageFlagBits::eComputeShader);
649 }
650 }
651 }
652 foundry.submit_and_wait(cmd_id);
653 }
654}
size_t b
uint32_t pass
std::unique_ptr< SharedBuffers > m_shared
PipelineUnit & unit_for(const std::string &key)
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
MAYAFLUX_API ComputePress & get_compute_press()
bool is_image(const fs::path &filepath)
Definition Depot.cpp:108

References b, MayaFlux::Portal::Graphics::ShaderFoundry::COMPUTE, MayaFlux::Portal::Graphics::get_compute_press(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Portal::Graphics::GpuBufferBinding::IMAGE_SAMPLED, MayaFlux::Portal::Graphics::GpuBufferBinding::IMAGE_STORAGE, MayaFlux::Portal::Graphics::GpuBufferBinding::INPUT_OUTPUT, MayaFlux::is_image(), m_shared, MayaFlux::Portal::Graphics::GpuBufferBinding::OUTPUT, MayaFlux::Yantra::ExecutionContext::parameters, pass, and unit_for().

Referenced by MayaFlux::Yantra::GpuDispatchCore::dispatch_core_chained_indirect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: