From 5b9ab82e845ef3235e4a32b0408035ca14296dd0 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Thu, 24 Sep 2020 10:14:09 +0200 Subject: [PATCH 1/3] Fix accumulation on DX11 --- .../CHANGELOG.md | 1 + .../Documentation~/Accumulation.md | 2 +- .../Accumulation/Shaders/Accumulation.compute | 11 ++++++++++- .../Accumulation/SubFrameManager.cs | 17 ++++++++++++++--- .../HDRenderPipeline.RenderGraph.cs | 3 ++- 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 518105d4800..fabe1d523ae 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -83,6 +83,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixed SSGI compilation issues on PS4. - Fixed "Screen position out of view frustum" error when camera is on exactly the planar reflection probe plane. - Workaround issue that caused objects using eye shader to not be rendered on xbox. +- Fixed accumulation on DX11 ### Changed - Preparation pass for RTSSShadows to be supported by render graph. diff --git a/com.unity.render-pipelines.high-definition/Documentation~/Accumulation.md b/com.unity.render-pipelines.high-definition/Documentation~/Accumulation.md index b0c50801f05..953427d9968 100644 --- a/com.unity.render-pipelines.high-definition/Documentation~/Accumulation.md +++ b/com.unity.render-pipelines.high-definition/Documentation~/Accumulation.md @@ -69,7 +69,7 @@ public class FrameManager : MonoBehaviour { RenderPipelineManager.beginFrameRendering -= PrepareSubFrameCallBack; HDRenderPipeline renderPipeline = RenderPipelineManager.currentPipeline as HDRenderPipeline; - renderPipeline.EndRecording(); + renderPipeline?.EndRecording(); m_Recording = false; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/Shaders/Accumulation.compute b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/Shaders/Accumulation.compute index 9f5ca00ba16..2b9c8159d3f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/Shaders/Accumulation.compute +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/Shaders/Accumulation.compute @@ -4,8 +4,13 @@ #pragma kernel KMain +#pragma multi_compile _ INPUT_FROM_RADIANCE_TEXTURE + // Inputs +#ifdef INPUT_FROM_RADIANCE_TEXTURE TEXTURE2D_X(_RadianceTexture); +#endif + float4 _AccumulationWeights; int _AccumulationNeedsExposure; uint _AccumulationFrameIndex; @@ -55,8 +60,12 @@ void KMain(uint3 dispatchThreadId : SV_DispatchThreadID) _CameraColorTextureRW[COORD_TEXTURE2D_X(currentPixelCoord)] = float4(_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)].xyz * exposureMultiplier, 1.0); } else - { + { +#ifdef INPUT_FROM_RADIANCE_TEXTURE float4 color = _RadianceTexture[COORD_TEXTURE2D_X(dispatchThreadId.xy)]; +#else + float4 color = _CameraColorTextureRW[COORD_TEXTURE2D_X(dispatchThreadId.xy)]; +#endif if (sampleCount++) color.xyz = (_AccumulatedFrameTexture[COORD_TEXTURE2D_X(currentPixelCoord)].xyz * _AccumulationWeights.y + _AccumulationWeights.x * color.xyz) * _AccumulationWeights.z; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs index 77a31cadace..e3a69909a21 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs @@ -291,7 +291,7 @@ struct RenderAccumulationParameters public HDCamera hdCamera; } - RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCamera, bool needExposure) + RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCamera, bool needExposure, bool inputFromRadianceTexture) { var parameters = new RenderAccumulationParameters(); @@ -301,6 +301,11 @@ RenderAccumulationParameters PrepareRenderAccumulationParameters(HDCamera hdCame parameters.needExposure = needExposure; parameters.hdCamera = hdCamera; + parameters.accumulationCS.shaderKeywords = null; + if (inputFromRadianceTexture) + { + parameters.accumulationCS.EnableKeyword("INPUT_FROM_RADIANCE_TEXTURE"); + } return parameters; } @@ -310,7 +315,8 @@ void RenderAccumulation(HDCamera hdCamera, RTHandle inputTexture, RTHandle outpu RTHandle history = hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1); - var parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure); + bool inputFromRadianceTexture = !inputTexture.Equals(outputTexture); + var parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure, inputFromRadianceTexture); RenderAccumulation(parameters, inputTexture, outputTexture, history, cmd); } @@ -332,11 +338,16 @@ static void RenderAccumulation(in RenderAccumulationParameters parameters, RTHan cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNumSamples, (int)parameters.subFrameManager.subFrameCount); cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._AccumulatedFrameTexture, historyTexture); cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._CameraColorTextureRW, outputTexture); - cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture); cmd.SetComputeVectorParam(accumulationShader, HDShaderIDs._AccumulationWeights, frameWeights); cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNeedsExposure, parameters.needExposure ? 1 : 0); cmd.DispatchCompute(accumulationShader, parameters.accumulationKernel, (parameters.hdCamera.actualWidth + 7) / 8, (parameters.hdCamera.actualHeight + 7) / 8, parameters.hdCamera.viewCount); + accumulationShader.shaderKeywords = null; + if (!inputTexture.Equals(outputTexture)) + { + cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture); + } + // Increment the iteration counter, if we haven't converged yet if (camData.currentIteration < parameters.subFrameManager.subFrameCount) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs index 3f69ac60fee..237c92f4e94 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs @@ -1396,7 +1396,8 @@ void RenderAccumulation(RenderGraph renderGraph, HDCamera hdCamera, TextureHandl TextureHandle history = renderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.PathTracing) ?? hdCamera.AllocHistoryFrameRT((int)HDCameraFrameHistoryType.PathTracing, PathTracingHistoryBufferAllocatorFunction, 1)); - passData.parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure); + bool inputFromRadianceTexture = !inputTexture.Equals(outputTexture); + passData.parameters = PrepareRenderAccumulationParameters(hdCamera, needExposure, inputFromRadianceTexture); passData.input = builder.ReadTexture(inputTexture); passData.output = builder.WriteTexture(outputTexture); passData.history = builder.WriteTexture(history); From be940d68a794cb83f926994abf8c40bf510b5086 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Thu, 24 Sep 2020 10:58:44 +0200 Subject: [PATCH 2/3] Remove left-over line of code --- .../Runtime/RenderPipeline/Accumulation/SubFrameManager.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs index e3a69909a21..0d34ba8b836 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs @@ -342,7 +342,6 @@ static void RenderAccumulation(in RenderAccumulationParameters parameters, RTHan cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNeedsExposure, parameters.needExposure ? 1 : 0); cmd.DispatchCompute(accumulationShader, parameters.accumulationKernel, (parameters.hdCamera.actualWidth + 7) / 8, (parameters.hdCamera.actualHeight + 7) / 8, parameters.hdCamera.viewCount); - accumulationShader.shaderKeywords = null; if (!inputTexture.Equals(outputTexture)) { cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture); From 2441caccbbda23046f1848f43b3205713612b467 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Thu, 24 Sep 2020 11:27:04 +0200 Subject: [PATCH 3/3] minor bugfix --- .../Runtime/RenderPipeline/Accumulation/SubFrameManager.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs index 0d34ba8b836..640f179af0b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/Accumulation/SubFrameManager.cs @@ -338,14 +338,13 @@ static void RenderAccumulation(in RenderAccumulationParameters parameters, RTHan cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNumSamples, (int)parameters.subFrameManager.subFrameCount); cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._AccumulatedFrameTexture, historyTexture); cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._CameraColorTextureRW, outputTexture); - cmd.SetComputeVectorParam(accumulationShader, HDShaderIDs._AccumulationWeights, frameWeights); - cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNeedsExposure, parameters.needExposure ? 1 : 0); - cmd.DispatchCompute(accumulationShader, parameters.accumulationKernel, (parameters.hdCamera.actualWidth + 7) / 8, (parameters.hdCamera.actualHeight + 7) / 8, parameters.hdCamera.viewCount); - if (!inputTexture.Equals(outputTexture)) { cmd.SetComputeTextureParam(accumulationShader, parameters.accumulationKernel, HDShaderIDs._RadianceTexture, inputTexture); } + cmd.SetComputeVectorParam(accumulationShader, HDShaderIDs._AccumulationWeights, frameWeights); + cmd.SetComputeIntParam(accumulationShader, HDShaderIDs._AccumulationNeedsExposure, parameters.needExposure ? 1 : 0); + cmd.DispatchCompute(accumulationShader, parameters.accumulationKernel, (parameters.hdCamera.actualWidth + 7) / 8, (parameters.hdCamera.actualHeight + 7) / 8, parameters.hdCamera.viewCount); // Increment the iteration counter, if we haven't converged yet if (camData.currentIteration < parameters.subFrameManager.subFrameCount)