Skip to content

Commit

Permalink
[URP] RTHandles Load/Store actions optimizations fix
Browse files Browse the repository at this point in the history
This is a backport of PR #6334 to fix reported foveation issues.
  • Loading branch information
janice-see committed Aug 17, 2023
1 parent c6d5da7 commit 745f5c8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData

renderingData.cameraData.xr.StopSinglePass(cmd);

cmd.SetGlobalTexture(ShaderPropertyId.sourceTex, m_InternalLut.Identifier());
CoreUtils.SetRenderTarget(cmd, m_InternalLut.Identifier(), RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store, ClearFlag.None, Color.clear);
// Render the lut
cmd.Blit(null, m_InternalLut.id, material);
cmd.Blit(null, BuiltinRenderTextureType.CurrentActive, material, 0);

renderingData.cameraData.xr.StartSinglePass(cmd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ public override void Execute(ScriptableRenderContext context, ref RenderingData
switch (m_DownsamplingMethod)
{
case Downsampling.None:
RenderingUtils.Blit(cmd, source, opaqueColorRT, m_CopyColorMaterial, 0, useDrawProceduleBlit);
RenderingUtils.Blit(cmd, source, opaqueColorRT, m_CopyColorMaterial, 0, useDrawProceduleBlit, RenderBufferLoadAction.DontCare);
break;
case Downsampling._2xBilinear:
RenderingUtils.Blit(cmd, source, opaqueColorRT, m_CopyColorMaterial, 0, useDrawProceduleBlit);
RenderingUtils.Blit(cmd, source, opaqueColorRT, m_CopyColorMaterial, 0, useDrawProceduleBlit, RenderBufferLoadAction.DontCare);
break;
case Downsampling._4xBox:
m_SamplingMaterial.SetFloat(m_SampleOffsetShaderHandle, 2);
RenderingUtils.Blit(cmd, source, opaqueColorRT, m_SamplingMaterial, 0, useDrawProceduleBlit);
RenderingUtils.Blit(cmd, source, opaqueColorRT, m_SamplingMaterial, 0, useDrawProceduleBlit, RenderBufferLoadAction.DontCare);
break;
case Downsampling._4xBilinear:
RenderingUtils.Blit(cmd, source, opaqueColorRT, m_CopyColorMaterial, 0, useDrawProceduleBlit);
RenderingUtils.Blit(cmd, source, opaqueColorRT, m_CopyColorMaterial, 0, useDrawProceduleBlit, RenderBufferLoadAction.DontCare);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ public class CopyDepthPass : ScriptableRenderPass
internal bool AllocateRT { get; set; }
internal int MssaSamples { get; set; }
Material m_CopyDepthMaterial;
public CopyDepthPass(RenderPassEvent evt, Material copyDepthMaterial)
internal bool m_ShouldClear;

public CopyDepthPass(RenderPassEvent evt, Material copyDepthMaterial, bool shouldClear = false)
{
base.profilingSampler = new ProfilingSampler(nameof(CopyDepthPass));
AllocateRT = true;
m_CopyDepthMaterial = copyDepthMaterial;
renderPassEvent = evt;
m_ShouldClear = shouldClear;
}

/// <summary>
Expand All @@ -51,7 +54,9 @@ public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderin

// On Metal iOS, prevent camera attachments to be bound and cleared during this pass.
ConfigureTarget(new RenderTargetIdentifier(destination.Identifier(), 0, CubemapFace.Unknown, -1), descriptor.depthStencilFormat, descriptor.width, descriptor.height, descriptor.msaaSamples, true);
ConfigureClear(ClearFlag.None, Color.black);

if (m_ShouldClear)
ConfigureClear(ClearFlag.All, Color.black);
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,10 @@ void SetRenderPassAttachments(CommandBuffer cmd, ScriptableRenderPass renderPass
finalClearFlag |= (cameraClearFlag & ClearFlag.Color);
finalClearColor = CoreUtils.ConvertSRGBToActiveColorSpace(camera.backgroundColor);

// on platforms that support Load and Store actions having the clear flag means that the action will be DontCare, which is something we want when the color target is bound the first time
if (SystemInfo.usesLoadStoreActions)
finalClearFlag |= renderPass.clearFlag;

if (m_FirstTimeCameraDepthTargetIsBound)
{
// m_CameraColorTarget can be an opaque pointer to a RenderTexture with depth-surface.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public UniversalRenderer(UniversalRendererData data) : base(data)

if (this.renderingMode == RenderingMode.Forward)
{
m_PrimedDepthCopyPass = new CopyDepthPass(RenderPassEvent.AfterRenderingPrePasses, m_CopyDepthMaterial);
m_PrimedDepthCopyPass = new CopyDepthPass(RenderPassEvent.AfterRenderingPrePasses, m_CopyDepthMaterial, true);
}

if (this.renderingMode == RenderingMode.Deferred)
Expand Down Expand Up @@ -280,7 +280,7 @@ public UniversalRenderer(UniversalRendererData data) : base(data)
new ShaderTagId("LightweightForward") // Legacy shaders (do not have a gbuffer pass) are considered forward-only for backward compatibility
};
int forwardOnlyStencilRef = stencilData.stencilReference | (int)StencilUsage.MaterialUnlit;
m_GBufferCopyDepthPass = new CopyDepthPass(RenderPassEvent.BeforeRenderingGbuffer + 1, m_CopyDepthMaterial);
m_GBufferCopyDepthPass = new CopyDepthPass(RenderPassEvent.BeforeRenderingGbuffer + 1, m_CopyDepthMaterial, true);
m_TileDepthRangePass = new TileDepthRangePass(RenderPassEvent.BeforeRenderingGbuffer + 2, m_DeferredLights, 0);
m_TileDepthRangeExtraPass = new TileDepthRangePass(RenderPassEvent.BeforeRenderingGbuffer + 3, m_DeferredLights, 1);
m_DeferredPass = new DeferredPass(RenderPassEvent.BeforeRenderingDeferredLights, m_DeferredLights);
Expand All @@ -290,7 +290,7 @@ public UniversalRenderer(UniversalRendererData data) : base(data)
// Always create this pass even in deferred because we use it for wireframe rendering in the Editor or offscreen depth texture rendering.
m_RenderOpaqueForwardPass = new DrawObjectsPass(URPProfileId.DrawOpaqueObjects, true, RenderPassEvent.BeforeRenderingOpaques, RenderQueueRange.opaque, data.opaqueLayerMask, m_DefaultStencilState, stencilData.stencilReference);

m_CopyDepthPass = new CopyDepthPass(RenderPassEvent.AfterRenderingSkybox, m_CopyDepthMaterial);
m_CopyDepthPass = new CopyDepthPass(RenderPassEvent.AfterRenderingSkybox, m_CopyDepthMaterial, true);
m_DrawSkyboxPass = new DrawSkyboxPass(RenderPassEvent.BeforeRenderingSkybox);
m_CopyColorPass = new CopyColorPass(RenderPassEvent.AfterRenderingSkybox, m_SamplingMaterial, m_BlitMaterial);
#if ADAPTIVE_PERFORMANCE_2_1_0_OR_NEWER
Expand Down Expand Up @@ -772,6 +772,8 @@ public override void Setup(ScriptableRenderContext context, ref RenderingData re
m_RenderOpaqueForwardPass.ConfigureColorStoreAction(opaquePassColorStoreAction);
m_RenderOpaqueForwardPass.ConfigureDepthStoreAction(opaquePassDepthStoreAction);

m_RenderOpaqueForwardPass.ConfigureClear(ClearFlag.All, Color.black);

EnqueuePass(m_RenderOpaqueForwardPass);
}

Expand Down

0 comments on commit 745f5c8

Please sign in to comment.