1 Commits

  1. 11
      Shaders/ffx_fsr_unity_common.cginc
  2. 46
      Shaders/shaders/fsr2/ffx_fsr2_callbacks_hlsl.h
  3. 57
      Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h

11
Shaders/ffx_fsr_unity_common.cginc

@ -57,14 +57,3 @@
#define InterlockedMin(dest, val) { (dest) = min((dest), (val)); }
#define InterlockedMax(dest, val) { (dest) = max((dest), (val)); }
#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)
// 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

46
Shaders/shaders/fsr2/ffx_fsr2_callbacks_hlsl.h

@ -339,35 +339,21 @@ FfxUInt32x2 SPD_RenderSize()
}
#endif // #if defined(FSR2_BIND_CB_SPD)
// Declare and sample camera buffers as regular textures, unless overridden
#if !defined(UNITY_FSR_TEX2D)
#define UNITY_FSR_TEX2D(type) Texture2D<type>
#endif
#if !defined(UNITY_FSR_RWTEX2D)
#define UNITY_FSR_RWTEX2D(type) RWTexture2D<type>
#endif
#if !defined(UNITY_FSR_POS)
#define UNITY_FSR_POS(pxPos) (pxPos)
#endif
#if !defined(UNITY_FSR_UV)
#define UNITY_FSR_UV(uv) (uv)
#endif
SamplerState s_PointClamp : register(s0);
SamplerState s_LinearClamp : register(s1);
// SRVs
#if defined FSR2_BIND_SRV_INPUT_COLOR
UNITY_FSR_TEX2D(FfxFloat32x4) r_input_color_jittered : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_COLOR);
TYPED_TEXTURE2D_X(FfxFloat32x4, r_input_color_jittered) : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_COLOR);
#endif
#if defined FSR2_BIND_SRV_INPUT_OPAQUE_ONLY
UNITY_FSR_TEX2D(FfxFloat32x4) r_input_opaque_only : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY);
TYPED_TEXTURE2D_X(FfxFloat32x4, r_input_opaque_only) : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY);
#endif
#if defined FSR2_BIND_SRV_INPUT_MOTION_VECTORS
UNITY_FSR_TEX2D(FfxFloat32x4) r_input_motion_vectors : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_MOTION_VECTORS);
TYPED_TEXTURE2D_X(FfxFloat32x4, r_input_motion_vectors) : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_MOTION_VECTORS);
#endif
#if defined FSR2_BIND_SRV_INPUT_DEPTH
UNITY_FSR_TEX2D(FfxFloat32) r_input_depth : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_DEPTH);
TYPED_TEXTURE2D_X(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);
@ -376,10 +362,10 @@ SamplerState s_LinearClamp : register(s1);
Texture2D<FfxFloat32x2> r_auto_exposure : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_AUTO_EXPOSURE);
#endif
#if defined FSR2_BIND_SRV_REACTIVE_MASK
UNITY_FSR_TEX2D(FfxFloat32) r_reactive_mask : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_REACTIVE_MASK);
TYPED_TEXTURE2D_X(FfxFloat32, r_reactive_mask) : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_REACTIVE_MASK);
#endif
#if defined FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK
UNITY_FSR_TEX2D(FfxFloat32) r_transparency_and_composition_mask : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK);
TYPED_TEXTURE2D_X(FfxFloat32, r_transparency_and_composition_mask) : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK);
#endif
#if defined FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH
Texture2D<FfxUInt32> r_reconstructed_previous_nearest_depth : FFX_FSR2_DECLARE_SRV(FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH);
@ -463,7 +449,7 @@ SamplerState s_LinearClamp : register(s1);
RWTexture2D<FfxFloat32x4> rw_luma_history : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_LUMA_HISTORY);
#endif
#if defined FSR2_BIND_UAV_UPSCALED_OUTPUT
UNITY_FSR_RWTEX2D(FfxFloat32x4) rw_upscaled_output : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_UPSCALED_OUTPUT);
RW_TEXTURE2D_X(FfxFloat32x4, rw_upscaled_output) : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_UPSCALED_OUTPUT);
#endif
#if defined FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE
globallycoherent RWTexture2D<FfxFloat32> rw_img_mip_shading_change : FFX_FSR2_DECLARE_UAV(FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE);
@ -514,42 +500,42 @@ FfxFloat32 SampleMipLuma(FfxFloat32x2 fUV, FfxUInt32 mipLevel)
#if defined(FSR2_BIND_SRV_INPUT_DEPTH)
FfxFloat32 LoadInputDepth(FfxUInt32x2 iPxPos)
{
return r_input_depth[UNITY_FSR_POS(iPxPos)];
return r_input_depth[COORD_TEXTURE2D_X(iPxPos)];
}
#endif
#if defined(FSR2_BIND_SRV_INPUT_DEPTH)
FfxFloat32 SampleInputDepth(FfxFloat32x2 fUV)
{
return r_input_depth.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).x;
return SAMPLE_TEXTURE2D_X_LOD(r_input_depth, s_LinearClamp, fUV, 0).x;
}
#endif
#if defined(FSR2_BIND_SRV_REACTIVE_MASK)
FfxFloat32 LoadReactiveMask(FfxUInt32x2 iPxPos)
{
return r_reactive_mask[UNITY_FSR_POS(iPxPos)];
return r_reactive_mask[COORD_TEXTURE2D_X(iPxPos)];
}
#endif
#if defined(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK)
FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos)
{
return r_transparency_and_composition_mask[UNITY_FSR_POS(iPxPos)];
return r_transparency_and_composition_mask[COORD_TEXTURE2D_X(iPxPos)];
}
#endif
#if defined(FSR2_BIND_SRV_INPUT_COLOR)
FfxFloat32x3 LoadInputColor(FfxUInt32x2 iPxPos)
{
return r_input_color_jittered[UNITY_FSR_POS(iPxPos)].rgb;
return r_input_color_jittered[COORD_TEXTURE2D_X(iPxPos)].rgb;
}
#endif
#if defined(FSR2_BIND_SRV_INPUT_COLOR)
FfxFloat32x3 SampleInputColor(FfxFloat32x2 fUV)
{
return r_input_color_jittered.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).rgb;
return SAMPLE_TEXTURE2D_X_LOD(r_input_color_jittered, s_LinearClamp, fUV, 0).rgb;
}
#endif
@ -571,7 +557,7 @@ FFX_MIN16_F3 LoadPreparedInputColorHalf(FfxUInt32x2 iPxPos)
#if defined(FSR2_BIND_SRV_INPUT_MOTION_VECTORS)
FfxFloat32x2 LoadInputMotionVector(FfxUInt32x2 iPxDilatedMotionVectorPos)
{
FfxFloat32x2 fSrcMotionVector = r_input_motion_vectors[UNITY_FSR_POS(iPxDilatedMotionVectorPos)].xy;
FfxFloat32x2 fSrcMotionVector = r_input_motion_vectors[COORD_TEXTURE2D_X(iPxDilatedMotionVectorPos)].xy;
FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();
@ -630,7 +616,7 @@ void StoreInternalColorAndWeight(FfxUInt32x2 iPxPos, FfxFloat32x4 fColorAndWeigh
#if defined(FSR2_BIND_UAV_UPSCALED_OUTPUT)
void StoreUpscaledOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor)
{
rw_upscaled_output[UNITY_FSR_POS(iPxPos)] = FfxFloat32x4(fColor, 1.f);
rw_upscaled_output[COORD_TEXTURE2D_X(iPxPos)] = FfxFloat32x4(fColor, 1.f);
}
#endif
@ -862,7 +848,7 @@ void StoreDilatedReactiveMasks(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETE
#if defined(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY)
FfxFloat32x3 LoadOpaqueOnly(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
{
return r_input_opaque_only[UNITY_FSR_POS(iPxPos)].xyz;
return r_input_opaque_only[COORD_TEXTURE2D_X(iPxPos)].xyz;
}
#endif

57
Shaders/shaders/fsr3upscaler/ffx_fsr3upscaler_callbacks_hlsl.h

@ -340,23 +340,6 @@ FfxUInt32x2 SPD_RenderSize()
}
#endif // #if defined(FSR3UPSCALER_BIND_CB_SPD)
// Declare and sample camera buffers as regular textures, unless overridden
#if !defined(UNITY_FSR_TEX2D)
#define UNITY_FSR_TEX2D(type) Texture2D<type>
#endif
#if !defined(UNITY_FSR_RWTEX2D)
#define UNITY_FSR_RWTEX2D(type) RWTexture2D<type>
#endif
#if !defined(UNITY_FSR_POS)
#define UNITY_FSR_POS(pxPos) (pxPos)
#endif
#if !defined(UNITY_FSR_UV)
#define UNITY_FSR_UV(uv) (uv)
#endif
#if !defined(UNITY_FSR_GETDIMS)
#define UNITY_FSR_GETDIMS(tex, w, h) (tex).GetDimensions((w), (h))
#endif
SamplerState s_PointClamp : register(s0);
SamplerState s_LinearClamp : register(s1);
@ -380,85 +363,85 @@ FfxFloat32x2 SampleSPDMipLevel(FfxFloat32x2 fUV, FfxUInt32 mipLevel)
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_DEPTH)
UNITY_FSR_TEX2D(FfxFloat32) r_input_depth : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_DEPTH);
TYPED_TEXTURE2D_X(FfxFloat32, r_input_depth) : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_DEPTH);
FfxFloat32 LoadInputDepth(FfxUInt32x2 iPxPos)
{
return r_input_depth[UNITY_FSR_POS(iPxPos)];
return r_input_depth[COORD_TEXTURE2D_X(iPxPos)];
}
FfxFloat32 SampleInputDepth(FfxFloat32x2 fUV)
{
return r_input_depth.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).x;
return SAMPLE_TEXTURE2D_X_LOD(r_input_depth, s_LinearClamp, fUV, 0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_REACTIVE_MASK)
UNITY_FSR_TEX2D(FfxFloat32) r_reactive_mask : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_REACTIVE_MASK);
TYPED_TEXTURE2D_X(FfxFloat32, r_reactive_mask) : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_REACTIVE_MASK);
FfxFloat32 LoadReactiveMask(FfxUInt32x2 iPxPos)
{
return r_reactive_mask[UNITY_FSR_POS(iPxPos)] * fReactivenessScale;
return r_reactive_mask[COORD_TEXTURE2D_X(iPxPos)] * fReactivenessScale;
}
FfxInt32x2 GetReactiveMaskResourceDimensions()
{
FfxUInt32 uWidth;
FfxUInt32 uHeight;
UNITY_FSR_GETDIMS(r_reactive_mask, uWidth, uHeight);
GET_TEXTURE2D_X_SIZE(r_reactive_mask, uWidth, uHeight);
return FfxInt32x2(uWidth, uHeight);
}
FfxFloat32 SampleReactiveMask(FfxFloat32x2 fUV)
{
return r_reactive_mask.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).x * fReactivenessScale;
return SAMPLE_TEXTURE2D_X_LOD(r_reactive_mask, s_LinearClamp, fUV, 0).x * fReactivenessScale;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK)
UNITY_FSR_TEX2D(FfxFloat32) r_transparency_and_composition_mask : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK);
TYPED_TEXTURE2D_X(FfxFloat32, r_transparency_and_composition_mask) : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK);
FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos)
{
return r_transparency_and_composition_mask[UNITY_FSR_POS(iPxPos)];
return r_transparency_and_composition_mask[COORD_TEXTURE2D_X(iPxPos)];
}
FfxInt32x2 GetTransparencyAndCompositionMaskResourceDimensions()
{
FfxUInt32 uWidth;
FfxUInt32 uHeight;
UNITY_FSR_GETDIMS(r_transparency_and_composition_mask, uWidth, uHeight);
GET_TEXTURE2D_X_SIZE(r_transparency_and_composition_mask, uWidth, uHeight);
return FfxInt32x2(uWidth, uHeight);
}
FfxFloat32 SampleTransparencyAndCompositionMask(FfxFloat32x2 fUV)
{
return r_transparency_and_composition_mask.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).x;
return SAMPLE_TEXTURE2D_X_LOD(r_transparency_and_composition_mask, s_LinearClamp, fUV, 0).x;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_COLOR)
UNITY_FSR_TEX2D(FfxFloat32x4) r_input_color_jittered : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_COLOR);
TYPED_TEXTURE2D_X(FfxFloat32x4, r_input_color_jittered) : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_COLOR);
FfxFloat32x3 LoadInputColor(FfxUInt32x2 iPxPos)
{
return r_input_color_jittered[UNITY_FSR_POS(iPxPos)].rgb;
return r_input_color_jittered[COORD_TEXTURE2D_X(iPxPos)].rgb;
}
FfxFloat32x3 SampleInputColor(FfxFloat32x2 fUV)
{
return r_input_color_jittered.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).rgb;
return SAMPLE_TEXTURE2D_X_LOD(r_input_color_jittered, s_LinearClamp, fUV, 0).rgb;
}
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_MOTION_VECTORS)
UNITY_FSR_TEX2D(FfxFloat32x4) r_input_motion_vectors : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_MOTION_VECTORS);
TYPED_TEXTURE2D_X(FfxFloat32x4, r_input_motion_vectors) : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_MOTION_VECTORS);
FfxFloat32x2 LoadInputMotionVector(FfxUInt32x2 iPxDilatedMotionVectorPos)
{
FfxFloat32x2 fSrcMotionVector = r_input_motion_vectors[UNITY_FSR_POS(iPxDilatedMotionVectorPos)].xy;
FfxFloat32x2 fSrcMotionVector = r_input_motion_vectors[COORD_TEXTURE2D_X(iPxDilatedMotionVectorPos)].xy;
FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();
@ -536,11 +519,11 @@ void StoreInternalColorAndWeight(FfxUInt32x2 iPxPos, FfxFloat32x4 fColorAndWeigh
#endif
#if defined(FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT)
UNITY_FSR_RWTEX2D(FfxFloat32x4) rw_upscaled_output : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT);
RW_TEXTURE2D_X(FfxFloat32x4, rw_upscaled_output) : FFX_FSR3UPSCALER_DECLARE_UAV(FSR3UPSCALER_BIND_UAV_UPSCALED_OUTPUT);
void StoreUpscaledOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor)
{
rw_upscaled_output[UNITY_FSR_POS(iPxPos)] = FfxFloat32x4(fColor, 1.f);
rw_upscaled_output[COORD_TEXTURE2D_X(iPxPos)] = FfxFloat32x4(fColor, 1.f);
}
#endif
@ -857,11 +840,11 @@ void StoreDilatedReactiveMasks(FFX_PARAMETER_IN FfxUInt32x2 iPxPos, FFX_PARAMETE
#endif
#if defined(FSR3UPSCALER_BIND_SRV_INPUT_OPAQUE_ONLY)
UNITY_FSR_TEX2D(FfxFloat32x4) r_input_opaque_only : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_OPAQUE_ONLY);
TYPED_TEXTURE2D_X(FfxFloat32x4, r_input_opaque_only) : FFX_FSR3UPSCALER_DECLARE_SRV(FSR3UPSCALER_BIND_SRV_INPUT_OPAQUE_ONLY);
FfxFloat32x3 LoadOpaqueOnly(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
{
return r_input_opaque_only[UNITY_FSR_POS(iPxPos)].xyz;
return r_input_opaque_only[COORD_TEXTURE2D_X(iPxPos)].xyz;
}
#endif

Loading…
Cancel
Save