From a3525fd90d40bfce17e35e958db97a27973f79c6 Mon Sep 17 00:00:00 2001 From: "pavlos.mavridis" Date: Tue, 10 Mar 2020 14:24:34 +0100 Subject: [PATCH 01/10] Very basic AOV support for custom pass --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 4 ++++ .../Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 8c08d67f32a..21653f2b5da 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2452,6 +2452,10 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePostProcess); aovRequest.PushCameraTexture(cmd, AOVBuffers.Color, hdCamera, m_CameraColorBuffer, aovBuffers); + if (m_CustomPassColorBuffer.IsValueCreated) + { + aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPass, hdCamera, m_CustomPassColorBuffer.Value, aovBuffers); + } RenderTargetIdentifier postProcessDest = HDUtils.PostProcessIsFinalPass(hdCamera) ? target.id : m_IntermediateAfterPostProcessBuffer; RenderPostProcess(cullingResults, hdCamera, postProcessDest, renderContext, cmd); diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs index 85182c54125..d95cdac07f0 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs @@ -12,6 +12,8 @@ public enum AOVBuffers /// Normals buffer at the end of the frame. Normals, /// Motion vectors buffer at the end of the frame. - MotionVectors + MotionVectors, + /// Custom pass buffer. + CustomPass //TODO: all injection points } } From a69e4662e938f319b7441ff2ecbedd3331c9ee35 Mon Sep 17 00:00:00 2001 From: "pavlos.mavridis" Date: Wed, 11 Mar 2020 12:27:35 +0100 Subject: [PATCH 02/10] Updated AOV API for custom passes --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 18 ++++++++++++++---- .../RenderPass/AOV/AOVBuffers.cs | 14 ++++++++++++-- .../RenderPass/AOV/AOVRequestData.cs | 14 ++++++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 21653f2b5da..ef35b19c680 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2144,6 +2144,9 @@ void Callback(CommandBuffer c, HDCamera cam) if (depthBufferModified) m_IsDepthBufferCopyValid = false; + // Push the custom pass buffer, in case it was requested in the AOVs + aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferAfterOpaqueDepthAndNormal, hdCamera, m_CustomPassColorBuffer, aovBuffers); + // In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing. GenerateDepthPyramid(hdCamera, cmd, FullScreenDebugMode.DepthPyramid); @@ -2371,6 +2374,9 @@ void Callback(CommandBuffer c, HDCamera cam) cmd.SetGlobalTexture(HDShaderIDs._ColorPyramidTexture, m_CameraColorBuffer); RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePreRefraction); + // Push the custom pass buffer, in case it was requested in the AOVs + aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferBeforePreRefraction, hdCamera, m_CustomPassColorBuffer, aovBuffers); + // Render pre refraction objects RenderForwardTransparent(cullingResults, hdCamera, true, renderContext, cmd); @@ -2392,6 +2398,9 @@ void Callback(CommandBuffer c, HDCamera cam) // We don't have access to the color pyramid with transparent if rough refraction is disabled RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforeTransparent); + // Push the custom pass texture, if it was requested in the AOVs + aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferBeforePostProcess, hdCamera, m_CustomPassColorBuffer, aovBuffers); + // Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects. RenderForwardTransparent(cullingResults, hdCamera, false, renderContext, cmd); @@ -2451,17 +2460,18 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePostProcess); + // Push the camera and custom pass textures, in case they were requested in the AOVs aovRequest.PushCameraTexture(cmd, AOVBuffers.Color, hdCamera, m_CameraColorBuffer, aovBuffers); - if (m_CustomPassColorBuffer.IsValueCreated) - { - aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPass, hdCamera, m_CustomPassColorBuffer.Value, aovBuffers); - } + aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferBeforePostProcess, hdCamera, m_CustomPassColorBuffer, aovBuffers); RenderTargetIdentifier postProcessDest = HDUtils.PostProcessIsFinalPass(hdCamera) ? target.id : m_IntermediateAfterPostProcessBuffer; RenderPostProcess(cullingResults, hdCamera, postProcessDest, renderContext, cmd); RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.AfterPostProcess); + // Push the custom pass texture, in case it was requested in the AOVs + aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferAfterPostProcess, hdCamera, m_CustomPassColorBuffer, aovBuffers); + // Copy and rescale depth buffer for XR devices if (hdCamera.xr.enabled && hdCamera.xr.copyDepth) { diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs index d95cdac07f0..03e5c245ac5 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs @@ -13,7 +13,17 @@ public enum AOVBuffers Normals, /// Motion vectors buffer at the end of the frame. MotionVectors, - /// Custom pass buffer. - CustomPass //TODO: all injection points + /// Custom pass buffer after the custom pass at "BeforeRendering" injection point is executed. + CustomPassBufferBeforeRendering, + /// Custom pass buffer after the custom pass at "AfterOpaqueDepthAndNormal" injection point is executed. + CustomPassBufferAfterOpaqueDepthAndNormal, + /// Custom pass buffer after the custom pass at "BeforePreRefraction" injection point is executed. + CustomPassBufferBeforePreRefraction, + /// Custom pass buffer after the custom pass at "BeforeTransparent" injection point is executed. + CustomPassBufferBeforeTransparent, + /// Custom pass buffer after the custom pass at "BeforePostProcess" injection point is executed. + CustomPassBufferBeforePostProcess, + /// Custom pass buffer after the custom pass at "AfterPostProcess" injection point is executed. + CustomPassBufferAfterPostProcess } } 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 3598d05c20b..b57dcaee6f6 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 @@ -111,6 +111,20 @@ List targets HDUtils.BlitCameraTexture(cmd, source, targets[index]); } + internal void PushCameraTexture( + CommandBuffer cmd, + AOVBuffers aovBufferId, + HDCamera camera, + Lazy source, + List targets + ) + { + if (!source.IsValueCreated) + return; + + PushCameraTexture(cmd, aovBufferId, camera, source.Value, targets); + } + class PushCameraTexturePassData { public int requestIndex; From 51b4fdc7a8b760c90c1d63f54f71e7f7328e552e Mon Sep 17 00:00:00 2001 From: "pavlos.mavridis" Date: Wed, 11 Mar 2020 14:28:12 +0100 Subject: [PATCH 03/10] Changelog --- com.unity.render-pipelines.high-definition/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.render-pipelines.high-definition/CHANGELOG.md b/com.unity.render-pipelines.high-definition/CHANGELOG.md index 55481e24e24..8e32bc76223 100644 --- a/com.unity.render-pipelines.high-definition/CHANGELOG.md +++ b/com.unity.render-pipelines.high-definition/CHANGELOG.md @@ -97,6 +97,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added support for alpha to coverage for HDRP shaders and shader graph - Added support for Quality Levels to Subsurface Scattering. - Added option to disable XR rendering on the camera settings. +- Added support for custom passes in the AOV API ### Fixed - Fix when rescale probe all direction below zero (1219246) From 007e4707ccf80adcab703f3abccb129df26ec5b0 Mon Sep 17 00:00:00 2001 From: "pavlos.mavridis" Date: Thu, 12 Mar 2020 16:30:25 +0100 Subject: [PATCH 04/10] Update AOV API --- .../RenderPipeline/HDRenderPipeline.cs | 10 +-- .../RenderPass/AOV/AOVBuffers.cs | 33 ++++--- .../RenderPass/AOV/AOVRequestBuilder.cs | 22 +++++ .../RenderPass/AOV/AOVRequestData.cs | 86 ++++++++++++++++--- 4 files changed, 120 insertions(+), 31 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index ef35b19c680..87244a7c65d 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2145,7 +2145,7 @@ void Callback(CommandBuffer c, HDCamera cam) m_IsDepthBufferCopyValid = false; // Push the custom pass buffer, in case it was requested in the AOVs - aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferAfterOpaqueDepthAndNormal, hdCamera, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); // In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing. GenerateDepthPyramid(hdCamera, cmd, FullScreenDebugMode.DepthPyramid); @@ -2375,7 +2375,7 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePreRefraction); // Push the custom pass buffer, in case it was requested in the AOVs - aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferBeforePreRefraction, hdCamera, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforePreRefraction, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); // Render pre refraction objects RenderForwardTransparent(cullingResults, hdCamera, true, renderContext, cmd); @@ -2399,7 +2399,7 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforeTransparent); // Push the custom pass texture, if it was requested in the AOVs - aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferBeforePostProcess, hdCamera, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforeTransparent, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); // Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects. RenderForwardTransparent(cullingResults, hdCamera, false, renderContext, cmd); @@ -2462,7 +2462,7 @@ void Callback(CommandBuffer c, HDCamera cam) // Push the camera and custom pass textures, in case they were requested in the AOVs aovRequest.PushCameraTexture(cmd, AOVBuffers.Color, hdCamera, m_CameraColorBuffer, aovBuffers); - aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferBeforePostProcess, hdCamera, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforePostProcess, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); RenderTargetIdentifier postProcessDest = HDUtils.PostProcessIsFinalPass(hdCamera) ? target.id : m_IntermediateAfterPostProcessBuffer; RenderPostProcess(cullingResults, hdCamera, postProcessDest, renderContext, cmd); @@ -2470,7 +2470,7 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.AfterPostProcess); // Push the custom pass texture, in case it was requested in the AOVs - aovRequest.PushCameraTexture(cmd, AOVBuffers.CustomPassBufferAfterPostProcess, hdCamera, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.AfterPostProcess, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); // Copy and rescale depth buffer for XR devices if (hdCamera.xr.enabled && hdCamera.xr.copyDepth) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs index 03e5c245ac5..5b8b704543f 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs @@ -12,18 +12,25 @@ public enum AOVBuffers /// Normals buffer at the end of the frame. Normals, /// Motion vectors buffer at the end of the frame. - MotionVectors, - /// Custom pass buffer after the custom pass at "BeforeRendering" injection point is executed. - CustomPassBufferBeforeRendering, - /// Custom pass buffer after the custom pass at "AfterOpaqueDepthAndNormal" injection point is executed. - CustomPassBufferAfterOpaqueDepthAndNormal, - /// Custom pass buffer after the custom pass at "BeforePreRefraction" injection point is executed. - CustomPassBufferBeforePreRefraction, - /// Custom pass buffer after the custom pass at "BeforeTransparent" injection point is executed. - CustomPassBufferBeforeTransparent, - /// Custom pass buffer after the custom pass at "BeforePostProcess" injection point is executed. - CustomPassBufferBeforePostProcess, - /// Custom pass buffer after the custom pass at "AfterPostProcess" injection point is executed. - CustomPassBufferAfterPostProcess + MotionVectors + } + + + public struct CustomPassAOVBuffers + { + public enum OutputType + { + CustomPassBuffer, + Camera + } + + public CustomPassInjectionPoint injectionPoint; + public OutputType outputType; + + public CustomPassAOVBuffers(CustomPassInjectionPoint ip, OutputType ot) + { + injectionPoint = ip; + outputType = ot; + } } } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs index 251ebd0d33c..9bbe07ae67b 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs @@ -29,6 +29,28 @@ FramePassCallback callback return this; } + /// Add a AOV request. + /// Settings to use for this frame pass. + /// An allocator for each buffer. + /// If non null, only these lights will be rendered, if none, all lights will be rendered. + /// A list of buffers to use. + /// A callback that can use the requested buffers once the rendering has completed. + /// + public AOVRequestBuilder Add( + AOVRequest settings, + AOVRequestBufferAllocator bufferAllocator, + AOVRequestCustomPassBufferAllocator customPassbufferAllocator, + List includedLightList, + AOVBuffers[] aovBuffers, + CustomPassAOVBuffers[] customPassAovBuffers, + FramePassCallback callback + ) + { + (m_AOVRequestDataData ?? (m_AOVRequestDataData = ListPool.Get())).Add( + new AOVRequestData(settings, bufferAllocator, customPassbufferAllocator, includedLightList, aovBuffers, customPassAovBuffers, callback)); + return this; + } + /// Build the frame passes. Allocated resources will be transferred to the returned value. /// The built collection. public AOVRequestDataCollection Build() 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 b57dcaee6f6..49762de5942 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 @@ -16,6 +16,12 @@ namespace UnityEngine.Rendering.HighDefinition /// The AOVBuffer to allocatE. public delegate RTHandle AOVRequestBufferAllocator(AOVBuffers aovBufferId); + /// + /// Called to allocate a RTHandle for a specific custom pass AOVBuffer. + /// + /// The AOVBuffer to allocatE. + public delegate RTHandle AOVRequestCustomPassBufferAllocator(CustomPassAOVBuffers aovBufferId); + /// Describes a frame pass. public struct AOVRequestData { @@ -41,34 +47,65 @@ public struct AOVRequestData private AOVRequest m_Settings; private AOVBuffers[] m_RequestedAOVBuffers; + private CustomPassAOVBuffers[] m_CustomPassAOVBuffers; private FramePassCallback m_Callback; private readonly AOVRequestBufferAllocator m_BufferAllocator; + private readonly AOVRequestCustomPassBufferAllocator m_CustomPassBufferAllocator; private List m_LightFilter; /// Whether this frame pass is valid. - public bool isValid => m_RequestedAOVBuffers != null && m_Callback != null; + public bool isValid => (m_RequestedAOVBuffers != null || m_CustomPassAOVBuffers != null) && m_Callback != null; + + /// Create a new frame pass. + /// Settings to use. + /// Buffer allocators to use. + /// If null, all light will be rendered, if not, only those light will be rendered. + /// The requested buffers for the callback. + /// The callback to execute. + public AOVRequestData( + AOVRequest settings, + AOVRequestBufferAllocator bufferAllocator, + List lightFilter, + AOVBuffers[] requestedAOVBuffers, + FramePassCallback callback + ) + { + m_Settings = settings; + m_BufferAllocator = bufferAllocator; + m_RequestedAOVBuffers = requestedAOVBuffers; + m_LightFilter = lightFilter; + m_Callback = callback; + m_CustomPassAOVBuffers = null; + m_CustomPassBufferAllocator = null; + } /// Create a new frame pass. /// Settings to use. /// Buffer allocators to use. /// If null, all light will be rendered, if not, only those light will be rendered. /// The requested buffers for the callback. + /// The custom pass buffers that will be captured. /// The callback to execute. public AOVRequestData( AOVRequest settings, AOVRequestBufferAllocator bufferAllocator, + AOVRequestCustomPassBufferAllocator customPassBufferAllocator, List lightFilter, AOVBuffers[] requestedAOVBuffers, + CustomPassAOVBuffers[] customPassAOVBuffers, FramePassCallback callback ) { m_Settings = settings; m_BufferAllocator = bufferAllocator; m_RequestedAOVBuffers = requestedAOVBuffers; + m_CustomPassAOVBuffers = customPassAOVBuffers; + m_CustomPassBufferAllocator = customPassBufferAllocator; m_LightFilter = lightFilter; m_Callback = callback; } + /// Allocate texture if required. /// A buffer of texture ready to use. public void AllocateTargetTexturesIfRequired(ref List textures) @@ -76,12 +113,19 @@ public void AllocateTargetTexturesIfRequired(ref List textures) if (!isValid || textures == null) return; - Assert.IsNotNull(m_RequestedAOVBuffers); - textures.Clear(); - foreach (var bufferId in m_RequestedAOVBuffers) - textures.Add(m_BufferAllocator(bufferId)); + if (m_RequestedAOVBuffers != null) + { + foreach (var bufferId in m_RequestedAOVBuffers) + textures.Add(m_BufferAllocator(bufferId)); + } + + if (m_CustomPassAOVBuffers != null) + { + foreach (var aovBufferId in m_CustomPassAOVBuffers) + textures.Add(m_CustomPassBufferAllocator(aovBufferId)); + } } /// Copy a camera sized texture into the texture buffers. @@ -98,7 +142,7 @@ internal void PushCameraTexture( List targets ) { - if (!isValid) + if (!isValid || m_RequestedAOVBuffers == null) return; Assert.IsNotNull(m_RequestedAOVBuffers); @@ -111,18 +155,34 @@ List targets HDUtils.BlitCameraTexture(cmd, source, targets[index]); } - internal void PushCameraTexture( + internal void PushCustomPassTexture( CommandBuffer cmd, - AOVBuffers aovBufferId, - HDCamera camera, - Lazy source, + CustomPassInjectionPoint injectionPoint, + RTHandle cameraSource, + Lazy customPassSource, List targets ) { - if (!source.IsValueCreated) + if (!isValid || m_CustomPassAOVBuffers == null) + return; + + Assert.IsNotNull(targets); + + var index = Array.FindIndex(m_CustomPassAOVBuffers, x => x.injectionPoint == injectionPoint); + if (index == -1) return; - PushCameraTexture(cmd, aovBufferId, camera, source.Value, targets); + if (m_CustomPassAOVBuffers[index].outputType == CustomPassAOVBuffers.OutputType.Camera) + { + HDUtils.BlitCameraTexture(cmd, cameraSource, targets[index]); + } + else + { + if (customPassSource.IsValueCreated) + { + HDUtils.BlitCameraTexture(cmd, customPassSource.Value, targets[index]); + } + } } class PushCameraTexturePassData @@ -141,7 +201,7 @@ internal void PushCameraTexture( List targets ) { - if (!isValid) + if (!isValid || m_RequestedAOVBuffers == null) return; Assert.IsNotNull(m_RequestedAOVBuffers); From 5ec19273b32a1ae432b7eebf625af2da0d1c2243 Mon Sep 17 00:00:00 2001 From: "pavlos.mavridis" Date: Thu, 12 Mar 2020 20:01:03 +0100 Subject: [PATCH 05/10] API improvements --- .../RenderPipeline/HDRenderPipeline.cs | 15 +++--- .../RenderPass/AOV/AOVRequestBuilder.cs | 2 +- .../RenderPass/AOV/AOVRequestData.cs | 53 +++++++++++++++++-- 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 87244a7c65d..d9ae97074b4 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -1902,8 +1902,9 @@ AOVRequestData aovRequest } using (ListPool.Get(out var aovBuffers)) + using (ListPool.Get(out var aovCustomPassBuffers)) { - aovRequest.AllocateTargetTexturesIfRequired(ref aovBuffers); + aovRequest.AllocateTargetTexturesIfRequired(ref aovBuffers, ref aovCustomPassBuffers); // If we render a reflection view or a preview we should not display any debug information // This need to be call before ApplyDebugDisplaySettings() @@ -2145,7 +2146,7 @@ void Callback(CommandBuffer c, HDCamera cam) m_IsDepthBufferCopyValid = false; // Push the custom pass buffer, in case it was requested in the AOVs - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); // In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing. GenerateDepthPyramid(hdCamera, cmd, FullScreenDebugMode.DepthPyramid); @@ -2375,7 +2376,7 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePreRefraction); // Push the custom pass buffer, in case it was requested in the AOVs - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforePreRefraction, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforePreRefraction, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); // Render pre refraction objects RenderForwardTransparent(cullingResults, hdCamera, true, renderContext, cmd); @@ -2399,7 +2400,7 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforeTransparent); // Push the custom pass texture, if it was requested in the AOVs - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforeTransparent, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforeTransparent, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); // Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects. RenderForwardTransparent(cullingResults, hdCamera, false, renderContext, cmd); @@ -2462,7 +2463,7 @@ void Callback(CommandBuffer c, HDCamera cam) // Push the camera and custom pass textures, in case they were requested in the AOVs aovRequest.PushCameraTexture(cmd, AOVBuffers.Color, hdCamera, m_CameraColorBuffer, aovBuffers); - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforePostProcess, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforePostProcess, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); RenderTargetIdentifier postProcessDest = HDUtils.PostProcessIsFinalPass(hdCamera) ? target.id : m_IntermediateAfterPostProcessBuffer; RenderPostProcess(cullingResults, hdCamera, postProcessDest, renderContext, cmd); @@ -2470,7 +2471,7 @@ void Callback(CommandBuffer c, HDCamera cam) RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.AfterPostProcess); // Push the custom pass texture, in case it was requested in the AOVs - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.AfterPostProcess, m_CameraColorBuffer, m_CustomPassColorBuffer, aovBuffers); + aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.AfterPostProcess, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); // Copy and rescale depth buffer for XR devices if (hdCamera.xr.enabled && hdCamera.xr.copyDepth) @@ -2556,7 +2557,7 @@ void Callback(CommandBuffer c, HDCamera cam) RenderGizmos(cmd, camera, renderContext, GizmoSubset.PostImageEffects); #endif - aovRequest.Execute(cmd, aovBuffers, RenderOutputProperties.From(hdCamera)); + aovRequest.Execute(cmd, aovBuffers, aovCustomPassBuffers, RenderOutputProperties.From(hdCamera)); } // This is required so that all commands up to here are executed before EndCameraRendering is called for the user. diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs index 9bbe07ae67b..a32d223b22e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs @@ -43,7 +43,7 @@ public AOVRequestBuilder Add( List includedLightList, AOVBuffers[] aovBuffers, CustomPassAOVBuffers[] customPassAovBuffers, - FramePassCallback callback + FramePassCallbackEx callback ) { (m_AOVRequestDataData ?? (m_AOVRequestDataData = ListPool.Get())).Add( 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 49762de5942..08d29da2578 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 @@ -16,6 +16,11 @@ namespace UnityEngine.Rendering.HighDefinition /// The AOVBuffer to allocatE. public delegate RTHandle AOVRequestBufferAllocator(AOVBuffers aovBufferId); + /// Called when the rendering has completed. + /// A command buffer that can be used. + /// The buffers that has been requested. + /// Several properties that were computed for this frame. + public delegate void FramePassCallbackEx(CommandBuffer cmd, List buffers, List customPassbuffers, RenderOutputProperties outputProperties); /// /// Called to allocate a RTHandle for a specific custom pass AOVBuffer. /// @@ -49,12 +54,13 @@ public struct AOVRequestData private AOVBuffers[] m_RequestedAOVBuffers; private CustomPassAOVBuffers[] m_CustomPassAOVBuffers; private FramePassCallback m_Callback; + private FramePassCallbackEx m_CallbackEx; private readonly AOVRequestBufferAllocator m_BufferAllocator; private readonly AOVRequestCustomPassBufferAllocator m_CustomPassBufferAllocator; private List m_LightFilter; /// Whether this frame pass is valid. - public bool isValid => (m_RequestedAOVBuffers != null || m_CustomPassAOVBuffers != null) && m_Callback != null; + public bool isValid => (m_RequestedAOVBuffers != null || m_CustomPassAOVBuffers != null) && (m_Callback != null || m_CallbackEx != null); /// Create a new frame pass. /// Settings to use. @@ -75,6 +81,8 @@ FramePassCallback callback m_RequestedAOVBuffers = requestedAOVBuffers; m_LightFilter = lightFilter; m_Callback = callback; + + m_CallbackEx = null; m_CustomPassAOVBuffers = null; m_CustomPassBufferAllocator = null; } @@ -93,7 +101,7 @@ public AOVRequestData( List lightFilter, AOVBuffers[] requestedAOVBuffers, CustomPassAOVBuffers[] customPassAOVBuffers, - FramePassCallback callback + FramePassCallbackEx callback ) { m_Settings = settings; @@ -102,7 +110,8 @@ FramePassCallback callback m_CustomPassAOVBuffers = customPassAOVBuffers; m_CustomPassBufferAllocator = customPassBufferAllocator; m_LightFilter = lightFilter; - m_Callback = callback; + m_Callback = null; + m_CallbackEx = callback; } @@ -120,11 +129,28 @@ public void AllocateTargetTexturesIfRequired(ref List textures) foreach (var bufferId in m_RequestedAOVBuffers) textures.Add(m_BufferAllocator(bufferId)); } + } + + /// Allocate texture if required. + /// A buffer of texture ready to use. + public void AllocateTargetTexturesIfRequired(ref List textures, ref List customPassTextures) + { + if (!isValid || textures == null) + return; + + textures.Clear(); + customPassTextures.Clear(); + + if (m_RequestedAOVBuffers != null) + { + foreach (var bufferId in m_RequestedAOVBuffers) + textures.Add(m_BufferAllocator(bufferId)); + } if (m_CustomPassAOVBuffers != null) { foreach (var aovBufferId in m_CustomPassAOVBuffers) - textures.Add(m_CustomPassBufferAllocator(aovBufferId)); + customPassTextures.Add(m_CustomPassBufferAllocator(aovBufferId)); } } @@ -237,6 +263,25 @@ public void Execute(CommandBuffer cmd, List framePassTextures, RenderO m_Callback(cmd, framePassTextures, outputProperties); } + /// Execute the frame pass callback. It assumes that the textures are properly initialized and filled. + /// The command buffer to use. + /// The textures to use. + /// The properties computed for this frame. + public void Execute(CommandBuffer cmd, List framePassTextures, List customPassTextures, RenderOutputProperties outputProperties) + { + if (!isValid) + return; + + if (m_CallbackEx != null) + { + m_CallbackEx(cmd, framePassTextures, customPassTextures, outputProperties); + } + else + { + m_Callback(cmd, framePassTextures, outputProperties); + } + } + /// Setup the display manager if necessary. /// public void SetupDebugData(ref DebugDisplaySettings debugDisplaySettings) From efe4ad27c0a026b9e875fece82f87fb902ecb7dc Mon Sep 17 00:00:00 2001 From: "pavlos.mavridis" Date: Fri, 20 Mar 2020 10:34:37 +0100 Subject: [PATCH 06/10] API documentation --- .../RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs | 6 ++++-- .../Runtime/RenderPipeline/RenderPass/AOV/AOVRequestData.cs | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs index a32d223b22e..d7c9ca9f358 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVRequestBuilder.cs @@ -34,20 +34,22 @@ FramePassCallback callback /// An allocator for each buffer. /// If non null, only these lights will be rendered, if none, all lights will be rendered. /// A list of buffers to use. + /// A list of custom passes to captured. + /// An allocator for each custom pass buffer. /// A callback that can use the requested buffers once the rendering has completed. /// public AOVRequestBuilder Add( AOVRequest settings, AOVRequestBufferAllocator bufferAllocator, - AOVRequestCustomPassBufferAllocator customPassbufferAllocator, List includedLightList, AOVBuffers[] aovBuffers, CustomPassAOVBuffers[] customPassAovBuffers, + AOVRequestCustomPassBufferAllocator customPassbufferAllocator, FramePassCallbackEx callback ) { (m_AOVRequestDataData ?? (m_AOVRequestDataData = ListPool.Get())).Add( - new AOVRequestData(settings, bufferAllocator, customPassbufferAllocator, includedLightList, aovBuffers, customPassAovBuffers, callback)); + new AOVRequestData(settings, bufferAllocator, includedLightList, aovBuffers, customPassAovBuffers, customPassbufferAllocator, callback)); return this; } 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 08d29da2578..4bec8799848 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 @@ -93,14 +93,15 @@ FramePassCallback callback /// If null, all light will be rendered, if not, only those light will be rendered. /// The requested buffers for the callback. /// The custom pass buffers that will be captured. + /// Buffer allocators to use for custom passes. /// The callback to execute. public AOVRequestData( AOVRequest settings, AOVRequestBufferAllocator bufferAllocator, - AOVRequestCustomPassBufferAllocator customPassBufferAllocator, List lightFilter, AOVBuffers[] requestedAOVBuffers, CustomPassAOVBuffers[] customPassAOVBuffers, + AOVRequestCustomPassBufferAllocator customPassBufferAllocator, FramePassCallbackEx callback ) { @@ -114,7 +115,6 @@ FramePassCallbackEx callback m_CallbackEx = callback; } - /// Allocate texture if required. /// A buffer of texture ready to use. public void AllocateTargetTexturesIfRequired(ref List textures) From b7cc90a5d1dca6a27a97551e94bef1a483e5e7f8 Mon Sep 17 00:00:00 2001 From: "pavlos.mavridis" Date: Thu, 26 Mar 2020 09:35:00 +0100 Subject: [PATCH 07/10] API doc, factorize all push texture calls in RenderCustomPass --- .../RenderPipeline/HDRenderPipeline.cs | 31 ++++++------------- .../RenderPass/AOV/AOVBuffers.cs | 15 ++++----- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index d9ae97074b4..8ccd7686f10 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2045,7 +2045,7 @@ AOVRequestData aovRequest cmd.SetGlobalTexture(HDShaderIDs._CustomDepthTexture, m_CustomPassDepthBuffer.Value); } - RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforeRendering); + RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforeRendering, aovRequest, aovCustomPassBuffers); RenderRayTracingPrepass(cullingResults, hdCamera, renderContext, cmd, false); @@ -2139,15 +2139,12 @@ void Callback(CommandBuffer c, HDCamera cam) m_SharedRTManager.BindNormalBuffer(cmd); // After Depth and Normals/roughness including decals - bool depthBufferModified = RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.AfterOpaqueDepthAndNormal); + bool depthBufferModified = RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, m_CustomPassColorBuffer, aovCustomPassBuffers); // If the depth was already copied in RenderDBuffer, we force the copy again because the custom pass modified the depth. if (depthBufferModified) m_IsDepthBufferCopyValid = false; - // Push the custom pass buffer, in case it was requested in the AOVs - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); - // In both forward and deferred, everything opaque should have been rendered at this point so we can safely copy the depth buffer for later processing. GenerateDepthPyramid(hdCamera, cmd, FullScreenDebugMode.DepthPyramid); @@ -2373,10 +2370,7 @@ void Callback(CommandBuffer c, HDCamera cam) // To allow users to fetch the current color buffer, we temporarily bind the camera color buffer cmd.SetGlobalTexture(HDShaderIDs._ColorPyramidTexture, m_CameraColorBuffer); - RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePreRefraction); - - // Push the custom pass buffer, in case it was requested in the AOVs - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforePreRefraction, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); + RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePreRefraction, aovRequest, aovCustomPassBuffers); // Render pre refraction objects RenderForwardTransparent(cullingResults, hdCamera, true, renderContext, cmd); @@ -2397,10 +2391,7 @@ void Callback(CommandBuffer c, HDCamera cam) } // We don't have access to the color pyramid with transparent if rough refraction is disabled - RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforeTransparent); - - // Push the custom pass texture, if it was requested in the AOVs - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforeTransparent, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); + RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforeTransparent, aovRequest, aovCustomPassBuffers); // Render all type of transparent forward (unlit, lit, complex (hair...)) to keep the sorting between transparent objects. RenderForwardTransparent(cullingResults, hdCamera, false, renderContext, cmd); @@ -2459,19 +2450,14 @@ void Callback(CommandBuffer c, HDCamera cam) // At this point, m_CameraColorBuffer has been filled by either debug views are regular rendering so we can push it here. PushColorPickerDebugTexture(cmd, hdCamera, m_CameraColorBuffer); - RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePostProcess); + RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.BeforePostProcess, aovRequest, aovCustomPassBuffers); - // Push the camera and custom pass textures, in case they were requested in the AOVs aovRequest.PushCameraTexture(cmd, AOVBuffers.Color, hdCamera, m_CameraColorBuffer, aovBuffers); - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.BeforePostProcess, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); RenderTargetIdentifier postProcessDest = HDUtils.PostProcessIsFinalPass(hdCamera) ? target.id : m_IntermediateAfterPostProcessBuffer; RenderPostProcess(cullingResults, hdCamera, postProcessDest, renderContext, cmd); - RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.AfterPostProcess); - - // Push the custom pass texture, in case it was requested in the AOVs - aovRequest.PushCustomPassTexture(cmd, CustomPassInjectionPoint.AfterPostProcess, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); + RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.AfterPostProcess, aovRequest, aovCustomPassBuffers); // Copy and rescale depth buffer for XR devices if (hdCamera.xr.enabled && hdCamera.xr.copyDepth) @@ -3693,7 +3679,7 @@ void RenderForwardError(CullingResults cullResults, HDCamera hdCamera, Scriptabl } } - bool RenderCustomPass(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResults, CustomPassInjectionPoint injectionPoint) + bool RenderCustomPass(ScriptableRenderContext context, CommandBuffer cmd, HDCamera hdCamera, CullingResults cullingResults, CustomPassInjectionPoint injectionPoint, AOVRequestData aovRequest, List aovCustomPassBuffers) { if (!hdCamera.frameSettings.IsEnabled(FrameSettingsField.CustomPass)) return false; @@ -3715,6 +3701,9 @@ bool RenderCustomPass(ScriptableRenderContext context, CommandBuffer cmd, HDCame executed |= customPass.Execute(context, cmd, hdCamera, cullingResults, m_SharedRTManager, customPassTargets); } + // Push the custom pass buffer, in case it was requested in the AOVs + aovRequest.PushCustomPassTexture(cmd, injectionPoint, m_CameraColorBuffer, m_CustomPassColorBuffer, aovCustomPassBuffers); + return executed; } diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs index 5b8b704543f..aedb7b90c1e 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs @@ -15,22 +15,23 @@ public enum AOVBuffers MotionVectors } - + /// + /// Describes the type of custom pass buffer that will be exported with the AOV API. + /// public struct CustomPassAOVBuffers { + /// Specifies which output type to export. public enum OutputType { + /// The custom pass buffer will be exported. CustomPassBuffer, + /// The color buffer of the camera will be exported. Camera } + /// The injection point of the custom passes that will be exported. public CustomPassInjectionPoint injectionPoint; + /// Specifies which output type to export. public OutputType outputType; - - public CustomPassAOVBuffers(CustomPassInjectionPoint ip, OutputType ot) - { - injectionPoint = ip; - outputType = ot; - } } } From 55b58068ea61cf6f743e33ae8ef76a938d4c7150 Mon Sep 17 00:00:00 2001 From: "pavlos.mavridis" Date: Thu, 26 Mar 2020 10:34:21 +0100 Subject: [PATCH 08/10] added default values and constructor for CustomPassAOVBuffers --- .../RenderPipeline/RenderPass/AOV/AOVBuffers.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs index aedb7b90c1e..f30acd39acb 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/AOV/AOVBuffers.cs @@ -18,7 +18,7 @@ public enum AOVBuffers /// /// Describes the type of custom pass buffer that will be exported with the AOV API. /// - public struct CustomPassAOVBuffers + public class CustomPassAOVBuffers { /// Specifies which output type to export. public enum OutputType @@ -30,8 +30,19 @@ public enum OutputType } /// The injection point of the custom passes that will be exported. - public CustomPassInjectionPoint injectionPoint; + public CustomPassInjectionPoint injectionPoint = CustomPassInjectionPoint.BeforeRendering; /// Specifies which output type to export. - public OutputType outputType; + public OutputType outputType = OutputType.CustomPassBuffer; + + /// + /// Constructor for CustomPassAOVBuffers + /// + /// The injection point of the custom passes that will be exported. + /// The buffer type to export at the scpecified injection point. + public CustomPassAOVBuffers(CustomPassInjectionPoint injectionPoint, OutputType outputType) + { + this.injectionPoint = injectionPoint; + this.outputType = outputType; + } } } From 4185062ea2d00462e9b1e769f1f5bc0f100758a8 Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Tue, 7 Apr 2020 12:21:32 +0200 Subject: [PATCH 09/10] fix merge conflicts --- .../Runtime/RenderPipeline/HDRenderPipeline.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs index 8ccd7686f10..5c0bec16ca9 100644 --- a/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs +++ b/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs @@ -2139,7 +2139,7 @@ void Callback(CommandBuffer c, HDCamera cam) m_SharedRTManager.BindNormalBuffer(cmd); // After Depth and Normals/roughness including decals - bool depthBufferModified = RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, m_CustomPassColorBuffer, aovCustomPassBuffers); + bool depthBufferModified = RenderCustomPass(renderContext, cmd, hdCamera, customPassCullingResults, CustomPassInjectionPoint.AfterOpaqueDepthAndNormal, aovRequest, aovCustomPassBuffers); // If the depth was already copied in RenderDBuffer, we force the copy again because the custom pass modified the depth. if (depthBufferModified) From 911e99593ac97bb7816e87fb1ebda3deee00332b Mon Sep 17 00:00:00 2001 From: Pavlos Mavridis Date: Thu, 9 Apr 2020 11:24:41 +0200 Subject: [PATCH 10/10] Fix GC alloc during rendering: use a for loop instead of findIndex+lambda --- .../RenderPipeline/RenderPass/AOV/AOVRequestData.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 4bec8799848..ae9bf328baa 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 @@ -194,7 +194,16 @@ List targets Assert.IsNotNull(targets); - var index = Array.FindIndex(m_CustomPassAOVBuffers, x => x.injectionPoint == injectionPoint); + int index = -1; + for (int i = 0; i < m_CustomPassAOVBuffers.Length; ++i) + { + if (m_CustomPassAOVBuffers[i].injectionPoint == injectionPoint) + { + index = i; + break; + } + } + if (index == -1) return;