From fd98e2bbc57f962928a039900b4eb3fbe7ca0d1c Mon Sep 17 00:00:00 2001 From: Michael Pollind Date: Thu, 4 Jan 2024 21:29:21 -0800 Subject: [PATCH] feat: add uniform ring buffer for viewport Signed-off-by: Michael Pollind --- HPL2/include/graphics/RendererDeferred2.h | 5 +++++ HPL2/resource/scene_resource.h.fsl | 4 ++++ HPL2/sources/graphics/RendererDeferred2.cpp | 7 +++++++ 3 files changed, 16 insertions(+) diff --git a/HPL2/include/graphics/RendererDeferred2.h b/HPL2/include/graphics/RendererDeferred2.h index 1bf62ee0c..9c2e2100b 100644 --- a/HPL2/include/graphics/RendererDeferred2.h +++ b/HPL2/include/graphics/RendererDeferred2.h @@ -107,6 +107,8 @@ namespace hpl { static constexpr uint32_t LightClusterSlices = 24; static constexpr uint32_t TransientImagePoolCount = 256; + static constexpr uint32_t ViewportRingBufferSize = 2048; + static constexpr uint32_t IndirectArgumentSize = 8 * sizeof(uint32_t); struct RootConstantDrawIndexArguments { @@ -225,6 +227,8 @@ namespace hpl { cRenderList m_rendererList; + GPURingBuffer m_viewPortUniformBuffer{}; + SharedRootSignature m_lightClusterRootSignature; std::array m_lightDescriptorPerFrameSet; SharedShader m_lightClusterShader; @@ -312,6 +316,7 @@ namespace hpl { uint32_t m_objectIndex = 0; uint32_t m_indirectIndex = 0; uint32_t m_particleIndex = 0; + uint32_t m_viewportIndex = 0; }; ResetFrameHandler m_resetHandler; TransientFrameVariable m_variables; diff --git a/HPL2/resource/scene_resource.h.fsl b/HPL2/resource/scene_resource.h.fsl index c101fc584..6753cfe07 100644 --- a/HPL2/resource/scene_resource.h.fsl +++ b/HPL2/resource/scene_resource.h.fsl @@ -22,6 +22,10 @@ CBUFFER(sceneInfo, UPDATE_FREQ_PER_FRAME, b1, binding = 4) { DATA(ViewportInfo, viewports[64], None); }; +CBUFFER(viewportBlock, UPDATE_FREQ_PER_BATCH, b2, binding = 5) { + DATA(ViewportInfo, viewport, None); +}; + RES(Buffer(UniformObject), sceneObjects, UPDATE_FREQ_PER_FRAME, t0, binding = 5); RES(Buffer(Light), lights, UPDATE_FREQ_PER_FRAME, t1, binding = 6); RES(Buffer(Particle), particles, UPDATE_FREQ_PER_FRAME, t2, binding = 7); diff --git a/HPL2/sources/graphics/RendererDeferred2.cpp b/HPL2/sources/graphics/RendererDeferred2.cpp index 0fa88da03..b1e512f53 100644 --- a/HPL2/sources/graphics/RendererDeferred2.cpp +++ b/HPL2/sources/graphics/RendererDeferred2.cpp @@ -1274,6 +1274,9 @@ namespace hpl { m_diffuseIndexPool = IndexPool(resource::MaxSolidDiffuseMaterials); m_translucencyIndexPool = IndexPool(resource::MaxTranslucenctMaterials); m_waterIndexPool = IndexPool(resource::MaxWaterMaterials); + + addUniformGPURingBuffer(forgeRenderer->Rend(), ViewportRingBufferSize, &m_viewPortUniformBuffer); + // create Descriptor sets m_sceneDescriptorConstSet.Load(forgeRenderer->Rend(), [&](DescriptorSet** descSet) { @@ -1481,6 +1484,7 @@ namespace hpl { vars.m_objectIndex = 0; vars.m_indirectIndex = 0; vars.m_particleIndex = 0; + vars.m_viewportIndex = 0; vars.m_objectSlotIndex.clear(); }); @@ -1618,6 +1622,9 @@ namespace hpl { updateDescriptorSet( 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) }; beginUpdateResource(&updateDesc);