MayaFlux 0.5.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 459 of file StagingUtils.cpp.

464{
465 if (!source) {
466 error<std::invalid_argument>(
467 Journal::Component::Buffers,
468 Journal::Context::BufferProcessing,
469 std::source_location::current(),
470 "download_from_gpu: source buffer is null");
471 }
472
473 if (size == 0) {
474 return;
475 }
476
477 auto temp_target = std::make_shared<VKBuffer>(
478 size, VKBuffer::Usage::STAGING, Kakshya::DataModality::UNKNOWN);
479
480 auto buffer_service = Registry::BackendRegistry::instance()
481 .get_service<Registry::Service::BufferService>();
482
483 if (!buffer_service) {
484 error<std::runtime_error>(
485 Journal::Component::Buffers,
486 Journal::Context::BufferProcessing,
487 std::source_location::current(),
488 "download_from_gpu requires a valid buffer service");
489 }
490
491 buffer_service->initialize_buffer(temp_target);
492
493 if (source->is_host_visible()) {
494 download_host_visible(source, temp_target);
495 } else {
496 std::shared_ptr<VKBuffer> staging_buf = staging;
497
498 if (!staging_buf) {
499 staging_buf = create_staging_buffer(size);
500 }
501
502 download_device_local(source, temp_target, staging_buf);
503 }
504
505 auto temp_data = temp_target->get_data();
506
507 if (temp_data.empty()) {
508 error<std::runtime_error>(
509 Journal::Component::Buffers,
510 Journal::Context::BufferProcessing,
511 std::source_location::current(),
512 "download_from_gpu: failed to retrieve data from temporary buffer");
513 }
514
515 if (temp_data.size() > 1) {
516 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
517 "download_from_gpu: unexpected multiple data variants in temporary buffer. Only the first will be used.");
518 }
519
520 Kakshya::DataAccess accessor(
521 const_cast<Kakshya::DataVariant&>(temp_data[0]),
522 {},
523 source->get_modality());
524
525 auto [ptr, bytes, format_hint] = accessor.gpu_buffer();
526
527 std::memcpy(data, ptr, std::min(size, bytes));
528}
#define MF_ERROR(comp, ctx,...)
const uint8_t * ptr
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.
Source source()
Begin a Source chain.
Definition Plot.hpp:128

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, ptr, and MayaFlux::Kakshya::UNKNOWN.

Referenced by MayaFlux::Buffers::ShaderProcessor::download_bound(), MayaFlux::Buffers::ShaderProcessor::download_bound(), 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: