Browse Source

Eliminated unnecessary blit to an intermediate temp RT by allowing PPV2 screen space RTs to be created with random write access. This way FSR2 can output directly to the PPV2 effects chain.

stable
Nico de Poel 3 years ago
parent
commit
2e67acb859
  1. 14
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs
  2. 2
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs
  3. 6
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessRenderContext.cs

14
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs

@ -107,7 +107,7 @@ namespace UnityEngine.Rendering.PostProcessing
private Fsr2Context _fsrContext; private Fsr2Context _fsrContext;
private Vector2Int _renderSize; private Vector2Int _renderSize;
private Vector2Int _displaySize; private Vector2Int _displaySize;
private bool _reset;
private bool _resetHistory;
private IFsr2Callbacks _callbacks; private IFsr2Callbacks _callbacks;
private float _appliedBiasOffset; private float _appliedBiasOffset;
@ -138,7 +138,7 @@ namespace UnityEngine.Rendering.PostProcessing
public void ResetHistory() public void ResetHistory()
{ {
_reset = true;
_resetHistory = true;
} }
public void ConfigureJitteredProjectionMatrix(PostProcessRenderContext context) public void ConfigureJitteredProjectionMatrix(PostProcessRenderContext context)
@ -192,15 +192,11 @@ namespace UnityEngine.Rendering.PostProcessing
_dispatchDescription.Reactive = Fsr2ShaderIDs.UavAutoReactive; _dispatchDescription.Reactive = Fsr2ShaderIDs.UavAutoReactive;
} }
cmd.GetTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput, _displaySize.x, _displaySize.y, 0, default, context.sourceFormat, default, 1, true);
_fsrContext.Dispatch(_dispatchDescription, cmd); _fsrContext.Dispatch(_dispatchDescription, cmd);
cmd.BlitFullscreenTriangle(Fsr2ShaderIDs.UavUpscaledOutput, context.destination);
cmd.ReleaseTemporaryRT(Fsr2ShaderIDs.UavUpscaledOutput);
cmd.EndSample("FSR2"); cmd.EndSample("FSR2");
_reset = false;
_resetHistory = false;
} }
private void CreateFsrContext(PostProcessRenderContext context) private void CreateFsrContext(PostProcessRenderContext context)
@ -282,7 +278,7 @@ namespace UnityEngine.Rendering.PostProcessing
if (reactiveMask != null) _dispatchDescription.Reactive = reactiveMask; if (reactiveMask != null) _dispatchDescription.Reactive = reactiveMask;
if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = transparencyAndCompositionMask; if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = transparencyAndCompositionMask;
_dispatchDescription.Output = null;
_dispatchDescription.Output = context.destination;
_dispatchDescription.PreExposure = preExposure; _dispatchDescription.PreExposure = preExposure;
_dispatchDescription.EnableSharpening = performSharpenPass; _dispatchDescription.EnableSharpening = performSharpenPass;
_dispatchDescription.Sharpness = sharpness; _dispatchDescription.Sharpness = sharpness;
@ -295,7 +291,7 @@ namespace UnityEngine.Rendering.PostProcessing
_dispatchDescription.CameraFar = camera.farClipPlane; _dispatchDescription.CameraFar = camera.farClipPlane;
_dispatchDescription.CameraFovAngleVertical = camera.fieldOfView * Mathf.Deg2Rad; _dispatchDescription.CameraFovAngleVertical = camera.fieldOfView * Mathf.Deg2Rad;
_dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity _dispatchDescription.ViewSpaceToMetersFactor = 1.0f; // 1 unit is 1 meter in Unity
_dispatchDescription.Reset = _reset;
_dispatchDescription.Reset = _resetHistory;
_dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition; _dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition;
if (autoGenerateTransparencyAndComposition) if (autoGenerateTransparencyAndComposition)

2
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessLayer.cs

@ -1181,7 +1181,7 @@ namespace UnityEngine.Rendering.PostProcessing
var fsrTarget = m_TargetPool.Get(); var fsrTarget = m_TargetPool.Get();
var finalDestination = context.destination; var finalDestination = context.destination;
context.GetScreenSpaceTemporaryRT(cmd, fsrTarget, 0, context.sourceFormat);
context.GetScreenSpaceTemporaryRT(cmd, fsrTarget, 0, context.sourceFormat, enableRandomWrite: true);
context.destination = fsrTarget; context.destination = fsrTarget;
superResolution.colorOpaqueOnly = m_opaqueOnly; superResolution.colorOpaqueOnly = m_opaqueOnly;
superResolution.Render(context); superResolution.Render(context);

6
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/PostProcessRenderContext.cs

@ -372,9 +372,10 @@ namespace UnityEngine.Rendering.PostProcessing
/// <param name="filter">The texture filtering mode</param> /// <param name="filter">The texture filtering mode</param>
/// <param name="widthOverride">Override the display width; use <c>0</c> to disable the override</param> /// <param name="widthOverride">Override the display width; use <c>0</c> to disable the override</param>
/// <param name="heightOverride">Override the display height; use <c>0</c> to disable the override</param> /// <param name="heightOverride">Override the display height; use <c>0</c> to disable the override</param>
/// <param name="enableRandomWrite">Enable random access write into this render texture</param>
public void GetScreenSpaceTemporaryRT(CommandBuffer cmd, int nameID, public void GetScreenSpaceTemporaryRT(CommandBuffer cmd, int nameID,
int depthBufferBits = 0, RenderTextureFormat colorFormat = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default, int depthBufferBits = 0, RenderTextureFormat colorFormat = RenderTextureFormat.Default, RenderTextureReadWrite readWrite = RenderTextureReadWrite.Default,
FilterMode filter = FilterMode.Bilinear, int widthOverride = 0, int heightOverride = 0)
FilterMode filter = FilterMode.Bilinear, int widthOverride = 0, int heightOverride = 0, bool enableRandomWrite = false)
{ {
var desc = GetDescriptor(depthBufferBits, colorFormat, readWrite); var desc = GetDescriptor(depthBufferBits, colorFormat, readWrite);
if (widthOverride > 0) if (widthOverride > 0)
@ -386,6 +387,9 @@ namespace UnityEngine.Rendering.PostProcessing
if (stereoActive && desc.dimension == Rendering.TextureDimension.Tex2DArray) if (stereoActive && desc.dimension == Rendering.TextureDimension.Tex2DArray)
desc.dimension = Rendering.TextureDimension.Tex2D; desc.dimension = Rendering.TextureDimension.Tex2D;
if (enableRandomWrite)
desc.enableRandomWrite = true;
#if UNITY_2019_1_OR_NEWER #if UNITY_2019_1_OR_NEWER
cmd.GetTemporaryRT(nameID, desc, filter); cmd.GetTemporaryRT(nameID, desc, filter);
#elif UNITY_2017_3_OR_NEWER #elif UNITY_2017_3_OR_NEWER

Loading…
Cancel
Save