MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ process_block()

void MayaFlux::Buffers::AudioComputeProcessor::process_block ( const std::shared_ptr< Buffer > & buffer)
private

Definition at line 186 of file AudioComputeProcessor.cpp.

187{
188 auto audio = std::dynamic_pointer_cast<AudioBuffer>(buffer);
189 if (!audio) {
191 "AudioComputeProcessor received a non-audio buffer");
192 return;
193 }
194
195 auto& samples = audio->get_data();
196 const auto frames = static_cast<uint32_t>(samples.size());
197
198 if (frames == 0) {
199 return;
200 }
201
202 if (!m_attached.load(std::memory_order_seq_cst)) {
203 audio->clear();
204 return;
205 }
206
207 if (frames != m_frames) {
208 resize_block(frames);
209 }
210
211 const size_t bytes = static_cast<size_t>(frames) * k_word_bytes;
212
213 auto* words = static_cast<unsigned char*>(m_block->get_buffer_resources().mapped_ptr);
214 if (!words) {
215 audio->clear();
216 return;
217 }
218
219 for (size_t i = 0; i < frames; ++i) {
220 Transitive::Protocol::store_le_double(words + i * k_word_bytes, samples[i]);
221 }
222 upload_to_gpu(words, bytes, m_block, nullptr, 0, true);
223
224 const auto before = m_last_command_buffer;
226
227 if (!is_shader_loaded() || m_last_command_buffer == before) {
228 audio->clear();
230 "AudioComputeProcessor dispatch did not run, child cleared");
231 return;
232 }
233
234 const auto& resources = m_block->get_buffer_resources();
236 .get_service<Registry::Service::BufferService>();
237 if (service && service->invalidate_range) {
238 service->invalidate_range(resources.memory, 0, bytes);
239 }
240
241 const auto* out = static_cast<const unsigned char*>(resources.mapped_ptr);
242 for (size_t i = 0; i < frames; ++i) {
243 samples[i] = Transitive::Protocol::load_le_double(out + i * k_word_bytes);
244 }
245}
#define MF_RT_ERROR(comp, ctx,...)
std::atomic< bool > m_attached
Set on attach, cleared on detach.
Portal::Graphics::CommandBufferID m_last_command_buffer
void processing_function(const std::shared_ptr< Buffer > &buffer) override
The core processing function that must be implemented by derived classes.
bool is_shader_loaded() const
Check if shader is loaded.
Interface * get_service()
Query for a backend service.
static BackendRegistry & instance()
Get the global registry instance.
void upload_to_gpu(const void *data, size_t size, const std::shared_ptr< VKBuffer > &target, const std::shared_ptr< VKBuffer > &staging, size_t dst_offset, bool awaited)
Upload raw data to GPU buffer (auto-detects host-visible vs device-local).
@ BufferProcessing
Buffer processing (Buffers::BufferManager, processing chains).
@ Buffers
Buffers, Managers, processors and processing chains.
void store_le_double(uint8_t *dst, double val) noexcept
Store a double as eight little-endian bytes of its IEEE 754 bits.
double load_le_double(const uint8_t *src) noexcept
Load a double from eight little-endian bytes of its IEEE 754 bits.

References MayaFlux::Journal::BufferProcessing, MayaFlux::Journal::Buffers, MayaFlux::Registry::BackendRegistry::get_service(), MayaFlux::Registry::BackendRegistry::instance(), MayaFlux::Buffers::ShaderProcessor::is_shader_loaded(), MayaFlux::Transitive::Protocol::load_le_double(), m_attached, m_block, m_frames, MayaFlux::Buffers::ShaderProcessor::m_last_command_buffer, MF_RT_ERROR, MayaFlux::Buffers::ShaderProcessor::processing_function(), resize_block(), MayaFlux::Transitive::Protocol::store_le_double(), and MayaFlux::Buffers::upload_to_gpu().

Referenced by processing_function().

Here is the call graph for this function:
Here is the caller graph for this function: