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

◆ download_compute_mesh()

MAYAFLUX_API std::optional< Kakshya::MeshData > MayaFlux::Buffers::download_compute_mesh ( const std::shared_ptr< ComputeMeshBuffer > &  buffer)

Download a ComputeMeshBuffer's current live geometry to CPU.

One-shot and blocking, via download_from_gpu_async: call it off the graphics thread. Downloads exactly ComputeMeshBuffer::get_live_vertex_count() vertices rather than the worst-case allocation.

Parameters
bufferSource buffer. setup_processors() must have run.
Returns
The geometry as non-indexed triangles, or nullopt if the buffer is null, has no readable counter, or the live vertex count is zero.

Definition at line 460 of file StagingUtils.cpp.

462{
463 if (!buffer) {
464 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
465 "download_compute_mesh: null buffer");
466 return std::nullopt;
467 }
468
469 const auto vertex_count = buffer->get_live_vertex_count();
470 if (!vertex_count) {
471 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
472 "download_compute_mesh: no mesh processor (setup_processors() has not been called) "
473 "or the counter buffer is not host-visible or not allocated yet");
474 return std::nullopt;
475 }
476 if (*vertex_count == 0) {
477 MF_ERROR(Journal::Component::Buffers, Journal::Context::BufferProcessing,
478 "download_compute_mesh: live vertex count is zero");
479 return std::nullopt;
480 }
481
482 std::vector<uint8_t> bytes(static_cast<size_t>(*vertex_count) * sizeof(Kakshya::MeshVertex));
483 std::shared_ptr<VKBuffer> staging;
484 download_from_gpu_async(buffer, bytes.data(), bytes.size(), staging);
485
486 return triangle_soup_mesh(bytes);
487}
#define MF_ERROR(comp, ctx,...)
std::shared_ptr< NetworkGeometryBuffer > buffer
std::optional< Kakshya::MeshData > triangle_soup_mesh(std::span< const uint8_t > vertex_bytes)
Wrap non-indexed triangle vertices as MeshData.
void download_from_gpu_async(const std::shared_ptr< VKBuffer > &source, void *data, size_t size, std::shared_ptr< VKBuffer > &staging)
Download from a device-local GPU buffer without stalling the graphics queue.

References buffer, MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, download_from_gpu_async(), MF_ERROR, and triangle_soup_mesh().

Referenced by MayaFlux::IO::download_compute_mesh().

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