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

10{
11 Kakshya::DataAccess accessor(
12 const_cast<Kakshya::DataVariant&>(data),
13 {},
14 target->get_modality());
15
16 auto [ptr, bytes, format_hint] = accessor.gpu_buffer();
17
18 if (bytes > target->get_size_bytes()) {
19 error<std::runtime_error>(
20 Journal::Component::Buffers,
21 Journal::Context::BufferProcessing,
22 std::source_location::current(),
23 "Upload data size {} exceeds buffer capacity {}",
24 bytes, target->get_size_bytes());
25 }
26
27 auto& target_resources = target->get_buffer_resources();
28 void* mapped = target_resources.mapped_ptr;
29 if (!mapped) {
30 error<std::runtime_error>(
31 Journal::Component::Buffers,
32 Journal::Context::BufferProcessing,
33 std::source_location::current(),
34 "Host-visible buffer has no mapped pointer");
35 }
36
37 std::memcpy(mapped, ptr, bytes);
38
39 target->mark_dirty_range(0, bytes);
40
41 auto buffer_service = Registry::BackendRegistry::instance()
42 .get_service<Registry::Service::BufferService>();
43
44 if (!buffer_service) {
45 error<std::runtime_error>(
46 Journal::Component::Buffers,
47 Journal::Context::BufferProcessing,
48 std::source_location::current(),
49 "upload_host_visible requires a valid buffer service");
50 }
51
52 auto dirty_ranges = target->get_and_clear_dirty_ranges();
53 for (auto& [offset, size] : dirty_ranges) {
54 buffer_service->flush_range(
55 target_resources.memory,
56 offset,
57 size);
58 }
59}
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:73

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

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: