MayaFlux 1.0.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 723 of file GpuResourceManager.cpp.

729{
730 const auto& params = safe_variant_get_or_throw<ChainedIndirectParams>(ctx.parameters,
731 "GpuResourceManager: dispatch_batched_indirect requires ChainedIndirectParams");
732
733 auto& unit = unit_for(key);
734 auto& foundry = Portal::Graphics::get_shader_foundry();
735 auto& compute_press = Portal::Graphics::get_compute_press();
736
737 auto& indirect_slot = m_shared->slots.at({ indirect_set, indirect_binding });
738 const vk::Buffer indirect_buffer = indirect_slot.buffer;
739 const uint32_t init_cmd[3] = { groups[0], groups[1], groups[2] };
740 std::memcpy(indirect_slot.mapped_ptr, init_cmd, sizeof(init_cmd));
741
742 const uint32_t default_passes = std::max(1U, 65536U / std::max(1U, groups[0] * groups[1] * groups[2]));
743 const uint32_t effective_passes_per_batch = params.passes_per_batch.value_or(default_passes);
744
745 for (uint32_t base = 0; base < params.pass_count; base += effective_passes_per_batch) {
746 const uint32_t batch_end = std::min(base + effective_passes_per_batch, params.pass_count);
747 auto cmd_id = foundry.begin_commands(Portal::Graphics::ShaderFoundry::CommandBufferType::COMPUTE);
748
749 for (uint32_t pass = base; pass < batch_end; ++pass) {
750 std::vector<uint8_t> pc_data(push_constant_size);
751 params.pc_updater(pass, 1, pc_data.data());
752 compute_press.bind_all(cmd_id, unit.pipeline_id, unit.descriptor_set_ids, pc_data.data(), push_constant_size);
753 compute_press.dispatch_indirect(cmd_id, indirect_buffer);
754
755 for (const auto& b : bindings) {
756 const auto et = b.element_type;
759 const bool is_output = b.direction == GpuBufferBinding::Direction::OUTPUT
761 const bool is_shared = m_shared->slots.contains({ b.set, static_cast<size_t>(b.binding) });
762 if (is_output && !is_image && !is_shared
763 && static_cast<size_t>(b.binding) < unit.impl->buffers.size()
764 && unit.impl->buffers[b.binding].buffer) {
765 foundry.buffer_barrier(
766 cmd_id,
767 unit.impl->buffers[b.binding].buffer,
768 vk::AccessFlagBits::eShaderWrite,
769 vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite,
770 vk::PipelineStageFlagBits::eComputeShader,
771 vk::PipelineStageFlagBits::eComputeShader);
772 }
773 }
774 }
775 foundry.submit_and_wait(cmd_id);
776 }
777}
size_t b
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:136

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, 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: