Set NVRHI upload buffer size to avoid Vulkan staging buffer fragmentation

(cherry picked from commit 3a55e9701a6f4ad5297d41e3486aeb4075972383)
This commit is contained in:
Stephen Saunders 2023-02-13 15:42:16 -05:00
parent 73df924ee2
commit 86a6e486d5
3 changed files with 37 additions and 5 deletions

View file

@ -40,6 +40,7 @@ idImageManager imageManager;
idImageManager* globalImages = &imageManager;
extern DeviceManager* deviceManager;
extern idCVar r_uploadBufferSizeMB;
idCVar preLoad_Images( "preLoad_Images", "1", CVAR_SYSTEM | CVAR_BOOL, "preload images during beginlevelload" );
@ -891,7 +892,14 @@ int idImageManager::LoadLevelImages( bool pacifier )
#if defined( USE_NVRHI )
if( !commandList )
{
commandList = deviceManager->GetDevice()->createCommandList();
nvrhi::CommandListParameters params = {};
if( deviceManager->GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN )
{
// SRS - set upload buffer size to avoid Vulkan staging buffer fragmentation
size_t maxBufferSize = ( size_t )( r_uploadBufferSizeMB.GetInteger() * 1024 * 1024 );
params.setUploadChunkSize( maxBufferSize );
}
commandList = deviceManager->GetDevice()->createCommandList( params );
}
common->UpdateLevelLoadPacifier();
@ -1017,7 +1025,14 @@ void idImageManager::LoadDeferredImages( nvrhi::ICommandList* _commandList )
{
if( !commandList )
{
commandList = deviceManager->GetDevice()->createCommandList();
nvrhi::CommandListParameters params = {};
if( deviceManager->GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN )
{
// SRS - set upload buffer size to avoid Vulkan staging buffer fragmentation
size_t maxBufferSize = ( size_t )( r_uploadBufferSizeMB.GetInteger() * 1024 * 1024 );
params.setUploadChunkSize( maxBufferSize );
}
commandList = deviceManager->GetDevice()->createCommandList( params );
}
nvrhi::ICommandList* thisCmdList = _commandList;

View file

@ -38,6 +38,7 @@ If you have questions concerning this license or the applicable additional terms
#include <sys/DeviceManager.h>
extern DeviceManager* deviceManager;
extern idCVar r_uploadBufferSizeMB;
#endif
idCVar binaryLoadRenderModels( "binaryLoadRenderModels", "1", 0, "enable binary load/write of render models" );
@ -245,7 +246,14 @@ void idRenderModelManagerLocal::Init()
#if defined( USE_NVRHI )
if( !commandList )
{
commandList = deviceManager->GetDevice()->createCommandList();
nvrhi::CommandListParameters params = {};
if( deviceManager->GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN )
{
// SRS - set upload buffer size to avoid Vulkan staging buffer fragmentation
size_t maxBufferSize = ( size_t )( r_uploadBufferSizeMB.GetInteger() * 1024 * 1024 );
params.setUploadChunkSize( maxBufferSize );
}
commandList = deviceManager->GetDevice()->createCommandList( params );
}
#endif
@ -1513,4 +1521,4 @@ void idImportOptions::Init( const char* commandline, const char* ospath )
}
}
// RB end
// RB end

View file

@ -55,6 +55,8 @@ idCVar stereoRender_warpTargetFraction( "stereoRender_warpTargetFraction", "1.0"
idCVar r_showSwapBuffers( "r_showSwapBuffers", "0", CVAR_BOOL, "Show timings from GL_BlockingSwapBuffers" );
idCVar r_syncEveryFrame( "r_syncEveryFrame", "1", CVAR_BOOL, "Don't let the GPU buffer execution past swapbuffers" );
idCVar r_uploadBufferSizeMB( "r_uploadBufferSizeMB", "64", CVAR_INTEGER | CVAR_INIT, "Size of gpu upload buffer (Vulkan only)" );
// SRS - What is GLimp_SwapBuffers() used for? Disable for now
//void GLimp_SwapBuffers();
void RB_SetMVP( const idRenderMatrix& mvp );
@ -214,7 +216,14 @@ void idRenderBackend::Init()
if( !commandList )
{
commandList = deviceManager->GetDevice()->createCommandList();
nvrhi::CommandListParameters params = {};
if( deviceManager->GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN )
{
// SRS - set upload buffer size to avoid Vulkan staging buffer fragmentation
size_t maxBufferSize = ( size_t )( r_uploadBufferSizeMB.GetInteger() * 1024 * 1024 );
params.setUploadChunkSize( maxBufferSize );
}
commandList = deviceManager->GetDevice()->createCommandList( params );
}
// allocate the vertex array range or vertex objects