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

◆ upload_host_visible()

MAYAFLUX_API void MayaFlux::Buffers::upload_host_visible ( const std::shared_ptr< VKBuffer > &  target,
const Kakshya::DataVariant data 
)

Upload data to a host-visible buffer.

Parameters
targetTarget VKBuffer to upload data into
dataDataVariant containing the data to upload

This function handles uploading data from a Kakshya::DataVariant into a host-visible VKBuffer. It maps the buffer memory, copies the data, and marks the buffer as dirty for synchronization.

Definition at line 14 of file StagingUtils.cpp.

15{
16 Kakshya::DataAccess accessor(
17 const_cast<Kakshya::DataVariant&>(data),
18 {},
19 target->get_modality());
20
21 auto [ptr, bytes, format_hint] = accessor.gpu_buffer();
22
23 if (bytes > target->get_size_bytes()) {
24 error<std::runtime_error>(
25 Journal::Component::Buffers,
26 Journal::Context::BufferProcessing,
27 std::source_location::current(),
28 "Upload data size {} exceeds buffer capacity {}",
29 bytes, target->get_size_bytes());
30 }
31
32 auto& target_resources = target->get_buffer_resources();
33 void* mapped = target_resources.mapped_ptr;
34 if (!mapped) {
35 error<std::runtime_error>(
36 Journal::Component::Buffers,
37 Journal::Context::BufferProcessing,
38 std::source_location::current(),
39 "Host-visible buffer has no mapped pointer");
40 }
41
42 std::memcpy(mapped, ptr, bytes);
43
44 target->mark_dirty_range(0, bytes);
45
46 auto buffer_service = Registry::BackendRegistry::instance()
47 .get_service<Registry::Service::BufferService>();
48
49 if (!buffer_service) {
50 error<std::runtime_error>(
51 Journal::Component::Buffers,
52 Journal::Context::BufferProcessing,
53 std::source_location::current(),
54 "upload_host_visible requires a valid buffer service");
55 }
56
57 auto dirty_ranges = target->get_and_clear_dirty_ranges();
58 for (auto& [offset, size] : dirty_ranges) {
59 buffer_service->flush_range(
60 target_resources.memory,
61 offset,
62 size);
63 }
64}
const uint8_t * ptr
float offset
Type-erased accessor for NDData with semantic view construction.
std::variant< std::vector< double >, std::vector< float >, std::vector< uint8_t >, std::vector< uint16_t >, std::vector< uint32_t >, std::vector< std::complex< float > >, std::vector< std::complex< double > >, std::vector< glm::vec2 >, std::vector< glm::vec3 >, std::vector< glm::vec4 >, std::vector< glm::mat4 > > DataVariant
Multi-type data storage for different precision needs.
Definition NDData.hpp:102

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Registry::BackendRegistry::get_service(), MayaFlux::Kakshya::DataAccess::gpu_buffer(), MayaFlux::Registry::BackendRegistry::instance(), offset, and ptr.

Referenced by MayaFlux::Buffers::BufferUploadProcessor::processing_function(), and upload_to_gpu().

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