MayaFlux 0.5.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 250 of file StagingUtils.cpp.

251{
252 auto buffer_service = Registry::BackendRegistry::instance()
253 .get_service<Registry::Service::BufferService>();
254
255 if (!buffer_service) {
256 error<std::runtime_error>(
257 Journal::Component::Buffers,
258 Journal::Context::BufferProcessing,
259 std::source_location::current(),
260 "download_device_local requires a valid buffer service");
261 }
262
263 buffer_service->copy_buffer(
264 static_cast<void*>(source->get_buffer()),
265 static_cast<void*>(staging_buffer->get_buffer()),
266 source->get_size_bytes(), 0, 0);
267
268 staging_buffer->mark_invalid_range(0, source->get_size_bytes());
269
270 auto& staging_resources = staging_buffer->get_buffer_resources();
271 auto invalid_ranges = staging_buffer->get_and_clear_invalid_ranges();
272 for (auto& [offset, size] : invalid_ranges) {
273 buffer_service->invalidate_range(
274 staging_resources.memory,
275 offset,
276 size);
277 }
278
279 void* staging_mapped = staging_resources.mapped_ptr;
280 if (!staging_mapped) {
281 error<std::runtime_error>(
282 Journal::Component::Buffers,
283 Journal::Context::BufferProcessing,
284 std::source_location::current(),
285 "Staging buffer has no mapped pointer");
286 }
287
288 std::vector<uint8_t> raw_bytes(source->get_size_bytes());
289 std::memcpy(raw_bytes.data(), staging_mapped, source->get_size_bytes());
290
291 std::dynamic_pointer_cast<VKBuffer>(target)->set_data({ raw_bytes });
292}
float offset
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(), MayaFlux::Registry::BackendRegistry::instance(), and offset.

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: