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

◆ download_from_gpu_async()

MAYAFLUX_API void MayaFlux::Buffers::download_from_gpu_async ( const std::shared_ptr< VKBuffer > &  source,
void *  data,
size_t  size,
std::shared_ptr< VKBuffer > &  staging 
)

Download from a device-local GPU buffer without stalling the graphics queue.

Records a buffer copy into a fenced command buffer, waits on the fence from the calling thread, then memcpys from the mapped staging buffer into data. Unlike download_from_gpu, this does not call queue.waitIdle, making it safe to call from any thread that is not the graphics thread itself.

staging is allocated and cached by the caller to avoid per-call Vulkan object churn. Pass the same staging buffer each frame; it is resized if size exceeds its current capacity.

Parameters
sourceDevice-local source buffer.
dataDestination host pointer, at least size bytes.
sizeByte count to copy.
stagingPersistent host-visible staging buffer. Created via create_staging_buffer(). Resized in-place if too small.

Definition at line 530 of file StagingUtils.cpp.

535{
536 if (!source || !data || size == 0)
537 return;
538
539 auto buffer_service = Registry::BackendRegistry::instance()
540 .get_service<Registry::Service::BufferService>();
541
542 if (!buffer_service
543 || !buffer_service->execute_fenced
544 || !buffer_service->wait_fenced
545 || !buffer_service->release_fenced
546 || !buffer_service->invalidate_range) {
547 error<std::runtime_error>(
548 Journal::Component::Buffers,
549 Journal::Context::BufferProcessing,
550 std::source_location::current(),
551 "download_from_gpu_async: BufferService unavailable");
552 }
553
554 if (!staging || staging->get_size_bytes() < size)
555 staging = create_staging_buffer(size);
556
557 auto handle = buffer_service->copy_buffer_fenced(
558 static_cast<void*>(source->get_buffer()),
559 static_cast<void*>(staging->get_buffer()),
560 size, 0, 0);
561
562 if (!handle) {
563 error<std::runtime_error>(
564 Journal::Component::Buffers,
565 Journal::Context::BufferProcessing,
566 std::source_location::current(),
567 "download_from_gpu_async: execute_fenced returned null");
568 }
569
570 buffer_service->wait_fenced(handle);
571
572 auto& resources = staging->get_buffer_resources();
573 buffer_service->invalidate_range(resources.memory, 0, size);
574
575 void* ptr = staging->get_mapped_ptr();
576 if (!ptr) {
577 buffer_service->release_fenced(handle);
578 error<std::runtime_error>(
579 Journal::Component::Buffers,
580 Journal::Context::BufferProcessing,
581 std::source_location::current(),
582 "download_from_gpu_async: staging buffer has no mapped pointer");
583 }
584
585 std::memcpy(data, ptr, size);
586 buffer_service->release_fenced(handle);
587}
const uint8_t * ptr
Backend buffer management service interface.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, create_staging_buffer(), MayaFlux::Registry::BackendRegistry::get_service(), MayaFlux::Registry::BackendRegistry::instance(), and ptr.

Referenced by MayaFlux::Nodes::GpuSync::GeometryReadbackNode::compute_frame().

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