From c421c343bf1987749097f8d26976e646df812bef Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Mon, 29 Jun 2020 15:05:14 +0200 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 d12323f9579ccb837e33f4046cd5784f2222ea65 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Tue, 7 Jul 2020 10:52:30 +0200 Subject: [PATCH 4/5] Post merge fixes --- .../PostProcessSystem.RenderGraph.cs | 80 +++++++++---------- .../HDRenderPipeline.Prepass.cs | 4 +- 2 files changed, 42 insertions(+), 42 deletions(-) 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 ecac37d999b..799116bf22b 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 @@ -213,7 +213,7 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (GuardBandPassData data, RenderGraphContext ctx) => { - ClearWithGuardBands(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source)); + ClearWithGuardBands(data.parameters, ctx.cmd, data.source); }); source = passData.source; @@ -238,7 +238,7 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (StopNaNPassData data, RenderGraphContext ctx) => { - DoStopNaNs(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), ctx.resources.GetTexture(data.destination)); + DoStopNaNs(data.parameters, ctx.cmd, data.source, data.destination); }); source = passData.destination; @@ -271,10 +271,10 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (DynamicExposureData data, RenderGraphContext ctx) => { - DoHistogramBasedExposure(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), - ctx.resources.GetTexture(data.prevExposure), - ctx.resources.GetTexture(data.nextExposure), - ctx.resources.GetTexture(data.exposureDebugData)); + DoHistogramBasedExposure(data.parameters, ctx.cmd, data.source, + data.prevExposure, + data.nextExposure, + data.exposureDebugData); }); } else @@ -287,11 +287,11 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (DynamicExposureData data, RenderGraphContext ctx) => { - DoDynamicExposure(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), - ctx.resources.GetTexture(data.prevExposure), - ctx.resources.GetTexture(data.nextExposure), - ctx.resources.GetTexture(data.tmpTarget1024), - ctx.resources.GetTexture(data.tmpTarget32)); + DoDynamicExposure(data.parameters, ctx.cmd, data.source, + data.prevExposure, + data.nextExposure, + data.tmpTarget1024, + data.tmpTarget32); }); } } @@ -312,7 +312,7 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (ApplyExposureData data, RenderGraphContext ctx) => { - ApplyExposure(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), ctx.resources.GetTexture(data.destination), ctx.resources.GetTexture(data.prevExposure)); + ApplyExposure(data.parameters, ctx.cmd, data.source, data.destination, data.prevExposure); }); source = passData.destination; @@ -364,15 +364,15 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (TemporalAntiAliasingData data, RenderGraphContext ctx) => { - DoTemporalAntialiasing(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), - ctx.resources.GetTexture(data.destination), - ctx.resources.GetTexture(data.motionVecTexture), - ctx.resources.GetTexture(data.depthBuffer), - ctx.resources.GetTexture(data.depthMipChain), - ctx.resources.GetTexture(data.prevHistory), - ctx.resources.GetTexture(data.nextHistory), - ctx.resources.GetTexture(data.prevMVLen), - ctx.resources.GetTexture(data.nextMVLen)); + DoTemporalAntialiasing(data.parameters, ctx.cmd, data.source, + data.destination, + data.motionVecTexture, + data.depthBuffer, + data.depthMipChain, + data.prevHistory, + data.nextHistory, + data.prevMVLen, + data.nextMVLen); }); source = passData.destination; @@ -397,11 +397,11 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (SMAAData data, RenderGraphContext ctx) => { - DoSMAA(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), - ctx.resources.GetTexture(data.smaaEdgeTex), - ctx.resources.GetTexture(data.smaaBlendTex), - ctx.resources.GetTexture(data.destination), - ctx.resources.GetTexture(data.depthBuffer)); + DoSMAA(data.parameters, ctx.cmd, data.source, + data.smaaEdgeTex, + data.smaaBlendTex, + data.destination, + data.depthBuffer); }); source = passData.destination; @@ -477,14 +477,14 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (MotionBlurData data, RenderGraphContext ctx) => { - DoMotionBlur(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), - ctx.resources.GetTexture(data.destination), - ctx.resources.GetTexture(data.motionVecTexture), - ctx.resources.GetTexture(data.preppedMotionVec), - ctx.resources.GetTexture(data.minMaxTileVel), - ctx.resources.GetTexture(data.maxTileNeigbourhood), - ctx.resources.GetTexture(data.tileToScatterMax), - ctx.resources.GetTexture(data.tileToScatterMin)); + DoMotionBlur(data.parameters, ctx.cmd, data.source, + data.destination, + data.motionVecTexture, + data.preppedMotionVec, + data.minMaxTileVel, + data.maxTileNeigbourhood, + data.tileToScatterMax, + data.tileToScatterMin); }); source = passData.destination; @@ -508,7 +508,7 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (PaniniProjectionData data, RenderGraphContext ctx) => { - DoPaniniProjection(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), ctx.resources.GetTexture(data.destination)); + DoPaniniProjection(data.parameters, ctx.cmd, data.source, data.destination); }); source = passData.destination; @@ -536,11 +536,11 @@ public void Render(RenderGraph renderGraph, for(int i=0; i { - DoFXAA(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), ctx.resources.GetTexture(data.destination)); + DoFXAA(data.parameters, ctx.cmd, data.source, data.destination); }); source = passData.destination; @@ -651,7 +651,7 @@ public void Render(RenderGraph renderGraph, builder.SetRenderFunc( (CASData data, RenderGraphContext ctx) => { - DoContrastAdaptiveSharpening(data.parameters, ctx.cmd, ctx.resources.GetTexture(data.source), ctx.resources.GetTexture(data.destination)); + DoContrastAdaptiveSharpening(data.parameters, ctx.cmd, data.source, data.destination); }); source = passData.destination; 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 713a4236cc9..fc1ad9cb52c 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 @@ -313,7 +313,7 @@ bool RenderDepthPrepass(RenderGraph renderGraph, CullingResults cull, HDCamera h if (data.hasDepthDeferredPass && data.decalLayersEnabled) { deferredMrt = context.renderGraphPool.GetTempArray(1); - deferredMrt[0] = context.resources.GetTexture(data.decalBuffer); + deferredMrt[0] = data.decalBuffer; } var forwardMrt = context.renderGraphPool.GetTempArray((data.msaaEnabled ? 2 : 1) + (data.decalLayersEnabled ? 1 : 0)); @@ -780,7 +780,7 @@ void RenderDBuffer(RenderGraph renderGraph, HDCamera hdCamera, TextureHandle dec data.depthStencilBuffer, data.meshDecalsRendererList, data.propertyMaskBuffer, - resources.GetTexture(data.decalBuffer), + data.decalBuffer, context.renderContext, context.cmd); }); From aa542e7b27dfb782a9591730de45f33c17b20a06 Mon Sep 17 00:00:00 2001 From: Julien Ignace Date: Tue, 7 Jul 2020 12:55:20 +0200 Subject: [PATCH 5/5] Fixed error handling of casting handles to resources. --- .../RenderGraphResourceRegistry.cs | 54 ++++++++++--------- .../RenderGraph/RenderGraphResources.cs | 24 ++++----- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs index 8a9657631f9..8847f3825d3 100644 --- a/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs +++ b/com.unity.render-pipelines.core/Runtime/RenderGraph/RenderGraphResourceRegistry.cs @@ -9,6 +9,26 @@ class RenderGraphResourceRegistry { static readonly ShaderTagId s_EmptyName = new ShaderTagId(""); + static RenderGraphResourceRegistry m_CurrentRegistry; + internal static RenderGraphResourceRegistry current + { + get + { + // 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_CurrentRegistry == null) + { + throw new InvalidOperationException("Current Render Graph Resource Registry is not set. You are probably trying to cast a Render Graph handle to a resource outside of a Render Graph Pass."); + } +#endif + return m_CurrentRegistry; + } + set + { + m_CurrentRegistry = value; + } + } + class IRenderGraphResource { public bool imported; @@ -94,14 +114,11 @@ 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; @@ -110,8 +127,6 @@ internal RTHandle GetTexture(in TextureHandle handle) internal RendererList GetRendererList(in RendererListHandle handle) { - CheckRenderGraphExecution(); - if (!handle.IsValid() || handle >= m_RendererListResources.size) return RendererList.nullRendererList; @@ -120,8 +135,6 @@ internal RendererList GetRendererList(in RendererListHandle handle) internal ComputeBuffer GetComputeBuffer(in ComputeBufferHandle handle) { - CheckRenderGraphExecution(); - if (!handle.IsValid()) return null; @@ -162,21 +175,12 @@ ResType GetResource(DynamicArray resour internal void BeginRender(int currentFrameIndex) { m_CurrentFrameIndex = currentFrameIndex; - m_IsExecutingRenderGraph = true; + current = this; } 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 + current = null; } void CheckHandleValidity(in ResourceHandle res) @@ -212,7 +216,7 @@ internal TextureHandle ImportTexture(RTHandle rt, int shaderProperty = 0) texResource.imported = true; texResource.shaderProperty = shaderProperty; - return new TextureHandle(newHandle, this); + return new TextureHandle(newHandle); } internal TextureHandle ImportBackbuffer(RenderTargetIdentifier rt) @@ -226,7 +230,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() @@ -250,7 +254,7 @@ internal TextureHandle CreateTexture(in TextureDesc desc, int shaderProperty = 0 texResource.desc = desc; texResource.shaderProperty = shaderProperty; texResource.transientPassIndex = transientPassIndex; - return new TextureHandle(newHandle, this); + return new TextureHandle(newHandle); } internal int GetTextureResourceCount() @@ -273,7 +277,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) @@ -282,7 +286,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) @@ -293,7 +297,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) @@ -446,7 +450,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 140a65a7f84..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,23 +51,23 @@ 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 /// /// Input TextureHandle. - public static implicit operator RTHandle(TextureHandle texture) => texture.IsValid() ? texture.handle.registry.GetTexture(texture) : null; + public static implicit operator RTHandle(TextureHandle texture) => texture.IsValid() ? RenderGraphResourceRegistry.current.GetTexture(texture) : null; /// /// Cast to RenderTargetIdentifier /// /// Input TextureHandle. - public static implicit operator RenderTargetIdentifier(TextureHandle texture) => texture.IsValid() ? texture.handle.registry.GetTexture(texture) : null; + public static implicit operator RenderTargetIdentifier(TextureHandle texture) => texture.IsValid() ? RenderGraphResourceRegistry.current.GetTexture(texture) : null; /// /// Cast to RenderTexture /// /// Input TextureHandle. - public static implicit operator RenderTexture(TextureHandle texture) => texture.IsValid() ? texture.handle.registry.GetTexture(texture) : null; + public static implicit operator RenderTexture(TextureHandle texture) => texture.IsValid() ? RenderGraphResourceRegistry.current.GetTexture(texture) : null; /// /// Return true if the handle is valid. @@ -87,13 +84,13 @@ 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 /// /// Input ComputeBufferHandle - public static implicit operator ComputeBuffer(ComputeBufferHandle buffer) => buffer.IsValid() ? buffer.handle.registry.GetComputeBuffer(buffer) : null; + public static implicit operator ComputeBuffer(ComputeBufferHandle buffer) => buffer.IsValid() ? RenderGraphResourceRegistry.current.GetComputeBuffer(buffer) : null; /// /// Return true if the handle is valid. @@ -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. /// @@ -119,7 +115,7 @@ 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; + public static implicit operator RendererList(RendererListHandle rendererList) => rendererList.IsValid() ? RenderGraphResourceRegistry.current.GetRendererList(rendererList) : RendererList.nullRendererList; /// /// Return true if the handle is valid.