From 06b5f63171177834ab0489c42120666c54a43d1c Mon Sep 17 00:00:00 2001 From: Trevor Dasch Date: Tue, 5 Mar 2024 11:41:32 -0500 Subject: [PATCH] Fix deprecated API warning by passing motion vector color and depth RTs as RTHandles instead of RenderTargetIdentifiers --- .../Runtime/Passes/OculusMotionVectorPass.cs | 14 +++++++------- .../Runtime/UniversalRenderer.cs | 17 +++++++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/Passes/OculusMotionVectorPass.cs b/Packages/com.unity.render-pipelines.universal/Runtime/Passes/OculusMotionVectorPass.cs index b784800eb85..dc2dbe2a97b 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/Passes/OculusMotionVectorPass.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/Passes/OculusMotionVectorPass.cs @@ -14,8 +14,8 @@ public class OculusMotionVectorPass : ScriptableRenderPass FilteringSettings m_FilteringSettings; ProfilingSampler m_ProfilingSampler; - RenderTargetIdentifier motionVectorColorIdentifier; - RenderTargetIdentifier motionVectorDepthIdentifier; + RTHandle motionVectorColorHandle; + RTHandle motionVectorDepthHandle; public OculusMotionVectorPass(string profilerTag, bool opaque, RenderPassEvent evt, RenderQueueRange renderQueueRange, LayerMask layerMask, StencilState stencilState, int stencilReference) { @@ -32,16 +32,16 @@ internal OculusMotionVectorPass(URPProfileId profileId, bool opaque, RenderPassE } public void Setup( - RenderTargetIdentifier motionVecColorIdentifier, - RenderTargetIdentifier motionVecDepthIdentifier) + RTHandle motionVecColorIdentifier, + RTHandle motionVecDepthIdentifier) { - this.motionVectorColorIdentifier = motionVecColorIdentifier; - this.motionVectorDepthIdentifier = motionVecDepthIdentifier; + this.motionVectorColorHandle = motionVecColorIdentifier; + this.motionVectorDepthHandle = motionVecDepthIdentifier; } public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData) { - ConfigureTarget(motionVectorColorIdentifier, motionVectorDepthIdentifier); + ConfigureTarget(motionVectorColorHandle, motionVectorDepthHandle); ConfigureClear(ClearFlag.All, Color.black); } diff --git a/Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs b/Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs index 858084e3a90..2045568dd16 100644 --- a/Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs +++ b/Packages/com.unity.render-pipelines.universal/Runtime/UniversalRenderer.cs @@ -133,6 +133,7 @@ public override int SupportedCameraStackingTypes() RTHandle m_OpaqueColor; RTHandle m_MotionVectorColor; RTHandle m_MotionVectorDepth; + RTHandle m_XRMotionVectorTargetHandleAlias; ForwardLights m_ForwardLights; DeferredLights m_DeferredLights; @@ -393,6 +394,7 @@ internal override void ReleaseRenderTargets() m_OpaqueColor?.Release(); m_MotionVectorColor?.Release(); m_MotionVectorDepth?.Release(); + m_XRMotionVectorTargetHandleAlias?.Release(); hasReleasedRTs = true; } @@ -960,12 +962,19 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re #if !UNITY_EDITOR if (cameraData.xr.motionVectorRenderTargetValid) { - RenderTargetHandle motionVecHandle = new RenderTargetHandle(cameraData.xr.motionVectorRenderTarget); - var rtMotionId = motionVecHandle.Identifier(); - rtMotionId = new RenderTargetIdentifier(rtMotionId, 0, CubemapFace.Unknown, -1); + RenderTargetIdentifier motionVecId = cameraData.xr.motionVectorRenderTarget; + + if (m_XRMotionVectorTargetHandleAlias == null || m_XRMotionVectorTargetHandleAlias.nameID != motionVecId) + { + m_XRMotionVectorTargetHandleAlias?.Release(); + m_XRMotionVectorTargetHandleAlias = RTHandles.Alloc(motionVecId); + } // ID is the same since a RenderTexture encapsulates all the attachments, including both color+depth. - m_OculusMotionVecPass.Setup(rtMotionId, rtMotionId); + RTHandle mvColor = m_XRMotionVectorTargetHandleAlias; + RTHandle mvDepth = m_XRMotionVectorTargetHandleAlias; + + m_OculusMotionVecPass.Setup(mvColor, mvDepth); EnqueuePass(m_OculusMotionVecPass); } #endif