MayaFlux 0.1.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 281 of file StagingUtils.cpp.

286{
287 if (!source) {
288 error<std::invalid_argument>(
289 Journal::Component::Buffers,
290 Journal::Context::BufferProcessing,
291 std::source_location::current(),
292 "download_from_gpu: source buffer is null");
293 }
294
295 if (size == 0) {
296 return;
297 }
298
299 auto temp_target = std::make_shared<VKBuffer>(
300 size, VKBuffer::Usage::STAGING, Kakshya::DataModality::UNKNOWN);
301
302 if (source->is_host_visible()) {
303 download_host_visible(source, temp_target);
304 } else {
305 std::shared_ptr<VKBuffer> staging_buf = staging;
306
307 if (!staging_buf) {
308 staging_buf = create_staging_buffer(size);
309 }
310
311 download_device_local(source, temp_target, staging_buf);
312 }
313
314 auto temp_data = temp_target->get_data();
315
316 if (temp_data.empty()) {
317 error<std::runtime_error>(
318 Journal::Component::Buffers,
319 Journal::Context::BufferProcessing,
320 std::source_location::current(),
321 "download_from_gpu: failed to retrieve data from temporary buffer");
322 }
323
324 if (temp_data.size() > 1) {
325 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
326 "download_from_gpu: unexpected multiple data variants in temporary buffer. Only the first will be used.");
327 }
328
329 Kakshya::DataAccess accessor(
330 const_cast<Kakshya::DataVariant&>(temp_data[0]),
331 {},
332 source->get_modality());
333
334 auto [ptr, bytes, format_hint] = accessor.gpu_buffer();
335
336 std::memcpy(data, ptr, std::min(size, bytes));
337}
#define MF_ERROR(comp, ctx,...)
std::shared_ptr< VKBuffer > create_staging_buffer(size_t size)
Create staging buffer for transfers.
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::Kakshya::DataAccess::gpu_buffer(), 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: