Browse Source

Added a workaround for HDRP using texture arrays for its camera buffers on some platforms.

Also cleaned up some unused keywords to reduce shader compile times.
hdrp
Nico de Poel 3 years ago
parent
commit
e69ea6dd10
  1. 2
      Assets/Resources/FSR2/ffx_fsr2_accumulate_pass.compute
  2. 5
      Assets/Resources/FSR2/ffx_fsr2_autogen_reactive_pass.compute
  3. 5
      Assets/Resources/FSR2/ffx_fsr2_compute_luminance_pyramid_pass.compute
  4. 5
      Assets/Resources/FSR2/ffx_fsr2_depth_clip_pass.compute
  5. 3
      Assets/Resources/FSR2/ffx_fsr2_lock_pass.compute
  6. 3
      Assets/Resources/FSR2/ffx_fsr2_rcas_pass.compute
  7. 4
      Assets/Resources/FSR2/ffx_fsr2_reconstruct_previous_depth_pass.compute
  8. 5
      Assets/Resources/FSR2/ffx_fsr2_tcr_autogen_pass.compute
  9. 36
      Assets/Resources/FSR2/ffx_fsr2_unity_common.cginc
  10. 39
      Assets/Resources/FSR2/shaders/ffx_fsr2_callbacks_hlsl.h
  11. 7
      Assets/Scripts/Core/Fsr2Pipeline.cs

2
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

5
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"

5
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"

5
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"

3
Assets/Resources/FSR2/ffx_fsr2_lock_pass.compute

@ -21,12 +21,9 @@
#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
#include "ffx_fsr2_unity_common.cginc"

3
Assets/Resources/FSR2/ffx_fsr2_rcas_pass.compute

@ -20,12 +20,9 @@
#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
#include "ffx_fsr2_unity_common.cginc"

4
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"

5
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"

36
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<type>
#define UNITY_FSR2_POS(pxPos) FfxUInt32x3(pxPos, SLICE_ARRAY_INDEX)
#define UNITY_FSR2_UV(uv) FfxFloat32x3(uv, SLICE_ARRAY_INDEX)
#endif
#endif

39
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<type>
#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()
{
@ -226,10 +237,10 @@ SamplerState s_LinearClamp : register(s1);
// SRVs
#if defined(FFX_INTERNAL)
Texture2D<FfxFloat32x4> r_input_opaque_only : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_OPAQUE_ONLY);
Texture2D<FfxFloat32x4> r_input_color_jittered : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_COLOR);
Texture2D<FfxFloat32x4> r_input_motion_vectors : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_MOTION_VECTORS);
Texture2D<FfxFloat32> r_input_depth : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_DEPTH);
UNITY_FSR2_TEX2D(FfxFloat32x4) r_input_opaque_only : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_OPAQUE_ONLY);
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<FfxFloat32x2> r_input_exposure : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_INPUT_EXPOSURE);
Texture2D<FfxFloat32x2> r_auto_exposure : FFX_FSR2_DECLARE_SRV(FFX_FSR2_RESOURCE_IDENTIFIER_AUTO_EXPOSURE);
Texture2D<FfxFloat32> 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<FfxFloat32x4> 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<FfxFloat32x4> r_input_opaque_only : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY);
UNITY_FSR2_TEX2D(FfxFloat32x4) r_input_opaque_only : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY);
#endif
#if defined FSR2_BIND_SRV_INPUT_MOTION_VECTORS
Texture2D<FfxFloat32x4> 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<FfxFloat32> 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<FfxFloat32x2> 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();
@ -759,7 +770,7 @@ void StoreDilatedReactiveMasks(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETE
#if defined(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY) || defined(FFX_INTERNAL)
FfxFloat32x3 LoadOpaqueOnly(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
{
return r_input_opaque_only[iPxPos].xyz;
return r_input_opaque_only[UNITY_FSR2_POS(iPxPos)].xyz;
}
#endif

7
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()

Loading…
Cancel
Save