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

◆ download_device_local()

MAYAFLUX_API void MayaFlux::Buffers::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.

Parameters
sourceSource VKBuffer to download data from
targetTarget VKBuffer to store the downloaded data
staging_bufferHost-visible staging VKBuffer used for the download

This function handles downloading data from a device-local VKBuffer by utilizing a staging buffer. It issues a command to copy the data from the device-local buffer to the staging buffer, invalidates the staging buffer memory, and then copies the data into a CPU-accessible format to update the target buffer.

Definition at line 157 of file StagingUtils.cpp.

158{
159 auto buffer_service = Registry::BackendRegistry::instance()
160 .get_service<Registry::Service::BufferService>();
161
162 if (!buffer_service) {
163 error<std::runtime_error>(
164 Journal::Component::Buffers,
165 Journal::Context::BufferProcessing,
166 std::source_location::current(),
167 "download_device_local requires a valid buffer service");
168 }
169
170 buffer_service->copy_buffer(
171 static_cast<void*>(source->get_buffer()),
172 static_cast<void*>(staging_buffer->get_buffer()),
173 source->get_size_bytes(), 0, 0);
174
175 staging_buffer->mark_invalid_range(0, source->get_size_bytes());
176
177 auto& staging_resources = staging_buffer->get_buffer_resources();
178 auto invalid_ranges = staging_buffer->get_and_clear_invalid_ranges();
179 for (auto& [offset, size] : invalid_ranges) {
180 buffer_service->invalidate_range(
181 staging_resources.memory,
182 offset,
183 size);
184 }
185
186 void* staging_mapped = staging_resources.mapped_ptr;
187 if (!staging_mapped) {
188 error<std::runtime_error>(
189 Journal::Component::Buffers,
190 Journal::Context::BufferProcessing,
191 std::source_location::current(),
192 "Staging buffer has no mapped pointer");
193 }
194
195 std::vector<uint8_t> raw_bytes(source->get_size_bytes());
196 std::memcpy(raw_bytes.data(), staging_mapped, source->get_size_bytes());
197
198 std::dynamic_pointer_cast<VKBuffer>(target)->set_data({ raw_bytes });
199}
Source source()
Begin a Source chain.
Definition Plot.hpp:128
Backend buffer management service interface.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Registry::BackendRegistry::get_service(), and MayaFlux::Registry::BackendRegistry::instance().

Referenced by MayaFlux::Buffers::VKBuffer::clone_to(), MayaFlux::Buffers::BufferDownloadProcessor::download_device_local(), and download_from_gpu().

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