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 162 of file StagingUtils.cpp.

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