Clean up NVRHI resources before Sys_Quit(), otherwise non-zero exit code (destructors too late)

This commit is contained in:
Stephen Saunders 2022-10-27 14:52:08 -04:00
parent dd69e30e40
commit 8219860378
9 changed files with 112 additions and 4 deletions

View file

@ -784,6 +784,9 @@ void idImageManager::Shutdown()
imageHash.Clear();
deferredImages.DeleteContents( true );
deferredImageHash.Clear();
#if defined( USE_NVRHI )
commandList = nullptr;
#endif
}
/*

View file

@ -67,6 +67,12 @@ void fhImmediateMode::Init( nvrhi::ICommandList* commandList )
InitBuffers( commandList );
}
void fhImmediateMode::Shutdown()
{
vertexBuffer.FreeBufferObject();
indexBuffer.FreeBufferObject();
}
void fhImmediateMode::ResetStats()
{
drawCallCount = 0;

View file

@ -73,6 +73,7 @@ public:
static void AddTrianglesFromPolygon( fhImmediateMode& im, const idVec3* xyz, int num );
static void Init( nvrhi::ICommandList* commandList );
static void Shutdown();
static void ResetStats();
static int DrawCallCount();
static int DrawCallVertexSize();

View file

@ -199,8 +199,32 @@ void idRenderBackend::Init()
void idRenderBackend::Shutdown()
{
delete ssaoPass;
// SRS - Clean up NVRHI resources before Sys_Quit(), otherwise non-zero exit code (destructors too late)
// Clear all cached pipeline data
tr.backend.ClearCaches();
// Delete all renderpass resources
commonPasses.Shutdown();
// Delete current binding sets
for( int i = 0; i < currentBindingSets.Num(); i++ )
{
currentBindingSets[i].Reset();
}
// Unload shaders, delete binding layouts, and unmap memory
renderProgManager.Shutdown();
// Delete renderlog command buffer and timer query resources
renderLog.Shutdown();
// Delete command list
commandList.Reset();
// Delete immediate mode buffer objects
fhImmediateMode::Shutdown();
#if defined( VULKAN_USE_PLATFORM_SDL )
VKimp_Shutdown();
#else

View file

@ -177,6 +177,40 @@ void CommonRenderPasses::Init( nvrhi::IDevice* device )
}
}
void CommonRenderPasses::Shutdown()
{
// SRS - Delete the pipelines referenced by the blit cache
for( auto& [key, pipeline] : m_BlitPsoCache )
{
pipeline.Reset();
}
// SRS - These assets have automatic resource management with overloaded = operator
m_RectVS = nullptr;
m_BlitPS = nullptr;
m_BlitArrayPS = nullptr;
m_SharpenPS = nullptr;
m_SharpenArrayPS = nullptr;
m_BlackTexture = nullptr;
m_GrayTexture = nullptr;
m_WhiteTexture = nullptr;
m_BlackTexture2DArray = nullptr;
m_WhiteTexture2DArray = nullptr;
m_BlackCubeMapArray = nullptr;
m_PointClampSampler = nullptr;
m_PointWrapSampler = nullptr;
m_LinearClampSampler = nullptr;
m_LinearBorderSampler = nullptr;
m_LinearClampCompareSampler = nullptr;
m_LinearWrapSampler = nullptr;
m_AnisotropicWrapSampler = nullptr;
m_AnisotropicClampEdgeSampler = nullptr;
m_BlitBindingLayout = nullptr;
}
void CommonRenderPasses::BlitTexture( nvrhi::ICommandList* commandList, const BlitParameters& params, BindingCache* bindingCache )
{
assert( commandList );

View file

@ -134,6 +134,7 @@ public:
CommonRenderPasses();
void Init( nvrhi::IDevice* device );
void Shutdown();
void BlitTexture( nvrhi::ICommandList* commandList, const BlitParameters& params, BindingCache* bindingCache = nullptr );
@ -141,4 +142,4 @@ public:
void BlitTexture( nvrhi::ICommandList* commandList, nvrhi::IFramebuffer* targetFramebuffer, nvrhi::ITexture* sourceTexture, BindingCache* bindingCache = nullptr );
};
#endif
#endif

View file

@ -332,6 +332,21 @@ void idRenderLog::Init()
#endif
}
void idRenderLog::Shutdown()
{
#if defined( USE_NVRHI )
if( commandList )
{
commandList.Reset();
}
for( int i = 0; i < MRB_TOTAL_QUERIES; i++ )
{
timerQueries[i].Reset();
}
#endif
}
void idRenderLog::StartFrame( nvrhi::ICommandList* _commandList )
{
#if defined( USE_NVRHI )
@ -537,4 +552,4 @@ void idRenderLog::CloseBlock()
{
PC_EndNamedEvent( commandList );
}
// RB end
// RB end

View file

@ -90,6 +90,7 @@ public:
idRenderLog();
void Init();
void Shutdown();
void StartFrame( nvrhi::ICommandList* _commandList );
void EndFrame();

View file

@ -769,6 +769,29 @@ idRenderProgManager::Shutdown()
void idRenderProgManager::Shutdown()
{
KillAllShaders();
#if defined( USE_NVRHI )
// SRS - Delete renderprogs builtin binding layouts
for( int i = 0; i < renderProgs.Num(); i++ )
{
for( int j = 0; j < renderProgs[i].bindingLayouts.Num(); j++ )
{
renderProgs[i].bindingLayouts[j].Reset();
}
}
// SRS - Delete binding layouts
for( int i = 0; i < bindingLayouts.Num(); i++ )
{
for( int j = 0; j < bindingLayouts[i].Num(); j++ )
{
bindingLayouts[i][j].Reset();
}
}
// SRS - Unmap buffer memory using overloaded = operator
constantBuffer = nullptr;
#endif
}
/*
@ -1228,4 +1251,4 @@ void RpPrintState( uint64 stateBits )
{
printStencil( STENCIL_FACE_NUM, stateBits, mask, ref );
}
}
}