Browse Source

Modified RenderTargetView yet again: made a distinction between an invalid (Unassigned) texture reference and a valid-but-empty (None) texture reference. Inverted IsEmpty as well to be a more generic IsValid property now.

master
Nico de Poel 2 years ago
parent
commit
d9f9ef10ff
  1. 14
      Assets/Scripts/Core/Fsr2.cs
  2. 18
      Assets/Scripts/Core/Fsr2Context.cs
  3. 6
      Assets/Scripts/Fsr2ImageEffect.cs

14
Assets/Scripts/Core/Fsr2.cs

@ -168,7 +168,17 @@ namespace FidelityFX
/// </summary> /// </summary>
public readonly struct RenderTargetView public readonly struct RenderTargetView
{ {
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 RenderTargetView Unassigned = new RenderTargetView(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 RenderTargetView None = new RenderTargetView(BuiltinRenderTextureType.None);
public RenderTargetView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0) public RenderTargetView(in RenderTargetIdentifier renderTarget, RenderTextureSubElement subElement = RenderTextureSubElement.Default, int mipLevel = 0)
{ {
@ -177,7 +187,7 @@ namespace FidelityFX
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;

18
Assets/Scripts/Core/Fsr2Context.cs

@ -159,7 +159,7 @@ 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); dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.AutoExposure);
else if (dispatchParams.Exposure.IsEmpty)
else if (!dispatchParams.Exposure.IsValid)
dispatchParams.Exposure = new Fsr2.RenderTargetView(_resources.DefaultExposure); dispatchParams.Exposure = new Fsr2.RenderTargetView(_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.RenderTargetView(_resources.DefaultReactive);
if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new Fsr2.RenderTargetView(_resources.DefaultReactive);
Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams); Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams);
SetupConstants(dispatchParams, resetAccumulation); SetupConstants(dispatchParams, resetAccumulation);
@ -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");
} }

6
Assets/Scripts/Fsr2ImageEffect.cs

@ -328,9 +328,9 @@ namespace FidelityFX
_dispatchDescription.Color = new Fsr2.RenderTargetView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Color); _dispatchDescription.Color = new Fsr2.RenderTargetView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Color);
_dispatchDescription.Depth = new Fsr2.RenderTargetView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth); _dispatchDescription.Depth = new Fsr2.RenderTargetView(BuiltinRenderTextureType.CameraTarget, RenderTextureSubElement.Depth);
_dispatchDescription.MotionVectors = new Fsr2.RenderTargetView(BuiltinRenderTextureType.MotionVectors); _dispatchDescription.MotionVectors = new Fsr2.RenderTargetView(BuiltinRenderTextureType.MotionVectors);
_dispatchDescription.Exposure = Fsr2.RenderTargetView.Empty;
_dispatchDescription.Reactive = Fsr2.RenderTargetView.Empty;
_dispatchDescription.TransparencyAndComposition = Fsr2.RenderTargetView.Empty;
_dispatchDescription.Exposure = Fsr2.RenderTargetView.Unassigned;
_dispatchDescription.Reactive = Fsr2.RenderTargetView.Unassigned;
_dispatchDescription.TransparencyAndComposition = Fsr2.RenderTargetView.Unassigned;
if (!enableAutoExposure && exposure != null) _dispatchDescription.Exposure = new Fsr2.RenderTargetView(exposure); if (!enableAutoExposure && exposure != null) _dispatchDescription.Exposure = new Fsr2.RenderTargetView(exposure);
if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr2.RenderTargetView(reactiveMask); if (reactiveMask != null) _dispatchDescription.Reactive = new Fsr2.RenderTargetView(reactiveMask);

Loading…
Cancel
Save