From 5703e106fec37fb5662d07785be078078615cc53 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Wed, 17 Jul 2024 17:52:06 +0200 Subject: [PATCH] Consolidated texture array-related keywords into a single RP-agnostic global keyword that can be enabled from the HDRP integration. This also removes the need for the core FSR code to check the current render pipeline and hack in a special HDRP mode. --- Runtime/FSR2/Fsr2Pass.cs | 7 --- Runtime/FSR3/Fsr3UpscalerPass.cs | 7 --- Shaders/ffx_fsr2_accumulate_pass.compute | 3 +- .../ffx_fsr2_autogen_reactive_pass.compute | 3 +- ...sr2_compute_luminance_pyramid_pass.compute | 3 +- Shaders/ffx_fsr2_depth_clip_pass.compute | 3 +- Shaders/ffx_fsr2_lock_pass.compute | 2 + Shaders/ffx_fsr2_rcas_pass.compute | 3 +- ...r2_reconstruct_previous_depth_pass.compute | 3 +- Shaders/ffx_fsr2_tcr_autogen_pass.compute | 3 +- .../ffx_fsr3upscaler_accumulate_pass.compute | 3 +- ...fsr3upscaler_autogen_reactive_pass.compute | 3 +- .../ffx_fsr3upscaler_debug_view_pass.compute | 3 +- ...fsr3upscaler_luma_instability_pass.compute | 3 +- ...ffx_fsr3upscaler_luma_pyramid_pass.compute | 3 +- ...x_fsr3upscaler_prepare_inputs_pass.compute | 3 +- ...r3upscaler_prepare_reactivity_pass.compute | 3 +- Shaders/ffx_fsr3upscaler_rcas_pass.compute | 3 +- ...x_fsr3upscaler_shading_change_pass.compute | 3 +- ...scaler_shading_change_pyramid_pass.compute | 3 +- .../ffx_fsr3upscaler_tcr_autogen_pass.compute | 3 +- Shaders/ffx_fsr_unity_common.cginc | 59 +++++++++---------- 22 files changed, 48 insertions(+), 81 deletions(-) diff --git a/Runtime/FSR2/Fsr2Pass.cs b/Runtime/FSR2/Fsr2Pass.cs index 415a353..5114a01 100644 --- a/Runtime/FSR2/Fsr2Pass.cs +++ b/Runtime/FSR2/Fsr2Pass.cs @@ -95,13 +95,6 @@ namespace FidelityFX if ((flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_INVERTED_DEPTH"); if (useLut) ComputeShader.EnableKeyword("FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE"); if ((flags & Fsr2.InitializationFlags.EnableFP16Usage) != 0) ComputeShader.EnableKeyword("FFX_HALF"); - - // Inform the shader which render pipeline we're currently using - var pipeline = GraphicsSettings.currentRenderPipeline; - if (pipeline != null && pipeline.GetType().Name.Contains("HDRenderPipeline")) - { - ComputeShader.EnableKeyword("UNITY_FSR_HDRP"); - } } } diff --git a/Runtime/FSR3/Fsr3UpscalerPass.cs b/Runtime/FSR3/Fsr3UpscalerPass.cs index 3825d1e..3146142 100644 --- a/Runtime/FSR3/Fsr3UpscalerPass.cs +++ b/Runtime/FSR3/Fsr3UpscalerPass.cs @@ -93,13 +93,6 @@ namespace FidelityFX if ((flags & Fsr3Upscaler.InitializationFlags.EnableDepthInverted) != 0) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH"); if (useLut) ComputeShader.EnableKeyword("FFX_FSR3UPSCALER_OPTION_REPROJECT_USE_LANCZOS_TYPE"); if ((flags & Fsr3Upscaler.InitializationFlags.EnableFP16Usage) != 0) ComputeShader.EnableKeyword("FFX_HALF"); - - // Inform the shader which render pipeline we're currently using - var pipeline = GraphicsSettings.currentRenderPipeline; - if (pipeline != null && pipeline.GetType().Name.Contains("HDRenderPipeline")) - { - ComputeShader.EnableKeyword("UNITY_FSR_HDRP"); - } } } diff --git a/Shaders/ffx_fsr2_accumulate_pass.compute b/Shaders/ffx_fsr2_accumulate_pass.compute index bddc926..63532d7 100644 --- a/Shaders/ffx_fsr2_accumulate_pass.compute +++ b/Shaders/ffx_fsr2_accumulate_pass.compute @@ -28,8 +28,7 @@ #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH #pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr2_autogen_reactive_pass.compute b/Shaders/ffx_fsr2_autogen_reactive_pass.compute index 9a9a681..6bc2301 100644 --- a/Shaders/ffx_fsr2_autogen_reactive_pass.compute +++ b/Shaders/ffx_fsr2_autogen_reactive_pass.compute @@ -25,8 +25,7 @@ #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute b/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute index 6fd1075..7058cc5 100644 --- a/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute +++ b/Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute @@ -25,8 +25,7 @@ #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr2_depth_clip_pass.compute b/Shaders/ffx_fsr2_depth_clip_pass.compute index b578aad..582ca6b 100644 --- a/Shaders/ffx_fsr2_depth_clip_pass.compute +++ b/Shaders/ffx_fsr2_depth_clip_pass.compute @@ -25,8 +25,7 @@ #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr2_lock_pass.compute b/Shaders/ffx_fsr2_lock_pass.compute index aed4051..fb12d2c 100644 --- a/Shaders/ffx_fsr2_lock_pass.compute +++ b/Shaders/ffx_fsr2_lock_pass.compute @@ -25,6 +25,8 @@ #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY + #include "ffx_fsr_unity_common.cginc" #include "shaders/ffx_fsr2_lock_pass.hlsl" diff --git a/Shaders/ffx_fsr2_rcas_pass.compute b/Shaders/ffx_fsr2_rcas_pass.compute index 904afaf..e6ac7df 100644 --- a/Shaders/ffx_fsr2_rcas_pass.compute +++ b/Shaders/ffx_fsr2_rcas_pass.compute @@ -24,8 +24,7 @@ #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute b/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute index 621b351..12f2ec3 100644 --- a/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute +++ b/Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute @@ -26,8 +26,7 @@ #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr2_tcr_autogen_pass.compute b/Shaders/ffx_fsr2_tcr_autogen_pass.compute index 3805e8d..5d2668a 100644 --- a/Shaders/ffx_fsr2_tcr_autogen_pass.compute +++ b/Shaders/ffx_fsr2_tcr_autogen_pass.compute @@ -25,8 +25,7 @@ #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_accumulate_pass.compute b/Shaders/ffx_fsr3upscaler_accumulate_pass.compute index 6b45375..a8d6864 100644 --- a/Shaders/ffx_fsr3upscaler_accumulate_pass.compute +++ b/Shaders/ffx_fsr3upscaler_accumulate_pass.compute @@ -26,8 +26,7 @@ #pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_APPLY_SHARPENING -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute b/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute index af09d05..500352a 100644 --- a/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute +++ b/Shaders/ffx_fsr3upscaler_autogen_reactive_pass.compute @@ -22,8 +22,7 @@ #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_debug_view_pass.compute b/Shaders/ffx_fsr3upscaler_debug_view_pass.compute index f8895ad..027e414 100644 --- a/Shaders/ffx_fsr3upscaler_debug_view_pass.compute +++ b/Shaders/ffx_fsr3upscaler_debug_view_pass.compute @@ -22,8 +22,7 @@ #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute b/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute index 0ab63e9..5cffc66 100644 --- a/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute +++ b/Shaders/ffx_fsr3upscaler_luma_instability_pass.compute @@ -22,8 +22,7 @@ #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute b/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute index 2a28e32..347b0d6 100644 --- a/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute +++ b/Shaders/ffx_fsr3upscaler_luma_pyramid_pass.compute @@ -22,8 +22,7 @@ #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute b/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute index 898e7af..b71ea5d 100644 --- a/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute +++ b/Shaders/ffx_fsr3upscaler_prepare_inputs_pass.compute @@ -24,8 +24,7 @@ #pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_LOW_RESOLUTION_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute b/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute index cdf3e37..ebf4e91 100644 --- a/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute +++ b/Shaders/ffx_fsr3upscaler_prepare_reactivity_pass.compute @@ -22,8 +22,7 @@ #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_rcas_pass.compute b/Shaders/ffx_fsr3upscaler_rcas_pass.compute index 247170b..282a9ae 100644 --- a/Shaders/ffx_fsr3upscaler_rcas_pass.compute +++ b/Shaders/ffx_fsr3upscaler_rcas_pass.compute @@ -20,8 +20,7 @@ #pragma kernel CS -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_shading_change_pass.compute b/Shaders/ffx_fsr3upscaler_shading_change_pass.compute index 6624181..34c3ade 100644 --- a/Shaders/ffx_fsr3upscaler_shading_change_pass.compute +++ b/Shaders/ffx_fsr3upscaler_shading_change_pass.compute @@ -22,8 +22,7 @@ #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute b/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute index 59db203..ffe5bfe 100644 --- a/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute +++ b/Shaders/ffx_fsr3upscaler_shading_change_pyramid_pass.compute @@ -22,8 +22,7 @@ #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute b/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute index 6c09a1e..952c052 100644 --- a/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute +++ b/Shaders/ffx_fsr3upscaler_tcr_autogen_pass.compute @@ -23,8 +23,7 @@ #pragma multi_compile_local __ FFX_HALF #pragma multi_compile_local __ FFX_FSR3UPSCALER_OPTION_JITTERED_MOTION_VECTORS -#pragma multi_compile_local __ UNITY_FSR_HDRP -#pragma multi_compile __ DISABLE_TEXTURE2D_X_ARRAY +#pragma multi_compile __ UNITY_FSR_TEXTURE2D_X_ARRAY #include "ffx_fsr_unity_common.cginc" diff --git a/Shaders/ffx_fsr_unity_common.cginc b/Shaders/ffx_fsr_unity_common.cginc index 8b77b56..b1bcb5c 100644 --- a/Shaders/ffx_fsr_unity_common.cginc +++ b/Shaders/ffx_fsr_unity_common.cginc @@ -46,40 +46,37 @@ #endif // Workaround for HDRP using texture arrays for its camera buffers on some platforms -// The below defines are copied from: Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/TextureXR.hlsl -#if defined(UNITY_FSR_HDRP) - // Must be in sync with C# with property useTexArray in TextureXR.cs - #if ((defined(SHADER_API_D3D11) || defined(SHADER_API_D3D12)) && !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_GAMECORE)) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN) - #define UNITY_TEXTURE2D_X_ARRAY_SUPPORTED - #endif - - // Control if TEXTURE2D_X macros will expand to texture arrays - #if defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED) && !defined(DISABLE_TEXTURE2D_X_ARRAY) - #define USE_TEXTURE2D_X_AS_ARRAY - #endif +// The below defines are adapted from: Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureXR.hlsl +#if ((defined(SHADER_API_D3D11) || defined(SHADER_API_D3D12)) && !defined(SHADER_API_XBOXONE) && !defined(SHADER_API_GAMECORE)) || defined(SHADER_API_PSSL) || defined(SHADER_API_VULKAN) + #define UNITY_TEXTURE2D_X_ARRAY_SUPPORTED +#endif - // Early defines for single-pass instancing - #if defined(STEREO_INSTANCING_ON) && defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED) - #define UNITY_STEREO_INSTANCING_ENABLED - #endif +// Control if TEXTURE2D_X macros will expand to texture arrays +#if defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED) && defined(UNITY_FSR_TEXTURE2D_X_ARRAY) + #define USE_TEXTURE2D_X_AS_ARRAY +#endif - // Helper macros to handle XR single-pass with Texture2DArray - #if defined(USE_TEXTURE2D_X_AS_ARRAY) +// Early defines for single-pass instancing +#if defined(STEREO_INSTANCING_ON) && defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED) + #define UNITY_STEREO_INSTANCING_ENABLED +#endif - // Only single-pass stereo instancing used array indexing - #if defined(UNITY_STEREO_INSTANCING_ENABLED) - static uint unity_StereoEyeIndex; - #define SLICE_ARRAY_INDEX unity_StereoEyeIndex - #else - #define SLICE_ARRAY_INDEX 0 - #endif +// Helper macros to handle XR single-pass with Texture2DArray +#if defined(USE_TEXTURE2D_X_AS_ARRAY) - // Declare and sample camera buffers as texture arrays - #define UNITY_FSR_TEX2D(type) Texture2DArray - #define UNITY_FSR_RWTEX2D(type) RWTexture2DArray - #define UNITY_FSR_POS(pxPos) FfxUInt32x3(pxPos, SLICE_ARRAY_INDEX) - #define UNITY_FSR_UV(uv) FfxFloat32x3(uv, SLICE_ARRAY_INDEX) - #define UNITY_FSR_GETDIMS(tex, w, h) { FfxUInt32 uElements; (tex).GetDimensions((w), (h), uElements); } - + // Only single-pass stereo instancing used array indexing + #if defined(UNITY_STEREO_INSTANCING_ENABLED) + static uint unity_StereoEyeIndex; + #define SLICE_ARRAY_INDEX unity_StereoEyeIndex + #else + #define SLICE_ARRAY_INDEX 0 #endif + + // Declare and sample camera buffers as texture arrays + #define UNITY_FSR_TEX2D(type) Texture2DArray + #define UNITY_FSR_RWTEX2D(type) RWTexture2DArray + #define UNITY_FSR_POS(pxPos) FfxUInt32x3(pxPos, SLICE_ARRAY_INDEX) + #define UNITY_FSR_UV(uv) FfxFloat32x3(uv, SLICE_ARRAY_INDEX) + #define UNITY_FSR_GETDIMS(tex, w, h) { FfxUInt32 uElements; (tex).GetDimensions((w), (h), uElements); } + #endif