diff --git a/HPL2/include/graphics/RendererDeferred2.h b/HPL2/include/graphics/RendererDeferred2.h index 9c2e2100b..3156c77e5 100644 --- a/HPL2/include/graphics/RendererDeferred2.h +++ b/HPL2/include/graphics/RendererDeferred2.h @@ -108,6 +108,7 @@ namespace hpl { static constexpr uint32_t TransientImagePoolCount = 256; static constexpr uint32_t ViewportRingBufferSize = 2048; + static constexpr uint32_t ScenePerDescriptorBatchSize = 32; static constexpr uint32_t IndirectArgumentSize = 8 * sizeof(uint32_t); @@ -205,6 +206,7 @@ namespace hpl { SharedRootSignature m_sceneRootSignature; SharedDescriptorSet m_sceneDescriptorConstSet; std::array m_sceneDescriptorPerFrameSet; + std::array m_sceneDescriptorPerBatchSet; SharedShader m_visibilityBufferPassShader; SharedShader m_visibilityBufferAlphaPassShader; @@ -219,16 +221,14 @@ namespace hpl { std::array m_perSceneInfoBuffer; std::array m_indirectDrawArgsBuffer; - std::array m_materialSampler; - SharedTexture m_emptyTexture2D; SharedTexture m_emptyTextureCube; Image* m_dissolveImage; cRenderList m_rendererList; - GPURingBuffer m_viewPortUniformBuffer{}; - + GPURingBuffer m_viewPortUniformBuffer{}; + SharedRootSignature m_lightClusterRootSignature; std::array m_lightDescriptorPerFrameSet; SharedShader m_lightClusterShader; diff --git a/HPL2/resource/visibility_emit_shade_pass.frag.fsl b/HPL2/resource/visibility_emit_shade_pass.frag.fsl index 9619cdfaa..b3f4ea68d 100644 --- a/HPL2/resource/visibility_emit_shade_pass.frag.fsl +++ b/HPL2/resource/visibility_emit_shade_pass.frag.fsl @@ -29,7 +29,7 @@ float4 PS_MAIN(PsIn In) UniformObject obj = Get(sceneObjects)[objectId]; uint startIndex = obj.indexOffset; uint vertexOffset = obj.vertexOffset; - ViewportInfo viewInfo = Get(viewports)[PRIMARY_VIEWPORT_INDEX]; + ViewportInfo viewInfo = Get(viewport); float4x4 vp = mul(viewInfo.projMat, viewInfo.viewMat); float4x4 mvp = mul(vp, obj.modelMat); diff --git a/HPL2/sources/graphics/GraphicsAllocator.cpp b/HPL2/sources/graphics/GraphicsAllocator.cpp index c5dbaf3b9..d13dcc36d 100644 --- a/HPL2/sources/graphics/GraphicsAllocator.cpp +++ b/HPL2/sources/graphics/GraphicsAllocator.cpp @@ -53,13 +53,4 @@ namespace hpl { GPURingBufferOffset GraphicsAllocator::allocTransientIndexBuffer(uint32_t size) { return getGPURingBufferOffset(&m_transientIndeciesBuffer, size); } - - // GraphicsAllocator::OffsetAllocHandle GraphicsAllocator::allocVertexFromSharedBuffer(uint32_t size) { - // OffsetAllocator::Allocation alloc = m_vertexBufferAllocator.allocate(size); - // return OffsetAllocHandle(&m_vertexBufferAllocator, alloc, m_sharedVertexBuffer); - // } - // GraphicsAllocator::OffsetAllocHandle GraphicsAllocator::allocIndeciesFromSharedBuffer(uint32_t size) { - // OffsetAllocator::Allocation alloc = m_indexBufferAllocator.allocate(size); - // return OffsetAllocHandle(&m_indexBufferAllocator, alloc, m_sharedIndexBuffer); - // } } // namespace hpl diff --git a/HPL2/sources/graphics/RendererDeferred2.cpp b/HPL2/sources/graphics/RendererDeferred2.cpp index b1e512f53..7a4eac523 100644 --- a/HPL2/sources/graphics/RendererDeferred2.cpp +++ b/HPL2/sources/graphics/RendererDeferred2.cpp @@ -1,4 +1,5 @@ #include "graphics/RendererDeferred2.h" +#include "Common_3/Utilities/RingBuffer.h" #include "graphics/DrawPacket.h" #include "graphics/ForgeHandles.h" #include "graphics/ForgeRenderer.h" @@ -1274,7 +1275,7 @@ namespace hpl { m_diffuseIndexPool = IndexPool(resource::MaxSolidDiffuseMaterials); m_translucencyIndexPool = IndexPool(resource::MaxTranslucenctMaterials); m_waterIndexPool = IndexPool(resource::MaxWaterMaterials); - + addUniformGPURingBuffer(forgeRenderer->Rend(), ViewportRingBufferSize, &m_viewPortUniformBuffer); @@ -1291,7 +1292,11 @@ namespace hpl { addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet); return true; }); - + m_sceneDescriptorPerBatchSet[swapchainIndex].Load(forgeRenderer->Rend(), [&](DescriptorSet** descSet) { + DescriptorSetDesc descriptorSetDesc{ m_sceneRootSignature.m_handle, DESCRIPTOR_UPDATE_FREQ_PER_BATCH, ScenePerDescriptorBatchSize }; + addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet); + return true; + }); m_lightDescriptorPerFrameSet[swapchainIndex].Load(forgeRenderer->Rend(), [&](DescriptorSet** descSet) { DescriptorSetDesc descriptorSetDesc{ m_lightClusterRootSignature.m_handle, DESCRIPTOR_UPDATE_FREQ_PER_FRAME, 1 }; addDescriptorSet(forgeRenderer->Rend(), &descriptorSetDesc, descSet); @@ -1488,6 +1493,7 @@ namespace hpl { vars.m_objectSlotIndex.clear(); }); + auto viewportDatum = m_boundViewportData.resolve(viewport); if (!viewportDatum || viewportDatum->m_size != viewport.GetSizeU2()) { auto updateDatum = std::make_unique(); @@ -1607,6 +1613,26 @@ namespace hpl { frame.m_resourcePool->Push(viewportDatum->m_outputBuffer[frame.m_frameIndex]); frame.m_resourcePool->Push(viewportDatum->m_albedoBuffer[frame.m_frameIndex]); frame.m_resourcePool->Push(viewportDatum->m_refractionImage[frame.m_frameIndex]); + + uint32_t mainBatchIndex = frameVars.m_viewportIndex++; + { + GPURingBufferOffset offset = getGPURingBufferOffset(&m_viewPortUniformBuffer, sizeof(resource::ViewportInfo)); + BufferUpdateDesc updateDesc = { offset.pBuffer, offset.mOffset }; + beginUpdateResource(&updateDesc); + resource::ViewportInfo* viewportInfo = reinterpret_cast(updateDesc.pMappedData); + (*viewportInfo) = resource::ViewportInfo::create(apFrustum, float4(0.0f, 0.0f, static_cast(viewportDatum->m_size.x), static_cast(viewportDatum->m_size.y))); + endUpdateResource(&updateDesc); + + { + DescriptorDataRange viewportRange = { (uint32_t)offset.mOffset, sizeof(resource::ViewportInfo) }; + std::array params = { + DescriptorData { .pName = "viewportBlock", .pRanges = &viewportRange, .ppBuffers = &offset.pBuffer } + }; + updateDescriptorSet( + forgeRenderer->Rend(), mainBatchIndex, m_sceneDescriptorPerBatchSet[frame.m_frameIndex].m_handle, params.size(), params.data()); + } + } + // ---------------- // Setup Data // ----------------- @@ -1623,7 +1649,7 @@ namespace hpl { forgeRenderer->Rend(), 0, m_sceneDescriptorPerFrameSet[frame.m_frameIndex].m_handle, params.size(), params.data()); } - + { BufferUpdateDesc updateDesc = { m_perSceneInfoBuffer[frame.m_frameIndex].m_handle, 0, sizeof(resource::SceneInfoResource) }; @@ -2255,7 +2281,6 @@ namespace hpl { cmdResourceBarrier(cmd, 0, nullptr, 0, nullptr, rtBarriers.size(), rtBarriers.data()); } { - //cmdBeginDebugMarker(cmd, 0, 1, 0, "Visibility Emit Buffer Pass"); LoadActionsDesc loadActions = {}; loadActions.mLoadActionsColor[0] = LOAD_ACTION_CLEAR; loadActions.mClearColorValues[0] = { .r = 0.0f, .g = 0.0f, .b = 0.0f, .a = 0.0f }; @@ -2268,8 +2293,8 @@ namespace hpl { cmdBindPipeline(cmd, m_visbilityEmitBufferPass.m_handle); cmdBindDescriptorSet(cmd, 0, m_sceneDescriptorConstSet.m_handle); cmdBindDescriptorSet(cmd, 0, m_sceneDescriptorPerFrameSet[frame.m_frameIndex].m_handle); + cmdBindDescriptorSet(cmd, mainBatchIndex, m_sceneDescriptorPerBatchSet[frame.m_frameIndex].m_handle); cmdDraw(cmd, 3, 0); - //cmdEndDebugMarker(cmd); } { //cmdBeginDebugMarker(cmd, 0, 1, 0, "Decal Output Buffer Pass");