MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
BufferDownloadProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6
7/**
8 * @class BufferDownloadProcessor
9 * @brief Transfers data from GPU VKBuffer to CPU target buffer
10 *
11 * Inverse of BufferUploadProcessor.
12 * Handles staging and transfer from device-local buffers.
13 *
14 * Usage:
15 * auto download = std::make_shared<BufferDownloadProcessor>();
16 * download->configure_target(gpu_buffer1, cpu_target1);
17 * download->configure_target(gpu_buffer2, cpu_target2);
18 *
19 * chain->add_processor(download, gpu_buffer1);
20 * chain->add_processor(download, gpu_buffer2);
21 *
22 * Each process() call downloads latest data to the configured target for that source.
23 */
24class MAYAFLUX_API BufferDownloadProcessor : public VKBufferProcessor {
25public:
27 ~BufferDownloadProcessor() override;
28
29 void processing_function(std::shared_ptr<Buffer> buffer) override;
30 void on_attach(std::shared_ptr<Buffer> buffer) override;
31 void on_detach(std::shared_ptr<Buffer> buffer) override;
32
33 [[nodiscard]] bool is_compatible_with(std::shared_ptr<Buffer> buffer) const override;
34
35 /**
36 * @brief Configure target buffer for a specific source
37 * @param source VKBuffer to download from
38 * @param target CPU-side buffer to write to (AudioBuffer, etc.)
39 */
40 void configure_target(const std::shared_ptr<Buffer>& source, std::shared_ptr<Buffer> target);
41
42 /**
43 * @brief Remove target configuration for a source
44 * @param source VKBuffer to remove configuration for
45 */
46 void remove_target(const std::shared_ptr<Buffer>& source);
47
48 /**
49 * @brief Get configured target for a source
50 * @param source VKBuffer to query
51 * @return Target buffer, or nullptr if not configured
52 */
53 [[nodiscard]] std::shared_ptr<Buffer> get_target(const std::shared_ptr<Buffer>& source) const;
54
55private:
56 // Maps source VKBuffer -> target Buffer
57 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<Buffer>> m_target_map;
58
59 // Maps source VKBuffer -> staging buffer (for device-local transfers)
60 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<VKBuffer>> m_staging_buffers;
61
62 void ensure_staging_buffer(const std::shared_ptr<VKBuffer>& source);
63 void download_host_visible(const std::shared_ptr<VKBuffer>& source);
64 void download_device_local(const std::shared_ptr<VKBuffer>& source);
65};
66
67} // namespace MayaFlux::Buffers
std::unordered_map< std::shared_ptr< Buffer >, std::shared_ptr< VKBuffer > > m_staging_buffers
std::unordered_map< std::shared_ptr< Buffer >, std::shared_ptr< Buffer > > m_target_map
Transfers data from GPU VKBuffer to CPU target buffer.
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.