diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs
index 9a8b187..6d08112 100644
--- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs
+++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs
@@ -266,9 +266,9 @@ namespace UnityEngine.Rendering.PostProcessing
_dispatchDescription.Color = new Fsr2.RenderTargetView(context.source);
_dispatchDescription.Depth = new Fsr2.RenderTargetView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth);
_dispatchDescription.MotionVectors = new Fsr2.RenderTargetView(BuiltinRenderTextureType.MotionVectors);
- _dispatchDescription.Exposure = null;
- _dispatchDescription.Reactive = null;
- _dispatchDescription.TransparencyAndComposition = null;
+ _dispatchDescription.Exposure = Fsr2.RenderTargetView.Empty;
+ _dispatchDescription.Reactive = Fsr2.RenderTargetView.Empty;
+ _dispatchDescription.TransparencyAndComposition = Fsr2.RenderTargetView.Empty;
if (exposureSource == ExposureSource.Manual && exposure != null) _dispatchDescription.Exposure = new Fsr2.RenderTargetView(exposure);
if (exposureSource == ExposureSource.Unity) _dispatchDescription.Exposure = new Fsr2.RenderTargetView(context.autoExposureTexture);
diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs
index 59cb113..9866358 100644
--- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs
+++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs
@@ -125,6 +125,13 @@ namespace FidelityFX
return Mathf.Abs(value) < Mathf.Epsilon ? 1.0f : Mathf.Sin(Mathf.PI * value) / (Mathf.PI * value) * (Mathf.Sin(0.5f * Mathf.PI * value) / (0.5f * Mathf.PI * value));
}
+#if !UNITY_2021_1_OR_NEWER
+ internal static void SetBufferData(this CommandBuffer commandBuffer, ComputeBuffer computeBuffer, Array data)
+ {
+ commandBuffer.SetComputeBufferData(computeBuffer, data);
+ }
+#endif
+
public enum QualityMode
{
UltraQuality = 0,
@@ -157,34 +164,37 @@ namespace FidelityFX
}
///
- /// A structure wrapping all of the necessary information to bind a specific buffer or attachment of a render target to a compute shader.
+ /// An immutable structure wrapping all of the necessary information to bind a specific buffer or attachment of a render target to a compute shader.
///
- public struct RenderTargetView
+ public readonly struct RenderTargetView
{
+ public static readonly RenderTargetView Empty = new RenderTargetView(default);
+
public RenderTargetView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0)
{
RenderTarget = renderTarget;
SubElement = subElement;
MipLevel = mipLevel;
}
-
+
+ public bool IsEmpty => RenderTarget.Equals(default);
+
public readonly RenderTargetIdentifier RenderTarget;
public readonly RenderTextureSubElement SubElement;
public readonly int MipLevel;
}
///
- /// The input and output resources are all optional. If they are null, the Fsr2Context won't try to bind them to any shaders.
- /// This allows for customized and more efficient resource management outside of Fsr2Context, tailored to the specific scenario.
+ /// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 2.
///
public class DispatchDescription
{
public RenderTargetView Color;
public RenderTargetView Depth;
public RenderTargetView MotionVectors;
- public RenderTargetView? Exposure;
- public RenderTargetView? Reactive;
- public RenderTargetView? TransparencyAndComposition;
+ public RenderTargetView Exposure; // optional
+ public RenderTargetView Reactive; // optional
+ public RenderTargetView TransparencyAndComposition; // optional
public RenderTargetView Output;
public Vector2 JitterOffset;
public Vector2 MotionVectorScale;
@@ -202,7 +212,7 @@ namespace FidelityFX
// EXPERIMENTAL reactive mask generation parameters
public bool EnableAutoReactive;
- public RenderTargetView? ColorOpaqueOnly;
+ public RenderTargetView ColorOpaqueOnly;
public float AutoTcThreshold = 0.05f;
public float AutoTcScale = 1.0f;
public float AutoReactiveScale = 5.0f;
@@ -210,6 +220,7 @@ namespace FidelityFX
}
///
+ /// A structure encapsulating the parameters for automatic generation of a reactive mask.
/// The default values for Scale, CutoffThreshold, BinaryValue and Flags were taken from the FSR2 demo project.
///
public class GenerateReactiveDescription
diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs
index 610f469..ec3b38f 100644
--- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs
+++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs
@@ -159,7 +159,7 @@ namespace FidelityFX
// If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends
if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0)
dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.AutoExposure);
- else if (dispatchParams.Exposure == null)
+ else if (dispatchParams.Exposure.IsEmpty)
dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.DefaultExposure);
if (dispatchParams.EnableAutoReactive)
@@ -169,7 +169,10 @@ namespace FidelityFX
_resources.CreateTcrAutogenResources(_contextDescription);
if (resetAccumulation)
- commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], (dispatchParams.ColorOpaqueOnly ?? new Fsr2.RenderTargetView(Fsr2ShaderIDs.SrvOpaqueOnly)).RenderTarget);
+ {
+ RenderTargetIdentifier opaqueOnly = dispatchParams.ColorOpaqueOnly.IsEmpty ? Fsr2ShaderIDs.SrvOpaqueOnly : dispatchParams.ColorOpaqueOnly.RenderTarget;
+ commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], opaqueOnly);
+ }
}
else if (_resources.AutoReactive != null)
{
@@ -177,8 +180,8 @@ namespace FidelityFX
_resources.DestroyTcrAutogenResources();
}
- if (dispatchParams.Reactive == null) dispatchParams.Reactive = new Fsr2.RenderTargetView(_resources.DefaultReactive);
- if (dispatchParams.TransparencyAndComposition == null) dispatchParams.TransparencyAndComposition = new Fsr2.RenderTargetView(_resources.DefaultReactive);
+ if (dispatchParams.Reactive.IsEmpty) dispatchParams.Reactive = new Fsr2.RenderTargetView(_resources.DefaultReactive);
+ if (dispatchParams.TransparencyAndComposition.IsEmpty) dispatchParams.TransparencyAndComposition = new Fsr2.RenderTargetView(_resources.DefaultReactive);
Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams);
SetupConstants(dispatchParams, resetAccumulation);
@@ -433,7 +436,27 @@ namespace FidelityFX
private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams)
{
- if (dispatchParams.Exposure.HasValue && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0)
+ if (dispatchParams.Color.IsEmpty)
+ {
+ Debug.LogError("Color resource is null");
+ }
+
+ if (dispatchParams.Depth.IsEmpty)
+ {
+ Debug.LogError("Depth resource is null");
+ }
+
+ if (dispatchParams.MotionVectors.IsEmpty)
+ {
+ Debug.LogError("MotionVectors resource is null");
+ }
+
+ if (dispatchParams.Output.IsEmpty)
+ {
+ Debug.LogError("Output resource is null");
+ }
+
+ if (!dispatchParams.Exposure.IsEmpty && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0)
{
Debug.LogWarning("Exposure resource provided, however auto exposure flag is present");
}
diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Pipeline.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Pipeline.cs
index 4b00278..c0aafd8 100644
--- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Pipeline.cs
+++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Pipeline.cs
@@ -157,16 +157,12 @@ namespace FidelityFX
ref var color = ref dispatchParams.Color;
ref var depth = ref dispatchParams.Depth;
ref var motionVectors = ref dispatchParams.MotionVectors;
+ ref var exposure = ref dispatchParams.Exposure;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement);
-
- if (dispatchParams.Exposure.HasValue)
- {
- var exposure = dispatchParams.Exposure.Value;
- commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
- }
+ commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]);
@@ -189,28 +185,16 @@ namespace FidelityFX
ref var color = ref dispatchParams.Color;
ref var depth = ref dispatchParams.Depth;
ref var motionVectors = ref dispatchParams.MotionVectors;
+ ref var exposure = ref dispatchParams.Exposure;
+ ref var reactive = ref dispatchParams.Reactive;
+ ref var tac = ref dispatchParams.TransparencyAndComposition;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputDepth, depth.RenderTarget, depth.MipLevel, depth.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement);
-
- if (dispatchParams.Exposure.HasValue)
- {
- var exposure = dispatchParams.Exposure.Value;
- commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
- }
-
- if (dispatchParams.Reactive.HasValue)
- {
- var reactive = dispatchParams.Reactive.Value;
- commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement);
- }
-
- if (dispatchParams.TransparencyAndComposition.HasValue)
- {
- var tac = dispatchParams.TransparencyAndComposition.Value;
- commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement);
- }
+ commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
+ commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement);
+ commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReconstructedPrevNearestDepth, Fsr2ShaderIDs.UavReconstructedPrevNearestDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]);
@@ -284,11 +268,8 @@ namespace FidelityFX
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement);
}
- if (dispatchParams.Exposure.HasValue)
- {
- var exposure = dispatchParams.Exposure.Value;
- commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
- }
+ ref var exposure = ref dispatchParams.Exposure;
+ commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedReactiveMasks, Fsr2ShaderIDs.UavDilatedReactiveMasks);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInternalUpscaled, Resources.InternalUpscaled[frameIndex ^ 1]);
@@ -327,12 +308,8 @@ namespace FidelityFX
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
- if (dispatchParams.Exposure.HasValue)
- {
- var exposure = dispatchParams.Exposure.Value;
- commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
- }
-
+ ref var exposure = ref dispatchParams.Exposure;
+ commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputExposure, exposure.RenderTarget, exposure.MipLevel, exposure.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvRcasInput, Resources.InternalUpscaled[frameIndex]);
ref var output = ref dispatchParams.Output;
@@ -391,31 +368,19 @@ namespace FidelityFX
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
- if (dispatchParams.ColorOpaqueOnly.HasValue)
- {
- var opaqueOnly = dispatchParams.ColorOpaqueOnly.Value;
- commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement);
- }
-
ref var color = ref dispatchParams.Color;
ref var motionVectors = ref dispatchParams.MotionVectors;
+ ref var opaqueOnly = ref dispatchParams.ColorOpaqueOnly;
+ ref var reactive = ref dispatchParams.Reactive;
+ ref var tac = ref dispatchParams.TransparencyAndComposition;
+
+ commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvOpaqueOnly, opaqueOnly.RenderTarget, opaqueOnly.MipLevel, opaqueOnly.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputColor, color.RenderTarget, color.MipLevel, color.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvInputMotionVectors, motionVectors.RenderTarget, motionVectors.MipLevel, motionVectors.SubElement);
-
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex ^ 1]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex ^ 1]);
-
- if (dispatchParams.Reactive.HasValue)
- {
- var reactive = dispatchParams.Reactive.Value;
- commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement);
- }
-
- if (dispatchParams.TransparencyAndComposition.HasValue)
- {
- var tac = dispatchParams.TransparencyAndComposition.Value;
- commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement);
- }
+ commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvReactiveMask, reactive.RenderTarget, reactive.MipLevel, reactive.SubElement);
+ commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvTransparencyAndCompositionMask, tac.RenderTarget, tac.MipLevel, tac.SubElement);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoReactive, Resources.AutoReactive);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoComposition, Resources.AutoComposition);