Browse Source

Use Core SRP shader includes to define Texture XR macros, replacing the old ad-hoc solution

srp
Nico de Poel 3 weeks ago
parent
commit
cb6efd6c74
  1. 2
      Shaders/ffx_fsr2_accumulate_pass.compute
  2. 2
      Shaders/ffx_fsr2_autogen_reactive_pass.compute
  3. 2
      Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute
  4. 2
      Shaders/ffx_fsr2_depth_clip_pass.compute
  5. 2
      Shaders/ffx_fsr2_lock_pass.compute
  6. 2
      Shaders/ffx_fsr2_rcas_pass.compute
  7. 2
      Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute
  8. 2
      Shaders/ffx_fsr2_tcr_autogen_pass.compute
  9. 35
      Shaders/ffx_fsr_unity_common.cginc
  10. 1
      Shaders/shaders/fsr2/ffx_fsr2_sample.h
  11. 1
      Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_sample.h

2
Shaders/ffx_fsr2_accumulate_pass.compute

@ -1,4 +1,4 @@
// Copyright (c) 2024 Nico de Poel
// Copyright (c) 2026 Nico de Poel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

2
Shaders/ffx_fsr2_autogen_reactive_pass.compute

@ -1,4 +1,4 @@
// Copyright (c) 2024 Nico de Poel
// Copyright (c) 2026 Nico de Poel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

2
Shaders/ffx_fsr2_compute_luminance_pyramid_pass.compute

@ -1,4 +1,4 @@
// Copyright (c) 2024 Nico de Poel
// Copyright (c) 2026 Nico de Poel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

2
Shaders/ffx_fsr2_depth_clip_pass.compute

@ -1,4 +1,4 @@
// Copyright (c) 2024 Nico de Poel
// Copyright (c) 2026 Nico de Poel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

2
Shaders/ffx_fsr2_lock_pass.compute

@ -1,4 +1,4 @@
// Copyright (c) 2024 Nico de Poel
// Copyright (c) 2026 Nico de Poel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

2
Shaders/ffx_fsr2_rcas_pass.compute

@ -1,4 +1,4 @@
// Copyright (c) 2024 Nico de Poel
// Copyright (c) 2026 Nico de Poel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

2
Shaders/ffx_fsr2_reconstruct_previous_depth_pass.compute

@ -1,4 +1,4 @@
// Copyright (c) 2024 Nico de Poel
// Copyright (c) 2026 Nico de Poel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

2
Shaders/ffx_fsr2_tcr_autogen_pass.compute

@ -1,4 +1,4 @@
// Copyright (c) 2024 Nico de Poel
// Copyright (c) 2026 Nico de Poel
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal

35
Shaders/ffx_fsr_unity_common.cginc

@ -18,6 +18,13 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#if !defined(UNITY_FSR_TEXTURE2D_X_ARRAY)
#define DISABLE_TEXTURE2D_X_ARRAY
#endif
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureXR.hlsl"
// Suppress a few warnings produced by FFX's HLSL code
#pragma warning(disable: 3078) // Loop control variable conflicts
#pragma warning(disable: 3203) // Signed/unsigned mismatch
@ -44,44 +51,20 @@
// #endif
// Hack to work around the lack of texture atomics on Metal
// TODO: replace texture atomics with a compute buffer setup
#if defined(SHADER_API_METAL)
#define InterlockedAdd(dest, val, orig) { (orig) = (dest); (dest) += (val); }
#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 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) || defined(SHADER_API_METAL)
#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(UNITY_FSR_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
// TODO: replace all declarations in callbacks.hlsl with TEXTURE2D_X
#if defined(USE_TEXTURE2D_X_AS_ARRAY)
// 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<type>
#define UNITY_FSR_RWTEX2D(type) RWTexture2DArray<type>
#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

1
Shaders/shaders/fsr2/ffx_fsr2_sample.h

@ -127,7 +127,6 @@ FFX_MIN16_F4 Bilinear(FetchedBilinearSamplesMin16 BilinearSamples, FFX_MIN16_F2
FfxFloat32 Lanczos2NoClamp(FfxFloat32 x)
{
const FfxFloat32 PI = 3.141592653589793f; // TODO: share SDK constants
return abs(x) < FSR2_EPSILON ? 1.f : (sin(PI * x) / (PI * x)) * (sin(0.5f * PI * x) / (0.5f * PI * x));
}

1
Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_sample.h

@ -127,7 +127,6 @@ FFX_MIN16_F4 Bilinear(FetchedBilinearSamplesMin16 BilinearSamples, FFX_MIN16_F2
FfxFloat32 Lanczos2NoClamp(FfxFloat32 x)
{
const FfxFloat32 PI = 3.141592653589793f; // TODO: share SDK constants
return abs(x) < FSR3UPSCALER_EPSILON ? 1.f : (sin(PI * x) / (PI * x)) * (sin(0.5f * PI * x) / (0.5f * PI * x));
}

Loading…
Cancel
Save