Browse Source

Added texture array support for inputs and outputs

armasr
Nico de Poel 10 months ago
parent
commit
133343b285
  1. 35
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc
  2. 62
      Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_callbacks_hlsl.h

35
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/ffxm_fsr2_common.cginc

@ -47,3 +47,38 @@
#define unorm #define unorm
#define globallycoherent #define globallycoherent
#endif #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)
#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_FFXM_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)
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)
#endif

62
Packages/com.unity.postprocessing@3.2.2/PostProcessing/Runtime/Effects/Upscaling/ASR/Shaders/shaders/fsr2/ffxm_fsr2_callbacks_hlsl.h

@ -299,21 +299,35 @@ FfxUInt32x2 SPD_RenderSize()
} }
#endif // #if defined(FSR2_BIND_CB_SPD) #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_PointClamp : register(s0);
SamplerState s_LinearClamp : register(s1); SamplerState s_LinearClamp : register(s1);
// SRVs // SRVs
#if defined FSR2_BIND_SRV_INPUT_COLOR #if defined FSR2_BIND_SRV_INPUT_COLOR
Texture2D<FfxFloat32x4> r_input_color_jittered : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_COLOR);
UNITY_FSR_TEX2D(FfxFloat32x4) r_input_color_jittered : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_COLOR);
#endif #endif
#if defined FSR2_BIND_SRV_INPUT_OPAQUE_ONLY #if defined FSR2_BIND_SRV_INPUT_OPAQUE_ONLY
Texture2D<FfxFloat32x4> r_input_opaque_only : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY);
UNITY_FSR_TEX2D(FfxFloat32x4) r_input_opaque_only : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY);
#endif #endif
#if defined FSR2_BIND_SRV_INPUT_MOTION_VECTORS #if defined FSR2_BIND_SRV_INPUT_MOTION_VECTORS
Texture2D<FfxFloat32x4> r_input_motion_vectors : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_MOTION_VECTORS);
UNITY_FSR_TEX2D(FfxFloat32x4) r_input_motion_vectors : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_MOTION_VECTORS);
#endif #endif
#if defined FSR2_BIND_SRV_INPUT_DEPTH #if defined FSR2_BIND_SRV_INPUT_DEPTH
Texture2D<FfxFloat32> r_input_depth : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_DEPTH);
UNITY_FSR_TEX2D(FfxFloat32) r_input_depth : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_DEPTH);
#endif #endif
#if defined FSR2_BIND_SRV_INPUT_EXPOSURE #if defined FSR2_BIND_SRV_INPUT_EXPOSURE
Texture2D<FfxFloat32x2> r_input_exposure : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_EXPOSURE); Texture2D<FfxFloat32x2> r_input_exposure : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_INPUT_EXPOSURE);
@ -322,10 +336,10 @@ SamplerState s_LinearClamp : register(s1);
Texture2D<FfxFloat32x2> r_auto_exposure : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_AUTO_EXPOSURE); Texture2D<FfxFloat32x2> r_auto_exposure : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_AUTO_EXPOSURE);
#endif #endif
#if defined FSR2_BIND_SRV_REACTIVE_MASK #if defined FSR2_BIND_SRV_REACTIVE_MASK
Texture2D<FfxFloat32> r_reactive_mask : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_REACTIVE_MASK);
UNITY_FSR_TEX2D(FfxFloat32) r_reactive_mask : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_REACTIVE_MASK);
#endif #endif
#if defined FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK #if defined FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK
Texture2D<FfxFloat32> r_transparency_and_composition_mask : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK);
UNITY_FSR_TEX2D(FfxFloat32) r_transparency_and_composition_mask : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK);
#endif #endif
#if defined FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH #if defined FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH
Texture2D<FfxUInt32> r_reconstructed_previous_nearest_depth : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH); Texture2D<FfxUInt32> r_reconstructed_previous_nearest_depth : FFXM_FSR2_DECLARE_SRV(FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH);
@ -414,7 +428,7 @@ SamplerState s_LinearClamp : register(s1);
RWTexture2D<FfxFloat32x4> rw_luma_history : FFXM_FSR2_DECLARE_UAV(FSR2_BIND_UAV_LUMA_HISTORY); RWTexture2D<FfxFloat32x4> rw_luma_history : FFXM_FSR2_DECLARE_UAV(FSR2_BIND_UAV_LUMA_HISTORY);
#endif #endif
#if defined FSR2_BIND_UAV_UPSCALED_OUTPUT #if defined FSR2_BIND_UAV_UPSCALED_OUTPUT
RWTexture2D<FfxFloat32x4> rw_upscaled_output : FFXM_FSR2_DECLARE_UAV(FSR2_BIND_UAV_UPSCALED_OUTPUT);
UNITY_FSR_RWTEX2D(FfxFloat32x4) rw_upscaled_output : FFXM_FSR2_DECLARE_UAV(FSR2_BIND_UAV_UPSCALED_OUTPUT);
#endif #endif
#if defined FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE #if defined FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE
globallycoherent RWTexture2D<FfxFloat32> rw_img_mip_shading_change : FFXM_FSR2_DECLARE_UAV(FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE); globallycoherent RWTexture2D<FfxFloat32> rw_img_mip_shading_change : FFXM_FSR2_DECLARE_UAV(FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE);
@ -456,7 +470,7 @@ FfxFloat32 SampleMipLuma(FfxFloat32x2 fUV, FfxUInt32 mipLevel)
#if defined(FSR2_BIND_SRV_INPUT_DEPTH) #if defined(FSR2_BIND_SRV_INPUT_DEPTH)
FfxFloat32 LoadInputDepth(FfxUInt32x2 iPxPos) FfxFloat32 LoadInputDepth(FfxUInt32x2 iPxPos)
{ {
return r_input_depth[iPxPos];
return r_input_depth[UNITY_FSR_POS(iPxPos)];
} }
/* /*
dd00 (-1,1) *------* dd10 (0,-1) dd00 (-1,1) *------* dd10 (0,-1)
@ -470,7 +484,7 @@ void GatherInputDepthRQuad(FfxFloat32x2 fUV,
FFXM_PARAMETER_INOUT FfxFloat32 dd01, FFXM_PARAMETER_INOUT FfxFloat32 dd01,
FFXM_PARAMETER_INOUT FfxFloat32 dd11) FFXM_PARAMETER_INOUT FfxFloat32 dd11)
{ {
FfxFloat32x4 rrrr = r_input_depth.GatherRed(s_PointClamp, fUV);
FfxFloat32x4 rrrr = r_input_depth.GatherRed(s_PointClamp, UNITY_FSR_UV(fUV));
dd01 = FfxFloat32(rrrr.x); dd01 = FfxFloat32(rrrr.x);
dd11 = FfxFloat32(rrrr.y); dd11 = FfxFloat32(rrrr.y);
dd10 = FfxFloat32(rrrr.z); dd10 = FfxFloat32(rrrr.z);
@ -481,14 +495,14 @@ void GatherInputDepthRQuad(FfxFloat32x2 fUV,
#if defined(FSR2_BIND_SRV_INPUT_DEPTH) #if defined(FSR2_BIND_SRV_INPUT_DEPTH)
FfxFloat32 SampleInputDepth(FfxFloat32x2 fUV) FfxFloat32 SampleInputDepth(FfxFloat32x2 fUV)
{ {
return r_input_depth.SampleLevel(s_LinearClamp, fUV, 0).x;
return r_input_depth.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).x;
} }
#endif #endif
#if defined(FSR2_BIND_SRV_REACTIVE_MASK) #if defined(FSR2_BIND_SRV_REACTIVE_MASK)
FfxFloat32 LoadReactiveMask(FfxUInt32x2 iPxPos) FfxFloat32 LoadReactiveMask(FfxUInt32x2 iPxPos)
{ {
return r_reactive_mask[iPxPos];
return r_reactive_mask[UNITY_FSR_POS(iPxPos)];
} }
/* /*
col00 (-1,1) *------* col10 (0,-1) col00 (-1,1) *------* col10 (0,-1)
@ -502,7 +516,7 @@ void GatherReactiveRQuad(FfxFloat32x2 fUV,
FFXM_PARAMETER_INOUT FFXM_MIN16_F col01, FFXM_PARAMETER_INOUT FFXM_MIN16_F col01,
FFXM_PARAMETER_INOUT FFXM_MIN16_F col11) FFXM_PARAMETER_INOUT FFXM_MIN16_F col11)
{ {
FFXM_MIN16_F4 rrrr = r_reactive_mask.GatherRed(s_PointClamp, fUV);
FFXM_MIN16_F4 rrrr = r_reactive_mask.GatherRed(s_PointClamp, UNITY_FSR_UV(fUV));
col01 = FFXM_MIN16_F(rrrr.x); col01 = FFXM_MIN16_F(rrrr.x);
col11 = FFXM_MIN16_F(rrrr.y); col11 = FFXM_MIN16_F(rrrr.y);
col10 = FFXM_MIN16_F(rrrr.z); col10 = FFXM_MIN16_F(rrrr.z);
@ -513,7 +527,7 @@ void GatherReactiveRQuad(FfxFloat32x2 fUV,
#if defined(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK) #if defined(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK)
FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos) FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos)
{ {
return r_transparency_and_composition_mask[iPxPos];
return r_transparency_and_composition_mask[UNITY_FSR_POS(iPxPos)];
} }
/* /*
col00 (-1,1) *------* col10 (0,-1) col00 (-1,1) *------* col10 (0,-1)
@ -527,7 +541,7 @@ void GatherTransparencyAndCompositionMaskRQuad(FfxFloat32x2 fUV,
FFXM_PARAMETER_INOUT FFXM_MIN16_F col01, FFXM_PARAMETER_INOUT FFXM_MIN16_F col01,
FFXM_PARAMETER_INOUT FFXM_MIN16_F col11) FFXM_PARAMETER_INOUT FFXM_MIN16_F col11)
{ {
FFXM_MIN16_F4 rrrr = r_transparency_and_composition_mask.GatherRed(s_PointClamp, fUV);
FFXM_MIN16_F4 rrrr = r_transparency_and_composition_mask.GatherRed(s_PointClamp, UNITY_FSR_UV(fUV));
col01 = FFXM_MIN16_F(rrrr.x); col01 = FFXM_MIN16_F(rrrr.x);
col11 = FFXM_MIN16_F(rrrr.y); col11 = FFXM_MIN16_F(rrrr.y);
col10 = FFXM_MIN16_F(rrrr.z); col10 = FFXM_MIN16_F(rrrr.z);
@ -538,7 +552,7 @@ void GatherTransparencyAndCompositionMaskRQuad(FfxFloat32x2 fUV,
#if defined(FSR2_BIND_SRV_INPUT_COLOR) #if defined(FSR2_BIND_SRV_INPUT_COLOR)
FFXM_MIN16_F3 LoadInputColor(FfxUInt32x2 iPxPos) FFXM_MIN16_F3 LoadInputColor(FfxUInt32x2 iPxPos)
{ {
return r_input_color_jittered[iPxPos].rgb;
return r_input_color_jittered[UNITY_FSR_POS(iPxPos)].rgb;
} }
/* /*
col00 (-1,1) *------* col10 (0,-1) col00 (-1,1) *------* col10 (0,-1)
@ -552,9 +566,9 @@ void GatherInputColorRGBQuad(FfxFloat32x2 fUV,
FFXM_PARAMETER_INOUT FFXM_MIN16_F3 col01, FFXM_PARAMETER_INOUT FFXM_MIN16_F3 col01,
FFXM_PARAMETER_INOUT FFXM_MIN16_F3 col11) FFXM_PARAMETER_INOUT FFXM_MIN16_F3 col11)
{ {
FFXM_MIN16_F4 rrrr = r_input_color_jittered.GatherRed(s_PointClamp, fUV);
FFXM_MIN16_F4 gggg = r_input_color_jittered.GatherGreen(s_PointClamp, fUV);
FFXM_MIN16_F4 bbbb = r_input_color_jittered.GatherBlue(s_PointClamp, fUV);
FFXM_MIN16_F4 rrrr = r_input_color_jittered.GatherRed(s_PointClamp, UNITY_FSR_UV(fUV));
FFXM_MIN16_F4 gggg = r_input_color_jittered.GatherGreen(s_PointClamp, UNITY_FSR_UV(fUV));
FFXM_MIN16_F4 bbbb = r_input_color_jittered.GatherBlue(s_PointClamp, UNITY_FSR_UV(fUV));
col01 = FFXM_MIN16_F3(rrrr.x, gggg.x, bbbb.x); col01 = FFXM_MIN16_F3(rrrr.x, gggg.x, bbbb.x);
col11 = FFXM_MIN16_F3(rrrr.y, gggg.y, bbbb.y); col11 = FFXM_MIN16_F3(rrrr.y, gggg.y, bbbb.y);
col10 = FFXM_MIN16_F3(rrrr.z, gggg.z, bbbb.z); col10 = FFXM_MIN16_F3(rrrr.z, gggg.z, bbbb.z);
@ -565,7 +579,7 @@ void GatherInputColorRGBQuad(FfxFloat32x2 fUV,
#if defined(FSR2_BIND_SRV_INPUT_COLOR) #if defined(FSR2_BIND_SRV_INPUT_COLOR)
FFXM_MIN16_F3 SampleInputColor(FfxFloat32x2 fUV) FFXM_MIN16_F3 SampleInputColor(FfxFloat32x2 fUV)
{ {
return r_input_color_jittered.SampleLevel(s_LinearClamp, fUV, 0).rgb;
return r_input_color_jittered.SampleLevel(s_LinearClamp, UNITY_FSR_UV(fUV), 0).rgb;
} }
#endif #endif
@ -603,7 +617,7 @@ void GatherPreparedInputColorRGBQuad(FfxFloat32x2 fUV,
#if defined(FSR2_BIND_SRV_INPUT_MOTION_VECTORS) #if defined(FSR2_BIND_SRV_INPUT_MOTION_VECTORS)
FFXM_MIN16_F2 LoadInputMotionVector(FfxUInt32x2 iPxDilatedMotionVectorPos) FFXM_MIN16_F2 LoadInputMotionVector(FfxUInt32x2 iPxDilatedMotionVectorPos)
{ {
FFXM_MIN16_F2 fSrcMotionVector = r_input_motion_vectors[iPxDilatedMotionVectorPos].xy;
FFXM_MIN16_F2 fSrcMotionVector = r_input_motion_vectors[UNITY_FSR_POS(iPxDilatedMotionVectorPos)].xy;
FFXM_MIN16_F2 fUvMotionVector = fSrcMotionVector * MotionVectorScale(); FFXM_MIN16_F2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();
@ -625,8 +639,8 @@ void GatherInputMotionVectorRGQuad(FfxFloat32x2 fUV,
FFXM_PARAMETER_INOUT FFXM_MIN16_F2 col01, FFXM_PARAMETER_INOUT FFXM_MIN16_F2 col01,
FFXM_PARAMETER_INOUT FFXM_MIN16_F2 col11) FFXM_PARAMETER_INOUT FFXM_MIN16_F2 col11)
{ {
FFXM_MIN16_F4 rrrr = r_input_motion_vectors.GatherRed(s_PointClamp, fUV);
FFXM_MIN16_F4 gggg = r_input_motion_vectors.GatherGreen(s_PointClamp, fUV);
FFXM_MIN16_F4 rrrr = r_input_motion_vectors.GatherRed(s_PointClamp, UNITY_FSR_UV(fUV));
FFXM_MIN16_F4 gggg = r_input_motion_vectors.GatherGreen(s_PointClamp, UNITY_FSR_UV(fUV));
col01 = FFXM_MIN16_F2(rrrr.x, gggg.x) * MotionVectorScale(); col01 = FFXM_MIN16_F2(rrrr.x, gggg.x) * MotionVectorScale();
col11 = FFXM_MIN16_F2(rrrr.y, gggg.y) * MotionVectorScale(); col11 = FFXM_MIN16_F2(rrrr.y, gggg.y) * MotionVectorScale();
col10 = FFXM_MIN16_F2(rrrr.z, gggg.z) * MotionVectorScale(); col10 = FFXM_MIN16_F2(rrrr.z, gggg.z) * MotionVectorScale();
@ -711,7 +725,7 @@ void StoreInternalColorAndWeight(FfxUInt32x2 iPxPos, FfxFloat32x4 fColorAndWeigh
#if defined(FSR2_BIND_UAV_UPSCALED_OUTPUT) #if defined(FSR2_BIND_UAV_UPSCALED_OUTPUT)
void StoreUpscaledOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor) void StoreUpscaledOutput(FfxUInt32x2 iPxPos, FfxFloat32x3 fColor)
{ {
rw_upscaled_output[iPxPos] = FfxFloat32x4(fColor, 1.f);
rw_upscaled_output[UNITY_FSR_POS(iPxPos)] = FfxFloat32x4(fColor, 1.f);
} }
#endif #endif
@ -948,7 +962,7 @@ FFXM_MIN16_F2 LoadDilatedReactiveMasks(FFXM_PARAMETER_IN FfxUInt32x2 iPxPos)
#if defined(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY) #if defined(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY)
FfxFloat32x3 LoadOpaqueOnly(FFXM_PARAMETER_IN FFXM_MIN16_I2 iPxPos) FfxFloat32x3 LoadOpaqueOnly(FFXM_PARAMETER_IN FFXM_MIN16_I2 iPxPos)
{ {
return r_input_opaque_only[iPxPos].xyz;
return r_input_opaque_only[UNITY_FSR_POS(iPxPos)].xyz;
} }
#endif #endif

Loading…
Cancel
Save