MayaFlux 0.5.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(const std::shared_ptr<Buffer>& buffer) override;
30 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
31 void on_detach(const std::shared_ptr<Buffer>& buffer) override;
32
33 [[nodiscard]] bool is_compatible_with(const 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
55 /**
56 * @brief Configure targets to receive downloads of every entry in a
57 * VKBuffer's back_buffers, re-read every processing cycle.
58 * @param source VKBuffer whose back_buffers is being downloaded in full.
59 * @param targets CPU-side buffers to write into, one per back_buffers
60 * entry, in order.
61 *
62 * back_buffers.size() is read fresh each call. If targets.size() does not
63 * match at process time, the call is skipped with an error rather than
64 * partially applied. Interpretation of individual entries (which one is
65 * "current", "front", or otherwise meaningful) is the calling code's
66 * concern; this call only moves bytes.
67 */
68 void configure_back_buffers(
69 const std::shared_ptr<Buffer>& source,
70 std::vector<std::shared_ptr<Buffer>> targets);
71
72 /**
73 * @brief Remove back_buffers configuration for a source.
74 */
75 void remove_back_buffers(const std::shared_ptr<Buffer>& source);
76
77private:
78 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<Buffer>> m_target_map; ///< Maps source VKBuffer -> target Buffer
79 std::unordered_map<std::shared_ptr<Buffer>, std::shared_ptr<VKBuffer>> m_staging_buffers; ///< Maps source VKBuffer -> staging buffer (for device-local transfers)
80 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
81
82 void ensure_staging_buffer(const std::shared_ptr<VKBuffer>& source);
83 void download_host_visible(const std::shared_ptr<VKBuffer>& source);
84 void download_device_local(const std::shared_ptr<VKBuffer>& source);
85 void download_back_buffers(const std::shared_ptr<VKBuffer>& source);
86};
87
88} // namespace MayaFlux::Buffers
std::unordered_map< std::shared_ptr< Buffer >, std::shared_ptr< VKBuffer > > m_staging_buffers
Maps source VKBuffer -> staging buffer (for device-local transfers)
std::unordered_map< std::shared_ptr< Buffer >, std::shared_ptr< Buffer > > m_target_map
Maps source VKBuffer -> target Buffer.
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.
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.