MayaFlux 0.1.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
TransferProcessor.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Buffers {
6
7class AudioBuffer;
8
9/**
10 * @enum TransferDirection
11 * @brief Specifies the direction of data transfer
12 */
13enum class TransferDirection : uint8_t {
14 AUDIO_TO_GPU = 0, // Upload: AudioBuffer → VKBuffer
15 GPU_TO_AUDIO = 1, // Download: VKBuffer → AudioBuffer
16 BIDIRECTIONAL = 2 // Both directions (future, complex)
17};
18
20public:
22
23 /**
24 * @brief Create transfer from audio to GPU
25 * @param source Source AudioBuffer
26 * @param target Target VKBuffer
27 */
29 const std::shared_ptr<AudioBuffer>& source,
30 const std::shared_ptr<VKBuffer>& target);
31
32 /**
33 * @brief Create transfer with explicit direction
34 * @param audio_buffer AudioBuffer for transfer
35 * @param gpu_buffer VKBuffer for transfer
36 * @param direction Direction of transfer (AUDIO_TO_GPU or GPU_TO_AUDIO)
37 */
39 const std::shared_ptr<AudioBuffer>& audio_buffer,
40 const std::shared_ptr<VKBuffer>& gpu_buffer,
41 TransferDirection direction);
42
43 ~TransferProcessor() override = default;
44
45 /**
46 * @brief Configure audio→GPU transfer
47 */
49 const std::shared_ptr<AudioBuffer>& source,
50 const std::shared_ptr<VKBuffer>& target);
51
52 /**
53 * @brief Configure GPU→audio transfer
54 */
56 const std::shared_ptr<VKBuffer>& source,
57 const std::shared_ptr<AudioBuffer>& target);
58
59 /**
60 * @brief Set up staging buffer for device-local GPU buffer
61 */
62 void setup_staging(
63 const std::shared_ptr<VKBuffer>& target,
64 std::shared_ptr<VKBuffer> staging_buffer);
65
66 /**
67 * @brief Get current transfer direction
68 */
70
71 /**
72 * @brief Set transfer direction
73 */
74 void set_direction(TransferDirection direction) { m_direction = direction; }
75
76 void on_attach(std::shared_ptr<Buffer> buffer) override;
77 void on_detach(std::shared_ptr<Buffer> buffer) override;
78
79 void processing_function(std::shared_ptr<Buffer> buffer) override;
80
81private:
82 // Audio→GPU transfers
83 std::unordered_map<std::shared_ptr<AudioBuffer>, std::shared_ptr<VKBuffer>> m_audio_to_gpu_map;
84
85 // GPU→Audio transfers
86 std::unordered_map<std::shared_ptr<VKBuffer>, std::shared_ptr<AudioBuffer>> m_gpu_to_audio_map;
87
88 // Staging buffers (for device-local GPU memory)
89 std::unordered_map<std::shared_ptr<VKBuffer>, std::shared_ptr<VKBuffer>> m_staging_map;
90
91 // Current transfer direction
93
94 bool validate_audio_to_gpu(const std::shared_ptr<VKBuffer>& target) const;
95 bool validate_gpu_to_audio(const std::shared_ptr<AudioBuffer>& target) const;
96
97 void process_audio_to_gpu(const std::shared_ptr<Buffer>& gpu_buffer);
98 void process_gpu_to_audio(const std::shared_ptr<Buffer>& audio_buffer);
99};
100
101} // namespace MayaFlux::Buffers
bool validate_audio_to_gpu(const std::shared_ptr< VKBuffer > &target) const
void processing_function(std::shared_ptr< Buffer > buffer) override
The core processing function that must be implemented by derived classes.
void on_attach(std::shared_ptr< Buffer > buffer) override
Called when this processor is attached to a buffer.
void connect_audio_to_gpu(const std::shared_ptr< AudioBuffer > &source, const std::shared_ptr< VKBuffer > &target)
Configure audio→GPU transfer.
void connect_gpu_to_audio(const std::shared_ptr< VKBuffer > &source, const std::shared_ptr< AudioBuffer > &target)
Configure GPU→audio transfer.
void setup_staging(const std::shared_ptr< VKBuffer > &target, std::shared_ptr< VKBuffer > staging_buffer)
Set up staging buffer for device-local GPU buffer.
std::unordered_map< std::shared_ptr< VKBuffer >, std::shared_ptr< AudioBuffer > > m_gpu_to_audio_map
TransferDirection get_direction() const
Get current transfer direction.
bool validate_gpu_to_audio(const std::shared_ptr< AudioBuffer > &target) const
void process_gpu_to_audio(const std::shared_ptr< Buffer > &audio_buffer)
std::unordered_map< std::shared_ptr< VKBuffer >, std::shared_ptr< VKBuffer > > m_staging_map
void process_audio_to_gpu(const std::shared_ptr< Buffer > &gpu_buffer)
void on_detach(std::shared_ptr< Buffer > buffer) override
Called when this processor is detached from a buffer.
std::unordered_map< std::shared_ptr< AudioBuffer >, std::shared_ptr< VKBuffer > > m_audio_to_gpu_map
void set_direction(TransferDirection direction)
Set transfer direction.
TransferDirection
Specifies the direction of data transfer.