2
0

godot-changes.patch 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. diff --git a/thirdparty/amd-fsr2/ffx_fsr2.cpp b/thirdparty/amd-fsr2/ffx_fsr2.cpp
  2. index 051018e437..864f7f1294 100644
  3. --- a/thirdparty/amd-fsr2/ffx_fsr2.cpp
  4. +++ b/thirdparty/amd-fsr2/ffx_fsr2.cpp
  5. @@ -36,6 +36,17 @@
  6. #pragma clang diagnostic ignored "-Wunused-variable"
  7. #endif
  8. +// -- GODOT start --
  9. +#ifndef _countof
  10. +#define _countof(array) (sizeof(array) / sizeof(array[0]))
  11. +#endif
  12. +
  13. +#ifndef _MSC_VER
  14. +#include <wchar.h>
  15. +#define wcscpy_s wcscpy
  16. +#endif
  17. +// -- GODOT end --
  18. +
  19. // max queued frames for descriptor management
  20. static const uint32_t FSR2_MAX_QUEUED_FRAMES = 16;
  21. @@ -943,6 +954,10 @@ static FfxErrorCode fsr2Dispatch(FfxFsr2Context_Private* context, const FfxFsr2D
  22. context->constants.lumaMipDimensions[0] = uint32_t(context->constants.maxRenderSize[0] / mipDiv);
  23. context->constants.lumaMipDimensions[1] = uint32_t(context->constants.maxRenderSize[1] / mipDiv);
  24. + // -- GODOT start --
  25. + memcpy(context->constants.reprojectionMatrix, params->reprojectionMatrix, sizeof(context->constants.reprojectionMatrix));
  26. + // -- GODOT end --
  27. +
  28. // reactive mask bias
  29. const int32_t threadGroupWorkRegionDim = 8;
  30. const int32_t dispatchSrcX = (context->constants.renderSize[0] + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
  31. diff --git a/thirdparty/amd-fsr2/ffx_fsr2.h b/thirdparty/amd-fsr2/ffx_fsr2.h
  32. index 2a1c74abb1..7df3773ccc 100644
  33. --- a/thirdparty/amd-fsr2/ffx_fsr2.h
  34. +++ b/thirdparty/amd-fsr2/ffx_fsr2.h
  35. @@ -146,6 +146,10 @@ typedef struct FfxFsr2DispatchDescription {
  36. float autoReactiveScale; ///< A value to scale the reactive mask
  37. float autoReactiveMax; ///< A value to clamp the reactive mask
  38. + // -- GODOT start --
  39. + float reprojectionMatrix[16]; ///< The matrix used for reprojecting pixels with invalid motion vectors by using the depth.
  40. + // -- GODOT end --
  41. +
  42. } FfxFsr2DispatchDescription;
  43. /// A structure encapsulating the parameters for automatic generation of a reactive mask
  44. diff --git a/thirdparty/amd-fsr2/ffx_fsr2_private.h b/thirdparty/amd-fsr2/ffx_fsr2_private.h
  45. index 6b5fbc5117..0face069b6 100644
  46. --- a/thirdparty/amd-fsr2/ffx_fsr2_private.h
  47. +++ b/thirdparty/amd-fsr2/ffx_fsr2_private.h
  48. @@ -44,6 +44,11 @@ typedef struct Fsr2Constants {
  49. float deltaTime;
  50. float dynamicResChangeFactor;
  51. float viewSpaceToMetersFactor;
  52. +
  53. + // -- GODOT start --
  54. + float pad;
  55. + float reprojectionMatrix[16];
  56. + // -- GODOT end --
  57. } Fsr2Constants;
  58. struct FfxFsr2ContextDescription;
  59. diff --git a/thirdparty/amd-fsr2/ffx_types.h b/thirdparty/amd-fsr2/ffx_types.h
  60. index 74edd192c4..8b65219b50 100644
  61. --- a/thirdparty/amd-fsr2/ffx_types.h
  62. +++ b/thirdparty/amd-fsr2/ffx_types.h
  63. @@ -22,6 +22,9 @@
  64. #pragma once
  65. #include <stdint.h>
  66. +// -- GODOT start --
  67. +#include <stdlib.h>
  68. +// -- GODOT end --
  69. #if defined (FFX_GCC)
  70. /// FidelityFX exported functions
  71. diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl
  72. index 6006fd024e..d2306fec4c 100644
  73. --- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl
  74. +++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_accumulate_pass.glsl
  75. @@ -19,7 +19,7 @@
  76. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  77. // THE SOFTWARE.
  78. -#version 450
  79. +
  80. #extension GL_GOOGLE_include_directive : require
  81. #extension GL_EXT_samplerless_texture_functions : require
  82. @@ -35,7 +35,6 @@
  83. #endif
  84. #define FSR2_BIND_SRV_INTERNAL_UPSCALED 3
  85. #define FSR2_BIND_SRV_LOCK_STATUS 4
  86. -#define FSR2_BIND_SRV_INPUT_DEPTH_CLIP 5
  87. #define FSR2_BIND_SRV_PREPARED_INPUT_COLOR 6
  88. #define FSR2_BIND_SRV_LUMA_INSTABILITY 7
  89. #define FSR2_BIND_SRV_LANCZOS_LUT 8
  90. @@ -52,6 +51,12 @@
  91. #define FSR2_BIND_CB_FSR2 18
  92. +// -- GODOT start --
  93. +#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS
  94. +#define FSR2_BIND_SRV_INPUT_DEPTH 5
  95. +#endif
  96. +// -- GODOT end --
  97. +
  98. #include "ffx_fsr2_callbacks_glsl.h"
  99. #include "ffx_fsr2_common.h"
  100. #include "ffx_fsr2_sample.h"
  101. diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_autogen_reactive_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_autogen_reactive_pass.glsl
  102. index 7ae41cf0c1..e62b445924 100644
  103. --- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_autogen_reactive_pass.glsl
  104. +++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_autogen_reactive_pass.glsl
  105. @@ -19,7 +19,7 @@
  106. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  107. // THE SOFTWARE.
  108. -#version 450
  109. +
  110. #extension GL_GOOGLE_include_directive : require
  111. #extension GL_EXT_samplerless_texture_functions : require
  112. diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h b/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h
  113. index 10da13fb81..45279bd357 100644
  114. --- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h
  115. +++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h
  116. @@ -52,6 +52,11 @@
  117. FfxFloat32 fDeltaTime;
  118. FfxFloat32 fDynamicResChangeFactor;
  119. FfxFloat32 fViewSpaceToMetersFactor;
  120. +
  121. + // -- GODOT start --
  122. + FfxFloat32 fPad;
  123. + mat4 mReprojectionMatrix;
  124. + // -- GODOT end --
  125. } cbFSR2;
  126. #endif
  127. @@ -317,7 +322,13 @@ FfxFloat32 LoadInputDepth(FfxInt32x2 iPxPos)
  128. #if defined(FSR2_BIND_SRV_REACTIVE_MASK)
  129. FfxFloat32 LoadReactiveMask(FfxInt32x2 iPxPos)
  130. {
  131. +// -- GODOT start --
  132. +#if FFX_FSR2_OPTION_GODOT_REACTIVE_MASK_CLAMP
  133. + return min(texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r, 0.9f);
  134. +#else
  135. return texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r;
  136. +#endif
  137. +// -- GODOT end --
  138. }
  139. #endif
  140. @@ -354,6 +365,18 @@ FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos)
  141. {
  142. FfxFloat32x2 fSrcMotionVector = texelFetch(r_input_motion_vectors, iPxDilatedMotionVectorPos, 0).xy;
  143. +// -- GODOT start --
  144. +#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS
  145. + bool bInvalidMotionVector = all(lessThanEqual(fSrcMotionVector, vec2(-1.0f, -1.0f)));
  146. + if (bInvalidMotionVector)
  147. + {
  148. + FfxFloat32 fSrcDepth = LoadInputDepth(iPxDilatedMotionVectorPos);
  149. + FfxFloat32x2 fUv = (iPxDilatedMotionVectorPos + FfxFloat32(0.5)) / RenderSize();
  150. + fSrcMotionVector = FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS_FUNCTION(fUv, fSrcDepth, cbFSR2.mReprojectionMatrix);
  151. + }
  152. +#endif
  153. +// -- GODOT end --
  154. +
  155. FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();
  156. #if FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
  157. 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
  158. index 3c99b9819a..088e425452 100644
  159. --- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_compute_luminance_pyramid_pass.glsl
  160. +++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_compute_luminance_pyramid_pass.glsl
  161. @@ -19,7 +19,7 @@
  162. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  163. // THE SOFTWARE.
  164. -#version 450
  165. +
  166. #extension GL_GOOGLE_include_directive : require
  167. #extension GL_EXT_samplerless_texture_functions : require
  168. diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_depth_clip_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_depth_clip_pass.glsl
  169. index c7e30937a1..65cc8b67ef 100644
  170. --- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_depth_clip_pass.glsl
  171. +++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_depth_clip_pass.glsl
  172. @@ -19,7 +19,7 @@
  173. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  174. // THE SOFTWARE.
  175. -#version 450
  176. +
  177. #extension GL_GOOGLE_include_directive : require
  178. #extension GL_EXT_samplerless_texture_functions : require
  179. diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_lock_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_lock_pass.glsl
  180. index f7cad59c20..0adce1bb11 100644
  181. --- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_lock_pass.glsl
  182. +++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_lock_pass.glsl
  183. @@ -19,7 +19,7 @@
  184. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  185. // THE SOFTWARE.
  186. -#version 450
  187. +
  188. #extension GL_GOOGLE_include_directive : require
  189. #extension GL_EXT_samplerless_texture_functions : require
  190. diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_rcas_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_rcas_pass.glsl
  191. index 20807a32e9..f78fa53e6e 100644
  192. --- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_rcas_pass.glsl
  193. +++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_rcas_pass.glsl
  194. @@ -19,7 +19,7 @@
  195. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  196. // THE SOFTWARE.
  197. -#version 450
  198. +
  199. #extension GL_GOOGLE_include_directive : require
  200. #extension GL_EXT_samplerless_texture_functions : require
  201. 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
  202. index 20e17eef8c..25c18c0622 100644
  203. --- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_reconstruct_previous_depth_pass.glsl
  204. +++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_reconstruct_previous_depth_pass.glsl
  205. @@ -19,7 +19,7 @@
  206. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  207. // THE SOFTWARE.
  208. -#version 450
  209. +
  210. #extension GL_GOOGLE_include_directive : require
  211. #extension GL_EXT_samplerless_texture_functions : require
  212. diff --git a/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl b/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl
  213. index bebca91099..12b4b40e08 100644
  214. --- a/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl
  215. +++ b/thirdparty/amd-fsr2/shaders/ffx_fsr2_tcr_autogen_pass.glsl
  216. @@ -19,7 +19,7 @@
  217. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  218. // THE SOFTWARE.
  219. -#version 450
  220. +
  221. #extension GL_GOOGLE_include_directive : require
  222. #extension GL_EXT_samplerless_texture_functions : require
  223. @@ -40,6 +40,12 @@
  224. #define FSR2_BIND_CB_FSR2 11
  225. #define FSR2_BIND_CB_REACTIVE 12
  226. +// -- GODOT start --
  227. +#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS
  228. +#define FSR2_BIND_SRV_INPUT_DEPTH 13
  229. +#endif
  230. +// -- GODOT end --
  231. +
  232. #include "ffx_fsr2_callbacks_glsl.h"
  233. #include "ffx_fsr2_common.h"