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

◆ ensure_buffers()

bool MayaFlux::Portal::Graphics::PrimitiveMill::ensure_buffers ( const std::shared_ptr< Buffers::VKBuffer > & source,
const Kakshya::VertexLayout & layout,
uint32_t total,
size_t run_count )
private

Grows the destination ring, run and prefix arenas to fit.

Every slot is replaced at once and the outgoing buffers are released once the work submitted so far completes. The 1.5x headroom keeps geometry that is being added to from re-growing on nearly every cycle.

Definition at line 570 of file PrimitiveMill.cpp.

575{
577 .get_service<Registry::Service::BufferService>();
578 if (!svc) {
580 "PrimitiveMill: BufferService unavailable");
581 return false;
582 }
583
584 if (total > m_output_capacity || m_outputs.size() != m_output_ring) {
585 const auto grown = static_cast<uint32_t>(static_cast<float>(total) * 1.5F);
586
587 auto milled_layout = layout;
588 milled_layout.vertex_count = total;
589
590 if (!m_outputs.empty()) {
591 get_shader_foundry().release_after_submit([svc, outgoing = std::move(m_outputs)] {
592 for (const auto& buffer : outgoing) {
593 svc->destroy_buffer(buffer);
594 }
595 });
596 }
597
598 m_outputs.assign(m_output_ring, nullptr);
599 for (auto& slot : m_outputs) {
600 slot = std::make_shared<VKBuffer>(
601 static_cast<size_t>(grown) * layout.stride_bytes,
602 VKBuffer::Usage::VERTEX,
603 source->get_modality());
604 slot->set_vertex_layout(milled_layout);
605 svc->initialize_buffer(slot);
606 }
607
608 m_output_capacity = grown;
609 m_output_slot = 0;
610 } else {
611 for (auto& slot : m_outputs) {
612 auto milled_layout = *slot->get_vertex_layout();
613 milled_layout.vertex_count = total;
614 slot->set_vertex_layout(milled_layout);
615 }
616 }
617
618 const auto arena_slots = static_cast<size_t>(m_output_ring) + 1;
619 const auto fit_arena = [arena_slots](std::unique_ptr<SlotArena>& arena, size_t bytes) {
620 if (arena && arena->slot_bytes() >= bytes) {
621 return;
622 }
623 if (!arena) {
624 arena = std::make_unique<SlotArena>();
625 }
626 arena->initialize(
627 static_cast<size_t>(static_cast<float>(bytes) * 1.5F),
628 BufferUsageHint::HOST_STORAGE, arena_slots);
629 };
630
631 fit_arena(m_run_arena, std::max<size_t>(run_count * RUN_WORDS * sizeof(uint32_t), sizeof(uint32_t)));
632 fit_arena(m_prefix_arena, std::max<size_t>(m_prefix.size() * sizeof(uint32_t), sizeof(uint32_t)));
633
634 return !m_outputs.empty()
635 && m_run_arena && m_run_arena->is_initialized()
636 && m_prefix_arena && m_prefix_arena->is_initialized();
637}
#define MF_RT_ERROR(comp, ctx,...)
std::unique_ptr< SlotArena > m_prefix_arena
std::unique_ptr< SlotArena > m_run_arena
std::vector< std::shared_ptr< Buffers::VKBuffer > > m_outputs
Milled buffers rotated between dispatches, all at m_output_capacity.
void release_after_submit(std::function< void()> release)
Run a release action once every submission made so far has completed.
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
@ Rendering
GPU rendering operations (graphics pipeline, frame rendering).
@ Portal
High-level user-facing API layer.
Source source()
Begin a Source chain.
Definition Plot.hpp:127
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
@ HOST_STORAGE
Host-visible storage buffer (eStorageBuffer + eHostVisible|eHostCoherent).

References MayaFlux::Registry::BackendRegistry::get_service(), MayaFlux::Portal::Graphics::get_shader_foundry(), MayaFlux::Portal::Graphics::HOST_STORAGE, MayaFlux::Registry::BackendRegistry::instance(), m_output_capacity, m_output_ring, m_output_slot, m_outputs, m_prefix, m_prefix_arena, m_run_arena, MF_RT_ERROR, MayaFlux::Journal::Portal, MayaFlux::Portal::Graphics::ShaderFoundry::release_after_submit(), MayaFlux::Journal::Rendering, MayaFlux::Kakshya::VertexLayout::stride_bytes, and MayaFlux::Kakshya::VertexLayout::vertex_count.

Referenced by mill().

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