aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/ALc.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2016-05-14 23:43:40 -0700
committerChris Robinson <[email protected]>2016-05-14 23:43:40 -0700
commitb3338d25f6d4fd02935ac83d0d3f227b145307d1 (patch)
treecb3b14deec8f1298121d61d1fbd2c57b6610dd41 /Alc/ALc.c
parent0f7e4993237e83ddc53a958a6369924da53c4a99 (diff)
Provide asynchronous property updates for sources
This necessitates a change in how source updates are handled. Rather than just being able to update sources when a dependent object state is changed (e.g. a listener gain change), now all source updates must be proactively provided. Consequently, apps that do not utilize any deferring (AL_SOFT_defer_updates or alcSuspendContext/alcProcessContext) may utilize more CPU since it'll be filling out more update containers for the mixer thread to use. The upside is that there's less blocking between the app's calling thread and the mixer thread, particularly for vectors and other multi-value properties (filters and sends). Deferring behavior when used is also improved, since updates that shouldn't be applied yet are simply not provided. And when they are provided, the mixer doesn't have to ignore them, meaning the actual deferring of a context doesn't have to synchrnously force an update -- the process call will send any pending updates, which the mixer will apply even if another deferral occurs before the mixer runs, because it'll still be there waiting on the next mixer invocation. There is one slight bug introduced by this commit. When a listener change is made, or changes to multiple sources while updates are being deferred, it is possible for the mixer to run while the sources are prepping their updates, causing some of the source updates to be seen before the other. This will be fixed in short order.
Diffstat (limited to 'Alc/ALc.c')
-rw-r--r--Alc/ALc.c65
1 files changed, 17 insertions, 48 deletions
diff --git a/Alc/ALc.c b/Alc/ALc.c
index 47aa0f04..e5c18d8c 100644
--- a/Alc/ALc.c
+++ b/Alc/ALc.c
@@ -1558,22 +1558,7 @@ extern inline ALint GetChannelIndex(const enum Channel names[MAX_OUTPUT_CHANNELS
*/
void ALCcontext_DeferUpdates(ALCcontext *context)
{
- ALCdevice *device = context->Device;
- FPUCtl oldMode;
-
- SetMixerFPUMode(&oldMode);
-
- V0(device->Backend,lock)();
- if(!context->DeferUpdates)
- {
- context->DeferUpdates = AL_TRUE;
-
- /* Make sure all pending updates are performed */
- UpdateContextSources(context);
- }
- V0(device->Backend,unlock)();
-
- RestoreFPUMode(&oldMode);
+ ATOMIC_STORE(&context->DeferUpdates, AL_TRUE);
}
/* ALCcontext_ProcessUpdates
@@ -1584,14 +1569,15 @@ void ALCcontext_ProcessUpdates(ALCcontext *context)
{
ALCdevice *device = context->Device;
- V0(device->Backend,lock)();
- if(context->DeferUpdates)
+ ReadLock(&context->PropLock);
+ if(ATOMIC_EXCHANGE(ALenum, &context->DeferUpdates, AL_FALSE))
{
ALsizei pos;
- context->DeferUpdates = AL_FALSE;
+ UpdateListenerProps(context);
LockUIntMapRead(&context->SourceMap);
+ V0(device->Backend,lock)();
for(pos = 0;pos < context->SourceMap.size;pos++)
{
ALsource *Source = context->SourceMap.array[pos].value;
@@ -1610,9 +1596,11 @@ void ALCcontext_ProcessUpdates(ALCcontext *context)
if(new_state)
SetSourceState(Source, context, new_state);
}
+ V0(device->Backend,unlock)();
UnlockUIntMapRead(&context->SourceMap);
+ UpdateAllSourceProps(context);
}
- V0(device->Backend,unlock)();
+ ReadUnlock(&context->PropLock);
}
@@ -2052,7 +2040,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
}
SetMixerFPUMode(&oldMode);
- V0(device->Backend,lock)();
if(device->DefaultSlot)
{
ALeffectslot *slot = device->DefaultSlot;
@@ -2062,7 +2049,6 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
state->OutChannels = device->Dry.NumChannels;
if(V(state,deviceUpdate)(device) == AL_FALSE)
{
- V0(device->Backend,unlock)();
RestoreFPUMode(&oldMode);
return ALC_INVALID_DEVICE;
}
@@ -2074,6 +2060,7 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
{
ALsizei pos;
+ ReadLock(&context->PropLock);
LockUIntMapRead(&context->EffectSlotMap);
for(pos = 0;pos < context->EffectSlotMap.size;pos++)
{
@@ -2085,10 +2072,11 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
if(V(state,deviceUpdate)(device) == AL_FALSE)
{
UnlockUIntMapRead(&context->EffectSlotMap);
- V0(device->Backend,unlock)();
+ ReadUnlock(&context->PropLock);
RestoreFPUMode(&oldMode);
return ALC_INVALID_DEVICE;
}
+
UpdateEffectSlotProps(slot, AL_FALSE);
}
UnlockUIntMapRead(&context->EffectSlotMap);
@@ -2105,38 +2093,19 @@ static ALCenum UpdateDeviceParams(ALCdevice *device, const ALCint *attrList)
source->Send[s].Slot = NULL;
source->Send[s].Gain = 1.0f;
source->Send[s].GainHF = 1.0f;
+ source->Send[s].HFReference = LOWPASSFREQREF;
+ source->Send[s].GainLF = 1.0f;
+ source->Send[s].LFReference = HIGHPASSFREQREF;
s++;
}
- ATOMIC_STORE(&source->NeedsUpdate, AL_TRUE);
}
UnlockUIntMapRead(&context->SourceMap);
- for(pos = 0;pos < context->VoiceCount;pos++)
- {
- ALvoice *voice = &context->Voices[pos];
- ALsource *source = voice->Source;
- ALbufferlistitem *BufferListItem;
-
- if(!source)
- continue;
-
- BufferListItem = ATOMIC_LOAD(&source->queue);
- while(BufferListItem != NULL)
- {
- ALbuffer *buffer;
- if((buffer=BufferListItem->buffer) != NULL)
- {
- ATOMIC_STORE(&source->NeedsUpdate, AL_FALSE);
- voice->Update(voice, source, buffer, context);
- break;
- }
- BufferListItem = BufferListItem->next;
- }
- }
+ UpdateAllSourceProps(context);
+ ReadUnlock(&context->PropLock);
context = context->next;
}
- V0(device->Backend,unlock)();
RestoreFPUMode(&oldMode);
if(!(device->Flags&DEVICE_PAUSED))
@@ -2308,7 +2277,7 @@ static ALvoid InitContext(ALCcontext *Context)
Context->DopplerFactor = 1.0f;
Context->DopplerVelocity = 1.0f;
Context->SpeedOfSound = SPEEDOFSOUNDMETRESPERSEC;
- Context->DeferUpdates = AL_FALSE;
+ ATOMIC_INIT(&Context->DeferUpdates, AL_FALSE);
Context->ExtensionList = alExtList;
}