Browse Source
Made all the ASR shader keywords global and encapsulated all of the keyword management into a separate class, which will enable and disable keywords globally based on the initialization flags and dispatch parameters.
asr-console
Made all the ASR shader keywords global and encapsulated all of the keyword management into a separate class, which will enable and disable keywords globally based on the initialization flags and dispatch parameters.
asr-console
6 changed files with 148 additions and 76 deletions
-
4Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrContext.cs
-
124Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrKeywords.cs
-
3Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrKeywords.cs.meta
-
77Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Runtime/AsrPass.cs
-
8Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_compute_luminance_pyramid_pass.compute
-
8Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_lock_pass.compute
@ -0,0 +1,124 @@ |
|||||
|
using UnityEngine; |
||||
|
using UnityEngine.Rendering; |
||||
|
|
||||
|
namespace ArmASR |
||||
|
{ |
||||
|
public class AsrKeywords |
||||
|
{ |
||||
|
private static readonly string OptionHalfPrecision = "FFXM_HALF"; |
||||
|
private static readonly string OptionHdrColorInput = "FFXM_FSR2_OPTION_HDR_COLOR_INPUT"; |
||||
|
private static readonly string OptionLowResolutionMotionVectors = "FFXM_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS"; |
||||
|
private static readonly string OptionJitteredMotionVectors = "FFXM_FSR2_OPTION_JITTERED_MOTION_VECTORS"; |
||||
|
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"; |
||||
|
|
||||
|
#if UNITY_2021_2_OR_NEWER
|
||||
|
private readonly GlobalKeyword _halfPrecisionKeyword; |
||||
|
private readonly GlobalKeyword _hdrColorInputKeyword; |
||||
|
private readonly GlobalKeyword _lowResMotionVectorsKeyword; |
||||
|
private readonly GlobalKeyword _jitteredMotionVectorsKeyword; |
||||
|
private readonly GlobalKeyword _invertedDepthKeyword; |
||||
|
private readonly GlobalKeyword _reprojectUseLutKeyword; |
||||
|
private readonly GlobalKeyword _applySharpeningKeyword; |
||||
|
#endif
|
||||
|
|
||||
|
public AsrKeywords() |
||||
|
{ |
||||
|
#if UNITY_2021_2_OR_NEWER
|
||||
|
_halfPrecisionKeyword = new GlobalKeyword(OptionHalfPrecision); |
||||
|
_hdrColorInputKeyword = new GlobalKeyword(OptionHdrColorInput); |
||||
|
_lowResMotionVectorsKeyword = new GlobalKeyword(OptionLowResolutionMotionVectors); |
||||
|
_jitteredMotionVectorsKeyword = new GlobalKeyword(OptionJitteredMotionVectors); |
||||
|
_invertedDepthKeyword = new GlobalKeyword(OptionInvertedDepth); |
||||
|
_reprojectUseLutKeyword = new GlobalKeyword(OptionReprojectUseLut); |
||||
|
_applySharpeningKeyword = new GlobalKeyword(OptionApplySharpening); |
||||
|
#endif
|
||||
|
} |
||||
|
|
||||
|
public void ApplyKeywords(CommandBuffer commandBuffer, 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+
|
||||
|
if (SystemInfo.computeSubGroupSize == 64) |
||||
|
{ |
||||
|
useLut = true; |
||||
|
} |
||||
|
#endif
|
||||
|
|
||||
|
// This matches the permutation rules from the CreatePipeline* functions
|
||||
|
#if UNITY_2021_2_OR_NEWER
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableFP16Usage) != 0) |
||||
|
commandBuffer.EnableKeyword(_halfPrecisionKeyword); |
||||
|
else |
||||
|
commandBuffer.DisableKeyword(_halfPrecisionKeyword); |
||||
|
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableHighDynamicRange) != 0) |
||||
|
commandBuffer.EnableKeyword(_hdrColorInputKeyword); |
||||
|
else |
||||
|
commandBuffer.DisableKeyword(_hdrColorInputKeyword); |
||||
|
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) |
||||
|
commandBuffer.EnableKeyword(_lowResMotionVectorsKeyword); |
||||
|
else |
||||
|
commandBuffer.DisableKeyword(_lowResMotionVectorsKeyword); |
||||
|
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) |
||||
|
commandBuffer.EnableKeyword(_jitteredMotionVectorsKeyword); |
||||
|
else |
||||
|
commandBuffer.DisableKeyword(_jitteredMotionVectorsKeyword); |
||||
|
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableDepthInverted) != 0) |
||||
|
commandBuffer.EnableKeyword(_invertedDepthKeyword); |
||||
|
else |
||||
|
commandBuffer.DisableKeyword(_invertedDepthKeyword); |
||||
|
|
||||
|
if (useLut) |
||||
|
commandBuffer.EnableKeyword(_reprojectUseLutKeyword); |
||||
|
else |
||||
|
commandBuffer.DisableKeyword(_reprojectUseLutKeyword); |
||||
|
|
||||
|
if (dispatchParams.EnableSharpening) |
||||
|
commandBuffer.EnableKeyword(_applySharpeningKeyword); |
||||
|
else |
||||
|
commandBuffer.DisableKeyword(_applySharpeningKeyword); |
||||
|
#else
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableFP16Usage) != 0) |
||||
|
commandBuffer.EnableShaderKeyword(OptionHalfPrecision); |
||||
|
else |
||||
|
commandBuffer.DisableShaderKeyword(OptionHalfPrecision); |
||||
|
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableHighDynamicRange) != 0) |
||||
|
commandBuffer.EnableShaderKeyword(OptionHdrColorInput); |
||||
|
else |
||||
|
commandBuffer.DisableShaderKeyword(OptionHdrColorInput); |
||||
|
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableDisplayResolutionMotionVectors) == 0) |
||||
|
commandBuffer.EnableShaderKeyword(OptionLowResolutionMotionVectors); |
||||
|
else |
||||
|
commandBuffer.DisableShaderKeyword(OptionLowResolutionMotionVectors); |
||||
|
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableMotionVectorsJitterCancellation) != 0) |
||||
|
commandBuffer.EnableShaderKeyword(OptionJitteredMotionVectors); |
||||
|
else |
||||
|
commandBuffer.DisableShaderKeyword(OptionJitteredMotionVectors); |
||||
|
|
||||
|
if ((initFlags & Asr.InitializationFlags.EnableDepthInverted) != 0) |
||||
|
commandBuffer.EnableShaderKeyword(OptionInvertedDepth); |
||||
|
else |
||||
|
commandBuffer.DisableShaderKeyword(OptionInvertedDepth); |
||||
|
|
||||
|
if (useLut) |
||||
|
commandBuffer.EnableShaderKeyword(OptionReprojectUseLut); |
||||
|
else |
||||
|
commandBuffer.DisableShaderKeyword(OptionReprojectUseLut); |
||||
|
|
||||
|
if (dispatchParams.EnableSharpening) |
||||
|
commandBuffer.EnableShaderKeyword(OptionApplySharpening); |
||||
|
else |
||||
|
commandBuffer.DisableShaderKeyword(OptionApplySharpening); |
||||
|
#endif
|
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,3 @@ |
|||||
|
fileFormatVersion: 2 |
||||
|
guid: a2636bdd1878444fb3d3475610d379df |
||||
|
timeCreated: 1742641520 |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue