057367bf4f
Introduces support for FSR2 as a new upscaler option available from the project settings. Also introduces an specific render list for surfaces that require motion and the ability to derive motion vectors from depth buffer and camera motion.
265 lines
21 KiB
Diff
265 lines
21 KiB
Diff
diff --git a/thirdparty/amd-fsr2/ffx_fsr2.cpp b/thirdparty/amd-fsr2/ffx_fsr2.cpp
|
|
index 051018e437..864f7f1294 100644
|
|
--- a/thirdparty/amd-fsr2/ffx_fsr2.cpp
|
|
+++ b/thirdparty/amd-fsr2/ffx_fsr2.cpp
|
|
@@ -36,6 +36,17 @@
|
|
#pragma clang diagnostic ignored "-Wunused-variable"
|
|
#endif
|
|
|
|
+// -- GODOT start --
|
|
+#ifndef _countof
|
|
+#define _countof(array) (sizeof(array) / sizeof(array[0]))
|
|
+#endif
|
|
+
|
|
+#ifndef _MSC_VER
|
|
+#include <wchar.h>
|
|
+#define wcscpy_s wcscpy
|
|
+#endif
|
|
+// -- GODOT end --
|
|
+
|
|
// max queued frames for descriptor management
|
|
static const uint32_t FSR2_MAX_QUEUED_FRAMES = 16;
|
|
|
|
@@ -943,6 +954,10 @@ static FfxErrorCode fsr2Dispatch(FfxFsr2Context_Private* context, const FfxFsr2D
|
|
context->constants.lumaMipDimensions[0] = uint32_t(context->constants.maxRenderSize[0] / mipDiv);
|
|
context->constants.lumaMipDimensions[1] = uint32_t(context->constants.maxRenderSize[1] / mipDiv);
|
|
|
|
+ // -- GODOT start --
|
|
+ memcpy(context->constants.reprojectionMatrix, params->reprojectionMatrix, sizeof(context->constants.reprojectionMatrix));
|
|
+ // -- GODOT end --
|
|
+
|
|
// reactive mask bias
|
|
const int32_t threadGroupWorkRegionDim = 8;
|
|
const int32_t dispatchSrcX = (context->constants.renderSize[0] + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
|
|
diff --git a/thirdparty/amd-fsr2/ffx_fsr2.h b/thirdparty/amd-fsr2/ffx_fsr2.h
|
|
index 2a1c74abb1..7df3773ccc 100644
|
|
--- a/thirdparty/amd-fsr2/ffx_fsr2.h
|
|
+++ b/thirdparty/amd-fsr2/ffx_fsr2.h
|
|
@@ -146,6 +146,10 @@ typedef struct FfxFsr2DispatchDescription {
|
|
float autoReactiveScale; ///< A value to scale the reactive mask
|
|
float autoReactiveMax; ///< A value to clamp the reactive mask
|
|
|
|
+ // -- GODOT start --
|
|
+ float reprojectionMatrix[16]; ///< The matrix used for reprojecting pixels with invalid motion vectors by using the depth.
|
|
+ // -- GODOT end --
|
|
+
|
|
} FfxFsr2DispatchDescription;
|
|
|
|
/// A structure encapsulating the parameters for automatic generation of a reactive mask
|
|
diff --git a/thirdparty/amd-fsr2/ffx_fsr2_private.h b/thirdparty/amd-fsr2/ffx_fsr2_private.h
|
|
index 6b5fbc5117..0face069b6 100644
|
|
--- a/thirdparty/amd-fsr2/ffx_fsr2_private.h
|
|
+++ b/thirdparty/amd-fsr2/ffx_fsr2_private.h
|
|
@@ -44,6 +44,11 @@ typedef struct Fsr2Constants {
|
|
float deltaTime;
|
|
float dynamicResChangeFactor;
|
|
float viewSpaceToMetersFactor;
|
|
+
|
|
+ // -- GODOT start --
|
|
+ float pad;
|
|
+ float reprojectionMatrix[16];
|
|
+ // -- GODOT end --
|
|
} Fsr2Constants;
|
|
|
|
struct FfxFsr2ContextDescription;
|
|
diff --git a/thirdparty/amd-fsr2/ffx_types.h b/thirdparty/amd-fsr2/ffx_types.h
|
|
index 74edd192c4..8b65219b50 100644
|
|
--- a/thirdparty/amd-fsr2/ffx_types.h
|
|
+++ b/thirdparty/amd-fsr2/ffx_types.h
|
|
@@ -22,6 +22,9 @@
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
+// -- GODOT start --
|
|
+#include <stdlib.h>
|
|
+// -- GODOT end --
|
|
|
|
#if defined (FFX_GCC)
|
|
/// FidelityFX exported functions
|
|
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl
|
|
index 6006fd024e..d2306fec4c 100644
|
|
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl
|
|
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl
|
|
@@ -19,7 +19,7 @@
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
-#version 450
|
|
+
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_samplerless_texture_functions : require
|
|
@@ -35,7 +35,6 @@
|
|
#endif
|
|
#define FSR2_BIND_SRV_INTERNAL_UPSCALED 3
|
|
#define FSR2_BIND_SRV_LOCK_STATUS 4
|
|
-#define FSR2_BIND_SRV_INPUT_DEPTH_CLIP 5
|
|
#define FSR2_BIND_SRV_PREPARED_INPUT_COLOR 6
|
|
#define FSR2_BIND_SRV_LUMA_INSTABILITY 7
|
|
#define FSR2_BIND_SRV_LANCZOS_LUT 8
|
|
@@ -52,6 +51,12 @@
|
|
|
|
#define FSR2_BIND_CB_FSR2 18
|
|
|
|
+// -- GODOT start --
|
|
+#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS
|
|
+#define FSR2_BIND_SRV_INPUT_DEPTH 5
|
|
+#endif
|
|
+// -- GODOT end --
|
|
+
|
|
#include "ffx_fsr2_callbacks_glsl.h"
|
|
#include "ffx_fsr2_common.h"
|
|
#include "ffx_fsr2_sample.h"
|
|
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_autogen_reactive_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_autogen_reactive_pass.glsl
|
|
index 7ae41cf0c1..e62b445924 100644
|
|
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_autogen_reactive_pass.glsl
|
|
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_autogen_reactive_pass.glsl
|
|
@@ -19,7 +19,7 @@
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
-#version 450
|
|
+
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_samplerless_texture_functions : require
|
|
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h b/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h
|
|
index 10da13fb81..45279bd357 100644
|
|
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h
|
|
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h
|
|
@@ -52,6 +52,11 @@
|
|
FfxFloat32 fDeltaTime;
|
|
FfxFloat32 fDynamicResChangeFactor;
|
|
FfxFloat32 fViewSpaceToMetersFactor;
|
|
+
|
|
+ // -- GODOT start --
|
|
+ FfxFloat32 fPad;
|
|
+ mat4 mReprojectionMatrix;
|
|
+ // -- GODOT end --
|
|
} cbFSR2;
|
|
#endif
|
|
|
|
@@ -317,7 +322,13 @@ FfxFloat32 LoadInputDepth(FfxInt32x2 iPxPos)
|
|
#if defined(FSR2_BIND_SRV_REACTIVE_MASK)
|
|
FfxFloat32 LoadReactiveMask(FfxInt32x2 iPxPos)
|
|
{
|
|
+// -- GODOT start --
|
|
+#if FFX_FSR2_OPTION_GODOT_REACTIVE_MASK_CLAMP
|
|
+ return min(texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r, 0.9f);
|
|
+#else
|
|
return texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r;
|
|
+#endif
|
|
+// -- GODOT end --
|
|
}
|
|
#endif
|
|
|
|
@@ -354,6 +365,18 @@ FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos)
|
|
{
|
|
FfxFloat32x2 fSrcMotionVector = texelFetch(r_input_motion_vectors, iPxDilatedMotionVectorPos, 0).xy;
|
|
|
|
+// -- GODOT start --
|
|
+#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS
|
|
+ bool bInvalidMotionVector = all(lessThanEqual(fSrcMotionVector, vec2(-1.0f, -1.0f)));
|
|
+ if (bInvalidMotionVector)
|
|
+ {
|
|
+ FfxFloat32 fSrcDepth = LoadInputDepth(iPxDilatedMotionVectorPos);
|
|
+ FfxFloat32x2 fUv = (iPxDilatedMotionVectorPos + FfxFloat32(0.5)) / RenderSize();
|
|
+ fSrcMotionVector = FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS_FUNCTION(fUv, fSrcDepth, cbFSR2.mReprojectionMatrix);
|
|
+ }
|
|
+#endif
|
|
+// -- GODOT end --
|
|
+
|
|
FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();
|
|
|
|
#if FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
|
|
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_compute_luminance_pyramid_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_compute_luminance_pyramid_pass.glsl
|
|
index 3c99b9819a..088e425452 100644
|
|
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_compute_luminance_pyramid_pass.glsl
|
|
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_compute_luminance_pyramid_pass.glsl
|
|
@@ -19,7 +19,7 @@
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
-#version 450
|
|
+
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_samplerless_texture_functions : require
|
|
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_depth_clip_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_depth_clip_pass.glsl
|
|
index c7e30937a1..65cc8b67ef 100644
|
|
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_depth_clip_pass.glsl
|
|
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_depth_clip_pass.glsl
|
|
@@ -19,7 +19,7 @@
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
-#version 450
|
|
+
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_samplerless_texture_functions : require
|
|
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_lock_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_lock_pass.glsl
|
|
index f7cad59c20..0adce1bb11 100644
|
|
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_lock_pass.glsl
|
|
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_lock_pass.glsl
|
|
@@ -19,7 +19,7 @@
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
-#version 450
|
|
+
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_samplerless_texture_functions : require
|
|
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_rcas_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_rcas_pass.glsl
|
|
index 20807a32e9..f78fa53e6e 100644
|
|
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_rcas_pass.glsl
|
|
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_rcas_pass.glsl
|
|
@@ -19,7 +19,7 @@
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
-#version 450
|
|
+
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_samplerless_texture_functions : require
|
|
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_reconstruct_previous_depth_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_reconstruct_previous_depth_pass.glsl
|
|
index 20e17eef8c..25c18c0622 100644
|
|
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_reconstruct_previous_depth_pass.glsl
|
|
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_reconstruct_previous_depth_pass.glsl
|
|
@@ -19,7 +19,7 @@
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
-#version 450
|
|
+
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_samplerless_texture_functions : require
|
|
diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl
|
|
index bebca91099..12b4b40e08 100644
|
|
--- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl
|
|
+++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl
|
|
@@ -19,7 +19,7 @@
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
// THE SOFTWARE.
|
|
|
|
-#version 450
|
|
+
|
|
|
|
#extension GL_GOOGLE_include_directive : require
|
|
#extension GL_EXT_samplerless_texture_functions : require
|
|
@@ -40,6 +40,12 @@
|
|
#define FSR2_BIND_CB_FSR2 11
|
|
#define FSR2_BIND_CB_REACTIVE 12
|
|
|
|
+// -- GODOT start --
|
|
+#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS
|
|
+#define FSR2_BIND_SRV_INPUT_DEPTH 13
|
|
+#endif
|
|
+// -- GODOT end --
|
|
+
|
|
#include "ffx_fsr2_callbacks_glsl.h"
|
|
#include "ffx_fsr2_common.h"
|
|
|