|
|
@ -41,8 +41,6 @@ namespace FidelityFX |
|
|
protected ComputeShader ComputeShader; |
|
|
protected ComputeShader ComputeShader; |
|
|
protected int KernelIndex; |
|
|
protected int KernelIndex; |
|
|
|
|
|
|
|
|
protected virtual bool AllowFP16 => true; |
|
|
|
|
|
|
|
|
|
|
|
protected Fsr2Pass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) |
|
|
protected Fsr2Pass(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) |
|
|
{ |
|
|
{ |
|
|
ContextDescription = contextDescription; |
|
|
ContextDescription = contextDescription; |
|
|
@ -81,16 +79,13 @@ namespace FidelityFX |
|
|
} |
|
|
} |
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
// Allow 16-bit floating point as a configuration option, except on passes that explicitly disable it
|
|
|
|
|
|
bool supportedFP16 = ((flags & Fsr2.InitializationFlags.EnableFP16Usage) != 0 && AllowFP16); |
|
|
|
|
|
|
|
|
|
|
|
// This matches the permutation rules from the CreatePipeline* functions
|
|
|
// This matches the permutation rules from the CreatePipeline* functions
|
|
|
if ((flags & Fsr2.InitializationFlags.EnableHighDynamicRange) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT"); |
|
|
if ((flags & Fsr2.InitializationFlags.EnableHighDynamicRange) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_HDR_COLOR_INPUT"); |
|
|
if ((flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS"); |
|
|
if ((flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS"); |
|
|
if ((flags & Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS"); |
|
|
if ((flags & Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS"); |
|
|
if ((flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH"); |
|
|
if ((flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH"); |
|
|
if (useLut) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE"); |
|
|
if (useLut) shaderRef.EnableKeyword("FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE"); |
|
|
if (supportedFP16) shaderRef.EnableKeyword("FFX_HALF"); |
|
|
|
|
|
|
|
|
if ((flags & Fsr2.InitializationFlags.EnableFP16Usage) != 0) shaderRef.EnableKeyword("FFX_HALF"); |
|
|
|
|
|
|
|
|
// Inform the shader which render pipeline we're currently using
|
|
|
// Inform the shader which render pipeline we're currently using
|
|
|
var pipeline = GraphicsSettings.currentRenderPipeline; |
|
|
var pipeline = GraphicsSettings.currentRenderPipeline; |
|
|
@ -137,7 +132,7 @@ namespace FidelityFX |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavExposureMip5, Resources.SceneLuminance, 5); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoExposure, Resources.AutoExposure); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavAutoExposure, Resources.AutoExposure); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr2.SpdConstants>()); |
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbSpd, _spdConstants, 0, Marshal.SizeOf<Fsr2.SpdConstants>()); |
|
|
|
|
|
|
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
@ -166,7 +161,7 @@ namespace FidelityFX |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex]); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
} |
|
|
} |
|
|
@ -201,7 +196,7 @@ namespace FidelityFX |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedDepth, Fsr2ShaderIDs.UavDilatedDepth); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvDilatedDepth, Fsr2ShaderIDs.UavDilatedDepth); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvPrevDilatedMotionVectors, Resources.DilatedMotionVectors[frameIndex ^ 1]); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
} |
|
|
} |
|
|
@ -218,7 +213,7 @@ namespace FidelityFX |
|
|
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
|
|
public override void ScheduleDispatch(CommandBuffer commandBuffer, Fsr2.DispatchDescription dispatchParams, int frameIndex, int dispatchX, int dispatchY) |
|
|
{ |
|
|
{ |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLockInputLuma, Fsr2ShaderIDs.UavLockInputLuma); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.SrvLockInputLuma, Fsr2ShaderIDs.UavLockInputLuma); |
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
} |
|
|
} |
|
|
@ -227,9 +222,6 @@ namespace FidelityFX |
|
|
internal class Fsr2AccumulatePass : Fsr2Pass |
|
|
internal class Fsr2AccumulatePass : Fsr2Pass |
|
|
{ |
|
|
{ |
|
|
private const string SharpeningKeyword = "FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING"; |
|
|
private const string SharpeningKeyword = "FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING"; |
|
|
|
|
|
|
|
|
// Workaround: Disable FP16 path for the accumulate pass on NVIDIA due to reduced occupancy and high VRAM throughput.
|
|
|
|
|
|
protected override bool AllowFP16 => SystemInfo.graphicsDeviceVendorID != 0x10DE; |
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_2021_2_OR_NEWER
|
|
|
#if UNITY_2021_2_OR_NEWER
|
|
|
private readonly LocalKeyword _sharpeningKeyword; |
|
|
private readonly LocalKeyword _sharpeningKeyword; |
|
|
@ -288,7 +280,7 @@ namespace FidelityFX |
|
|
ref var output = ref dispatchParams.Output; |
|
|
ref var output = ref dispatchParams.Output; |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
} |
|
|
} |
|
|
@ -315,7 +307,7 @@ namespace FidelityFX |
|
|
ref var output = ref dispatchParams.Output; |
|
|
ref var output = ref dispatchParams.Output; |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavUpscaledOutput, output.RenderTarget, output.MipLevel, output.SubElement); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbRcas, _rcasConstants, 0, Marshal.SizeOf<Fsr2.RcasConstants>()); |
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbRcas, _rcasConstants, 0, Marshal.SizeOf<Fsr2.RcasConstants>()); |
|
|
|
|
|
|
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
@ -387,7 +379,7 @@ namespace FidelityFX |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex]); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPreAlpha, Resources.PrevPreAlpha[frameIndex]); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex]); |
|
|
commandBuffer.SetComputeTextureParam(ComputeShader, KernelIndex, Fsr2ShaderIDs.UavPrevColorPostAlpha, Resources.PrevPostAlpha[frameIndex]); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr2, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
|
|
|
|
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbFsr3Upscaler, Constants, 0, Marshal.SizeOf<Fsr2.Fsr2Constants>()); |
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbGenReactive, _tcrAutogenerateConstants, 0, Marshal.SizeOf<Fsr2.GenerateReactiveConstants2>()); |
|
|
commandBuffer.SetComputeConstantBufferParam(ComputeShader, Fsr2ShaderIDs.CbGenReactive, _tcrAutogenerateConstants, 0, Marshal.SizeOf<Fsr2.GenerateReactiveConstants2>()); |
|
|
|
|
|
|
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
commandBuffer.DispatchCompute(ComputeShader, KernelIndex, dispatchX, dispatchY, 1); |
|
|
|