From 5b0d1a9d55b05040706289e7f7701c9d319f040b Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Wed, 28 Apr 2021 16:38:02 +0200 Subject: [PATCH 1/2] Fix history buffer allocation for AOVs when the request does not come in first frame --- .../Textures/BufferedRTHandleSystem.cs | 12 ++++++++++ .../CHANGELOG.md | 1 + .../Runtime/RenderPipeline/Camera/HDCamera.cs | 22 +++++++++++++------ 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/Textures/BufferedRTHandleSystem.cs b/com.unity.render-pipelines.core/Runtime/Textures/BufferedRTHandleSystem.cs index b8e89f04c6b..ff40f3fe260 100644 --- a/com.unity.render-pipelines.core/Runtime/Textures/BufferedRTHandleSystem.cs +++ b/com.unity.render-pipelines.core/Runtime/Textures/BufferedRTHandleSystem.cs @@ -143,6 +143,18 @@ public void ResetReferenceSize(int width, int height) m_RTHandleSystem.ResetReferenceSize(width, height); } + /// + /// Queries the number of RT handle buffers allocated for a buffer ID. + /// + /// The buffer ID to query. + public int GetNumFramesAllocated(int bufferId) + { + if (!m_RTHandles.ContainsKey(bufferId)) + return 0; + + return m_RTHandles[bufferId].Length; + } + void Swap() { foreach (var item in m_RTHandles) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 6ff40a07cad..c7971db9028 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -169,6 +169,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed NaNs when denoising pixels where the dot product between normal and view direction is near zero (case 1329624). - Fixed ray traced reflections that were too dark for unlit materials. Reflections are now more consistent with the material emissiveness. - Fixed pyramid color being incorrect when hardware dynamic resolution is enabled. +- Fixed issue with history buffer allocation for AOVs when the request does not come in first frame. ### Changed - Changed Window/Render Pipeline/HD Render Pipeline Wizard to Window/Rendering/HDRP Wizard diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index 746620132b4..04cda68e8ae 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -731,9 +731,11 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp, // If we have a mismatch with color buffer format we need to reallocate the pyramid var hdPipeline = (HDRenderPipeline)(RenderPipelineManager.currentPipeline); bool forceReallocPyramid = false; - if (m_NumColorPyramidBuffersAllocated > 0) + int colorBufferID = (int)HDCameraFrameHistoryType.ColorBufferMipChain; + int numColorPyramidBuffersAllocated = m_HistoryRTSystem.GetNumFramesAllocated(colorBufferID); + if (numColorPyramidBuffersAllocated > 0) { - var currPyramid = GetCurrentFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain); + var currPyramid = GetCurrentFrameRT(colorBufferID); if (currPyramid != null && currPyramid.rt.graphicsFormat != hdPipeline.GetColorBufferFormat()) { forceReallocPyramid = true; @@ -746,8 +748,18 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp, if (isHistoryColorPyramidRequired) // Superset of case above numColorPyramidBuffersRequired = 2; + // Check if we have any AOV requests that require history buffer allocations (the actual allocation happens later in this function) + foreach (var aovRequest in aovRequests) + { + var aovHistory = GetHistoryRTHandleSystem(aovRequest); + if (aovHistory.GetNumFramesAllocated(colorBufferID) != numColorPyramidBuffersRequired) + { + forceReallocPyramid = true; + } + } + // Handle the color buffers - if (m_NumColorPyramidBuffersAllocated != numColorPyramidBuffersRequired || forceReallocPyramid) + if (numColorPyramidBuffersAllocated != numColorPyramidBuffersRequired || forceReallocPyramid) { // Reinit the system. colorPyramidHistoryIsValid = false; @@ -775,9 +787,6 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp, } BindHistoryRTHandleSystem(cameraHistory); } - - // Mark as init. - m_NumColorPyramidBuffersAllocated = numColorPyramidBuffersRequired; } // Handle the volumetric fog buffers @@ -1210,7 +1219,6 @@ public RTHandle Allocator(string id, int frameIndex, RTHandleSystem rtHandleSyst HDAdditionalCameraData m_AdditionalCameraData = null; // Init in Update BufferedRTHandleSystem m_HistoryRTSystem = new BufferedRTHandleSystem(); - int m_NumColorPyramidBuffersAllocated = 0; int m_NumVolumetricBuffersAllocated = 0; float m_AmbientOcclusionResolutionScale = 0.0f; // Factor used to track if history should be reallocated for Ambient Occlusion float m_ScreenSpaceAccumulationResolutionScale = 0.0f; // Use another scale if AO & SSR don't have the same resolution From a0f859168521bc357b14ca6c553073315a9d0c0a Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Wed, 28 Apr 2021 17:24:47 +0200 Subject: [PATCH 2/2] Add a break in the for loop --- .../Runtime/RenderPipeline/Camera/HDCamera.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs index 04cda68e8ae..17879c80f9a 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Camera/HDCamera.cs @@ -755,6 +755,7 @@ internal void Update(FrameSettings currentFrameSettings, HDRenderPipeline hdrp, if (aovHistory.GetNumFramesAllocated(colorBufferID) != numColorPyramidBuffersRequired) { forceReallocPyramid = true; + break; } }