Skip to content

Commit 1503d11

Browse files
lpledouxUnityEvergreen
authored andcommitted
[Port] [2022.3] Fix for incorrect buffer size when switching XR On/Off
1 parent 0e25d76 commit 1503d11

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDRenderPipeline.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,7 @@ public HDRenderPipeline(HDRenderPipelineAsset asset)
622622

623623
m_DepthPyramidMipLevelOffsetsBuffer = new ComputeBuffer(15, sizeof(int) * 2);
624624

625-
m_CustomPassColorBuffer = new Lazy<RTHandle>(() => RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GetCustomBufferFormat(), enableRandomWrite: true, useDynamicScale: true, name: "CustomPassColorBuffer"));
626-
m_CustomPassDepthBuffer = new Lazy<RTHandle>(() => RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.R32_UInt, useDynamicScale: true, name: "CustomPassDepthBuffer", depthBufferBits: DepthBits.Depth32));
625+
AllocateCustomPassBuffers();
627626

628627
// For debugging
629628
MousePositionDebug.instance.Build();
@@ -2034,6 +2033,14 @@ protected override void Render(ScriptableRenderContext renderContext, Camera[] c
20342033
// 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.
20352034
RTHandles.SetHardwareDynamicResolutionState(m_Asset.currentPlatformRenderPipelineSettings.dynamicResolutionSettings.dynResType == DynamicResolutionType.Hardware);
20362035

2036+
// This is to ensure that custom pass buffers have the adequate depth/number of slices when switching from XR enabled/disabled
2037+
if (m_CustomPassColorBuffer.Value.rt.volumeDepth != TextureXR.slices)
2038+
{
2039+
RTHandles.Release(m_CustomPassColorBuffer.Value);
2040+
RTHandles.Release(m_CustomPassDepthBuffer.Value);
2041+
AllocateCustomPassBuffers();
2042+
}
2043+
20372044
// Culling loop
20382045
foreach ((Camera camera, XRPass xrPass) in xrLayout.GetActivePasses())
20392046
{
@@ -2953,5 +2960,11 @@ static void AdjustUIOverlayOwnership(int cameraCount)
29532960
SupportedRenderingFeatures.active.rendersUIOverlay = true;
29542961
}
29552962
}
2963+
2964+
void AllocateCustomPassBuffers()
2965+
{
2966+
m_CustomPassColorBuffer = new Lazy<RTHandle>(() => RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GetCustomBufferFormat(), enableRandomWrite: true, useDynamicScale: true, name: "CustomPassColorBuffer"));
2967+
m_CustomPassDepthBuffer = new Lazy<RTHandle>(() => RTHandles.Alloc(Vector2.one, TextureXR.slices, dimension: TextureXR.dimension, colorFormat: GraphicsFormat.R32_UInt, useDynamicScale: true, name: "CustomPassDepthBuffer", depthBufferBits: DepthBits.Depth32));
2968+
}
29562969
}
29572970
}

0 commit comments

Comments
 (0)