From 03fd58cb5aa9fff882588f287cf198a7f6d2c543 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Fri, 17 Mar 2023 12:21:53 +0100 Subject: [PATCH] Check for compute shader support when enabling FSR2, and moved debug checking flag to default context creation method. --- Assets/Scripts/Fsr2ImageEffect.cs | 11 +++++++---- Assets/Scripts/Internal/Fsr2.cs | 7 +++++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/Fsr2ImageEffect.cs b/Assets/Scripts/Fsr2ImageEffect.cs index 7007588..f018821 100644 --- a/Assets/Scripts/Fsr2ImageEffect.cs +++ b/Assets/Scripts/Fsr2ImageEffect.cs @@ -69,6 +69,13 @@ namespace FidelityFX private void OnEnable() { + if (!SystemInfo.supportsComputeShaders) + { + Debug.LogError("FSR2 requires compute shader support!"); + enabled = false; + return; + } + _helper = GetComponent(); // Set up the original camera to output all of the required FSR2 input resources at the desired resolution @@ -82,10 +89,6 @@ namespace FidelityFX if (enableFP16) flags |= Fsr2.InitializationFlags.EnableFP16Usage; if (enableAutoExposure) flags |= Fsr2.InitializationFlags.EnableAutoExposure; -#if UNITY_EDITOR || DEVELOPMENT_BUILD - flags |= Fsr2.InitializationFlags.EnableDebugChecking; -#endif - _displaySize = new Vector2Int(_renderCamera.pixelWidth, _renderCamera.pixelHeight); Fsr2.GetRenderResolutionFromQualityMode(out var renderWidth, out var renderHeight, _displaySize.x, _displaySize.y, qualityMode); _renderSize = new Vector2Int(renderWidth, renderHeight); diff --git a/Assets/Scripts/Internal/Fsr2.cs b/Assets/Scripts/Internal/Fsr2.cs index 314f448..45cf68d 100644 --- a/Assets/Scripts/Internal/Fsr2.cs +++ b/Assets/Scripts/Internal/Fsr2.cs @@ -23,6 +23,10 @@ namespace FidelityFX else flags &= ~InitializationFlags.EnableDepthInverted; +#if UNITY_EDITOR || DEVELOPMENT_BUILD + flags |= InitializationFlags.EnableDebugChecking; +#endif + Debug.Log($"Setting up FSR2 with render size: {maxRenderSize.x}x{maxRenderSize.y}, display size: {displaySize.x}x{displaySize.y}, flags: {flags}"); var contextDescription = new ContextDescription @@ -99,8 +103,7 @@ namespace FidelityFX public static float Lanczos2(float value) { - return Mathf.Abs(value) < Mathf.Epsilon ? 1.0f : - Mathf.Sin(Mathf.PI * value) / (Mathf.PI * value) * (Mathf.Sin(0.5f * Mathf.PI * value) / (0.5f * Mathf.PI * value)); + return Mathf.Abs(value) < Mathf.Epsilon ? 1.0f : Mathf.Sin(Mathf.PI * value) / (Mathf.PI * value) * (Mathf.Sin(0.5f * Mathf.PI * value) / (0.5f * Mathf.PI * value)); } public enum QualityMode