Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Divide large constant buffer into subsets and implement push constants for performance #855

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
428fc40
Divide large constant buffer into subsets and implement push constant…
SRSaunders Oct 4, 2023
01bd50b
Refactor renderParmSets to fit within D3D12 root constant limit and r…
SRSaunders Oct 9, 2023
988d3ed
Clamp max push constant size to nvrhi::c_MaxPushConstantSize
SRSaunders Oct 10, 2023
3b7f5c7
Define r_useDX12PushConstants cvar (default off) to control DX12 push…
SRSaunders Oct 10, 2023
9151190
Fix uniforms change detection and add r_useVulkanPushConstants cvar (…
SRSaunders Oct 21, 2023
4164245
Simplify change detection logic that controls writing of constant buf…
SRSaunders Oct 24, 2023
012d7bc
Memory Optimization: allocate constant buffers only when push constan…
SRSaunders Nov 29, 2023
ff2aa9f
Fix ImmediateMode so debug tools work properly with push constants
SRSaunders Dec 20, 2023
df6c995
Move Vulkan maxPushConstantSize to CreateDeviceAndSwapChain() to matc…
SRSaunders Jan 25, 2024
a4fc711
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Feb 5, 2024
89bff20
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Feb 25, 2024
629bf04
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Apr 2, 2024
233c797
Set ShaderMake retryCount=20 to handle macOS/linux shell failures dur…
SRSaunders Apr 3, 2024
5bf1c8f
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Jun 23, 2024
d8cd1af
Merge branch 'RobertBeckebans:master' into rpsubsets-and-pc
SRSaunders Jun 23, 2024
3d29301
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Aug 5, 2024
9951dcb
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Aug 18, 2024
fadc9a6
Refactor renderparm subsets and layout types for compatibility with P…
SRSaunders Aug 19, 2024
9ca013b
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Nov 2, 2024
370d969
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Nov 27, 2024
ae4da72
Add new SMAA binding layout types to push constant subset mapping
SRSaunders Nov 27, 2024
8197bbb
Merge branch 'master'
SRSaunders Nov 27, 2024
0d43c3d
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Dec 8, 2024
aa94bfd
Add bumpyenvironment2 shader and octahedron cube layout types to push…
SRSaunders Dec 9, 2024
e0726cc
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Dec 26, 2024
00e4a59
Merge branch 'master' into rpsubsets-and-pc
SRSaunders Jan 19, 2025
e01f780
Restore logic for committing constant buffers on binding layout change
SRSaunders Jan 19, 2025
91e3a05
Work-around Vulkan GPU timeout errors by disabling PCs on x86 for sel…
SRSaunders Jan 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions neo/compileshaders.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ function(compile_shaders)
--platform=SPIRV
--binaryBlob
--outputExt=.bin
--retryCount=20 # SRS - allow 20 retries to recover from any macOS/linux command shell failures during multi-threaded compilation
-I ${SHADER_INCLUDE_DIR}
-D SPIRV
${CFLAGS}
Expand Down
6 changes: 4 additions & 2 deletions neo/renderer/ImmediateMode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void fhImmediateMode::End()
vertexBuffer.Update( drawVerts, drawVertsUsed * sizeof( idDrawVert ), 0, false, commandList );
indexBuffer.Update( lineIndices, drawVertsUsed * sizeof( triIndex_t ), 0, false, commandList );

renderProgManager.CommitConstantBuffer( commandList, true );
renderProgManager.CommitConstantBuffer( commandList, false );

int bindingLayoutType = renderProgManager.BindingLayoutType();

Expand All @@ -147,7 +147,7 @@ void fhImmediateMode::End()

for( int i = 0; i < layouts->Num(); i++ )
{
if( !tr.backend.currentBindingSets[i] || *tr.backend.currentBindingSets[i]->getDesc() != tr.backend.pendingBindingSetDescs[bindingLayoutType][i] )
if( !tr.backend.currentBindingSets[i] || *tr.backend.currentBindingSets[i]->getDesc() != tr.backend.pendingBindingSetDescs[bindingLayoutType][i] || bindingLayoutType != tr.backend.prevBindingLayoutType )
{
tr.backend.currentBindingSets[i] = tr.backend.bindingCache.GetOrCreateBindingSet( tr.backend.pendingBindingSetDescs[bindingLayoutType][i], ( *layouts )[i] );
}
Expand Down Expand Up @@ -182,6 +182,8 @@ void fhImmediateMode::End()
state.viewport.addScissorRect( nvrhi::Rect( viewport ) );

commandList->setGraphicsState( state );

renderProgManager.CommitPushConstants( commandList, bindingLayoutType );
}

nvrhi::DrawArguments args;
Expand Down
9 changes: 6 additions & 3 deletions neo/renderer/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2174,12 +2174,15 @@ void idMaterial::ParseStage( idLexer& src, const textureRepeat_t trpDefault )
ss->conditionRegister = ParseExpression( src );
continue;
}

auto usePushConstants = renderProgManager.layoutTypeAttributes[BINDING_LAYOUT_POST_PROCESS_INGAME].pcEnabled ? "1" : "0";

if( !token.Icmp( "program" ) )
{
if( src.ReadTokenOnLine( &token ) )
{
#if !defined( DMAP )
idList<shaderMacro_t> macros = { { "USE_GPU_SKINNING", "0" } };
idList<shaderMacro_t> macros = { { "USE_GPU_SKINNING", "0" }, { "USE_PUSH_CONSTANTS", usePushConstants } };
newStage.vertexProgram = renderProgManager.FindShader( token.c_str(), SHADER_STAGE_VERTEX, "", macros, false );
newStage.fragmentProgram = renderProgManager.FindShader( token.c_str(), SHADER_STAGE_FRAGMENT, "", macros, false );
#endif
Expand All @@ -2191,7 +2194,7 @@ void idMaterial::ParseStage( idLexer& src, const textureRepeat_t trpDefault )
if( src.ReadTokenOnLine( &token ) )
{
#if !defined( DMAP )
idList<shaderMacro_t> macros = { { "USE_GPU_SKINNING", "0" } };
idList<shaderMacro_t> macros = { { "USE_GPU_SKINNING", "0" }, { "USE_PUSH_CONSTANTS", usePushConstants } };
newStage.fragmentProgram = renderProgManager.FindShader( token.c_str(), SHADER_STAGE_FRAGMENT, "", macros, false );
#endif
}
Expand All @@ -2202,7 +2205,7 @@ void idMaterial::ParseStage( idLexer& src, const textureRepeat_t trpDefault )
if( src.ReadTokenOnLine( &token ) )
{
#if !defined( DMAP )
idList<shaderMacro_t> macros = { { "USE_GPU_SKINNING", "0" } };
idList<shaderMacro_t> macros = { { "USE_GPU_SKINNING", "0" }, { "USE_PUSH_CONSTANTS", usePushConstants } };
newStage.vertexProgram = renderProgManager.FindShader( token.c_str(), SHADER_STAGE_VERTEX, "", macros, false );
#endif
}
Expand Down
8 changes: 2 additions & 6 deletions neo/renderer/NVRHI/BufferObject_NVRHI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,13 +729,9 @@ bool idUniformBuffer::AllocBufferObject( const void* data, int allocSize, buffer
// This buffer is a shader resource as opposed to a constant buffer due to
// constant buffers not being able to be sub-ranged.
nvrhi::BufferDesc bufferDesc;
//bufferDesc.initialState = nvrhi::ResourceStates::ConstantBuffer; // SRS - shouldn't this be initialized to CopyDest?
bufferDesc.initialState = nvrhi::ResourceStates::CopyDest;
bufferDesc.canHaveTypedViews = true;
bufferDesc.canHaveRawViews = true;
bufferDesc.byteSize = numBytes;
bufferDesc.structStride = sizeof( idVec4 );
bufferDesc.isConstantBuffer = true;
bufferDesc.structStride = sizeof( idVec4 ); // SRS - this defines a structured storage buffer vs. a constant buffer
bufferDesc.initialState = nvrhi::ResourceStates::Common;

if( usage == BU_DYNAMIC )
{
Expand Down
Loading