diff --git a/Assets/Resources/FSR2/ffx_fsr2_accumulate_pass.compute b/Assets/Resources/FSR2/ffx_fsr2_accumulate_pass.compute index 9dd16c6..a359485 100644 --- a/Assets/Resources/FSR2/ffx_fsr2_accumulate_pass.compute +++ b/Assets/Resources/FSR2/ffx_fsr2_accumulate_pass.compute @@ -28,6 +28,8 @@ #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH #pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING +#pragma multi_compile_local __ UNITY_FSR2_HDRP + #include "ffx_fsr2_unity_common.cginc" // Ensure the correct value is defined for this keyword, as it is used to select one of multiple sampler functions diff --git a/Assets/Resources/FSR2/ffx_fsr2_autogen_reactive_pass.compute b/Assets/Resources/FSR2/ffx_fsr2_autogen_reactive_pass.compute index d21d3cd..d27a02d 100644 --- a/Assets/Resources/FSR2/ffx_fsr2_autogen_reactive_pass.compute +++ b/Assets/Resources/FSR2/ffx_fsr2_autogen_reactive_pass.compute @@ -21,12 +21,11 @@ #pragma kernel CS #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE -#pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT #pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING + +#pragma multi_compile_local __ UNITY_FSR2_HDRP #include "ffx_fsr2_unity_common.cginc" diff --git a/Assets/Resources/FSR2/ffx_fsr2_compute_luminance_pyramid_pass.compute b/Assets/Resources/FSR2/ffx_fsr2_compute_luminance_pyramid_pass.compute index bce3c6f..385dfe4 100644 --- a/Assets/Resources/FSR2/ffx_fsr2_compute_luminance_pyramid_pass.compute +++ b/Assets/Resources/FSR2/ffx_fsr2_compute_luminance_pyramid_pass.compute @@ -21,12 +21,11 @@ #pragma kernel CS //#pragma multi_compile_local __ FFX_HALF // causes a hard-coded error message from the shader include ¯\_(ツ)_/¯ -#pragma multi_compile_local __ FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE -#pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT #pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING + +#pragma multi_compile_local __ UNITY_FSR2_HDRP #include "ffx_fsr2_unity_common.cginc" diff --git a/Assets/Resources/FSR2/ffx_fsr2_depth_clip_pass.compute b/Assets/Resources/FSR2/ffx_fsr2_depth_clip_pass.compute index ba15fd2..4e41933 100644 --- a/Assets/Resources/FSR2/ffx_fsr2_depth_clip_pass.compute +++ b/Assets/Resources/FSR2/ffx_fsr2_depth_clip_pass.compute @@ -21,12 +21,11 @@ #pragma kernel CS #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE -#pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT #pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING + +#pragma multi_compile_local __ UNITY_FSR2_HDRP #include "ffx_fsr2_unity_common.cginc" diff --git a/Assets/Resources/FSR2/ffx_fsr2_lock_pass.compute b/Assets/Resources/FSR2/ffx_fsr2_lock_pass.compute index a213901..dc654cb 100644 --- a/Assets/Resources/FSR2/ffx_fsr2_lock_pass.compute +++ b/Assets/Resources/FSR2/ffx_fsr2_lock_pass.compute @@ -21,12 +21,11 @@ #pragma kernel CS #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE -#pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT #pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING + +#pragma multi_compile_local __ UNITY_FSR2_HDRP #include "ffx_fsr2_unity_common.cginc" diff --git a/Assets/Resources/FSR2/ffx_fsr2_rcas_pass.compute b/Assets/Resources/FSR2/ffx_fsr2_rcas_pass.compute index a9e8b70..94f1704 100644 --- a/Assets/Resources/FSR2/ffx_fsr2_rcas_pass.compute +++ b/Assets/Resources/FSR2/ffx_fsr2_rcas_pass.compute @@ -20,12 +20,11 @@ #pragma kernel CS -#pragma multi_compile_local __ FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE -#pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT #pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING + +#pragma multi_compile_local __ UNITY_FSR2_HDRP #include "ffx_fsr2_unity_common.cginc" diff --git a/Assets/Resources/FSR2/ffx_fsr2_reconstruct_previous_depth_pass.compute b/Assets/Resources/FSR2/ffx_fsr2_reconstruct_previous_depth_pass.compute index 794f635..c6cc99f 100644 --- a/Assets/Resources/FSR2/ffx_fsr2_reconstruct_previous_depth_pass.compute +++ b/Assets/Resources/FSR2/ffx_fsr2_reconstruct_previous_depth_pass.compute @@ -21,12 +21,12 @@ #pragma kernel CS #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE #pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT #pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING + +#pragma multi_compile_local __ UNITY_FSR2_HDRP #include "ffx_fsr2_unity_common.cginc" diff --git a/Assets/Resources/FSR2/ffx_fsr2_tcr_autogen_pass.compute b/Assets/Resources/FSR2/ffx_fsr2_tcr_autogen_pass.compute index 9c71006..62d386b 100644 --- a/Assets/Resources/FSR2/ffx_fsr2_tcr_autogen_pass.compute +++ b/Assets/Resources/FSR2/ffx_fsr2_tcr_autogen_pass.compute @@ -21,12 +21,11 @@ #pragma kernel CS #pragma multi_compile_local __ FFX_HALF -#pragma multi_compile_local __ FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE -#pragma multi_compile_local __ FFX_FSR2_OPTION_HDR_COLOR_INPUT #pragma multi_compile_local __ FFX_FSR2_OPTION_LOW_RESOLUTION_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS #pragma multi_compile_local __ FFX_FSR2_OPTION_INVERTED_DEPTH -#pragma multi_compile_local __ FFX_FSR2_OPTION_APPLY_SHARPENING + +#pragma multi_compile_local __ UNITY_FSR2_HDRP #include "ffx_fsr2_unity_common.cginc" diff --git a/Assets/Resources/FSR2/ffx_fsr2_unity_common.cginc b/Assets/Resources/FSR2/ffx_fsr2_unity_common.cginc index 4d2985b..98c5b17 100644 --- a/Assets/Resources/FSR2/ffx_fsr2_unity_common.cginc +++ b/Assets/Resources/FSR2/ffx_fsr2_unity_common.cginc @@ -43,3 +43,39 @@ #define InterlockedMin(dest, val) { (dest) = min((dest), (val)); } #define InterlockedMax(dest, val) { (dest) = max((dest), (val)); } #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_FSR2_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 + + // Early defines for single-pass instancing + #if defined(STEREO_INSTANCING_ON) && defined(UNITY_TEXTURE2D_X_ARRAY_SUPPORTED) + #define UNITY_STEREO_INSTANCING_ENABLED + #endif + + // Helper macros to handle XR single-pass with Texture2DArray + #if defined(USE_TEXTURE2D_X_AS_ARRAY) + + // Only single-pass stereo instancing used array indexing + #if defined(UNITY_STEREO_INSTANCING_ENABLED) + #define SLICE_ARRAY_INDEX unity_StereoEyeIndex + #else + #define SLICE_ARRAY_INDEX 0 + #endif + + // Declare and sample camera buffers as texture arrays + #define UNITY_FSR2_TEX2D(type) Texture2DArray + #define UNITY_FSR2_POS(pxPos) FfxUInt32x3(pxPos, SLICE_ARRAY_INDEX) + #define UNITY_FSR2_UV(uv) FfxFloat32x3(uv, SLICE_ARRAY_INDEX) + + #endif +#endif diff --git a/Assets/Resources/FSR2/shaders/ffx_fsr2_callbacks_hlsl.h b/Assets/Resources/FSR2/shaders/ffx_fsr2_callbacks_hlsl.h index 1f872c8..5df5a4a 100644 --- a/Assets/Resources/FSR2/shaders/ffx_fsr2_callbacks_hlsl.h +++ b/Assets/Resources/FSR2/shaders/ffx_fsr2_callbacks_hlsl.h @@ -124,6 +124,17 @@ #endif // #if FFX_FSR2_EMBED_ROOTSIG #endif // #if defined(FFX_GPU) +// Declare and sample camera buffers as regular textures, unless overridden +#if !defined(UNITY_FSR2_TEX2D) +#define UNITY_FSR2_TEX2D(type) Texture2D +#endif +#if !defined(UNITY_FSR2_POS) +#define UNITY_FSR2_POS(pxPos) (pxPos) +#endif +#if !defined(UNITY_FSR2_UV) +#define UNITY_FSR2_UV(uv) (uv) +#endif + /* Define getter functions in the order they are defined in the CB! */ FfxInt32x2 RenderSize() { @@ -227,9 +238,9 @@ SamplerState s_LinearClamp : register(s1); // SRVs #if defined(FFX_INTERNAL) Texture2D r_input_opaque_only : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_OPAQUE_ONLY); - Texture2D r_input_color_jittered : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_COLOR); - Texture2D r_input_motion_vectors : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_MOTION_VECTORS); - Texture2D r_input_depth : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_DEPTH); + UNITY_FSR2_TEX2D(FfxFloat32x4) r_input_color_jittered : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_COLOR); + UNITY_FSR2_TEX2D(FfxFloat32x4) r_input_motion_vectors : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_MOTION_VECTORS); + UNITY_FSR2_TEX2D(FfxFloat32) r_input_depth : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_DEPTH); Texture2D r_input_exposure : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_EXPOSURE); Texture2D r_auto_exposure : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_AUTO_EXPOSURE); Texture2D r_reactive_mask : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_REACTIVE_MASK); @@ -280,16 +291,16 @@ SamplerState s_LinearClamp : register(s1); #else // #if defined(FFX_INTERNAL) #if defined FSR2_BIND_SRV_INPUT_COLOR - Texture2D r_input_color_jittered : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_COLOR); + UNITY_FSR2_TEX2D(FfxFloat32x4) r_input_color_jittered : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_COLOR); #endif #if defined FSR2_BIND_SRV_INPUT_OPAQUE_ONLY Texture2D r_input_opaque_only : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY); #endif #if defined FSR2_BIND_SRV_INPUT_MOTION_VECTORS - Texture2D r_input_motion_vectors : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_MOTION_VECTORS); + UNITY_FSR2_TEX2D(FfxFloat32x4) r_input_motion_vectors : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_MOTION_VECTORS); #endif #if defined FSR2_BIND_SRV_INPUT_DEPTH - Texture2D r_input_depth : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_DEPTH); + UNITY_FSR2_TEX2D(FfxFloat32) r_input_depth : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_DEPTH); #endif #if defined FSR2_BIND_SRV_INPUT_EXPOSURE Texture2D r_input_exposure : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_EXPOSURE); @@ -437,14 +448,14 @@ FfxFloat32 SampleMipLuma(FfxFloat32x2 fUV, FfxUInt32 mipLevel) #if defined(FSR2_BIND_SRV_INPUT_DEPTH) || defined(FFX_INTERNAL) FfxFloat32 LoadInputDepth(FfxUInt32x2 iPxPos) { - return r_input_depth[iPxPos]; + return r_input_depth[UNITY_FSR2_POS(iPxPos)]; } #endif #if defined(FSR2_BIND_SRV_INPUT_DEPTH) || defined(FFX_INTERNAL) FfxFloat32 SampleInputDepth(FfxFloat32x2 fUV) { - return r_input_depth.SampleLevel(s_LinearClamp, fUV, 0).x; + return r_input_depth.SampleLevel(s_LinearClamp, UNITY_FSR2_UV(fUV), 0).x; } #endif @@ -465,14 +476,14 @@ FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos) #if defined(FSR2_BIND_SRV_INPUT_COLOR) || defined(FFX_INTERNAL) FfxFloat32x3 LoadInputColor(FfxUInt32x2 iPxPos) { - return r_input_color_jittered[iPxPos].rgb; + return r_input_color_jittered[UNITY_FSR2_POS(iPxPos)].rgb; } #endif #if defined(FSR2_BIND_SRV_INPUT_COLOR) || defined(FFX_INTERNAL) FfxFloat32x3 SampleInputColor(FfxFloat32x2 fUV) { - return r_input_color_jittered.SampleLevel(s_LinearClamp, fUV, 0).rgb; + return r_input_color_jittered.SampleLevel(s_LinearClamp, UNITY_FSR2_UV(fUV), 0).rgb; } #endif @@ -486,7 +497,7 @@ FfxFloat32x3 LoadPreparedInputColor(FfxUInt32x2 iPxPos) #if defined(FSR2_BIND_SRV_INPUT_MOTION_VECTORS) || defined(FFX_INTERNAL) FfxFloat32x2 LoadInputMotionVector(FfxUInt32x2 iPxDilatedMotionVectorPos) { - FfxFloat32x2 fSrcMotionVector = r_input_motion_vectors[iPxDilatedMotionVectorPos].xy; + FfxFloat32x2 fSrcMotionVector = r_input_motion_vectors[UNITY_FSR2_POS(iPxDilatedMotionVectorPos)].xy; FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale(); diff --git a/Assets/Scripts/Core/Fsr2Pipeline.cs b/Assets/Scripts/Core/Fsr2Pipeline.cs index 6e3d083..7db59f4 100644 --- a/Assets/Scripts/Core/Fsr2Pipeline.cs +++ b/Assets/Scripts/Core/Fsr2Pipeline.cs @@ -134,6 +134,13 @@ namespace FidelityFX if ((flags & Fsr2.InitializationFlags.EnableDepthInverted) != 0) shaderRef.EnableKeyword("FFX_FSR2_OPTION_INVERTED_DEPTH"); if (useLut) shaderRef.EnableKeyword("FFX_FSR2_OPTION_REPROJECT_USE_LANCZOS_TYPE"); if (supportedFP16) shaderRef.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")) + { + shaderRef.EnableKeyword("UNITY_FSR2_HDRP"); + } } private void UnloadComputeShader()