From d24aac50fb5098a63c6218e3bfbaac53364d8e11 Mon Sep 17 00:00:00 2001 From: Robin Date: Thu, 15 Oct 2020 17:44:32 +0100 Subject: [PATCH 1/5] Initial set of changes to make the intermediate targets use dynamic resolution instead of allocating them each frame at different sizes when dynamic resolution is on. This should reduce memory pressure and fragmentation. --- .../Runtime/Effects/MultiScaleVO.cs | 132 ++++++++++-------- 1 file changed, 76 insertions(+), 56 deletions(-) diff --git a/PostProcessing/Runtime/Effects/MultiScaleVO.cs b/PostProcessing/Runtime/Effects/MultiScaleVO.cs index b1beb1c5..0e6cea09 100644 --- a/PostProcessing/Runtime/Effects/MultiScaleVO.cs +++ b/PostProcessing/Runtime/Effects/MultiScaleVO.cs @@ -39,7 +39,11 @@ enum Pass readonly float[] m_InvThicknessTable = new float[12]; readonly float[] m_SampleWeightTable = new float[12]; - // Scaled dimensions used with dynamic resolution + // Unscaled dimensions used for allocating targets that might scale themselves. + readonly int[] m_Widths = new int[7]; + readonly int[] m_Heights = new int[7]; + + // Scaled dimensions adjusted for the current dynamic resolution scale readonly int[] m_ScaledWidths = new int[7]; readonly int[] m_ScaledHeights = new int[7]; @@ -74,13 +78,19 @@ public void SetResources(PostProcessResources resources) m_Resources = resources; } - void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav) + enum DynamicScale + { + Allow, + Disallow + }; + + void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav, DynamicScale dynamicScale) { int sizeId = (int)size; cmd.GetTemporaryRT(id, new RenderTextureDescriptor { - width = m_ScaledWidths[sizeId], - height = m_ScaledHeights[sizeId], + width = m_Widths[sizeId], + height = m_Heights[sizeId], colorFormat = format, depthBufferBits = 0, volumeDepth = 1, @@ -88,6 +98,9 @@ void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, msaaSamples = 1, #if UNITY_2019_2_OR_NEWER mipCount = 1, +#endif +#if UNITY_2017_3_OR_NEWER + useDynamicScale = dynamicScale == DynamicScale.Allow, #endif enableRandomWrite = uav, dimension = TextureDimension.Tex2D, @@ -95,13 +108,13 @@ void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, }, FilterMode.Point); } - void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav) + void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav, DynamicScale dynamicScale) { int sizeId = (int)size; cmd.GetTemporaryRT(id, new RenderTextureDescriptor { - width = m_ScaledWidths[sizeId], - height = m_ScaledHeights[sizeId], + width = m_Widths[sizeId], + height = m_Heights[sizeId], colorFormat = format, depthBufferBits = 0, volumeDepth = 16, @@ -109,6 +122,9 @@ void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat fo msaaSamples = 1, #if UNITY_2019_2_OR_NEWER mipCount = 1, +#endif +#if UNITY_2017_3_OR_NEWER + useDynamicScale = dynamicScale == DynamicScale.Allow, #endif enableRandomWrite = uav, dimension = TextureDimension.Tex2DArray, @@ -152,24 +168,27 @@ Vector3 GetSizeArray(MipLevel mip) public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifier destination, RenderTargetIdentifier? depthMap, bool invert, bool isMSAA) { // Base size + m_Widths[0] = m_ScaledWidths[0] = camera.pixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1); + m_Heights[0] = m_ScaledHeights[0] = camera.pixelHeight; #if UNITY_2017_3_OR_NEWER + // Adjust the scaled dimensions based off the dynamic resolution resolution used at the moment. m_ScaledWidths[0] = camera.scaledPixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1); m_ScaledHeights[0] = camera.scaledPixelHeight; -#else - m_ScaledWidths[0] = camera.pixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1); - m_ScaledHeights[0] = camera.pixelHeight; #endif - + Debug.LogFormat("ScaledWidth: {0}, ScaledHeight: {1}", m_ScaledWidths[0], m_ScaledHeights[0]); + // L1 -> L6 sizes for (int i = 1; i < 7; i++) { int div = 1 << i; + m_Widths[i] = (m_Widths[0] + (div - 1)) / div; + m_Heights[i] = (m_Heights[0] + (div - 1)) / div; m_ScaledWidths[i] = (m_ScaledWidths[0] + (div - 1)) / div; m_ScaledHeights[i] = (m_ScaledHeights[0] + (div - 1)) / div; } // Allocate temporary textures - PushAllocCommands(cmd, isMSAA); + PushAllocCommands(cmd, isMSAA, camera.allowDynamicResolution ? DynamicScale.Allow : DynamicScale.Disallow); // Render logic PushDownsampleCommands(cmd, camera, depthMap, isMSAA); @@ -189,53 +208,53 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi PushReleaseCommands(cmd); } - void PushAllocCommands(CommandBuffer cmd, bool isMSAA) + void PushAllocCommands(CommandBuffer cmd, bool isMSAA, DynamicScale dynamicScale) { if(isMSAA) { - Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RGHalf, true); - - Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RGFloat, true); - Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RGFloat, true); - Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RGFloat, true); - Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RGFloat, true); - - AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RGHalf, true); - AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RGHalf, true); - AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RGHalf, true); - AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RGHalf, true); - - Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.RG16, true); - Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.RG16, true); - Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.RG16, true); - Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.RG16, true); - - Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.RG16, true); - Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.RG16, true); - Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.RG16, true); + Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RGHalf, true, dynamicScale); + + Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RGFloat, true, dynamicScale); + Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RGFloat, true, dynamicScale); + Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RGFloat, true, dynamicScale); + Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RGFloat, true, dynamicScale); + + AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RGHalf, true, dynamicScale); + AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RGHalf, true, dynamicScale); + AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RGHalf, true, dynamicScale); + AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RGHalf, true, dynamicScale); + + Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.RG16, true, dynamicScale); + Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.RG16, true, dynamicScale); + Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.RG16, true, dynamicScale); + Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.RG16, true, dynamicScale); + + Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.RG16, true, dynamicScale); + Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.RG16, true, dynamicScale); + Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.RG16, true, dynamicScale); } else { - Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RHalf, true); - - Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RFloat, true); - Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RFloat, true); - Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RFloat, true); - Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RFloat, true); - - AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RHalf, true); - AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RHalf, true); - AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RHalf, true); - AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RHalf, true); - - Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.R8, true); - Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.R8, true); - Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.R8, true); - Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.R8, true); - - Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.R8, true); - Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.R8, true); - Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.R8, true); + Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RHalf, true, dynamicScale); + + Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RFloat, true, dynamicScale); + Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RFloat, true, dynamicScale); + Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RFloat, true, dynamicScale); + Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RFloat, true, dynamicScale); + + AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RHalf, true, dynamicScale); + AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RHalf, true, dynamicScale); + AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RHalf, true, dynamicScale); + AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RHalf, true, dynamicScale); + + Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.R8, true, dynamicScale); + Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.R8, true, dynamicScale); + Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.R8, true, dynamicScale); + Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.R8, true, dynamicScale); + + Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.R8, true, dynamicScale); + Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.R8, true, dynamicScale); + Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.R8, true, dynamicScale); } } @@ -254,7 +273,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti // buffer (it's only available in some specific situations). if (!RuntimeUtilities.IsResolvedDepthAvailable(camera)) { - Alloc(cmd, ShaderIDs.DepthCopy, MipLevel.Original, RenderTextureFormat.RFloat, false); + Alloc(cmd, ShaderIDs.DepthCopy, MipLevel.Original, RenderTextureFormat.RFloat, false, camera.allowDynamicResolution ? DynamicScale.Allow : DynamicScale.Disallow); depthMapId = new RenderTargetIdentifier(ShaderIDs.DepthCopy); cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, depthMapId, m_PropertySheet, (int)Pass.DepthCopy); needDepthMapRelease = true; @@ -463,9 +482,9 @@ void PreparePropertySheet(PostProcessRenderContext context) void CheckAOTexture(PostProcessRenderContext context) { bool AOUpdateNeeded = m_AmbientOnlyAO == null || !m_AmbientOnlyAO.IsCreated() || m_AmbientOnlyAO.width != context.width || m_AmbientOnlyAO.height != context.height; -#if UNITY_2017_3_OR_NEWER +#if UNITY_2017_3_OR_NEWER AOUpdateNeeded = AOUpdateNeeded || m_AmbientOnlyAO.useDynamicScale != context.camera.allowDynamicResolution; -#endif +#endif if (AOUpdateNeeded) { RuntimeUtilities.Destroy(m_AmbientOnlyAO); @@ -480,6 +499,7 @@ void CheckAOTexture(PostProcessRenderContext context) #endif }; m_AmbientOnlyAO.Create(); + Debug.Log("Creating New AO Texture"); } } From a58a6a0696cdfbfdab83fe52b5f7d3e13b29f8b4 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 16 Oct 2020 09:03:50 +0100 Subject: [PATCH 2/5] Tidy up the code. --- .../Runtime/Effects/MultiScaleVO.cs | 102 ++++++++---------- 1 file changed, 47 insertions(+), 55 deletions(-) diff --git a/PostProcessing/Runtime/Effects/MultiScaleVO.cs b/PostProcessing/Runtime/Effects/MultiScaleVO.cs index 0e6cea09..427be0ba 100644 --- a/PostProcessing/Runtime/Effects/MultiScaleVO.cs +++ b/PostProcessing/Runtime/Effects/MultiScaleVO.cs @@ -78,13 +78,7 @@ public void SetResources(PostProcessResources resources) m_Resources = resources; } - enum DynamicScale - { - Allow, - Disallow - }; - - void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav, DynamicScale dynamicScale) + void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav, bool dynamicScale) { int sizeId = (int)size; cmd.GetTemporaryRT(id, new RenderTextureDescriptor @@ -100,7 +94,7 @@ void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, mipCount = 1, #endif #if UNITY_2017_3_OR_NEWER - useDynamicScale = dynamicScale == DynamicScale.Allow, + useDynamicScale = dynamicScale, #endif enableRandomWrite = uav, dimension = TextureDimension.Tex2D, @@ -108,7 +102,7 @@ void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, }, FilterMode.Point); } - void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav, DynamicScale dynamicScale) + void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav, bool dynamicScale) { int sizeId = (int)size; cmd.GetTemporaryRT(id, new RenderTextureDescriptor @@ -124,7 +118,7 @@ void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat fo mipCount = 1, #endif #if UNITY_2017_3_OR_NEWER - useDynamicScale = dynamicScale == DynamicScale.Allow, + useDynamicScale = dynamicScale, #endif enableRandomWrite = uav, dimension = TextureDimension.Tex2DArray, @@ -175,7 +169,6 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi m_ScaledWidths[0] = camera.scaledPixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1); m_ScaledHeights[0] = camera.scaledPixelHeight; #endif - Debug.LogFormat("ScaledWidth: {0}, ScaledHeight: {1}", m_ScaledWidths[0], m_ScaledHeights[0]); // L1 -> L6 sizes for (int i = 1; i < 7; i++) @@ -188,7 +181,7 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi } // Allocate temporary textures - PushAllocCommands(cmd, isMSAA, camera.allowDynamicResolution ? DynamicScale.Allow : DynamicScale.Disallow); + PushAllocCommands(cmd, isMSAA, camera); // Render logic PushDownsampleCommands(cmd, camera, depthMap, isMSAA); @@ -208,53 +201,53 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi PushReleaseCommands(cmd); } - void PushAllocCommands(CommandBuffer cmd, bool isMSAA, DynamicScale dynamicScale) + void PushAllocCommands(CommandBuffer cmd, bool isMSAA, Camera camera) { if(isMSAA) { - Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RGHalf, true, dynamicScale); - - Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RGFloat, true, dynamicScale); - Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RGFloat, true, dynamicScale); - Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RGFloat, true, dynamicScale); - Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RGFloat, true, dynamicScale); - - AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RGHalf, true, dynamicScale); - AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RGHalf, true, dynamicScale); - AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RGHalf, true, dynamicScale); - AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RGHalf, true, dynamicScale); - - Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.RG16, true, dynamicScale); - Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.RG16, true, dynamicScale); - Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.RG16, true, dynamicScale); - Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.RG16, true, dynamicScale); - - Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.RG16, true, dynamicScale); - Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.RG16, true, dynamicScale); - Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.RG16, true, dynamicScale); + Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution); + + Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RGFloat, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RGFloat, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RGFloat, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RGFloat, true, camera.allowDynamicResolution); + + AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution); + AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution); + AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution); + AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RGHalf, true, camera.allowDynamicResolution); + + Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.RG16, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.RG16, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.RG16, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.RG16, true, camera.allowDynamicResolution); + + Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.RG16, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.RG16, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.RG16, true, camera.allowDynamicResolution); } else { - Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RHalf, true, dynamicScale); - - Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RFloat, true, dynamicScale); - Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RFloat, true, dynamicScale); - Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RFloat, true, dynamicScale); - Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RFloat, true, dynamicScale); - - AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RHalf, true, dynamicScale); - AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RHalf, true, dynamicScale); - AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RHalf, true, dynamicScale); - AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RHalf, true, dynamicScale); - - Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.R8, true, dynamicScale); - Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.R8, true, dynamicScale); - Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.R8, true, dynamicScale); - Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.R8, true, dynamicScale); - - Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.R8, true, dynamicScale); - Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.R8, true, dynamicScale); - Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.R8, true, dynamicScale); + Alloc(cmd, ShaderIDs.LinearDepth, MipLevel.Original, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution); + + Alloc(cmd, ShaderIDs.LowDepth1, MipLevel.L1, RenderTextureFormat.RFloat, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.LowDepth2, MipLevel.L2, RenderTextureFormat.RFloat, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.LowDepth3, MipLevel.L3, RenderTextureFormat.RFloat, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.LowDepth4, MipLevel.L4, RenderTextureFormat.RFloat, true, camera.allowDynamicResolution); + + AllocArray(cmd, ShaderIDs.TiledDepth1, MipLevel.L3, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution); + AllocArray(cmd, ShaderIDs.TiledDepth2, MipLevel.L4, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution); + AllocArray(cmd, ShaderIDs.TiledDepth3, MipLevel.L5, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution); + AllocArray(cmd, ShaderIDs.TiledDepth4, MipLevel.L6, RenderTextureFormat.RHalf, true, camera.allowDynamicResolution); + + Alloc(cmd, ShaderIDs.Occlusion1, MipLevel.L1, RenderTextureFormat.R8, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Occlusion2, MipLevel.L2, RenderTextureFormat.R8, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Occlusion3, MipLevel.L3, RenderTextureFormat.R8, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Occlusion4, MipLevel.L4, RenderTextureFormat.R8, true, camera.allowDynamicResolution); + + Alloc(cmd, ShaderIDs.Combined1, MipLevel.L1, RenderTextureFormat.R8, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Combined2, MipLevel.L2, RenderTextureFormat.R8, true, camera.allowDynamicResolution); + Alloc(cmd, ShaderIDs.Combined3, MipLevel.L3, RenderTextureFormat.R8, true, camera.allowDynamicResolution); } } @@ -273,7 +266,7 @@ void PushDownsampleCommands(CommandBuffer cmd, Camera camera, RenderTargetIdenti // buffer (it's only available in some specific situations). if (!RuntimeUtilities.IsResolvedDepthAvailable(camera)) { - Alloc(cmd, ShaderIDs.DepthCopy, MipLevel.Original, RenderTextureFormat.RFloat, false, camera.allowDynamicResolution ? DynamicScale.Allow : DynamicScale.Disallow); + Alloc(cmd, ShaderIDs.DepthCopy, MipLevel.Original, RenderTextureFormat.RFloat, false, camera.allowDynamicResolution); depthMapId = new RenderTargetIdentifier(ShaderIDs.DepthCopy); cmd.BlitFullscreenTriangle(BuiltinRenderTextureType.None, depthMapId, m_PropertySheet, (int)Pass.DepthCopy); needDepthMapRelease = true; @@ -499,7 +492,6 @@ void CheckAOTexture(PostProcessRenderContext context) #endif }; m_AmbientOnlyAO.Create(); - Debug.Log("Creating New AO Texture"); } } From 3c4d70b2b27c2638ed696533c8ec94ec0b0eddbb Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 16 Oct 2020 09:11:50 +0100 Subject: [PATCH 3/5] Update package version to 3.0.1 and add CHANGELOG entry --- CHANGELOG.md | 4 ++++ package.json | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2252b519..7b28a643 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [3.0.1] - 2020-10-16 +### Fixed +- Fix for MSVO when used with dynamic resolution reallocating temp render targets whenever the dynamic resolution scale was changed. Now those temp targets will use dynamic scaling as well. This will require a matching fix in Unity to work correctly (ADD COMPATIBLE VERSIONS HERE). (case XXXXXX). + ## [3.0.0] - 2020-10-13 ### Fixed diff --git a/package.json b/package.json index 5fe7c695..95cc4dca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.unity.postprocessing", - "version": "3.0.0", + "version": "3.0.1", "displayName": "Post Processing", "unity": "2018.4", "description": "The post-processing stack (v2) comes with a collection of effects and image filters you can apply to your cameras to improve the visuals of your games.", From 675a432caa8429ed2491c15adeb843f457a86907 Mon Sep 17 00:00:00 2001 From: Robin Date: Fri, 16 Oct 2020 11:07:08 +0100 Subject: [PATCH 4/5] Fix 2018.4 not compiling. This will also mean players < 2019.4 keep using the existing codepath as the new codepath shows up a bug that needs fixing in Unity. --- PostProcessing/Runtime/Effects/MultiScaleVO.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/PostProcessing/Runtime/Effects/MultiScaleVO.cs b/PostProcessing/Runtime/Effects/MultiScaleVO.cs index 427be0ba..d1de1d6f 100644 --- a/PostProcessing/Runtime/Effects/MultiScaleVO.cs +++ b/PostProcessing/Runtime/Effects/MultiScaleVO.cs @@ -81,10 +81,16 @@ public void SetResources(PostProcessResources resources) void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav, bool dynamicScale) { int sizeId = (int)size; + cmd.GetTemporaryRT(id, new RenderTextureDescriptor { +#if UNITY_2019_4_OR_NEWER width = m_Widths[sizeId], height = m_Heights[sizeId], +#else + width = m_ScaledWidths[sizeId], + height = m_ScaledHeights[sizeId], +#endif colorFormat = format, depthBufferBits = 0, volumeDepth = 1, @@ -93,7 +99,7 @@ void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, #if UNITY_2019_2_OR_NEWER mipCount = 1, #endif -#if UNITY_2017_3_OR_NEWER +#if UNITY_2019_4_OR_NEWER useDynamicScale = dynamicScale, #endif enableRandomWrite = uav, @@ -105,10 +111,16 @@ void Alloc(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat format, bool uav, bool dynamicScale) { int sizeId = (int)size; + cmd.GetTemporaryRT(id, new RenderTextureDescriptor { +#if UNITY_2019_4_OR_NEWER width = m_Widths[sizeId], height = m_Heights[sizeId], +#else + width = m_ScaledWidths[sizeId], + height = m_ScaledHeights[sizeId], +#endif colorFormat = format, depthBufferBits = 0, volumeDepth = 16, @@ -117,7 +129,7 @@ void AllocArray(CommandBuffer cmd, int id, MipLevel size, RenderTextureFormat fo #if UNITY_2019_2_OR_NEWER mipCount = 1, #endif -#if UNITY_2017_3_OR_NEWER +#if UNITY_2019_4_OR_NEWER useDynamicScale = dynamicScale, #endif enableRandomWrite = uav, From 6f83a6d0274fac96c83ec089bba1cd28da78a4bd Mon Sep 17 00:00:00 2001 From: Robin Date: Wed, 21 Oct 2020 14:57:38 +0100 Subject: [PATCH 5/5] Fix resolutions some scaling factors causing the dynamic resolution to calculate the texture size as one size but the m_Scaled(Width|Height) calculation was not quite the same and caused the wrong number of dispatches to be generated. And example is a base image size of 2160p scaled down to 2142p causing a mismatch in the height. --- PostProcessing/Runtime/Effects/MultiScaleVO.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/PostProcessing/Runtime/Effects/MultiScaleVO.cs b/PostProcessing/Runtime/Effects/MultiScaleVO.cs index d1de1d6f..aa105342 100644 --- a/PostProcessing/Runtime/Effects/MultiScaleVO.cs +++ b/PostProcessing/Runtime/Effects/MultiScaleVO.cs @@ -180,16 +180,19 @@ public void GenerateAOMap(CommandBuffer cmd, Camera camera, RenderTargetIdentifi // Adjust the scaled dimensions based off the dynamic resolution resolution used at the moment. m_ScaledWidths[0] = camera.scaledPixelWidth * (RuntimeUtilities.isSinglePassStereoEnabled ? 2 : 1); m_ScaledHeights[0] = camera.scaledPixelHeight; -#endif - +#endif + float widthScalingFactor = ScalableBufferManager.widthScaleFactor; + float heightScalingFactor = ScalableBufferManager.heightScaleFactor; // L1 -> L6 sizes for (int i = 1; i < 7; i++) { int div = 1 << i; m_Widths[i] = (m_Widths[0] + (div - 1)) / div; m_Heights[i] = (m_Heights[0] + (div - 1)) / div; - m_ScaledWidths[i] = (m_ScaledWidths[0] + (div - 1)) / div; - m_ScaledHeights[i] = (m_ScaledHeights[0] + (div - 1)) / div; + // Scaled width and heights have to match their calculations like will happen with dynamic resolution otherwise with odd numbers you can get a difference between what the dynamic resolution version + // generates and what we use here. + m_ScaledWidths[i] = Mathf.CeilToInt(m_Widths[i] * widthScalingFactor); + m_ScaledHeights[i] = Mathf.CeilToInt(m_Heights[i] * heightScalingFactor); } // Allocate temporary textures