25 auto vk_buffer = std::dynamic_pointer_cast<VKBuffer>(buffer);
28 "BufferUploadProcessor requires VKBuffer");
32 if (!vk_buffer->is_initialized()) {
34 "VKBuffer not initialized - register with BufferManager first");
39 if (source_it ==
m_source_map.end() || !source_it->second) {
41 "BufferUploadProcessor has no source configured for this buffer");
45 auto source = source_it->second;
46 auto source_data = std::dynamic_pointer_cast<VKBuffer>(source)->get_data();
47 if (source_data.empty()) {
49 "Source buffer has no data to upload");
53 if (vk_buffer->is_host_visible()) {
70 if (it !=
m_staging_buffers.end() && it->second->get_size_bytes() >= target->get_size_bytes() && it->second->is_initialized()) {
74 auto staging_buffer = std::make_shared<VKBuffer>(
75 target->get_size_bytes(),
80 error<std::runtime_error>(
83 std::source_location::current(),
84 "No processing context available for staging buffer initialization");
87 if (!staging_buffer->is_initialized()) {
90 }
catch (
const std::exception& e) {
94 std::source_location::current(),
95 "Failed to initialize staging buffer: {}", e.what());
102 "Created staging buffer: {} bytes", staging_buffer->get_size_bytes());
108 error<std::runtime_error>(
111 std::source_location::current(),
112 "BufferUploadProcessor can only be attached to VKBuffer");
121 error<std::runtime_error>(
124 std::source_location::current(),
125 "BufferUploadProcessor requires a valid buffer service");
129 "BufferUploadProcessor attached to buffer");
137 "BufferUploadProcessor detached from buffer");
142 return std::dynamic_pointer_cast<VKBuffer>(buffer) !=
nullptr;
147 if (!std::dynamic_pointer_cast<VKBuffer>(target)) {
148 error<std::runtime_error>(
151 std::source_location::current(),
152 "Target must be a VKBuffer");
158 "Configured upload source for target buffer");
#define MF_INFO(comp, ctx,...)
#define MF_RT_WARN(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
ProcessingToken m_processing_token
void processing_function(std::shared_ptr< Buffer > buffer) override
The core processing function that must be implemented by derived classes.
void configure_source(const std::shared_ptr< Buffer > &target, std::shared_ptr< Buffer > source)
Configure source buffer for a specific target.
~BufferUploadProcessor() override
void remove_source(const std::shared_ptr< Buffer > &target)
Remove source configuration for a target.
bool is_compatible_with(std::shared_ptr< Buffer > buffer) const override
Checks if this processor can handle the specified buffer type.
std::unordered_map< std::shared_ptr< Buffer >, std::shared_ptr< Buffer > > m_source_map
std::shared_ptr< Buffer > get_source(const std::shared_ptr< Buffer > &target) const
Get configured source for a target.
void upload_device_local(const std::shared_ptr< VKBuffer > &target, const Kakshya::DataVariant &data)
void on_detach(std::shared_ptr< Buffer > buffer) override
Called when this processor is detached from a buffer.
std::unordered_map< std::shared_ptr< Buffer >, std::shared_ptr< VKBuffer > > m_staging_buffers
void on_attach(std::shared_ptr< Buffer > buffer) override
Called when this processor is attached to a buffer.
void ensure_staging_buffer(const std::shared_ptr< VKBuffer > &target)
Registry::Service::BufferService * m_buffer_service
@ STAGING
Host-visible staging buffer (CPU-writable)
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
void upload_host_visible(const std::shared_ptr< VKBuffer > &target, const Kakshya::DataVariant &data)
Upload data to a host-visible buffer.
void 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.
@ GRAPHICS_BACKEND
Standard graphics processing backend configuration.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
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.
@ UNKNOWN
Unknown or undefined modality.
std::function< void(const std::shared_ptr< void > &)> initialize_buffer
Initialize a buffer object.
Backend buffer management service interface.