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");
44 if (target_it ==
m_target_map.end() || !target_it->second) {
46 "BufferDownloadProcessor has no target configured for this buffer");
50 if (vk_buffer->is_host_visible()) {
60 if (target_it ==
m_target_map.end() || !target_it->second) {
63 auto target = target_it->second;
71 if (target_it ==
m_target_map.end() || !target_it->second) {
74 auto target = target_it->second;
86 if (it !=
m_staging_buffers.end() && it->second->get_size_bytes() >= source->get_size_bytes() && it->second->is_initialized()) {
90 auto staging_buffer = std::make_shared<VKBuffer>(
91 source->get_size_bytes(),
92 VKBuffer::Usage::STAGING,
96 error<std::runtime_error>(
99 std::source_location::current(),
100 "No processing context available for staging buffer initialization");
103 if (!staging_buffer->is_initialized()) {
106 }
catch (
const std::exception& e) {
110 std::source_location::current(),
111 "Failed to initialize staging buffer: {}", e.what());
118 "Created staging buffer for download: {} bytes", staging_buffer->get_size_bytes());
124 error<std::runtime_error>(
127 std::source_location::current(),
128 "BufferDownloadProcessor can only be attached to VKBuffer");
137 error<std::runtime_error>(
140 std::source_location::current(),
141 "No processing context available for BufferDownloadProcessor");
145 "BufferDownloadProcessor attached");
153 "BufferDownloadProcessor detached");
158 return std::dynamic_pointer_cast<VKBuffer>(buffer) !=
nullptr;
163 if (!std::dynamic_pointer_cast<VKBuffer>(source)) {
164 error<std::runtime_error>(
167 std::source_location::current(),
168 "Source must be a VKBuffer");
174 "Configured download target for source buffer");
183 const std::shared_ptr<Buffer>& source,
184 std::vector<std::shared_ptr<Buffer>> targets)
186 if (!std::dynamic_pointer_cast<VKBuffer>(source)) {
187 error<std::runtime_error>(
190 std::source_location::current(),
191 "Source must be a VKBuffer");
197 "Configured back_buffers download targets for source buffer");
212 auto& targets = it->second;
213 auto& resources = source->get_buffer_resources();
215 if (targets.size() != resources.back_buffers.size()) {
217 "download_back_buffers: {} targets configured, {} entries present",
218 targets.size(), resources.back_buffers.size());
224 for (
size_t i = 0; i < resources.back_buffers.size(); ++i) {
225 auto target = std::dynamic_pointer_cast<VKBuffer>(targets[i]);
228 "download_back_buffers: target {} is not a VKBuffer", i);
232 const size_t bytes = target->get_size_bytes();
233 std::vector<uint8_t> raw(bytes);
236 target->set_data({ raw });
#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
Maps source VKBuffer -> staging buffer (for device-local transfers)
bool is_compatible_with(const std::shared_ptr< Buffer > &buffer) const override
Checks if this processor can handle the specified buffer type.
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)
void on_attach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is attached to a buffer.
void processing_function(const std::shared_ptr< Buffer > &buffer) override
The core processing function that must be implemented by derived classes.
std::unordered_map< std::shared_ptr< Buffer >, std::shared_ptr< Buffer > > m_target_map
Maps source VKBuffer -> target Buffer.
void on_detach(const std::shared_ptr< Buffer > &buffer) override
Called when this processor is detached from a buffer.
void download_back_buffers(const std::shared_ptr< VKBuffer > &source)
void remove_back_buffers(const std::shared_ptr< Buffer > &source)
Remove back_buffers configuration for a source.
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 download_host_visible(const std::shared_ptr< VKBuffer > &source)
std::unordered_map< std::shared_ptr< Buffer >, std::vector< std::shared_ptr< Buffer > > > m_back_buffers_target_map
Maps source VKBuffer -> vector of target Buffers for back_buffers.
void ensure_staging_buffer(const std::shared_ptr< VKBuffer > &source)
void configure_back_buffers(const std::shared_ptr< Buffer > &source, std::vector< std::shared_ptr< Buffer > > targets)
Configure targets to receive downloads of every entry in a VKBuffer's back_buffers,...
void remove_target(const std::shared_ptr< Buffer > &source)
Remove target configuration for a source.
ProcessingToken m_processing_token
Registry::Service::BufferService * m_buffer_service
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_back_buffer(const VKBufferResources::GenerationSlot &slot, void *data, size_t size, std::shared_ptr< VKBuffer > &staging)
Download a raw back_buffers slot to host memory.
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.