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

◆ upload_device_local()

MAYAFLUX_API void MayaFlux::Buffers::upload_device_local ( const std::shared_ptr< VKBuffer > &  target,
const std::shared_ptr< VKBuffer > &  staging_buffer,
const Kakshya::DataVariant &  data,
size_t  dst_offset = 0 
)

Upload data to a device-local buffer using a staging buffer.

Parameters
targetTarget VKBuffer to upload data into
staging_bufferHost-visible staging VKBuffer used for the upload
dataDataVariant containing the data to upload

This function handles uploading data from a Kakshya::DataVariant into a device-local VKBuffer by utilizing a staging buffer. It copies the data into the staging buffer, flushes it, and then issues a command to copy from the staging buffer to the target device-local buffer.

Parameters
dst_offsetByte offset into target the staging copy lands at. The default 0 reproduces the whole-buffer overwrite exactly; a nonzero value writes a sub-range and leaves the rest untouched. The staging buffer itself only needs to hold data.

Definition at line 70 of file StagingUtils.cpp.

71{
72 Kakshya::DataAccess accessor(
73 const_cast<Kakshya::DataVariant&>(data),
74 {},
75 target->get_modality());
76
77 auto [ptr, bytes, format_hint] = accessor.gpu_buffer();
78
79 if (dst_offset + bytes > target->get_size_bytes()) {
80 error<std::runtime_error>(
81 Journal::Component::Buffers,
82 Journal::Context::BufferProcessing,
83 std::source_location::current(),
84 "Upload data size {} at offset {} exceeds buffer capacity {}",
85 bytes, dst_offset, target->get_size_bytes());
86 }
87
88 auto& staging_resources = staging_buffer->get_buffer_resources();
89
90 void* staging_mapped = staging_resources.mapped_ptr;
91 if (!staging_mapped) {
92 error<std::runtime_error>(
93 Journal::Component::Buffers,
94 Journal::Context::BufferProcessing,
95 std::source_location::current(),
96 "Staging buffer has no mapped pointer");
97 }
98
99 std::memcpy(staging_mapped, ptr, bytes);
100 staging_buffer->mark_dirty_range(0, bytes);
101
102 auto buffer_service = Registry::BackendRegistry::instance()
103 .get_service<Registry::Service::BufferService>();
104
105 if (!buffer_service) {
106 error<std::runtime_error>(
107 Journal::Component::Buffers,
108 Journal::Context::BufferProcessing,
109 std::source_location::current(),
110 "upload_host_visible requires a valid buffer service");
111 }
112
113 auto dirty_ranges = staging_buffer->get_and_clear_dirty_ranges();
114 for (auto& [offset, size] : dirty_ranges) {
115 buffer_service->flush_range(
116 staging_resources.memory,
117 offset,
118 size);
119 }
120
121 buffer_service->copy_buffer(
122 static_cast<void*>(staging_buffer->get_buffer()),
123 static_cast<void*>(target->get_buffer()),
124 bytes, 0, dst_offset);
125}
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::VKBuffer::clone_to(), MayaFlux::Buffers::BufferUploadProcessor::upload_device_local(), and upload_to_gpu().

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