diff --git a/neo/idlib/containers/StaticList.h b/neo/idlib/containers/StaticList.h index 83e965f7..2689ab68 100644 --- a/neo/idlib/containers/StaticList.h +++ b/neo/idlib/containers/StaticList.h @@ -47,6 +47,7 @@ public: idStaticList(); idStaticList( const idStaticList& other ); + idStaticList( std::initializer_list initializerList ); ~idStaticList(); void Clear(); // marks the list as empty. does not deallocate or intialize data. @@ -114,6 +115,13 @@ ID_INLINE idStaticList::idStaticList( const idStaticList *this = other; } +template +ID_INLINE idStaticList::idStaticList( std::initializer_list initializerList ) +{ + SetNum( std::size( initializerList ) ); + std::copy( initializerList.begin(), initializerList.end(), list ); +} + /* ================ idStaticList::~idStaticList diff --git a/neo/renderer/BindingCache.cpp b/neo/renderer/BindingCache.cpp index 97e3bf81..2be869cc 100644 --- a/neo/renderer/BindingCache.cpp +++ b/neo/renderer/BindingCache.cpp @@ -39,7 +39,7 @@ nvrhi::BindingSetHandle BindingCache::GetCachedBindingSet( const nvrhi::BindingS nvrhi::BindingSetHandle BindingCache::GetOrCreateBindingSet( const nvrhi::BindingSetDesc& desc, nvrhi::IBindingLayout* layout ) { -#if 0 +#if 1 size_t hash = 0; nvrhi::hash_combine( hash, desc ); nvrhi::hash_combine( hash, layout ); diff --git a/neo/renderer/Image.h b/neo/renderer/Image.h index 90412d09..8063d5d8 100644 --- a/neo/renderer/Image.h +++ b/neo/renderer/Image.h @@ -239,7 +239,7 @@ typedef enum // RB end TD_R8F, // Stephen: Added for ambient occlusion render target. TD_LDR, // Stephen: Added for SRGB render target when tonemapping. - TD_DEPTH_STENCIL, + TD_DEPTH_STENCIL, // depth buffer and stencil buffer } textureUsage_t; typedef enum diff --git a/neo/renderer/NVRHI/Image_NVRHI.cpp b/neo/renderer/NVRHI/Image_NVRHI.cpp index 27d6d764..b1e33b59 100644 --- a/neo/renderer/NVRHI/Image_NVRHI.cpp +++ b/neo/renderer/NVRHI/Image_NVRHI.cpp @@ -257,7 +257,7 @@ void idImage::AllocImage() break; case FMT_ALPHA: - format = nvrhi::Format::R8_UNORM; + format = nvrhi::Format::R8_UINT; break; case FMT_L8A8: @@ -265,15 +265,15 @@ void idImage::AllocImage() break; case FMT_LUM8: - format = nvrhi::Format::R8_UNORM; + format = nvrhi::Format::R8_UINT; break; case FMT_INT8: - format = nvrhi::Format::R8_UNORM; + format = nvrhi::Format::R8_UINT; break; case FMT_R8: - format = nvrhi::Format::R8_UNORM; + format = nvrhi::Format::R8_UINT; break; case FMT_DXT1: diff --git a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp index 86bfbd32..69e967ee 100644 --- a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp @@ -571,6 +571,9 @@ void idRenderBackend::Init() slopeScaleBias = 0.f; depthBias = 0.f; + currentBindingSets.SetNum( currentBindingSets.Max() ); + pendingBindingSetDescs.SetNum( pendingBindingSetDescs.Max() ); + // RB: prepare ImGui system //ImGui_Init(); } @@ -586,7 +589,7 @@ void idRenderBackend::Shutdown() idRenderBackend::DrawElementsWithCounters ============= */ -void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf, nvrhi::BindingSetHandle bindingSetHandle ) +void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf ) { // Get vertex buffer const vertCacheHandle_t vbHandle = surf->ambientCache; @@ -612,7 +615,6 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf, nvrhi::B if( currentVertexOffset != vertOffset ) { currentVertexOffset = vertOffset; - //changeState = true; } if( currentVertexBuffer != ( nvrhi::IBuffer* )vertexBuffer->GetAPIObject() || !r_useStateCaching.GetBool() ) @@ -643,7 +645,6 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf, nvrhi::B if( currentIndexOffset != indexOffset ) { currentIndexOffset = indexOffset; - //changeState = true; } RENDERLOG_PRINTF( "Binding Buffers: %p:%i %p:%i\n", vertexBuffer, vertOffset, indexBuffer, indexOffset ); @@ -654,32 +655,25 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf, nvrhi::B changeState = true; } + GetCurrentBindingLayout(); + // RB: for debugging int program = renderProgManager.CurrentProgram(); int bindingLayoutType = renderProgManager.BindingLayoutType(); + auto& info = renderProgManager.GetProgramInfo( program ); - if( bindingSetHandle ) + for( int i = 0; i < info.bindingLayouts->Num(); i++ ) { - if( !currentBindingSet || *currentBindingSet->getDesc() != *bindingSetHandle->getDesc() ) + if( !currentBindingSets[i] || *currentBindingSets[i]->getDesc() != pendingBindingSetDescs[i] ) { - changeState = true; - } - } - else - { - nvrhi::BindingSetDesc bindingSetDesc; - GetCurrentBindingLayout( bindingSetDesc ); - - if( !currentBindingSet || *currentBindingSet->getDesc() != bindingSetDesc ) - { - currentBindingSet = bindingCache.GetOrCreateBindingSet( bindingSetDesc, renderProgManager.BindingLayout() ); + currentBindingSets[i] = bindingCache.GetOrCreateBindingSet( pendingBindingSetDescs[i], ( *info.bindingLayouts )[i] ); changeState = true; } } renderProgManager.CommitConstantBuffer( commandList ); - PipelineKey key{ glStateBits, renderProgManager.CurrentProgram(), viewDef->isMirror, depthBias, slopeScaleBias, currentFrameBuffer }; + PipelineKey key{ glStateBits, program, viewDef->isMirror, depthBias, slopeScaleBias, currentFrameBuffer }; auto pipeline = pipelineCache.GetOrCreatePipeline( key ); if( currentPipeline != pipeline ) @@ -691,7 +685,12 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf, nvrhi::B if( changeState ) { nvrhi::GraphicsState state; - state.bindings = { currentBindingSet }; + + for( int i = 0; i < info.bindingLayouts->Num(); i++ ) + { + state.bindings.push_back( currentBindingSets[i] ); + } + state.indexBuffer = { currentIndexBuffer, nvrhi::Format::R16_UINT, 0 }; state.vertexBuffers = { { currentVertexBuffer, 0, 0 } }; state.pipeline = pipeline; @@ -725,46 +724,68 @@ void idRenderBackend::DrawElementsWithCounters( const drawSurf_t* surf, nvrhi::B pc.c_drawIndexes += surf->numIndexes; } -void idRenderBackend::GetCurrentBindingLayout( nvrhi::BindingSetDesc& bindingSetDesc ) +void idRenderBackend::GetCurrentBindingLayout() { - if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_DEFAULT ) + auto& info = renderProgManager.GetProgramInfo( renderProgManager.CurrentProgram() ); + + int type = info.bindingLayoutType; + + if( type == BINDING_LAYOUT_DEFAULT ) { - bindingSetDesc - .addItem( nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_AnisotropicWrapSampler ) ); + pendingBindingSetDescs[0].bindings = + { + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ) + }; + + pendingBindingSetDescs[1].bindings = + { + nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_AnisotropicWrapSampler ) + }; } - else if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_GBUFFER ) + else if( type == BINDING_LAYOUT_GBUFFER ) { - bindingSetDesc - .addItem( nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) ); + pendingBindingSetDescs[0].bindings = + { + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) + }; } - else if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_AMBIENT_LIGHTING_IBL ) + else if( type == BINDING_LAYOUT_AMBIENT_LIGHTING_IBL ) { - bindingSetDesc - .addItem( nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 3, ( nvrhi::ITexture* )GetImageAt( 3 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 4, ( nvrhi::ITexture* )GetImageAt( 4 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 7, ( nvrhi::ITexture* )GetImageAt( 7 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 8, ( nvrhi::ITexture* )GetImageAt( 8 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 9, ( nvrhi::ITexture* )GetImageAt( 9 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 10, ( nvrhi::ITexture* )GetImageAt( 10 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_AnisotropicWrapSampler ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearClampSampler ) ); + pendingBindingSetDescs[0].bindings = + { + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 3, ( nvrhi::ITexture* )GetImageAt( 3 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 4, ( nvrhi::ITexture* )GetImageAt( 4 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 7, ( nvrhi::ITexture* )GetImageAt( 7 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 8, ( nvrhi::ITexture* )GetImageAt( 8 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 9, ( nvrhi::ITexture* )GetImageAt( 9 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 10, ( nvrhi::ITexture* )GetImageAt( 10 )->GetTextureID() ) + }; + + pendingBindingSetDescs[1].bindings = + { + nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_AnisotropicWrapSampler ), + nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearClampSampler ) + }; } - else if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_DRAW_AO ) + else if( type == BINDING_LAYOUT_DRAW_AO ) { - bindingSetDesc - .addItem( nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearClampSampler ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearClampSampler ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 2, commonPasses.m_PointWrapSampler ) ); // blue noise + pendingBindingSetDescs[0].bindings = + { + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ) + }; + + pendingBindingSetDescs[1].bindings = + { + nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_PointWrapSampler ) // blue noise + }; } /* else if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_DRAW_AO1 ) @@ -775,59 +796,89 @@ void idRenderBackend::GetCurrentBindingLayout( nvrhi::BindingSetDesc& bindingSet .addItem( nvrhi::BindingSetItem::Sampler( 0, ( nvrhi::ISampler* )GetImageAt( 0 )->GetSampler( samplerCache ) ) ); } */ - else if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_DRAW_INTERACTION ) + else if( type == BINDING_LAYOUT_DRAW_INTERACTION ) { - bindingSetDesc - .addItem( nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 3, ( nvrhi::ITexture* )GetImageAt( 3 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 4, ( nvrhi::ITexture* )GetImageAt( 4 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_AnisotropicWrapSampler ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearClampSampler ) ); + pendingBindingSetDescs[0].bindings = + { + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 3, ( nvrhi::ITexture* )GetImageAt( 3 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 4, ( nvrhi::ITexture* )GetImageAt( 4 )->GetTextureID() ) + }; + + pendingBindingSetDescs[1].bindings = + { + nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_AnisotropicWrapSampler ), + nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearClampSampler ) + }; } - else if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_DRAW_INTERACTION_SM ) + else if( type == BINDING_LAYOUT_DRAW_INTERACTION_SM ) { - bindingSetDesc - .addItem( nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 3, ( nvrhi::ITexture* )GetImageAt( 3 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 4, ( nvrhi::ITexture* )GetImageAt( 4 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 5, ( nvrhi::ITexture* )GetImageAt( 5 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 6, ( nvrhi::ITexture* )GetImageAt( 6 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_AnisotropicWrapSampler ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearClampSampler ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 2, commonPasses.m_LinearClampCompareSampler ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 3, commonPasses.m_PointWrapSampler ) ); // blue noise + pendingBindingSetDescs[0].bindings = + { + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 3, ( nvrhi::ITexture* )GetImageAt( 3 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 4, ( nvrhi::ITexture* )GetImageAt( 4 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 5, ( nvrhi::ITexture* )GetImageAt( 5 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 6, ( nvrhi::ITexture* )GetImageAt( 6 )->GetTextureID() ) + }; + + pendingBindingSetDescs[1].bindings = + { + nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_AnisotropicWrapSampler ), + nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearClampSampler ), + nvrhi::BindingSetItem::Sampler( 2, commonPasses.m_LinearClampCompareSampler ), + nvrhi::BindingSetItem::Sampler( 3, commonPasses.m_PointWrapSampler ) // blue noise + }; } - else if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_DRAW_FOG ) + else if( type == BINDING_LAYOUT_DRAW_FOG ) { - bindingSetDesc - .addItem( nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearClampSampler ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearClampSampler ) ); + pendingBindingSetDescs[0].bindings = + { + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) + }; + + pendingBindingSetDescs[1].bindings = + { + nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearClampSampler ), + nvrhi::BindingSetItem::Sampler( 1, commonPasses.m_LinearClampSampler ) + }; } - else if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_POST_PROCESS_CNM ) + else if( type == BINDING_LAYOUT_POST_PROCESS_CNM ) { - bindingSetDesc - .addItem( nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearClampSampler ) ); + pendingBindingSetDescs[0].bindings = + { + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 2, ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID() ) + }; + + pendingBindingSetDescs[1].bindings = + { + nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearClampSampler ) + }; } - else if( renderProgManager.BindingLayoutType() == BINDING_LAYOUT_NORMAL_CUBE ) + else if( type == BINDING_LAYOUT_NORMAL_CUBE ) { - bindingSetDesc - .addItem( nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) ) - .addItem( nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearWrapSampler ) ); + pendingBindingSetDescs[0].bindings = + { + nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ), + nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) + }; + + pendingBindingSetDescs[1].bindings = + { + nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_LinearWrapSampler ) + }; } else { @@ -883,7 +934,6 @@ void idRenderBackend::GL_EndRenderPass() deviceManager->GetDevice()->executeCommandList( commandList ); - bindingCache.Clear(); deviceManager->GetDevice()->runGarbageCollection(); commandList->open(); @@ -1798,17 +1848,6 @@ idImage* idRenderBackend::GetImageAt( int index ) return context.imageParms[index]; } -void idRenderBackend::BindProgram( nvrhi::ShaderHandle vShader, nvrhi::ShaderHandle fShader, nvrhi::InputLayoutHandle layout, nvrhi::BindingLayoutHandle bindingLayout ) -{ - vertexShader = vShader; - pixelShader = fShader; - inputLayout = layout; - currentBindingLayout = bindingLayout; - - // reset the pipeline. - currentPipeline = nullptr; -} - void idRenderBackend::ResetPipelineCache() { pipelineCache.Clear(); diff --git a/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp b/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp index 1a1c5e69..b078d160 100644 --- a/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp @@ -63,15 +63,6 @@ void idRenderProgManager::BindProgram( int index ) currentIndex = index; RENDERLOG_PRINTF( "Binding HLSL Program %s\n", renderProgs[index].name.c_str() ); - - renderProg_t& prog = renderProgs[index]; - - tr.backend.BindProgram( shaders[prog.vertexShaderIndex].handle, - shaders[prog.fragmentShaderIndex].handle, - prog.inputLayout, - prog.bindingLayout ); - - renderProgs[index].bindingLayout; } /* @@ -195,7 +186,7 @@ void idRenderProgManager::LoadProgram( const int programIndex, const int vertexS vertexLayoutDescs[prog.vertexLayout].Num(), shaders[prog.vertexShaderIndex].handle ); } - prog.bindingLayout = bindingLayouts[prog.bindingLayoutType]; + prog.bindingLayouts = bindingLayouts[prog.bindingLayoutType]; } void idRenderProgManager::LoadComputeProgram( const int programIndex, const int computeShaderIndex ) @@ -209,7 +200,7 @@ void idRenderProgManager::LoadComputeProgram( const int programIndex, const int vertexLayoutDescs[prog.vertexLayout].Num(), shaders[prog.vertexShaderIndex].handle ); } - prog.bindingLayout = bindingLayouts[prog.bindingLayoutType]; + prog.bindingLayouts = bindingLayouts[prog.bindingLayoutType]; } diff --git a/neo/renderer/PipelineCache.cpp b/neo/renderer/PipelineCache.cpp index fdddc32f..2d7b92fc 100644 --- a/neo/renderer/PipelineCache.cpp +++ b/neo/renderer/PipelineCache.cpp @@ -38,7 +38,10 @@ nvrhi::GraphicsPipelineHandle PipelineCache::GetOrCreatePipeline( const Pipeline programInfo_t progInfo = renderProgManager.GetProgramInfo( key.program ); pipelineDesc.setVertexShader( progInfo.vs ).setFragmentShader( progInfo.ps ); pipelineDesc.inputLayout = progInfo.inputLayout; - pipelineDesc.bindingLayouts = { progInfo.bindingLayout }; + for( int i = 0; i < progInfo.bindingLayouts->Num(); i++ ) + { + pipelineDesc.bindingLayouts.push_back( ( *progInfo.bindingLayouts )[i] ); + } pipelineDesc.primType = nvrhi::PrimitiveType::TriangleList; // Set up default state. diff --git a/neo/renderer/RenderBackend.cpp b/neo/renderer/RenderBackend.cpp index 22efe748..ef87936d 100644 --- a/neo/renderer/RenderBackend.cpp +++ b/neo/renderer/RenderBackend.cpp @@ -3629,11 +3629,6 @@ void idRenderBackend::ShadowMapPassFast( const drawSurf_t* drawSurfs, const view GL_SelectTexture( 0 ); globalImages->blackImage->Bind(); - nvrhi::BindingSetDesc bindingSetDesc; - GetCurrentBindingLayout( bindingSetDesc ); - - currentBindingSet = bindingCache.GetOrCreateBindingSet( bindingSetDesc, renderProgManager.BindingLayout() ); - uint64 glState = 0; // the actual stencil func will be set in the draw code, but we need to make sure it isn't @@ -3809,7 +3804,7 @@ void idRenderBackend::ShadowMapPassFast( const drawSurf_t* drawSurfs, const view assert( ( GL_GetCurrentState() & GLS_DEPTHFUNC_BITS ) == GLS_DEPTHFUNC_LESS ); // draw it solid - DrawElementsWithCounters( drawSurf, currentBindingSet ); + DrawElementsWithCounters( drawSurf ); renderLog.CloseBlock(); } @@ -4221,7 +4216,7 @@ void idRenderBackend::DrawInteractions( const viewDef_t* _viewDef ) // go back from light view to default camera view ResetViewportAndScissorToDefaultCamera( _viewDef ); - GL_EndRenderPass(); + //GL_EndRenderPass(); if( vLight->localInteractions != NULL ) { renderLog.OpenBlock( "Local Light Interactions", colorPurple ); @@ -6479,14 +6474,14 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste //------------------------------------------------- AmbientPass( drawSurfs, numDrawSurfs, false ); - GL_EndRenderPass(); + //GL_EndRenderPass(); //------------------------------------------------- // main light renderer //------------------------------------------------- DrawInteractions( _viewDef ); - GL_EndRenderPass(); + //GL_EndRenderPass(); //------------------------------------------------- // capture the depth for the motion blur before rendering any post process surfaces that may contribute to the depth @@ -6524,7 +6519,7 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste renderLog.CloseMainBlock(); } - GL_EndRenderPass(); + //GL_EndRenderPass(); //------------------------------------------------- // use direct light and emissive light contributions to add indirect screen space light @@ -6590,7 +6585,7 @@ void idRenderBackend::DrawViewInternal( const viewDef_t* _viewDef, const int ste renderLog.CloseMainBlock(); } - GL_EndRenderPass(); + //GL_EndRenderPass(); //------------------------------------------------- // render debug tools diff --git a/neo/renderer/RenderBackend.h b/neo/renderer/RenderBackend.h index 67241e4b..d18b0ad7 100644 --- a/neo/renderer/RenderBackend.h +++ b/neo/renderer/RenderBackend.h @@ -289,8 +289,8 @@ public: private: void DrawFlickerBox(); - void DrawElementsWithCounters( const drawSurf_t* surf, nvrhi::BindingSetHandle bindingSetHandle = nullptr ); - void GetCurrentBindingLayout( nvrhi::BindingSetDesc& bindingSetDesc ); + void DrawElementsWithCounters( const drawSurf_t* surf ); + void GetCurrentBindingLayout(); void DrawStencilShadowPass( const drawSurf_t* drawSurf, const bool renderZPass ); void SetColorMappings(); @@ -509,7 +509,8 @@ private: uint currentVertexOffset; nvrhi::BufferHandle currentIndexBuffer; uint currentIndexOffset; - nvrhi::BindingSetHandle currentBindingSet; + idStaticList currentBindingSets; + idStaticList pendingBindingSetDescs; nvrhi::BindingLayoutHandle currentBindingLayout; nvrhi::GraphicsPipelineHandle currentPipeline; nvrhi::RenderState currentRenderState; @@ -536,7 +537,6 @@ private: public: - void BindProgram( nvrhi::ShaderHandle vShader, nvrhi::ShaderHandle fShader, nvrhi::InputLayoutHandle layout, nvrhi::BindingLayoutHandle bindingLayout ); void ResetPipelineCache(); void SetCurrentImage( idImage* image ); diff --git a/neo/renderer/RenderProgs.cpp b/neo/renderer/RenderProgs.cpp index 4c6f2c20..30440972 100644 --- a/neo/renderer/RenderProgs.cpp +++ b/neo/renderer/RenderProgs.cpp @@ -45,7 +45,7 @@ If you have questions concerning this license or the applicable additional terms void CreateVertexDescriptions(); - void CreateDescriptorPools( VkDescriptorPool( &pools )[ NUM_FRAME_DATA ] ); + void CreateDescriptorPools( VkDescriptorPool( &pools )[NUM_FRAME_DATA] ); #endif @@ -174,10 +174,14 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) auto defaultLayoutDesc = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) - .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) - .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ); + .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ); - bindingLayouts[BINDING_LAYOUT_DEFAULT] = device->createBindingLayout( defaultLayoutDesc ); + auto samplerOneLayoutDesc = nvrhi::BindingLayoutDesc() + .setVisibility( nvrhi::ShaderType::Pixel ) + .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ); + auto samplerOneBindingLayout = device->createBindingLayout( samplerOneLayoutDesc ); + + bindingLayouts[BINDING_LAYOUT_DEFAULT] = { device->createBindingLayout( defaultLayoutDesc ), samplerOneBindingLayout }; auto ambientIblLayoutDesc = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) @@ -190,37 +194,37 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 7 ) ) // irradiance cube map .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 8 ) ) // radiance cube map 1 .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 9 ) ) // radiance cube map 2 - .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 10 ) ) // radiance cube map 3 - .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ) // (Wrap) Anisotropic sampler: normal sampler & specular sampler - .addItem( nvrhi::BindingLayoutItem::Sampler( 1 ) ); // (Clamp) Linear sampler: brdf lut sampler & ssao sampler + .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 10 ) ); // radiance cube map 3 - bindingLayouts[BINDING_LAYOUT_AMBIENT_LIGHTING_IBL] = device->createBindingLayout( ambientIblLayoutDesc ); + auto samplerTwoBindingLayoutDesc = nvrhi::BindingLayoutDesc() + .setVisibility( nvrhi::ShaderType::Pixel ) + .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ) // (Wrap) Anisotropic sampler: normal sampler & specular sampler + .addItem( nvrhi::BindingLayoutItem::Sampler( 1 ) ); // (Clamp) Linear sampler: brdf lut sampler & ssao sampler + auto samplerTwoBindingLayout = device->createBindingLayout( samplerTwoBindingLayoutDesc ); + + bindingLayouts[BINDING_LAYOUT_AMBIENT_LIGHTING_IBL] = { device->createBindingLayout( ambientIblLayoutDesc ), samplerTwoBindingLayout }; auto blitLayoutDesc = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ); // blit constants - bindingLayouts[BINDING_LAYOUT_BLIT] = device->createBindingLayout( blitLayoutDesc ); + bindingLayouts[BINDING_LAYOUT_BLIT] = { device->createBindingLayout( blitLayoutDesc ) }; auto aoLayoutDesc = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ) - .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 2 ) ) - .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ) - .addItem( nvrhi::BindingLayoutItem::Sampler( 1 ) ) - .addItem( nvrhi::BindingLayoutItem::Sampler( 2 ) ); + .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 2 ) ); - bindingLayouts[BINDING_LAYOUT_DRAW_AO] = device->createBindingLayout( aoLayoutDesc ); + bindingLayouts[BINDING_LAYOUT_DRAW_AO] = { device->createBindingLayout( aoLayoutDesc ), samplerOneBindingLayout }; auto aoLayoutDesc2 = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) - .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) - .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ); + .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ); - bindingLayouts[BINDING_LAYOUT_DRAW_AO1] = device->createBindingLayout( aoLayoutDesc2 ); + bindingLayouts[BINDING_LAYOUT_DRAW_AO1] = { device->createBindingLayout( aoLayoutDesc2 ), samplerOneBindingLayout }; auto interactionBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) @@ -229,11 +233,9 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ) // specular .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 2 ) ) // base color .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 3 ) ) // light falloff - .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 4 ) ) // light projection - .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ) // Linear wrap sampler for the normal/specular/color - .addItem( nvrhi::BindingLayoutItem::Sampler( 1 ) ); // Sampler for the light falloff/projection + .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 4 ) ); // light projection - bindingLayouts[BINDING_LAYOUT_DRAW_INTERACTION] = device->createBindingLayout( interactionBindingLayout ); + bindingLayouts[BINDING_LAYOUT_DRAW_INTERACTION] = { device->createBindingLayout( interactionBindingLayout ), samplerTwoBindingLayout }; auto interactionSmBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) @@ -244,42 +246,42 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 3 ) ) // light falloff .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 4 ) ) // light projection .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 5 ) ) // shadow map array - .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 6 ) ) // jitter - .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ) // material - .addItem( nvrhi::BindingLayoutItem::Sampler( 1 ) ) // lighting - .addItem( nvrhi::BindingLayoutItem::Sampler( 2 ) ) // shadow compare - .addItem( nvrhi::BindingLayoutItem::Sampler( 3 ) ); // blue noise for shadow jitter + .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 6 ) ); // jitter - bindingLayouts[BINDING_LAYOUT_DRAW_INTERACTION_SM] = device->createBindingLayout( interactionSmBindingLayout ); + auto samplerFourBindingLayoutDesc = nvrhi::BindingLayoutDesc() + .setVisibility( nvrhi::ShaderType::Pixel ) + .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ) // material + .addItem( nvrhi::BindingLayoutItem::Sampler( 1 ) ) // lighting + .addItem( nvrhi::BindingLayoutItem::Sampler( 2 ) ) // shadow compare + .addItem( nvrhi::BindingLayoutItem::Sampler( 3 ) ); // blue noise for shadow jitter + auto samplerFourBindingLayout = device->createBindingLayout( samplerFourBindingLayoutDesc ); + + bindingLayouts[BINDING_LAYOUT_DRAW_INTERACTION_SM] = { device->createBindingLayout( interactionSmBindingLayout ), samplerFourBindingLayout }; auto fogBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) - .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ) - .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ) - .addItem( nvrhi::BindingLayoutItem::Sampler( 1 ) ); + .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ); - bindingLayouts[BINDING_LAYOUT_DRAW_FOG] = device->createBindingLayout( fogBindingLayout ); + bindingLayouts[BINDING_LAYOUT_DRAW_FOG] = { device->createBindingLayout( fogBindingLayout ), samplerTwoBindingLayout }; auto ppFxBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) // current render .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ) // normal map - .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 2 ) ) // mask - .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ); // Linear sampler + .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 2 ) ); // mask - bindingLayouts[BINDING_LAYOUT_POST_PROCESS_CNM] = device->createBindingLayout( ppFxBindingLayout ); + bindingLayouts[BINDING_LAYOUT_POST_PROCESS_CNM] = { device->createBindingLayout( ppFxBindingLayout ), samplerOneBindingLayout }; auto normalCubeBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) // cube map - .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ) // normal map - .addItem( nvrhi::BindingLayoutItem::Sampler( 0 ) ); // Linear sampler + .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ); // normal map - bindingLayouts[BINDING_LAYOUT_NORMAL_CUBE] = device->createBindingLayout( normalCubeBindingLayout ); + bindingLayouts[BINDING_LAYOUT_NORMAL_CUBE] = { device->createBindingLayout( normalCubeBindingLayout ), samplerOneBindingLayout }; nvrhi::BindingLayoutDesc tonemapLayout; tonemapLayout.visibility = nvrhi::ShaderType::Pixel; @@ -291,7 +293,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) nvrhi::BindingLayoutItem::Texture_SRV( 2 ), nvrhi::BindingLayoutItem::Sampler( 0 ) }; - bindingLayouts[BINDING_LAYOUT_TONEMAP] = device->createBindingLayout( tonemapLayout ); + bindingLayouts[BINDING_LAYOUT_TONEMAP] = { device->createBindingLayout( tonemapLayout ) }; nvrhi::BindingLayoutDesc histogramLayout; histogramLayout.visibility = nvrhi::ShaderType::Compute; @@ -301,7 +303,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) nvrhi::BindingLayoutItem::Texture_SRV( 0 ), nvrhi::BindingLayoutItem::TypedBuffer_UAV( 0 ) }; - bindingLayouts[BINDING_LAYOUT_HISTOGRAM] = device->createBindingLayout( histogramLayout ); + bindingLayouts[BINDING_LAYOUT_HISTOGRAM] = { device->createBindingLayout( histogramLayout ) }; nvrhi::BindingLayoutDesc exposureLayout; exposureLayout.visibility = nvrhi::ShaderType::Compute; @@ -311,7 +313,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) nvrhi::BindingLayoutItem::TypedBuffer_SRV( 0 ), nvrhi::BindingLayoutItem::TypedBuffer_UAV( 0 ) }; - bindingLayouts[BINDING_LAYOUT_EXPOSURE] = device->createBindingLayout( exposureLayout ); + bindingLayouts[BINDING_LAYOUT_EXPOSURE] = { device->createBindingLayout( exposureLayout ) }; // RB: added checks for GPU skinning struct builtinShaders_t @@ -324,6 +326,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) rpStage_t stages; vertexLayoutType_t layout; bindingLayoutType_t bindingLayout; + bindingLayoutType_t bindingLayout2; } builtins[] = { { BUILTIN_GUI, "builtin/gui", "", {}, false, SHADER_STAGE_DEFAULT, LAYOUT_DRAW_VERT, BINDING_LAYOUT_DEFAULT }, @@ -459,7 +462,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) for( int i = 0; i < numBuiltins; i++ ) { - renderProg_t& prog = renderProgs[ i ]; + renderProg_t& prog = renderProgs[i]; prog.name = builtins[i].name; prog.builtin = true; @@ -475,21 +478,21 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) } int vIndex = -1; - if( builtins[ i ].stages & SHADER_STAGE_VERTEX ) + if( builtins[i].stages & SHADER_STAGE_VERTEX ) { - vIndex = FindShader( builtins[ i ].name, SHADER_STAGE_VERTEX, builtins[i].nameOutSuffix, builtins[i].macros, true, builtins[i].layout ); + vIndex = FindShader( builtins[i].name, SHADER_STAGE_VERTEX, builtins[i].nameOutSuffix, builtins[i].macros, true, builtins[i].layout ); } int fIndex = -1; - if( builtins[ i ].stages & SHADER_STAGE_FRAGMENT ) + if( builtins[i].stages & SHADER_STAGE_FRAGMENT ) { - fIndex = FindShader( builtins[ i ].name, SHADER_STAGE_FRAGMENT, builtins[i].nameOutSuffix, builtins[i].macros, true, builtins[i].layout ); + fIndex = FindShader( builtins[i].name, SHADER_STAGE_FRAGMENT, builtins[i].nameOutSuffix, builtins[i].macros, true, builtins[i].layout ); } int cIndex = -1; if( builtins[i].stages & SHADER_STAGE_COMPUTE ) { - cIndex = FindShader( builtins[ i ].name, SHADER_STAGE_COMPUTE, builtins[i].nameOutSuffix, builtins[i].macros, true, builtins[i].layout ); + cIndex = FindShader( builtins[i].name, SHADER_STAGE_COMPUTE, builtins[i].nameOutSuffix, builtins[i].macros, true, builtins[i].layout ); } idLib::Printf( "Loading shader program %s\n", prog.name.c_str() ); @@ -561,8 +564,8 @@ void idRenderProgManager::Init( nvrhi::IDevice* _device ) for( int i = 0; i < NUM_FRAME_DATA; ++i ) { - parmBuffers[ i ] = new idUniformBuffer(); - parmBuffers[ i ]->AllocBufferObject( NULL, MAX_DESC_SETS * MAX_DESC_SET_UNIFORMS * sizeof( idVec4 ), BU_DYNAMIC ); + parmBuffers[i] = new idUniformBuffer(); + parmBuffers[i]->AllocBufferObject( NULL, MAX_DESC_SETS * MAX_DESC_SET_UNIFORMS * sizeof( idVec4 ), BU_DYNAMIC ); } // Placeholder: mainly for optionalSkinning @@ -620,7 +623,7 @@ int idRenderProgManager::FindShader( const char* name, rpStage_t stage ) for( int i = 0; i < shaders.Num(); i++ ) { - shader_t& shader = shaders[ i ]; + shader_t& shader = shaders[i]; if( shader.name.Icmp( shaderName.c_str() ) == 0 && shader.stage == stage ) { LoadShader( i, stage ); @@ -716,7 +719,7 @@ int idRenderProgManager::FindShader( const char* name, rpStage_t stage, const ch #if defined( USE_NVRHI ) nvrhi::ShaderHandle idRenderProgManager::GetShader( int index ) { - return shaders[ index ].handle; + return shaders[index].handle; } programInfo_t idRenderProgManager::GetProgramInfo( int index ) @@ -724,6 +727,9 @@ programInfo_t idRenderProgManager::GetProgramInfo( int index ) programInfo_t info; renderProg_t& prog = renderProgs[index]; + + info.bindingLayoutType = prog.bindingLayoutType; + if( prog.vertexShaderIndex > -1 && prog.vertexShaderIndex < shaders.Num() ) { info.vs = GetShader( prog.vertexShaderIndex ); @@ -737,7 +743,7 @@ programInfo_t idRenderProgManager::GetProgramInfo( int index ) info.cs = GetShader( prog.computeShaderIndex ); } info.inputLayout = prog.inputLayout; - info.bindingLayout = prog.bindingLayout; + info.bindingLayouts = &prog.bindingLayouts; return info; } @@ -1060,4 +1066,4 @@ void RpPrintState( uint64 stateBits ) { printStencil( STENCIL_FACE_NUM, stateBits, mask, ref ); } -} +} \ No newline at end of file diff --git a/neo/renderer/RenderProgs.h b/neo/renderer/RenderProgs.h index 6990db39..67b10033 100644 --- a/neo/renderer/RenderProgs.h +++ b/neo/renderer/RenderProgs.h @@ -264,11 +264,12 @@ struct shaderMacro_t #if defined( USE_NVRHI ) struct programInfo_t { + int bindingLayoutType; nvrhi::ShaderHandle vs; nvrhi::ShaderHandle ps; nvrhi::ShaderHandle cs; nvrhi::InputLayoutHandle inputLayout; - nvrhi::BindingLayoutHandle bindingLayout; + idStaticList* bindingLayouts; }; #endif @@ -923,10 +924,6 @@ public: { return renderProgs[currentIndex].inputLayout; } - ID_INLINE nvrhi::BindingLayoutHandle BindingLayout() - { - return renderProgs[currentIndex].bindingLayout; - } ID_INLINE int BindingLayoutType() { return renderProgs[currentIndex].bindingLayoutType; @@ -1010,7 +1007,7 @@ private: vertexLayout( LAYOUT_UNKNOWN ), bindingLayoutType( BINDING_LAYOUT_DEFAULT ), inputLayout( nullptr ), - bindingLayout( nullptr ) + bindingLayouts() { } @@ -1023,7 +1020,7 @@ private: vertexLayoutType_t vertexLayout; bindingLayoutType_t bindingLayoutType; nvrhi::InputLayoutHandle inputLayout; - nvrhi::BindingLayoutHandle bindingLayout; + idStaticList< nvrhi::BindingLayoutHandle, nvrhi::c_MaxBindingLayouts > bindingLayouts; }; void LoadShader( shader_t& shader ); @@ -1037,7 +1034,7 @@ private: using VertexAttribDescList = idList< nvrhi::VertexAttributeDesc >; idStaticList< VertexAttribDescList, NUM_VERTEX_LAYOUTS > vertexLayoutDescs; - idStaticList< nvrhi::BindingLayoutHandle, NUM_BINDING_LAYOUTS > bindingLayouts; + idStaticList< idStaticList, NUM_BINDING_LAYOUTS > bindingLayouts; nvrhi::BufferHandle constantBuffer; diff --git a/neo/renderer/RenderSystem_init.cpp b/neo/renderer/RenderSystem_init.cpp index d16ef6fa..2db7ef1f 100644 --- a/neo/renderer/RenderSystem_init.cpp +++ b/neo/renderer/RenderSystem_init.cpp @@ -328,7 +328,7 @@ idCVar r_showLightGrid( "r_showLightGrid", "0", CVAR_RENDERER | CVAR_INTEGER, "s idCVar r_useLightGrid( "r_useLightGrid", "1", CVAR_RENDERER | CVAR_BOOL, "" ); -idCVar r_exposure( "r_exposure", "-0.5", CVAR_ARCHIVE | CVAR_RENDERER | CVAR_FLOAT, "HDR exposure or LDR brightness [-1.0 .. 0.0]", -1.0f, 0.0f ); +idCVar r_exposure( "r_exposure", "-0.5", CVAR_ARCHIVE | CVAR_RENDERER | CVAR_FLOAT, "HDR exposure or LDR brightness [-4.0 .. 4.0]", -4.0f, 4.0f ); // RB end const char* fileExten[4] = { "tga", "png", "jpg", "exr" }; diff --git a/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl b/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl index 487157fe..da94f4cf 100644 --- a/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl +++ b/neo/shaders/builtin/SSAO/AmbientOcclusion_AO.ps.hlsl @@ -97,9 +97,7 @@ Texture2D t_NormalRoughness : register( t0 ); Texture2D t_ViewDepth : register( t1 ); Texture2D t_BlueNoise : register( t2 ); -SamplerState normalSampler : register( s0 ); -SamplerState depthSampler : register( s1 ); -SamplerState blueNoiseSampler : register( s2 ); +SamplerState blueNoiseSampler : register( s0 ); #define CS_Z_buffer t_ViewDepth diff --git a/neo/shaders/builtin/SSAO/AmbientOcclusion_blur.ps.hlsl b/neo/shaders/builtin/SSAO/AmbientOcclusion_blur.ps.hlsl index 685b7bc4..1e8d1b65 100644 --- a/neo/shaders/builtin/SSAO/AmbientOcclusion_blur.ps.hlsl +++ b/neo/shaders/builtin/SSAO/AmbientOcclusion_blur.ps.hlsl @@ -26,10 +26,6 @@ Texture2D t_NormalRoughness : register( t0 ); Texture2D t_ViewDepth : register( t1 ); Texture2D t_Ao : register( t2 ); -SamplerState normalSampler : register( s0 ); -SamplerState depthSampler : register( s1 ); -SamplerState aoSampler : register( s2 ); - #define normal_buffer t_NormalRoughness #define cszBuffer t_ViewDepth #define source t_Ao diff --git a/neo/shaders/builtin/legacy/bumpyenvironment.ps.hlsl b/neo/shaders/builtin/legacy/bumpyenvironment.ps.hlsl index e24ba442..d39202ac 100644 --- a/neo/shaders/builtin/legacy/bumpyenvironment.ps.hlsl +++ b/neo/shaders/builtin/legacy/bumpyenvironment.ps.hlsl @@ -37,7 +37,7 @@ Texture2D t_NormalMap : register(t1); SamplerState samp0 : register(s0); // texture 0 is the cube map struct PS_IN { - float4 position : VPOS; + float4 position : SV_Position; float2 texcoord0 : TEXCOORD0_centroid; float3 texcoord1 : TEXCOORD1_centroid; float3 texcoord2 : TEXCOORD2_centroid; diff --git a/neo/shaders/builtin/lighting/interactionAmbient.ps.hlsl b/neo/shaders/builtin/lighting/interactionAmbient.ps.hlsl index e3588f4a..3b0c42c1 100644 --- a/neo/shaders/builtin/lighting/interactionAmbient.ps.hlsl +++ b/neo/shaders/builtin/lighting/interactionAmbient.ps.hlsl @@ -44,7 +44,7 @@ SamplerState samp3 : register(s3); // texture 4 is the light falloff texture SamplerState samp4 : register(s4); // texture 5 is the light projection texture struct PS_IN { - half4 position : VPOS; + half4 position : SV_Position; half4 texcoord1 : TEXCOORD1_centroid; half4 texcoord2 : TEXCOORD2_centroid; half4 texcoord3 : TEXCOORD3_centroid; diff --git a/neo/shaders/builtin/lighting/interactionAmbient.vs.hlsl b/neo/shaders/builtin/lighting/interactionAmbient.vs.hlsl index f2a23621..1414743c 100644 --- a/neo/shaders/builtin/lighting/interactionAmbient.vs.hlsl +++ b/neo/shaders/builtin/lighting/interactionAmbient.vs.hlsl @@ -30,29 +30,34 @@ If you have questions concerning this license or the applicable additional terms // *INDENT-OFF* + +#if USE_GPU_SKINNING +cbuffer CB : register( b1 ) { float4 matrices[408]; }; +#endif + struct VS_IN { float4 position : POSITION; float2 texcoord : TEXCOORD0; - float4 normal : NORMAL; - float4 tangent : TANGENT; - float4 color : COLOR0; + float4 normal : NORMAL; + float4 tangent : TANGENT; + float4 color : COLOR0; }; struct VS_OUT { - float4 position : POSITION; - float4 texcoord1 : TEXCOORD1; - float4 texcoord2 : TEXCOORD2; - float4 texcoord3 : TEXCOORD3; - float4 texcoord4 : TEXCOORD4; - float4 texcoord5 : TEXCOORD5; - float4 texcoord6 : TEXCOORD6; + float4 position : SV_Position; + float4 texcoord1 : TEXCOORD1_centroid; + float4 texcoord2 : TEXCOORD2_centroid; + float4 texcoord3 : TEXCOORD3_centroid; + float4 texcoord4 : TEXCOORD4_centroid; + float4 texcoord5 : TEXCOORD5_centroid; + float4 texcoord6 : TEXCOORD6_centroid; float4 color : COLOR0; }; + // *INDENT-ON* void main( VS_IN vertex, out VS_OUT result ) { - float4 normal = vertex.normal * 2.0 - 1.0; float4 tangent = vertex.tangent * 2.0 - 1.0; float3 binormal = cross( normal.xyz, tangent.xyz ) * tangent.w; diff --git a/neo/sys/DeviceManager.h b/neo/sys/DeviceManager.h index 85f84410..08c4a4a5 100644 --- a/neo/sys/DeviceManager.h +++ b/neo/sys/DeviceManager.h @@ -121,7 +121,7 @@ public: y = dpiScaleFactorY; } - void UpdateWindowSize(); + void UpdateWindowSize( const glimpParms_t& params ); protected: friend class idRenderBackend; @@ -130,7 +130,6 @@ protected: bool windowVisible = false; bool isNvidia = false; - DeviceCreationParameters deviceParms; float dpiScaleFactorX = 1.f; diff --git a/neo/sys/win32/DeviceManager_DX12.cpp b/neo/sys/win32/DeviceManager_DX12.cpp index ac1aad45..4799faac 100644 --- a/neo/sys/win32/DeviceManager_DX12.cpp +++ b/neo/sys/win32/DeviceManager_DX12.cpp @@ -39,6 +39,9 @@ #pragma comment(lib, "d3d12.lib") #pragma comment(lib, "dxgi.lib") +// TODO extend this so 1 will be just NVRHI and 2 will turn on the additional VK validation layer +idCVar r_useValidationLayers( "r_useValidationLayers", "0", CVAR_BOOL | CVAR_INIT, "" ); + using nvrhi::RefCountPtr; #define HR_RETURN(hr) if(FAILED(hr)) return false @@ -397,7 +400,7 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain() nvrhiDevice = nvrhi::d3d12::createDevice( deviceDesc ); - deviceParms.enableNvrhiValidationLayer = true; + deviceParms.enableNvrhiValidationLayer = r_useValidationLayers.GetBool(); if( deviceParms.enableNvrhiValidationLayer ) { diff --git a/neo/sys/win32/win_glimp.cpp b/neo/sys/win32/win_glimp.cpp index 8f9646e1..c57368ae 100644 --- a/neo/sys/win32/win_glimp.cpp +++ b/neo/sys/win32/win_glimp.cpp @@ -1131,51 +1131,29 @@ bool DeviceManager::CreateWindowDeviceAndSwapChain( const glimpParms_t& parms, c glConfig.isFullscreen = parms.fullScreen; - UpdateWindowSize(); + UpdateWindowSize( parms ); return true; } -void DeviceManager::UpdateWindowSize() +void DeviceManager::UpdateWindowSize( const glimpParms_t& params ) { - // get the current monitor position and size on the desktop, assuming - // any required ChangeDisplaySettings has already been done - RECT rect; - if( ::GetClientRect( win32.hWnd, &rect ) ) - { - if( rect.right > rect.left && rect.bottom > rect.top ) - { - // save the window size in cvars if we aren't fullscreen - int style = GetWindowLong( win32.hWnd, GWL_STYLE ); - - glConfig.nativeScreenWidth = rect.right - rect.left; - glConfig.nativeScreenHeight = rect.bottom - rect.top; - } - } - - if( glConfig.nativeScreenWidth == 0 || glConfig.nativeScreenHeight == 0 ) - { - // window is minimized - windowVisible = false; - return; - } - windowVisible = true; - if( int( deviceParms.backBufferWidth ) != glConfig.nativeScreenWidth || - int( deviceParms.backBufferHeight ) != glConfig.nativeScreenHeight || + if( int( deviceParms.backBufferWidth ) != params.width || + int( deviceParms.backBufferHeight ) != params.height || ( deviceParms.vsyncEnabled != requestedVSync && GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN ) ) { // window is not minimized, and the size has changed BackBufferResizing(); - deviceParms.backBufferWidth = glConfig.nativeScreenWidth; - deviceParms.backBufferHeight = glConfig.nativeScreenHeight; + deviceParms.backBufferWidth = params.width; + deviceParms.backBufferHeight = params.height; deviceParms.vsyncEnabled = requestedVSync; ResizeSwapChain(); - //BackBufferResized(); + BackBufferResized(); } deviceParms.vsyncEnabled = requestedVSync; @@ -1553,6 +1531,8 @@ bool GLimp_SetScreenParms( glimpParms_t parms ) glConfig.nativeScreenWidth = parms.width; glConfig.nativeScreenHeight = parms.height; + deviceManager->UpdateWindowSize( parms ); + return true; } diff --git a/neo/sys/win32/win_wndproc.cpp b/neo/sys/win32/win_wndproc.cpp index 386dcf0e..31ebaa75 100644 --- a/neo/sys/win32/win_wndproc.cpp +++ b/neo/sys/win32/win_wndproc.cpp @@ -201,12 +201,6 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) r_windowHeight.SetInteger( glConfig.nativeScreenHeight ); } } - - if( glConfig.nativeScreenWidth != originalWidth || glConfig.nativeScreenHeight != originalHeight ) - { - deviceManager->UpdateWindowSize(); - Framebuffer::ResizeFramebuffers(); - } } } #endif