MayaFlux 0.1.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 
)

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.

Definition at line 61 of file StagingUtils.cpp.

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