From c421c343bf1987749097f8d26976e646df812bef Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Mon, 29 Jun 2020 15:05:14 +0200 Subject: [PATCH 01/23] Made conversion from render graph handles to actual resource implicit to reduce boiler plate code. --- .../Runtime/RenderGraph/RenderGraph.cs | 3 - .../RenderGraphResourceRegistry.cs | 42 ++------ .../RenderGraph/RenderGraphResources.cs | 40 +++++-- .../AmbientOcclusion.RenderGraph.cs | 15 ++- .../Shadow/HDShadowManager.RenderGraph.cs | 18 ++-- .../PostProcessSystem.RenderGraph.cs | 22 ++-- .../Runtime/RenderPipeline/Camera/HDCamera.cs | 7 +- .../RenderPipeline/HDRenderPipeline.Debug.cs | 69 +++++------- .../HDRenderPipeline.LightLoop.cs | 102 +++++++++--------- .../HDRenderPipeline.PostProcess.cs | 6 +- .../HDRenderPipeline.Prepass.cs | 69 +++++------- .../HDRenderPipeline.RenderGraph.cs | 95 ++++++---------- .../HDRenderPipeline.RenderGraphUtils.cs | 2 +- .../HDRenderPipeline.SubsurfaceScattering.cs | 14 +-- .../RenderPass/AOV/AOVRequestData.cs | 2 +- 15 files changed, 215 insertions(+), 291 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs index 7559a39daf4..adcd6f824b8 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs @@ -30,8 +30,6 @@ public ref struct RenderGraphContext public CommandBuffer cmd; ///Render Graph pooll used for temporary data. public RenderGraphObjectPool renderGraphPool; - ///Render Graph Resource Registry used for accessing resources. - public RenderGraphResourceRegistry resources; ///Render Graph default resources. public RenderGraphDefaultResources defaultResources; } @@ -814,7 +812,6 @@ void ExecuteRenderGraph(ScriptableRenderContext renderContext, CommandBuffer cmd rgContext.cmd = cmd; rgContext.renderContext = renderContext; rgContext.renderGraphPool = m_RenderGraphPool; - rgContext.resources = m_Resources; rgContext.defaultResources = m_DefaultResources; for (int passIndex = 0; passIndex < m_CompiledPassInfos.size; ++passIndex) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index 521b97aa8e3..bb7fc7c96b6 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -5,10 +5,7 @@ namespace UnityEngine.Experimental.Rendering.RenderGraphModule { - /// - /// The RenderGraphResourceRegistry holds all resource allocated during Render Graph execution. - /// - public class RenderGraphResourceRegistry + class RenderGraphResourceRegistry { static readonly ShaderTagId s_EmptyName = new ShaderTagId(""); @@ -100,13 +97,7 @@ internal RendererListResource(in RendererListDesc desc) RTHandle m_CurrentBackbuffer; - #region Public Interface - /// - /// Returns the RTHandle associated with the provided resource handle. - /// - /// Handle to a texture resource. - /// The RTHandle associated with the provided resource handle or null if the handle is invalid. - public RTHandle GetTexture(in TextureHandle handle) + internal RTHandle GetTexture(in TextureHandle handle) { if (!handle.IsValid()) return null; @@ -114,12 +105,7 @@ public RTHandle GetTexture(in TextureHandle handle) return GetTextureResource(handle.handle).resource; } - /// - /// Returns the RendererList associated with the provided resource handle. - /// - /// Handle to a Renderer List resource. - /// The Renderer List associated with the provided resource handle or an invalid renderer list if the handle is invalid. - public RendererList GetRendererList(in RendererListHandle handle) + internal RendererList GetRendererList(in RendererListHandle handle) { if (!handle.IsValid() || handle >= m_RendererListResources.size) return RendererList.nullRendererList; @@ -127,19 +113,13 @@ public RendererList GetRendererList(in RendererListHandle handle) return m_RendererListResources[handle].rendererList; } - /// - /// Returns the Compute Buffer associated with the provided resource handle. - /// - /// Handle to a Compute Buffer resource. - /// The Compute Buffer associated with the provided resource handle or a null reference if the handle is invalid. - public ComputeBuffer GetComputeBuffer(in ComputeBufferHandle handle) + internal ComputeBuffer GetComputeBuffer(in ComputeBufferHandle handle) { if (!handle.IsValid()) return null; return GetComputeBufferResource(handle.handle).resource; } - #endregion #region Internal Interface private RenderGraphResourceRegistry() @@ -210,7 +190,7 @@ internal TextureHandle ImportTexture(RTHandle rt, int shaderProperty = 0) texResource.imported = true; texResource.shaderProperty = shaderProperty; - return new TextureHandle(newHandle); + return new TextureHandle(newHandle, this); } internal TextureHandle ImportBackbuffer(RenderTargetIdentifier rt) @@ -224,7 +204,7 @@ internal TextureHandle ImportBackbuffer(RenderTargetIdentifier rt) texResource.resource = m_CurrentBackbuffer; texResource.imported = true; - return new TextureHandle(newHandle); + return new TextureHandle(newHandle, this); } int AddNewResource(DynamicArray resourceArray, out ResType outRes) where ResType : IRenderGraphResource, new() @@ -248,7 +228,7 @@ internal TextureHandle CreateTexture(in TextureDesc desc, int shaderProperty = 0 texResource.desc = desc; texResource.shaderProperty = shaderProperty; texResource.transientPassIndex = transientPassIndex; - return new TextureHandle(newHandle); + return new TextureHandle(newHandle, this); } internal int GetTextureResourceCount() @@ -271,7 +251,7 @@ internal RendererListHandle CreateRendererList(in RendererListDesc desc) ValidateRendererListDesc(desc); int newHandle = m_RendererListResources.Add(new RendererListResource(desc)); - return new RendererListHandle(newHandle); + return new RendererListHandle(newHandle, this); } internal ComputeBufferHandle ImportComputeBuffer(ComputeBuffer computeBuffer) @@ -280,7 +260,7 @@ internal ComputeBufferHandle ImportComputeBuffer(ComputeBuffer computeBuffer) bufferResource.resource = computeBuffer; bufferResource.imported = true; - return new ComputeBufferHandle(newHandle); + return new ComputeBufferHandle(newHandle, this); } internal ComputeBufferHandle CreateComputeBuffer(in ComputeBufferDesc desc, int transientPassIndex = -1) @@ -291,7 +271,7 @@ internal ComputeBufferHandle CreateComputeBuffer(in ComputeBufferDesc desc, int bufferResource.desc = desc; bufferResource.transientPassIndex = transientPassIndex; - return new ComputeBufferHandle(newHandle); + return new ComputeBufferHandle(newHandle, this); } internal ComputeBufferDesc GetComputeBufferResourceDesc(in ResourceHandle handle) @@ -444,7 +424,7 @@ internal void ReleaseTexture(RenderGraphContext rgContext, int index) var clearFlag = resource.desc.depthBufferBits != DepthBits.None ? ClearFlag.Depth : ClearFlag.Color; // Not ideal to do new TextureHandle here but GetTexture is a public API and we rather have it take an explicit TextureHandle parameters. // Everywhere else internally int is better because it allows us to share more code. - CoreUtils.SetRenderTarget(rgContext.cmd, GetTexture(new TextureHandle(index)), clearFlag, Color.magenta); + CoreUtils.SetRenderTarget(rgContext.cmd, GetTexture(new TextureHandle(index, this)), clearFlag, Color.magenta); } } diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs index 73ee1dc8535..efcfff2e8d8 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs @@ -14,21 +14,24 @@ internal enum RenderGraphResourceType // Can't have a default constructor with handle = -1 hence the ugly IsValid implementation (where m_IsValid will be false by default). internal struct ResourceHandle { - bool m_IsValid; + bool m_IsValid; public int index { get; private set; } public RenderGraphResourceType type { get; private set; } public int iType { get { return (int)type; } } - internal ResourceHandle(int value, RenderGraphResourceType type) + internal RenderGraphResourceRegistry registry; + + internal ResourceHandle(int value, RenderGraphResourceType type, RenderGraphResourceRegistry registry) { index = value; this.type = type; + this.registry = registry; m_IsValid = true; } public static implicit operator int(ResourceHandle handle) => handle.index; - public bool IsValid() => m_IsValid; + public bool IsValid() => m_IsValid && registry != null; } // BEHOLD C# COPY PASTA @@ -43,7 +46,23 @@ public struct TextureHandle { internal ResourceHandle handle; - internal TextureHandle(int handle) { this.handle = new ResourceHandle(handle, RenderGraphResourceType.Texture); } + internal TextureHandle(int handle, RenderGraphResourceRegistry registry) { this.handle = new ResourceHandle(handle, RenderGraphResourceType.Texture, registry); } + + /// + /// Cast to RTHandle + /// + /// Input TextureHandle. + public static implicit operator RTHandle(TextureHandle texture) => texture.IsValid() ? texture.handle.registry.GetTexture(texture) : null; + /// + /// Cast to RenderTargetIdentifier + /// + /// Input TextureHandle. + public static implicit operator RenderTargetIdentifier(TextureHandle texture) => texture.IsValid() ? texture.handle.registry.GetTexture(texture) : null; + /// + /// Cast to RenderTexture + /// + /// Input TextureHandle. + public static implicit operator RenderTexture(TextureHandle texture) => texture.IsValid() ? texture.handle.registry.GetTexture(texture) : null; /// /// Return true if the handle is valid. @@ -60,7 +79,13 @@ public struct ComputeBufferHandle { internal ResourceHandle handle; - internal ComputeBufferHandle(int handle) { this.handle = new ResourceHandle(handle, RenderGraphResourceType.ComputeBuffer); } + internal ComputeBufferHandle(int handle, RenderGraphResourceRegistry registry) { this.handle = new ResourceHandle(handle, RenderGraphResourceType.ComputeBuffer, registry); } + + /// + /// Cast to ComputeBuffer + /// + /// Input ComputeBufferHandle + public static implicit operator ComputeBuffer(ComputeBufferHandle buffer) => buffer.IsValid() ? buffer.handle.registry.GetComputeBuffer(buffer) : null; /// /// Return true if the handle is valid. @@ -77,7 +102,8 @@ public struct RendererListHandle { bool m_IsValid; internal int handle { get; private set; } - internal RendererListHandle(int handle) { this.handle = handle; m_IsValid = true; } + internal RenderGraphResourceRegistry registry; + internal RendererListHandle(int handle, RenderGraphResourceRegistry registry) { this.handle = handle; m_IsValid = true; this.registry = registry; } /// /// Conversion to int. /// @@ -85,6 +111,8 @@ public struct RendererListHandle /// The integer representation of the handle. public static implicit operator int(RendererListHandle handle) { return handle.handle; } + public static implicit operator RendererList(RendererListHandle rendererList) => rendererList.IsValid() ? rendererList.registry.GetRendererList(rendererList) : RendererList.nullRendererList; + /// /// Return true if the handle is valid. /// diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs index 065d388cba1..51dc68f4f0f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs @@ -68,7 +68,7 @@ TextureHandle RenderAO(RenderGraph renderGraph, in RenderAOParameters parameters builder.SetRenderFunc( (RenderAOPassData data, RenderGraphContext ctx) => { - RenderAO(data.parameters, ctx.resources.GetTexture(data.packedData), ctx.resources.GetTexture(data.depthPyramid), ctx.resources.GetTexture(data.normalBuffer), ctx.cmd); + RenderAO(data.parameters, data.packedData, data.depthPyramid, data.normalBuffer, ctx.cmd); }); return passData.packedData; @@ -124,13 +124,12 @@ TextureHandle DenoiseAO( RenderGraph renderGraph, builder.SetRenderFunc( (DenoiseAOPassData data, RenderGraphContext ctx) => { - var res = ctx.resources; DenoiseAO( data.parameters, - res.GetTexture(data.packedData), - res.GetTexture(data.packedDataBlurred), - res.GetTexture(data.currentHistory), - res.GetTexture(data.outputHistory), - res.GetTexture(data.denoiseOutput), + data.packedData, + data.packedDataBlurred, + data.currentHistory, + data.outputHistory, + data.denoiseOutput, ctx.cmd); }); @@ -161,7 +160,7 @@ TextureHandle UpsampleAO(RenderGraph renderGraph, in RenderAOParameters paramete builder.SetRenderFunc( (UpsampleAOPassData data, RenderGraphContext ctx) => { - UpsampleAO(data.parameters, ctx.resources.GetTexture(data.input), ctx.resources.GetTexture(data.output), ctx.cmd); + UpsampleAO(data.parameters, data.input, data.output, ctx.cmd); }); return passData.output; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs index a07de453005..c0ae47a28b5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs @@ -62,9 +62,9 @@ class BindShadowGlobalResourcesPassData static void BindAtlasTexture(RenderGraphContext ctx, TextureHandle texture, int shaderId) { if (texture.IsValid()) - ctx.cmd.SetGlobalTexture(shaderId, ctx.resources.GetTexture(texture)); + ctx.cmd.SetGlobalTexture(shaderId, texture); else - ctx.cmd.SetGlobalTexture(shaderId, ctx.resources.GetTexture(ctx.defaultResources.blackTexture)); + ctx.cmd.SetGlobalTexture(shaderId, ctx.defaultResources.blackTexture); } void BindShadowGlobalResources(RenderGraph renderGraph, in ShadowResult shadowResult) @@ -148,26 +148,22 @@ internal TextureHandle RenderShadows(RenderGraph renderGraph, CullingResults cul builder.SetRenderFunc( (RenderShadowsPassData data, RenderGraphContext context) => { - RTHandle atlasTexture = context.resources.GetTexture(data.atlasTexture); RenderShadows( data.parameters, - atlasTexture, + data.atlasTexture, data.shadowDrawSettings, context.renderContext, context.cmd); if (data.parameters.blurAlgorithm == BlurAlgorithm.EVSM) { RTHandle[] momentTextures = context.renderGraphPool.GetTempArray(2); - momentTextures[0] = context.resources.GetTexture(data.momentAtlasTexture1); - momentTextures[1] = context.resources.GetTexture(data.momentAtlasTexture2); + momentTextures[0] = data.momentAtlasTexture1; + momentTextures[1] = data.momentAtlasTexture2; - EVSMBlurMoments(data.parameters, atlasTexture, momentTextures, context.cmd); + EVSMBlurMoments(data.parameters, data.atlasTexture, momentTextures, context.cmd); } else if (data.parameters.blurAlgorithm == BlurAlgorithm.IM) { - RTHandle momentAtlas = context.resources.GetTexture(data.momentAtlasTexture1); - RTHandle intermediateSummedArea = context.resources.GetTexture(data.intermediateSummedAreaTexture); - RTHandle summedArea = context.resources.GetTexture(data.summedAreaTexture); - IMBlurMoment(data.parameters, atlasTexture, momentAtlas, intermediateSummedArea, summedArea, context.cmd); + IMBlurMoment(data.parameters, data.atlasTexture, data.momentAtlasTexture1, data.intermediateSummedAreaTexture, data.summedAreaTexture, context.cmd); } }); diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs index 8e691623961..fb4705975ca 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs @@ -55,10 +55,7 @@ public void Render( RenderGraph renderGraph, builder.SetRenderFunc( (AlphaCopyPassData data, RenderGraphContext ctx) => { - DoCopyAlpha( data.parameters, - ctx.resources.GetTexture(data.source), - ctx.resources.GetTexture(data.outputAlpha), - ctx.cmd); + DoCopyAlpha(data.parameters, data.source, data.outputAlpha, ctx.cmd); }); alphaTexture = passData.outputAlpha; @@ -268,7 +265,7 @@ public void Render( RenderGraph renderGraph, builder.SetRenderFunc( (ColorGradingPassData data, RenderGraphContext ctx) => { - DoColorGrading(data.parameters, ctx.resources.GetTexture(data.logLut), ctx.cmd); + DoColorGrading(data.parameters, data.logLut, ctx.cmd); }); } @@ -297,10 +294,10 @@ public void Render( RenderGraph renderGraph, DoUberPostProcess( data.parameters, - ctx.resources.GetTexture(data.source), - ctx.resources.GetTexture(data.destination), - ctx.resources.GetTexture(data.logLut), - ctx.resources.GetTexture(data.source), // TODO: TMP VALUE, should be bloom texture and will be as soon as PP is ported to rendergraph. + data.source, + data.destination, + data.logLut, + data.source, // TODO: TMP VALUE, should be bloom texture and will be as soon as PP is ported to rendergraph. ctx.cmd); }); @@ -378,12 +375,7 @@ public void Render( RenderGraph renderGraph, builder.SetRenderFunc( (FinalPassData data, RenderGraphContext ctx) => { - DoFinalPass( data.parameters, - ctx.resources.GetTexture(data.source), - ctx.resources.GetTexture(data.afterPostProcessTexture), - ctx.resources.GetTexture(data.destination), - ctx.resources.GetTexture(data.alphaTexture), - ctx.cmd); + DoFinalPass(data.parameters, data.source, data.afterPostProcessTexture, data.destination, data.alphaTexture, ctx.cmd); }); } } 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 2eb5e588c41..fc74d22ca21 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 @@ -768,16 +768,15 @@ internal void ExecuteCaptureActions(RenderGraph renderGraph, TextureHandle input builder.SetRenderFunc( (ExecuteCaptureActionsPassData data, RenderGraphContext ctx) => { - var tempRT = ctx.resources.GetTexture(data.tempTexture); var mpb = ctx.renderGraphPool.GetTempMaterialPropertyBlock(); - mpb.SetTexture(HDShaderIDs._BlitTexture, ctx.resources.GetTexture(data.input)); + mpb.SetTexture(HDShaderIDs._BlitTexture, data.input); mpb.SetVector(HDShaderIDs._BlitScaleBias, data.viewportScale); mpb.SetFloat(HDShaderIDs._BlitMipLevel, 0); - ctx.cmd.SetRenderTarget(tempRT); + ctx.cmd.SetRenderTarget(data.tempTexture); ctx.cmd.DrawProcedural(Matrix4x4.identity, data.blitMaterial, 0, MeshTopology.Triangles, 3, 1, mpb); for (data.recorderCaptureActions.Reset(); data.recorderCaptureActions.MoveNext();) - data.recorderCaptureActions.Current(tempRT, ctx.cmd); + data.recorderCaptureActions.Current(data.tempTexture, ctx.cmd); }); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs index df68242484f..efbcddc6137 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs @@ -36,11 +36,11 @@ void RenderTransparencyOverdraw(RenderGraph renderGraph, TextureHandle depthBuff (TransparencyOverdrawPassData data, RenderGraphContext ctx) => { RenderTransparencyOverdraw( data.parameters, - ctx.resources.GetTexture(data.output), - ctx.resources.GetTexture(data.depthBuffer), - ctx.resources.GetRendererList(data.transparencyRL), - ctx.resources.GetRendererList(data.transparencyAfterPostRL), - ctx.resources.GetRendererList(data.transparencyLowResRL), + data.output, + data.depthBuffer, + data.transparencyRL, + data.transparencyAfterPostRL, + data.transparencyLowResRL, ctx.renderContext, ctx.cmd); }); @@ -72,11 +72,7 @@ TextureHandle ResolveFullScreenDebug(RenderGraph renderGraph, in DebugParameters builder.SetRenderFunc( (ResolveFullScreenDebugPassData data, RenderGraphContext ctx) => { - ResolveFullScreenDebug(data.debugParameters, - ctx.renderGraphPool.GetTempMaterialPropertyBlock(), - ctx.resources.GetTexture(data.input), - ctx.resources.GetTexture(data.depthPyramid), - ctx.resources.GetTexture(data.output), ctx.cmd); + ResolveFullScreenDebug(data.debugParameters, ctx.renderGraphPool.GetTempMaterialPropertyBlock(), data.input, data.depthPyramid, data.output, ctx.cmd); }); return passData.output; @@ -102,10 +98,7 @@ TextureHandle ResolveColorPickerDebug(RenderGraph renderGraph, in DebugParameter builder.SetRenderFunc( (ResolveColorPickerDebugPassData data, RenderGraphContext ctx) => { - ResolveColorPickerDebug(data.debugParameters, - ctx.resources.GetTexture(data.input), - ctx.resources.GetTexture(data.output), - ctx.cmd); + ResolveColorPickerDebug(data.debugParameters, data.input, data.output, ctx.cmd); }); return passData.output; @@ -157,20 +150,15 @@ void RenderDebugOverlays( RenderGraph renderGraph, float y = debugParams.hdCamera.actualHeight - overlaySize; var shadowAtlases = new HDShadowManager.ShadowDebugAtlasTextures(); - shadowAtlases.punctualShadowAtlas = data.shadowTextures.punctualShadowResult.IsValid() ? ctx.resources.GetTexture(data.shadowTextures.punctualShadowResult) : null; - shadowAtlases.cascadeShadowAtlas = data.shadowTextures.directionalShadowResult.IsValid() ? ctx.resources.GetTexture(data.shadowTextures.directionalShadowResult) : null; - shadowAtlases.areaShadowAtlas = data.shadowTextures.areaShadowResult.IsValid() ? ctx.resources.GetTexture(data.shadowTextures.areaShadowResult) : null; - shadowAtlases.cachedPunctualShadowAtlas = data.shadowTextures.cachedPunctualShadowResult.IsValid() ? ctx.resources.GetTexture(data.shadowTextures.cachedPunctualShadowResult) : null; - shadowAtlases.cachedAreaShadowAtlas = data.shadowTextures.cachedAreaShadowResult.IsValid() ? ctx.resources.GetTexture(data.shadowTextures.cachedAreaShadowResult) : null; - - ComputeBuffer tileBuffer = ctx.resources.GetComputeBuffer(data.tileList); - ComputeBuffer lightListBuffer = ctx.resources.GetComputeBuffer(data.lightList); - ComputeBuffer perVoxelLightListBuffer = ctx.resources.GetComputeBuffer(data.perVoxelLightList); - ComputeBuffer dispatchIndirectBuffer = ctx.resources.GetComputeBuffer(data.dispatchIndirect); + shadowAtlases.punctualShadowAtlas = data.shadowTextures.punctualShadowResult; + shadowAtlases.cascadeShadowAtlas = data.shadowTextures.directionalShadowResult; + shadowAtlases.areaShadowAtlas = data.shadowTextures.areaShadowResult; + shadowAtlases.cachedPunctualShadowAtlas = data.shadowTextures.cachedPunctualShadowResult; + shadowAtlases.cachedAreaShadowAtlas = data.shadowTextures.cachedAreaShadowResult; RenderSkyReflectionOverlay(debugParams, ctx.cmd, ctx.renderGraphPool.GetTempMaterialPropertyBlock(), ref x, ref y, overlaySize); RenderRayCountOverlay(debugParams, ctx.cmd, ref x, ref y, overlaySize); - RenderLightLoopDebugOverlay(debugParams, ctx.cmd, ref x, ref y, overlaySize, tileBuffer, lightListBuffer, perVoxelLightListBuffer, dispatchIndirectBuffer, ctx.resources.GetTexture(data.depthPyramidTexture)); + RenderLightLoopDebugOverlay(debugParams, ctx.cmd, ref x, ref y, overlaySize, data.tileList, data.lightList, data.perVoxelLightList, data.dispatchIndirect, data.depthPyramidTexture); RenderShadowsDebugOverlay(debugParams, shadowAtlases, ctx.cmd, ref x, ref y, overlaySize, ctx.renderGraphPool.GetTempMaterialPropertyBlock()); DecalSystem.instance.RenderDebugOverlay(debugParams.hdCamera, ctx.cmd, debugParams.debugDisplaySettings, ref x, ref y, overlaySize, debugParams.hdCamera.actualWidth); }); @@ -209,18 +197,16 @@ static void RenderLightVolumes(RenderGraph renderGraph, in DebugParameters debug (RenderLightVolumesPassData data, RenderGraphContext ctx) => { RenderTargetIdentifier[] mrt = ctx.renderGraphPool.GetTempArray(2); - var lightCountBuffer = ctx.resources.GetTexture(data.lightCountBuffer); - var colorAccumulationBuffer = ctx.resources.GetTexture(data.colorAccumulationBuffer); - mrt[0] = lightCountBuffer; - mrt[1] = colorAccumulationBuffer; + mrt[0] = data.lightCountBuffer; + mrt[1] = data.colorAccumulationBuffer; DebugLightVolumes.RenderLightVolumes( ctx.cmd, data.parameters, - mrt, lightCountBuffer, - colorAccumulationBuffer, - ctx.resources.GetTexture(data.debugLightVolumesTexture), - ctx.resources.GetTexture(data.depthBuffer), - ctx.resources.GetTexture(data.destination), + mrt, data.lightCountBuffer, + data.colorAccumulationBuffer, + data.debugLightVolumesTexture, + data.depthBuffer, + data.destination, ctx.renderGraphPool.GetTempMaterialPropertyBlock()); }); } @@ -310,8 +296,7 @@ TextureHandle RenderDebugViewMaterial(RenderGraph renderGraph, CullingResults cu builder.SetRenderFunc( (DebugViewMaterialData data, RenderGraphContext context) => { - var res = context.resources; - HDUtils.DrawFullScreen(context.cmd, data.debugGBufferMaterial, res.GetTexture(data.outputColor)); + HDUtils.DrawFullScreen(context.cmd, data.debugGBufferMaterial, data.outputColor); }); } } @@ -337,9 +322,8 @@ TextureHandle RenderDebugViewMaterial(RenderGraph renderGraph, CullingResults cu builder.SetRenderFunc( (DebugViewMaterialData data, RenderGraphContext context) => { - var res = context.resources; - DrawOpaqueRendererList(context, data.frameSettings, res.GetRendererList(data.opaqueRendererList)); - DrawTransparentRendererList(context, data.frameSettings, res.GetRendererList(data.transparentRendererList)); + DrawOpaqueRendererList(context, data.frameSettings, data.opaqueRendererList); + DrawTransparentRendererList(context, data.frameSettings, data.transparentRendererList); }); } } @@ -394,11 +378,10 @@ void PushFullScreenDebugTexture(RenderGraph renderGraph, TextureHandle input, in builder.SetRenderFunc( (PushFullScreenDebugPassData data, RenderGraphContext ctx) => { - var texture = ctx.resources.GetTexture(data.input); if (data.mipIndex != -1) - HDUtils.BlitCameraTexture(ctx.cmd, texture, ctx.resources.GetTexture(data.output), data.mipIndex); + HDUtils.BlitCameraTexture(ctx.cmd, data.input, data.output, data.mipIndex); else - HDUtils.BlitCameraTexture(ctx.cmd, texture, ctx.resources.GetTexture(data.output)); + HDUtils.BlitCameraTexture(ctx.cmd, data.input, data.output); }); m_DebugFullScreenTexture = passData.output; @@ -419,7 +402,7 @@ TextureHandle PushColorPickerDebugTexture(RenderGraph renderGraph, TextureHandle builder.SetRenderFunc( (PushFullScreenDebugPassData data, RenderGraphContext ctx) => { - HDUtils.BlitCameraTexture(ctx.cmd, ctx.resources.GetTexture(data.input), ctx.resources.GetTexture(data.output)); + HDUtils.BlitCameraTexture(ctx.cmd, data.input, data.output); }); return passData.output; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs index cdf56cd61f0..82fa896ae5b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs @@ -68,28 +68,28 @@ static BuildGPULightListResources PrepareBuildGPULightListResources(RenderGraphC { var buildLightListResources = new BuildGPULightListResources(); - buildLightListResources.depthBuffer = context.resources.GetTexture(data.depthBuffer); - buildLightListResources.stencilTexture = context.resources.GetTexture(data.stencilTexture); + buildLightListResources.depthBuffer = data.depthBuffer; + buildLightListResources.stencilTexture = data.stencilTexture; if (data.buildGPULightListParameters.computeMaterialVariants && data.buildGPULightListParameters.enableFeatureVariants) { buildLightListResources.gBuffer = context.renderGraphPool.GetTempArray(data.gBufferCount); for (int i = 0; i < data.gBufferCount; ++i) - buildLightListResources.gBuffer[i] = context.resources.GetTexture(data.gBuffer[i]); + buildLightListResources.gBuffer[i] = data.gBuffer[i]; } - buildLightListResources.lightVolumeDataBuffer = context.resources.GetComputeBuffer(data.lightVolumeDataBuffer); - buildLightListResources.convexBoundsBuffer = context.resources.GetComputeBuffer(data.convexBoundsBuffer); - buildLightListResources.AABBBoundsBuffer = context.resources.GetComputeBuffer(data.AABBBoundsBuffer); - buildLightListResources.globalLightListAtomic = context.resources.GetComputeBuffer(data.globalLightListAtomic); + buildLightListResources.lightVolumeDataBuffer = data.lightVolumeDataBuffer; + buildLightListResources.convexBoundsBuffer = data.convexBoundsBuffer; + buildLightListResources.AABBBoundsBuffer = data.AABBBoundsBuffer; + buildLightListResources.globalLightListAtomic = data.globalLightListAtomic; - buildLightListResources.tileFeatureFlags = context.resources.GetComputeBuffer(data.output.tileFeatureFlags); - buildLightListResources.dispatchIndirectBuffer = context.resources.GetComputeBuffer(data.output.dispatchIndirectBuffer); - buildLightListResources.perVoxelOffset = context.resources.GetComputeBuffer(data.output.perVoxelOffset); - buildLightListResources.perTileLogBaseTweak = context.resources.GetComputeBuffer(data.output.perTileLogBaseTweak); - buildLightListResources.tileList = context.resources.GetComputeBuffer(data.output.tileList); - buildLightListResources.bigTileLightList = context.resources.GetComputeBuffer(data.output.bigTileLightList); - buildLightListResources.perVoxelLightLists = context.resources.GetComputeBuffer(data.output.perVoxelLightLists); - buildLightListResources.lightList = context.resources.GetComputeBuffer(data.output.lightList); + buildLightListResources.tileFeatureFlags = data.output.tileFeatureFlags; + buildLightListResources.dispatchIndirectBuffer = data.output.dispatchIndirectBuffer; + buildLightListResources.perVoxelOffset = data.output.perVoxelOffset; + buildLightListResources.perTileLogBaseTweak = data.output.perTileLogBaseTweak; + buildLightListResources.tileList = data.output.tileList; + buildLightListResources.bigTileLightList = data.output.bigTileLightList; + buildLightListResources.perVoxelLightLists = data.output.perVoxelLightLists; + buildLightListResources.lightList = data.output.lightList; return buildLightListResources; } @@ -321,33 +321,33 @@ LightingOutput RenderDeferredLighting( RenderGraph renderGraph, var resources = new DeferredLightingResources(); resources.colorBuffers = context.renderGraphPool.GetTempArray(2); - resources.colorBuffers[0] = context.resources.GetTexture(data.colorBuffer); - resources.colorBuffers[1] = context.resources.GetTexture(data.sssDiffuseLightingBuffer); - resources.depthStencilBuffer = context.resources.GetTexture(data.depthBuffer); - resources.depthTexture = context.resources.GetTexture(data.depthTexture); + resources.colorBuffers[0] = data.colorBuffer; + resources.colorBuffers[1] = data.sssDiffuseLightingBuffer; + resources.depthStencilBuffer = data.depthBuffer; + resources.depthTexture = data.depthTexture; - resources.lightListBuffer = context.resources.GetComputeBuffer(data.lightListBuffer); - resources.tileFeatureFlagsBuffer = context.resources.GetComputeBuffer(data.tileFeatureFlagsBuffer); - resources.tileListBuffer = context.resources.GetComputeBuffer(data.tileListBuffer); - resources.dispatchIndirectBuffer = context.resources.GetComputeBuffer(data.dispatchIndirectBuffer); + resources.lightListBuffer = data.lightListBuffer; + resources.tileFeatureFlagsBuffer = data.tileFeatureFlagsBuffer; + resources.tileListBuffer = data.tileListBuffer; + resources.dispatchIndirectBuffer = data.dispatchIndirectBuffer; // TODO RENDERGRAPH: try to find a better way to bind this. // Issue is that some GBuffers have several names (for example normal buffer is both NormalBuffer and GBuffer1) // So it's not possible to use auto binding via dependency to shaderTagID // Should probably get rid of auto binding and go explicit all the way (might need to wait for us to remove non rendergraph code path). for (int i = 0; i < data.gbufferCount; ++i) - context.cmd.SetGlobalTexture(HDShaderIDs._GBufferTexture[i], context.resources.GetTexture(data.gbuffer[i])); + context.cmd.SetGlobalTexture(HDShaderIDs._GBufferTexture[i], data.gbuffer[i]); if (data.lightLayersTextureIndex != -1) - context.cmd.SetGlobalTexture(HDShaderIDs._LightLayersTexture, context.resources.GetTexture(data.gbuffer[data.lightLayersTextureIndex])); + context.cmd.SetGlobalTexture(HDShaderIDs._LightLayersTexture, data.gbuffer[data.lightLayersTextureIndex]); else context.cmd.SetGlobalTexture(HDShaderIDs._LightLayersTexture, TextureXR.GetWhiteTexture()); // TODO RENDERGRAPH: Remove these SetGlobal and properly send these textures to the deferred passes and bind them directly to compute shaders. // This can wait that we remove the old code path. - context.cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, context.resources.GetTexture(data.lightingBuffers.ambientOcclusionBuffer)); - context.cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, context.resources.GetTexture(data.lightingBuffers.ssrLightingBuffer)); - context.cmd.SetGlobalTexture(HDShaderIDs._ContactShadowTexture, context.resources.GetTexture(data.lightingBuffers.contactShadowsBuffer)); + context.cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, data.lightingBuffers.ambientOcclusionBuffer); + context.cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, data.lightingBuffers.ssrLightingBuffer); + context.cmd.SetGlobalTexture(HDShaderIDs._ContactShadowTexture, data.lightingBuffers.contactShadowsBuffer); if (data.parameters.enableTile) { @@ -439,18 +439,17 @@ TextureHandle RenderSSR( RenderGraph renderGraph, builder.SetRenderFunc( (RenderSSRPassData data, RenderGraphContext context) => { - var res = context.resources; RenderSSR(data.parameters, - res.GetTexture(data.depthBuffer), - res.GetTexture(data.depthPyramid), - res.GetTexture(data.normalBuffer), - res.GetTexture(data.motionVectorsBuffer), - res.GetTexture(data.hitPointsTexture), - res.GetTexture(data.stencilBuffer), - res.GetTexture(data.clearCoatMask), - res.GetTexture(data.colorPyramid), - res.GetTexture(data.lightingTexture), - res.GetComputeBuffer(data.coarseStencilBuffer), + data.depthBuffer, + data.depthPyramid, + data.normalBuffer, + data.motionVectorsBuffer, + data.hitPointsTexture, + data.stencilBuffer, + data.clearCoatMask, + data.colorPyramid, + data.lightingTexture, + data.coarseStencilBuffer, context.cmd, context.renderContext); }); @@ -502,8 +501,7 @@ TextureHandle RenderContactShadows(RenderGraph renderGraph, HDCamera hdCamera, T builder.SetRenderFunc( (RenderContactShadowPassData data, RenderGraphContext context) => { - var res = context.resources; - RenderContactShadows(data.parameters, res.GetTexture(data.contactShadowsTexture), res.GetTexture(data.depthTexture), data.lightLoopLightData, res.GetComputeBuffer(data.lightList), context.cmd); + RenderContactShadows(data.parameters, data.contactShadowsTexture, data.depthTexture, data.lightLoopLightData, data.lightList, context.cmd); }); } @@ -547,10 +545,10 @@ TextureHandle VolumeVoxelizationPass( RenderGraph renderGraph, (VolumeVoxelizationPassData data, RenderGraphContext ctx) => { VolumeVoxelizationPass( data.parameters, - ctx.resources.GetTexture(data.densityBuffer), + data.densityBuffer, data.visibleVolumeBoundsBuffer, data.visibleVolumeDataBuffer, - ctx.resources.GetComputeBuffer(data.bigTileLightListBuffer), + data.bigTileLightListBuffer, ctx.cmd); }); @@ -607,21 +605,17 @@ TextureHandle VolumetricLightingPass(RenderGraph renderGraph, HDCamera hdCamera, builder.SetRenderFunc( (VolumetricLightingPassData data, RenderGraphContext ctx) => { - RTHandle densityBufferRT = ctx.resources.GetTexture(data.densityBuffer); - RTHandle lightinBufferRT = ctx.resources.GetTexture(data.lightingBuffer); - RTHandle depthTextureRT = ctx.resources.GetTexture(data.depthTexture); - VolumetricLightingPass( data.parameters, - depthTextureRT, - densityBufferRT, - lightinBufferRT, - data.parameters.enableReprojection ? ctx.resources.GetTexture(data.historyBuffer) : null, - data.parameters.enableReprojection ? ctx.resources.GetTexture(data.feedbackBuffer) : null, - ctx.resources.GetComputeBuffer(data.bigTileLightListBuffer), + data.depthTexture, + data.densityBuffer, + data.lightingBuffer, + data.parameters.enableReprojection ? data.historyBuffer : (RTHandle)null, + data.parameters.enableReprojection ? data.feedbackBuffer : (RTHandle)null, + data.bigTileLightListBuffer, ctx.cmd); if (data.parameters.filterVolume) - FilterVolumetricLighting(data.parameters, densityBufferRT, lightinBufferRT, ctx.cmd); + FilterVolumetricLighting(data.parameters, data.densityBuffer, data.lightingBuffer, ctx.cmd); }); if (parameters.enableReprojection) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs index 2c6aac34fb9..ca14333abac 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.PostProcess.cs @@ -43,11 +43,7 @@ TextureHandle RenderPostProcess( RenderGraph renderGraph, builder.SetRenderFunc( (AfterPostProcessPassData data, RenderGraphContext ctx) => { - RenderAfterPostProcess(data.parameters - , ctx.resources.GetRendererList(data.opaqueAfterPostprocessRL) - , ctx.resources.GetRendererList(data.transparentAfterPostprocessRL) - , ctx.renderContext, ctx.cmd); - + RenderAfterPostProcess(data.parameters, data.opaqueAfterPostprocessRL, data.transparentAfterPostprocessRL, ctx.renderContext, ctx.cmd); }); afterPostProcessBuffer = passData.afterPostProcessBuffer; 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 ba09b19cd92..a88234dd2c2 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 @@ -290,21 +290,21 @@ bool RenderDepthPrepass(RenderGraph renderGraph, CullingResults cull, HDCamera h var mrt = context.renderGraphPool.GetTempArray(data.msaaEnabled ? 2 : 1); if (data.msaaEnabled) { - mrt[0] = context.resources.GetTexture(data.depthAsColorBuffer); - mrt[1] = context.resources.GetTexture(data.normalBuffer); + mrt[0] = data.depthAsColorBuffer; + mrt[1] = data.normalBuffer; } else { - mrt[0] = context.resources.GetTexture(data.normalBuffer); + mrt[0] = data.normalBuffer; } bool useRayTracing = data.frameSettings.IsEnabled(FrameSettingsField.RayTracing); RenderDepthPrepass(context.renderContext, context.cmd, data.frameSettings , mrt - , context.resources.GetTexture(data.depthBuffer) - , context.resources.GetRendererList(data.rendererListDepthOnly) - , context.resources.GetRendererList(data.rendererListMRT) + , data.depthBuffer + , data.rendererListDepthOnly + , data.rendererListMRT , data.hasDepthOnlyPrepass ); }); @@ -347,7 +347,7 @@ void RenderObjectsMotionVectors(RenderGraph renderGraph, CullingResults cull, HD // Disable write to normal buffer for unlit shader (the normal buffer binding change when using MSAA) context.cmd.SetGlobalInt(HDShaderIDs._ColorMaskNormal, data.frameSettings.IsEnabled(FrameSettingsField.MSAA) ? (int)ColorWriteMask.All : 0); - DrawOpaqueRendererList(context, data.frameSettings, context.resources.GetRendererList(data.rendererList)); + DrawOpaqueRendererList(context, data.frameSettings, data.rendererList); }); } } @@ -431,8 +431,8 @@ void SetupGBufferTargets(RenderGraph renderGraph, HDCamera hdCamera, GBufferPass static void BindDBufferGlobalData(in DBufferOutput dBufferOutput, in RenderGraphContext ctx) { for (int i = 0; i < dBufferOutput.dBufferCount; ++i) - ctx.cmd.SetGlobalTexture(HDShaderIDs._DBufferTexture[i], ctx.resources.GetTexture(dBufferOutput.mrt[i])); - ctx.cmd.SetGlobalBuffer(HDShaderIDs._DecalPropertyMaskBufferSRV, ctx.resources.GetComputeBuffer(dBufferOutput.decalPropertyMaskBuffer)); + ctx.cmd.SetGlobalTexture(HDShaderIDs._DBufferTexture[i], dBufferOutput.mrt[i]); + ctx.cmd.SetGlobalBuffer(HDShaderIDs._DecalPropertyMaskBufferSRV, dBufferOutput.decalPropertyMaskBuffer); } static void BindProbeVolumeGlobalData(in FrameSettings frameSettings, GBufferPassData data, in RenderGraphContext ctx) @@ -441,9 +441,9 @@ static void BindProbeVolumeGlobalData(in FrameSettings frameSettings, GBufferPas return; if (frameSettings.IsEnabled(FrameSettingsField.BigTilePrepass)) - ctx.cmd.SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, ctx.resources.GetComputeBuffer(data.probeVolumeBigTile)); - ctx.cmd.SetGlobalBuffer(HDShaderIDs.g_vProbeVolumesLayeredOffsetsBuffer, ctx.resources.GetComputeBuffer(data.probeVolumePerVoxelOffset)); - ctx.cmd.SetGlobalBuffer(HDShaderIDs.g_vProbeVolumesLightListGlobal, ctx.resources.GetComputeBuffer(data.probeVolumePerVoxelLightList)); + ctx.cmd.SetGlobalBuffer(HDShaderIDs.g_vBigTileLightList, data.probeVolumeBigTile); + ctx.cmd.SetGlobalBuffer(HDShaderIDs.g_vProbeVolumesLayeredOffsetsBuffer, data.probeVolumePerVoxelOffset); + ctx.cmd.SetGlobalBuffer(HDShaderIDs.g_vProbeVolumesLightListGlobal, data.probeVolumePerVoxelLightList); // int useDepthBuffer = 0; // cmd.SetGlobalInt(HDShaderIDs.g_isLogBaseBufferEnabled, useDepthBuffer); } @@ -483,7 +483,7 @@ void RenderGBuffer(RenderGraph renderGraph, TextureHandle sssBuffer, ref Prepass { BindProbeVolumeGlobalData(data.frameSettings, data, context); BindDBufferGlobalData(data.dBuffer, context); - DrawOpaqueRendererList(context, data.frameSettings, context.resources.GetRendererList(data.rendererList)); + DrawOpaqueRendererList(context, data.frameSettings, data.rendererList); }); } } @@ -543,10 +543,10 @@ void ResolvePrepassBuffers(RenderGraph renderGraph, HDCamera hdCamera, ref Prepa builder.SetRenderFunc( (ResolvePrepassData data, RenderGraphContext context) => { - data.depthResolveMaterial.SetTexture(HDShaderIDs._NormalTextureMS, context.resources.GetTexture(data.normalBufferMSAA)); - data.depthResolveMaterial.SetTexture(HDShaderIDs._DepthTextureMS, context.resources.GetTexture(data.depthAsColorBufferMSAA)); + data.depthResolveMaterial.SetTexture(HDShaderIDs._NormalTextureMS, data.normalBufferMSAA); + data.depthResolveMaterial.SetTexture(HDShaderIDs._DepthTextureMS, data.depthAsColorBufferMSAA); if (data.needMotionVectors) - data.depthResolveMaterial.SetTexture(HDShaderIDs._MotionVectorTextureMS, context.resources.GetTexture(data.motionVectorBufferMSAA)); + data.depthResolveMaterial.SetTexture(HDShaderIDs._MotionVectorTextureMS, data.motionVectorBufferMSAA); context.cmd.DrawProcedural(Matrix4x4.identity, data.depthResolveMaterial, data.depthResolvePassIndex, MeshTopology.Triangles, 3, 1); }); @@ -579,7 +579,6 @@ void CopyDepthBufferIfNeeded(RenderGraph renderGraph, HDCamera hdCamera, ref Pre builder.SetRenderFunc( (CopyDepthPassData data, RenderGraphContext context) => { - RenderGraphResourceRegistry resources = context.resources; // TODO: maybe we don't actually need the top MIP level? // That way we could avoid making the copy, and build the MIP hierarchy directly. // The downside is that our SSR tracing accuracy would decrease a little bit. @@ -588,7 +587,7 @@ void CopyDepthBufferIfNeeded(RenderGraph renderGraph, HDCamera hdCamera, ref Pre // TODO: reading the depth buffer with a compute shader will cause it to decompress in place. // On console, to preserve the depth test performance, we must NOT decompress the 'm_CameraDepthStencilBuffer' in place. // We should call decompressDepthSurfaceToCopy() and decompress it to 'm_CameraDepthBufferMipChain'. - data.GPUCopy.SampleCopyChannel_xyzw2x(context.cmd, resources.GetTexture(data.inputDepth), resources.GetTexture(data.outputDepth), new RectInt(0, 0, data.width, data.height)); + data.GPUCopy.SampleCopyChannel_xyzw2x(context.cmd, data.inputDepth, data.outputDepth, new RectInt(0, 0, data.width, data.height)); }); } @@ -617,14 +616,9 @@ void BuildCoarseStencilAndResolveIfNeeded(RenderGraph renderGraph, HDCamera hdCa builder.SetRenderFunc( (ResolveStencilPassData data, RenderGraphContext context) => { - var res = context.resources; - BuildCoarseStencilAndResolveIfNeeded(data.parameters, - res.GetTexture(data.inputDepth), - res.GetTexture(data.resolvedStencil), - res.GetComputeBuffer(data.coarseStencilBuffer), - context.cmd); - } - ); + BuildCoarseStencilAndResolveIfNeeded(data.parameters, data.inputDepth, data.resolvedStencil, data.coarseStencilBuffer, context.cmd); + }); + bool isMSAAEnabled = hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA); if (isMSAAEnabled) { @@ -727,8 +721,6 @@ void RenderDBuffer(RenderGraph renderGraph, HDCamera hdCamera, ref PrepassOutput builder.SetRenderFunc( (RenderDBufferPassData data, RenderGraphContext context) => { - RenderGraphResourceRegistry resources = context.resources; - RenderTargetIdentifier[] rti = context.renderGraphPool.GetTempArray(data.dBufferCount); RTHandle[] rt = context.renderGraphPool.GetTempArray(data.dBufferCount); @@ -736,16 +728,16 @@ void RenderDBuffer(RenderGraph renderGraph, HDCamera hdCamera, ref PrepassOutput // This way we can directly use the UseColorBuffer API and set clear color directly at resource creation and not in the RenderDBuffer shared function. for (int i = 0; i < data.dBufferCount; ++i) { - rt[i] = resources.GetTexture(data.mrt[i]); + rt[i] = data.mrt[i]; rti[i] = rt[i]; } RenderDBuffer( data.parameters, rti, rt, - resources.GetTexture(data.depthStencilBuffer), - resources.GetRendererList(data.meshDecalsRendererList), - resources.GetComputeBuffer(data.propertyMaskBuffer), + data.depthStencilBuffer, + data.meshDecalsRendererList, + data.propertyMaskBuffer, context.renderContext, context.cmd); }); @@ -770,13 +762,9 @@ void DecalNormalPatch(RenderGraph renderGraph, HDCamera hdCamera, ref PrepassOut { RTHandle[] mrt = ctx.renderGraphPool.GetTempArray(data.dBuffer.dBufferCount); for (int i = 0; i < data.dBuffer.dBufferCount; ++i) - mrt[i] = ctx.resources.GetTexture(data.dBuffer.mrt[i]); + mrt[i] = data.dBuffer.mrt[i]; - DecalNormalPatch( data.parameters, - mrt, - ctx.resources.GetTexture(data.depthStencilBuffer), - ctx.resources.GetTexture(data.normalBuffer), - ctx.cmd); + DecalNormalPatch(data.parameters, mrt, data.depthStencilBuffer, data.normalBuffer, ctx.cmd); }); } } @@ -803,7 +791,7 @@ void GenerateDepthPyramid(RenderGraph renderGraph, HDCamera hdCamera, ref Prepas builder.SetRenderFunc( (GenerateDepthPyramidPassData data, RenderGraphContext context) => { - data.mipGenerator.RenderMinDepthPyramid(context.cmd, context.resources.GetTexture(data.depthTexture), data.mipInfo); + data.mipGenerator.RenderMinDepthPyramid(context.cmd, data.depthTexture, data.mipInfo); }); output.depthPyramidTexture = passData.depthTexture; @@ -842,8 +830,7 @@ void RenderCameraMotionVectors(RenderGraph renderGraph, HDCamera hdCamera, Textu builder.SetRenderFunc( (CameraMotionVectorsPassData data, RenderGraphContext context) => { - var res = context.resources; - HDUtils.DrawFullScreen(context.cmd, data.cameraMotionVectorsMaterial, res.GetTexture(data.motionVectorsBuffer), res.GetTexture(data.depthBuffer), null, 0); + HDUtils.DrawFullScreen(context.cmd, data.cameraMotionVectorsMaterial,data.motionVectorsBuffer, data.depthBuffer, null, 0); }); } } 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 97c5d689500..159c141dc8a 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 @@ -323,9 +323,7 @@ void BlitFinalCameraTexture(RenderGraph renderGraph, HDCamera hdCamera, TextureH builder.SetRenderFunc( (FinalBlitPassData data, RenderGraphContext context) => { - var sourceTexture = context.resources.GetTexture(data.source); - var destinationTexture = context.resources.GetTexture(data.destination); - BlitFinalCameraTexture(data.parameters, context.renderGraphPool.GetTempMaterialPropertyBlock(), sourceTexture, destinationTexture, context.cmd); + BlitFinalCameraTexture(data.parameters, context.renderGraphPool.GetTempMaterialPropertyBlock(), data.source, data.destination, context.cmd); }); } } @@ -365,7 +363,7 @@ void SetFinalTarget(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle de (SetFinalTargetPassData data, RenderGraphContext ctx) => { // We need to make sure the viewport is correctly set for the editor rendering. It might have been changed by debug overlay rendering just before. - ctx.cmd.SetRenderTarget(ctx.resources.GetTexture(data.finalTarget)); + ctx.cmd.SetRenderTarget(data.finalTarget); ctx.cmd.SetViewport(data.finalViewport); if (data.copyDepth) @@ -373,7 +371,7 @@ void SetFinalTarget(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle de using (new ProfilingScope(ctx.cmd, ProfilingSampler.Get(HDProfileId.CopyDepthInTargetTexture))) { var mpb = ctx.renderGraphPool.GetTempMaterialPropertyBlock(); - mpb.SetTexture(HDShaderIDs._InputDepth, ctx.resources.GetTexture(data.depthBuffer)); + mpb.SetTexture(HDShaderIDs._InputDepth, data.depthBuffer); // When we are Main Game View we need to flip the depth buffer ourselves as we are after postprocess / blit that have already flipped the screen mpb.SetInt("_FlipY", data.flipY ? 1 : 0); mpb.SetVector(HDShaderIDs._BlitScaleBias, new Vector4(1.0f, 1.0f, 0.0f, 0.0f)); @@ -479,17 +477,12 @@ void RenderForwardOpaque( RenderGraph renderGraph, // TODO RENDERGRAPH: replace with UseColorBuffer when removing old rendering (SetRenderTarget is called inside RenderForwardRendererList because of that). var mrt = context.renderGraphPool.GetTempArray(data.renderTargetCount); for (int i = 0; i < data.renderTargetCount; ++i) - mrt[i] = context.resources.GetTexture(data.renderTarget[i]); + mrt[i] = data.renderTarget[i]; if (data.dbuffer != null) BindDBufferGlobalData(data.dbuffer.Value, context); - RenderForwardRendererList(data.frameSettings, - context.resources.GetRendererList(data.rendererList), - mrt, - context.resources.GetTexture(data.depthBuffer), - context.resources.GetComputeBuffer(data.lightListBuffer), - true, context.renderContext, context.cmd); + RenderForwardRendererList(data.frameSettings, data.rendererList, mrt, data.depthBuffer, data.lightListBuffer, true, context.renderContext, context.cmd); }); } } @@ -558,23 +551,18 @@ void RenderForwardTransparent( RenderGraph renderGraph, // TODO: replace with UseColorBuffer when removing old rendering. var mrt = context.renderGraphPool.GetTempArray(data.renderTargetCount); for (int i = 0; i < data.renderTargetCount; ++i) - mrt[i] = context.resources.GetTexture(data.renderTarget[i]); + mrt[i] = data.renderTarget[i]; // Bind all global data/parameters for transparent forward pass context.cmd.SetGlobalInt(HDShaderIDs._ColorMaskTransparentVel, data.renderMotionVecForTransparent ? (int)ColorWriteMask.All : 0); if (data.decalsEnabled) DecalSystem.instance.SetAtlas(context.cmd); // for clustered decals - context.cmd.SetGlobalBuffer(HDShaderIDs.g_vLayeredOffsetsBuffer, context.resources.GetComputeBuffer(data.perVoxelOffset)); - context.cmd.SetGlobalBuffer(HDShaderIDs.g_logBaseBuffer, context.resources.GetComputeBuffer(data.perTileLogBaseTweak)); - context.cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, context.resources.GetTexture(data.ssrLlightingBuffer)); + context.cmd.SetGlobalBuffer(HDShaderIDs.g_vLayeredOffsetsBuffer, data.perVoxelOffset); + context.cmd.SetGlobalBuffer(HDShaderIDs.g_logBaseBuffer, data.perTileLogBaseTweak); + context.cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, data.ssrLlightingBuffer); - RenderForwardRendererList( data.frameSettings, - context.resources.GetRendererList(data.rendererList), - mrt, - context.resources.GetTexture(data.depthBuffer), - context.resources.GetComputeBuffer(data.lightListBuffer), - false, context.renderContext, context.cmd); + RenderForwardRendererList( data.frameSettings, data.rendererList, mrt, data.depthBuffer, data.lightListBuffer, false, context.renderContext, context.cmd); }); } } @@ -599,7 +587,7 @@ void RenderTransparentDepthPrepass(RenderGraph renderGraph, HDCamera hdCamera, i builder.SetRenderFunc( (ForwardPassData data, RenderGraphContext context) => { - DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, context.resources.GetRendererList(data.rendererList)); + DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, data.rendererList); }); } } @@ -620,7 +608,7 @@ void RenderTransparentDepthPostpass(RenderGraph renderGraph, HDCamera hdCamera, builder.SetRenderFunc( (ForwardPassData data, RenderGraphContext context) => { - DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, context.resources.GetRendererList(data.rendererList)); + DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, data.rendererList); }); } } @@ -690,7 +678,7 @@ TextureHandle RenderLowResTransparent(RenderGraph renderGraph, HDCamera hdCamera UpdateOffscreenRenderingConstants(ref data.globalCB, true, 2u); ConstantBuffer.PushGlobal(context.cmd, data.globalCB, HDShaderIDs._ShaderVariablesGlobal); - DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, context.resources.GetRendererList(data.rendererList)); + DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, data.rendererList); UpdateOffscreenRenderingConstants(ref data.globalCB, false, 1u); ConstantBuffer.PushGlobal(context.cmd, data.globalCB, HDShaderIDs._ShaderVariablesGlobal); @@ -730,9 +718,8 @@ void UpsampleTransparent(RenderGraph renderGraph, HDCamera hdCamera, TextureHand builder.SetRenderFunc( (UpsampleTransparentPassData data, RenderGraphContext context) => { - var res = context.resources; - data.upsampleMaterial.SetTexture(HDShaderIDs._LowResTransparent, res.GetTexture(data.lowResTransparentBuffer)); - data.upsampleMaterial.SetTexture(HDShaderIDs._LowResDepthTexture, res.GetTexture(data.downsampledDepthBuffer)); + data.upsampleMaterial.SetTexture(HDShaderIDs._LowResTransparent, data.lowResTransparentBuffer); + data.upsampleMaterial.SetTexture(HDShaderIDs._LowResDepthTexture, data.downsampledDepthBuffer); context.cmd.DrawProcedural(Matrix4x4.identity, data.upsampleMaterial, 0, MeshTopology.Triangles, 3, 1, null); }); } @@ -815,11 +802,11 @@ void RenderForwardEmissive( RenderGraph renderGraph, builder.SetRenderFunc( (RenderForwardEmissivePassData data, RenderGraphContext context) => - { - HDUtils.DrawRendererList(context.renderContext, context.cmd, context.resources.GetRendererList(data.rendererList)); - if (data.enableDecals) - DecalSystem.instance.RenderForwardEmissive(context.cmd); - }); + { + HDUtils.DrawRendererList(context.renderContext, context.cmd, data.rendererList); + if (data.enableDecals) + DecalSystem.instance.RenderForwardEmissive(context.cmd); + }); } } @@ -842,7 +829,7 @@ void RenderForwardError(RenderGraph renderGraph, builder.SetRenderFunc( (ForwardPassData data, RenderGraphContext context) => { - HDUtils.DrawRendererList(context.renderContext, context.cmd, context.resources.GetRendererList(data.rendererList)); + HDUtils.DrawRendererList(context.renderContext, context.cmd, data.rendererList); }); } } @@ -872,7 +859,7 @@ void SendGeometryGraphicsBuffers(RenderGraph renderGraph, TextureHandle normalBu builder.SetRenderFunc( (SendGeometryBuffersPassData data, RenderGraphContext ctx) => { - SendGeometryGraphicsBuffers(data.parameters, ctx.resources.GetTexture(data.normalBuffer), ctx.resources.GetTexture(data.depthBuffer), ctx.cmd); + SendGeometryGraphicsBuffers(data.parameters, data.normalBuffer, data.depthBuffer, ctx.cmd); }); } } @@ -917,7 +904,7 @@ void ClearStencilBuffer(RenderGraph renderGraph, TextureHandle colorBuffer, Text (ClearStencilPassData data, RenderGraphContext ctx) => { data.clearStencilMaterial.SetInt(HDShaderIDs._StencilMask, (int)StencilUsage.HDRPReservedBits); - HDUtils.DrawFullScreen(ctx.cmd, data.clearStencilMaterial, ctx.resources.GetTexture(data.colorBuffer), ctx.resources.GetTexture(data.depthBuffer)); + HDUtils.DrawFullScreen(ctx.cmd, data.clearStencilMaterial, data.colorBuffer, data.depthBuffer); }); } } @@ -955,11 +942,7 @@ void PreRenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colo builder.SetRenderFunc( (PreRenderSkyPassData data, RenderGraphContext context) => { - var depthBuffer = context.resources.GetTexture(data.depthStencilBuffer); - var destination = context.resources.GetTexture(data.colorBuffer); - var normalBuffer= context.resources.GetTexture(data.normalBuffer); - - data.skyManager.PreRenderSky(data.hdCamera, data.sunLight, destination, normalBuffer, depthBuffer, data.debugDisplaySettings, data.frameCount, context.cmd); + data.skyManager.PreRenderSky(data.hdCamera, data.sunLight, data.colorBuffer, data.normalBuffer, data.depthStencilBuffer, data.debugDisplaySettings, data.frameCount, context.cmd); }); } } @@ -1006,17 +989,12 @@ void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBu // Necessary to perform dual-source (polychromatic alpha) blending which is not supported by Unity. // We load from the color buffer, perform blending manually, and store to the atmospheric scattering buffer. // Then we perform a copy from the atmospheric scattering buffer back to the color buffer. - var depthBuffer = context.resources.GetTexture(data.depthStencilBuffer); - var destination = context.resources.GetTexture(data.colorBuffer); - var intermediateBuffer = context.resources.GetTexture(data.intermediateBuffer); - var inputVolumetric = context.resources.GetTexture(data.volumetricLighting); - - data.skyManager.RenderSky(data.hdCamera, data.sunLight, destination, depthBuffer, data.debugDisplaySettings, data.frameCount, context.cmd); + data.skyManager.RenderSky(data.hdCamera, data.sunLight, data.colorBuffer, data.depthStencilBuffer, data.debugDisplaySettings, data.frameCount, context.cmd); if (Fog.IsFogEnabled(data.hdCamera) || Fog.IsPBRFogEnabled(data.hdCamera)) { var pixelCoordToViewDirWS = data.hdCamera.mainViewConstants.pixelCoordToViewDirWS; - data.skyManager.RenderOpaqueAtmosphericScattering(context.cmd, data.hdCamera, destination, inputVolumetric, intermediateBuffer, depthBuffer, pixelCoordToViewDirWS, data.hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA)); + data.skyManager.RenderOpaqueAtmosphericScattering(context.cmd, data.hdCamera, data.colorBuffer, data.volumetricLighting, data.intermediateBuffer, data.depthStencilBuffer, pixelCoordToViewDirWS, data.hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA)); } }); } @@ -1057,9 +1035,7 @@ void GenerateColorPyramid(RenderGraph renderGraph, HDCamera hdCamera, TextureHan (GenerateColorPyramidData data, RenderGraphContext context) => { Vector2Int pyramidSize = new Vector2Int(data.hdCamera.actualWidth, data.hdCamera.actualHeight); - var colorPyramid = context.resources.GetTexture(data.colorPyramid); - var inputTexture = context.resources.GetTexture(data.inputColor); - data.hdCamera.colorPyramidHistoryMipCount = data.mipGenerator.RenderColorGaussianPyramid(context.cmd, pyramidSize, inputTexture, colorPyramid); + data.hdCamera.colorPyramidHistoryMipCount = data.mipGenerator.RenderColorGaussianPyramid(context.cmd, pyramidSize, data.inputColor, data.colorPyramid); }); } @@ -1094,7 +1070,7 @@ TextureHandle AccumulateDistortion( RenderGraph renderGraph, builder.SetRenderFunc( (AccumulateDistortionPassData data, RenderGraphContext context) => { - DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, context.resources.GetRendererList(data.distortionRendererList)); + DrawTransparentRendererList(context.renderContext, context.cmd, data.frameSettings, data.distortionRendererList); }); return passData.distortionBuffer; @@ -1133,15 +1109,14 @@ void RenderDistortion( RenderGraph renderGraph, builder.SetRenderFunc( (RenderDistortionPassData data, RenderGraphContext context) => { - var res = context.resources; // TODO: Set stencil stuff via parameters rather than hard-coding it in shader. - data.applyDistortionMaterial.SetTexture(HDShaderIDs._DistortionTexture, res.GetTexture(data.distortionBuffer)); - data.applyDistortionMaterial.SetTexture(HDShaderIDs._ColorPyramidTexture, res.GetTexture(data.colorPyramidBuffer)); + data.applyDistortionMaterial.SetTexture(HDShaderIDs._DistortionTexture, data.distortionBuffer); + data.applyDistortionMaterial.SetTexture(HDShaderIDs._ColorPyramidTexture, data.colorPyramidBuffer); data.applyDistortionMaterial.SetVector(HDShaderIDs._Size, data.size); data.applyDistortionMaterial.SetInt(HDShaderIDs._StencilMask, (int)StencilUsage.DistortionVectors); data.applyDistortionMaterial.SetInt(HDShaderIDs._StencilRef, (int)StencilUsage.DistortionVectors); - HDUtils.DrawFullScreen(context.cmd, data.applyDistortionMaterial, res.GetTexture(data.colorBuffer), res.GetTexture(data.depthStencilBuffer), null, 0); + HDUtils.DrawFullScreen(context.cmd, data.applyDistortionMaterial, data.colorBuffer, data.depthStencilBuffer, null, 0); }); } } @@ -1202,9 +1177,8 @@ TextureHandle ResolveMSAAColor(RenderGraph renderGraph, HDCamera hdCamera, Textu builder.SetRenderFunc( (ResolveColorData data, RenderGraphContext context) => { - var res = context.resources; var mpb = context.renderGraphPool.GetTempMaterialPropertyBlock(); - mpb.SetTexture(HDShaderIDs._ColorTextureMS, res.GetTexture(data.input)); + mpb.SetTexture(HDShaderIDs._ColorTextureMS, data.input); context.cmd.DrawProcedural(Matrix4x4.identity, data.resolveMaterial, data.passIndex, MeshTopology.Triangles, 3, 1, mpb); }); @@ -1239,9 +1213,8 @@ TextureHandle ResolveMotionVector(RenderGraph renderGraph, HDCamera hdCamera, Te builder.SetRenderFunc( (ResolveMotionVectorData data, RenderGraphContext context) => { - var res = context.resources; var mpb = context.renderGraphPool.GetTempMaterialPropertyBlock(); - mpb.SetTexture(HDShaderIDs._MotionVectorTextureMS, res.GetTexture(data.input)); + mpb.SetTexture(HDShaderIDs._MotionVectorTextureMS, data.input); context.cmd.DrawProcedural(Matrix4x4.identity, data.resolveMaterial, data.passIndex, MeshTopology.Triangles, 3, 1, mpb); }); @@ -1279,7 +1252,7 @@ void RenderAccumulation(RenderGraph renderGraph, HDCamera hdCamera, TextureHandl builder.SetRenderFunc( (RenderAccumulationPassData data, RenderGraphContext ctx) => { - RenderAccumulation(data.parameters, ctx.resources.GetTexture(data.input), ctx.resources.GetTexture(data.output), ctx.resources.GetTexture(data.history), ctx.cmd); + RenderAccumulation(data.parameters, data.input, data.output, data.history, ctx.cmd); }); } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraphUtils.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraphUtils.cs index 8c41d4e0f24..52d3f67d800 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraphUtils.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.RenderGraphUtils.cs @@ -147,7 +147,7 @@ void RenderXROcclusionMeshes(RenderGraph renderGraph, HDCamera hdCamera, Texture builder.SetRenderFunc( (RenderOcclusionMeshesPassData data, RenderGraphContext ctx) => { - data.hdCamera.xr.RenderOcclusionMeshes(ctx.cmd, data.clearColor, ctx.resources.GetTexture(data.colorBuffer), ctx.resources.GetTexture(data.depthBuffer)); + data.hdCamera.xr.RenderOcclusionMeshes(ctx.cmd, data.clearColor, data.colorBuffer, data.depthBuffer); }); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.SubsurfaceScattering.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.SubsurfaceScattering.cs index 9815274982a..23e9b85a1b6 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.SubsurfaceScattering.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.SubsurfaceScattering.cs @@ -64,13 +64,13 @@ void RenderSubsurfaceScattering(RenderGraph renderGraph, HDCamera hdCamera, Text (SubsurfaceScaterringPassData data, RenderGraphContext context) => { var resources = new SubsurfaceScatteringResources(); - resources.colorBuffer = context.resources.GetTexture(data.colorBuffer); - resources.diffuseBuffer = context.resources.GetTexture(data.diffuseBuffer); - resources.depthStencilBuffer = context.resources.GetTexture(data.depthStencilBuffer); - resources.depthTexture = context.resources.GetTexture(data.depthTexture); - resources.cameraFilteringBuffer = context.resources.GetTexture(data.cameraFilteringBuffer); - resources.sssBuffer = context.resources.GetTexture(data.sssBuffer); - resources.coarseStencilBuffer = context.resources.GetComputeBuffer(data.coarseStencilBuffer); + resources.colorBuffer = data.colorBuffer; + resources.diffuseBuffer = data.diffuseBuffer; + resources.depthStencilBuffer = data.depthStencilBuffer; + resources.depthTexture = data.depthTexture; + resources.cameraFilteringBuffer = data.cameraFilteringBuffer; + resources.sssBuffer = data.sssBuffer; + resources.coarseStencilBuffer = data.coarseStencilBuffer; RenderSubsurfaceScattering(data.parameters, resources, context.cmd); }); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs index 8dc863829f2..65e7c0ce60c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs @@ -256,7 +256,7 @@ List targets builder.SetRenderFunc( (PushCameraTexturePassData data, RenderGraphContext ctx) => { - HDUtils.BlitCameraTexture(ctx.cmd, ctx.resources.GetTexture(data.source), data.targets[data.requestIndex]); + HDUtils.BlitCameraTexture(ctx.cmd, data.source, data.targets[data.requestIndex]); }); } } From 009691a6e93719a11a49f266484c71eea83ea8a6 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Mon, 29 Jun 2020 15:50:14 +0200 Subject: [PATCH 02/23] Post merge fixes --- .../Runtime/RenderGraph/RenderGraph.cs | 2 +- .../RenderPass/AOV/AOVRequestData.cs | 2 +- .../RenderPass/CustomPass/CustomPass.cs | 27 +++++++++---------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs index d0dbeb23cc8..9b562419e1a 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs @@ -20,7 +20,7 @@ public enum DepthAccess } /// - /// This struct specifies the context given to every render pass. + /// This class specifies the context given to every render pass. /// public class RenderGraphContext { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs index 9788b0f4722..5e36d58fc06 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs @@ -215,7 +215,7 @@ List targets builder.SetRenderFunc( (PushCameraTexturePassData data, RenderGraphContext ctx) => { - HDUtils.BlitCameraTexture(ctx.cmd, ctx.resources.GetTexture(data.source), data.target); + HDUtils.BlitCameraTexture(ctx.cmd, data.source, data.target); }); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPass.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPass.cs index ee7019aa0df..7efc28f2a9b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPass.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPass.cs @@ -66,8 +66,6 @@ internal ProfilingSampler profilingSampler CustomPassVolume owner; SharedRTManager currentRTManager; HDCamera currentHDCamera; - // This is a bit dirty but necessary as users may call function that need it but they don't have the instance to pass on. - RenderGraphContext currentRenderGraphContext; MaterialPropertyBlock userMaterialPropertyBlock; @@ -259,7 +257,6 @@ internal void ExecuteInternal(RenderGraph renderGraph, HDCamera hdCamera, Cullin (ExecutePassData data, RenderGraphContext ctx) => { var customPass = data.customPass; - customPass.currentRenderGraphContext = ctx; if (!customPass.isSetup) { @@ -272,15 +269,15 @@ internal void ExecuteInternal(RenderGraph renderGraph, HDCamera hdCamera, Cullin customPass.SetCustomPassTarget(ctx.cmd); - var outputColorBuffer = ctx.resources.GetTexture(customPass.currentRenderTarget.colorBufferRG); + var outputColorBuffer = customPass.currentRenderTarget.colorBufferRG; // Create the custom pass context: CustomPassContext customPassCtx = new CustomPassContext( ctx.renderContext, ctx.cmd, data.hdCamera, data.cullingResult, outputColorBuffer, - ctx.resources.GetTexture(customPass.currentRenderTarget.depthBufferRG), - ctx.resources.GetTexture(customPass.currentRenderTarget.normalBufferRG), + customPass.currentRenderTarget.depthBufferRG, + customPass.currentRenderTarget.normalBufferRG, customPass.currentRenderTarget.customColorBuffer, customPass.currentRenderTarget.customDepthBuffer, ctx.renderGraphPool.GetTempMaterialPropertyBlock() @@ -345,8 +342,8 @@ void SetCustomPassTarget(CommandBuffer cmd) } else { - colorBuffer = (targetColorBuffer == TargetBuffer.Custom) ? currentRenderTarget.customColorBuffer.Value : currentRenderGraphContext.resources.GetTexture(currentRenderTarget.colorBufferRG); - depthBuffer = (targetDepthBuffer == TargetBuffer.Custom) ? currentRenderTarget.customDepthBuffer.Value : currentRenderGraphContext.resources.GetTexture(currentRenderTarget.depthBufferRG); + colorBuffer = (targetColorBuffer == TargetBuffer.Custom) ? currentRenderTarget.customColorBuffer.Value : currentRenderTarget.colorBufferRG; + depthBuffer = (targetDepthBuffer == TargetBuffer.Custom) ? currentRenderTarget.customDepthBuffer.Value : currentRenderTarget.depthBufferRG; } if (targetColorBuffer == TargetBuffer.None && targetDepthBuffer != TargetBuffer.None) @@ -416,8 +413,8 @@ protected void SetCameraRenderTarget(CommandBuffer cmd, bool bindDepth = true, C RTHandle colorBuffer, depthBuffer; if (currentRenderTarget.useRenderGraph) { - colorBuffer = currentRenderGraphContext.resources.GetTexture(currentRenderTarget.colorBufferRG); - depthBuffer = currentRenderGraphContext.resources.GetTexture(currentRenderTarget.depthBufferRG); + colorBuffer = currentRenderTarget.colorBufferRG; + depthBuffer = currentRenderTarget.depthBufferRG; } else { @@ -474,8 +471,8 @@ protected void ResolveMSAAColorBuffer(CommandBuffer cmd, HDCamera hdCamera) RTHandle input, output; if (currentRenderTarget.useRenderGraph) { - input = currentRenderGraphContext.resources.GetTexture(currentRenderTarget.colorBufferRG); - output = currentRenderGraphContext.resources.GetTexture(currentRenderTarget.nonMSAAColorBufferRG); + input = currentRenderTarget.colorBufferRG; + output = currentRenderTarget.nonMSAAColorBufferRG; } else { @@ -507,8 +504,8 @@ protected void GetCameraBuffers(out RTHandle colorBuffer, out RTHandle depthBuff bool msaa = IsMSAAEnabled(currentHDCamera); if (currentRenderTarget.useRenderGraph) { - colorBuffer = currentRenderGraphContext.resources.GetTexture(currentRenderTarget.colorBufferRG); - depthBuffer = currentRenderGraphContext.resources.GetTexture(currentRenderTarget.depthBufferRG); + colorBuffer = currentRenderTarget.colorBufferRG; + depthBuffer = currentRenderTarget.depthBufferRG; } else { @@ -543,7 +540,7 @@ protected RTHandle GetNormalBuffer() throw new Exception("GetNormalBuffer can only be called inside the CustomPass.Execute function"); if (currentRenderTarget.useRenderGraph) - return currentRenderGraphContext.resources.GetTexture(currentRenderTarget.normalBufferRG); + return currentRenderTarget.normalBufferRG; else return currentRTManager.GetNormalBuffer(IsMSAAEnabled(currentHDCamera)); } From 525db80baad9f35d5841f54f5b9e8c47b226d496 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Thu, 2 Jul 2020 14:51:07 +0200 Subject: [PATCH 03/23] Added an exception when accessing resources while not executing render graph. --- .../Runtime/RenderGraph/RenderGraph.cs | 4 +++- .../RenderGraphResourceRegistry.cs | 24 ++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs index 9b562419e1a..0d05b85aff6 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs @@ -401,7 +401,7 @@ public void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, in { m_Logger.Initialize(); - m_Resources.BeginRender(parameters.renderingWidth, parameters.renderingHeight, parameters.msaaSamples, parameters.currentFrameIndex); + m_Resources.BeginRender(parameters.currentFrameIndex); LogFrameInformation(parameters.renderingWidth, parameters.renderingHeight); @@ -424,6 +424,8 @@ public void Execute(ScriptableRenderContext renderContext, CommandBuffer cmd, in m_DebugParameters.logFrameInformation = false; m_DebugParameters.logResources = false; + + m_Resources.EndRender(); } } #endregion diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index bb7fc7c96b6..8a9657631f9 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -94,11 +94,14 @@ internal RendererListResource(in RendererListDesc desc) RenderGraphDebugParams m_RenderGraphDebug; RenderGraphLogger m_Logger; int m_CurrentFrameIndex; + bool m_IsExecutingRenderGraph; RTHandle m_CurrentBackbuffer; internal RTHandle GetTexture(in TextureHandle handle) { + CheckRenderGraphExecution(); + if (!handle.IsValid()) return null; @@ -107,6 +110,8 @@ internal RTHandle GetTexture(in TextureHandle handle) internal RendererList GetRendererList(in RendererListHandle handle) { + CheckRenderGraphExecution(); + if (!handle.IsValid() || handle >= m_RendererListResources.size) return RendererList.nullRendererList; @@ -115,6 +120,8 @@ internal RendererList GetRendererList(in RendererListHandle handle) internal ComputeBuffer GetComputeBuffer(in ComputeBufferHandle handle) { + CheckRenderGraphExecution(); + if (!handle.IsValid()) return null; @@ -152,9 +159,24 @@ ResType GetResource(DynamicArray resour return res.resource; } - internal void BeginRender(int width, int height, MSAASamples msaaSamples, int currentFrameIndex) + internal void BeginRender(int currentFrameIndex) { m_CurrentFrameIndex = currentFrameIndex; + m_IsExecutingRenderGraph = true; + } + + internal void EndRender() + { + m_IsExecutingRenderGraph = false; + } + + void CheckRenderGraphExecution() + { + // We assume that it's enough to only check in editor because we don't want to pay the cost at runtime. +#if UNITY_EDITOR + if (!m_IsExecutingRenderGraph) + throw new InvalidOperationException("Invalid cast exception. Casting resource handles to actual resource is forbidden outside of render graph execution."); +#endif } void CheckHandleValidity(in ResourceHandle res) From a4987471f8da330945bc2451187fb4db48ee5bc6 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 3 Jul 2020 17:33:15 +0200 Subject: [PATCH 04/23] Removed auto binding of global texture and updated passes accordingly. --- .../Runtime/RenderGraph/RenderGraph.cs | 24 ++--- .../Runtime/RenderGraph/RenderGraphBuilder.cs | 4 +- .../RenderGraphResourceRegistry.cs | 34 +------ .../AmbientOcclusion.RenderGraph.cs | 16 ++-- .../ScreenSpaceLighting/AmbientOcclusion.cs | 15 ++-- .../Shadow/HDShadowManager.RenderGraph.cs | 4 +- .../HDRenderPipeline.LightLoop.cs | 22 +++-- .../HDRenderPipeline.Prepass.cs | 16 ++-- .../HDRenderPipeline.RenderGraph.cs | 88 +++++++++++-------- .../RenderPipeline/HDRenderPipeline.cs | 6 +- 10 files changed, 108 insertions(+), 121 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs index 0d05b85aff6..6cd96a853f2 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs @@ -54,7 +54,6 @@ class RenderGraphDebugParams public bool tagResourceNamesWithRG; public bool clearRenderTargetsAtCreation; public bool clearRenderTargetsAtRelease; - public bool unbindGlobalTextures; public bool logFrameInformation; public bool logResources; @@ -64,7 +63,6 @@ public void RegisterDebug() list.Add(new DebugUI.BoolField { displayName = "Tag Resources with RG", getter = () => tagResourceNamesWithRG, setter = value => tagResourceNamesWithRG = value }); list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at creation", getter = () => clearRenderTargetsAtCreation, setter = value => clearRenderTargetsAtCreation = value }); list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at release", getter = () => clearRenderTargetsAtRelease, setter = value => clearRenderTargetsAtRelease = value }); - list.Add(new DebugUI.BoolField { displayName = "Unbind Global Textures", getter = () => unbindGlobalTextures, setter = value => unbindGlobalTextures = value }); list.Add(new DebugUI.Button { displayName = "Log Frame Information", action = () => logFrameInformation = true }); list.Add(new DebugUI.Button { displayName = "Log Resources", action = () => logResources = true }); @@ -267,11 +265,10 @@ public void PurgeUnusedResources() /// Any pass writing to an imported texture will be considered having side effects and can't be automatically pruned. /// /// External RTHandle that needs to be imported. - /// Optional property that allows you to specify a Shader property name to use for automatic resource binding. /// A new TextureHandle. - public TextureHandle ImportTexture(RTHandle rt, int shaderProperty = 0) + public TextureHandle ImportTexture(RTHandle rt) { - return m_Resources.ImportTexture(rt, shaderProperty); + return m_Resources.ImportTexture(rt); } /// @@ -288,22 +285,20 @@ public TextureHandle ImportBackbuffer(RenderTargetIdentifier rt) /// Create a new Render Graph Texture resource. /// /// Texture descriptor. - /// Optional property that allows you to specify a Shader property name to use for automatic resource binding. /// A new TextureHandle. - public TextureHandle CreateTexture(in TextureDesc desc, int shaderProperty = 0) + public TextureHandle CreateTexture(in TextureDesc desc) { - return m_Resources.CreateTexture(desc, shaderProperty); + return m_Resources.CreateTexture(desc); } /// /// Create a new Render Graph Texture resource using the descriptor from another texture. /// /// Texture from which the descriptor should be used. - /// Optional property that allows you to specify a Shader property name to use for automatic resource binding. /// A new TextureHandle. - public TextureHandle CreateTexture(TextureHandle texture, int shaderProperty = 0) + public TextureHandle CreateTexture(TextureHandle texture) { - return m_Resources.CreateTexture(m_Resources.GetTextureResourceDesc(texture.handle), shaderProperty); + return m_Resources.CreateTexture(m_Resources.GetTextureResourceDesc(texture.handle)); } /// @@ -899,10 +894,6 @@ void PreRenderPassExecute(in CompiledPassInfo passInfo, RenderGraphContext rgCon // TODO RENDERGRAPH merge clear and setup here if possible RenderGraphPass pass = passInfo.pass; - // TODO RENDERGRAPH remove this when we do away with auto global texture setup - // (can't put it in the profiling scope otherwise it might be executed on compute queue which is not possible for global sets) - m_Resources.PreRenderPassSetGlobalTextures(rgContext, pass.resourceReadLists[(int)RenderGraphResourceType.Texture]); - foreach (var texture in passInfo.resourceCreateList[(int)RenderGraphResourceType.Texture]) m_Resources.CreateAndClearTexture(rgContext, texture); @@ -944,9 +935,6 @@ void PostRenderPassExecute(CommandBuffer mainCmd, ref CompiledPassInfo passInfo, rgContext.cmd = mainCmd; // Restore the main command buffer. } - if (m_DebugParameters.unbindGlobalTextures) - m_Resources.PostRenderPassUnbindGlobalTextures(rgContext, pass.resourceReadLists[(int)RenderGraphResourceType.Texture]); - m_RenderGraphPool.ReleaseAllTempAlloc(); foreach (var texture in passInfo.resourceReleaseList[(int)RenderGraphResourceType.Texture]) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilder.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilder.cs index 4b93e5392ac..0633c1a92cd 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilder.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilder.cs @@ -73,7 +73,7 @@ public TextureHandle WriteTexture(in TextureHandle input) /// A new transient TextureHandle. public TextureHandle CreateTransientTexture(in TextureDesc desc) { - var result = m_Resources.CreateTexture(desc, 0, m_RenderPass.index); + var result = m_Resources.CreateTexture(desc, m_RenderPass.index); m_RenderPass.AddTransientResource(result.handle); return result; } @@ -87,7 +87,7 @@ public TextureHandle CreateTransientTexture(in TextureDesc desc) public TextureHandle CreateTransientTexture(in TextureHandle texture) { var desc = m_Resources.GetTextureResourceDesc(texture.handle); - var result = m_Resources.CreateTexture(desc, 0, m_RenderPass.index); + var result = m_Resources.CreateTexture(desc, m_RenderPass.index); m_RenderPass.AddTransientResource(result.handle); return result; } diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index 8a9657631f9..009140de42c 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -13,7 +13,6 @@ class IRenderGraphResource { public bool imported; public int cachedHash; - public int shaderProperty; public int transientPassIndex; public bool wasReleased; @@ -21,7 +20,6 @@ public virtual void Reset() { imported = false; cachedHash = -1; - shaderProperty = 0; transientPassIndex = -1; wasReleased = false; } @@ -205,12 +203,11 @@ internal int GetResourceTransientIndex(in ResourceHandle res) } // Texture Creation/Import APIs are internal because creation should only go through RenderGraph - internal TextureHandle ImportTexture(RTHandle rt, int shaderProperty = 0) + internal TextureHandle ImportTexture(RTHandle rt) { int newHandle = AddNewResource(m_Resources[(int)RenderGraphResourceType.Texture], out TextureResource texResource); texResource.resource = rt; texResource.imported = true; - texResource.shaderProperty = shaderProperty; return new TextureHandle(newHandle, this); } @@ -242,13 +239,12 @@ internal TextureHandle ImportBackbuffer(RenderTargetIdentifier rt) return result; } - internal TextureHandle CreateTexture(in TextureDesc desc, int shaderProperty = 0, int transientPassIndex = -1) + internal TextureHandle CreateTexture(in TextureDesc desc, int transientPassIndex = -1) { ValidateTextureDesc(desc); int newHandle = AddNewResource(m_Resources[(int)RenderGraphResourceType.Texture], out TextureResource texResource); texResource.desc = desc; - texResource.shaderProperty = shaderProperty; texResource.transientPassIndex = transientPassIndex; return new TextureHandle(newHandle, this); } @@ -404,32 +400,6 @@ internal void CreateComputeBuffer(RenderGraphContext rgContext, int index) } } - void SetGlobalTextures(RenderGraphContext rgContext, List textures, bool bindDummyTexture) - { - foreach (var resource in textures) - { - var resourceDesc = GetTextureResource(resource); - if (resourceDesc.shaderProperty != 0) - { - if (resourceDesc.resource != null) - { - rgContext.cmd.SetGlobalTexture(resourceDesc.shaderProperty, bindDummyTexture ? TextureXR.GetMagentaTexture() : resourceDesc.resource); - } - } - } - } - - - internal void PreRenderPassSetGlobalTextures(RenderGraphContext rgContext, List textures) - { - SetGlobalTextures(rgContext, textures, false); - } - - internal void PostRenderPassUnbindGlobalTextures(RenderGraphContext rgContext, List textures) - { - SetGlobalTextures(rgContext, textures, true); - } - internal void ReleaseTexture(RenderGraphContext rgContext, int index) { var resource = m_Resources[(int)RenderGraphResourceType.Texture][index] as TextureResource; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs index 51dc68f4f0f..31a19c957b1 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.RenderGraph.cs @@ -7,7 +7,7 @@ partial class AmbientOcclusionSystem { TextureHandle CreateAmbientOcclusionTexture(RenderGraph renderGraph) { - return renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { enableRandomWrite = true, colorFormat = GraphicsFormat.R8_UNorm, name = "Ambient Occlusion" }, HDShaderIDs._AmbientOcclusionTexture); + return renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) { enableRandomWrite = true, colorFormat = GraphicsFormat.R8_UNorm, name = "Ambient Occlusion" }); } public TextureHandle Render(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthPyramid, TextureHandle normalBuffer, TextureHandle motionVectors, int frameCount, in HDUtils.PackedMipChainInfo depthMipInfo) @@ -33,12 +33,12 @@ public TextureHandle Render(RenderGraph renderGraph, HDCamera hdCamera, TextureH var aoParameters = PrepareRenderAOParameters(hdCamera, historySize * rtScaleForHistory, frameCount, depthMipInfo); var packedData = RenderAO(renderGraph, aoParameters, depthPyramid, normalBuffer); - result = DenoiseAO(renderGraph, aoParameters, motionVectors, packedData, currentHistory, outputHistory); + result = DenoiseAO(renderGraph, aoParameters, depthPyramid, motionVectors, packedData, currentHistory, outputHistory); } } else { - result = renderGraph.ImportTexture(TextureXR.GetBlackTexture(), HDShaderIDs._AmbientOcclusionTexture); + result = renderGraph.ImportTexture(TextureXR.GetBlackTexture()); } return result; } @@ -88,6 +88,7 @@ class DenoiseAOPassData TextureHandle DenoiseAO( RenderGraph renderGraph, in RenderAOParameters parameters, + TextureHandle depthTexture, TextureHandle motionVectors, TextureHandle aoPackedData, TextureHandle currentHistory, @@ -129,6 +130,7 @@ TextureHandle DenoiseAO( RenderGraph renderGraph, data.packedDataBlurred, data.currentHistory, data.outputHistory, + data.motionVectors, data.denoiseOutput, ctx.cmd); }); @@ -137,17 +139,18 @@ TextureHandle DenoiseAO( RenderGraph renderGraph, return passData.denoiseOutput; } - return UpsampleAO(renderGraph, parameters, denoiseOutput); + return UpsampleAO(renderGraph, parameters, denoiseOutput, depthTexture); } class UpsampleAOPassData { public RenderAOParameters parameters; + public TextureHandle depthTexture; public TextureHandle input; public TextureHandle output; } - TextureHandle UpsampleAO(RenderGraph renderGraph, in RenderAOParameters parameters, TextureHandle input) + TextureHandle UpsampleAO(RenderGraph renderGraph, in RenderAOParameters parameters, TextureHandle input, TextureHandle depthTexture) { using (var builder = renderGraph.AddRenderPass("Upsample GTAO", out var passData, ProfilingSampler.Get(HDProfileId.UpSampleSSAO))) { @@ -155,12 +158,13 @@ TextureHandle UpsampleAO(RenderGraph renderGraph, in RenderAOParameters paramete passData.parameters = parameters; passData.input = builder.ReadTexture(input); + passData.depthTexture = builder.ReadTexture(depthTexture); passData.output = builder.WriteTexture(CreateAmbientOcclusionTexture(renderGraph)); builder.SetRenderFunc( (UpsampleAOPassData data, RenderGraphContext ctx) => { - UpsampleAO(data.parameters, data.input, data.output, ctx.cmd); + UpsampleAO(data.parameters, data.depthTexture, data.input, data.output, ctx.cmd); }); return passData.output; diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs index f2b43eca525..edc5b7fc9df 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/ScreenSpaceLighting/AmbientOcclusion.cs @@ -299,7 +299,7 @@ internal void InitRaytracing(HDRenderPipeline renderPipeline) internal bool IsActive(HDCamera camera, AmbientOcclusion settings) => camera.frameSettings.IsEnabled(FrameSettingsField.SSAO) && settings.intensity.value > 0f; - internal void Render(CommandBuffer cmd, HDCamera camera, ScriptableRenderContext renderContext, RTHandle depthTexture, RTHandle normalBuffer, in ShaderVariablesRaytracing globalRTCB, int frameCount) + internal void Render(CommandBuffer cmd, HDCamera camera, ScriptableRenderContext renderContext, RTHandle depthTexture, RTHandle normalBuffer, RTHandle motionVectors, in ShaderVariablesRaytracing globalRTCB, int frameCount) { var settings = camera.volumeStack.GetComponent(); @@ -314,7 +314,7 @@ internal void Render(CommandBuffer cmd, HDCamera camera, ScriptableRenderContext m_RaytracingAmbientOcclusion.RenderAO(camera, cmd, m_AmbientOcclusionTex, globalRTCB, renderContext, frameCount); else { - Dispatch(cmd, camera, depthTexture, normalBuffer, frameCount); + Dispatch(cmd, camera, depthTexture, normalBuffer, motionVectors, frameCount); PostDispatchWork(cmd, camera); } } @@ -516,6 +516,7 @@ static void DenoiseAO( in RenderAOParameters parameters, RTHandle packedDataBlurredTex, RTHandle packedHistoryTex, RTHandle packedHistoryOutputTex, + RTHandle motionVectors, RTHandle aoOutputTex, CommandBuffer cmd) { @@ -560,12 +561,14 @@ static void DenoiseAO( in RenderAOParameters parameters, cmd.SetComputeTextureParam(blurCS, parameters.denoiseKernelTemporal, HDShaderIDs._AOPackedBlurred, packedDataBlurredTex); cmd.SetComputeTextureParam(blurCS, parameters.denoiseKernelTemporal, HDShaderIDs._AOPackedHistory, packedHistoryTex); cmd.SetComputeTextureParam(blurCS, parameters.denoiseKernelTemporal, HDShaderIDs._AOOutputHistory, packedHistoryOutputTex); + cmd.SetComputeTextureParam(blurCS, parameters.denoiseKernelTemporal, HDShaderIDs._CameraMotionVectorsTexture, motionVectors); cmd.SetComputeTextureParam(blurCS, parameters.denoiseKernelTemporal, HDShaderIDs._OcclusionTexture, aoOutputTex); cmd.DispatchCompute(blurCS, parameters.denoiseKernelTemporal, threadGroupX, threadGroupY, parameters.viewCount); } } static void UpsampleAO( in RenderAOParameters parameters, + RTHandle depthTexture, RTHandle input, RTHandle output, CommandBuffer cmd) @@ -578,6 +581,7 @@ static void UpsampleAO( in RenderAOParameters parameters, { cmd.SetComputeTextureParam(parameters.upsampleAndBlurAOCS, parameters.upsampleAndBlurKernel, HDShaderIDs._AOPackedData, input); cmd.SetComputeTextureParam(parameters.upsampleAndBlurAOCS, parameters.upsampleAndBlurKernel, HDShaderIDs._OcclusionTexture, output); + cmd.SetComputeTextureParam(parameters.upsampleAndBlurAOCS, parameters.upsampleAndBlurKernel, HDShaderIDs._CameraDepthTexture, depthTexture); const int groupSizeX = 8; const int groupSizeY = 8; @@ -590,6 +594,7 @@ static void UpsampleAO( in RenderAOParameters parameters, { cmd.SetComputeTextureParam(parameters.upsampleAndBlurAOCS, parameters.upsampleAOKernel, HDShaderIDs._AOPackedData, input); cmd.SetComputeTextureParam(parameters.upsampleAndBlurAOCS, parameters.upsampleAOKernel, HDShaderIDs._OcclusionTexture, output); + cmd.SetComputeTextureParam(parameters.upsampleAndBlurAOCS, parameters.upsampleAOKernel, HDShaderIDs._CameraDepthTexture, depthTexture); const int groupSizeX = 8; const int groupSizeY = 8; @@ -599,7 +604,7 @@ static void UpsampleAO( in RenderAOParameters parameters, } } - internal void Dispatch(CommandBuffer cmd, HDCamera camera, RTHandle depthTexture, RTHandle normalBuffer, int frameCount) + internal void Dispatch(CommandBuffer cmd, HDCamera camera, RTHandle depthTexture, RTHandle normalBuffer, RTHandle motionVectors, int frameCount) { var settings = camera.volumeStack.GetComponent(); if (IsActive(camera, settings)) @@ -625,14 +630,14 @@ internal void Dispatch(CommandBuffer cmd, HDCamera camera, RTHandle depthTexture using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.DenoiseSSAO))) { var output = m_RunningFullRes ? m_AmbientOcclusionTex : m_FinalHalfRes; - DenoiseAO(aoParameters, m_PackedDataTex, m_PackedDataBlurred, currentHistory, historyOutput, output, cmd); + DenoiseAO(aoParameters, m_PackedDataTex, m_PackedDataBlurred, currentHistory, historyOutput, motionVectors, output, cmd); } if (!m_RunningFullRes) { using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.UpSampleSSAO))) { - UpsampleAO(aoParameters, settings.temporalAccumulation.value ? m_FinalHalfRes : m_PackedDataTex, m_AmbientOcclusionTex, cmd); + UpsampleAO(aoParameters, depthTexture, settings.temporalAccumulation.value ? m_FinalHalfRes : m_PackedDataTex, m_AmbientOcclusionTex, cmd); } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs index c0ae47a28b5..c22bc4b2499 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs @@ -100,10 +100,10 @@ class RenderShadowsPassData public ShadowDrawingSettings shadowDrawSettings; } - TextureHandle AllocateMomentAtlas(RenderGraph renderGraph, string name, int shaderID = 0) + TextureHandle AllocateMomentAtlas(RenderGraph renderGraph, string name) { return renderGraph.CreateTexture(new TextureDesc(width / 2, height / 2) - { colorFormat = GraphicsFormat.R32G32_SFloat, useMipMap = true, autoGenerateMips = false, name = name, enableRandomWrite = true }, shaderID); + { colorFormat = GraphicsFormat.R32G32_SFloat, useMipMap = true, autoGenerateMips = false, name = name, enableRandomWrite = true }); } internal TextureHandle RenderShadows(RenderGraph renderGraph, CullingResults cullResults, in ShaderVariablesGlobal globalCB, FrameSettings frameSettings, string shadowPassName) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs index 82fa896ae5b..415d87b1262 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs @@ -10,8 +10,11 @@ public partial class HDRenderPipeline { struct LightingBuffers { + // TODO RENDERGRAPH: Those two buffers aren't really lighting buffers but only used for SSS + // We should probably move them out of here. public TextureHandle sssBuffer; public TextureHandle diffuseLightingBuffer; + public TextureHandle ambientOcclusionBuffer; public TextureHandle ssrLightingBuffer; public TextureHandle contactShadowsBuffer; @@ -28,6 +31,13 @@ static LightingBuffers ReadLightingBuffers(in LightingBuffers buffers, RenderGra return result; } + static void BindGlobalLightingBuffers(in LightingBuffers buffers, CommandBuffer cmd) + { + cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, buffers.ambientOcclusionBuffer); + cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, buffers.ssrLightingBuffer); + cmd.SetGlobalTexture(HDShaderIDs._ContactShadowTexture, buffers.contactShadowsBuffer); + } + class BuildGPULightListPassData { public BuildGPULightListParameters buildGPULightListParameters; @@ -345,9 +355,7 @@ LightingOutput RenderDeferredLighting( RenderGraph renderGraph, // TODO RENDERGRAPH: Remove these SetGlobal and properly send these textures to the deferred passes and bind them directly to compute shaders. // This can wait that we remove the old code path. - context.cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, data.lightingBuffers.ambientOcclusionBuffer); - context.cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, data.lightingBuffers.ssrLightingBuffer); - context.cmd.SetGlobalTexture(HDShaderIDs._ContactShadowTexture, data.lightingBuffers.contactShadowsBuffer); + BindGlobalLightingBuffers(data.lightingBuffers, context.cmd); if (data.parameters.enableTile) { @@ -432,7 +440,7 @@ TextureHandle RenderSSR( RenderGraph renderGraph, passData.hitPointsTexture = builder.CreateTransientTexture(new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R16G16_UNorm, clearBuffer = true, clearColor = Color.clear, enableRandomWrite = true, name = "SSR_Hit_Point_Texture" }); passData.lightingTexture = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) - { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, clearBuffer = true, clearColor = Color.clear, enableRandomWrite = true, name = "SSR_Lighting_Texture" }, HDShaderIDs._SsrLightingTexture)); + { colorFormat = GraphicsFormat.R16G16B16A16_SFloat, clearBuffer = true, clearColor = Color.clear, enableRandomWrite = true, name = "SSR_Lighting_Texture" })); //passData.hitPointsTexture = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) // { colorFormat = GraphicsFormat.ARGBFloat, clearBuffer = true, clearColor = Color.clear, enableRandomWrite = true, name = "SSR_Debug_Texture" })); @@ -479,7 +487,7 @@ class RenderContactShadowPassData TextureHandle RenderContactShadows(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthTexture, in BuildGPULightListOutput lightLists, int firstMipOffsetY) { if (!WillRenderContactShadow()) - return renderGraph.ImportTexture(TextureXR.GetClearTexture(), HDShaderIDs._ContactShadowTexture); + return renderGraph.defaultResources.clearTextureXR; TextureHandle result; using (var builder = renderGraph.AddRenderPass("Contact Shadows", out var passData)) @@ -494,7 +502,7 @@ TextureHandle RenderContactShadows(RenderGraph renderGraph, HDCamera hdCamera, T passData.lightList = builder.ReadComputeBuffer(lightLists.lightList); passData.depthTexture = builder.ReadTexture(depthTexture); passData.contactShadowsTexture = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) - { colorFormat = GraphicsFormat.R32_UInt, enableRandomWrite = true, clearBuffer = clearBuffer, clearColor = Color.clear, name = "ContactShadowsBuffer" }, HDShaderIDs._ContactShadowTexture)); + { colorFormat = GraphicsFormat.R32_UInt, enableRandomWrite = true, clearBuffer = clearBuffer, clearColor = Color.clear, name = "ContactShadowsBuffer" })); result = passData.contactShadowsTexture; @@ -589,7 +597,7 @@ TextureHandle VolumetricLightingPass(RenderGraph renderGraph, HDCamera hdCamera, Vector3Int viewportSize = ComputeVolumetricViewportSize(hdCamera, ref tileSize); // TODO RENDERGRAPH: Auto-scale of 3D RTs is not supported yet so we need to find a better solution for this. Or keep it as is? - passData.lightingBuffer = builder.WriteTexture(renderGraph.ImportTexture(m_LightingBuffer, HDShaderIDs._VBufferLighting)); + passData.lightingBuffer = builder.WriteTexture(renderGraph.ImportTexture(m_LightingBuffer)); if (passData.parameters.enableReprojection) { 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 e129c1db4f2..f03ed957838 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 @@ -97,14 +97,14 @@ TextureHandle CreateNormalBuffer(RenderGraph renderGraph, bool msaa) { TextureDesc normalDesc = new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm, clearBuffer = NeedClearGBuffer(), clearColor = Color.black, bindTextureMS = msaa, enableMSAA = msaa, enableRandomWrite = !msaa, name = msaa ? "NormalBufferMSAA" : "NormalBuffer" }; - return renderGraph.CreateTexture(normalDesc, msaa ? HDShaderIDs._NormalTextureMS : HDShaderIDs._NormalBufferTexture); + return renderGraph.CreateTexture(normalDesc); } TextureHandle CreateMotionVectorBuffer(RenderGraph renderGraph, bool msaa, bool clear) { TextureDesc motionVectorDesc = new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetMotionVectorFormat(), bindTextureMS = msaa, enableMSAA = msaa, clearBuffer = clear, clearColor = Color.clear, name = msaa ? "Motion Vectors MSAA" : "Motion Vectors" }; - return renderGraph.CreateTexture(motionVectorDesc, HDShaderIDs._CameraMotionVectorsTexture); + return renderGraph.CreateTexture(motionVectorDesc); } // TODO RENDERGRAPH: in someplaces we auto bind and in others we have to generate MRT because of discrepancy with non render graph path. @@ -270,7 +270,7 @@ bool RenderDepthPrepass(RenderGraph renderGraph, CullingResults cull, HDCamera h if (msaa) { passData.depthAsColorBuffer = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(Vector2.one, true, true) - { colorFormat = GraphicsFormat.R32_SFloat, clearBuffer = true, clearColor = Color.black, bindTextureMS = true, enableMSAA = true, name = "DepthAsColorMSAA" }, HDShaderIDs._DepthTextureMS)); + { colorFormat = GraphicsFormat.R32_SFloat, clearBuffer = true, clearColor = Color.black, bindTextureMS = true, enableMSAA = true, name = "DepthAsColorMSAA" })); } if (passData.hasDepthOnlyPrepass) @@ -396,26 +396,26 @@ void SetupGBufferTargets(RenderGraph renderGraph, HDCamera hdCamera, GBufferPass #if UNITY_2020_2_OR_NEWER , fastMemoryDesc = gbufferFastMemDesc #endif - }, HDShaderIDs._GBufferTexture[2]), 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" #if UNITY_2020_2_OR_NEWER , fastMemoryDesc = gbufferFastMemDesc #endif - }, HDShaderIDs._GBufferTexture[3]), 3); + }), 3); prepassOutput.gbuffer.lightLayersTextureIndex = -1; int currentIndex = 4; if (lightLayers) { passData.gbufferRT[currentIndex] = builder.UseColorBuffer(renderGraph.CreateTexture( - new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm, clearBuffer = clearGBuffer, clearColor = Color.clear, name = "LightLayers" }, HDShaderIDs._LightLayersTexture), currentIndex); + new TextureDesc(Vector2.one, true, true) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm, clearBuffer = clearGBuffer, clearColor = Color.clear, name = "LightLayers" }), currentIndex); prepassOutput.gbuffer.lightLayersTextureIndex = currentIndex++; } if (shadowMasks) { passData.gbufferRT[currentIndex] = builder.UseColorBuffer(renderGraph.CreateTexture( - new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetShadowMaskBufferFormat(), clearBuffer = clearGBuffer, clearColor = Color.clear, name = "ShadowMasks" }, HDShaderIDs._ShadowMaskTexture), currentIndex); + new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetShadowMaskBufferFormat(), clearBuffer = clearGBuffer, clearColor = Color.clear, name = "ShadowMasks" }), currentIndex); currentIndex++; } @@ -569,7 +569,7 @@ void CopyDepthBufferIfNeeded(RenderGraph renderGraph, HDCamera hdCamera, ref Pre using (var builder = renderGraph.AddRenderPass("Copy depth buffer", out var passData, ProfilingSampler.Get(HDProfileId.CopyDepthBuffer))) { passData.inputDepth = builder.ReadTexture(output.resolvedDepthBuffer); - passData.outputDepth = builder.WriteTexture(renderGraph.CreateTexture(m_DepthPyramidDesc, HDShaderIDs._CameraDepthTexture)); + passData.outputDepth = builder.WriteTexture(renderGraph.CreateTexture(m_DepthPyramidDesc)); passData.GPUCopy = m_GPUCopy; passData.width = hdCamera.actualWidth; passData.height = hdCamera.actualHeight; 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 ecdfaa14975..ff045c6f583 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 @@ -34,7 +34,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest, TextureHandle backBuffer = m_RenderGraph.ImportBackbuffer(target.id); TextureHandle colorBuffer = CreateColorBuffer(m_RenderGraph, hdCamera, msaa); m_NonMSAAColorBuffer = CreateColorBuffer(m_RenderGraph, hdCamera, false); - TextureHandle currentColorPyramid = m_RenderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain), HDShaderIDs._ColorPyramidTexture); + TextureHandle currentColorPyramid = m_RenderGraph.ImportTexture(hdCamera.GetCurrentFrameRT((int)HDCameraFrameHistoryType.ColorBufferMipChain)); LightingBuffers lightingBuffers = new LightingBuffers(); lightingBuffers.diffuseLightingBuffer = CreateDiffuseLightingBuffer(m_RenderGraph, msaa); @@ -179,7 +179,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest, // No need for old stencil values here since from transparent on different features are tagged ClearStencilBuffer(m_RenderGraph, colorBuffer, prepassOutput.depthBuffer); - colorBuffer = RenderTransparency(m_RenderGraph, hdCamera, colorBuffer, currentColorPyramid, gpuLightListOutput, ref prepassOutput, shadowResult, cullingResults, customPassCullingResults, aovRequest, aovBuffers); + colorBuffer = RenderTransparency(m_RenderGraph, hdCamera, colorBuffer, currentColorPyramid, volumetricLighting, gpuLightListOutput, ref prepassOutput, shadowResult, cullingResults, customPassCullingResults, aovRequest, aovBuffers); if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.TransparentsWriteMotionVector)) { @@ -392,26 +392,36 @@ class ForwardPassData public TextureHandle[] renderTarget = new TextureHandle[3]; public int renderTargetCount; public TextureHandle depthBuffer; - public TextureHandle ssrLlightingBuffer; public ComputeBufferHandle lightListBuffer; public ComputeBufferHandle perVoxelOffset; public ComputeBufferHandle perTileLogBaseTweak; public FrameSettings frameSettings; - public bool decalsEnabled; - public bool renderMotionVecForTransparent; - public DBufferOutput? dbuffer; } - void PrepareForwardPassData(RenderGraph renderGraph, - RenderGraphBuilder builder, - ForwardPassData data, - bool opaque, - FrameSettings frameSettings, - RendererListDesc rendererListDesc, - in BuildGPULightListOutput lightLists, - TextureHandle depthBuffer, - ShadowResult shadowResult, - DBufferOutput? dbuffer = null) + class ForwardOpaquePassData : ForwardPassData + { + public DBufferOutput dbuffer; + public LightingBuffers lightingBuffers; + } + + class ForwardTransparentPassData : ForwardPassData + { + public bool decalsEnabled; + public bool renderMotionVecForTransparent; + public TextureHandle transparentSSRLighting; + public TextureHandle volumetricLighting; + + } + + void PrepareCommonForwardPassData( RenderGraph renderGraph, + RenderGraphBuilder builder, + ForwardPassData data, + bool opaque, + FrameSettings frameSettings, + RendererListDesc rendererListDesc, + in BuildGPULightListOutput lightLists, + TextureHandle depthBuffer, + ShadowResult shadowResult) { bool useFptl = frameSettings.IsEnabled(FrameSettingsField.FPTLForForwardOpaque) && opaque; @@ -425,14 +435,8 @@ void PrepareForwardPassData(RenderGraph renderGraph, } data.depthBuffer = builder.UseDepthBuffer(depthBuffer, DepthAccess.ReadWrite); data.rendererList = builder.UseRendererList(renderGraph.CreateRendererList(rendererListDesc)); - // enable d-buffer flag value is being interpreted more like enable decals in general now that we have clustered - // decal datas count is 0 if no decals affect transparency - data.decalsEnabled = (frameSettings.IsEnabled(FrameSettingsField.Decals)) && (DecalSystem.m_DecalDatasCount > 0); - data.renderMotionVecForTransparent = NeedMotionVectorForTransparent(frameSettings); HDShadowManager.ReadShadowResult(shadowResult, builder); - if (dbuffer != null) - data.dbuffer = ReadDBuffer(dbuffer.Value, builder); } // Guidelines: In deferred by default there is no opaque in forward. However it is possible to force an opaque material to render in forward @@ -453,11 +457,11 @@ void RenderForwardOpaque( RenderGraph renderGraph, { bool debugDisplay = m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled(); - using (var builder = renderGraph.AddRenderPass( debugDisplay ? "Forward Opaque Debug" : "Forward Opaque", + using (var builder = renderGraph.AddRenderPass( debugDisplay ? "Forward Opaque Debug" : "Forward Opaque", out var passData, debugDisplay ? ProfilingSampler.Get(HDProfileId.ForwardOpaqueDebug) : ProfilingSampler.Get(HDProfileId.ForwardOpaque))) { - PrepareForwardPassData(renderGraph, builder, passData, true, hdCamera.frameSettings, PrepareForwardOpaqueRendererList(cullResults, hdCamera), lightLists, depthBuffer, shadowResult, dbuffer); + PrepareCommonForwardPassData(renderGraph, builder, passData, true, hdCamera.frameSettings, PrepareForwardOpaqueRendererList(cullResults, hdCamera), lightLists, depthBuffer, shadowResult); // In case of forward SSS we will bind all the required target. It is up to the shader to write into it or not. if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.SubsurfaceScattering)) @@ -473,18 +477,19 @@ void RenderForwardOpaque( RenderGraph renderGraph, passData.renderTargetCount = 1; } - ReadLightingBuffers(lightingBuffers, builder); + passData.dbuffer = ReadDBuffer(dbuffer, builder); + passData.lightingBuffers = ReadLightingBuffers(lightingBuffers, builder); builder.SetRenderFunc( - (ForwardPassData data, RenderGraphContext context) => + (ForwardOpaquePassData data, RenderGraphContext context) => { // TODO RENDERGRAPH: replace with UseColorBuffer when removing old rendering (SetRenderTarget is called inside RenderForwardRendererList because of that). var mrt = context.renderGraphPool.GetTempArray(data.renderTargetCount); for (int i = 0; i < data.renderTargetCount; ++i) mrt[i] = data.renderTarget[i]; - if (data.dbuffer != null) - BindDBufferGlobalData(data.dbuffer.Value, context); + BindDBufferGlobalData(data.dbuffer, context); + BindGlobalLightingBuffers(data.lightingBuffers, context.cmd); RenderForwardRendererList(data.frameSettings, data.rendererList, mrt, data.depthBuffer, data.lightListBuffer, true, context.renderContext, context.cmd); }); @@ -496,6 +501,7 @@ void RenderForwardTransparent( RenderGraph renderGraph, TextureHandle colorBuffer, TextureHandle motionVectorBuffer, TextureHandle depthBuffer, + TextureHandle volumetricLighting, TextureHandle ssrLighting, TextureHandle? colorPyramid, in BuildGPULightListOutput lightLists, @@ -521,18 +527,20 @@ void RenderForwardTransparent( RenderGraph renderGraph, profilingId = preRefractionPass ? HDProfileId.ForwardPreRefraction : HDProfileId.ForwardTransparent; } - using (var builder = renderGraph.AddRenderPass(passName, out var passData, ProfilingSampler.Get(profilingId))) + using (var builder = renderGraph.AddRenderPass(passName, out var passData, ProfilingSampler.Get(profilingId))) { - PrepareForwardPassData(renderGraph, builder, passData, false, hdCamera.frameSettings, PrepareForwardTransparentRendererList(cullResults, hdCamera, preRefractionPass), lightLists, depthBuffer, shadowResult); - - passData.ssrLlightingBuffer = builder.ReadTexture(ssrLighting); - - bool renderMotionVecForTransparent = NeedMotionVectorForTransparent(hdCamera.frameSettings); + PrepareCommonForwardPassData(renderGraph, builder, passData, false, hdCamera.frameSettings, PrepareForwardTransparentRendererList(cullResults, hdCamera, preRefractionPass), lightLists, depthBuffer, shadowResult); + // enable d-buffer flag value is being interpreted more like enable decals in general now that we have clustered + // decal datas count is 0 if no decals affect transparency + passData.decalsEnabled = (hdCamera.frameSettings.IsEnabled(FrameSettingsField.Decals)) && (DecalSystem.m_DecalDatasCount > 0); + passData.renderMotionVecForTransparent = NeedMotionVectorForTransparent(hdCamera.frameSettings); + passData.volumetricLighting = builder.ReadTexture(volumetricLighting); + passData.transparentSSRLighting = builder.ReadTexture(ssrLighting); passData.renderTargetCount = 2; passData.renderTarget[0] = builder.WriteTexture(colorBuffer); - if (renderMotionVecForTransparent) + if (passData.renderMotionVecForTransparent) { passData.renderTarget[1] = builder.WriteTexture(motionVectorBuffer); } @@ -550,7 +558,7 @@ void RenderForwardTransparent( RenderGraph renderGraph, } builder.SetRenderFunc( - (ForwardPassData data, RenderGraphContext context) => + (ForwardTransparentPassData data, RenderGraphContext context) => { // TODO: replace with UseColorBuffer when removing old rendering. var mrt = context.renderGraphPool.GetTempArray(data.renderTargetCount); @@ -564,7 +572,8 @@ void RenderForwardTransparent( RenderGraph renderGraph, context.cmd.SetGlobalBuffer(HDShaderIDs.g_vLayeredOffsetsBuffer, data.perVoxelOffset); context.cmd.SetGlobalBuffer(HDShaderIDs.g_logBaseBuffer, data.perTileLogBaseTweak); - context.cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, data.ssrLlightingBuffer); + context.cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, data.transparentSSRLighting); + context.cmd.SetGlobalTexture(HDShaderIDs._VBufferLighting, data.volumetricLighting); RenderForwardRendererList( data.frameSettings, data.rendererList, mrt, data.depthBuffer, data.lightListBuffer, false, context.renderContext, context.cmd); }); @@ -733,6 +742,7 @@ TextureHandle RenderTransparency( RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBuffer, TextureHandle currentColorPyramid, + TextureHandle volumetricLighting, in BuildGPULightListOutput lightLists, ref PrepassOutput prepassOutput, ShadowResult shadowResult, @@ -755,7 +765,7 @@ TextureHandle RenderTransparency( RenderGraph renderGraph, RenderCustomPass(m_RenderGraph, hdCamera, colorBuffer, prepassOutput.depthBuffer, prepassOutput.normalBuffer, customPassCullingResults, CustomPassInjectionPoint.BeforePreRefraction, aovRequest, aovBuffers); // Render pre-refraction objects - RenderForwardTransparent(renderGraph, hdCamera, colorBuffer, prepassOutput.motionVectorsBuffer, prepassOutput.depthBuffer, ssrLightingBuffer, null, lightLists, shadowResult, cullingResults, true); + RenderForwardTransparent(renderGraph, hdCamera, colorBuffer, prepassOutput.motionVectorsBuffer, prepassOutput.depthBuffer, volumetricLighting, ssrLightingBuffer, null, lightLists, shadowResult, cullingResults, true); if (hdCamera.frameSettings.IsEnabled(FrameSettingsField.Refraction)) { @@ -767,7 +777,7 @@ TextureHandle RenderTransparency( RenderGraph renderGraph, RenderCustomPass(m_RenderGraph, hdCamera, colorBuffer, prepassOutput.depthBuffer, prepassOutput.normalBuffer, customPassCullingResults, CustomPassInjectionPoint.BeforeTransparent, aovRequest, aovBuffers); // Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects. - RenderForwardTransparent(renderGraph, hdCamera, colorBuffer, prepassOutput.motionVectorsBuffer, prepassOutput.depthBuffer, ssrLightingBuffer, currentColorPyramid, lightLists, shadowResult, cullingResults, false); + RenderForwardTransparent(renderGraph, hdCamera, colorBuffer, prepassOutput.motionVectorsBuffer, prepassOutput.depthBuffer, volumetricLighting, ssrLightingBuffer, currentColorPyramid, lightLists, shadowResult, cullingResults, false); colorBuffer = ResolveMSAAColor(renderGraph, hdCamera, colorBuffer, m_NonMSAAColorBuffer); 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 8c5714b9d71..76a7856fa92 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2600,12 +2600,13 @@ void Callback(CommandBuffer c, HDGPUAsyncTaskParams a) { var depthTexture = m_SharedRTManager.GetDepthTexture(); var normalBuffer = m_SharedRTManager.GetNormalBuffer(); + var motionVectors = m_SharedRTManager.GetMotionVectorsBuffer(); SSAOTask.Start(cmd, asyncParams, AsyncSSAODispatch, !haveAsyncTaskWithShadows); haveAsyncTaskWithShadows = true; void AsyncSSAODispatch(CommandBuffer c, HDGPUAsyncTaskParams a) - => m_AmbientOcclusionSystem.Dispatch(c, a.hdCamera, depthTexture, normalBuffer, a.frameCount); + => m_AmbientOcclusionSystem.Dispatch(c, a.hdCamera, depthTexture, normalBuffer, motionVectors, a.frameCount); } using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.RenderShadowMaps))) @@ -2669,7 +2670,7 @@ void Callback(CommandBuffer c, HDCamera cam) } if (!hdCamera.frameSettings.SSAORunsAsync()) - m_AmbientOcclusionSystem.Render(cmd, hdCamera, renderContext, m_SharedRTManager.GetDepthTexture(), m_SharedRTManager.GetNormalBuffer(), m_ShaderVariablesRayTracingCB, m_FrameCount); + m_AmbientOcclusionSystem.Render(cmd, hdCamera, renderContext, m_SharedRTManager.GetDepthTexture(), m_SharedRTManager.GetNormalBuffer(), m_SharedRTManager.GetMotionVectorsBuffer(), m_ShaderVariablesRayTracingCB, m_FrameCount); // Run the contact shadows here as they need the light list HDUtils.CheckRTCreated(m_ContactShadowBuffer); @@ -4498,6 +4499,7 @@ static void RenderSSR( in RenderSSRParameters parameters, cmd.SetComputeTextureParam(cs, parameters.reprojectionKernel, HDShaderIDs._ColorPyramidTexture, previousColorPyramid); cmd.SetComputeTextureParam(cs, parameters.reprojectionKernel, HDShaderIDs._SsrClearCoatMaskTexture, clearCoatMask); cmd.SetComputeTextureParam(cs, parameters.reprojectionKernel, HDShaderIDs._CameraMotionVectorsTexture, motionVectorsBuffer); + cmd.SetComputeTextureParam(cs, parameters.reprojectionKernel, HDShaderIDs._NormalBufferTexture, normalBuffer); ConstantBuffer.Push(cmd, parameters.cb, cs, HDShaderIDs._ShaderVariablesScreenSpaceReflection); From fc73b49c25715130cc5734560d6f08b085c958dd Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 10:33:54 +0200 Subject: [PATCH 05/23] Post merge fix --- .../Runtime/RenderGraph/RenderGraphResourceRegistry.cs | 6 ------ .../Runtime/RenderGraph/RenderGraphResources.cs | 2 -- 2 files changed, 8 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index aae2e5c2e0f..ac5bc7124b0 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -118,8 +118,6 @@ internal RendererListResource(in RendererListDesc desc) internal RTHandle GetTexture(in TextureHandle handle) { - CheckRenderGraphExecution(); - if (!handle.IsValid()) return null; @@ -128,8 +126,6 @@ internal RTHandle GetTexture(in TextureHandle handle) internal RendererList GetRendererList(in RendererListHandle handle) { - CheckRenderGraphExecution(); - if (!handle.IsValid() || handle >= m_RendererListResources.size) return RendererList.nullRendererList; @@ -138,8 +134,6 @@ internal RendererList GetRendererList(in RendererListHandle handle) internal ComputeBuffer GetComputeBuffer(in ComputeBufferHandle handle) { - CheckRenderGraphExecution(); - if (!handle.IsValid()) return null; diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs index a9f99caaa10..de15cd4fb7b 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs @@ -94,7 +94,6 @@ public struct ComputeBufferHandle /// /// Input ComputeBufferHandle public static implicit operator ComputeBuffer(ComputeBufferHandle buffer) => buffer.IsValid() ? RenderGraphResourceRegistry.current.GetComputeBuffer(buffer) : null; - public static implicit operator ComputeBuffer(ComputeBufferHandle buffer) => buffer.IsValid() ? buffer.handle.registry.GetComputeBuffer(buffer) : null; /// /// Return true if the handle is valid. @@ -121,7 +120,6 @@ public struct RendererListHandle public static implicit operator int(RendererListHandle handle) { return handle.handle; } public static implicit operator RendererList(RendererListHandle rendererList) => rendererList.IsValid() ? RenderGraphResourceRegistry.current.GetRendererList(rendererList) : RendererList.nullRendererList; - public static implicit operator RendererList(RendererListHandle rendererList) => rendererList.IsValid() ? rendererList.registry.GetRendererList(rendererList) : RendererList.nullRendererList; /// /// Return true if the handle is valid. From 5841c165032cfdafadbac6ea6ee94443515d590d Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 11:15:37 +0200 Subject: [PATCH 06/23] Fixed shadow mask texture binding. --- .../Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs | 7 +++++++ .../Runtime/RenderPipeline/HDRenderPipeline.Prepass.cs | 4 +++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs index 415d87b1262..a0ea0620acb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs @@ -261,6 +261,7 @@ class DeferredLightingPassData public int gbufferCount; public int lightLayersTextureIndex; + public int shadowMaskTextureIndex; public TextureHandle[] gbuffer = new TextureHandle[8]; public ComputeBufferHandle lightListBuffer; @@ -311,6 +312,7 @@ LightingOutput RenderDeferredLighting( RenderGraph renderGraph, passData.lightingBuffers = ReadLightingBuffers(lightingBuffers, builder); passData.lightLayersTextureIndex = gbuffer.lightLayersTextureIndex; + passData.shadowMaskTextureIndex = gbuffer.shadowMaskTextureIndex; passData.gbufferCount = gbuffer.gBufferCount; for (int i = 0; i < gbuffer.gBufferCount; ++i) passData.gbuffer[i] = builder.ReadTexture(gbuffer.mrt[i]); @@ -353,6 +355,11 @@ LightingOutput RenderDeferredLighting( RenderGraph renderGraph, else context.cmd.SetGlobalTexture(HDShaderIDs._LightLayersTexture, TextureXR.GetWhiteTexture()); + if (data.shadowMaskTextureIndex != -1) + context.cmd.SetGlobalTexture(HDShaderIDs._ShadowMaskTexture, data.gbuffer[data.shadowMaskTextureIndex]); + else + context.cmd.SetGlobalTexture(HDShaderIDs._ShadowMaskTexture, TextureXR.GetWhiteTexture()); + // TODO RENDERGRAPH: Remove these SetGlobal and properly send these textures to the deferred passes and bind them directly to compute shaders. // This can wait that we remove the old code path. BindGlobalLightingBuffers(data.lightingBuffers, context.cmd); 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 c8a212d573f..402c2be2dbf 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 @@ -404,6 +404,7 @@ struct GBufferOutput public TextureHandle[] mrt; public int gBufferCount; public int lightLayersTextureIndex; + public int shadowMaskTextureIndex; } void SetupGBufferTargets(RenderGraph renderGraph, HDCamera hdCamera, GBufferPassData passData, TextureHandle sssBuffer, ref PrepassOutput prepassOutput, FrameSettings frameSettings, RenderGraphBuilder builder) @@ -439,6 +440,7 @@ void SetupGBufferTargets(RenderGraph renderGraph, HDCamera hdCamera, GBufferPass }), 3); prepassOutput.gbuffer.lightLayersTextureIndex = -1; + prepassOutput.gbuffer.shadowMaskTextureIndex = -1; int currentIndex = 4; if (lightLayers) { @@ -450,7 +452,7 @@ void SetupGBufferTargets(RenderGraph renderGraph, HDCamera hdCamera, GBufferPass { passData.gbufferRT[currentIndex] = builder.UseColorBuffer(renderGraph.CreateTexture( new TextureDesc(Vector2.one, true, true) { colorFormat = Builtin.GetShadowMaskBufferFormat(), clearBuffer = clearGBuffer, clearColor = Color.clear, name = "ShadowMasks" }), currentIndex); - currentIndex++; + prepassOutput.gbuffer.shadowMaskTextureIndex = currentIndex++; } prepassOutput.gbuffer.gBufferCount = currentIndex; From 91d9c799114bb5d9d03851527fd47024d3af66fe Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 11:29:49 +0200 Subject: [PATCH 07/23] Fix wrong merge --- .../RenderGraph/RenderGraphResourceRegistry.cs | 15 +++++++-------- .../Runtime/RenderGraph/RenderGraphResources.cs | 14 +++++--------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index ac5bc7124b0..2de34972e8a 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -112,7 +112,6 @@ internal RendererListResource(in RendererListDesc desc) RenderGraphDebugParams m_RenderGraphDebug; RenderGraphLogger m_Logger; int m_CurrentFrameIndex; - bool m_IsExecutingRenderGraph; RTHandle m_CurrentBackbuffer; @@ -214,7 +213,7 @@ internal TextureHandle ImportTexture(RTHandle rt) texResource.resource = rt; texResource.imported = true; - return new TextureHandle(newHandle, this); + return new TextureHandle(newHandle); } internal TextureHandle ImportBackbuffer(RenderTargetIdentifier rt) @@ -228,7 +227,7 @@ internal TextureHandle ImportBackbuffer(RenderTargetIdentifier rt) texResource.resource = m_CurrentBackbuffer; texResource.imported = true; - return new TextureHandle(newHandle, this); + return new TextureHandle(newHandle); } int AddNewResource(DynamicArray resourceArray, out ResType outRes) where ResType : IRenderGraphResource, new() @@ -251,7 +250,7 @@ internal TextureHandle CreateTexture(in TextureDesc desc, int transientPassIndex int newHandle = AddNewResource(m_Resources[(int)RenderGraphResourceType.Texture], out TextureResource texResource); texResource.desc = desc; texResource.transientPassIndex = transientPassIndex; - return new TextureHandle(newHandle, this); + return new TextureHandle(newHandle); } internal int GetTextureResourceCount() @@ -274,7 +273,7 @@ internal RendererListHandle CreateRendererList(in RendererListDesc desc) ValidateRendererListDesc(desc); int newHandle = m_RendererListResources.Add(new RendererListResource(desc)); - return new RendererListHandle(newHandle, this); + return new RendererListHandle(newHandle); } internal ComputeBufferHandle ImportComputeBuffer(ComputeBuffer computeBuffer) @@ -283,7 +282,7 @@ internal ComputeBufferHandle ImportComputeBuffer(ComputeBuffer computeBuffer) bufferResource.resource = computeBuffer; bufferResource.imported = true; - return new ComputeBufferHandle(newHandle, this); + return new ComputeBufferHandle(newHandle); } internal ComputeBufferHandle CreateComputeBuffer(in ComputeBufferDesc desc, int transientPassIndex = -1) @@ -294,7 +293,7 @@ internal ComputeBufferHandle CreateComputeBuffer(in ComputeBufferDesc desc, int bufferResource.desc = desc; bufferResource.transientPassIndex = transientPassIndex; - return new ComputeBufferHandle(newHandle, this); + return new ComputeBufferHandle(newHandle); } internal ComputeBufferDesc GetComputeBufferResourceDesc(in ResourceHandle handle) @@ -421,7 +420,7 @@ internal void ReleaseTexture(RenderGraphContext rgContext, int index) var clearFlag = resource.desc.depthBufferBits != DepthBits.None ? ClearFlag.Depth : ClearFlag.Color; // Not ideal to do new TextureHandle here but GetTexture is a public API and we rather have it take an explicit TextureHandle parameters. // Everywhere else internally int is better because it allows us to share more code. - CoreUtils.SetRenderTarget(rgContext.cmd, GetTexture(new TextureHandle(index, this)), clearFlag, Color.magenta); + CoreUtils.SetRenderTarget(rgContext.cmd, GetTexture(new TextureHandle(index)), clearFlag, Color.magenta); } } diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs index de15cd4fb7b..6c86aabcb11 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResources.cs @@ -20,18 +20,15 @@ internal struct ResourceHandle public RenderGraphResourceType type { get; private set; } public int iType { get { return (int)type; } } - internal RenderGraphResourceRegistry registry; - - internal ResourceHandle(int value, RenderGraphResourceType type, RenderGraphResourceRegistry registry) + internal ResourceHandle(int value, RenderGraphResourceType type) { index = value; this.type = type; - this.registry = registry; m_IsValid = true; } public static implicit operator int(ResourceHandle handle) => handle.index; - public bool IsValid() => m_IsValid && registry != null; + public bool IsValid() => m_IsValid; } // BEHOLD C# COPY PASTA @@ -54,7 +51,7 @@ public struct TextureHandle internal ResourceHandle handle; - internal TextureHandle(int handle, RenderGraphResourceRegistry registry) { this.handle = new ResourceHandle(handle, RenderGraphResourceType.Texture, registry); } + internal TextureHandle(int handle) { this.handle = new ResourceHandle(handle, RenderGraphResourceType.Texture); } /// /// Cast to RTHandle @@ -87,7 +84,7 @@ public struct ComputeBufferHandle { internal ResourceHandle handle; - internal ComputeBufferHandle(int handle, RenderGraphResourceRegistry registry) { this.handle = new ResourceHandle(handle, RenderGraphResourceType.ComputeBuffer, registry); } + internal ComputeBufferHandle(int handle) { this.handle = new ResourceHandle(handle, RenderGraphResourceType.ComputeBuffer); } /// /// Cast to ComputeBuffer @@ -110,8 +107,7 @@ public struct RendererListHandle { bool m_IsValid; internal int handle { get; private set; } - internal RenderGraphResourceRegistry registry; - internal RendererListHandle(int handle, RenderGraphResourceRegistry registry) { this.handle = handle; m_IsValid = true; this.registry = registry; } + internal RendererListHandle(int handle) { this.handle = handle; m_IsValid = true; } /// /// Conversion to int. /// From d578450128d0d1451d4cf5bed3b60b9076c8bb63 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 12:11:37 +0200 Subject: [PATCH 08/23] Fixed fog with MSAA and render graph --- .../OpaqueAtmosphericScattering.shader | 2 -- .../RenderPipeline/HDRenderPipeline.RenderGraph.cs | 8 ++++---- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 2 +- .../Runtime/Sky/SkyManager.cs | 9 +++++---- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/OpaqueAtmosphericScattering.shader b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/OpaqueAtmosphericScattering.shader index eb004e6f66f..28dd942da11 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/OpaqueAtmosphericScattering.shader +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/AtmosphericScattering/OpaqueAtmosphericScattering.shader @@ -63,7 +63,6 @@ Shader "Hidden/HDRP/OpaqueAtmosphericScattering" float2 positionSS = input.positionCS.xy; float3 V = GetSkyViewDirWS(positionSS); float depth = LoadCameraDepth(positionSS); - float3 surfColor = LOAD_TEXTURE2D_X(_ColorTexture, (int2)positionSS).rgb; float3 volColor, volOpacity; AtmosphericScatteringCompute(input, V, depth, volColor, volOpacity); @@ -77,7 +76,6 @@ Shader "Hidden/HDRP/OpaqueAtmosphericScattering" float2 positionSS = input.positionCS.xy; float3 V = GetSkyViewDirWS(positionSS); float depth = LOAD_TEXTURE2D_X_MSAA(_DepthTextureMS, (int2)positionSS, sampleIndex).x; - float3 surfColor = LOAD_TEXTURE2D_X_MSAA(_ColorTextureMS, (int2)positionSS, sampleIndex).rgb; float3 volColor, volOpacity; AtmosphericScatteringCompute(input, V, depth, volColor, volOpacity); 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 cf40e843fb5..3fca931cd83 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 @@ -168,7 +168,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest, RenderForwardEmissive(m_RenderGraph, hdCamera, colorBuffer, prepassOutput.depthBuffer, cullingResults); - RenderSky(m_RenderGraph, hdCamera, colorBuffer, volumetricLighting, prepassOutput.depthBuffer, prepassOutput.depthPyramidTexture); + RenderSky(m_RenderGraph, hdCamera, colorBuffer, volumetricLighting, prepassOutput.depthBuffer, msaa ? prepassOutput.depthAsColor : prepassOutput.depthPyramidTexture); // Send all the geometry graphics buffer to client systems if required (must be done after the pyramid and before the transparent depth pre-pass) SendGeometryGraphicsBuffers(m_RenderGraph, prepassOutput.normalBuffer, prepassOutput.depthPyramidTexture, hdCamera); @@ -976,6 +976,7 @@ class RenderSkyPassData public HDCamera hdCamera; public TextureHandle volumetricLighting; public TextureHandle colorBuffer; + public TextureHandle depthTexture; public TextureHandle depthStencilBuffer; public TextureHandle intermediateBuffer; public DebugDisplaySettings debugDisplaySettings; @@ -997,14 +998,13 @@ void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBu passData.hdCamera = hdCamera; passData.volumetricLighting = builder.ReadTexture(volumetricLighting); passData.colorBuffer = builder.WriteTexture(colorBuffer); + passData.depthTexture = builder.WriteTexture(depthTexture); passData.depthStencilBuffer = builder.WriteTexture(depthStencilBuffer); passData.intermediateBuffer = builder.CreateTransientTexture(colorBuffer); passData.debugDisplaySettings = m_CurrentDebugDisplaySettings; passData.skyManager = m_SkyManager; passData.frameCount = m_FrameCount; - builder.ReadTexture(depthTexture); - builder.SetRenderFunc( (RenderSkyPassData data, RenderGraphContext context) => { @@ -1016,7 +1016,7 @@ void RenderSky(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBu if (Fog.IsFogEnabled(data.hdCamera) || Fog.IsPBRFogEnabled(data.hdCamera)) { var pixelCoordToViewDirWS = data.hdCamera.mainViewConstants.pixelCoordToViewDirWS; - data.skyManager.RenderOpaqueAtmosphericScattering(context.cmd, data.hdCamera, data.colorBuffer, data.volumetricLighting, data.intermediateBuffer, data.depthStencilBuffer, pixelCoordToViewDirWS, data.hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA)); + data.skyManager.RenderOpaqueAtmosphericScattering(context.cmd, data.hdCamera, data.colorBuffer, data.depthTexture, data.volumetricLighting, data.intermediateBuffer, data.depthStencilBuffer, pixelCoordToViewDirWS, data.hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA)); } }); } 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 ec4d8fc16ac..fc95a564c36 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -4124,7 +4124,7 @@ void RenderSky(HDCamera hdCamera, CommandBuffer cmd) if (Fog.IsFogEnabled(hdCamera) || Fog.IsPBRFogEnabled(hdCamera)) { var pixelCoordToViewDirWS = hdCamera.mainViewConstants.pixelCoordToViewDirWS; - m_SkyManager.RenderOpaqueAtmosphericScattering(cmd, hdCamera, colorBuffer, m_LightingBuffer, intermediateBuffer, depthBuffer, pixelCoordToViewDirWS, hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA)); + m_SkyManager.RenderOpaqueAtmosphericScattering(cmd, hdCamera, colorBuffer, m_SharedRTManager.GetDepthTexture(msaaEnabled), m_LightingBuffer, intermediateBuffer, depthBuffer, pixelCoordToViewDirWS, hdCamera.frameSettings.IsEnabled(FrameSettingsField.MSAA)); } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs index a68ed110d27..fd153c0fb7e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Sky/SkyManager.cs @@ -932,6 +932,7 @@ public void RenderSky(HDCamera hdCamera, Light sunLight, RTHandle colorBuffer, R public void RenderOpaqueAtmosphericScattering(CommandBuffer cmd, HDCamera hdCamera, RTHandle colorBuffer, + RTHandle depthTexture, RTHandle volumetricLighting, RTHandle intermediateBuffer, RTHandle depthBuffer, @@ -940,16 +941,16 @@ public void RenderOpaqueAtmosphericScattering(CommandBuffer cmd, HDCamera hdCame using (new ProfilingScope(m_BuiltinParameters.commandBuffer, ProfilingSampler.Get(HDProfileId.OpaqueAtmosphericScattering))) { m_OpaqueAtmScatteringBlock.SetMatrix(HDShaderIDs._PixelCoordToViewDirWS, pixelCoordToViewDirWS); - if (isMSAA) - m_OpaqueAtmScatteringBlock.SetTexture(HDShaderIDs._ColorTextureMS, colorBuffer); - else - m_OpaqueAtmScatteringBlock.SetTexture(HDShaderIDs._ColorTexture, colorBuffer); + m_OpaqueAtmScatteringBlock.SetTexture(isMSAA ? HDShaderIDs._DepthTextureMS : HDShaderIDs._CameraDepthTexture, depthTexture); + // The texture can be null when volumetrics are disabled. if (volumetricLighting != null) m_OpaqueAtmScatteringBlock.SetTexture(HDShaderIDs._VBufferLighting, volumetricLighting); if (Fog.IsPBRFogEnabled(hdCamera)) { + m_OpaqueAtmScatteringBlock.SetTexture(isMSAA? HDShaderIDs._ColorTextureMS : HDShaderIDs._ColorTexture, colorBuffer); + // Color -> Intermediate. HDUtils.DrawFullScreen(cmd, m_OpaqueAtmScatteringMaterial, intermediateBuffer, depthBuffer, m_OpaqueAtmScatteringBlock, isMSAA ? 3 : 2); // Intermediate -> Color. From 3fe335b36f36895b82a442ad904f9996fcafc729 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 14:54:30 +0200 Subject: [PATCH 09/23] Replace new TextureHandle by TextureHandle.nullHandle --- .../Runtime/RenderGraph/RenderGraphPass.cs | 4 ++-- .../Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs | 2 +- .../Runtime/RenderPipeline/HDRenderPipeline.Debug.cs | 2 +- .../Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs index 3bc1715b7ca..e058f0bcfcc 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs @@ -61,10 +61,10 @@ public void Clear() // Invalidate everything colorBufferMaxIndex = -1; - depthBuffer = new TextureHandle(); + depthBuffer = TextureHandle.nullHandle; for (int i = 0; i < RenderGraph.kMaxMRTCount; ++i) { - colorBuffers[i] = new TextureHandle(); + colorBuffers[i] = TextureHandle.nullHandle; } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs index c22bc4b2499..15f0329b698 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs @@ -108,7 +108,7 @@ TextureHandle AllocateMomentAtlas(RenderGraph renderGraph, string name) internal TextureHandle RenderShadows(RenderGraph renderGraph, CullingResults cullResults, in ShaderVariablesGlobal globalCB, FrameSettings frameSettings, string shadowPassName) { - TextureHandle result = new TextureHandle(); + TextureHandle result = TextureHandle.nullHandle; if (m_ShadowRequests.Count == 0) return result; diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs index efbcddc6137..3f4caee8c25 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.Debug.cs @@ -22,7 +22,7 @@ void RenderTransparencyOverdraw(RenderGraph renderGraph, TextureHandle depthBuff { if (m_CurrentDebugDisplaySettings.IsDebugDisplayEnabled() && m_CurrentDebugDisplaySettings.data.fullScreenDebugMode == FullScreenDebugMode.TransparencyOverdraw) { - TextureHandle transparencyOverdrawOutput = new TextureHandle(); + TextureHandle transparencyOverdrawOutput = TextureHandle.nullHandle; using (var builder = renderGraph.AddRenderPass("Transparency Overdraw", out var passData)) { passData.parameters = PrepareTransparencyOverdrawParameters(hdCamera, cull); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs index a0ea0620acb..1a1aeb16672 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs @@ -570,7 +570,7 @@ TextureHandle VolumeVoxelizationPass( RenderGraph renderGraph, return passData.densityBuffer; } } - return new TextureHandle(); + return TextureHandle.nullHandle; } class VolumetricLightingPassData From 033c6b8e8a4317fe396c53867ee98366c09ef1f2 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 16:44:18 +0200 Subject: [PATCH 10/23] Fixed name of some textures --- .../Runtime/RenderGraph/RenderGraphResourceRegistry.cs | 8 ++++---- .../PostProcessing/PostProcessSystem.RenderGraph.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index 2de34972e8a..3a9158384b0 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -336,22 +336,22 @@ internal void CreateAndClearTexture(RenderGraphContext rgContext, int index) { case TextureSizeMode.Explicit: resource.resource = RTHandles.Alloc(desc.width, desc.height, desc.slices, desc.depthBufferBits, desc.colorFormat, desc.filterMode, desc.wrapMode, desc.dimension, desc.enableRandomWrite, - desc.useMipMap, desc.autoGenerateMips, desc.isShadowMap, desc.anisoLevel, desc.mipMapBias, desc.msaaSamples, desc.bindTextureMS, desc.useDynamicScale, desc.memoryless, desc.name); + desc.useMipMap, desc.autoGenerateMips, desc.isShadowMap, desc.anisoLevel, desc.mipMapBias, desc.msaaSamples, desc.bindTextureMS, desc.useDynamicScale, desc.memoryless, name); break; case TextureSizeMode.Scale: resource.resource = RTHandles.Alloc(desc.scale, desc.slices, desc.depthBufferBits, desc.colorFormat, desc.filterMode, desc.wrapMode, desc.dimension, desc.enableRandomWrite, - desc.useMipMap, desc.autoGenerateMips, desc.isShadowMap, desc.anisoLevel, desc.mipMapBias, desc.enableMSAA, desc.bindTextureMS, desc.useDynamicScale, desc.memoryless, desc.name); + desc.useMipMap, desc.autoGenerateMips, desc.isShadowMap, desc.anisoLevel, desc.mipMapBias, desc.enableMSAA, desc.bindTextureMS, desc.useDynamicScale, desc.memoryless, name); break; case TextureSizeMode.Functor: resource.resource = RTHandles.Alloc(desc.func, desc.slices, desc.depthBufferBits, desc.colorFormat, desc.filterMode, desc.wrapMode, desc.dimension, desc.enableRandomWrite, - desc.useMipMap, desc.autoGenerateMips, desc.isShadowMap, desc.anisoLevel, desc.mipMapBias, desc.enableMSAA, desc.bindTextureMS, desc.useDynamicScale, desc.memoryless, desc.name); + desc.useMipMap, desc.autoGenerateMips, desc.isShadowMap, desc.anisoLevel, desc.mipMapBias, desc.enableMSAA, desc.bindTextureMS, desc.useDynamicScale, desc.memoryless, name); break; } } //// Try to update name when re-using a texture. //// TODO RENDERGRAPH: Check if that actually works. - //resource.rt.name = desc.name; + //resource.rt.name = name; resource.cachedHash = hashCode; diff --git a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs index 799116bf22b..0a8477a7e79 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/PostProcessSystem.RenderGraph.cs @@ -145,12 +145,12 @@ void FillBloomMipsTextureHandles(BloomData bloomData, RenderGraph renderGraph, R var pixelSize = new Vector2Int((int)m_BloomMipsInfo[i].x, (int)m_BloomMipsInfo[i].y); bloomData.mipsDown[i] = builder.CreateTransientTexture(new TextureDesc(scale, true, true) - { colorFormat = m_ColorFormat, enableRandomWrite = true }); + { colorFormat = m_ColorFormat, enableRandomWrite = true, name = "BloomMipDown" }); if (i != 0) { bloomData.mipsUp[i] = builder.CreateTransientTexture(new TextureDesc(scale, true, true) - { colorFormat = m_ColorFormat, enableRandomWrite = true }); + { colorFormat = m_ColorFormat, enableRandomWrite = true, name = "BloomMipUp" }); } } From 9bfaccae7b04cceadc20a36f6578b39645fdad44 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 16:44:52 +0200 Subject: [PATCH 11/23] Implemented stub of ScreenSpaceShadows to fix default texture binding. --- .../Runtime/RenderGraph/RenderGraphDefaultResources.cs | 3 +++ .../Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs | 6 ++++++ .../Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs | 3 +++ .../Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs | 2 +- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs index 05f8ad1c2d8..367fdfcd0dc 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphDefaultResources.cs @@ -23,6 +23,8 @@ public class RenderGraphDefaultResources public TextureHandle magentaTextureXR { get; private set; } /// Default black XR 2D texture. public TextureHandle blackTextureXR { get; private set; } + /// Default black XR 2D Array texture. + public TextureHandle blackTextureArrayXR { get; private set; } /// Default black (UInt) XR 2D texture. public TextureHandle blackUIntTextureXR { get; private set; } /// Default black XR 3D texture. @@ -52,6 +54,7 @@ internal void InitializeForRendering(RenderGraph renderGraph) clearTextureXR = renderGraph.ImportTexture(TextureXR.GetClearTexture()); magentaTextureXR = renderGraph.ImportTexture(TextureXR.GetMagentaTexture()); blackTextureXR = renderGraph.ImportTexture(TextureXR.GetBlackTexture()); + blackTextureArrayXR = renderGraph.ImportTexture(TextureXR.GetBlackTextureArray()); blackUIntTextureXR = renderGraph.ImportTexture(TextureXR.GetBlackUIntTexture()); blackTexture3DXR = renderGraph.ImportTexture(TextureXR.GetBlackTexture3D()); whiteTextureXR = renderGraph.ImportTexture(TextureXR.GetWhiteTexture()); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs index b09053fd75c..03b5316494c 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/ScreenSpaceShadowManager.cs @@ -1,5 +1,6 @@ using System; using UnityEngine.Experimental.Rendering; +using UnityEngine.Experimental.Rendering.RenderGraphModule; namespace UnityEngine.Rendering.HighDefinition { @@ -264,6 +265,11 @@ void RenderScreenSpaceShadows(HDCamera hdCamera, CommandBuffer cmd) } } + TextureHandle RenderScreenSpaceShadows(RenderGraph renderGraph, HDCamera hdCamera) + { + return renderGraph.defaultResources.blackTextureArrayXR; + } + // Generic function that writes in the screen space shadow buffer void WriteToScreenSpaceShadowBuffer(CommandBuffer cmd, HDCamera hdCamera, RTHandle source, int shadowSlot, ScreenSpaceShadowType shadowType) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs index 1a1aeb16672..1987286b21e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.LightLoop.cs @@ -18,6 +18,7 @@ struct LightingBuffers public TextureHandle ambientOcclusionBuffer; public TextureHandle ssrLightingBuffer; public TextureHandle contactShadowsBuffer; + public TextureHandle screenspaceShadowBuffer; } static LightingBuffers ReadLightingBuffers(in LightingBuffers buffers, RenderGraphBuilder builder) @@ -27,6 +28,7 @@ static LightingBuffers ReadLightingBuffers(in LightingBuffers buffers, RenderGra result.ambientOcclusionBuffer = builder.ReadTexture(buffers.ambientOcclusionBuffer); result.ssrLightingBuffer = builder.ReadTexture(buffers.ssrLightingBuffer); result.contactShadowsBuffer = builder.ReadTexture(buffers.contactShadowsBuffer); + result.screenspaceShadowBuffer = builder.ReadTexture(buffers.screenspaceShadowBuffer); return result; } @@ -36,6 +38,7 @@ static void BindGlobalLightingBuffers(in LightingBuffers buffers, CommandBuffer cmd.SetGlobalTexture(HDShaderIDs._AmbientOcclusionTexture, buffers.ambientOcclusionBuffer); cmd.SetGlobalTexture(HDShaderIDs._SsrLightingTexture, buffers.ssrLightingBuffer); cmd.SetGlobalTexture(HDShaderIDs._ContactShadowTexture, buffers.contactShadowsBuffer); + cmd.SetGlobalTexture(HDShaderIDs._ScreenSpaceShadowsTexture, buffers.screenspaceShadowBuffer); } class BuildGPULightListPassData 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 3fca931cd83..7d6d1a61feb 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 @@ -150,7 +150,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest, // TODO RENDERGRAPH - //RenderScreenSpaceShadows(hdCamera, cmd); + lightingBuffers.screenspaceShadowBuffer = RenderScreenSpaceShadows(m_RenderGraph, hdCamera); var volumetricLighting = VolumetricLightingPass(m_RenderGraph, hdCamera, prepassOutput.depthPyramidTexture, volumetricDensityBuffer, gpuLightListOutput.bigTileLightList, shadowResult, m_FrameCount); From 4f00018460acc3178c40ff4d57b46be598ffbabd Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 16:45:09 +0200 Subject: [PATCH 12/23] Correctly deallocate cached shadows atlas --- .../Runtime/Lighting/Shadow/HDShadowManager.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs index 797ae62e431..c18b37971d5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.cs @@ -323,16 +323,24 @@ public void InitializeNonRenderGraphResources() { m_Atlas.AllocateRenderTexture(); m_CascadeAtlas.AllocateRenderTexture(); + cachedShadowManager.punctualShadowAtlas.AllocateRenderTexture(); if (ShaderConfig.s_AreaLights == 1) + { m_AreaLightShadowAtlas.AllocateRenderTexture(); + cachedShadowManager.areaShadowAtlas.AllocateRenderTexture(); + } } public void CleanupNonRenderGraphResources() { m_Atlas.Release(); m_CascadeAtlas.Release(); + cachedShadowManager.punctualShadowAtlas.Release(); if (ShaderConfig.s_AreaLights == 1) + { m_AreaLightShadowAtlas.Release(); + cachedShadowManager.areaShadowAtlas.Release(); + } } // Keep in sync with both HDShadowSampling.hlsl From 4f969edd405e061cef3c862a346e7a8b7b6123ba Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 17:37:46 +0200 Subject: [PATCH 13/23] Properly set color buffer for transparent custom passes. --- .../HDRenderPipeline.Prepass.cs | 2 -- .../HDRenderPipeline.RenderGraph.cs | 22 +++++++++++++++---- 2 files changed, 18 insertions(+), 6 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 402c2be2dbf..759c78ad079 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 @@ -114,8 +114,6 @@ TextureHandle CreateMotionVectorBuffer(RenderGraph renderGraph, bool msaa, bool return renderGraph.CreateTexture(motionVectorDesc); } - // TODO RENDERGRAPH: in someplaces we auto bind and in others we have to generate MRT because of discrepancy with non render graph path. - // Clean this once we only have one path. void BindPrepassColorBuffers(in RenderGraphBuilder builder, in PrepassOutput prepassOutput, HDCamera hdCamera) { int index = 0; 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 7d6d1a61feb..e892e63262f 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 @@ -708,7 +708,7 @@ TextureHandle RenderLowResTransparent(RenderGraph renderGraph, HDCamera hdCamera class UpsampleTransparentPassData { - public Material upsampleMaterial; + public Material upsampleMaterial; public TextureHandle colorBuffer; public TextureHandle lowResTransparentBuffer; public TextureHandle downsampledDepthBuffer; @@ -743,6 +743,20 @@ void UpsampleTransparent(RenderGraph renderGraph, HDCamera hdCamera, TextureHand } } + class SetGlobalColorPassData + { + public TextureHandle colorBuffer; + } + + void SetGlobalColorForCustomPass(RenderGraph renderGraph, TextureHandle colorBuffer) + { + using (var builder = renderGraph.AddRenderPass("SetGlobalColorForCustomPass", out var passData)) + { + passData.colorBuffer = builder.ReadTexture(colorBuffer); + builder.SetRenderFunc( (SetGlobalColorPassData data, RenderGraphContext context) => { context.cmd.SetGlobalTexture(HDShaderIDs._ColorPyramidTexture, data.colorBuffer); }); + } + } + TextureHandle RenderTransparency( RenderGraph renderGraph, HDCamera hdCamera, TextureHandle colorBuffer, @@ -763,9 +777,9 @@ TextureHandle RenderTransparency( RenderGraph renderGraph, //RenderRayTracingPrepass(cullingResults, hdCamera, renderContext, cmd, true); //RaytracingRecursiveRender(hdCamera, cmd, renderContext, cullingResults); - // TODO RENDERGRAPH - //// To allow users to fetch the current color buffer, we temporarily bind the camera color buffer - //cmd.SetGlobalTexture(HDShaderIDs._ColorPyramidTexture, m_CameraColorBuffer); + // TODO RENDERGRAPH: Remove this when we properly convert custom passes to full render graph with explicit color buffer reads. + // To allow users to fetch the current color buffer, we temporarily bind the camera color buffer + SetGlobalColorForCustomPass(renderGraph, currentColorPyramid); RenderCustomPass(m_RenderGraph, hdCamera, colorBuffer, prepassOutput.depthBuffer, prepassOutput.normalBuffer, customPassCullingResults, CustomPassInjectionPoint.BeforePreRefraction, aovRequest, aovBuffers); From a7573ee55c0293bd8cf5d2c04c4c32a4677593d7 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 8 Jul 2020 17:49:17 +0200 Subject: [PATCH 14/23] Small comment update. --- .../Runtime/RenderGraph/RenderGraphResourceRegistry.cs | 5 ++--- .../Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs | 1 + 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index 3a9158384b0..d4fcb94e55e 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -349,8 +349,8 @@ internal void CreateAndClearTexture(RenderGraphContext rgContext, int index) } } - //// Try to update name when re-using a texture. - //// TODO RENDERGRAPH: Check if that actually works. + // Try to update name when re-using a texture. + // TODO RENDERGRAPH: Check if that actually works. //resource.rt.name = name; resource.cachedHash = hashCode; @@ -510,7 +510,6 @@ void ValidateRendererListDesc(in RendererListDesc desc) void ValidateComputeBufferDesc(in ComputeBufferDesc desc) { #if DEVELOPMENT_BUILD || UNITY_EDITOR - // TODO RENDERGRAPH: Check actual condition on stride. if (desc.stride % 4 != 0) { throw new ArgumentException("Invalid Compute Buffer creation descriptor: Compute Buffer stride must be at least 4."); diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs index 15f0329b698..e5e99f2ad54 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs @@ -48,6 +48,7 @@ internal ShadowResult RenderShadows(RenderGraph renderGraph, in ShaderVariablesG // TODO RENDERGRAPH // Not really good to bind things globally here (makes lifecycle of the textures fuzzy) // Probably better to bind it explicitly where needed (deferred lighting and forward/debug passes) + // We can probably remove this when we have only one code path and can clean things up a bit. BindShadowGlobalResources(renderGraph, result); return result; From af137c3df16653467fad38e9ce744cdd340cb3c4 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 10 Jul 2020 09:57:52 +0200 Subject: [PATCH 15/23] Made naming of resources created by RG generic (user names are used for render graph specific debug display) --- .../Runtime/RenderGraph/RenderGraph.cs | 2 - .../RenderGraphResourceRegistry.cs | 40 ++++++++----------- .../HDRenderPipeline.Prepass.cs | 4 +- 3 files changed, 19 insertions(+), 27 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs index 6cd96a853f2..22fb767d704 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs @@ -51,7 +51,6 @@ public struct RenderGraphExecuteParams class RenderGraphDebugParams { - public bool tagResourceNamesWithRG; public bool clearRenderTargetsAtCreation; public bool clearRenderTargetsAtRelease; public bool logFrameInformation; @@ -60,7 +59,6 @@ class RenderGraphDebugParams public void RegisterDebug() { var list = new List(); - list.Add(new DebugUI.BoolField { displayName = "Tag Resources with RG", getter = () => tagResourceNamesWithRG, setter = value => tagResourceNamesWithRG = value }); list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at creation", getter = () => clearRenderTargetsAtCreation, setter = value => clearRenderTargetsAtCreation = value }); list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at release", getter = () => clearRenderTargetsAtRelease, setter = value => clearRenderTargetsAtRelease = value }); list.Add(new DebugUI.Button { displayName = "Log Frame Information", action = () => logFrameInformation = true }); diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index d4fcb94e55e..7bac751d79f 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -25,7 +25,7 @@ internal static RenderGraphResourceRegistry current } set { - m_CurrentRegistry = value; + m_CurrentRegistry = value; } } @@ -326,12 +326,10 @@ internal void CreateAndClearTexture(RenderGraphContext rgContext, int index) resource.resource = null; if (!m_TexturePool.TryGetResource(hashCode, out resource.resource)) { - string name = desc.name; - if (m_RenderGraphDebug.tagResourceNamesWithRG) - name = $"RenderGraph_{name}"; + // Textures are going to be reused under different aliases along the frame so we can't provide a specific name upon creation. + // The name in the desc is going to be used for debugging purpose and render graph visualization. + string name = $"RenderGraphTexture"; - // Note: Name used here will be the one visible in the memory profiler so it means that whatever is the first pass that actually allocate the texture will set the name. - // TODO: Find a way to display name by pass. switch (desc.sizeMode) { case TextureSizeMode.Explicit: @@ -349,10 +347,6 @@ internal void CreateAndClearTexture(RenderGraphContext rgContext, int index) } } - // Try to update name when re-using a texture. - // TODO RENDERGRAPH: Check if that actually works. - //resource.rt.name = name; - resource.cachedHash = hashCode; #if UNITY_2020_2_OR_NEWER @@ -376,7 +370,7 @@ internal void CreateAndClearTexture(RenderGraphContext rgContext, int index) } m_TexturePool.RegisterFrameAllocation(hashCode, resource.resource); - LogTextureCreation(resource.resource, resource.desc.clearBuffer || m_RenderGraphDebug.clearRenderTargetsAtCreation); + LogTextureCreation(resource); } } @@ -395,12 +389,12 @@ internal void CreateComputeBuffer(RenderGraphContext rgContext, int index) if (!m_ComputeBufferPool.TryGetResource(hashCode, out resource.resource)) { resource.resource = new ComputeBuffer(resource.desc.count, resource.desc.stride, resource.desc.type); - resource.resource.name = m_RenderGraphDebug.tagResourceNamesWithRG ? $"RenderGraph_{resource.desc.name}" : resource.desc.name; + resource.resource.name = $"RenderGraphComputeBuffer_{resource.desc.count}_{resource.desc.stride}_{resource.desc.type}"; } resource.cachedHash = hashCode; m_ComputeBufferPool.RegisterFrameAllocation(hashCode, resource.resource); - LogComputeBufferCreation(resource.resource); + LogComputeBufferCreation(resource); } } @@ -424,7 +418,7 @@ internal void ReleaseTexture(RenderGraphContext rgContext, int index) } } - LogTextureRelease(resource.resource); + LogTextureRelease(resource); m_TexturePool.ReleaseResource(resource.cachedHash, resource.resource, m_CurrentFrameIndex); m_TexturePool.UnregisterFrameAllocation(resource.cachedHash, resource.resource); resource.cachedHash = -1; @@ -442,7 +436,7 @@ internal void ReleaseComputeBuffer(RenderGraphContext rgContext, int index) if (resource.resource == null) throw new InvalidOperationException($"Tried to release a compute buffer ({resource.desc.name}) that was never created. Check that there is at least one pass writing to it first."); - LogComputeBufferRelease(resource.resource); + LogComputeBufferRelease(resource); m_ComputeBufferPool.ReleaseResource(resource.cachedHash, resource.resource, m_CurrentFrameIndex); m_ComputeBufferPool.UnregisterFrameAllocation(resource.cachedHash, resource.resource); resource.cachedHash = -1; @@ -561,35 +555,35 @@ internal void Cleanup() m_ComputeBufferPool.Cleanup(); } - void LogTextureCreation(RTHandle rt, bool cleared) + void LogTextureCreation(TextureResource rt) { if (m_RenderGraphDebug.logFrameInformation) { - m_Logger.LogLine($"Created Texture: {rt.rt.name} (Cleared: {cleared})"); + m_Logger.LogLine($"Created Texture: {rt.desc.name} (Cleared: {rt.desc.clearBuffer || m_RenderGraphDebug.clearRenderTargetsAtCreation})"); } } - void LogTextureRelease(RTHandle rt) + void LogTextureRelease(TextureResource rt) { if (m_RenderGraphDebug.logFrameInformation) { - m_Logger.LogLine($"Released Texture: {rt.rt.name}"); + m_Logger.LogLine($"Released Texture: {rt.desc.name}"); } } - void LogComputeBufferCreation(ComputeBuffer buffer) + void LogComputeBufferCreation(ComputeBufferResource buffer) { if (m_RenderGraphDebug.logFrameInformation) { - m_Logger.LogLine($"Created ComputeBuffer: {buffer}"); + m_Logger.LogLine($"Created ComputeBuffer: {buffer.desc.name}"); } } - void LogComputeBufferRelease(ComputeBuffer buffer) + void LogComputeBufferRelease(ComputeBufferResource buffer) { if (m_RenderGraphDebug.logFrameInformation) { - m_Logger.LogLine($"Released ComputeBuffer: {buffer}"); + m_Logger.LogLine($"Released ComputeBuffer: {buffer.desc.name}"); } } 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 759c78ad079..adde65907f0 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 @@ -675,7 +675,7 @@ class RenderDBufferPassData public TextureHandle depthStencilBuffer; public TextureHandle depthTexture; public ComputeBufferHandle propertyMaskBuffer; - public TextureHandle decalBuffer; + public TextureHandle decalBuffer; } struct DBufferOutput @@ -784,7 +784,7 @@ void RenderDBuffer(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle dec data.meshDecalsRendererList, data.propertyMaskBuffer, data.decalBuffer, - context.renderContext, + context.renderContext, context.cmd); }); } From 5f4f65e6272d037f506aa4c459bb90a0af8fa497 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 10 Jul 2020 10:19:13 +0200 Subject: [PATCH 16/23] Fixed custom pass global texture binding. --- .../Runtime/RenderPipeline/HDRenderPipeline.RenderGraph.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 e892e63262f..47425bf26d2 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 @@ -753,7 +753,12 @@ void SetGlobalColorForCustomPass(RenderGraph renderGraph, TextureHandle colorBuf using (var builder = renderGraph.AddRenderPass("SetGlobalColorForCustomPass", out var passData)) { passData.colorBuffer = builder.ReadTexture(colorBuffer); - builder.SetRenderFunc( (SetGlobalColorPassData data, RenderGraphContext context) => { context.cmd.SetGlobalTexture(HDShaderIDs._ColorPyramidTexture, data.colorBuffer); }); + builder.SetRenderFunc( (SetGlobalColorPassData data, RenderGraphContext context) => + { + RTHandle colorPyramid = data.colorBuffer; + if (colorPyramid != null) + context.cmd.SetGlobalTexture(HDShaderIDs._ColorPyramidTexture, data.colorBuffer); + }); } } From ffb8f495afdafe1326e4ee6a23399997ad92d9f4 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 10 Jul 2020 10:57:42 +0200 Subject: [PATCH 17/23] Added name to real time reflection probe textures. --- .../Runtime/Lighting/Reflection/HDProbe.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs index 18024aed0ee..56a4ddbcbe0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Reflection/HDProbe.cs @@ -192,6 +192,7 @@ public RenderTexture realtimeTexture if (m_RealtimeTexture != null) m_RealtimeTexture.Release(); m_RealtimeTexture = RTHandles.Alloc(value); + m_RealtimeTexture.rt.name = $"ProbeRealTimeTexture_{name}"; } } @@ -209,6 +210,7 @@ public RenderTexture realtimeDepthTexture if (m_RealtimeDepthBuffer != null) m_RealtimeDepthBuffer.Release(); m_RealtimeDepthBuffer = RTHandles.Alloc(value); + m_RealtimeDepthBuffer.rt.name = $"ProbeRealTimeDepthTexture_{name}"; } } From 34a5d3bce6dd56ad87c4171df216034c1100bedc Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 10 Jul 2020 11:31:24 +0200 Subject: [PATCH 18/23] Added an option to disable pass pruning and simplified logging code. --- .../Runtime/RenderGraph/RenderGraph.cs | 76 ++++++++++++------- .../RenderGraph/RenderGraphResourcePool.cs | 2 +- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs index 22fb767d704..0eccc06b2f4 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs @@ -53,6 +53,7 @@ class RenderGraphDebugParams { public bool clearRenderTargetsAtCreation; public bool clearRenderTargetsAtRelease; + public bool disablePassPruning; public bool logFrameInformation; public bool logResources; @@ -61,8 +62,25 @@ public void RegisterDebug() var list = new List(); list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at creation", getter = () => clearRenderTargetsAtCreation, setter = value => clearRenderTargetsAtCreation = value }); list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at release", getter = () => clearRenderTargetsAtRelease, setter = value => clearRenderTargetsAtRelease = value }); - list.Add(new DebugUI.Button { displayName = "Log Frame Information", action = () => logFrameInformation = true }); - list.Add(new DebugUI.Button { displayName = "Log Resources", action = () => logResources = true }); + list.Add(new DebugUI.BoolField { displayName = "Disable Pass Pruning", getter = () => disablePassPruning, setter = value => disablePassPruning = value }); + list.Add(new DebugUI.Button { displayName = "Log Frame Information", + action = () => + { + logFrameInformation = true; + #if UNITY_EDITOR + UnityEditor.SceneView.RepaintAll(); + #endif + } + }); + list.Add(new DebugUI.Button { displayName = "Log Resources", + action = () => + { + logResources = true; + #if UNITY_EDITOR + UnityEditor.SceneView.RepaintAll(); + #endif + } + }); var panel = DebugManager.instance.GetPanel("Render Graph", true); panel.children.Add(list.ToArray()); @@ -538,6 +556,12 @@ void PruneOutputlessPasses() void PruneUnusedPasses() { + if (m_DebugParameters.disablePassPruning) + { + LogLine("- Pass pruning disabled -\n"); + return; + } + // TODO RENDERGRAPH: temporarily remove pruning of passes without product. // Many passes are used just to set global variables so we don't want to force users to disallow pruning on those explicitly every time. // This will prune passes with no outputs. @@ -948,55 +972,51 @@ void ClearRenderPasses() m_RenderPasses.Clear(); } - void LogFrameInformation(int renderingWidth, int renderingHeight) + void LogLine(string format, params object[] args) { if (m_DebugParameters.logFrameInformation) { - m_Logger.LogLine("==== Staring frame at resolution ({0}x{1}) ====", renderingWidth, renderingHeight); - m_Logger.LogLine("Number of passes declared: {0}\n", m_RenderPasses.Count); + m_Logger.LogLine(format, args); } } + void LogFrameInformation(int renderingWidth, int renderingHeight) + { + LogLine("==== Staring frame at resolution ({0}x{1}) ====", renderingWidth, renderingHeight); + LogLine("Number of passes declared: {0}\n", m_RenderPasses.Count); + } + void LogRendererListsCreation() { - if (m_DebugParameters.logFrameInformation) - { - m_Logger.LogLine("Number of renderer lists created: {0}\n", m_RendererLists.Count); - } + LogLine("Number of renderer lists created: {0}\n", m_RendererLists.Count); } void LogRenderPassBegin(in CompiledPassInfo passInfo) { - if (m_DebugParameters.logFrameInformation) - { - RenderGraphPass pass = passInfo.pass; + RenderGraphPass pass = passInfo.pass; - m_Logger.LogLine("[{0}][{1}] \"{2}\"", pass.index, pass.enableAsyncCompute ? "Compute" : "Graphics", pass.name); - using (new RenderGraphLogIndent(m_Logger)) - { - if (passInfo.syncToPassIndex != -1) - m_Logger.LogLine("Synchronize with [{0}]", passInfo.syncToPassIndex); - } + LogLine("[{0}][{1}] \"{2}\"", pass.index, pass.enableAsyncCompute ? "Compute" : "Graphics", pass.name); + using (new RenderGraphLogIndent(m_Logger)) + { + if (passInfo.syncToPassIndex != -1) + LogLine("Synchronize with [{0}]", passInfo.syncToPassIndex); } } void LogPrunedPasses() { - if (m_DebugParameters.logFrameInformation) + LogLine("Pass pruning report:"); + using (new RenderGraphLogIndent(m_Logger)) { - m_Logger.LogLine("Pass pruning report:"); - using (new RenderGraphLogIndent(m_Logger)) + for (int i = 0; i < m_CompiledPassInfos.size; ++i) { - for (int i = 0; i < m_CompiledPassInfos.size; ++i) + if (m_CompiledPassInfos[i].pruned) { - if (m_CompiledPassInfos[i].pruned) - { - var pass = m_RenderPasses[i]; - m_Logger.LogLine("[{0}] {1}", pass.index, pass.name); - } + var pass = m_RenderPasses[i]; + LogLine("[{0}] {1}", pass.index, pass.name); } - m_Logger.LogLine("\n"); } + LogLine("\n"); } } diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourcePool.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourcePool.cs index 29f1a46c9e7..5bfaa45c17e 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourcePool.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourcePool.cs @@ -6,7 +6,7 @@ namespace UnityEngine.Experimental.Rendering.RenderGraphModule abstract class RenderGraphResourcePool where Type : class { - // Dictionary tracks resources by hash and stores resources with same hash in a List (list instead of a stack because we need to be able to remove stale allocations). + // Dictionary tracks resources by hash and stores resources with same hash in a List (list instead of a stack because we need to be able to remove stale allocations, potentially in the middle of the stack). protected Dictionary> m_ResourcePool = new Dictionary>(); #if DEVELOPMENT_BUILD || UNITY_EDITOR From e79d159514c57fbc7c7f173460dcfda33b12bc82 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 10 Jul 2020 11:51:27 +0200 Subject: [PATCH 19/23] Added XR copy depth --- .../HDRenderPipeline.RenderGraph.cs | 57 +++++++++++++------ 1 file changed, 39 insertions(+), 18 deletions(-) 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 47425bf26d2..07a4b50f3a3 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 @@ -234,24 +234,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest, RenderCustomPass(m_RenderGraph, hdCamera, postProcessDest, prepassOutput.depthBuffer, prepassOutput.normalBuffer, customPassCullingResults, CustomPassInjectionPoint.AfterPostProcess, aovRequest, aovBuffers); - // TODO RENDERGRAPH - //// Copy and rescale depth buffer for XR devices - //if (hdCamera.xr.enabled && hdCamera.xr.copyDepth) - //{ - // using (new ProfilingScope(cmd, ProfilingSampler.Get(HDProfileId.XRDepthCopy))) - // { - // var depthBuffer = m_SharedRTManager.GetDepthStencilBuffer(); - // var rtScale = depthBuffer.rtHandleProperties.rtHandleScale / DynamicResolutionHandler.instance.GetCurrentScale(); - - // m_CopyDepthPropertyBlock.SetTexture(HDShaderIDs._InputDepth, depthBuffer); - // m_CopyDepthPropertyBlock.SetVector(HDShaderIDs._BlitScaleBias, rtScale); - // m_CopyDepthPropertyBlock.SetInt("_FlipY", 1); - - // cmd.SetRenderTarget(target.id, 0, CubemapFace.Unknown, -1); - // cmd.SetViewport(hdCamera.finalViewport); - // CoreUtils.DrawFullScreen(cmd, m_CopyDepth, m_CopyDepthPropertyBlock); - // } - //} + CopyXRDepth(m_RenderGraph, hdCamera, prepassOutput.depthBuffer, backBuffer); // In developer build, we always render post process in m_AfterPostProcessBuffer at (0,0) in which we will then render debug. // Because of this, we need another blit here to the final render target at the right viewport. @@ -391,6 +374,44 @@ void SetFinalTarget(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle de } } + class CopyXRDepthPassData + { + public Material copyDepth; + public Rect viewport; + public TextureHandle depthBuffer; + public TextureHandle output; + } + + void CopyXRDepth(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle depthBuffer, TextureHandle output) + { + // Copy and rescale depth buffer for XR devices + if (hdCamera.xr.enabled && hdCamera.xr.copyDepth) + { + using (var builder = renderGraph.AddRenderPass("Copy XR Depth", out var passData, ProfilingSampler.Get(HDProfileId.XRDepthCopy))) + { + passData.copyDepth = m_CopyDepth; + passData.viewport = hdCamera.finalViewport; + passData.depthBuffer = builder.ReadTexture(depthBuffer); + passData.output = builder.WriteTexture(output); + + builder.SetRenderFunc( + (CopyXRDepthPassData data, RenderGraphContext ctx) => + { + var mpb = ctx.renderGraphPool.GetTempMaterialPropertyBlock(); + RTHandle depthRT = data.depthBuffer; + + mpb.SetTexture(HDShaderIDs._InputDepth, data.depthBuffer); + mpb.SetVector(HDShaderIDs._BlitScaleBias, depthRT.rtHandleProperties.rtHandleScale / DynamicResolutionHandler.instance.GetCurrentScale()); + mpb.SetInt("_FlipY", 1); + + ctx.cmd.SetRenderTarget(data.output, 0, CubemapFace.Unknown, -1); + ctx.cmd.SetViewport(data.viewport); + CoreUtils.DrawFullScreen(ctx.cmd, data.copyDepth, mpb); + }); + } + } + } + class ForwardPassData { public RendererListHandle rendererList; From 973de2528ff2858e7e999b6980e0e40fbd7e9a6d Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Fri, 10 Jul 2020 17:23:51 +0200 Subject: [PATCH 20/23] Rename "pass pruning" to "pass culling" --- .../Runtime/RenderGraph/RenderGraph.cs | 86 +++++++++---------- .../Runtime/RenderGraph/RenderGraphBuilder.cs | 12 +-- .../Runtime/RenderGraph/RenderGraphPass.cs | 8 +- .../Shadow/HDShadowManager.RenderGraph.cs | 2 +- .../HDRenderPipeline.RenderGraph.cs | 14 +-- 5 files changed, 61 insertions(+), 61 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs index 0eccc06b2f4..cfa5f5972fe 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs @@ -53,7 +53,7 @@ class RenderGraphDebugParams { public bool clearRenderTargetsAtCreation; public bool clearRenderTargetsAtRelease; - public bool disablePassPruning; + public bool disablePassCulling; public bool logFrameInformation; public bool logResources; @@ -62,7 +62,7 @@ public void RegisterDebug() var list = new List(); list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at creation", getter = () => clearRenderTargetsAtCreation, setter = value => clearRenderTargetsAtCreation = value }); list.Add(new DebugUI.BoolField { displayName = "Clear Render Targets at release", getter = () => clearRenderTargetsAtRelease, setter = value => clearRenderTargetsAtRelease = value }); - list.Add(new DebugUI.BoolField { displayName = "Disable Pass Pruning", getter = () => disablePassPruning, setter = value => disablePassPruning = value }); + list.Add(new DebugUI.BoolField { displayName = "Disable Pass Culling", getter = () => disablePassCulling, setter = value => disablePassCulling = value }); list.Add(new DebugUI.Button { displayName = "Log Frame Information", action = () => { @@ -136,7 +136,7 @@ internal struct CompiledPassInfo public List[] resourceCreateList; public List[] resourceReleaseList; public int refCount; - public bool pruned; + public bool culled; public bool hasSideEffect; public int syncToPassIndex; // Index of the pass that needs to be waited for. public int syncFromPassIndex; // Smaller pass index that waits for this pass. @@ -144,7 +144,7 @@ internal struct CompiledPassInfo public GraphicsFence fence; public bool enableAsyncCompute { get { return pass.enableAsyncCompute; } } - public bool allowPassPruning { get { return pass.allowPassPruning; } } + public bool allowPassCulling { get { return pass.allowPassCulling; } } #if DEVELOPMENT_BUILD || UNITY_EDITOR // This members are only here to ease debugging. @@ -184,7 +184,7 @@ public void Reset(RenderGraphPass pass) } refCount = 0; - pruned = false; + culled = false; hasSideEffect = false; syncToPassIndex = -1; syncFromPassIndex = -1; @@ -214,7 +214,7 @@ public void Reset(RenderGraphPass pass) // Compiled Render Graph info. DynamicArray[] m_CompiledResourcesInfos = new DynamicArray[(int)RenderGraphResourceType.Count]; DynamicArray m_CompiledPassInfos = new DynamicArray(); - Stack m_PruningStack = new Stack(); + Stack m_CullingStack = new Stack(); #region Public Interface @@ -278,7 +278,7 @@ public void PurgeUnusedResources() /// /// Import an external texture to the Render Graph. - /// Any pass writing to an imported texture will be considered having side effects and can't be automatically pruned. + /// Any pass writing to an imported texture will be considered having side effects and can't be automatically culled. /// /// External RTHandle that needs to be imported. /// A new TextureHandle. @@ -339,7 +339,7 @@ public RendererListHandle CreateRendererList(in RendererListDesc desc) /// /// Import an external Compute Buffer to the Render Graph - /// Any pass writing to an imported compute buffer will be considered having side effects and can't be automatically pruned. + /// Any pass writing to an imported compute buffer will be considered having side effects and can't be automatically culled. /// /// External Compute Buffer that needs to be imported. /// A new ComputeBufferHandle. @@ -527,21 +527,21 @@ void CountReferences() } } - void PruneOutputlessPasses() + void CullOutputlessPasses() { - // Gather passes that don't produce anything and prune them. - m_PruningStack.Clear(); + // Gather passes that don't produce anything and cull them. + m_CullingStack.Clear(); for (int pass = 0; pass < m_CompiledPassInfos.size; ++pass) { ref CompiledPassInfo passInfo = ref m_CompiledPassInfos[pass]; - if (passInfo.refCount == 0 && !passInfo.hasSideEffect && passInfo.allowPassPruning) + if (passInfo.refCount == 0 && !passInfo.hasSideEffect && passInfo.allowPassCulling) { // Producer is not necessary as it produces zero resources - // Prune it and decrement refCount of all the resources it reads. + // Cull it and decrement refCount of all the resources it reads. // We don't need to go recursively here because we decrement ref count of read resources - // so the subsequent passes of pruning will detect those and remove the related passes. - passInfo.pruned = true; + // so the subsequent passes of culling will detect those and remove the related passes. + passInfo.culled = true; for (int type = 0; type < (int)RenderGraphResourceType.Count; ++type) { foreach (var index in passInfo.pass.resourceReadLists[type]) @@ -554,46 +554,46 @@ void PruneOutputlessPasses() } } - void PruneUnusedPasses() + void CullUnusedPasses() { - if (m_DebugParameters.disablePassPruning) + if (m_DebugParameters.disablePassCulling) { - LogLine("- Pass pruning disabled -\n"); + LogLine("- Pass Culling Disabled -\n"); return; } - // TODO RENDERGRAPH: temporarily remove pruning of passes without product. - // Many passes are used just to set global variables so we don't want to force users to disallow pruning on those explicitly every time. - // This will prune passes with no outputs. - //PruneOutputlessPasses(); + // TODO RENDERGRAPH: temporarily remove culling of passes without product. + // Many passes are used just to set global variables so we don't want to force users to disallow culling on those explicitly every time. + // This will cull passes with no outputs. + //CullOutputlessPasses(); - // This will prune all passes that produce resource that are never read. + // This will cull all passes that produce resource that are never read. for (int type = 0; type < (int)RenderGraphResourceType.Count; ++type) { DynamicArray resourceUsageList = m_CompiledResourcesInfos[type]; // Gather resources that are never read. - m_PruningStack.Clear(); + m_CullingStack.Clear(); for (int i = 0; i < resourceUsageList.size; ++i) { if (resourceUsageList[i].refCount == 0) { - m_PruningStack.Push(i); + m_CullingStack.Push(i); } } - while (m_PruningStack.Count != 0) + while (m_CullingStack.Count != 0) { - var unusedResource = resourceUsageList[m_PruningStack.Pop()]; + var unusedResource = resourceUsageList[m_CullingStack.Pop()]; foreach (var producerIndex in unusedResource.producers) { ref var producerInfo = ref m_CompiledPassInfos[producerIndex]; producerInfo.refCount--; - if (producerInfo.refCount == 0 && !producerInfo.hasSideEffect && producerInfo.allowPassPruning) + if (producerInfo.refCount == 0 && !producerInfo.hasSideEffect && producerInfo.allowPassCulling) { // Producer is not necessary anymore as it produces zero resources - // Prune it and decrement refCount of all the textures it reads. - producerInfo.pruned = true; + // Cull it and decrement refCount of all the textures it reads. + producerInfo.culled = true; foreach (var resourceIndex in producerInfo.pass.resourceReadLists[type]) { @@ -601,14 +601,14 @@ void PruneUnusedPasses() resourceInfo.refCount--; // If a resource is not used anymore, add it to the stack to be processed in subsequent iteration. if (resourceInfo.refCount == 0) - m_PruningStack.Push(resourceIndex); + m_CullingStack.Push(resourceIndex); } } } } } - LogPrunedPasses(); + LogCulledPasses(); } void UpdatePassSynchronization(ref CompiledPassInfo currentPassInfo, ref CompiledPassInfo producerPassInfo, int currentPassIndex, int lastProducer, ref int intLastSyncIndex) @@ -679,7 +679,7 @@ int GetLatestValidReadIndex(in CompiledResourceInfo info) var consumers = info.consumers; for (int i = consumers.Count - 1; i >= 0; --i) { - if (!m_CompiledPassInfos[consumers[i]].pruned) + if (!m_CompiledPassInfos[consumers[i]].culled) return consumers[i]; } @@ -694,7 +694,7 @@ int GetFirstValidWriteIndex(in CompiledResourceInfo info) var producers = info.producers; for (int i = 0; i < producers.Count; i++) { - if (!m_CompiledPassInfos[producers[i]].pruned) + if (!m_CompiledPassInfos[producers[i]].culled) return producers[i]; } @@ -709,7 +709,7 @@ int GetLatestValidWriteIndex(in CompiledResourceInfo info) var producers = info.producers; for (int i = producers.Count - 1; i >= 0; --i) { - if (!m_CompiledPassInfos[producers[i]].pruned) + if (!m_CompiledPassInfos[producers[i]].culled) return producers[i]; } @@ -730,7 +730,7 @@ void UpdateResourceAllocationAndSynchronization() { ref CompiledPassInfo passInfo = ref m_CompiledPassInfos[passIndex]; - if (passInfo.pruned) + if (passInfo.culled) continue; for (int type = 0; type < (int)RenderGraphResourceType.Count; ++type) @@ -811,16 +811,16 @@ void UpdateResourceAllocationAndSynchronization() m_Resources.CreateRendererLists(m_RendererLists); } - // Internal for testing purpose only + // Internal visibility for testing purpose only // Traverse the render graph: // - Determines when resources are created/released // - Determines async compute pass synchronization - // - Prune unused render passes. + // - Cull unused render passes. internal void CompileRenderGraph() { InitializeCompilationData(); CountReferences(); - PruneUnusedPasses(); + CullUnusedPasses(); UpdateResourceAllocationAndSynchronization(); LogRendererListsCreation(); } @@ -836,7 +836,7 @@ void ExecuteRenderGraph(ScriptableRenderContext renderContext, CommandBuffer cmd for (int passIndex = 0; passIndex < m_CompiledPassInfos.size; ++passIndex) { ref var passInfo = ref m_CompiledPassInfos[passIndex]; - if (passInfo.pruned) + if (passInfo.culled) continue; if (!passInfo.pass.HasRenderFunc()) @@ -1003,14 +1003,14 @@ void LogRenderPassBegin(in CompiledPassInfo passInfo) } } - void LogPrunedPasses() + void LogCulledPasses() { - LogLine("Pass pruning report:"); + LogLine("Pass Culling Report:"); using (new RenderGraphLogIndent(m_Logger)) { for (int i = 0; i < m_CompiledPassInfos.size; ++i) { - if (m_CompiledPassInfos[i].pruned) + if (m_CompiledPassInfos[i].culled) { var pass = m_RenderPasses[i]; LogLine("[{0}] {1}", pass.index, pass.name); diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilder.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilder.cs index 0633c1a92cd..ef8318ac8c1 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilder.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphBuilder.cs @@ -175,15 +175,15 @@ public void EnableAsyncCompute(bool value) } /// - /// Allow or not pass pruning - /// By default all passes can be pruned out if the render graph detects it's not actually used. + /// Allow or not pass culling + /// By default all passes can be culled out if the render graph detects it's not actually used. /// In some cases, a pass may not write or read any texture but rather do something with side effects (like setting a global texture parameter for example). - /// This function can be used to tell the system that it should not prune this pass. + /// This function can be used to tell the system that it should not cull this pass. /// - /// - public void AllowPassPruning(bool value) + /// True to allow pass culling. + public void AllowPassCulling(bool value) { - m_RenderPass.AllowPassPruning(value); + m_RenderPass.AllowPassCulling(value); } /// diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs index e058f0bcfcc..f9ce8cc88ae 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphPass.cs @@ -19,7 +19,7 @@ public RenderFunc GetExecuteDelegate() public int index { get; protected set; } public ProfilingSampler customSampler { get; protected set; } public bool enableAsyncCompute { get; protected set; } - public bool allowPassPruning { get; protected set; } + public bool allowPassCulling { get; protected set; } public TextureHandle depthBuffer { get; protected set; } public TextureHandle[] colorBuffers { get; protected set; } = new TextureHandle[RenderGraph.kMaxMRTCount]; @@ -56,7 +56,7 @@ public void Clear() usedRendererListList.Clear(); enableAsyncCompute = false; - allowPassPruning = true; + allowPassCulling = true; refCount = 0; // Invalidate everything @@ -93,9 +93,9 @@ public void EnableAsyncCompute(bool value) enableAsyncCompute = value; } - public void AllowPassPruning(bool value) + public void AllowPassCulling(bool value) { - allowPassPruning = value; + allowPassCulling = value; } public void SetColorBuffer(TextureHandle resource, int index) diff --git a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs index e5e99f2ad54..79625322a12 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/Lighting/Shadow/HDShadowManager.RenderGraph.cs @@ -73,7 +73,7 @@ void BindShadowGlobalResources(RenderGraph renderGraph, in ShadowResult shadowRe using (var builder = renderGraph.AddRenderPass("BindShadowGlobalResources", out var passData)) { passData.shadowResult = ReadShadowResult(shadowResult, builder); - builder.AllowPassPruning(false); + builder.AllowPassCulling(false); builder.SetRenderFunc( (BindShadowGlobalResourcesPassData data, RenderGraphContext ctx) => { 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 07a4b50f3a3..81f54e91a81 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 @@ -140,7 +140,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest, // Temporary workaround otherwise the texture is not bound when executing directly with rendergraph using (var builder = m_RenderGraph.AddRenderPass("TempPass", out var passData)) { - builder.AllowPassPruning(false); + builder.AllowPassCulling(false); builder.SetRenderFunc( (TempPassData data, RenderGraphContext context) => { @@ -158,7 +158,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest, RenderForwardOpaque(m_RenderGraph, hdCamera, colorBuffer, lightingBuffers, gpuLightListOutput, prepassOutput.depthBuffer, shadowResult, prepassOutput.dbuffer, cullingResults); - // TODO RENDERGRAPH : Move this to the end after we do move semantic and graph pruning to avoid doing the rest of the frame for nothing + // TODO RENDERGRAPH : Move this to the end after we do move semantic and graph culling to avoid doing the rest of the frame for nothing aovRequest.PushCameraTexture(m_RenderGraph, AOVBuffers.Normals, hdCamera, prepassOutput.resolvedNormalBuffer, aovBuffers); lightingBuffers.diffuseLightingBuffer = ResolveMSAAColor(m_RenderGraph, hdCamera, lightingBuffers.diffuseLightingBuffer); @@ -190,7 +190,7 @@ void ExecuteWithRenderGraph( RenderRequest renderRequest, if (m_Asset.currentPlatformRenderPipelineSettings.supportMotionVectors) PushFullScreenDebugTexture(m_RenderGraph, prepassOutput.motionVectorsBuffer, FullScreenDebugMode.MotionVectors); - // TODO RENDERGRAPH : Move this to the end after we do move semantic and graph pruning to avoid doing the rest of the frame for nothing + // TODO RENDERGRAPH : Move this to the end after we do move semantic and graph culling to avoid doing the rest of the frame for nothing // Transparent objects may write to the depth and motion vectors buffers. aovRequest.PushCameraTexture(m_RenderGraph, AOVBuffers.DepthStencil, hdCamera, prepassOutput.resolvedDepthBuffer, aovBuffers); if (m_Asset.currentPlatformRenderPipelineSettings.supportMotionVectors) @@ -912,7 +912,7 @@ void SendGeometryGraphicsBuffers(RenderGraph renderGraph, TextureHandle normalBu using (var builder = renderGraph.AddRenderPass("Send Geometry Buffers", out var passData)) { - builder.AllowPassPruning(false); + builder.AllowPassCulling(false); passData.parameters = parameters; passData.normalBuffer = builder.ReadTexture(normalBuffer); @@ -935,7 +935,7 @@ void SendColorGraphicsBuffer(RenderGraph renderGraph, HDCamera hdCamera) { using (var builder = renderGraph.AddRenderPass("Send Color Buffers", out var passData)) { - builder.AllowPassPruning(false); + builder.AllowPassCulling(false); passData.hdCamera = hdCamera; @@ -1072,9 +1072,9 @@ class GenerateColorPyramidData void GenerateColorPyramid(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle inputColor, TextureHandle output, bool isPreRefraction) { - // Here we cannot rely on automatic pass pruning if the result is not read + // Here we cannot rely on automatic pass culling if the result is not read // because the output texture is imported from outside of render graph (as it is persistent) - // and in this case the pass is considered as having side effect and cannot be pruned. + // and in this case the pass is considered as having side effect and cannot be culled. if (isPreRefraction) { if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.Refraction)) From 6706275cc97722d9988c1c9793e8edaf556919cf Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 15 Jul 2020 09:48:13 +0200 Subject: [PATCH 21/23] Fixed tests compilation --- .../Tests/Editor/RenderGraphTests.cs | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/com.unity.render-pipelines.core/Tests/Editor/RenderGraphTests.cs b/com.unity.render-pipelines.core/Tests/Editor/RenderGraphTests.cs index ab01a3f3542..764d43156ca 100644 --- a/com.unity.render-pipelines.core/Tests/Editor/RenderGraphTests.cs +++ b/com.unity.render-pipelines.core/Tests/Editor/RenderGraphTests.cs @@ -20,9 +20,9 @@ class RenderGraphTestPassData public ComputeBufferHandle[] buffers = new ComputeBufferHandle[8]; } - // Final output (back buffer) of render graph needs to be explicitly imported in order to know that the chain of dependency should not be pruned. + // Final output (back buffer) of render graph needs to be explicitly imported in order to know that the chain of dependency should not be culled. [Test] - public void WriteToBackBufferNotPruned() + public void WriteToBackBufferNotCulled() { using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) { @@ -34,12 +34,12 @@ public void WriteToBackBufferNotPruned() var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); Assert.AreEqual(1, compiledPasses.size); - Assert.AreEqual(false, compiledPasses[0].pruned); + Assert.AreEqual(false, compiledPasses[0].culled); } - // If no back buffer is ever written to, everything should be pruned. + // If no back buffer is ever written to, everything should be culled. [Test] - public void NoWriteToBackBufferPruned() + public void NoWriteToBackBufferCulled() { using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) { @@ -51,12 +51,12 @@ public void NoWriteToBackBufferPruned() var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); Assert.AreEqual(1, compiledPasses.size); - Assert.AreEqual(true, compiledPasses[0].pruned); + Assert.AreEqual(true, compiledPasses[0].culled); } - // Writing to imported resource is considered as a side effect so passes should not be pruned. + // Writing to imported resource is considered as a side effect so passes should not be culled. [Test] - public void WriteToImportedTextureNotPruned() + public void WriteToImportedTextureNotCulled() { using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) { @@ -68,11 +68,11 @@ public void WriteToImportedTextureNotPruned() var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); Assert.AreEqual(1, compiledPasses.size); - Assert.AreEqual(false, compiledPasses[0].pruned); + Assert.AreEqual(false, compiledPasses[0].culled); } [Test] - public void WriteToImportedComputeBufferNotPruned() + public void WriteToImportedComputeBufferNotCulled() { using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) { @@ -84,15 +84,15 @@ public void WriteToImportedComputeBufferNotPruned() var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); Assert.AreEqual(1, compiledPasses.size); - Assert.AreEqual(false, compiledPasses[0].pruned); + Assert.AreEqual(false, compiledPasses[0].culled); } - // TODO RENDERGRAPH : Temporarily removed. See RenderGraph.cs pass pruning - //// A pass not writing to anything is useless and should be pruned. + // TODO RENDERGRAPH : Temporarily removed. See RenderGraph.cs pass culling + //// A pass not writing to anything is useless and should be culled. //[Test] - //public void PrunePassWithNoProduct() + //public void CullPassWithNoProduct() //{ - // // This pass reads an input but does not produce anything (no writes) so it should be pruned. + // // This pass reads an input but does not produce anything (no writes) so it should be culled. // TextureHandle texture = m_RenderGraph.CreateTexture(new TextureDesc(Vector2.one) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm }); // using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) // { @@ -104,15 +104,15 @@ public void WriteToImportedComputeBufferNotPruned() // var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); // Assert.AreEqual(1, compiledPasses.size); - // Assert.AreEqual(true, compiledPasses[0].pruned); + // Assert.AreEqual(true, compiledPasses[0].culled); //} - //// A series of passes with no final product should be pruned. + //// A series of passes with no final product should be culled. //[Test] - //public void PrunePassWithTextureDependenciesAndNoProduct() + //public void CullPassWithTextureDependenciesAndNoProduct() //{ // // First pass produces an output that is read by second pass. - // // Second pass does not produce anything so it should be pruned as well as all its unused dependencies. + // // Second pass does not produce anything so it should be culled as well as all its unused dependencies. // TextureHandle texture; // using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) // { @@ -130,18 +130,18 @@ public void WriteToImportedComputeBufferNotPruned() // var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); // Assert.AreEqual(2, compiledPasses.size); - // Assert.AreEqual(true, compiledPasses[0].pruned); - // Assert.AreEqual(true, compiledPasses[1].pruned); + // Assert.AreEqual(true, compiledPasses[0].culled); + // Assert.AreEqual(true, compiledPasses[1].culled); //} - //// A series of passes with no final product should be pruned. - //// Here first pass is not pruned because Compute Buffer is imported. + //// A series of passes with no final product should be culled. + //// Here first pass is not culled because Compute Buffer is imported. //// TODO: Add test where compute buffer is created instead of imported once the API exists. //[Test] - //public void PrunePassWithBufferDependenciesAndNoProduct() + //public void CullPassWithBufferDependenciesAndNoProduct() //{ // // First pass produces an output that is read by second pass. - // // Second pass does not produce anything so it should be pruned as well as all its unused dependencies. + // // Second pass does not produce anything so it should be culled as well as all its unused dependencies. // ComputeBufferHandle computeBuffer; // using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) // { @@ -159,14 +159,14 @@ public void WriteToImportedComputeBufferNotPruned() // var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); // Assert.AreEqual(2, compiledPasses.size); - // Assert.AreEqual(false, compiledPasses[0].pruned); // Not pruned because writing to an imported resource is a side effect. - // Assert.AreEqual(true, compiledPasses[1].pruned); + // Assert.AreEqual(false, compiledPasses[0].culled); // Not culled because writing to an imported resource is a side effect. + // Assert.AreEqual(true, compiledPasses[1].culled); //} [Test] - public void PassWriteResourcePartialNotReadAfterNotPruned() + public void PassWriteResourcePartialNotReadAfterNotCulled() { - // If a pass writes to a resource that is not unused globally by the graph but not read ever AFTER the pass then the pass should be pruned unless it writes to another used resource. + // If a pass writes to a resource that is not unused globally by the graph but not read ever AFTER the pass then the pass should be culled unless it writes to another used resource. TextureHandle texture0; using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) { @@ -182,9 +182,9 @@ public void PassWriteResourcePartialNotReadAfterNotPruned() builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } - // This pass writes to texture0 which is used so will not be pruned out. - // Since texture0 is never read after this pass, we should decrement refCount for this pass and potentially prune it. - // However, it also writes to texture1 which is used in the last pass so we musn't prune it. + // This pass writes to texture0 which is used so will not be culled out. + // Since texture0 is never read after this pass, we should decrement refCount for this pass and potentially cull it. + // However, it also writes to texture1 which is used in the last pass so we mustn't cull it. using (var builder = m_RenderGraph.AddRenderPass("TestPass2", out var passData)) { builder.WriteTexture(texture0); @@ -195,7 +195,7 @@ public void PassWriteResourcePartialNotReadAfterNotPruned() using (var builder = m_RenderGraph.AddRenderPass("TestPass3", out var passData)) { builder.ReadTexture(texture1); - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -203,19 +203,19 @@ public void PassWriteResourcePartialNotReadAfterNotPruned() var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); Assert.AreEqual(4, compiledPasses.size); - Assert.AreEqual(false, compiledPasses[0].pruned); - Assert.AreEqual(false, compiledPasses[1].pruned); - Assert.AreEqual(false, compiledPasses[2].pruned); - Assert.AreEqual(false, compiledPasses[3].pruned); + Assert.AreEqual(false, compiledPasses[0].culled); + Assert.AreEqual(false, compiledPasses[1].culled); + Assert.AreEqual(false, compiledPasses[2].culled); + Assert.AreEqual(false, compiledPasses[3].culled); } [Test] - public void PassDisallowPruningNotPruned() + public void PassDisallowCullingNotCulled() { - // This pass does nothing so should be pruned but we explicitly disallow it. + // This pass does nothing so should be culled but we explicitly disallow it. using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) { - builder.AllowPassPruning(false); + builder.AllowPassCulling(false); builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -223,12 +223,12 @@ public void PassDisallowPruningNotPruned() var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); Assert.AreEqual(1, compiledPasses.size); - Assert.AreEqual(false, compiledPasses[0].pruned); + Assert.AreEqual(false, compiledPasses[0].culled); } - // First pass produces two textures and second pass only read one of the two. Pass one should not be pruned. + // First pass produces two textures and second pass only read one of the two. Pass one should not be culled. [Test] - public void PartialUnusedProductNotPruned() + public void PartialUnusedProductNotCulled() { TextureHandle texture; using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) @@ -249,8 +249,8 @@ public void PartialUnusedProductNotPruned() var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); Assert.AreEqual(2, compiledPasses.size); - Assert.AreEqual(false, compiledPasses[0].pruned); - Assert.AreEqual(false, compiledPasses[1].pruned); + Assert.AreEqual(false, compiledPasses[0].culled); + Assert.AreEqual(false, compiledPasses[1].culled); } // Simple cycle of create/release of a texture across multiple passes. @@ -276,7 +276,7 @@ public void SimpleCreateReleaseTexture() using (var builder = m_RenderGraph.AddRenderPass("TestPass2", out var passData)) { builder.ReadTexture(texture); - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -303,7 +303,7 @@ public void UseTransientOutsidePassRaiseException() using (var builder = m_RenderGraph.AddRenderPass("TestPass1", out var passData)) { builder.ReadTexture(texture); // This is illegal (transient resource was created in previous pass) - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -318,7 +318,7 @@ public void TransientCreateReleaseInSamePass() using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) { texture = builder.CreateTransientTexture(new TextureDesc(Vector2.one) { colorFormat = GraphicsFormat.R8G8B8A8_UNorm }); - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -387,7 +387,7 @@ public void AsyncPassReleaseTextureOnGraphicsPipe() { builder.ReadTexture(texture1); builder.ReadTexture(texture3); - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.EnableAsyncCompute(false); builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -401,7 +401,7 @@ public void AsyncPassReleaseTextureOnGraphicsPipe() } [Test] - public void TransientResourceNotPruned() + public void TransientResourceNotCulled() { TextureHandle texture0; using (var builder = m_RenderGraph.AddRenderPass("TestPass0", out var passData)) @@ -421,7 +421,7 @@ public void TransientResourceNotPruned() using (var builder = m_RenderGraph.AddRenderPass("TestPass5", out var passData)) { builder.ReadTexture(texture0); - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.EnableAsyncCompute(false); builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -430,7 +430,7 @@ public void TransientResourceNotPruned() var compiledPasses = m_RenderGraph.GetCompiledPassInfos(); Assert.AreEqual(3, compiledPasses.size); - Assert.AreEqual(false, compiledPasses[1].pruned); + Assert.AreEqual(false, compiledPasses[1].culled); } [Test] @@ -453,7 +453,7 @@ public void AsyncPassWriteWaitOnGraphcisPipe() using (var builder = m_RenderGraph.AddRenderPass("TestPass2", out var passData)) { builder.ReadTexture(texture0); - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -487,7 +487,7 @@ public void AsyncPassReadWaitOnGraphcisPipe() using (var builder = m_RenderGraph.AddRenderPass("TestPass2", out var passData)) { builder.ReadTexture(texture1); - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -513,7 +513,7 @@ public void GraphicsPassWriteWaitOnAsyncPipe() using (var builder = m_RenderGraph.AddRenderPass("TestPass1", out var passData)) { builder.WriteTexture(texture0); - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } @@ -539,7 +539,7 @@ public void GraphicsPassReadWaitOnAsyncPipe() using (var builder = m_RenderGraph.AddRenderPass("TestPass1", out var passData)) { builder.ReadTexture(texture0); - builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be pruned + builder.WriteTexture(m_RenderGraph.ImportBackbuffer(0)); // Needed for the passes to not be culled builder.SetRenderFunc((RenderGraphTestPassData data, RenderGraphContext context) => { }); } From 953a33f6e481ffc19f677ce1a4bfbd64dcd0c597 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 15 Jul 2020 10:46:20 +0200 Subject: [PATCH 22/23] Revert logger changes because they made unavoidable allocs. --- .../Runtime/RenderGraph/RenderGraph.cs | 53 +++++++++++-------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs index cfa5f5972fe..0e28247f265 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraph.cs @@ -558,7 +558,10 @@ void CullUnusedPasses() { if (m_DebugParameters.disablePassCulling) { - LogLine("- Pass Culling Disabled -\n"); + if (m_DebugParameters.logFrameInformation) + { + m_Logger.LogLine("- Pass Culling Disabled -\n"); + } return; } @@ -972,51 +975,55 @@ void ClearRenderPasses() m_RenderPasses.Clear(); } - void LogLine(string format, params object[] args) + void LogFrameInformation(int renderingWidth, int renderingHeight) { if (m_DebugParameters.logFrameInformation) { - m_Logger.LogLine(format, args); + m_Logger.LogLine("==== Staring frame at resolution ({0}x{1}) ====", renderingWidth, renderingHeight); + m_Logger.LogLine("Number of passes declared: {0}\n", m_RenderPasses.Count); } } - void LogFrameInformation(int renderingWidth, int renderingHeight) - { - LogLine("==== Staring frame at resolution ({0}x{1}) ====", renderingWidth, renderingHeight); - LogLine("Number of passes declared: {0}\n", m_RenderPasses.Count); - } - void LogRendererListsCreation() { - LogLine("Number of renderer lists created: {0}\n", m_RendererLists.Count); + if (m_DebugParameters.logFrameInformation) + { + m_Logger.LogLine("Number of renderer lists created: {0}\n", m_RendererLists.Count); + } } void LogRenderPassBegin(in CompiledPassInfo passInfo) { - RenderGraphPass pass = passInfo.pass; - - LogLine("[{0}][{1}] \"{2}\"", pass.index, pass.enableAsyncCompute ? "Compute" : "Graphics", pass.name); - using (new RenderGraphLogIndent(m_Logger)) + if (m_DebugParameters.logFrameInformation) { - if (passInfo.syncToPassIndex != -1) - LogLine("Synchronize with [{0}]", passInfo.syncToPassIndex); + RenderGraphPass pass = passInfo.pass; + + m_Logger.LogLine("[{0}][{1}] \"{2}\"", pass.index, pass.enableAsyncCompute ? "Compute" : "Graphics", pass.name); + using (new RenderGraphLogIndent(m_Logger)) + { + if (passInfo.syncToPassIndex != -1) + m_Logger.LogLine("Synchronize with [{0}]", passInfo.syncToPassIndex); + } } } void LogCulledPasses() { - LogLine("Pass Culling Report:"); - using (new RenderGraphLogIndent(m_Logger)) + if (m_DebugParameters.logFrameInformation) { - for (int i = 0; i < m_CompiledPassInfos.size; ++i) + m_Logger.LogLine("Pass Culling Report:"); + using (new RenderGraphLogIndent(m_Logger)) { - if (m_CompiledPassInfos[i].culled) + for (int i = 0; i < m_CompiledPassInfos.size; ++i) { - var pass = m_RenderPasses[i]; - LogLine("[{0}] {1}", pass.index, pass.name); + if (m_CompiledPassInfos[i].culled) + { + var pass = m_RenderPasses[i]; + m_Logger.LogLine("[{0}] {1}", pass.index, pass.name); + } } + m_Logger.LogLine("\n"); } - LogLine("\n"); } } From 235fab6613d7ec07d339ebb564ebf583ec364bb8 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Wed, 15 Jul 2020 10:52:11 +0200 Subject: [PATCH 23/23] Removed useless formatting. --- .../Runtime/RenderGraph/RenderGraphResourceRegistry.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index 7bac751d79f..bf28006cb86 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -328,7 +328,7 @@ internal void CreateAndClearTexture(RenderGraphContext rgContext, int index) { // Textures are going to be reused under different aliases along the frame so we can't provide a specific name upon creation. // The name in the desc is going to be used for debugging purpose and render graph visualization. - string name = $"RenderGraphTexture"; + string name = "RenderGraphTexture"; switch (desc.sizeMode) {