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

◆ download_from_gpu() [3/3]

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

Download from GPU buffer to raw data (auto-detects host-visible vs device-local)

Parameters
sourceSource GPU buffer
dataDestination data pointer
sizeSize in bytes
stagingOptional staging buffer (created if needed for device-local)

Convenience wrapper over StagingUtils that:

  • Auto-detects if buffer is host-visible or device-local
  • Handles staging buffer creation if needed
  • Copies data to destination pointer

Definition at line 307 of file StagingUtils.cpp.

312{
313 if (!source) {
314 error<std::invalid_argument>(
315 Journal::Component::Buffers,
316 Journal::Context::BufferProcessing,
317 std::source_location::current(),
318 "download_from_gpu: source buffer is null");
319 }
320
321 if (size == 0) {
322 return;
323 }
324
325 auto temp_target = std::make_shared<VKBuffer>(
326 size, VKBuffer::Usage::STAGING, Kakshya::DataModality::UNKNOWN);
327
328 auto buffer_service = Registry::BackendRegistry::instance()
329 .get_service<Registry::Service::BufferService>();
330
331 if (!buffer_service) {
332 error<std::runtime_error>(
333 Journal::Component::Buffers,
334 Journal::Context::BufferProcessing,
335 std::source_location::current(),
336 "download_from_gpu requires a valid buffer service");
337 }
338
339 buffer_service->initialize_buffer(temp_target);
340
341 if (source->is_host_visible()) {
342 download_host_visible(source, temp_target);
343 } else {
344 std::shared_ptr<VKBuffer> staging_buf = staging;
345
346 if (!staging_buf) {
347 staging_buf = create_staging_buffer(size);
348 }
349
350 download_device_local(source, temp_target, staging_buf);
351 }
352
353 auto temp_data = temp_target->get_data();
354
355 if (temp_data.empty()) {
356 error<std::runtime_error>(
357 Journal::Component::Buffers,
358 Journal::Context::BufferProcessing,
359 std::source_location::current(),
360 "download_from_gpu: failed to retrieve data from temporary buffer");
361 }
362
363 if (temp_data.size() > 1) {
364 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
365 "download_from_gpu: unexpected multiple data variants in temporary buffer. Only the first will be used.");
366 }
367
368 Kakshya::DataAccess accessor(
369 const_cast<Kakshya::DataVariant&>(temp_data[0]),
370 {},
371 source->get_modality());
372
373 auto [ptr, bytes, format_hint] = accessor.gpu_buffer();
374
375 std::memcpy(data, ptr, std::min(size, bytes));
376}
#define MF_ERROR(comp, ctx,...)
std::shared_ptr< VKBuffer > create_staging_buffer(size_t size)
Create staging buffer for transfers.
void download_host_visible(const std::shared_ptr< VKBuffer > &source, const std::shared_ptr< VKBuffer > &target)
Download data from a host-visible buffer.
void download_device_local(const std::shared_ptr< VKBuffer > &source, const std::shared_ptr< VKBuffer > &target, const std::shared_ptr< VKBuffer > &staging_buffer)
Download data from a device-local buffer using a staging buffer.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, create_staging_buffer(), download_device_local(), download_host_visible(), MayaFlux::Registry::BackendRegistry::get_service(), MayaFlux::Kakshya::DataAccess::gpu_buffer(), MayaFlux::Registry::BackendRegistry::instance(), MF_ERROR, MayaFlux::Buffers::VKBuffer::STAGING, and MayaFlux::Kakshya::UNKNOWN.

Referenced by MayaFlux::Nodes::GpuSync::ComputeOutNode::compute_frame(), download_from_gpu(), download_from_gpu(), and download_to_view().

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