MayaFlux 1.0.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
19class MAYAFLUX_API TransferProcessor : public VKBufferProcessor {
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 */
48 void connect_audio_to_gpu(
49 const std::shared_ptr<AudioBuffer>& source,
50 const std::shared_ptr<VKBuffer>& target);
51
52 /**
53 * @brief Configure GPU→audio transfer
54 */
55 void connect_gpu_to_audio(
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 */
69 TransferDirection get_direction() const { return m_direction; }
70
71 /**
72 * @brief Set transfer direction
73 */
74 void set_direction(TransferDirection direction) { m_direction = direction; }
75
76 void on_attach(const std::shared_ptr<Buffer>& buffer) override;
77 void on_detach(const std::shared_ptr<Buffer>& buffer) override;
78
79 void processing_function(const 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
92 TransferDirection m_direction = TransferDirection::AUDIO_TO_GPU;
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
std::shared_ptr< NetworkGeometryBuffer > 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.
std::unordered_map< std::shared_ptr< VKBuffer >, std::shared_ptr< VKBuffer > > m_staging_map
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.