diff --git a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp index e265f7a5..7e0e0c65 100644 --- a/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderBackend_NVRHI.cpp @@ -194,6 +194,9 @@ void idRenderBackend::Init() { r_useSSAO.SetBool( false ); } + + deviceManager->GetDevice()->waitForIdle(); + deviceManager->GetDevice()->runGarbageCollection(); } void idRenderBackend::Shutdown() @@ -463,18 +466,24 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) desc.SetNum( nvrhi::c_MaxBindingLayouts ); } + //idUniformBuffer& ubo = renderProgManager.BindingParamUbo(); + //nvrhi::IBuffer* paramCb = ubo.GetAPIObject(); + nvrhi::IBuffer* paramCb = renderProgManager.ConstantBuffer(); + auto range = nvrhi::EntireBuffer; + if( type == BINDING_LAYOUT_DEFAULT ) { if( desc[0].bindings.empty() ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; } if( desc[1].bindings.empty() ) @@ -507,14 +516,15 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), nvrhi::BindingSetItem::StructuredBuffer_SRV( 11, currentJointBuffer, nvrhi::Format::UNKNOWN, nvrhi::BufferRange( currentJointOffset, sizeof( idVec4 ) * numBoneMatrices ) ) }; } else { auto& bindings = desc[0].bindings; - bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + bindings[0].resourceHandle = paramCb; + bindings[0].range = range; bindings[1].resourceHandle = currentJointBuffer; bindings[1].range = nvrhi::BufferRange{ currentJointOffset, sizeof( idVec4 )* numBoneMatrices }; } @@ -549,12 +559,13 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; } } else if( type == BINDING_LAYOUT_CONSTANT_BUFFER_ONLY_SKINNED ) @@ -563,46 +574,32 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer(0, paramCb, range), nvrhi::BindingSetItem::StructuredBuffer_SRV( 11, currentJointBuffer, nvrhi::Format::UNKNOWN, nvrhi::BufferRange( currentJointOffset, sizeof( idVec4 ) * numBoneMatrices ) ) }; } else { auto& bindings = desc[0].bindings; - bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + bindings[0].resourceHandle = paramCb; + bindings[0].range = range; bindings[1].resourceHandle = currentJointBuffer; bindings[1].range = nvrhi::BufferRange{ currentJointOffset, sizeof( idVec4 )* numBoneMatrices }; } } - /* - else if( type == BINDING_LAYOUT_GBUFFER ) - { - if( desc[0].bindings.empty() ) - { - desc[0].bindings = - { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), - }; - } - else - { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); - } - } - */ else if( type == BINDING_LAYOUT_AMBIENT_LIGHTING_IBL ) { if( desc[0].bindings.empty() ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; } if( desc[1].bindings.empty() ) @@ -663,14 +660,15 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), nvrhi::BindingSetItem::StructuredBuffer_SRV( 11, currentJointBuffer, nvrhi::Format::UNKNOWN, nvrhi::BufferRange( currentJointOffset, sizeof( idVec4 ) * numBoneMatrices ) ) }; } else { auto& bindings = desc[0].bindings; - bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + bindings[0].resourceHandle = paramCb; + bindings[0].range = range; bindings[1].resourceHandle = currentJointBuffer; bindings[1].range = nvrhi::BufferRange{ currentJointOffset, sizeof( idVec4 )* numBoneMatrices }; } @@ -733,7 +731,7 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), 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() ) @@ -741,7 +739,8 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; desc[0].bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID(); desc[0].bindings[2].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID(); desc[0].bindings[3].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID(); @@ -766,12 +765,13 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; } // materials: 1 @@ -828,14 +828,15 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), nvrhi::BindingSetItem::StructuredBuffer_SRV( 11, currentJointBuffer, nvrhi::Format::UNKNOWN, nvrhi::BufferRange( currentJointOffset, sizeof( idVec4 ) * numBoneMatrices ) ) }; } else { auto& bindings = desc[0].bindings; - bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + bindings[0].resourceHandle = paramCb; + bindings[0].range = range; bindings[1].resourceHandle = currentJointBuffer; bindings[1].range = nvrhi::BufferRange{ currentJointOffset, sizeof( idVec4 )* numBoneMatrices }; } @@ -894,12 +895,13 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; } // materials: 1 @@ -969,14 +971,15 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), nvrhi::BindingSetItem::StructuredBuffer_SRV( 11, currentJointBuffer, nvrhi::Format::UNKNOWN, nvrhi::BufferRange( currentJointOffset, sizeof( idVec4 ) * numBoneMatrices ) ) }; } else { auto& bindings = desc[0].bindings; - bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + bindings[0].resourceHandle = paramCb; + bindings[0].range = range; bindings[1].resourceHandle = currentJointBuffer; bindings[1].range = nvrhi::BufferRange{ currentJointOffset, sizeof( idVec4 )* numBoneMatrices }; } @@ -1047,12 +1050,13 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; } if( desc[1].bindings.empty() ) @@ -1091,14 +1095,15 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), nvrhi::BindingSetItem::StructuredBuffer_SRV( 11, currentJointBuffer, nvrhi::Format::UNKNOWN, nvrhi::BufferRange( currentJointOffset, sizeof( idVec4 ) * numBoneMatrices ) ) }; } else { auto& bindings = desc[0].bindings; - bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + bindings[0].resourceHandle = paramCb; + bindings[0].range = range; bindings[1].resourceHandle = currentJointBuffer; bindings[1].range = nvrhi::BufferRange{ currentJointOffset, sizeof( idVec4 )* numBoneMatrices }; } @@ -1139,12 +1144,13 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), - }; + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), + }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; } if( desc[1].bindings.empty() ) @@ -1180,14 +1186,15 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), nvrhi::BindingSetItem::StructuredBuffer_SRV( 11, currentJointBuffer, nvrhi::Format::UNKNOWN, nvrhi::BufferRange( currentJointOffset, sizeof( idVec4 ) * numBoneMatrices ) ) }; } else { auto& bindings = desc[0].bindings; - bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + bindings[0].resourceHandle = paramCb; + bindings[0].range = range; bindings[1].resourceHandle = currentJointBuffer; bindings[1].range = nvrhi::BufferRange{ currentJointOffset, sizeof( idVec4 )* numBoneMatrices }; } @@ -1225,7 +1232,7 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), 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() ) @@ -1233,7 +1240,8 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; desc[0].bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID(); desc[0].bindings[2].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID(); desc[0].bindings[3].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID(); @@ -1257,14 +1265,15 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ), nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; desc[0].bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID(); desc[0].bindings[2].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID(); } @@ -1289,12 +1298,13 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; } if( desc[1].bindings.empty() ) @@ -1330,15 +1340,21 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), nvrhi::BindingSetItem::StructuredBuffer_SRV( 11, currentJointBuffer, nvrhi::Format::UNKNOWN, nvrhi::BufferRange( currentJointOffset, sizeof( idVec4 ) * numBoneMatrices ) ) }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; auto& bindings = desc[0].bindings; - bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + bindings[0].resourceHandle = paramCb; + bindings[0].range = range; + + bindings[0].resourceHandle = paramCb; + bindings[0].range = range; + bindings[1].resourceHandle = currentJointBuffer; bindings[1].range = nvrhi::BufferRange{ currentJointOffset, sizeof( idVec4 )* numBoneMatrices }; } @@ -1376,7 +1392,7 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range ), 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() ) @@ -1384,7 +1400,8 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; desc[0].bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID(); desc[0].bindings[2].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID(); desc[0].bindings[3].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 2 )->GetTextureID(); @@ -1408,14 +1425,15 @@ void idRenderBackend::GetCurrentBindingLayout( int type ) { desc[0].bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, paramCb, range), nvrhi::BindingSetItem::Texture_SRV( 0, ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID() ), nvrhi::BindingSetItem::Texture_SRV( 1, ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID() ) }; } else { - desc[0].bindings[0].resourceHandle = renderProgManager.ConstantBuffer(); + desc[0].bindings[0].resourceHandle = paramCb; + desc[0].bindings[0].range = range; desc[0].bindings[1].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 0 )->GetTextureID(); desc[0].bindings[2].resourceHandle = ( nvrhi::ITexture* )GetImageAt( 1 )->GetTextureID(); } @@ -1482,6 +1500,9 @@ void idRenderBackend::GL_EndFrame() deviceManager->GetDevice()->executeCommandList( commandList ); + // Make sure that all frames have finished rendering + deviceManager->GetDevice()->waitForIdle(); + // required for Vulkan: transition our swap image to present deviceManager->EndFrame(); @@ -1498,9 +1519,6 @@ We want to exit this with the GPU idle, right at vsync */ void idRenderBackend::GL_BlockingSwapBuffers() { - // Make sure that all frames have finished rendering - deviceManager->GetDevice()->waitForIdle(); - // Release all in-flight references to the render targets deviceManager->GetDevice()->runGarbageCollection(); diff --git a/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp b/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp index 3c52c053..0b168f25 100644 --- a/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp +++ b/neo/renderer/NVRHI/RenderProgs_NVRHI.cpp @@ -36,7 +36,6 @@ If you have questions concerning this license or the applicable additional terms #include - /* ======================== idRenderProgManager::StartFrame @@ -313,7 +312,15 @@ void idRenderProgManager::CommitConstantBuffer( nvrhi::ICommandList* commandList if( uniformsChanged ) { commandList->writeBuffer( constantBuffer, uniforms.Ptr(), uniforms.Allocated() ); - - uniformsChanged = false; + //bindingParmUbo[BindingLayoutType()].Update( uniforms.Ptr(), ALIGN( sizeof(idVec4) * RENDERPARM_TOTAL, vertexCache.uniformBufferOffsetAlignment ), 0, false, commandList ); + //CopyBuffer((byte*)mappedUniforms, (byte*)uniforms.Ptr(), RENDERPARM_TOTAL * sizeof(idVec4)); + //int layout = BindingLayoutType(); + //idVec4* parms = (idVec4*)bindingParmUbo[layout].MapBuffer(BM_WRITE); + //for (int i = 0; i < RENDERPARM_TOTAL; i++) + //{ + // parms[ i ] = uniforms[ i ]; + //} + //bindingParmUbo[layout].UnmapBuffer(); + //uniformsChanged = false; } } \ No newline at end of file diff --git a/neo/renderer/RenderPass.cpp b/neo/renderer/RenderPass.cpp index 7d0a61cb..98330055 100644 --- a/neo/renderer/RenderPass.cpp +++ b/neo/renderer/RenderPass.cpp @@ -129,10 +129,12 @@ bool BasicTriangle::Init() CommonRenderPasses commonPasses; commonPasses.Init( GetDevice() ); + idUniformBuffer& ubo = renderProgManager.BindingParamUbo(); + nvrhi::BindingSetDesc bindingSetDesc; bindingSetDesc.bindings = { - nvrhi::BindingSetItem::ConstantBuffer( 0, renderProgManager.ConstantBuffer() ), + nvrhi::BindingSetItem::ConstantBuffer( 0, ubo.GetAPIObject(), nvrhi::BufferRange(ubo.GetOffset(), ubo.GetSize()) ), nvrhi::BindingSetItem::Texture_SRV( 0, texture ), nvrhi::BindingSetItem::Sampler( 0, commonPasses.m_AnisotropicWrapSampler ) }; diff --git a/neo/renderer/RenderProgs.cpp b/neo/renderer/RenderProgs.cpp index 21676f56..2b153b8c 100644 --- a/neo/renderer/RenderProgs.cpp +++ b/neo/renderer/RenderProgs.cpp @@ -102,21 +102,21 @@ void idRenderProgManager::Init( nvrhi::IDevice* device ) uniforms.SetNum( RENDERPARM_TOTAL, vec4_zero ); uniformsChanged = false; - if( deviceManager->GetGraphicsAPI() == nvrhi::GraphicsAPI::VULKAN ) + renderParmUbo.SetDebugName( "Mapped Render Parms" ); + renderParmUbo.AllocBufferObject( NULL, ALIGN( NUM_BINDING_LAYOUTS * RENDERPARM_TOTAL * sizeof( idVec4 ), glConfig.uniformBufferOffsetAlignment ), BU_DYNAMIC, nullptr ); + + const int bytes = ALIGN( RENDERPARM_TOTAL * sizeof( idVec4 ), glConfig.uniformBufferOffsetAlignment ); + int offset = 0; + for( int i = 0; i < NUM_BINDING_LAYOUTS; i++ ) { - // RB: FIXME this is ugly - DOUBLECHECK this - constantBuffer = device->createBuffer( - nvrhi::utils::CreateVolatileConstantBufferDesc( uniforms.Allocated(), - "RenderParams", 4096 ) ); - } - else - { - constantBuffer = device->createBuffer( - nvrhi::utils::CreateVolatileConstantBufferDesc( uniforms.Allocated(), - "RenderParams", - c_MaxRenderPassConstantBufferVersions ) ); + bindingParmUbo[i].Reference( renderParmUbo, offset, bytes ); + //mappedRenderParms[i] = ( idVec4* )bindingParmUbo[i].MapBuffer( bufferMapType_t::BM_WRITE ); + offset += bytes; } + auto constantBufferDesc = nvrhi::utils::CreateVolatileConstantBufferDesc( uniforms.Allocated(), "RenderParams", 16384 ); + constantBuffer = device->createBuffer(constantBufferDesc); + // === Main draw vertex layout === vertexLayoutDescs.SetNum( NUM_VERTEX_LAYOUTS, {} ); @@ -184,15 +184,17 @@ void idRenderProgManager::Init( nvrhi::IDevice* device ) bindingLayouts.SetNum( NUM_BINDING_LAYOUTS ); + auto renderParmLayoutItem = nvrhi::BindingLayoutItem::VolatileConstantBuffer(0); + auto uniformsLayoutDesc = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) - .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ); + .addItem( renderParmLayoutItem ); auto uniformsLayout = device->createBindingLayout( uniformsLayoutDesc ); auto skinningLayoutDesc = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) - .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) + .addItem(renderParmLayoutItem) .addItem( nvrhi::BindingLayoutItem::StructuredBuffer_SRV( 11 ) ); // joint buffer; auto skinningLayout = device->createBindingLayout( skinningLayoutDesc ); @@ -256,7 +258,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* device ) auto aoLayoutDesc = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) - .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) + .addItem( renderParmLayoutItem ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 2 ) ); @@ -265,25 +267,11 @@ void idRenderProgManager::Init( nvrhi::IDevice* device ) auto aoLayoutDesc2 = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) - .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) + .addItem( renderParmLayoutItem ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ); bindingLayouts[BINDING_LAYOUT_DRAW_AO1] = { device->createBindingLayout( aoLayoutDesc2 ), samplerOneBindingLayout }; - /* - nvrhi::BindingLayoutDesc shadowLayoutDesc; - shadowLayoutDesc.visibility = nvrhi::ShaderType::All; - shadowLayoutDesc.bindings = - { - nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) - }; - auto shadowLayout = device->createBindingLayout( shadowLayoutDesc ); - bindingLayouts[BINDING_LAYOUT_DRAW_SHADOWVOLUME] = - { - - }; - */ - auto interactionBindingLayoutDesc = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::Pixel ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 3 ) ) // light falloff @@ -359,7 +347,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* device ) auto pp3DBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) - .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) + .addItem(renderParmLayoutItem) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) // current render .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ) // normal map .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 2 ) ); // mask @@ -368,7 +356,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* device ) auto ppFxBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) - .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) + .addItem(renderParmLayoutItem) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ); @@ -392,7 +380,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* device ) auto binkVideoBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) - .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) + .addItem(renderParmLayoutItem) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) // cube map .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ) // cube map .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 2 ) ); // normal map @@ -401,7 +389,7 @@ void idRenderProgManager::Init( nvrhi::IDevice* device ) auto motionVectorsBindingLayout = nvrhi::BindingLayoutDesc() .setVisibility( nvrhi::ShaderType::All ) - .addItem( nvrhi::BindingLayoutItem::VolatileConstantBuffer( 0 ) ) + .addItem(renderParmLayoutItem) .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 0 ) ) // cube map .addItem( nvrhi::BindingLayoutItem::Texture_SRV( 1 ) ); // normal map diff --git a/neo/renderer/RenderProgs.h b/neo/renderer/RenderProgs.h index 6ef188db..8d8dd25b 100644 --- a/neo/renderer/RenderProgs.h +++ b/neo/renderer/RenderProgs.h @@ -1028,6 +1028,10 @@ public: { return constantBuffer; } + ID_INLINE idUniformBuffer& BindingParamUbo() + { + return bindingParmUbo[ BindingLayoutType() ]; + } ID_INLINE nvrhi::InputLayoutHandle InputLayout() { return renderProgs[currentIndex].inputLayout; @@ -1040,6 +1044,10 @@ public: { return &bindingLayouts[layoutType]; } + + idUniformBuffer renderParmUbo; + idArray bindingParmUbo; + idArray mappedRenderParms; #elif defined(USE_VULKAN) void PrintPipelines(); void ClearPipelines();