MayaFlux 0.4.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 390 of file StagingUtils.cpp.

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