@@ -706,8 +706,7 @@ public HDRenderPipeline(HDRenderPipelineAsset asset)
706706
707707 m_DepthPyramidMipLevelOffsetsBuffer = new ComputeBuffer ( 15 , sizeof ( int ) * 2 ) ;
708708
709- m_CustomPassColorBuffer = new Lazy < RTHandle > ( ( ) => RTHandles . Alloc ( Vector2 . one , TextureXR . slices , dimension : TextureXR . dimension , colorFormat : GetCustomBufferFormat ( ) , enableRandomWrite : true , useDynamicScale : true , name : "CustomPassColorBuffer" ) ) ;
710- m_CustomPassDepthBuffer = new Lazy < RTHandle > ( ( ) => RTHandles . Alloc ( Vector2 . one , TextureXR . slices , dimension : TextureXR . dimension , colorFormat : GraphicsFormat . None , useDynamicScale : true , name : "CustomPassDepthBuffer" , depthBufferBits : CoreUtils . GetDefaultDepthBufferBits ( ) ) ) ;
709+ AllocateCustomPassBuffers ( ) ;
711710
712711 // For debugging
713712 MousePositionDebug . instance . Build ( ) ;
@@ -2265,6 +2264,14 @@ protected override void Render(ScriptableRenderContext renderContext, List<Camer
22652264 // so will present rendering at native resolution. This will only pay a small cost of memory on the texture aliasing that the runtime has to keep track of.
22662265 RTHandles . SetHardwareDynamicResolutionState ( m_Asset . currentPlatformRenderPipelineSettings . dynamicResolutionSettings . dynResType == DynamicResolutionType . Hardware ) ;
22672266
2267+ // This is to ensure that custom pass buffers have the adequate depth/number of slices when switching from XR enabled/disabled
2268+ if ( m_CustomPassColorBuffer . Value . rt . volumeDepth != TextureXR . slices )
2269+ {
2270+ RTHandles . Release ( m_CustomPassColorBuffer . Value ) ;
2271+ RTHandles . Release ( m_CustomPassDepthBuffer . Value ) ;
2272+ AllocateCustomPassBuffers ( ) ;
2273+ }
2274+
22682275 // Culling loop
22692276 foreach ( ( Camera camera , XRPass xrPass ) in xrLayout . GetActivePasses ( ) )
22702277 {
@@ -3441,5 +3448,11 @@ static void AdjustUIOverlayOwnership(int cameraCount)
34413448 SupportedRenderingFeatures . active . rendersUIOverlay = true ;
34423449 }
34433450 }
3451+
3452+ void AllocateCustomPassBuffers ( )
3453+ {
3454+ m_CustomPassColorBuffer = new Lazy < RTHandle > ( ( ) => RTHandles . Alloc ( Vector2 . one , TextureXR . slices , dimension : TextureXR . dimension , colorFormat : GetCustomBufferFormat ( ) , enableRandomWrite : true , useDynamicScale : true , name : "CustomPassColorBuffer" ) ) ;
3455+ m_CustomPassDepthBuffer = new Lazy < RTHandle > ( ( ) => RTHandles . Alloc ( Vector2 . one , TextureXR . slices , dimension : TextureXR . dimension , colorFormat : GraphicsFormat . None , useDynamicScale : true , name : "CustomPassDepthBuffer" , depthBufferBits : CoreUtils . GetDefaultDepthBufferBits ( ) ) ) ;
3456+ }
34443457 }
34453458}
0 commit comments