MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ upload_device_local()

MAYAFLUX_API void MayaFlux::Buffers::upload_device_local ( const std::shared_ptr< VKBuffer > &  target,
const std::shared_ptr< VKBuffer > &  staging_buffer,
const Kakshya::DataVariant data 
)

Upload data to a device-local buffer using a staging buffer.

Parameters
targetTarget VKBuffer to upload data into
staging_bufferHost-visible staging VKBuffer used for the upload
dataDataVariant containing the data to upload

This function handles uploading data from a Kakshya::DataVariant into a device-local VKBuffer by utilizing a staging buffer. It copies the data into the staging buffer, flushes it, and then issues a command to copy from the staging buffer to the target device-local buffer.

Definition at line 66 of file StagingUtils.cpp.

67{
68 Kakshya::DataAccess accessor(
69 const_cast<Kakshya::DataVariant&>(data),
70 {},
71 target->get_modality());
72
73 auto [ptr, bytes, format_hint] = accessor.gpu_buffer();
74
75 if (bytes > target->get_size_bytes()) {
76 error<std::runtime_error>(
77 Journal::Component::Buffers,
78 Journal::Context::BufferProcessing,
79 std::source_location::current(),
80 "Upload data size {} exceeds buffer capacity {}",
81 bytes, target->get_size_bytes());
82 }
83
84 auto& staging_resources = staging_buffer->get_buffer_resources();
85
86 void* staging_mapped = staging_resources.mapped_ptr;
87 if (!staging_mapped) {
88 error<std::runtime_error>(
89 Journal::Component::Buffers,
90 Journal::Context::BufferProcessing,
91 std::source_location::current(),
92 "Staging buffer has no mapped pointer");
93 }
94
95 std::memcpy(staging_mapped, ptr, bytes);
96 staging_buffer->mark_dirty_range(0, bytes);
97
98 auto buffer_service = Registry::BackendRegistry::instance()
99 .get_service<Registry::Service::BufferService>();
100
101 if (!buffer_service) {
102 error<std::runtime_error>(
103 Journal::Component::Buffers,
104 Journal::Context::BufferProcessing,
105 std::source_location::current(),
106 "upload_host_visible requires a valid buffer service");
107 }
108
109 auto dirty_ranges = staging_buffer->get_and_clear_dirty_ranges();
110 for (auto& [offset, size] : dirty_ranges) {
111 buffer_service->flush_range(
112 staging_resources.memory,
113 offset,
114 size);
115 }
116
117 buffer_service->copy_buffer(
118 static_cast<void*>(staging_buffer->get_buffer()),
119 static_cast<void*>(target->get_buffer()),
120 bytes, 0, 0);
121}
const uint8_t * ptr
float offset
Type-erased accessor for NDData with semantic view construction.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:102

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Registry::BackendRegistry::get_service(), MayaFlux::Kakshya::DataAccess::gpu_buffer(), MayaFlux::Registry::BackendRegistry::instance(), offset, and ptr.

Referenced by MayaFlux::Buffers::VKBuffer::clone_to(), MayaFlux::Buffers::BufferUploadProcessor::upload_device_local(), and upload_to_gpu().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: