MayaFlux 1.0.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 826 of file StagingUtils.cpp.

831{
832 if (!source || !data || size == 0)
833 return;
834
835 auto buffer_service = Registry::BackendRegistry::instance()
836 .get_service<Registry::Service::BufferService>();
837
838 if (!buffer_service
839 || !buffer_service->execute_fenced
840 || !buffer_service->wait_fenced
841 || !buffer_service->release_fenced
842 || !buffer_service->invalidate_range) {
843 error<std::runtime_error>(
844 Journal::Component::Buffers,
845 Journal::Context::BufferProcessing,
846 std::source_location::current(),
847 "download_from_gpu_async: BufferService unavailable");
848 }
849
850 if (!staging || staging->get_size_bytes() < size)
851 staging = create_staging_buffer(size);
852
853 auto handle = buffer_service->copy_buffer_fenced(
854 static_cast<void*>(source->get_buffer()),
855 static_cast<void*>(staging->get_buffer()),
856 size, 0, 0);
857
858 if (!handle) {
859 error<std::runtime_error>(
860 Journal::Component::Buffers,
861 Journal::Context::BufferProcessing,
862 std::source_location::current(),
863 "download_from_gpu_async: execute_fenced returned null");
864 }
865
866 buffer_service->wait_fenced(handle);
867
868 auto& resources = staging->get_buffer_resources();
869 buffer_service->invalidate_range(resources.memory, 0, size);
870
871 void* ptr = staging->get_mapped_ptr();
872 if (!ptr) {
873 buffer_service->release_fenced(handle);
874 error<std::runtime_error>(
875 Journal::Component::Buffers,
876 Journal::Context::BufferProcessing,
877 std::source_location::current(),
878 "download_from_gpu_async: staging buffer has no mapped pointer");
879 }
880
881 std::memcpy(data, ptr, size);
882 buffer_service->release_fenced(handle);
883}
bool size
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(), ptr, and size.

Referenced by MayaFlux::Nodes::GpuSync::GeometryReadbackNode::compute_frame(), and download_compute_mesh().

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