Browse Source

Renamed RenderTargetView to ResourceView, which is a bit shorter to type and captures the essence well.

fsr2
Nico de Poel 2 years ago
parent
commit
8c7aeae4a7
  1. 34
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/SuperResolution.cs
  2. 40
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs
  3. 26
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs

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

@ -187,7 +187,7 @@ namespace UnityEngine.Rendering.PostProcessing
var scaledRenderSize = _genReactiveDescription.RenderSize; var scaledRenderSize = _genReactiveDescription.RenderSize;
cmd.GetTemporaryRT(Fsr2ShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true); cmd.GetTemporaryRT(Fsr2ShaderIDs.UavAutoReactive, scaledRenderSize.x, scaledRenderSize.y, 0, default, GraphicsFormat.R8_UNorm, 1, true);
_fsrContext.GenerateReactiveMask(_genReactiveDescription, cmd); _fsrContext.GenerateReactiveMask(_genReactiveDescription, cmd);
_dispatchDescription.Reactive = new Fsr2.RenderTargetView(Fsr2ShaderIDs.UavAutoReactive);
_dispatchDescription.Reactive = new Fsr2.ResourceView(Fsr2ShaderIDs.UavAutoReactive);
} }
_fsrContext.Dispatch(_dispatchDescription, cmd); _fsrContext.Dispatch(_dispatchDescription, cmd);
@ -263,21 +263,21 @@ namespace UnityEngine.Rendering.PostProcessing
var camera = context.camera; var camera = context.camera;
// Set up the main FSR2 dispatch parameters // Set up the main FSR2 dispatch parameters
_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 = 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);
if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr2.RenderTargetView(reactiveMask);
if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = new Fsr2.RenderTargetView(transparencyAndCompositionMask);
_dispatchDescription.Color = new Fsr2.ResourceView(context.source);
_dispatchDescription.Depth = new Fsr2.ResourceView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth);
_dispatchDescription.MotionVectors = new Fsr2.ResourceView(BuiltinRenderTextureType.MotionVectors);
_dispatchDescription.Exposure = Fsr2.ResourceView.Unassigned;
_dispatchDescription.Reactive = Fsr2.ResourceView.Unassigned;
_dispatchDescription.TransparencyAndComposition = Fsr2.ResourceView.Unassigned;
if (exposureSource == ExposureSource.Manual && exposure != null) _dispatchDescription.Exposure = new Fsr2.ResourceView(exposure);
if (exposureSource == ExposureSource.Unity) _dispatchDescription.Exposure = new Fsr2.ResourceView(context.autoExposureTexture);
if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr2.ResourceView(reactiveMask);
if (transparencyAndCompositionMask != null) _dispatchDescription.TransparencyAndComposition = new Fsr2.ResourceView(transparencyAndCompositionMask);
var scaledRenderSize = GetScaledRenderSize(context.camera); var scaledRenderSize = GetScaledRenderSize(context.camera);
_dispatchDescription.Output = new Fsr2.RenderTargetView(context.destination);
_dispatchDescription.Output = new Fsr2.ResourceView(context.destination);
_dispatchDescription.PreExposure = preExposure; _dispatchDescription.PreExposure = preExposure;
_dispatchDescription.EnableSharpening = performSharpenPass; _dispatchDescription.EnableSharpening = performSharpenPass;
_dispatchDescription.Sharpness = sharpness; _dispatchDescription.Sharpness = sharpness;
@ -296,7 +296,7 @@ namespace UnityEngine.Rendering.PostProcessing
_dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition; _dispatchDescription.EnableAutoReactive = autoGenerateTransparencyAndComposition;
if (autoGenerateTransparencyAndComposition) if (autoGenerateTransparencyAndComposition)
{ {
_dispatchDescription.ColorOpaqueOnly = new Fsr2.RenderTargetView(colorOpaqueOnly);
_dispatchDescription.ColorOpaqueOnly = new Fsr2.ResourceView(colorOpaqueOnly);
_dispatchDescription.AutoTcThreshold = generateTransparencyAndCompositionParameters.autoTcThreshold; _dispatchDescription.AutoTcThreshold = generateTransparencyAndCompositionParameters.autoTcThreshold;
_dispatchDescription.AutoTcScale = generateTransparencyAndCompositionParameters.autoTcScale; _dispatchDescription.AutoTcScale = generateTransparencyAndCompositionParameters.autoTcScale;
_dispatchDescription.AutoReactiveScale = generateTransparencyAndCompositionParameters.autoReactiveScale; _dispatchDescription.AutoReactiveScale = generateTransparencyAndCompositionParameters.autoReactiveScale;
@ -313,9 +313,9 @@ namespace UnityEngine.Rendering.PostProcessing
private void SetupAutoReactiveDescription(PostProcessRenderContext context) private void SetupAutoReactiveDescription(PostProcessRenderContext context)
{ {
// Set up the parameters to auto-generate a reactive mask // Set up the parameters to auto-generate a reactive mask
_genReactiveDescription.ColorOpaqueOnly = new Fsr2.RenderTargetView(colorOpaqueOnly);
_genReactiveDescription.ColorPreUpscale = new Fsr2.RenderTargetView(context.source);
_genReactiveDescription.OutReactive = new Fsr2.RenderTargetView(Fsr2ShaderIDs.UavAutoReactive);
_genReactiveDescription.ColorOpaqueOnly = new Fsr2.ResourceView(colorOpaqueOnly);
_genReactiveDescription.ColorPreUpscale = new Fsr2.ResourceView(context.source);
_genReactiveDescription.OutReactive = new Fsr2.ResourceView(Fsr2ShaderIDs.UavAutoReactive);
_genReactiveDescription.RenderSize = GetScaledRenderSize(context.camera); _genReactiveDescription.RenderSize = GetScaledRenderSize(context.camera);
_genReactiveDescription.Scale = generateReactiveParameters.scale; _genReactiveDescription.Scale = generateReactiveParameters.scale;
_genReactiveDescription.CutoffThreshold = generateReactiveParameters.cutoffThreshold; _genReactiveDescription.CutoffThreshold = generateReactiveParameters.cutoffThreshold;

40
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2.cs

@ -166,18 +166,28 @@ namespace FidelityFX
/// <summary> /// <summary>
/// An immutable 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.
/// </summary> /// </summary>
public readonly struct RenderTargetView
public readonly struct ResourceView
{ {
public static readonly RenderTargetView Empty = new RenderTargetView(default);
/// <summary>
/// This value is the equivalent of not setting any value at all; all struct fields will have their default values.
/// It does not refer to a valid texture, therefore any variable set to this value should be checked for IsValid and reassigned before being bound to a shader.
/// </summary>
public static readonly ResourceView Unassigned = new ResourceView(default);
/// <summary>
/// This value contains a valid texture reference that can be bound to a shader, however it is just an empty placeholder texture.
/// Binding this to a shader can be seen as setting the texture variable inside the shader to null.
/// </summary>
public static readonly ResourceView None = new ResourceView(BuiltinRenderTextureType.None);
public RenderTargetView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0)
public ResourceView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0)
{ {
RenderTarget = renderTarget; RenderTarget = renderTarget;
SubElement = subElement; SubElement = subElement;
MipLevel = mipLevel; MipLevel = mipLevel;
} }
public bool IsEmpty => RenderTarget.Equals(default);
public bool IsValid => !RenderTarget.Equals(default);
public readonly RenderTargetIdentifier RenderTarget; public readonly RenderTargetIdentifier RenderTarget;
public readonly RenderTextureSubElement SubElement; public readonly RenderTextureSubElement SubElement;
@ -189,13 +199,13 @@ namespace FidelityFX
/// </summary> /// </summary>
public class DispatchDescription public class DispatchDescription
{ {
public RenderTargetView Color;
public RenderTargetView Depth;
public RenderTargetView MotionVectors;
public RenderTargetView Exposure; // optional
public RenderTargetView Reactive; // optional
public RenderTargetView TransparencyAndComposition; // optional
public RenderTargetView Output;
public ResourceView Color;
public ResourceView Depth;
public ResourceView MotionVectors;
public ResourceView Exposure; // optional
public ResourceView Reactive; // optional
public ResourceView TransparencyAndComposition; // optional
public ResourceView Output;
public Vector2 JitterOffset; public Vector2 JitterOffset;
public Vector2 MotionVectorScale; public Vector2 MotionVectorScale;
public Vector2Int RenderSize; public Vector2Int RenderSize;
@ -212,7 +222,7 @@ namespace FidelityFX
// EXPERIMENTAL reactive mask generation parameters // EXPERIMENTAL reactive mask generation parameters
public bool EnableAutoReactive; public bool EnableAutoReactive;
public RenderTargetView ColorOpaqueOnly;
public ResourceView ColorOpaqueOnly;
public float AutoTcThreshold = 0.05f; public float AutoTcThreshold = 0.05f;
public float AutoTcScale = 1.0f; public float AutoTcScale = 1.0f;
public float AutoReactiveScale = 5.0f; public float AutoReactiveScale = 5.0f;
@ -225,9 +235,9 @@ namespace FidelityFX
/// </summary> /// </summary>
public class GenerateReactiveDescription public class GenerateReactiveDescription
{ {
public RenderTargetView ColorOpaqueOnly;
public RenderTargetView ColorPreUpscale;
public RenderTargetView OutReactive;
public ResourceView ColorOpaqueOnly;
public ResourceView ColorPreUpscale;
public ResourceView OutReactive;
public Vector2Int RenderSize; public Vector2Int RenderSize;
public float Scale = 0.5f; public float Scale = 0.5f;
public float CutoffThreshold = 0.2f; public float CutoffThreshold = 0.2f;

26
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/FSR2/Fsr2Context.cs

@ -158,9 +158,9 @@ namespace FidelityFX
// If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends // If auto exposure is enabled use the auto exposure SRV, otherwise what the app sends
if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0) if ((_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0)
dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.AutoExposure);
else if (dispatchParams.Exposure.IsEmpty)
dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.DefaultExposure);
dispatchParams.Exposure = new Fsr2.ResourceView(_resources.AutoExposure);
else if (!dispatchParams.Exposure.IsValid)
dispatchParams.Exposure = new Fsr2.ResourceView(_resources.DefaultExposure);
if (dispatchParams.EnableAutoReactive) if (dispatchParams.EnableAutoReactive)
{ {
@ -170,7 +170,7 @@ namespace FidelityFX
if (resetAccumulation) if (resetAccumulation)
{ {
RenderTargetIdentifier opaqueOnly = dispatchParams.ColorOpaqueOnly.IsEmpty ? Fsr2ShaderIDs.SrvOpaqueOnly : dispatchParams.ColorOpaqueOnly.RenderTarget;
RenderTargetIdentifier opaqueOnly = dispatchParams.ColorOpaqueOnly.IsValid ? dispatchParams.ColorOpaqueOnly.RenderTarget : Fsr2ShaderIDs.SrvOpaqueOnly;
commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], opaqueOnly); commandBuffer.Blit(_resources.PrevPreAlpha[frameIndex ^ 1], opaqueOnly);
} }
} }
@ -180,8 +180,8 @@ namespace FidelityFX
_resources.DestroyTcrAutogenResources(); _resources.DestroyTcrAutogenResources();
} }
if (dispatchParams.Reactive.IsEmpty) dispatchParams.Reactive = new Fsr2.RenderTargetView(_resources.DefaultReactive);
if (dispatchParams.TransparencyAndComposition.IsEmpty) dispatchParams.TransparencyAndComposition = new Fsr2.RenderTargetView(_resources.DefaultReactive);
if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new Fsr2.ResourceView(_resources.DefaultReactive);
if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new Fsr2.ResourceView(_resources.DefaultReactive);
Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams);
SetupConstants(dispatchParams, resetAccumulation); SetupConstants(dispatchParams, resetAccumulation);
@ -225,8 +225,8 @@ namespace FidelityFX
if (dispatchParams.EnableAutoReactive) if (dispatchParams.EnableAutoReactive)
{ {
GenerateTransparencyCompositionReactive(dispatchParams, commandBuffer, frameIndex); GenerateTransparencyCompositionReactive(dispatchParams, commandBuffer, frameIndex);
dispatchParams.Reactive = new Fsr2.RenderTargetView(_resources.AutoReactive);
dispatchParams.TransparencyAndComposition = new Fsr2.RenderTargetView(_resources.AutoComposition);
dispatchParams.Reactive = new Fsr2.ResourceView(_resources.AutoReactive);
dispatchParams.TransparencyAndComposition = new Fsr2.ResourceView(_resources.AutoComposition);
} }
// Compute luminance pyramid // Compute luminance pyramid
@ -436,27 +436,27 @@ namespace FidelityFX
private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams) private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams)
{ {
if (dispatchParams.Color.IsEmpty)
if (!dispatchParams.Color.IsValid)
{ {
Debug.LogError("Color resource is null"); Debug.LogError("Color resource is null");
} }
if (dispatchParams.Depth.IsEmpty)
if (!dispatchParams.Depth.IsValid)
{ {
Debug.LogError("Depth resource is null"); Debug.LogError("Depth resource is null");
} }
if (dispatchParams.MotionVectors.IsEmpty)
if (!dispatchParams.MotionVectors.IsValid)
{ {
Debug.LogError("MotionVectors resource is null"); Debug.LogError("MotionVectors resource is null");
} }
if (dispatchParams.Output.IsEmpty)
if (!dispatchParams.Output.IsValid)
{ {
Debug.LogError("Output resource is null"); Debug.LogError("Output resource is null");
} }
if (!dispatchParams.Exposure.IsEmpty && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0)
if (dispatchParams.Exposure.IsValid && (_contextDescription.Flags & Fsr2.InitializationFlags.EnableAutoExposure) != 0)
{ {
Debug.LogWarning("Exposure resource provided, however auto exposure flag is present"); Debug.LogWarning("Exposure resource provided, however auto exposure flag is present");
} }

Loading…
Cancel
Save