25 auto vk_buffer = std::dynamic_pointer_cast<VKBuffer>(buffer);
28 "BufferDownloadProcessor requires VKBuffer");
32 if (!vk_buffer->is_initialized()) {
34 "VKBuffer not initialized - register with BufferManager first");
39 if (target_it ==
m_target_map.end() || !target_it->second) {
41 "BufferDownloadProcessor has no target configured for this buffer");
45 if (vk_buffer->is_host_visible()) {
55 if (target_it ==
m_target_map.end() || !target_it->second) {
58 auto target = target_it->second;
66 if (target_it ==
m_target_map.end() || !target_it->second) {
69 auto target = target_it->second;
81 if (it !=
m_staging_buffers.end() && it->second->get_size_bytes() >= source->get_size_bytes() && it->second->is_initialized()) {
85 auto staging_buffer = std::make_shared<VKBuffer>(
86 source->get_size_bytes(),
91 error<std::runtime_error>(
94 std::source_location::current(),
95 "No processing context available for staging buffer initialization");
98 if (!staging_buffer->is_initialized()) {
101 }
catch (
const std::exception& e) {
105 std::source_location::current(),
106 "Failed to initialize staging buffer: {}", e.what());
113 "Created staging buffer for download: {} bytes", staging_buffer->get_size_bytes());
119 error<std::runtime_error>(
122 std::source_location::current(),
123 "BufferDownloadProcessor can only be attached to VKBuffer");
132 error<std::runtime_error>(
135 std::source_location::current(),
136 "No processing context available for BufferDownloadProcessor");
140 "BufferDownloadProcessor attached");
148 "BufferDownloadProcessor detached");
153 return std::dynamic_pointer_cast<VKBuffer>(buffer) !=
nullptr;
158 if (!std::dynamic_pointer_cast<VKBuffer>(source)) {
159 error<std::runtime_error>(
162 std::source_location::current(),
163 "Source must be a VKBuffer");
169 "Configured download target for source buffer");
#define MF_INFO(comp, ctx,...)
#define MF_RT_ERROR(comp, ctx,...)
std::unordered_map< std::shared_ptr< Buffer >, std::shared_ptr< VKBuffer > > m_staging_buffers
std::shared_ptr< Buffer > get_target(const std::shared_ptr< Buffer > &source) const
Get configured target for a source.
void download_device_local(const std::shared_ptr< VKBuffer > &source)
std::unordered_map< std::shared_ptr< Buffer >, std::shared_ptr< Buffer > > m_target_map
void on_detach(std::shared_ptr< Buffer > buffer) override
Called when this processor is detached from a buffer.
BufferDownloadProcessor()
void configure_target(const std::shared_ptr< Buffer > &source, std::shared_ptr< Buffer > target)
Configure target buffer for a specific source.
~BufferDownloadProcessor() override
void processing_function(std::shared_ptr< Buffer > buffer) override
The core processing function that must be implemented by derived classes.
void download_host_visible(const std::shared_ptr< VKBuffer > &source)
void ensure_staging_buffer(const std::shared_ptr< VKBuffer > &source)
void remove_target(const std::shared_ptr< Buffer > &source)
Remove target configuration for a source.
void on_attach(std::shared_ptr< Buffer > buffer) override
Called when this processor is attached to a buffer.
bool is_compatible_with(std::shared_ptr< Buffer > buffer) const override
Checks if this processor can handle the specified buffer type.
ProcessingToken m_processing_token
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.
@ GRAPHICS_BACKEND
Standard graphics processing backend configuration.
void download_host_visible(const std::shared_ptr< VKBuffer > &source, const std::shared_ptr< VKBuffer > &target)
Download data from a host-visible buffer.
void download_device_local(const std::shared_ptr< VKBuffer > &source, const std::shared_ptr< VKBuffer > &target, const std::shared_ptr< VKBuffer > &staging_buffer)
Download data from a device-local buffer using a staging buffer.
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains)
@ Buffers
Buffers, Managers, processors and processing chains.
@ UNKNOWN
Unknown or undefined modality.
std::function< void(const std::shared_ptr< void > &)> initialize_buffer
Initialize a buffer object.
Backend buffer management service interface.