Overhaul and optimize thread-buffer allocation

Every route calls Session::ensure_buffers when configuring
processors. Previously that unconditionally invoked the
BufferManager, even if no change was required.

This also fixes a potential issue when bouncing tracks.
::write_one_track() increases the buffersize to 8k, but only for
the ChanCount required to bounce. This was never properly reset.

Furthermore this is in preparation for RegionFX which may
need to increase the ChanCount of Threadbuffers.
This commit is contained in:
Robin Gareus 2024-03-22 04:48:27 +01:00
parent 6dfcb60763
commit 2f6a428f05
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 27 additions and 1 deletions

View File

@ -311,6 +311,8 @@ public:
BufferSet& get_route_buffers (ChanCount count = ChanCount::ZERO, bool silence = true);
BufferSet& get_mix_buffers (ChanCount count = ChanCount::ZERO);
void ensure_buffers_unlocked (ChanCount howmany);
bool have_rec_enabled_track () const;
bool have_rec_disabled_track () const;
@ -1513,6 +1515,8 @@ private:
void setup_engine_resampling ();
void ensure_buffers (ChanCount howmany = ChanCount::ZERO);
ChanCount _required_thread_buffers;
size_t _required_thread_buffersize;
void process_without_events (pframes_t);
void process_with_events (pframes_t);

View File

@ -230,6 +230,7 @@ Session::Session (AudioEngine &eng,
, _writable (false)
, _under_nsm_control (false)
, _xrun_count (0)
, _required_thread_buffersize (0)
, master_wait_end (0)
, post_export_sync (false)
, post_export_position (0)
@ -2407,6 +2408,7 @@ Session::set_block_size (pframes_t nframes)
* here.
*/
current_block_size = nframes;
_required_thread_buffersize = -1;
ensure_buffers ();
@ -5848,13 +5850,33 @@ Session::tempo_map_changed ()
set_dirty ();
}
void
Session::ensure_buffers_unlocked (ChanCount howmany)
{
if (_required_thread_buffers >= howmany) {
return;
}
Glib::Threads::Mutex::Lock lm (AudioEngine::instance()->process_lock ());
ensure_buffers (howmany);
}
/** Ensures that all buffers (scratch, send, silent, etc) are allocated for
* the given count with the current block size.
* Must be called with the process-lock held
*/
void
Session::ensure_buffers (ChanCount howmany)
{
BufferManager::ensure_buffers (howmany, bounce_processing() ? bounce_chunk_size : 0);
size_t want_size = bounce_processing() ? bounce_chunk_size : 0;
if (howmany.n_total () == 0) {
howmany = _required_thread_buffers;
}
if (_required_thread_buffers >= howmany && _required_thread_buffersize == want_size) {
return;
}
_required_thread_buffers = ChanCount::max (_required_thread_buffers, howmany);
_required_thread_buffersize = want_size;
BufferManager::ensure_buffers (_required_thread_buffers, _required_thread_buffersize);
}
uint32_t