Skip to content

Commit

Permalink
Memory Optimization: allocate constant buffers only when push constan…
Browse files Browse the repository at this point in the history
…ts not enabled
  • Loading branch information
SRSaunders committed Nov 29, 2023
1 parent 18769ec commit ea6d698
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
30 changes: 17 additions & 13 deletions neo/renderer/RenderProgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,23 +638,27 @@ void idRenderProgManager::Init( nvrhi::IDevice* device )
bindingLayouts[BINDING_LAYOUT_EXPOSURE] = { device->createBindingLayout( exposureLayout ) };

// SRS - allocate static/volatile constant buffers after renderparm buffer sizes are defined for each binding layout type
// - allocate constant buffers only when needed, i.e. when push constants are not enabled for binding layout type
for( int i = 0; i < NUM_BINDING_LAYOUTS; i++ )
{
nvrhi::BufferDesc constantBufferDesc;

// SRS - allocate static constant buffer for specific binding layouts, otherwise volatile
if( layoutTypeAttributes[i].cbStatic )
{
constantBufferDesc = nvrhi::utils::CreateStaticConstantBufferDesc( layoutTypeAttributes[i].rpBufSize, va( "RenderParams_%d", i ) );
constantBufferDesc.initialState = nvrhi::ResourceStates::ConstantBuffer;
constantBufferDesc.keepInitialState = true;
}
else
if( !renderProgManager.layoutTypeAttributes[i].pcEnabled )
{
constantBufferDesc = nvrhi::utils::CreateVolatileConstantBufferDesc( layoutTypeAttributes[i].rpBufSize, va( "RenderParams_%d", i ), 8192 );
}
nvrhi::BufferDesc constantBufferDesc;

constantBuffer[i] = device->createBuffer( constantBufferDesc );
// SRS - allocate static constant buffer for specific binding layouts, otherwise volatile
if( layoutTypeAttributes[i].cbStatic )
{
constantBufferDesc = nvrhi::utils::CreateStaticConstantBufferDesc( layoutTypeAttributes[i].rpBufSize, va( "RenderParams_%d", i ) );
constantBufferDesc.initialState = nvrhi::ResourceStates::ConstantBuffer;
constantBufferDesc.keepInitialState = true;
}
else
{
constantBufferDesc = nvrhi::utils::CreateVolatileConstantBufferDesc( layoutTypeAttributes[i].rpBufSize, va( "RenderParams_%d", i ), 8192 );
}

constantBuffer[i] = device->createBuffer( constantBufferDesc );
}
}

// SRS - added support for runtime configuration of push constants
Expand Down
1 change: 1 addition & 0 deletions neo/renderer/RenderProgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ enum renderParmSubSet_t
// - rpNominalSets **must** be <= sizeof( rpNominalSet ) -> currently 16 entries or 256 bytes
// - rpMaximalSets **must** be <= sizeof( rpMaximalSet ) -> currently 64 entries or 1024 bytes
// - The order/contents of all subsets must match the renderParmSet*.inc.hlsl include files
// - Each and every Binding Layout type must be a member of one and only one renderparm subset

const idList<renderParm_t, TAG_RENDER> rpMinimalSet0 = { RENDERPARM_LOCALVIEWORIGIN, RENDERPARM_VERTEXCOLOR_MODULATE, RENDERPARM_VERTEXCOLOR_ADD, RENDERPARM_COLOR, RENDERPARM_MVPMATRIX_X, RENDERPARM_MVPMATRIX_Y, RENDERPARM_MVPMATRIX_Z, RENDERPARM_MVPMATRIX_W };

Expand Down

0 comments on commit ea6d698

Please sign in to comment.