Browse Source

Rename FSR2 to FSR3 Upscaler, part 3: missing bits.

fsr3
Nico de Poel 2 years ago
parent
commit
ebb9d84171
  1. 2
      Assets/Scripts/Core/Fsr3Upscaler.cs
  2. 2
      Assets/Scripts/Core/Fsr3UpscalerCallbacks.cs
  3. 34
      Assets/Scripts/Core/Fsr3UpscalerContext.cs
  4. 14
      Assets/Scripts/Core/Fsr3UpscalerPass.cs
  5. 2
      Assets/Scripts/Fsr3UpscalerImageEffectHelper.cs

2
Assets/Scripts/Core/Fsr3Upscaler.cs

@ -258,7 +258,7 @@ namespace FidelityFX
}
[Serializable, StructLayout(LayoutKind.Sequential)]
internal struct Fsr2Constants
internal struct UpscalerConstants
{
public Vector2Int renderSize;
public Vector2Int maxRenderSize;

2
Assets/Scripts/Core/Fsr3UpscalerCallbacks.cs

@ -45,7 +45,7 @@ namespace FidelityFX
}
/// <summary>
/// Default implementation of IFsr2Callbacks using simple Resources calls.
/// Default implementation of IFsr3UpscalerCallbacks using simple Resources calls.
/// These are fine for testing but a proper game will want to extend and override these methods.
/// </summary>
public class Fsr3UpscalerCallbacksBase: IFsr3UpscalerCallbacks

34
Assets/Scripts/Core/Fsr3UpscalerContext.cs

@ -49,9 +49,9 @@ namespace FidelityFX
private readonly Fsr3UpscalerResources _resources = new Fsr3UpscalerResources();
private ComputeBuffer _fsr2ConstantsBuffer;
private readonly Fsr3Upscaler.Fsr2Constants[] _fsr2ConstantsArray = { new Fsr3Upscaler.Fsr2Constants() };
private ref Fsr3Upscaler.Fsr2Constants Constants => ref _fsr2ConstantsArray[0];
private ComputeBuffer _upscalerConstantsBuffer;
private readonly Fsr3Upscaler.UpscalerConstants[] _upscalerConstantsArray = { new Fsr3Upscaler.UpscalerConstants() };
private ref Fsr3Upscaler.UpscalerConstants UpscalerConsts => ref _upscalerConstantsArray[0];
private ComputeBuffer _spdConstantsBuffer;
private readonly Fsr3Upscaler.SpdConstants[] _spdConstantsArray = { new Fsr3Upscaler.SpdConstants() };
@ -78,7 +78,7 @@ namespace FidelityFX
_contextDescription = contextDescription;
_commandBuffer = new CommandBuffer { name = "FSR3 Upscaler" };
_fsr2ConstantsBuffer = CreateConstantBuffer<Fsr3Upscaler.Fsr2Constants>();
_upscalerConstantsBuffer = CreateConstantBuffer<Fsr3Upscaler.UpscalerConstants>();
_spdConstantsBuffer = CreateConstantBuffer<Fsr3Upscaler.SpdConstants>();
_rcasConstantsBuffer = CreateConstantBuffer<Fsr3Upscaler.RcasConstants>();
_generateReactiveConstantsBuffer = CreateConstantBuffer<Fsr3Upscaler.GenerateReactiveConstants>();
@ -88,7 +88,7 @@ namespace FidelityFX
_firstExecution = true;
_resourceFrameIndex = 0;
Constants.displaySize = _contextDescription.DisplaySize;
UpscalerConsts.displaySize = _contextDescription.DisplaySize;
_resources.Create(_contextDescription);
CreatePasses();
@ -96,14 +96,14 @@ namespace FidelityFX
private void CreatePasses()
{
_computeLuminancePyramidPass = new Fsr3UpscalerComputeLuminancePyramidPass(_contextDescription, _resources, _fsr2ConstantsBuffer, _spdConstantsBuffer);
_reconstructPreviousDepthPass = new Fsr3UpscalerReconstructPreviousDepthPass(_contextDescription, _resources, _fsr2ConstantsBuffer);
_depthClipPass = new Fsr3UpscalerDepthClipPass(_contextDescription, _resources, _fsr2ConstantsBuffer);
_lockPass = new Fsr3UpscalerLockPass(_contextDescription, _resources, _fsr2ConstantsBuffer);
_accumulatePass = new Fsr3UpscalerAccumulatePass(_contextDescription, _resources, _fsr2ConstantsBuffer);
_rcasPass = new Fsr3UpscalerRcasPass(_contextDescription, _resources, _fsr2ConstantsBuffer, _rcasConstantsBuffer);
_computeLuminancePyramidPass = new Fsr3UpscalerComputeLuminancePyramidPass(_contextDescription, _resources, _upscalerConstantsBuffer, _spdConstantsBuffer);
_reconstructPreviousDepthPass = new Fsr3UpscalerReconstructPreviousDepthPass(_contextDescription, _resources, _upscalerConstantsBuffer);
_depthClipPass = new Fsr3UpscalerDepthClipPass(_contextDescription, _resources, _upscalerConstantsBuffer);
_lockPass = new Fsr3UpscalerLockPass(_contextDescription, _resources, _upscalerConstantsBuffer);
_accumulatePass = new Fsr3UpscalerAccumulatePass(_contextDescription, _resources, _upscalerConstantsBuffer);
_rcasPass = new Fsr3UpscalerRcasPass(_contextDescription, _resources, _upscalerConstantsBuffer, _rcasConstantsBuffer);
_generateReactivePass = new Fsr3UpscalerGenerateReactivePass(_contextDescription, _resources, _generateReactiveConstantsBuffer);
_tcrAutogeneratePass = new Fsr3UpscalerTcrAutogeneratePass(_contextDescription, _resources, _fsr2ConstantsBuffer, _tcrAutogenerateConstantsBuffer);
_tcrAutogeneratePass = new Fsr3UpscalerTcrAutogeneratePass(_contextDescription, _resources, _upscalerConstantsBuffer, _tcrAutogenerateConstantsBuffer);
}
public void Destroy()
@ -123,7 +123,7 @@ namespace FidelityFX
DestroyConstantBuffer(ref _generateReactiveConstantsBuffer);
DestroyConstantBuffer(ref _rcasConstantsBuffer);
DestroyConstantBuffer(ref _spdConstantsBuffer);
DestroyConstantBuffer(ref _fsr2ConstantsBuffer);
DestroyConstantBuffer(ref _upscalerConstantsBuffer);
_commandBuffer.Dispose();
_commandBuffer = null;
@ -187,8 +187,8 @@ namespace FidelityFX
// Reactive mask bias
const int threadGroupWorkRegionDim = 8;
int dispatchSrcX = (Constants.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchSrcY = (Constants.renderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchSrcX = (UpscalerConsts.renderSize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchSrcY = (UpscalerConsts.renderSize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchDstX = (_contextDescription.DisplaySize.x + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchDstY = (_contextDescription.DisplaySize.y + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
@ -222,7 +222,7 @@ namespace FidelityFX
SetupSpdConstants(dispatchParams, out var dispatchThreadGroupCount);
// Initialize constant buffers data
commandBuffer.SetBufferData(_fsr2ConstantsBuffer, _fsr2ConstantsArray);
commandBuffer.SetBufferData(_upscalerConstantsBuffer, _upscalerConstantsArray);
commandBuffer.SetBufferData(_spdConstantsBuffer, _spdConstantsArray);
// Auto reactive
@ -305,7 +305,7 @@ namespace FidelityFX
private void SetupConstants(Fsr3Upscaler.DispatchDescription dispatchParams, bool resetAccumulation)
{
ref Fsr3Upscaler.Fsr2Constants constants = ref Constants;
ref Fsr3Upscaler.UpscalerConstants constants = ref UpscalerConsts;
constants.jitterOffset = dispatchParams.JitterOffset;
constants.renderSize = dispatchParams.RenderSize;

14
Assets/Scripts/Core/Fsr3UpscalerPass.cs

@ -132,7 +132,7 @@ namespace FidelityFX
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavAutoExposure, Resources.AutoExposure);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.Fsr2Constants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr3Upscaler.SpdConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
@ -161,7 +161,7 @@ namespace FidelityFX
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.Fsr2Constants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
@ -196,7 +196,7 @@ namespace FidelityFX
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvDilatedDepth, Fsr3ShaderIDs.UavDilatedDepth);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.Fsr2Constants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
@ -213,7 +213,7 @@ namespace FidelityFX
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr3Upscaler.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY)
{
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.SrvLockInputLuma, Fsr3ShaderIDs.UavLockInputLuma);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.Fsr2Constants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
@ -280,7 +280,7 @@ namespace FidelityFX
ref var output = ref dispatchParams.Output;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.Fsr2Constants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
}
@ -307,7 +307,7 @@ namespace FidelityFX
ref var output = ref dispatchParams.Output;
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.Fsr2Constants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbRcas, _rcasConstants, 0, Marshal.SizeOf<Fsr3Upscaler.RcasConstants>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);
@ -379,7 +379,7 @@ namespace FidelityFX
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex]);
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr3ShaderIDs.UavPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex]);
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.Fsr2Constants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr3Upscaler.UpscalerConstants>());
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr3ShaderIDs.CbGenReactive, _tcrAutogenerateConstants, 0, Marshal.SizeOf<Fsr3Upscaler.GenerateReactiveConstants2>());
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1);

2
Assets/Scripts/Fsr3UpscalerImageEffectHelper.cs

@ -24,7 +24,7 @@ using UnityEngine;
namespace FidelityFX
{
/// <summary>
/// Small helper script to be used in conjunction with the Fsr2ImageEffect script.
/// Small helper script to be used in conjunction with the Fsr3UpscalerImageEffect script.
/// The FSR3 Upscaler image effect needs to be the last effect in the post-processing chain but for render scaling to work properly, it also needs to be the first to execute OnPreCull.
/// Unfortunately altering the script execution order does not affect the order in which OnPreCull is executed. Only the order of scripts on the same game object matters.
///

Loading…
Cancel
Save