Allocators for audio system file cache (#1485)

* Reinstates an allocator for FileCacheManager

Replaces the allocator that was removed during redcode that is used for
loading banks.  Default schema for now to get things working again.

* Update path functions to AZ::IO::Path

Removes old PathUtil functions in favor of AZ::IO::Path apis.

* Update the audio allocator classes

Cleans up the audio allocator classes a bit.

* Addresses PR feedback

Updates some code to handle nullptr a bit better, and improve log
messages.

* Updates to audio CVars and address feedback

Per feedback, converted more of the audio cvars to AZ_CVAR, but not all
of them could be converted at this time.  Moved audio allocator
initialization to system component ctor/dtor to give RAII.  Updated
location of a PAL file.

* Updates the copyright of the file added in this PR

Merged copyright changes, so need to update new files.
This commit is contained in:
Eric Phister
2021-06-23 16:57:48 -05:00
committed by GitHub
parent 3d0093307f
commit 0a68f23ee0
20 changed files with 342 additions and 283 deletions
@@ -32,6 +32,12 @@ namespace Audio
CSoundCVars g_audioCVars;
CAudioLogger g_audioLogger;
AZ::EnvironmentVariable<int*> g_audioVerbosityVar;
namespace Platform
{
void InitializeAudioAllocators();
void ShutdownAudioAllocators();
}
} // namespace Audio
namespace AudioSystemGem
@@ -79,6 +85,16 @@ namespace AudioSystemGem
AZ_UNUSED(dependent);
}
AudioSystemGemSystemComponent::AudioSystemGemSystemComponent()
{
Audio::Platform::InitializeAudioAllocators();
}
AudioSystemGemSystemComponent::~AudioSystemGemSystemComponent()
{
Audio::Platform::ShutdownAudioAllocators();
}
void AudioSystemGemSystemComponent::Init()
{
m_loseFocusRequest.nFlags = Audio::eARF_PRIORITY_HIGH;
@@ -110,48 +126,30 @@ namespace AudioSystemGem
bool AudioSystemGemSystemComponent::Initialize(const SSystemInitParams* initParams)
{
using namespace Audio;
// When nullptr is passed, create a NullAudioSystem instead of the real thing.
if (!initParams)
{
return CreateNullAudioSystem();
}
Audio::g_audioCVars.RegisterVariables();
g_audioCVars.RegisterVariables();
#if !defined(AUDIO_RELEASE)
Audio::g_audioVerbosityVar = AZ::Environment::CreateVariable<int*>("AudioLogVerbosity");
Audio::g_audioVerbosityVar.Set(&Audio::g_audioCVars.m_nAudioLoggingOptions);
g_audioVerbosityVar = AZ::Environment::CreateVariable<int*>("AudioLogVerbosity");
g_audioVerbosityVar.Set(&g_audioCVars.m_nAudioLoggingOptions);
#endif // !AUDIO_RELEASE
bool success = false;
// initialize audio system memory pool
if (!AZ::AllocatorInstance<Audio::AudioSystemAllocator>::IsReady())
{
const size_t poolSize = Audio::g_audioCVars.m_nATLPoolSize << 10;
Audio::AudioSystemAllocator::Descriptor allocDesc;
// Generic Allocator:
allocDesc.m_allocationRecords = true;
allocDesc.m_heap.m_numFixedMemoryBlocks = 1;
allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0] = poolSize;
allocDesc.m_heap.m_fixedMemoryBlocks[0] = AZ::AllocatorInstance<AZ::OSAllocator>::Get().Allocate(
allocDesc.m_heap.m_fixedMemoryBlocksByteSize[0],
allocDesc.m_heap.m_memoryBlockAlignment
);
AZ::AllocatorInstance<Audio::AudioSystemAllocator>::Create(allocDesc);
}
if (CreateAudioSystem())
{
Audio::g_audioLogger.Log(Audio::eALT_ALWAYS, "AudioSystem created!");
g_audioLogger.Log(eALT_ALWAYS, "AudioSystem created!");
// Initialize the implementation module...
bool initImplSuccess = false;
Audio::Gem::AudioEngineGemRequestBus::BroadcastResult(initImplSuccess, &Audio::Gem::AudioEngineGemRequestBus::Events::Initialize);
Gem::AudioEngineGemRequestBus::BroadcastResult(initImplSuccess, &Gem::AudioEngineGemRequestBus::Events::Initialize);
if (initImplSuccess)
{
@@ -161,13 +159,13 @@ namespace AudioSystemGem
}
else
{
if (Audio::Gem::AudioEngineGemRequestBus::HasHandlers())
if (Gem::AudioEngineGemRequestBus::HasHandlers())
{
Audio::g_audioLogger.Log(Audio::eALT_ERROR, "The Audio Engine did not initialize correctly!");
g_audioLogger.Log(eALT_ERROR, "The Audio Engine did not initialize correctly!");
}
else
{
Audio::g_audioLogger.Log(Audio::eALT_WARNING, "Running without any AudioEngine!");
g_audioLogger.Log(eALT_WARNING, "Running without any AudioEngine!");
}
}
@@ -185,20 +183,16 @@ namespace AudioSystemGem
void AudioSystemGemSystemComponent::Release()
{
Audio::AudioSystemRequestBus::Broadcast(&Audio::AudioSystemRequestBus::Events::Release);
Audio::Gem::AudioEngineGemRequestBus::Broadcast(&Audio::Gem::AudioEngineGemRequestBus::Events::Release);
using namespace Audio;
AudioSystemRequestBus::Broadcast(&AudioSystemRequestBus::Events::Release);
Gem::AudioEngineGemRequestBus::Broadcast(&Gem::AudioEngineGemRequestBus::Events::Release);
// Delete the Audio System
// It should be the last object that is freed from the audio system memory pool before the allocator is destroyed.
m_audioSystem.reset();
if (AZ::AllocatorInstance<Audio::AudioSystemAllocator>::IsReady())
{
AZ::AllocatorInstance<Audio::AudioSystemAllocator>::Destroy();
}
Audio::g_audioVerbosityVar.Reset();
Audio::g_audioCVars.UnregisterVariables();
g_audioVerbosityVar.Reset();
g_audioCVars.UnregisterVariables();
GetISystem()->GetISystemEventDispatcher()->RemoveListener(this);
}