MayaFlux 1.0.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 137 of file StagingUtils.cpp.

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

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: