MayaFlux 0.1.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 166 of file StagingUtils.cpp.

167{
168 auto buffer_service = Registry::BackendRegistry::instance()
169 .get_service<Registry::Service::BufferService>();
170
171 if (!buffer_service) {
172 error<std::runtime_error>(
173 Journal::Component::Buffers,
174 Journal::Context::BufferProcessing,
175 std::source_location::current(),
176 "upload_host_visible requires a valid buffer service");
177 }
178
179 buffer_service->execute_immediate([&](void* ptr) {
180 vk::BufferCopy copy_region;
181 copy_region.srcOffset = 0;
182 copy_region.dstOffset = 0;
183 copy_region.size = source->get_size_bytes();
184
185 auto cmd = static_cast<vk::CommandBuffer*>(ptr);
186
187 cmd->copyBuffer(
188 source->get_buffer(),
189 staging_buffer->get_buffer(),
190 1, &copy_region);
191 });
192
193 staging_buffer->mark_invalid_range(0, source->get_size_bytes());
194
195 auto& staging_resources = staging_buffer->get_buffer_resources();
196 auto invalid_ranges = staging_buffer->get_and_clear_invalid_ranges();
197 for (auto& [offset, size] : invalid_ranges) {
198 buffer_service->invalidate_range(
199 staging_resources.memory,
200 offset,
201 size);
202 }
203
204 void* staging_mapped = staging_resources.mapped_ptr;
205 if (!staging_mapped) {
206 error<std::runtime_error>(
207 Journal::Component::Buffers,
208 Journal::Context::BufferProcessing,
209 std::source_location::current(),
210 "Staging buffer has no mapped pointer");
211 }
212
213 std::vector<uint8_t> raw_bytes(source->get_size_bytes());
214 std::memcpy(raw_bytes.data(), staging_mapped, source->get_size_bytes());
215
216 std::dynamic_pointer_cast<VKBuffer>(target)->set_data({ raw_bytes });
217}
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: