MayaFlux 1.0.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,
size_t  dst_offset = 0 
)

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.

Parameters
dst_offsetByte offset into target to write at. The default 0 reproduces the whole-buffer overwrite exactly; a nonzero value writes a sub-range and leaves the rest of the buffer untouched.

Definition at line 18 of file StagingUtils.cpp.

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

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

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

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