MayaFlux 1.0.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 755 of file StagingUtils.cpp.

760{
761 if (!source) {
762 error<std::invalid_argument>(
763 Journal::Component::Buffers,
764 Journal::Context::BufferProcessing,
765 std::source_location::current(),
766 "download_from_gpu: source buffer is null");
767 }
768
769 if (size == 0) {
770 return;
771 }
772
773 auto temp_target = std::make_shared<VKBuffer>(
774 size, VKBuffer::Usage::STAGING, Kakshya::DataModality::UNKNOWN);
775
776 auto buffer_service = Registry::BackendRegistry::instance()
777 .get_service<Registry::Service::BufferService>();
778
779 if (!buffer_service) {
780 error<std::runtime_error>(
781 Journal::Component::Buffers,
782 Journal::Context::BufferProcessing,
783 std::source_location::current(),
784 "download_from_gpu requires a valid buffer service");
785 }
786
787 buffer_service->initialize_buffer(temp_target);
788
789 if (source->is_host_visible()) {
790 download_host_visible(source, temp_target);
791 } else {
792 std::shared_ptr<VKBuffer> staging_buf = staging;
793
794 if (!staging_buf) {
795 staging_buf = create_staging_buffer(size);
796 }
797
798 download_device_local(source, temp_target, staging_buf);
799 }
800
801 auto temp_data = temp_target->get_data();
802
803 if (temp_data.empty()) {
804 error<std::runtime_error>(
805 Journal::Component::Buffers,
806 Journal::Context::BufferProcessing,
807 std::source_location::current(),
808 "download_from_gpu: failed to retrieve data from temporary buffer");
809 }
810
811 if (temp_data.size() > 1) {
812 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
813 "download_from_gpu: unexpected multiple data variants in temporary buffer. Only the first will be used.");
814 }
815
816 Kakshya::DataAccess accessor(
817 const_cast<Kakshya::DataVariant&>(temp_data[0]),
818 {},
819 source->get_modality());
820
821 auto [ptr, bytes, format_hint] = accessor.gpu_buffer();
822
823 std::memcpy(data, ptr, std::min(size, bytes));
824}
#define MF_ERROR(comp, ctx,...)
bool size
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:127

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, size, 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: