From 11eadbd68923f950d9bd4b8b31339507bba21358 Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 16 Jun 2020 14:25:35 +0200 Subject: [PATCH 1/2] Change unity version guards for ESRAM --- .../RenderGraph/RenderGraphResourceRegistry.cs | 6 ++++++ .../Runtime/Textures/RTHandle.cs | 7 +++---- .../RenderPipeline/HDRenderPipeline.Prepass.cs | 14 ++++++++++++-- .../RenderPipeline/HDRenderPipeline.RenderGraph.cs | 9 +++++++-- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 6 +++++- 5 files changed, 33 insertions(+), 9 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index 8722df245d9..f464b1c8a4c 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -118,6 +118,7 @@ public enum TextureSizeMode Functor } +#if UNITY_2020_2_OR_NEWER /// /// Subset of the texture desc containing information for fast memory allocation (when platform supports it) /// @@ -130,6 +131,7 @@ public struct FastMemoryDesc ///How much of the render target is to be switched into fast memory (between 0 and 1). public float residencyFraction; } +#endif /// /// Descriptor used to create texture resources @@ -182,8 +184,10 @@ public struct TextureDesc public RenderTextureMemoryless memoryless; ///Texture name. public string name; +#if UNITY_2020_2_OR_NEWER ///Descriptor to determine how the texture will be in fast memory on platform that supports it. public FastMemoryDesc fastMemoryDesc; +#endif // Initial state. Those should not be used in the hash ///Texture needs to be cleared on first use. @@ -642,11 +646,13 @@ internal void CreateAndClearTexture(RenderGraphContext rgContext, TextureHandle { CreateTextureForPass(ref resource); +#if UNITY_2020_2_OR_NEWER var fastMemDesc = resource.desc.fastMemoryDesc; if(fastMemDesc.inFastMemory) { resource.rt.SwitchToFastMemory(rgContext.cmd, fastMemDesc.residencyFraction, fastMemDesc.flags); } +#endif if (resource.desc.clearBuffer || m_RenderGraphDebug.clearRenderTargetsAtCreation) { diff --git a/com.unity.render-pipelines.core/Runtime/Textures/RTHandle.cs b/com.unity.render-pipelines.core/Runtime/Textures/RTHandle.cs index 68dd42878ef..c540dbb85be 100644 --- a/com.unity.render-pipelines.core/Runtime/Textures/RTHandle.cs +++ b/com.unity.render-pipelines.core/Runtime/Textures/RTHandle.cs @@ -146,6 +146,7 @@ public Vector2Int GetScaledSize(Vector2Int refSize) } } +#if UNITY_2020_2_OR_NEWER /// /// Switch the render target to fast memory on platform that have it. /// @@ -160,10 +161,8 @@ public void SwitchToFastMemory(CommandBuffer cmd, bool copyContents = false ) { -#if UNITY_2020_2_OR_NEWER residencyFraction = Mathf.Clamp01(residencyFraction); cmd.SwitchIntoFastMemory(m_RT, flags, residencyFraction, copyContents); -#endif } /// @@ -187,9 +186,9 @@ public void CopyToFastMemory(CommandBuffer cmd, /// Whether the content of render target are copied or not when switching out fast memory. public void SwitchOutFastMemory(CommandBuffer cmd, bool copyContents = true) { -#if UNITY_2020_2_OR_NEWER cmd.SwitchOutOfFastMemory(m_RT, copyContents); -#endif } +#endif + } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs index ebaed2ee4da..74ee4adabdd 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs @@ -333,17 +333,27 @@ void SetupGBufferTargets(RenderGraph renderGraph, HDCamera hdCamera, GBufferPass passData.gbufferRT[0] = builder.UseColorBuffer(sssBuffer, 0); passData.gbufferRT[1] = builder.UseColorBuffer(prepassOutput.normalBuffer, 1); +#if UNITY_2020_2_OR_NEWER FastMemoryDesc gbufferFastMemDesc; gbufferFastMemDesc.inFastMemory = true; gbufferFastMemDesc.residencyFraction = 1.0f; gbufferFastMemDesc.flags = FastMemoryFlags.SpillTop; +#endif // If we are in deferred mode and the SSR is enabled, we need to make sure that the second gbuffer is cleared given that we are using that information for clear coat selection bool clearGBuffer2 = clearGBuffer || hdCamera.IsSSREnabled(); passData.gbufferRT[2] = builder.UseColorBuffer(renderGraph.CreateTexture( - new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm, clearBuffer = clearGBuffer2, clearColor = Color.clear, name = "GBuffer2", fastMemoryDesc = gbufferFastMemDesc }, HDShaderIDs._GBufferTexture[2]), 2); + new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm, clearBuffer = clearGBuffer2, clearColor = Color.clear, name = "GBuffer2", +#if UNITY_2020_2_OR_NEWER + fastMemoryDesc = gbufferFastMemDesc +#endif + }, HDShaderIDs._GBufferTexture[2]), 2); passData.gbufferRT[3] = builder.UseColorBuffer(renderGraph.CreateTexture( - new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetLightingBufferFormat(), clearBuffer = clearGBuffer, clearColor = Color.clear, name = "GBuffer3", fastMemoryDesc = gbufferFastMemDesc }, HDShaderIDs._GBufferTexture[3]), 3); + new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetLightingBufferFormat(), clearBuffer = clearGBuffer, clearColor = Color.clear, name = "GBuffer3", +#if UNITY_2020_2_OR_NEWER + fastMemoryDesc = gbufferFastMemDesc +#endif + }, HDShaderIDs._GBufferTexture[3]), 3); prepassOutput.gbuffer.lightLayersTextureIndex = -1; int currentIndex = 4; 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 706f7af6222..4abf8297d8f 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 @@ -983,10 +983,13 @@ void RenderDistortion( RenderGraph renderGraph, TextureHandle CreateColorBuffer(RenderGraph renderGraph, HDCamera hdCamera, bool msaa) { + +#if UNITY_2020_2_OR_NEWER FastMemoryDesc colorFastMemDesc; colorFastMemDesc.inFastMemory = true; colorFastMemDesc.residencyFraction = 1.0f; colorFastMemDesc.flags = FastMemoryFlags.SpillTop; +#endif return renderGraph.CreateTexture( new TextureDesc(Vector2.one, true, true) @@ -997,8 +1000,10 @@ TextureHandle CreateColorBuffer(RenderGraph renderGraph, HDCamera hdCamera, bool enableMSAA = msaa, clearBuffer = NeedClearColorBuffer(hdCamera), clearColor = GetColorBufferClearColor(hdCamera), - name = msaa ? "CameraColorMSAA" : "CameraColor", - fastMemoryDesc = colorFastMemDesc + name = msaa ? "CameraColorMSAA" : "CameraColor" +#if UNITY_2020_2_OR_NEWER + , fastMemoryDesc = colorFastMemDesc +#endif }); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 8d456991f2d..9f6ea97b49e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -646,6 +646,7 @@ void ValidateResources() #endif +#if UNITY_2020_2_OR_NEWER internal void SwitchRenderTargetsToFastMem(CommandBuffer cmd, HDCamera camera) { // Color and normal buffer will always be in fast memory @@ -667,7 +668,7 @@ internal void SwitchRenderTargetsToFastMem(CommandBuffer cmd, HDCamera camera) // Trying to fit the depth pyramid m_SharedRTManager.GetDepthTexture().SwitchToFastMemory(cmd, residencyFraction: 1.0f, FastMemoryFlags.SpillTop, false); } - +#endif /// /// Resets the reference size of the internal RTHandle System. /// This allows users to reduce the memory footprint of render textures after doing a super sampled rendering pass for example. @@ -2206,7 +2207,9 @@ AOVRequestData aovRequest // Render graph deals with Fast memory support in an automatic way. if(!m_EnableRenderGraph) { +#if UNITY_2020_2_OR_NEWER SwitchRenderTargetsToFastMem(cmd, hdCamera); +#endif } if (m_RayTracingSupported) @@ -4855,6 +4858,7 @@ static void ResolveColorPickerDebug(in DebugParameters parameters, HDUtils.DrawFullScreen(cmd, parameters.colorPickerMaterial, output); } + static void RenderExposureDebug(in DebugParameters parameters, RTHandle inputColorBuffer, RTHandle postprocessedColorBuffer, From 2c0fa7a9459842000adc00d7f02e58925a24746c Mon Sep 17 00:00:00 2001 From: FrancescoC-Unity Date: Tue, 16 Jun 2020 14:58:36 +0200 Subject: [PATCH 2/2] move commas --- .../Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs index 74ee4adabdd..d44ff9459ba 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs @@ -343,15 +343,15 @@ void SetupGBufferTargets(RenderGraph renderGraph, HDCamera hdCamera, GBufferPass // If we are in deferred mode and the SSR is enabled, we need to make sure that the second gbuffer is cleared given that we are using that information for clear coat selection bool clearGBuffer2 = clearGBuffer || hdCamera.IsSSREnabled(); passData.gbufferRT[2] = builder.UseColorBuffer(renderGraph.CreateTexture( - new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm, clearBuffer = clearGBuffer2, clearColor = Color.clear, name = "GBuffer2", + new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm, clearBuffer = clearGBuffer2, clearColor = Color.clear, name = "GBuffer2" #if UNITY_2020_2_OR_NEWER - fastMemoryDesc = gbufferFastMemDesc + , fastMemoryDesc = gbufferFastMemDesc #endif }, HDShaderIDs._GBufferTexture[2]), 2); passData.gbufferRT[3] = builder.UseColorBuffer(renderGraph.CreateTexture( - new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetLightingBufferFormat(), clearBuffer = clearGBuffer, clearColor = Color.clear, name = "GBuffer3", + new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetLightingBufferFormat(), clearBuffer = clearGBuffer, clearColor = Color.clear, name = "GBuffer3" #if UNITY_2020_2_OR_NEWER - fastMemoryDesc = gbufferFastMemDesc + , fastMemoryDesc = gbufferFastMemDesc #endif }, HDShaderIDs._GBufferTexture[3]), 3);