From a1086edfe3641ca73a866166f480382ca867c05e Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Fri, 17 Feb 2023 14:01:43 +0100 Subject: [PATCH] Updated C# bindings so far for the changes in FSR 2.2 --- Assets/Scripts/Fsr2Context.cs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/Assets/Scripts/Fsr2Context.cs b/Assets/Scripts/Fsr2Context.cs index f6f4880..8625692 100644 --- a/Assets/Scripts/Fsr2Context.cs +++ b/Assets/Scripts/Fsr2Context.cs @@ -17,6 +17,7 @@ namespace FidelityFX private ComputeShader _generateReactiveShader; private ComputeShader _rcasShader; private ComputeShader _computeLuminancePyramidShader; + private ComputeShader _tcrAutogenShader; private ComputeBuffer _fsr2ConstantsBuffer; private readonly Fsr2Constants[] _fsr2ConstantsArray = { new Fsr2Constants() }; @@ -37,9 +38,6 @@ namespace FidelityFX // Set defaults _fsr2ConstantsArray[0].displaySize = _contextDescription.DisplaySize; - _fsr2ConstantsArray[0].displaySizeRcp = new Vector2( - 1.0f / _contextDescription.DisplaySize.x, - 1.0f / _contextDescription.DisplaySize.y); // Generate the data for the LUT const uint lanczos2LutWidth = 128; @@ -52,6 +50,12 @@ namespace FidelityFX } InitShaders(); + + // TODO: create resources, i.e. render textures used for intermediate results. + // Note that "aliasable" resources should be equivalent to GetTemporary render textures + // UAVs *may* be an issue with the PS4 not handling simultaneous reading and writing to an RT properly + // Unity does have Graphics.SetRandomWriteTarget for enabling UAV on ComputeBuffers or RTs + // Unity doesn't do 1D textures so just default to Texture2D } private void InitShaders() @@ -64,6 +68,7 @@ namespace FidelityFX LoadComputeShader("FSR2/ffx_fsr2_lock_pass", ref _lockShader); LoadComputeShader("FSR2/ffx_fsr2_accumulate_pass", ref _accumulateShader); LoadComputeShader("FSR2/ffx_fsr2_autogen_reactive_pass", ref _generateReactiveShader); + LoadComputeShader("FSR2/ffx_fsr2_tcr_autogen_pass", ref _tcrAutogenShader); } private void LoadComputeShader(string name, ref ComputeShader shaderRef) @@ -85,7 +90,7 @@ namespace FidelityFX // Run the RCAS sharpening filter on the upscaled image int rcasKernel = _rcasShader.FindKernel("CS"); - _rcasShader.SetTexture(rcasKernel, "r_exposure", dispatchDescription.Exposure); + _rcasShader.SetTexture(rcasKernel, "r_input_exposure", dispatchDescription.Exposure); _rcasShader.SetTexture(rcasKernel, "r_rcas_input", dispatchDescription.Input); _rcasShader.SetTexture(rcasKernel, "rw_upscaled_output", dispatchDescription.Output); _rcasShader.SetConstantBuffer("cbFSR2", _fsr2ConstantsBuffer, 0, Marshal.SizeOf()); @@ -128,27 +133,25 @@ namespace FidelityFX private struct Fsr2Constants { public Vector2Int renderSize; + public Vector2Int maxRenderSize; public Vector2Int displaySize; - public uint lumaMipDimensionsX, lumaMipDimensionsY; - public uint lumaMipLevelToUse; - public uint frameIndex; - public Vector2 displaySizeRcp; - public Vector2 jitterOffset; + public Vector2Int inputColorResourceDimensions; + public Vector2Int lumaMipDimensions; + public int lumaMipLevelToUse; + public int frameIndex; + public Vector4 deviceToViewDepth; - public Vector2 depthClipUVScale; - public Vector2 postLockStatusUVScale; - public Vector2 reactiveMaskDimRcp; + public Vector2 jitterOffset; public Vector2 motionVectorScale; public Vector2 downscaleFactor; + public Vector2 motionVectorJitterCancellation; public float preExposure; + public float previousFramePreExposure; public float tanHalfFOV; - public Vector2 motionVectorJitterCancellation; public float jitterPhaseCount; - public float lockInitialLifetime; - public float lockTickDelta; public float deltaTime; public float dynamicResChangeFactor; - public float lumaMipRcp; + public float viewSpaceToMetersFactor; } [Serializable, StructLayout(LayoutKind.Sequential)]