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 324 of file StagingUtils.cpp.

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