Staging: add a limit of how many commands to stage

Although staging commands can be a good idea from performance pov, it
also means that we are increasing the size of the command buffer,
until the queue submission is set (in most drivers).

For example, when computing the Interactions, staged command buffers
can be easily greater that 15k. This could be a problem with
low-memory devices, like rpi4.

This patch adds a new variable to configure the maximum size of staged
commands. When that limit is reached a Flush is done (similar to the
existing limit on the UploadBufferSize).
This commit is contained in:
Alejandro Piñeiro 2021-02-22 14:04:46 +01:00
parent 6736b288e5
commit 23f27816ad
2 changed files with 13 additions and 0 deletions

View file

@ -34,6 +34,7 @@ If you have questions concerning this license or the applicable additional terms
#include "Staging_VK.h"
idCVar r_vkUploadBufferSizeMB( "r_vkUploadBufferSizeMB", "64", CVAR_INTEGER | CVAR_INIT, "Size of gpu upload buffer." );
idCVar r_vkStagingMaxCommands( "r_vkStagingMaxCommands", "-1", CVAR_INTEGER | CVAR_INIT, "Maximum amount of commands staged (-1 for no limit)" );
/*
===========================================================================
@ -182,6 +183,12 @@ byte* idVulkanStagingManager::Stage( const int size, const int alignment, VkComm
Flush();
}
int maxCommands = r_vkStagingMaxCommands.GetInteger();
if ( ( maxCommands > 0 ) && ( stage->stagedCommands >= maxCommands) )
{
Flush();
}
stage = &buffers[ currentBuffer ];
if( stage->submitted )
{
@ -195,6 +202,8 @@ byte* idVulkanStagingManager::Stage( const int size, const int alignment, VkComm
byte* data = stage->data + stage->offset;
stage->offset += size;
stage->stagedCommands++;
return data;
}
@ -237,6 +246,7 @@ void idVulkanStagingManager::Flush()
vkQueueSubmit( vkcontext.graphicsQueue, 1, &submitInfo, stage.fence );
stage.submitted = true;
stage.stagedCommands = 0;
currentBuffer = ( currentBuffer + 1 ) % NUM_FRAME_DATA;
}
@ -256,6 +266,7 @@ void idVulkanStagingManager::Wait( stagingBuffer_t& stage )
ID_VK_CHECK( vkWaitForFences( vkcontext.device, 1, &stage.fence, VK_TRUE, UINT64_MAX ) );
ID_VK_CHECK( vkResetFences( vkcontext.device, 1, &stage.fence ) );
stage.stagedCommands = 0;
stage.offset = 0;
stage.submitted = false;

View file

@ -54,6 +54,8 @@ struct stagingBuffer_t
VkFence fence;
VkDeviceSize offset;
byte* data;
int stagedCommands;
};
class idVulkanStagingManager