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

◆ dispatch_batched()

void MayaFlux::Yantra::GpuResourceManager::dispatch_batched ( uint32_t  pass_count,
const std::array< uint32_t, 3 > &  groups,
const std::vector< GpuBufferBinding > &  bindings,
const std::function< void(uint32_t pass, std::vector< uint8_t > &)> &  push_constant_updater,
size_t  push_constant_size,
const std::unordered_map< std::string, std::any > &  execution_metadata = {} 
)

Definition at line 381 of file GpuResourceManager.cpp.

388{
389 auto& foundry = Portal::Graphics::get_shader_foundry();
390 auto& compute_press = Portal::Graphics::get_compute_press();
391
392 const uint32_t workgroups_per_pass = groups[0] * groups[1] * groups[2];
393
394 const uint32_t default_passes = std::max(1U, 65536U / std::max(1U, workgroups_per_pass));
395 const uint32_t passes_per_batch = [&] {
396 auto it = execution_metadata.find("passes_per_batch");
397 if (it != execution_metadata.end())
398 return safe_any_cast_or_default<uint32_t>(it->second, default_passes);
399 return default_passes;
400 }();
401
402 for (uint32_t base = 0; base < pass_count; base += passes_per_batch) {
403 const uint32_t batch_end = std::min(base + passes_per_batch, pass_count);
404
405 auto cmd_id = foundry.begin_commands(
407
408 for (uint32_t pass = base; pass < batch_end; ++pass) {
409 std::vector<uint8_t> pc_data(push_constant_size);
410 push_constant_updater(pass, pc_data);
411
412 compute_press.bind_all(
414 pc_data.data(), push_constant_size);
415
416 compute_press.dispatch(cmd_id, groups[0], groups[1], groups[2]);
417
418 for (size_t i = 0; i < bindings.size(); ++i) {
419 if (bindings[i].direction == GpuBufferBinding::Direction::INPUT_OUTPUT) {
420 foundry.buffer_barrier(
421 cmd_id,
422 m_impl->buffers[i].buffer,
423 vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eShaderRead,
424 vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eShaderRead,
425 vk::PipelineStageFlagBits::eComputeShader,
426 vk::PipelineStageFlagBits::eComputeShader);
427 }
428 }
429 }
430
431 for (size_t i = 0; i < bindings.size(); ++i) {
432 if (bindings[i].direction == GpuBufferBinding::Direction::OUTPUT
433 || bindings[i].direction == GpuBufferBinding::Direction::INPUT_OUTPUT) {
434 foundry.buffer_barrier(
435 cmd_id,
436 m_impl->buffers[i].buffer,
437 vk::AccessFlagBits::eShaderWrite,
438 vk::AccessFlagBits::eHostRead,
439 vk::PipelineStageFlagBits::eComputeShader,
440 vk::PipelineStageFlagBits::eHost);
441 }
442 }
443
444 foundry.submit_and_wait(cmd_id);
445 }
446}
Portal::Graphics::ComputePipelineID m_pipeline_id
std::vector< Portal::Graphics::DescriptorSetID > m_descriptor_set_ids
std::unique_ptr< GpuResourceManagerImpl > m_impl
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
MAYAFLUX_API ComputePress & get_compute_press()

References MayaFlux::Portal::Graphics::ShaderFoundry::COMPUTE, MayaFlux::Portal::Graphics::get_compute_press(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Yantra::GpuBufferBinding::INPUT_OUTPUT, m_descriptor_set_ids, m_impl, m_pipeline_id, and MayaFlux::Yantra::GpuBufferBinding::OUTPUT.

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

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