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

◆ record_sequence()

void MayaFlux::Portal::Graphics::ComputePress::record_sequence ( CommandBufferID  cmd_id,
const std::vector< ComputeStage > &  stages 
)

Record multiple pipeline dispatches into one already-open command buffer, inserting a barrier between each consecutive stage for that stage's hazard_bindings.

Vulkan permits binding different pipelines sequentially within a single command buffer recording — this is not a render-pass-style batching mechanism, only direct multi-pipeline recording plus the hazard barriers each transition needs. Does not submit; caller owns the command buffer's lifetime via ShaderFoundry (begin_commands / submit_and_wait or submit_async), the same as any other recorded sequence of commands.

Image bindings receive an eGeneral -> eGeneral shader write/read hazard barrier via ShaderFoundry::image_barrier. Non-image bindings receive a buffer_barrier with the same access/stage masks. Both use compute-to-compute pipeline stages throughout, since this method is for chaining compute stages only.

Parameters
cmd_idCommand buffer to record into. Must already be active (begun via ShaderFoundry::begin_commands).
stagesOrdered list of pipeline dispatches to record.

Definition at line 446 of file ComputePress.cpp.

449{
450 if (!is_initialized()) {
451 return;
452 }
453
454 auto& foundry = *m_shader_foundry;
455
456 for (size_t i = 0; i < stages.size(); ++i) {
457 const auto& stage = stages[i];
458
459 bind_all(
460 cmd_id,
461 stage.pipeline_id,
462 stage.descriptor_set_ids,
463 stage.push_constant_data.empty() ? nullptr : stage.push_constant_data.data(),
464 stage.push_constant_data.size());
465
466 if (stage.indirect.buffer) {
467 foundry.buffer_barrier(
468 cmd_id,
469 stage.indirect.buffer,
470 vk::AccessFlagBits::eShaderWrite,
471 vk::AccessFlagBits::eIndirectCommandRead,
472 vk::PipelineStageFlagBits::eComputeShader,
473 vk::PipelineStageFlagBits::eDrawIndirect);
474 dispatch_indirect(cmd_id, stage.indirect.buffer, stage.indirect.offset);
475 } else {
476 dispatch(cmd_id, stage.groups[0], stage.groups[1], stage.groups[2]);
477 }
478
479 for (const auto& hazard : stage.hazard_resources) {
480 if (hazard.binding.direction != GpuBufferBinding::Direction::INPUT_OUTPUT)
481 continue;
482
483 const bool is_image = hazard.binding.element_type == GpuBufferBinding::ElementType::IMAGE_STORAGE
484 || hazard.binding.element_type == GpuBufferBinding::ElementType::IMAGE_SAMPLED;
485
486 if (is_image) {
487 foundry.image_barrier(
488 cmd_id,
489 hazard.image,
490 vk::ImageLayout::eGeneral,
491 vk::ImageLayout::eGeneral,
492 vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eShaderRead,
493 vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eShaderRead,
494 vk::PipelineStageFlagBits::eComputeShader,
495 vk::PipelineStageFlagBits::eComputeShader);
496 } else {
497 foundry.buffer_barrier(
498 cmd_id,
499 hazard.buffer,
500 vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eShaderRead,
501 vk::AccessFlagBits::eShaderWrite | vk::AccessFlagBits::eShaderRead,
502 vk::PipelineStageFlagBits::eComputeShader,
503 vk::PipelineStageFlagBits::eComputeShader);
504 }
505 }
506
508 "record_sequence: stage {} of {} recorded ({} hazard barriers)",
509 i + 1, stages.size(), stage.hazard_resources.size());
510 }
511}
#define MF_DEBUG(comp, ctx,...)
bool size
void bind_all(CommandBufferID cmd_id, ComputePipelineID pipeline_id, const std::vector< DescriptorSetID > &descriptor_set_ids, const void *push_constants_data=nullptr, size_t push_constant_size=0)
All-in-one: bind pipeline + descriptors + push constants.
void dispatch(CommandBufferID cmd_id, uint32_t x, uint32_t y, uint32_t z)
Dispatch compute workgroups.
bool is_initialized() const
Check if ComputePress is initialized.
void dispatch_indirect(CommandBufferID cmd_id, vk::Buffer indirect_buffer, vk::DeviceSize offset=0)
Dispatch compute workgroups indirectly.
void buffer_barrier(CommandBufferID cmd_id, vk::Buffer buffer, vk::AccessFlags src_access, vk::AccessFlags dst_access, vk::PipelineStageFlags src_stage, vk::PipelineStageFlags dst_stage)
Insert buffer memory barrier.
@ GPUCompute
GPU compute operations (shaders, GPGPU tasks)
@ Portal
High-level user-facing API layer.
bool is_image(const fs::path &filepath)
Definition Depot.cpp:136

References bind_all(), MayaFlux::Portal::Graphics::ShaderFoundry::buffer_barrier(), dispatch(), dispatch_indirect(), MayaFlux::Journal::GPUCompute, MayaFlux::Portal::Graphics::GpuBufferBinding::IMAGE_SAMPLED, MayaFlux::Portal::Graphics::GpuBufferBinding::IMAGE_STORAGE, MayaFlux::Portal::Graphics::GpuBufferBinding::INPUT_OUTPUT, MayaFlux::is_image(), is_initialized(), m_shader_foundry, MF_DEBUG, and MayaFlux::Journal::Portal.

+ Here is the call graph for this function: