Browse Source

Merge branch 'framework' into fsr3framegen

fsr3framegen
Nico de Poel 2 years ago
parent
commit
2bb45ffb76
  1. 36
      Runtime/FSR2/Fsr2.cs
  2. 42
      Runtime/FSR2/Fsr2Context.cs
  3. 6
      Runtime/FSR2/Fsr2Resources.cs
  4. 36
      Runtime/FSR3/Fsr3Upscaler.cs
  5. 48
      Runtime/FSR3/Fsr3UpscalerContext.cs
  6. 6
      Runtime/FSR3/Fsr3UpscalerResources.cs

36
Runtime/FSR2/Fsr2.cs

@ -127,7 +127,7 @@ namespace FidelityFX.FSR2
/// <summary> /// <summary>
/// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 2. /// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 2.
/// </summary> /// </summary>
public class DispatchDescription
public struct DispatchDescription
{ {
public ResourceView Color; public ResourceView Color;
public ResourceView Depth; public ResourceView Depth;
@ -154,26 +154,42 @@ namespace FidelityFX.FSR2
// EXPERIMENTAL reactive mask generation parameters // EXPERIMENTAL reactive mask generation parameters
public bool EnableAutoReactive; public bool EnableAutoReactive;
public ResourceView ColorOpaqueOnly; public ResourceView ColorOpaqueOnly;
public float AutoTcThreshold = 0.05f;
public float AutoTcScale = 1.0f;
public float AutoReactiveScale = 5.0f;
public float AutoReactiveMax = 0.9f;
public float AutoTcThreshold;
public float AutoTcScale;
public float AutoReactiveScale;
public float AutoReactiveMax;
public static readonly DispatchDescription Default = new DispatchDescription
{
AutoTcThreshold = 0.05f,
AutoTcScale = 1.0f,
AutoReactiveScale = 5.0f,
AutoReactiveMax = 0.9f,
};
} }
/// <summary> /// <summary>
/// A structure encapsulating the parameters for automatic generation of a reactive mask. /// 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. /// The default values for Scale, CutoffThreshold, BinaryValue and Flags were taken from the FSR2 demo project.
/// </summary> /// </summary>
public class GenerateReactiveDescription
public struct GenerateReactiveDescription
{ {
public ResourceView ColorOpaqueOnly; public ResourceView ColorOpaqueOnly;
public ResourceView ColorPreUpscale; public ResourceView ColorPreUpscale;
public ResourceView OutReactive; public ResourceView OutReactive;
public Vector2Int RenderSize; public Vector2Int RenderSize;
public float Scale = 0.5f;
public float CutoffThreshold = 0.2f;
public float BinaryValue = 0.9f;
public GenerateReactiveFlags Flags = GenerateReactiveFlags.ApplyTonemap | GenerateReactiveFlags.ApplyThreshold | GenerateReactiveFlags.UseComponentsMax;
public float Scale;
public float CutoffThreshold;
public float BinaryValue;
public GenerateReactiveFlags Flags;
public static readonly GenerateReactiveDescription Default = new GenerateReactiveDescription
{
Scale = 0.5f,
CutoffThreshold = 0.2f,
BinaryValue = 0.9f,
Flags = GenerateReactiveFlags.ApplyTonemap | GenerateReactiveFlags.ApplyThreshold | GenerateReactiveFlags.UseComponentsMax,
};
} }
[Flags] [Flags]

42
Runtime/FSR2/Fsr2Context.cs

@ -38,14 +38,14 @@ namespace FidelityFX.FSR2
private Fsr2.ContextDescription _contextDescription; private Fsr2.ContextDescription _contextDescription;
private CommandBuffer _commandBuffer; private CommandBuffer _commandBuffer;
private Fsr2Pass _computeLuminancePyramidPass;
private Fsr2Pass _reconstructPreviousDepthPass;
private Fsr2Pass _depthClipPass;
private Fsr2Pass _lockPass;
private Fsr2Pass _accumulatePass;
private Fsr2Pass _sharpenPass;
private Fsr2Pass _generateReactivePass;
private Fsr2Pass _tcrAutogeneratePass;
private Fsr2ComputeLuminancePyramidPass _computeLuminancePyramidPass;
private Fsr2ReconstructPreviousDepthPass _reconstructPreviousDepthPass;
private Fsr2DepthClipPass _depthClipPass;
private Fsr2LockPass _lockPass;
private Fsr2AccumulatePass _accumulatePass;
private Fsr2SharpenPass _sharpenPass;
private Fsr2GenerateReactivePass _generateReactivePass;
private Fsr2TcrAutogeneratePass _tcrAutogeneratePass;
private readonly Fsr2Resources _resources = new Fsr2Resources(); private readonly Fsr2Resources _resources = new Fsr2Resources();
@ -61,7 +61,7 @@ namespace FidelityFX.FSR2
private readonly CustomSampler _sampler = CustomSampler.Create("FSR2"); private readonly CustomSampler _sampler = CustomSampler.Create("FSR2");
public void Create(Fsr2.ContextDescription contextDescription)
public void Create(in Fsr2.ContextDescription contextDescription)
{ {
_contextDescription = contextDescription; _contextDescription = contextDescription;
_commandBuffer = new CommandBuffer { name = "FSR2" }; _commandBuffer = new CommandBuffer { name = "FSR2" };
@ -120,7 +120,7 @@ namespace FidelityFX.FSR2
} }
} }
public void Dispatch(Fsr2.DispatchDescription dispatchParams)
public void Dispatch(in Fsr2.DispatchDescription dispatchParams)
{ {
_commandBuffer.Clear(); _commandBuffer.Clear();
Dispatch(dispatchParams, _commandBuffer); Dispatch(dispatchParams, _commandBuffer);
@ -177,7 +177,7 @@ namespace FidelityFX.FSR2
if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive); if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive);
if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive); if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive);
Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams);
Fsr2Resources.CreateAliasableResources(commandBuffer, _contextDescription);
SetupConstants(dispatchParams, resetAccumulation); SetupConstants(dispatchParams, resetAccumulation);
@ -210,7 +210,7 @@ namespace FidelityFX.FSR2
} }
// FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option // FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option
bool depthInverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) == Fsr2.InitializationFlags.EnableDepthInverted;
bool depthInverted = (_contextDescription.Flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0;
commandBuffer.SetRenderTarget(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth); commandBuffer.SetRenderTarget(Fsr2ShaderIDs.UavReconstructedPrevNearestDepth);
commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white);
@ -265,14 +265,14 @@ namespace FidelityFX.FSR2
commandBuffer.EndSample(_sampler); commandBuffer.EndSample(_sampler);
} }
public void GenerateReactiveMask(Fsr2.GenerateReactiveDescription dispatchParams)
public void GenerateReactiveMask(in Fsr2.GenerateReactiveDescription dispatchParams)
{ {
_commandBuffer.Clear(); _commandBuffer.Clear();
GenerateReactiveMask(dispatchParams, _commandBuffer); GenerateReactiveMask(dispatchParams, _commandBuffer);
Graphics.ExecuteCommandBuffer(_commandBuffer); Graphics.ExecuteCommandBuffer(_commandBuffer);
} }
public void GenerateReactiveMask(Fsr2.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer)
public void GenerateReactiveMask(in Fsr2.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer)
{ {
const int threadGroupWorkRegionDim = 8; const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
@ -285,10 +285,10 @@ namespace FidelityFX.FSR2
genReactiveConsts.flags = (uint)dispatchParams.Flags; genReactiveConsts.flags = (uint)dispatchParams.Flags;
_generateReactiveConstants.UpdateBufferData(commandBuffer); _generateReactiveConstants.UpdateBufferData(commandBuffer);
((Fsr2GenerateReactivePass)_generateReactivePass).ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY);
_generateReactivePass.ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY);
} }
private void GenerateTransparencyCompositionReactive(Fsr2.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int frameIndex)
private void GenerateTransparencyCompositionReactive(in Fsr2.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int bufferIndex)
{ {
const int threadGroupWorkRegionDim = 8; const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
@ -301,10 +301,10 @@ namespace FidelityFX.FSR2
tcrAutoGenConsts.autoReactiveMax = dispatchParams.AutoReactiveMax; tcrAutoGenConsts.autoReactiveMax = dispatchParams.AutoReactiveMax;
_tcrAutogenerateConstants.UpdateBufferData(commandBuffer); _tcrAutogenerateConstants.UpdateBufferData(commandBuffer);
_tcrAutogeneratePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_tcrAutogeneratePass.ScheduleDispatch(commandBuffer, dispatchParams, bufferIndex, dispatchSrcX, dispatchSrcY);
} }
private void SetupConstants(Fsr2.DispatchDescription dispatchParams, bool resetAccumulation)
private void SetupConstants(in Fsr2.DispatchDescription dispatchParams, bool resetAccumulation)
{ {
ref Fsr2.UpscalerConstants constants = ref _upscalerConstants.Value; ref Fsr2.UpscalerConstants constants = ref _upscalerConstants.Value;
@ -371,13 +371,13 @@ namespace FidelityFX.FSR2
constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv); constants.lumaMipDimensions.y = (int)(constants.maxRenderSize.y / mipDiv);
} }
private void SetupRcasConstants(Fsr2.DispatchDescription dispatchParams)
private void SetupRcasConstants(in Fsr2.DispatchDescription dispatchParams)
{ {
int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1)); int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1));
_rcasConstants.Value = RcasConfigs[sharpnessIndex]; _rcasConstants.Value = RcasConfigs[sharpnessIndex];
} }
private void SetupSpdConstants(Fsr2.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount)
private void SetupSpdConstants(in Fsr2.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount)
{ {
// Downsample // Downsample
ref Fsr2.SpdConstants spdConstants = ref _spdConstants.Value; ref Fsr2.SpdConstants spdConstants = ref _spdConstants.Value;
@ -386,7 +386,7 @@ namespace FidelityFX.FSR2
spdConstants.renderSizeY = (uint)dispatchParams.RenderSize.y; spdConstants.renderSizeY = (uint)dispatchParams.RenderSize.y;
} }
private void DebugCheckDispatch(Fsr2.DispatchDescription dispatchParams)
private void DebugCheckDispatch(in Fsr2.DispatchDescription dispatchParams)
{ {
if (!dispatchParams.Color.IsValid) if (!dispatchParams.Color.IsValid)
{ {

6
Runtime/FSR2/Fsr2Resources.cs

@ -47,7 +47,7 @@ namespace FidelityFX.FSR2
public readonly RenderTexture[] PrevPreAlpha = new RenderTexture[2]; public readonly RenderTexture[] PrevPreAlpha = new RenderTexture[2];
public readonly RenderTexture[] PrevPostAlpha = new RenderTexture[2]; public readonly RenderTexture[] PrevPostAlpha = new RenderTexture[2];
public void Create(Fsr2.ContextDescription contextDescription)
public void Create(in Fsr2.ContextDescription contextDescription)
{ {
// Generate the data for the LUT // Generate the data for the LUT
const int lanczos2LutWidth = 128; const int lanczos2LutWidth = 128;
@ -96,7 +96,7 @@ namespace FidelityFX.FSR2
CreateDoubleBufferedResource(LumaHistory, "FSR2_LumaHistory", contextDescription.DisplaySize, GraphicsFormat.R8G8B8A8_UNorm); CreateDoubleBufferedResource(LumaHistory, "FSR2_LumaHistory", contextDescription.DisplaySize, GraphicsFormat.R8G8B8A8_UNorm);
} }
public void CreateTcrAutogenResources(Fsr2.ContextDescription contextDescription)
public void CreateTcrAutogenResources(in Fsr2.ContextDescription contextDescription)
{ {
// Resource FSR2_AutoReactive: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE // Resource FSR2_AutoReactive: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
AutoReactive = CreateResource("FSR2_AutoReactive", contextDescription.MaxRenderSize, GraphicsFormat.R8_UNorm); AutoReactive = CreateResource("FSR2_AutoReactive", contextDescription.MaxRenderSize, GraphicsFormat.R8_UNorm);
@ -113,7 +113,7 @@ namespace FidelityFX.FSR2
// Set up shared aliasable resources, i.e. temporary render textures // Set up shared aliasable resources, i.e. temporary render textures
// These do not need to persist between frames, but they do need to be available between passes // These do not need to persist between frames, but they do need to be available between passes
public static void CreateAliasableResources(CommandBuffer commandBuffer, Fsr2.ContextDescription contextDescription, Fsr2.DispatchDescription dispatchParams)
public static void CreateAliasableResources(CommandBuffer commandBuffer, in Fsr2.ContextDescription contextDescription)
{ {
Vector2Int displaySize = contextDescription.DisplaySize; Vector2Int displaySize = contextDescription.DisplaySize;
Vector2Int maxRenderSize = contextDescription.MaxRenderSize; Vector2Int maxRenderSize = contextDescription.MaxRenderSize;

36
Runtime/FSR3/Fsr3Upscaler.cs

@ -133,7 +133,7 @@ namespace FidelityFX.FSR3
/// <summary> /// <summary>
/// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 3. /// A structure encapsulating the parameters for dispatching the various passes of FidelityFX Super Resolution 3.
/// </summary> /// </summary>
public class DispatchDescription
public struct DispatchDescription
{ {
public ResourceView Color; public ResourceView Color;
public ResourceView Depth; public ResourceView Depth;
@ -161,26 +161,42 @@ namespace FidelityFX.FSR3
// EXPERIMENTAL reactive mask generation parameters // EXPERIMENTAL reactive mask generation parameters
public bool EnableAutoReactive; public bool EnableAutoReactive;
public ResourceView ColorOpaqueOnly; public ResourceView ColorOpaqueOnly;
public float AutoTcThreshold = 0.05f;
public float AutoTcScale = 1.0f;
public float AutoReactiveScale = 5.0f;
public float AutoReactiveMax = 0.9f;
public float AutoTcThreshold;
public float AutoTcScale;
public float AutoReactiveScale;
public float AutoReactiveMax;
public static readonly DispatchDescription Default = new DispatchDescription
{
AutoTcThreshold = 0.05f,
AutoTcScale = 1.0f,
AutoReactiveScale = 5.0f,
AutoReactiveMax = 0.9f,
};
} }
/// <summary> /// <summary>
/// A structure encapsulating the parameters for automatic generation of a reactive mask. /// 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 FSR3 demo project. /// The default values for Scale, CutoffThreshold, BinaryValue and Flags were taken from the FSR3 demo project.
/// </summary> /// </summary>
public class GenerateReactiveDescription
public struct GenerateReactiveDescription
{ {
public ResourceView ColorOpaqueOnly; public ResourceView ColorOpaqueOnly;
public ResourceView ColorPreUpscale; public ResourceView ColorPreUpscale;
public ResourceView OutReactive; public ResourceView OutReactive;
public Vector2Int RenderSize; public Vector2Int RenderSize;
public float Scale = 0.5f;
public float CutoffThreshold = 0.2f;
public float BinaryValue = 0.9f;
public GenerateReactiveFlags Flags = GenerateReactiveFlags.ApplyTonemap | GenerateReactiveFlags.ApplyThreshold | GenerateReactiveFlags.UseComponentsMax;
public float Scale;
public float CutoffThreshold;
public float BinaryValue;
public GenerateReactiveFlags Flags;
public static readonly GenerateReactiveDescription Default = new GenerateReactiveDescription
{
Scale = 0.5f,
CutoffThreshold = 0.2f,
BinaryValue = 0.9f,
Flags = GenerateReactiveFlags.ApplyTonemap | GenerateReactiveFlags.ApplyThreshold | GenerateReactiveFlags.UseComponentsMax,
};
} }
[Flags] [Flags]

48
Runtime/FSR3/Fsr3UpscalerContext.cs

@ -39,18 +39,18 @@ namespace FidelityFX.FSR3
private Fsr3Upscaler.ContextDescription _contextDescription; private Fsr3Upscaler.ContextDescription _contextDescription;
private CommandBuffer _commandBuffer; private CommandBuffer _commandBuffer;
private Fsr3UpscalerPass _prepareInputsPass;
private Fsr3UpscalerPass _lumaPyramidPass;
private Fsr3UpscalerPass _shadingChangePyramidPass;
private Fsr3UpscalerPass _shadingChangePass;
private Fsr3UpscalerPass _prepareReactivityPass;
private Fsr3UpscalerPass _lumaInstabilityPass;
private Fsr3UpscalerPass _accumulatePass;
private Fsr3UpscalerPass _sharpenPass;
private Fsr3UpscalerPass _generateReactivePass;
private Fsr3UpscalerPass _tcrAutogeneratePass;
private Fsr3UpscalerPrepareInputsPass _prepareInputsPass;
private Fsr3UpscalerLumaPyramidPass _lumaPyramidPass;
private Fsr3UpscalerShadingChangePyramidPass _shadingChangePyramidPass;
private Fsr3UpscalerShadingChangePass _shadingChangePass;
private Fsr3UpscalerPrepareReactivityPass _prepareReactivityPass;
private Fsr3UpscalerLumaInstabilityPass _lumaInstabilityPass;
private Fsr3UpscalerAccumulatePass _accumulatePass;
private Fsr3UpscalerSharpenPass _sharpenPass;
private Fsr3UpscalerGenerateReactivePass _generateReactivePass;
private Fsr3UpscalerTcrAutogeneratePass _tcrAutogeneratePass;
#if UNITY_EDITOR || DEVELOPMENT_BUILD #if UNITY_EDITOR || DEVELOPMENT_BUILD
private Fsr3UpscalerPass _debugViewPass;
private Fsr3UpscalerDebugViewPass _debugViewPass;
#endif #endif
private readonly Fsr3UpscalerResources _resources = new Fsr3UpscalerResources(); private readonly Fsr3UpscalerResources _resources = new Fsr3UpscalerResources();
@ -69,7 +69,7 @@ namespace FidelityFX.FSR3
private readonly CustomSampler _sampler = CustomSampler.Create("FSR3 Upscaler"); private readonly CustomSampler _sampler = CustomSampler.Create("FSR3 Upscaler");
public void Create(Fsr3Upscaler.ContextDescription contextDescription)
public void Create(in Fsr3Upscaler.ContextDescription contextDescription)
{ {
_contextDescription = contextDescription; _contextDescription = contextDescription;
_commandBuffer = new CommandBuffer { name = "FSR3 Upscaler" }; _commandBuffer = new CommandBuffer { name = "FSR3 Upscaler" };
@ -138,7 +138,7 @@ namespace FidelityFX.FSR3
} }
} }
public void Dispatch(Fsr3Upscaler.DispatchDescription dispatchParams)
public void Dispatch(in Fsr3Upscaler.DispatchDescription dispatchParams)
{ {
_commandBuffer.Clear(); _commandBuffer.Clear();
Dispatch(dispatchParams, _commandBuffer); Dispatch(dispatchParams, _commandBuffer);
@ -199,7 +199,7 @@ namespace FidelityFX.FSR3
if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive); if (!dispatchParams.Reactive.IsValid) dispatchParams.Reactive = new ResourceView(_resources.DefaultReactive);
if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive); if (!dispatchParams.TransparencyAndComposition.IsValid) dispatchParams.TransparencyAndComposition = new ResourceView(_resources.DefaultReactive);
Fsr3UpscalerResources.CreateAliasableResources(commandBuffer, _contextDescription, dispatchParams);
Fsr3UpscalerResources.CreateAliasableResources(commandBuffer, _contextDescription);
SetupConstants(dispatchParams, resetAccumulation); SetupConstants(dispatchParams, resetAccumulation);
@ -233,7 +233,7 @@ namespace FidelityFX.FSR3
} }
// FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option // FSR3: need to clear here since we need the content of this surface for frame interpolation, so clearing in the lock pass is not an option
bool depthInverted = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) == Fsr3Upscaler.InitializationFlags.EnableDepthInverted;
bool depthInverted = (_contextDescription.Flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0;
commandBuffer.SetRenderTarget(_resources.ReconstructedPrevNearestDepth); commandBuffer.SetRenderTarget(_resources.ReconstructedPrevNearestDepth);
commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white); commandBuffer.ClearRenderTarget(false, true, depthInverted ? Color.clear : Color.white);
@ -289,14 +289,14 @@ namespace FidelityFX.FSR3
commandBuffer.EndSample(_sampler); commandBuffer.EndSample(_sampler);
} }
public void GenerateReactiveMask(Fsr3Upscaler.GenerateReactiveDescription dispatchParams)
public void GenerateReactiveMask(in Fsr3Upscaler.GenerateReactiveDescription dispatchParams)
{ {
_commandBuffer.Clear(); _commandBuffer.Clear();
GenerateReactiveMask(dispatchParams, _commandBuffer); GenerateReactiveMask(dispatchParams, _commandBuffer);
Graphics.ExecuteCommandBuffer(_commandBuffer); Graphics.ExecuteCommandBuffer(_commandBuffer);
} }
public void GenerateReactiveMask(Fsr3Upscaler.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer)
public void GenerateReactiveMask(in Fsr3Upscaler.GenerateReactiveDescription dispatchParams, CommandBuffer commandBuffer)
{ {
const int threadGroupWorkRegionDim = 8; const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
@ -309,10 +309,10 @@ namespace FidelityFX.FSR3
genReactiveConsts.flags = (uint)dispatchParams.Flags; genReactiveConsts.flags = (uint)dispatchParams.Flags;
_generateReactiveConstants.UpdateBufferData(commandBuffer); _generateReactiveConstants.UpdateBufferData(commandBuffer);
((Fsr3UpscalerGenerateReactivePass)_generateReactivePass).ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY);
_generateReactivePass.ScheduleDispatch(commandBuffer, dispatchParams, dispatchSrcX, dispatchSrcY);
} }
private void GenerateTransparencyCompositionReactive(Fsr3Upscaler.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int frameIndex)
private void GenerateTransparencyCompositionReactive(in Fsr3Upscaler.DispatchDescription dispatchParams, CommandBuffer commandBuffer, int bufferIndex)
{ {
const int threadGroupWorkRegionDim = 8; const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; int dispatchSrcX = (dispatchParams.RenderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
@ -325,10 +325,10 @@ namespace FidelityFX.FSR3
tcrAutoGenConsts.autoReactiveMax = dispatchParams.AutoReactiveMax; tcrAutoGenConsts.autoReactiveMax = dispatchParams.AutoReactiveMax;
_tcrAutogenerateConstants.UpdateBufferData(commandBuffer); _tcrAutogenerateConstants.UpdateBufferData(commandBuffer);
_tcrAutogeneratePass.ScheduleDispatch(commandBuffer, dispatchParams, frameIndex, dispatchSrcX, dispatchSrcY);
_tcrAutogeneratePass.ScheduleDispatch(commandBuffer, dispatchParams, bufferIndex, dispatchSrcX, dispatchSrcY);
} }
private void SetupConstants(Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation)
private void SetupConstants(in Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation)
{ {
ref Fsr3Upscaler.UpscalerConstants constants = ref _upscalerConstants.Value; ref Fsr3Upscaler.UpscalerConstants constants = ref _upscalerConstants.Value;
@ -408,13 +408,13 @@ namespace FidelityFX.FSR3
constants.frameIndex += 1.0f; constants.frameIndex += 1.0f;
} }
private void SetupRcasConstants(Fsr3Upscaler.DispatchDescription dispatchParams)
private void SetupRcasConstants(in Fsr3Upscaler.DispatchDescription dispatchParams)
{ {
int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1)); int sharpnessIndex = Mathf.RoundToInt(Mathf.Clamp01(dispatchParams.Sharpness) * (RcasConfigs.Length - 1));
_rcasConstants.Value = RcasConfigs[sharpnessIndex]; _rcasConstants.Value = RcasConfigs[sharpnessIndex];
} }
private void SetupSpdConstants(Fsr3Upscaler.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount)
private void SetupSpdConstants(in Fsr3Upscaler.DispatchDescription dispatchParams, out Vector2Int dispatchThreadGroupCount)
{ {
// Downsample // Downsample
ref Fsr3Upscaler.SpdConstants spdConstants = ref _spdConstants.Value; ref Fsr3Upscaler.SpdConstants spdConstants = ref _spdConstants.Value;
@ -423,7 +423,7 @@ namespace FidelityFX.FSR3
spdConstants.renderSizeY = (uint)dispatchParams.RenderSize.y; spdConstants.renderSizeY = (uint)dispatchParams.RenderSize.y;
} }
private void DebugCheckDispatch(Fsr3Upscaler.DispatchDescription dispatchParams)
private void DebugCheckDispatch(in Fsr3Upscaler.DispatchDescription dispatchParams)
{ {
if (!dispatchParams.Color.IsValid) if (!dispatchParams.Color.IsValid)
{ {

6
Runtime/FSR3/Fsr3UpscalerResources.cs

@ -51,7 +51,7 @@ namespace FidelityFX.FSR3
public readonly RenderTexture[] PrevPreAlpha = new RenderTexture[2]; public readonly RenderTexture[] PrevPreAlpha = new RenderTexture[2];
public readonly RenderTexture[] PrevPostAlpha = new RenderTexture[2]; public readonly RenderTexture[] PrevPostAlpha = new RenderTexture[2];
public void Create(Fsr3Upscaler.ContextDescription contextDescription)
public void Create(in Fsr3Upscaler.ContextDescription contextDescription)
{ {
// Generate the data for the LUT // Generate the data for the LUT
const int lanczos2LutWidth = 128; const int lanczos2LutWidth = 128;
@ -103,7 +103,7 @@ namespace FidelityFX.FSR3
CreateDoubleBufferedResource(LumaHistory, "FSR3UPSCALER_LumaHistory", maxRenderSize, GraphicsFormat.R16G16B16A16_SFloat); CreateDoubleBufferedResource(LumaHistory, "FSR3UPSCALER_LumaHistory", maxRenderSize, GraphicsFormat.R16G16B16A16_SFloat);
} }
public void CreateTcrAutogenResources(Fsr3Upscaler.ContextDescription contextDescription)
public void CreateTcrAutogenResources(in Fsr3Upscaler.ContextDescription contextDescription)
{ {
// Resource FSR3UPSCALER_AutoReactive: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE // Resource FSR3UPSCALER_AutoReactive: FFX_RESOURCE_USAGE_UAV, FFX_SURFACE_FORMAT_R8_UNORM, FFX_RESOURCE_FLAGS_NONE
AutoReactive = CreateResource("FSR3UPSCALER_AutoReactive", contextDescription.MaxRenderSize, GraphicsFormat.R8_UNorm); AutoReactive = CreateResource("FSR3UPSCALER_AutoReactive", contextDescription.MaxRenderSize, GraphicsFormat.R8_UNorm);
@ -120,7 +120,7 @@ namespace FidelityFX.FSR3
// Set up shared aliasable resources, i.e. temporary render textures // Set up shared aliasable resources, i.e. temporary render textures
// These do not need to persist between frames, but they do need to be available between passes // These do not need to persist between frames, but they do need to be available between passes
public static void CreateAliasableResources(CommandBuffer commandBuffer, Fsr3Upscaler.ContextDescription contextDescription, Fsr3Upscaler.DispatchDescription dispatchParams)
public static void CreateAliasableResources(CommandBuffer commandBuffer, in Fsr3Upscaler.ContextDescription contextDescription)
{ {
Vector2Int maxUpscaleSize = contextDescription.MaxUpscaleSize; Vector2Int maxUpscaleSize = contextDescription.MaxUpscaleSize;
Vector2Int maxRenderSize = contextDescription.MaxRenderSize; Vector2Int maxRenderSize = contextDescription.MaxRenderSize;

Loading…
Cancel
Save