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 395 of file StagingUtils.cpp.

400{
401 if (!source || !data || size == 0)
402 return;
403
404 auto buffer_service = Registry::BackendRegistry::instance()
405 .get_service<Registry::Service::BufferService>();
406
407 if (!buffer_service
408 || !buffer_service->execute_fenced
409 || !buffer_service->wait_fenced
410 || !buffer_service->release_fenced
411 || !buffer_service->invalidate_range) {
412 error<std::runtime_error>(
413 Journal::Component::Buffers,
414 Journal::Context::BufferProcessing,
415 std::source_location::current(),
416 "download_from_gpu_async: BufferService unavailable");
417 }
418
419 if (!staging || staging->get_size_bytes() < size)
420 staging = create_staging_buffer(size);
421
422 auto handle = buffer_service->copy_buffer_fenced(
423 static_cast<void*>(source->get_buffer()),
424 static_cast<void*>(staging->get_buffer()),
425 size, 0, 0);
426
427 if (!handle) {
428 error<std::runtime_error>(
429 Journal::Component::Buffers,
430 Journal::Context::BufferProcessing,
431 std::source_location::current(),
432 "download_from_gpu_async: execute_fenced returned null");
433 }
434
435 buffer_service->wait_fenced(handle);
436
437 auto& resources = staging->get_buffer_resources();
438 buffer_service->invalidate_range(resources.memory, 0, size);
439
440 void* ptr = staging->get_mapped_ptr();
441 if (!ptr) {
442 buffer_service->release_fenced(handle);
443 error<std::runtime_error>(
444 Journal::Component::Buffers,
445 Journal::Context::BufferProcessing,
446 std::source_location::current(),
447 "download_from_gpu_async: staging buffer has no mapped pointer");
448 }
449
450 std::memcpy(data, ptr, size);
451 buffer_service->release_fenced(handle);
452}
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: