From 20a930097ef9780b736b49b90fe1969b85a48fb8 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Sat, 22 Mar 2025 15:24:59 +0100 Subject: [PATCH] Added keywords for balanced/performance presets and GLES support --- .../Upscaling/ASR/Runtime/AsrContext.cs | 2 +- .../Upscaling/ASR/Runtime/AsrKeywords.cs | 40 ++++++++++++++++++- .../ASR/Shaders/ffxm_fsr2_common.cginc | 5 +++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs index a63ac5c..1424b56 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs @@ -128,7 +128,7 @@ namespace ArmASR if (dispatchParams.UseTextureArrays) commandBuffer.EnableShaderKeyword("UNITY_FFXM_TEXTURE2D_X_ARRAY"); - _keywords.ApplyKeywords(commandBuffer, _contextDescription.Flags, dispatchParams); + _keywords.ApplyKeywords(commandBuffer, _contextDescription.Variant, _contextDescription.Flags, dispatchParams); if (_firstExecution) { diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrKeywords.cs b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrKeywords.cs index f80c75e..43de5e1 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrKeywords.cs +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrKeywords.cs @@ -12,6 +12,8 @@ namespace ArmASR private static readonly string OptionInvertedDepth = "FFXM_FSR2_OPTION_INVERTED_DEPTH"; private static readonly string OptionReprojectUseLut = "FFXM_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE"; private static readonly string OptionApplySharpening = "FFXM_FSR2_OPTION_APPLY_SHARPENING"; + private static readonly string OptionBalancedPreset = "FFXM_FSR2_OPTION_SHADER_OPT_BALANCED"; + private static readonly string OptionPerformancePreset = "FFXM_FSR2_OPTION_SHADER_OPT_PERFORMANCE"; #if UNITY_2021_2_OR_NEWER private readonly GlobalKeyword _halfPrecisionKeyword; @@ -21,6 +23,8 @@ namespace ArmASR private readonly GlobalKeyword _invertedDepthKeyword; private readonly GlobalKeyword _reprojectUseLutKeyword; private readonly GlobalKeyword _applySharpeningKeyword; + private readonly GlobalKeyword _balancedPresetKeyword; + private readonly GlobalKeyword _performancePresetKeyword; #endif public AsrKeywords() @@ -33,10 +37,12 @@ namespace ArmASR _invertedDepthKeyword = GlobalKeyword.Create(OptionInvertedDepth); _reprojectUseLutKeyword = GlobalKeyword.Create(OptionReprojectUseLut); _applySharpeningKeyword = GlobalKeyword.Create(OptionApplySharpening); + _balancedPresetKeyword = GlobalKeyword.Create(OptionBalancedPreset); + _performancePresetKeyword = GlobalKeyword.Create(OptionPerformancePreset); #endif } - public void ApplyKeywords(CommandBuffer commandBuffer, Asr.InitializationFlags initFlags, in Asr.DispatchDescription dispatchParams) + public void ApplyKeywords(CommandBuffer commandBuffer, Asr.Variant variant, Asr.InitializationFlags initFlags, in Asr.DispatchDescription dispatchParams) { bool useLut = false; #if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+ @@ -82,6 +88,22 @@ namespace ArmASR commandBuffer.EnableKeyword(_applySharpeningKeyword); else commandBuffer.DisableKeyword(_applySharpeningKeyword); + + switch (variant) + { + case Asr.Variant.Quality: + commandBuffer.DisableKeyword(_balancedPresetKeyword); + commandBuffer.DisableKeyword(_performancePresetKeyword); + break; + case Asr.Variant.Balanced: + commandBuffer.EnableKeyword(_balancedPresetKeyword); + commandBuffer.DisableKeyword(_performancePresetKeyword); + break; + case Asr.Variant.Performance: + commandBuffer.EnableKeyword(_balancedPresetKeyword); + commandBuffer.EnableKeyword(_performancePresetKeyword); + break; + } #else if ((initFlags & Asr.InitializationFlags.EnableFP16Usage) != 0) commandBuffer.EnableShaderKeyword(OptionHalfPrecision); @@ -117,6 +139,22 @@ namespace ArmASR commandBuffer.EnableShaderKeyword(OptionApplySharpening); else commandBuffer.DisableShaderKeyword(OptionApplySharpening); + + switch (variant) + { + case Asr.Variant.Quality: + commandBuffer.DisableShaderKeyword(OptionBalancedPreset); + commandBuffer.DisableShaderKeyword(OptionPerformancePreset); + break; + case Asr.Variant.Balanced: + commandBuffer.EnableShaderKeyword(OptionBalancedPreset); + commandBuffer.DisableShaderKeyword(OptionPerformancePreset); + break; + case Asr.Variant.Performance: + commandBuffer.EnableShaderKeyword(OptionBalancedPreset); + commandBuffer.EnableShaderKeyword(OptionPerformancePreset); + break; + } #endif } diff --git a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc index 4d8ce66..a108327 100644 --- a/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc +++ b/Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc @@ -3,6 +3,11 @@ #pragma warning(disable: 3205) // Conversion from larger type to smaller, possible loss of data #pragma warning(disable: 3556) // Integer divides might be much slower, try using uints if possible +// ASR has some special code paths for OpenGL ES 3.2 +#if defined(SHADER_API_GLES3) +#define FFXM_SHADER_PLATFORM_GLES_3_2 (1) +#endif + // Work around the lack of texture atomics on Metal #if defined(SHADER_API_METAL) #define InterlockedAdd(dest, val, orig) { (orig) = (dest); (dest) += (val); }