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

◆ upload_back_buffer_async()

MAYAFLUX_API TransferHandle MayaFlux::Buffers::upload_back_buffer_async ( const VKBufferResources::GenerationSlot slot,
const void *  data,
size_t  size,
std::shared_ptr< VKBuffer > &  staging 
)

Upload to a back_buffers slot without waiting for completion.

Parameters
slotDestination slot, typically from VKBuffer::get_back_buffer().
dataSource pointer, at least size bytes. Copied into staging before returning, so the caller may free it immediately.
sizeByte count to copy.
stagingPersistent staging buffer, grown if too small.
Returns
Handle to pass to resolve_transfer, or null for host-visible slots where the write was a direct memcpy.

The staging buffer is in use until the returned handle is resolved. Any further transfer through the same staging buffer must resolve this one first, or the copy source is overwritten mid-flight.

Definition at line 133 of file StagingUtils.cpp.

138{
139 if (!data || size == 0)
140 return {};
141
142 if (slot.mapped_ptr) {
143 std::memcpy(slot.mapped_ptr, data, size);
144 return {};
145 }
146
147 auto buffer_service = Registry::BackendRegistry::instance()
148 .get_service<Registry::Service::BufferService>();
149
150 if (!buffer_service
151 || !buffer_service->execute_fenced
152 || !buffer_service->wait_fenced
153 || !buffer_service->release_fenced
154 || !buffer_service->flush_range) {
155 error<std::runtime_error>(
156 Journal::Component::Buffers,
157 Journal::Context::BufferProcessing,
158 std::source_location::current(),
159 "upload_back_buffer_async: BufferService unavailable");
160 }
161
162 if (!staging || staging->get_size_bytes() < size)
163 staging = create_staging_buffer(size);
164
165 void* ptr = staging->get_mapped_ptr();
166 if (!ptr) {
167 error<std::runtime_error>(
168 Journal::Component::Buffers,
169 Journal::Context::BufferProcessing,
170 std::source_location::current(),
171 "upload_back_buffer_async: staging buffer has no mapped pointer");
172 }
173
174 std::memcpy(ptr, data, size);
175
176 auto& resources = staging->get_buffer_resources();
177 buffer_service->flush_range(resources.memory, 0, size);
178
179 auto handle = buffer_service->copy_buffer_fenced(
180 static_cast<void*>(staging->get_buffer()),
181 static_cast<void*>(slot.buffer),
182 size, 0, 0);
183
184 if (!handle) {
185 error<std::runtime_error>(
186 Journal::Component::Buffers,
187 Journal::Context::BufferProcessing,
188 std::source_location::current(),
189 "upload_back_buffer_async: copy_buffer_fenced returned null");
190 }
191
192 return handle;
193}
const uint8_t * ptr
std::shared_ptr< VKBuffer > create_staging_buffer(size_t size)
Create staging buffer for transfers.

References MayaFlux::Buffers::VKBufferResources::GenerationSlot::buffer, MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, create_staging_buffer(), MayaFlux::Registry::BackendRegistry::get_service(), MayaFlux::Registry::BackendRegistry::instance(), MayaFlux::Buffers::VKBufferResources::GenerationSlot::mapped_ptr, and ptr.

Referenced by MayaFlux::Buffers::VolumeGridBuffer::seed_raw(), and upload_back_buffer().

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