Skip to content

Commit 97648d6

Browse files
axolotoEvergreen
authored andcommitted
Graphics/SRP/RPF - [UUM-57147] - Disabling NRP for Editor FinalCopyDepth pass
This PR disables Native Render Pass (NRP) support of URP Editor-only `FinalCopyDepth` pass which is used a pre-step for the Post-Process Gizmos pass in URP 3D. Using NRP in this pass triggered a corner case which is not well covered by NRP pipeline in Compatibility mode. Indeed, NRP pipeline begins a native render pass with a number of MSAA samples taken from the `CameraTargetDescriptor`. `CameraTargetDescriptor` seems to obtain that information from the RenderPipeline asset, so depending on what users select in the UI, it can be no MSAA/x2/x4/x8. On the other hand, `FinalCopyDepth` seems to be the only pass targeting `k_CameraTarget` in URP 3D and its attachment (backbuffer) has no MSAA enabled, triggering a mismatch in NRP validation layer as the number of samples is different (unacceptable in NRP). As this is Editor only + Compatibility mode, I assume that using NRP for this pass is not really important and can be disabled. Compatibility mode with no NRP works fine for this case. Note that NRP Render Graph should be preferred over NRP Compatibility mode for Unity 6.
1 parent d6bfada commit 97648d6

File tree

3 files changed

+5
-11
lines changed

3 files changed

+5
-11
lines changed

Packages/com.unity.render-pipelines.universal/Runtime/Passes/CopyDepthPass.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,8 @@ public void Dispose()
7272
[Obsolete(DeprecationMessage.CompatibilityScriptingAPIObsolete, false)]
7373
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
7474
{
75-
var descriptor = renderingData.cameraData.cameraTargetDescriptor;
76-
var isDepth = (destination.rt && destination.rt.graphicsFormat == GraphicsFormat.None);
77-
descriptor.graphicsFormat = isDepth ? GraphicsFormat.D32_SFloat_S8_UInt : GraphicsFormat.R32_SFloat;
78-
descriptor.msaaSamples = 1;
79-
8075
// Disable obsolete warning for internal usage
8176
#pragma warning disable CS0618
82-
83-
// This is a temporary workaround for Editor as not setting any depth here
84-
// would lead to overwriting depth in certain scenarios (reproducable while running DX11 tests)
8577
#if UNITY_EDITOR
8678
// This is a temporary workaround for Editor as not setting any depth here
8779
// would lead to overwriting depth in certain scenarios (reproducable while running DX11 tests)

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public UniversalRenderer(UniversalRendererData data) : base(data)
357357
m_FinalBlitPass = new FinalBlitPass(RenderPassEvent.AfterRendering + k_FinalBlitPassQueueOffset, m_BlitMaterial, m_BlitHDRMaterial);
358358

359359
#if UNITY_EDITOR
360-
m_FinalDepthCopyPass = new CopyDepthPass(RenderPassEvent.AfterRendering + 9, copyDephPS);
360+
m_FinalDepthCopyPass = new CopyDepthPass(RenderPassEvent.AfterRendering + 9, copyDephPS, false, true);
361361
if (GraphicsSettings.TryGetRenderPipelineSettings<UniversalRenderPipelineDebugShaders>(out var debugShaders))
362362
m_ProbeVolumeDebugPass = new ProbeVolumeDebugPass(RenderPassEvent.BeforeRenderingTransparents, debugShaders.probeVolumeSamplingDebugComputeShader);
363363
#endif
@@ -1471,8 +1471,11 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
14711471
{
14721472
// Scene view camera should always resolve target (not stacked)
14731473
m_FinalDepthCopyPass.Setup(m_DepthTexture, k_CameraTarget);
1474-
m_FinalDepthCopyPass.CopyToDepth = true;
14751474
m_FinalDepthCopyPass.MssaSamples = 0;
1475+
// Turning off unnecessary NRP in Editor because of MSAA mistmatch between CameraTargetDescriptor vs camera backbuffer
1476+
// NRP layer considers this being a pass with MSAA samples by checking CameraTargetDescriptor taken from RP asset
1477+
// while the camera backbuffer has a single sample
1478+
m_FinalDepthCopyPass.useNativeRenderPass = false;
14761479
EnqueuePass(m_FinalDepthCopyPass);
14771480
}
14781481
#endif

Packages/com.unity.render-pipelines.universal/Runtime/UniversalRendererRenderGraph.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,6 @@ private void OnAfterRendering(RenderGraph renderGraph)
14361436
if (cameraData.isSceneViewCamera || cameraData.isPreviewCamera || (isGizmosEnabled && cameraData.resolveFinalTarget))
14371437
{
14381438
TextureHandle cameraDepthTexture = resourceData.cameraDepthTexture;
1439-
m_FinalDepthCopyPass.CopyToDepth = true;
14401439
m_FinalDepthCopyPass.MssaSamples = 0;
14411440
m_FinalDepthCopyPass.Render(renderGraph, frameData, resourceData.activeDepthTexture, cameraDepthTexture, false, "Final Depth Copy");
14421441
}

0 commit comments

Comments
 (0)