From ea05e5da58478a18c9561bf5d3faf344ecb52776 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Tue, 30 May 2023 14:59:17 +0200 Subject: [PATCH] Perform OnRenderImage blit using an explicit temporary RT for the upscaled output. This can be blitted directly instead of needing an awkward command buffer, and it'll be less likely to cause issues than blitting from and to the same display buffer. --- .../PostProcessing/Runtime/PostProcessLayer.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs index 15e3774..9eb8ad2 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs @@ -210,11 +210,12 @@ namespace UnityEngine.Rendering.PostProcessing CommandBuffer m_LegacyCmdBufferBeforeLighting; CommandBuffer m_LegacyCmdBufferOpaque; CommandBuffer m_LegacyCmdBuffer; - CommandBuffer m_BlitCmdBuffer; Camera m_Camera; PostProcessRenderContext m_CurrentContext; LogHistogram m_LogHistogram; + RenderTexture m_upscaledOutput; + bool m_SettingsUpdateNeeded = true; bool m_IsRenderingInSceneView = false; @@ -252,7 +253,6 @@ namespace UnityEngine.Rendering.PostProcessing m_LegacyCmdBufferBeforeLighting = new CommandBuffer { name = "Deferred Ambient Occlusion" }; m_LegacyCmdBufferOpaque = new CommandBuffer { name = "Opaque Only Post-processing" }; m_LegacyCmdBuffer = new CommandBuffer { name = "Post-processing" }; - m_BlitCmdBuffer = new CommandBuffer { name = "Backbuffer blit" }; m_Camera = GetComponent(); @@ -286,10 +286,8 @@ namespace UnityEngine.Rendering.PostProcessing if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive()) { // Blit the upscaled image to the backbuffer - m_BlitCmdBuffer.Blit(m_CurrentContext.destination, dst); - Graphics.ExecuteCommandBuffer(m_BlitCmdBuffer); - - RenderTexture.active = dst; + Graphics.Blit(m_upscaledOutput, dst); + m_upscaledOutput.Release(); return; } @@ -584,7 +582,6 @@ namespace UnityEngine.Rendering.PostProcessing m_LegacyCmdBufferBeforeLighting.Clear(); m_LegacyCmdBufferOpaque.Clear(); m_LegacyCmdBuffer.Clear(); - m_BlitCmdBuffer.Clear(); SetupContext(context); @@ -716,9 +713,9 @@ namespace UnityEngine.Rendering.PostProcessing if (!finalBlitToCameraTarget && m_CurrentContext.IsSuperResolutionActive()) { - // Use the main display buffer for temporarily storing the upscaled full-resolution image - context.flip = true; - context.destination = Display.main.colorBuffer; + var displaySize = superResolution.displaySize; + m_upscaledOutput = context.GetScreenSpaceTemporaryRT(widthOverride: displaySize.x, heightOverride: displaySize.y); + context.destination = m_upscaledOutput; } #if UNITY_2019_1_OR_NEWER