From 12b5791cd2194926e73658a7902b905a601ccf13 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sun, 26 Feb 2023 13:43:51 +0100 Subject: [PATCH] Enabled 16-bit floating point support by changing the unused 1D Texture option into an FP16 option, which makes its usage configurable by the game dev. Also included the workaround to force FP32 in the accumulate pass on Nvidia cards. --- Assets/Scripts/Fsr2.cs | 2 +- Assets/Scripts/Fsr2Controller.cs | 2 +- Assets/Scripts/Fsr2Pipeline.cs | 12 ++++++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Assets/Scripts/Fsr2.cs b/Assets/Scripts/Fsr2.cs index 6999df6..256dbee 100644 --- a/Assets/Scripts/Fsr2.cs +++ b/Assets/Scripts/Fsr2.cs @@ -118,7 +118,7 @@ namespace FidelityFX EnableDepthInfinite = 1 << 4, EnableAutoExposure = 1 << 5, EnableDynamicResolution = 1 << 6, - EnableTexture1DUsage = 1 << 7, + EnableFP16Usage = 1 << 7, EnableDebugChecking = 1 << 8, } diff --git a/Assets/Scripts/Fsr2Controller.cs b/Assets/Scripts/Fsr2Controller.cs index aa87f13..0db4bfa 100644 --- a/Assets/Scripts/Fsr2Controller.cs +++ b/Assets/Scripts/Fsr2Controller.cs @@ -70,7 +70,7 @@ public class Fsr2Controller : MonoBehaviour RenderPipelineManager.endContextRendering += OnEndContextRendering; - _context = Fsr2.CreateContext(DisplaySize, RenderSize, Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation); + _context = Fsr2.CreateContext(DisplaySize, RenderSize, Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation | Fsr2.InitializationFlags.EnableFP16Usage); // TODO: do we need a depth buffer for the output? We will need depth & motion vectors for subsequent post-FX. How should FSR2 output these? // TODO: can probably be a temporary RT diff --git a/Assets/Scripts/Fsr2Pipeline.cs b/Assets/Scripts/Fsr2Pipeline.cs index 9c35ed8..d7ee0f1 100644 --- a/Assets/Scripts/Fsr2Pipeline.cs +++ b/Assets/Scripts/Fsr2Pipeline.cs @@ -59,6 +59,8 @@ namespace FidelityFX protected static readonly int CbSpd = Shader.PropertyToID("cbSPD"); protected static readonly int CbRcas = Shader.PropertyToID("cbRCAS"); protected static readonly int CbGenReactive = Shader.PropertyToID("cbGenerateReactive"); + + protected virtual bool AllowFP16 => true; protected Fsr2Pipeline(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) { @@ -131,14 +133,17 @@ namespace FidelityFX kernelIndex = shaderRef.FindKernel("CS"); bool useLut = (SystemInfo.computeSubGroupSize == 64); + + // 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 mirrors 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_FSR2_OPTION_HDR_COLOR_INPUT"); if ((flags & Fsr2.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) shaderRef.EnableKeyword("FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS"); if ((flags & Fsr2.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) shaderRef.EnableKeyword("FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS"); if ((flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0) shaderRef.EnableKeyword("FFX_FSR2_OPTION_INVERTED_DEPTH"); if (useLut) shaderRef.EnableKeyword("FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE"); - // TODO: enable FFX_HALF if FP16 is supported (except RCAS) + if (supportedFP16) shaderRef.EnableKeyword("FFX_HALF"); } private void UnloadComputeShader() @@ -249,6 +254,9 @@ namespace FidelityFX internal class Fsr2AccumulatePipeline : Fsr2Pipeline { + // 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; + public Fsr2AccumulatePipeline(Fsr2.ContextDescription contextDescription, Fsr2Resources resources, ComputeBuffer constants) : base(contextDescription, resources, constants) {