Path: blob/master/thirdparty/amd-fsr2/patches/0002-godot-fsr2-options.patch
9898 views
diff --git a/thirdparty/amd-fsr2/ffx_fsr2.cpp b/thirdparty/amd-fsr2/ffx_fsr2.cpp1index 3970aa7f5b..ec571b9cd2 1006442--- a/thirdparty/amd-fsr2/ffx_fsr2.cpp3+++ b/thirdparty/amd-fsr2/ffx_fsr2.cpp4@@ -952,6 +952,8 @@ static FfxErrorCode fsr2Dispatch(FfxFsr2Context_Private* context, const FfxFsr2D5context->constants.lumaMipDimensions[0] = uint32_t(context->constants.maxRenderSize[0] / mipDiv);6context->constants.lumaMipDimensions[1] = uint32_t(context->constants.maxRenderSize[1] / mipDiv);78+ memcpy(context->constants.reprojectionMatrix, params->reprojectionMatrix, sizeof(context->constants.reprojectionMatrix));9+10// reactive mask bias11const int32_t threadGroupWorkRegionDim = 8;12const int32_t dispatchSrcX = (context->constants.renderSize[0] + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;13diff --git a/thirdparty/amd-fsr2/ffx_fsr2.h b/thirdparty/amd-fsr2/ffx_fsr2.h14index 2a1c74abb1..dfcd4caf35 10064415--- a/thirdparty/amd-fsr2/ffx_fsr2.h16+++ b/thirdparty/amd-fsr2/ffx_fsr2.h17@@ -146,6 +146,7 @@ typedef struct FfxFsr2DispatchDescription {18float autoReactiveScale; ///< A value to scale the reactive mask19float autoReactiveMax; ///< A value to clamp the reactive mask2021+ float reprojectionMatrix[16]; ///< The matrix used for reprojecting pixels with invalid motion vectors by using the depth.22} FfxFsr2DispatchDescription;2324/// A structure encapsulating the parameters for automatic generation of a reactive mask25diff --git a/thirdparty/amd-fsr2/ffx_fsr2_private.h b/thirdparty/amd-fsr2/ffx_fsr2_private.h26index 6b5fbc5117..8a9aec5778 10064427--- a/thirdparty/amd-fsr2/ffx_fsr2_private.h28+++ b/thirdparty/amd-fsr2/ffx_fsr2_private.h29@@ -44,6 +44,9 @@ typedef struct Fsr2Constants {30float deltaTime;31float dynamicResChangeFactor;32float viewSpaceToMetersFactor;33+34+ float pad;35+ float reprojectionMatrix[16];36} Fsr2Constants;3738struct FfxFsr2ContextDescription;39diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl40index 31d68292d4..2e98c8a6c5 10064441--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl42+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl43@@ -35,7 +35,7 @@44#endif45#define FSR2_BIND_SRV_INTERNAL_UPSCALED 346#define FSR2_BIND_SRV_LOCK_STATUS 447-#define FSR2_BIND_SRV_INPUT_DEPTH_CLIP 548+//#define FSR2_BIND_SRV_INPUT_DEPTH_CLIP 549#define FSR2_BIND_SRV_PREPARED_INPUT_COLOR 650#define FSR2_BIND_SRV_LUMA_INSTABILITY 751#define FSR2_BIND_SRV_LANCZOS_LUT 852@@ -52,6 +52,10 @@5354#define FSR2_BIND_CB_FSR2 185556+#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS57+#define FSR2_BIND_SRV_INPUT_DEPTH 558+#endif59+60#include "ffx_fsr2_callbacks_glsl.h"61#include "ffx_fsr2_common.h"62#include "ffx_fsr2_sample.h"63diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h b/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h64index 10da13fb81..b610037cc6 10064465--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h66+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h67@@ -52,6 +52,9 @@68FfxFloat32 fDeltaTime;69FfxFloat32 fDynamicResChangeFactor;70FfxFloat32 fViewSpaceToMetersFactor;71+72+ FfxFloat32 fPad;73+ mat4 mReprojectionMatrix;74} cbFSR2;75#endif7677@@ -317,7 +320,11 @@ FfxFloat32 LoadInputDepth(FfxInt32x2 iPxPos)78#if defined(FSR2_BIND_SRV_REACTIVE_MASK)79FfxFloat32 LoadReactiveMask(FfxInt32x2 iPxPos)80{81+#if FFX_FSR2_OPTION_GODOT_REACTIVE_MASK_CLAMP82+ return min(texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r, 0.9f);83+#else84return texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r;85+#endif86}87#endif8889@@ -354,6 +361,16 @@ FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos)90{91FfxFloat32x2 fSrcMotionVector = texelFetch(r_input_motion_vectors, iPxDilatedMotionVectorPos, 0).xy;9293+#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS94+ bool bInvalidMotionVector = all(lessThanEqual(fSrcMotionVector, vec2(-1.0f, -1.0f)));95+ if (bInvalidMotionVector)96+ {97+ FfxFloat32 fSrcDepth = LoadInputDepth(iPxDilatedMotionVectorPos);98+ FfxFloat32x2 fUv = (iPxDilatedMotionVectorPos + FfxFloat32(0.5)) / RenderSize();99+ fSrcMotionVector = FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS_FUNCTION(fUv, fSrcDepth, cbFSR2.mReprojectionMatrix);100+ }101+#endif102+103FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();104105#if FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS106diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl107index 7d6a66b8ac..5c042c332a 100644108--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl109+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl110@@ -40,6 +40,10 @@111#define FSR2_BIND_CB_FSR2 11112#define FSR2_BIND_CB_REACTIVE 12113114+#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS115+#define FSR2_BIND_SRV_INPUT_DEPTH 13116+#endif117+118#include "ffx_fsr2_callbacks_glsl.h"119#include "ffx_fsr2_common.h"120121122123