Browse Source

Added keywords for balanced/performance presets and GLES support

asr-console
Nico de Poel 11 months ago
parent
commit
20a930097e
  1. 2
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs
  2. 40
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrKeywords.cs
  3. 5
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc

2
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs

@ -128,7 +128,7 @@ namespace ArmASR
if (dispatchParams.UseTextureArrays) if (dispatchParams.UseTextureArrays)
commandBuffer.EnableShaderKeyword("UNITY_FFXM_TEXTURE2D_X_ARRAY"); commandBuffer.EnableShaderKeyword("UNITY_FFXM_TEXTURE2D_X_ARRAY");
_keywords.ApplyKeywords(commandBuffer, _contextDescription.Flags, dispatchParams);
_keywords.ApplyKeywords(commandBuffer, _contextDescription.Variant, _contextDescription.Flags, dispatchParams);
if (_firstExecution) if (_firstExecution)
{ {

40
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 OptionInvertedDepth = "FFXM_FSR2_OPTION_INVERTED_DEPTH";
private static readonly string OptionReprojectUseLut = "FFXM_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE"; 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 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 #if UNITY_2021_2_OR_NEWER
private readonly GlobalKeyword _halfPrecisionKeyword; private readonly GlobalKeyword _halfPrecisionKeyword;
@ -21,6 +23,8 @@ namespace ArmASR
private readonly GlobalKeyword _invertedDepthKeyword; private readonly GlobalKeyword _invertedDepthKeyword;
private readonly GlobalKeyword _reprojectUseLutKeyword; private readonly GlobalKeyword _reprojectUseLutKeyword;
private readonly GlobalKeyword _applySharpeningKeyword; private readonly GlobalKeyword _applySharpeningKeyword;
private readonly GlobalKeyword _balancedPresetKeyword;
private readonly GlobalKeyword _performancePresetKeyword;
#endif #endif
public AsrKeywords() public AsrKeywords()
@ -33,10 +37,12 @@ namespace ArmASR
_invertedDepthKeyword = GlobalKeyword.Create(OptionInvertedDepth); _invertedDepthKeyword = GlobalKeyword.Create(OptionInvertedDepth);
_reprojectUseLutKeyword = GlobalKeyword.Create(OptionReprojectUseLut); _reprojectUseLutKeyword = GlobalKeyword.Create(OptionReprojectUseLut);
_applySharpeningKeyword = GlobalKeyword.Create(OptionApplySharpening); _applySharpeningKeyword = GlobalKeyword.Create(OptionApplySharpening);
_balancedPresetKeyword = GlobalKeyword.Create(OptionBalancedPreset);
_performancePresetKeyword = GlobalKeyword.Create(OptionPerformancePreset);
#endif #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; bool useLut = false;
#if UNITY_2022_1_OR_NEWER // This will also work in 2020.3.43+ and 2021.3.14+ #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); commandBuffer.EnableKeyword(_applySharpeningKeyword);
else else
commandBuffer.DisableKeyword(_applySharpeningKeyword); 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 #else
if ((initFlags & Asr.InitializationFlags.EnableFP16Usage) != 0) if ((initFlags & Asr.InitializationFlags.EnableFP16Usage) != 0)
commandBuffer.EnableShaderKeyword(OptionHalfPrecision); commandBuffer.EnableShaderKeyword(OptionHalfPrecision);
@ -117,6 +139,22 @@ namespace ArmASR
commandBuffer.EnableShaderKeyword(OptionApplySharpening); commandBuffer.EnableShaderKeyword(OptionApplySharpening);
else else
commandBuffer.DisableShaderKeyword(OptionApplySharpening); 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 #endif
} }

5
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: 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 #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 // Work around the lack of texture atomics on Metal
#if defined(SHADER_API_METAL) #if defined(SHADER_API_METAL)
#define InterlockedAdd(dest, val, orig) { (orig) = (dest); (dest) += (val); } #define InterlockedAdd(dest, val, orig) { (orig) = (dest); (dest) += (val); }

Loading…
Cancel
Save