From 3947fb1d2bd7275c12a4a6e395b5c44c6f1e6d63 Mon Sep 17 00:00:00 2001 From: David Berger Date: Wed, 13 Oct 2021 13:23:26 -0700 Subject: [PATCH 1/7] Add adaptive performance decals scaler options. --- .../CHANGELOG.md | 1 + .../Entities/DecalCreateDrawCallSystem.cs | 18 +++++++++++++++--- ...ty.RenderPipelines.Universal.Runtime.asmdef | 5 +++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.universal/CHANGELOG.md b/com.unity.render-pipelines.universal/CHANGELOG.md index 9c8cf0745cc..845c642b6b6 100644 --- a/com.unity.render-pipelines.universal/CHANGELOG.md +++ b/com.unity.render-pipelines.universal/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added Depth Texture setting for Overlay Camera. - Added Depth Priming support for Vulkan with MSAA. - Added Shadows and Additional Lights off variants stripping. +- Added Adaptive Performance Decals scaler. ### Changed diff --git a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs index 90d6e6149d8..b25db665709 100644 --- a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs +++ b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs @@ -62,24 +62,36 @@ internal class DecalCreateDrawCallSystem private DecalEntityManager m_EntityManager; private ProfilingSampler m_Sampler; private float m_MaxDrawDistance; +#if ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER + private UniversalRenderPipelineAsset m_pipelineAsset; +#endif public DecalCreateDrawCallSystem(DecalEntityManager entityManager, float maxDrawDistance) { m_EntityManager = entityManager; m_Sampler = new ProfilingSampler("DecalCreateDrawCallSystem.Execute"); m_MaxDrawDistance = maxDrawDistance; +#if ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER + m_pipelineAsset = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset; +#endif } public void Execute() { + float maximumDrawDistance = m_MaxDrawDistance; +#if ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER + if (m_pipelineAsset.useAdaptivePerformance) + maximumDrawDistance = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; +#endif + using (new ProfilingScope(null, m_Sampler)) { for (int i = 0; i < m_EntityManager.chunkCount; ++i) - Execute(m_EntityManager.cachedChunks[i], m_EntityManager.culledChunks[i], m_EntityManager.drawCallChunks[i], m_EntityManager.cachedChunks[i].count); + Execute(m_EntityManager.cachedChunks[i], m_EntityManager.culledChunks[i], m_EntityManager.drawCallChunks[i], m_EntityManager.cachedChunks[i].count, maximumDrawDistance); } } - private void Execute(DecalCachedChunk cachedChunk, DecalCulledChunk culledChunk, DecalDrawCallChunk drawCallChunk, int count) + private void Execute(DecalCachedChunk cachedChunk, DecalCulledChunk culledChunk, DecalDrawCallChunk drawCallChunk, int count, float maximumDrawDistance) { if (count == 0) return; @@ -102,7 +114,7 @@ private void Execute(DecalCachedChunk cachedChunk, DecalCulledChunk culledChunk, cullingMask = culledChunk.cullingMask, visibleDecalIndices = culledChunk.visibleDecalIndices, visibleDecalCount = culledChunk.visibleDecalCount, - maxDrawDistance = m_MaxDrawDistance, + maxDrawDistance = maximumDrawDistance, decalToWorldsDraw = drawCallChunk.decalToWorlds, normalToDecalsDraw = drawCallChunk.normalToDecals, diff --git a/com.unity.render-pipelines.universal/Runtime/Unity.RenderPipelines.Universal.Runtime.asmdef b/com.unity.render-pipelines.universal/Runtime/Unity.RenderPipelines.Universal.Runtime.asmdef index a9931382de3..ea8506cb533 100644 --- a/com.unity.render-pipelines.universal/Runtime/Unity.RenderPipelines.Universal.Runtime.asmdef +++ b/com.unity.render-pipelines.universal/Runtime/Unity.RenderPipelines.Universal.Runtime.asmdef @@ -31,6 +31,11 @@ "expression": "2.1.0", "define": "ADAPTIVE_PERFORMANCE_2_1_0_OR_NEWER" }, + { + "name": "com.unity.adaptiveperformance", + "expression": "4.0.0-pre.1", + "define": "ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER" + }, { "name": "com.unity.burst", "expression": "1.0.0", From 238dcc71c89e6f244de4ef093b713e666c138f9c Mon Sep 17 00:00:00 2001 From: David Berger Date: Mon, 18 Oct 2021 08:48:02 -0700 Subject: [PATCH 2/7] Move logic to DecalRenderFeature to remove dependency of Rendering Asset. --- .../Entities/DecalCreateDrawCallSystem.cs | 22 +++++-------------- .../Entities/DecalUpdateCullingGroupSystem.cs | 6 ++--- .../RendererFeatures/DecalRendererFeature.cs | 15 +++++++++++++ 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs index b25db665709..d0d1e0331d0 100644 --- a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs +++ b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs @@ -61,37 +61,25 @@ internal class DecalCreateDrawCallSystem { private DecalEntityManager m_EntityManager; private ProfilingSampler m_Sampler; - private float m_MaxDrawDistance; -#if ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER - private UniversalRenderPipelineAsset m_pipelineAsset; -#endif + public float maxDrawDistance; public DecalCreateDrawCallSystem(DecalEntityManager entityManager, float maxDrawDistance) { m_EntityManager = entityManager; m_Sampler = new ProfilingSampler("DecalCreateDrawCallSystem.Execute"); - m_MaxDrawDistance = maxDrawDistance; -#if ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER - m_pipelineAsset = GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset; -#endif + this.maxDrawDistance = maxDrawDistance; } public void Execute() { - float maximumDrawDistance = m_MaxDrawDistance; -#if ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER - if (m_pipelineAsset.useAdaptivePerformance) - maximumDrawDistance = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; -#endif - using (new ProfilingScope(null, m_Sampler)) { for (int i = 0; i < m_EntityManager.chunkCount; ++i) - Execute(m_EntityManager.cachedChunks[i], m_EntityManager.culledChunks[i], m_EntityManager.drawCallChunks[i], m_EntityManager.cachedChunks[i].count, maximumDrawDistance); + Execute(m_EntityManager.cachedChunks[i], m_EntityManager.culledChunks[i], m_EntityManager.drawCallChunks[i], m_EntityManager.cachedChunks[i].count); } } - private void Execute(DecalCachedChunk cachedChunk, DecalCulledChunk culledChunk, DecalDrawCallChunk drawCallChunk, int count, float maximumDrawDistance) + private void Execute(DecalCachedChunk cachedChunk, DecalCulledChunk culledChunk, DecalDrawCallChunk drawCallChunk, int count) { if (count == 0) return; @@ -114,7 +102,7 @@ private void Execute(DecalCachedChunk cachedChunk, DecalCulledChunk culledChunk, cullingMask = culledChunk.cullingMask, visibleDecalIndices = culledChunk.visibleDecalIndices, visibleDecalCount = culledChunk.visibleDecalCount, - maxDrawDistance = maximumDrawDistance, + maxDrawDistance = maxDrawDistance, decalToWorldsDraw = drawCallChunk.decalToWorlds, normalToDecalsDraw = drawCallChunk.normalToDecals, diff --git a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalUpdateCullingGroupSystem.cs b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalUpdateCullingGroupSystem.cs index 24e1610d3a4..43728a61b00 100644 --- a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalUpdateCullingGroupSystem.cs +++ b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalUpdateCullingGroupSystem.cs @@ -52,7 +52,7 @@ public override void Dispose() /// internal class DecalUpdateCullingGroupSystem { - private float[] m_BoundingDistance = new float[1]; + public float[] boundingDistance = new float[1]; private Camera m_Camera; private DecalEntityManager m_EntityManager; private ProfilingSampler m_Sampler; @@ -60,7 +60,7 @@ internal class DecalUpdateCullingGroupSystem public DecalUpdateCullingGroupSystem(DecalEntityManager entityManager, float drawDistance) { m_EntityManager = entityManager; - m_BoundingDistance[0] = drawDistance; + boundingDistance[0] = drawDistance; m_Sampler = new ProfilingSampler("DecalUpdateCullingGroupsSystem.Execute"); } @@ -81,7 +81,7 @@ public void Execute(DecalCachedChunk cachedChunk, DecalCulledChunk culledChunk, CullingGroup cullingGroup = culledChunk.cullingGroups; cullingGroup.targetCamera = m_Camera; cullingGroup.SetDistanceReferencePoint(m_Camera.transform.position); - cullingGroup.SetBoundingDistances(m_BoundingDistance); + cullingGroup.SetBoundingDistances(boundingDistance); cachedChunk.boundingSpheres.CopyTo(cachedChunk.boundingSphereArray); cullingGroup.SetBoundingSpheres(cachedChunk.boundingSphereArray); cullingGroup.SetBoundingSphereCount(count); diff --git a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs index 7dd94364e29..91baf856eec 100644 --- a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs +++ b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using UnityEngine.Assertions; using UnityEngine.Rendering.Universal.Internal; @@ -406,6 +407,8 @@ public override void OnCameraPreCull(ScriptableRenderer renderer, in CameraData RecreateSystemsIfNeeded(renderer, cameraData); + ChangeAdaptivePerformanceDrawDistances(); + m_DecalEntityManager.Update(); @@ -443,6 +446,8 @@ public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingD RecreateSystemsIfNeeded(renderer, renderingData.cameraData); + ChangeAdaptivePerformanceDrawDistances(); + if (intermediateRendering) { m_DecalUpdateCulledSystem.Execute(); @@ -494,5 +499,15 @@ protected override void Dispose(bool disposing) sharedDecalEntityManager.Release(m_DecalEntityManager); } } + + [Conditional("ADAPTIVE_PERFORMANCE_2_1_0_OR_NEWER")] + private void ChangeAdaptivePerformanceDrawDistances() + { + if (UniversalRenderPipeline.asset.useAdaptivePerformance) + { + m_DecalCreateDrawCallSystem.maxDrawDistance = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; + m_DecalUpdateCullingGroupSystem.boundingDistance[0] = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; + } + } } } From 23ad48cd24f9efa4f8bcfb1864069dab11d9721e Mon Sep 17 00:00:00 2001 From: David Berger Date: Mon, 18 Oct 2021 08:49:44 -0700 Subject: [PATCH 3/7] Fixed old define. --- .../Runtime/RendererFeatures/DecalRendererFeature.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs index 91baf856eec..ae57ccf4aba 100644 --- a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs +++ b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs @@ -500,7 +500,7 @@ protected override void Dispose(bool disposing) } } - [Conditional("ADAPTIVE_PERFORMANCE_2_1_0_OR_NEWER")] + [Conditional("ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER")] private void ChangeAdaptivePerformanceDrawDistances() { if (UniversalRenderPipeline.asset.useAdaptivePerformance) From ed9e890844298e6e49840cc69b288f7b188828c4 Mon Sep 17 00:00:00 2001 From: David Berger Date: Mon, 18 Oct 2021 09:02:55 -0700 Subject: [PATCH 4/7] Added some safeguards for edtitor. --- .../Runtime/RendererFeatures/DecalRendererFeature.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs index ae57ccf4aba..66cdde83cb7 100644 --- a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs +++ b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs @@ -505,8 +505,10 @@ private void ChangeAdaptivePerformanceDrawDistances() { if (UniversalRenderPipeline.asset.useAdaptivePerformance) { - m_DecalCreateDrawCallSystem.maxDrawDistance = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; - m_DecalUpdateCullingGroupSystem.boundingDistance[0] = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; + if(m_DecalCreateDrawCallSystem != null) + m_DecalCreateDrawCallSystem.maxDrawDistance = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; + if (m_DecalUpdateCullingGroupSystem != null) + m_DecalUpdateCullingGroupSystem.boundingDistance[0] = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; } } } From 95909da44ed2ebd0e2b0835ab52d7167702bbb1b Mon Sep 17 00:00:00 2001 From: David Berger Date: Mon, 18 Oct 2021 11:16:15 -0700 Subject: [PATCH 5/7] fix fomrating --- .../Runtime/RendererFeatures/DecalRendererFeature.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs index 66cdde83cb7..fdd5d140c63 100644 --- a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs +++ b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs @@ -505,10 +505,14 @@ private void ChangeAdaptivePerformanceDrawDistances() { if (UniversalRenderPipeline.asset.useAdaptivePerformance) { - if(m_DecalCreateDrawCallSystem != null) + if (m_DecalCreateDrawCallSystem != null) + { m_DecalCreateDrawCallSystem.maxDrawDistance = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; + } if (m_DecalUpdateCullingGroupSystem != null) + { m_DecalUpdateCullingGroupSystem.boundingDistance[0] = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; + } } } } From 69f0fc45dc7ab8d53c0bbd04a7a5b721209ea31c Mon Sep 17 00:00:00 2001 From: David Berger Date: Tue, 19 Oct 2021 09:12:25 -0700 Subject: [PATCH 6/7] Upgrade to properties. --- .../Decal/Entities/DecalCreateDrawCallSystem.cs | 15 ++++++++++++--- .../Entities/DecalUpdateCullingGroupSystem.cs | 15 ++++++++++++--- .../RendererFeatures/DecalRendererFeature.cs | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs index d0d1e0331d0..de7926bb2cd 100644 --- a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs +++ b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalCreateDrawCallSystem.cs @@ -61,13 +61,22 @@ internal class DecalCreateDrawCallSystem { private DecalEntityManager m_EntityManager; private ProfilingSampler m_Sampler; - public float maxDrawDistance; + private float m_MaxDrawDistance; + + /// + /// Provides acces to the maximum draw distance. + /// + public float maxDrawDistance + { + get { return m_MaxDrawDistance; } + set { m_MaxDrawDistance = value; } + } public DecalCreateDrawCallSystem(DecalEntityManager entityManager, float maxDrawDistance) { m_EntityManager = entityManager; m_Sampler = new ProfilingSampler("DecalCreateDrawCallSystem.Execute"); - this.maxDrawDistance = maxDrawDistance; + m_MaxDrawDistance = maxDrawDistance; } public void Execute() @@ -102,7 +111,7 @@ private void Execute(DecalCachedChunk cachedChunk, DecalCulledChunk culledChunk, cullingMask = culledChunk.cullingMask, visibleDecalIndices = culledChunk.visibleDecalIndices, visibleDecalCount = culledChunk.visibleDecalCount, - maxDrawDistance = maxDrawDistance, + maxDrawDistance = m_MaxDrawDistance, decalToWorldsDraw = drawCallChunk.decalToWorlds, normalToDecalsDraw = drawCallChunk.normalToDecals, diff --git a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalUpdateCullingGroupSystem.cs b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalUpdateCullingGroupSystem.cs index 43728a61b00..67b5d5523e4 100644 --- a/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalUpdateCullingGroupSystem.cs +++ b/com.unity.render-pipelines.universal/Runtime/Decal/Entities/DecalUpdateCullingGroupSystem.cs @@ -52,7 +52,16 @@ public override void Dispose() /// internal class DecalUpdateCullingGroupSystem { - public float[] boundingDistance = new float[1]; + /// + /// Provides acces to the bounding distance. + /// + public float boundingDistance + { + get { return m_BoundingDistance[0]; } + set { m_BoundingDistance[0] = value; } + } + + private float[] m_BoundingDistance = new float[1]; private Camera m_Camera; private DecalEntityManager m_EntityManager; private ProfilingSampler m_Sampler; @@ -60,7 +69,7 @@ internal class DecalUpdateCullingGroupSystem public DecalUpdateCullingGroupSystem(DecalEntityManager entityManager, float drawDistance) { m_EntityManager = entityManager; - boundingDistance[0] = drawDistance; + m_BoundingDistance[0] = drawDistance; m_Sampler = new ProfilingSampler("DecalUpdateCullingGroupsSystem.Execute"); } @@ -81,7 +90,7 @@ public void Execute(DecalCachedChunk cachedChunk, DecalCulledChunk culledChunk, CullingGroup cullingGroup = culledChunk.cullingGroups; cullingGroup.targetCamera = m_Camera; cullingGroup.SetDistanceReferencePoint(m_Camera.transform.position); - cullingGroup.SetBoundingDistances(boundingDistance); + cullingGroup.SetBoundingDistances(m_BoundingDistance); cachedChunk.boundingSpheres.CopyTo(cachedChunk.boundingSphereArray); cullingGroup.SetBoundingSpheres(cachedChunk.boundingSphereArray); cullingGroup.SetBoundingSphereCount(count); diff --git a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs index fdd5d140c63..045c87c82ad 100644 --- a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs +++ b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs @@ -511,7 +511,7 @@ private void ChangeAdaptivePerformanceDrawDistances() } if (m_DecalUpdateCullingGroupSystem != null) { - m_DecalUpdateCullingGroupSystem.boundingDistance[0] = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; + m_DecalUpdateCullingGroupSystem.boundingDistance = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; } } } From b68a34ba329c1b82970f8fe3eb58f30d7ea2ae72 Mon Sep 17 00:00:00 2001 From: David Berger Date: Wed, 20 Oct 2021 09:49:39 -0700 Subject: [PATCH 7/7] Add missing #if --- .../Runtime/RendererFeatures/DecalRendererFeature.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs index 045c87c82ad..b376e27e410 100644 --- a/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs +++ b/com.unity.render-pipelines.universal/Runtime/RendererFeatures/DecalRendererFeature.cs @@ -503,6 +503,7 @@ protected override void Dispose(bool disposing) [Conditional("ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER")] private void ChangeAdaptivePerformanceDrawDistances() { +#if ADAPTIVE_PERFORMANCE_4_0_0_OR_NEWER if (UniversalRenderPipeline.asset.useAdaptivePerformance) { if (m_DecalCreateDrawCallSystem != null) @@ -514,6 +515,7 @@ private void ChangeAdaptivePerformanceDrawDistances() m_DecalUpdateCullingGroupSystem.boundingDistance = AdaptivePerformance.AdaptivePerformanceRenderSettings.DecalsDrawDistance; } } +#endif } } }