Download from GPU buffer to raw data (auto-detects host-visible vs device-local)
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()) {
360 } else {
361 std::shared_ptr<VKBuffer> staging_buf = staging;
362
363 if (!staging_buf) {
365 }
366
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 {},
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,...)
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.