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

342{
343 if (!source) {
344 error<std::invalid_argument>(
345 Journal::Component::Buffers,
346 Journal::Context::BufferProcessing,
347 std::source_location::current(),
348 "download_from_gpu: source buffer is null");
349 }
350
351 if (size == 0) {
352 return;
353 }
354
355 auto temp_target = std::make_shared<VKBuffer>(
356 size, VKBuffer::Usage::STAGING, Kakshya::DataModality::UNKNOWN);
357
358 auto buffer_service = Registry::BackendRegistry::instance()
359 .get_service<Registry::Service::BufferService>();
360
361 if (!buffer_service) {
362 error<std::runtime_error>(
363 Journal::Component::Buffers,
364 Journal::Context::BufferProcessing,
365 std::source_location::current(),
366 "download_from_gpu requires a valid buffer service");
367 }
368
369 buffer_service->initialize_buffer(temp_target);
370
371 if (source->is_host_visible()) {
372 download_host_visible(source, temp_target);
373 } else {
374 std::shared_ptr<VKBuffer> staging_buf = staging;
375
376 if (!staging_buf) {
377 staging_buf = create_staging_buffer(size);
378 }
379
380 download_device_local(source, temp_target, staging_buf);
381 }
382
383 auto temp_data = temp_target->get_data();
384
385 if (temp_data.empty()) {
386 error<std::runtime_error>(
387 Journal::Component::Buffers,
388 Journal::Context::BufferProcessing,
389 std::source_location::current(),
390 "download_from_gpu: failed to retrieve data from temporary buffer");
391 }
392
393 if (temp_data.size() > 1) {
394 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
395 "download_from_gpu: unexpected multiple data variants in temporary buffer. Only the first will be used.");
396 }
397
398 Kakshya::DataAccess accessor(
399 const_cast<Kakshya::DataVariant&>(temp_data[0]),
400 {},
401 source->get_modality());
402
403 auto [ptr, bytes, format_hint] = accessor.gpu_buffer();
404
405 std::memcpy(data, ptr, std::min(size, bytes));
406}
#define MF_ERROR(comp, ctx,...)
Range size
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, size, 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: