ffx_fsr2.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. // This file is part of the FidelityFX SDK.
  2. //
  3. // Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. // @defgroup FSR2
  22. #pragma once
  23. // Include the interface for the backend of the FSR2 API.
  24. #include "ffx_fsr2_interface.h"
  25. /// FidelityFX Super Resolution 2 major version.
  26. ///
  27. /// @ingroup FSR2
  28. #define FFX_FSR2_VERSION_MAJOR (2)
  29. /// FidelityFX Super Resolution 2 minor version.
  30. ///
  31. /// @ingroup FSR2
  32. #define FFX_FSR2_VERSION_MINOR (2)
  33. /// FidelityFX Super Resolution 2 patch version.
  34. ///
  35. /// @ingroup FSR2
  36. #define FFX_FSR2_VERSION_PATCH (1)
  37. /// The size of the context specified in 32bit values.
  38. ///
  39. /// @ingroup FSR2
  40. #define FFX_FSR2_CONTEXT_SIZE (16536)
  41. #if defined(__cplusplus)
  42. extern "C" {
  43. #endif // #if defined(__cplusplus)
  44. /// An enumeration of all the quality modes supported by FidelityFX Super
  45. /// Resolution 2 upscaling.
  46. ///
  47. /// In order to provide a consistent user experience across multiple
  48. /// applications which implement FSR2. It is strongly recommended that the
  49. /// following preset scaling factors are made available through your
  50. /// application's user interface.
  51. ///
  52. /// If your application does not expose the notion of preset scaling factors
  53. /// for upscaling algorithms (perhaps instead implementing a fixed ratio which
  54. /// is immutable) or implementing a more dynamic scaling scheme (such as
  55. /// dynamic resolution scaling), then there is no need to use these presets.
  56. ///
  57. /// Please note that <c><i>FFX_FSR2_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> is
  58. /// an optional mode which may introduce significant quality degradation in the
  59. /// final image. As such it is recommended that you evaluate the final results
  60. /// of using this scaling mode before deciding if you should include it in your
  61. /// application.
  62. ///
  63. /// @ingroup FSR2
  64. typedef enum FfxFsr2QualityMode {
  65. FFX_FSR2_QUALITY_MODE_QUALITY = 1, ///< Perform upscaling with a per-dimension upscaling ratio of 1.5x.
  66. FFX_FSR2_QUALITY_MODE_BALANCED = 2, ///< Perform upscaling with a per-dimension upscaling ratio of 1.7x.
  67. FFX_FSR2_QUALITY_MODE_PERFORMANCE = 3, ///< Perform upscaling with a per-dimension upscaling ratio of 2.0x.
  68. FFX_FSR2_QUALITY_MODE_ULTRA_PERFORMANCE = 4 ///< Perform upscaling with a per-dimension upscaling ratio of 3.0x.
  69. } FfxFsr2QualityMode;
  70. /// An enumeration of bit flags used when creating a
  71. /// <c><i>FfxFsr2Context</i></c>. See <c><i>FfxFsr2ContextDescription</i></c>.
  72. ///
  73. /// @ingroup FSR2
  74. typedef enum FfxFsr2InitializationFlagBits {
  75. FFX_FSR2_ENABLE_HIGH_DYNAMIC_RANGE = (1<<0), ///< A bit indicating if the input color data provided is using a high-dynamic range.
  76. FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS = (1<<1), ///< A bit indicating if the motion vectors are rendered at display resolution.
  77. FFX_FSR2_ENABLE_MOTION_VECTORS_JITTER_CANCELLATION = (1<<2), ///< A bit indicating that the motion vectors have the jittering pattern applied to them.
  78. FFX_FSR2_ENABLE_DEPTH_INVERTED = (1<<3), ///< A bit indicating that the input depth buffer data provided is inverted [1..0].
  79. FFX_FSR2_ENABLE_DEPTH_INFINITE = (1<<4), ///< A bit indicating that the input depth buffer data provided is using an infinite far plane.
  80. FFX_FSR2_ENABLE_AUTO_EXPOSURE = (1<<5), ///< A bit indicating if automatic exposure should be applied to input color data.
  81. FFX_FSR2_ENABLE_DYNAMIC_RESOLUTION = (1<<6), ///< A bit indicating that the application uses dynamic resolution scaling.
  82. FFX_FSR2_ENABLE_TEXTURE1D_USAGE = (1<<7), ///< A bit indicating that the backend should use 1D textures.
  83. FFX_FSR2_ENABLE_DEBUG_CHECKING = (1<<8), ///< A bit indicating that the runtime should check some API values and report issues.
  84. } FfxFsr2InitializationFlagBits;
  85. /// A structure encapsulating the parameters required to initialize FidelityFX
  86. /// Super Resolution 2 upscaling.
  87. ///
  88. /// @ingroup FSR2
  89. typedef struct FfxFsr2ContextDescription {
  90. uint32_t flags; ///< A collection of <c><i>FfxFsr2InitializationFlagBits</i></c>.
  91. FfxDimensions2D maxRenderSize; ///< The maximum size that rendering will be performed at.
  92. FfxDimensions2D displaySize; ///< The size of the presentation resolution targeted by the upscaling process.
  93. FfxFsr2Interface callbacks; ///< A set of pointers to the backend implementation for FSR 2.0.
  94. FfxDevice device; ///< The abstracted device which is passed to some callback functions.
  95. FfxFsr2Message fpMessage; ///< A pointer to a function that can recieve messages from the runtime.
  96. } FfxFsr2ContextDescription;
  97. /// A structure encapsulating the parameters for dispatching the various passes
  98. /// of FidelityFX Super Resolution 2.
  99. ///
  100. /// @ingroup FSR2
  101. typedef struct FfxFsr2DispatchDescription {
  102. FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR2 rendering commands into.
  103. FfxResource color; ///< A <c><i>FfxResource</i></c> containing the color buffer for the current frame (at render resolution).
  104. FfxResource depth; ///< A <c><i>FfxResource</i></c> containing 32bit depth values for the current frame (at render resolution).
  105. FfxResource motionVectors; ///< A <c><i>FfxResource</i></c> containing 2-dimensional motion vectors (at render resolution if <c><i>FFX_FSR2_ENABLE_DISPLAY_RESOLUTION_MOTION_VECTORS</i></c> is not set).
  106. FfxResource exposure; ///< A optional <c><i>FfxResource</i></c> containing a 1x1 exposure value.
  107. FfxResource reactive; ///< A optional <c><i>FfxResource</i></c> containing alpha value of reactive objects in the scene.
  108. FfxResource transparencyAndComposition; ///< A optional <c><i>FfxResource</i></c> containing alpha value of special objects in the scene.
  109. FfxResource output; ///< A <c><i>FfxResource</i></c> containing the output color buffer for the current frame (at presentation resolution).
  110. FfxFloatCoords2D jitterOffset; ///< The subpixel jitter offset applied to the camera.
  111. FfxFloatCoords2D motionVectorScale; ///< The scale factor to apply to motion vectors.
  112. FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
  113. bool enableSharpening; ///< Enable an additional sharpening pass.
  114. float sharpness; ///< The sharpness value between 0 and 1, where 0 is no additional sharpness and 1 is maximum additional sharpness.
  115. float frameTimeDelta; ///< The time elapsed since the last frame (expressed in milliseconds).
  116. float preExposure; ///< The pre exposure value (must be > 0.0f)
  117. bool reset; ///< A boolean value which when set to true, indicates the camera has moved discontinuously.
  118. float cameraNear; ///< The distance to the near plane of the camera.
  119. float cameraFar; ///< The distance to the far plane of the camera.
  120. float cameraFovAngleVertical; ///< The camera angle field of view in the vertical direction (expressed in radians).
  121. float viewSpaceToMetersFactor; ///< The scale factor to convert view space units to meters
  122. // EXPERIMENTAL reactive mask generation parameters
  123. bool enableAutoReactive; ///< A boolean value to indicate internal reactive autogeneration should be used
  124. FfxResource colorOpaqueOnly; ///< A <c><i>FfxResource</i></c> containing the opaque only color buffer for the current frame (at render resolution).
  125. float autoTcThreshold; ///< Cutoff value for TC
  126. float autoTcScale; ///< A value to scale the transparency and composition mask
  127. float autoReactiveScale; ///< A value to scale the reactive mask
  128. float autoReactiveMax; ///< A value to clamp the reactive mask
  129. // -- GODOT start --
  130. float reprojectionMatrix[16]; ///< The matrix used for reprojecting pixels with invalid motion vectors by using the depth.
  131. // -- GODOT end --
  132. } FfxFsr2DispatchDescription;
  133. /// A structure encapsulating the parameters for automatic generation of a reactive mask
  134. ///
  135. /// @ingroup FSR2
  136. typedef struct FfxFsr2GenerateReactiveDescription {
  137. FfxCommandList commandList; ///< The <c><i>FfxCommandList</i></c> to record FSR2 rendering commands into.
  138. FfxResource colorOpaqueOnly; ///< A <c><i>FfxResource</i></c> containing the opaque only color buffer for the current frame (at render resolution).
  139. FfxResource colorPreUpscale; ///< A <c><i>FfxResource</i></c> containing the opaque+translucent color buffer for the current frame (at render resolution).
  140. FfxResource outReactive; ///< A <c><i>FfxResource</i></c> containing the surface to generate the reactive mask into.
  141. FfxDimensions2D renderSize; ///< The resolution that was used for rendering the input resources.
  142. float scale; ///< A value to scale the output
  143. float cutoffThreshold; ///< A threshold value to generate a binary reactive mask
  144. float binaryValue; ///< A value to set for the binary reactive mask
  145. uint32_t flags; ///< Flags to determine how to generate the reactive mask
  146. } FfxFsr2GenerateReactiveDescription;
  147. /// A structure encapsulating the FidelityFX Super Resolution 2 context.
  148. ///
  149. /// This sets up an object which contains all persistent internal data and
  150. /// resources that are required by FSR2.
  151. ///
  152. /// The <c><i>FfxFsr2Context</i></c> object should have a lifetime matching
  153. /// your use of FSR2. Before destroying the FSR2 context care should be taken
  154. /// to ensure the GPU is not accessing the resources created or used by FSR2.
  155. /// It is therefore recommended that the GPU is idle before destroying the
  156. /// FSR2 context.
  157. ///
  158. /// @ingroup FSR2
  159. typedef struct FfxFsr2Context {
  160. uint32_t data[FFX_FSR2_CONTEXT_SIZE]; ///< An opaque set of <c>uint32_t</c> which contain the data for the context.
  161. } FfxFsr2Context;
  162. /// Create a FidelityFX Super Resolution 2 context from the parameters
  163. /// programmed to the <c><i>FfxFsr2CreateParams</i></c> structure.
  164. ///
  165. /// The context structure is the main object used to interact with the FSR2
  166. /// API, and is responsible for the management of the internal resources used
  167. /// by the FSR2 algorithm. When this API is called, multiple calls will be
  168. /// made via the pointers contained in the <c><i>callbacks</i></c> structure.
  169. /// These callbacks will attempt to retreive the device capabilities, and
  170. /// create the internal resources, and pipelines required by FSR2's
  171. /// frame-to-frame function. Depending on the precise configuration used when
  172. /// creating the <c><i>FfxFsr2Context</i></c> a different set of resources and
  173. /// pipelines might be requested via the callback functions.
  174. ///
  175. /// The flags included in the <c><i>flags</i></c> field of
  176. /// <c><i>FfxFsr2Context</i></c> how match the configuration of your
  177. /// application as well as the intended use of FSR2. It is important that these
  178. /// flags are set correctly (as well as a correct programmed
  179. /// <c><i>FfxFsr2DispatchDescription</i></c>) to ensure correct operation. It is
  180. /// recommended to consult the overview documentation for further details on
  181. /// how FSR2 should be integerated into an application.
  182. ///
  183. /// When the <c><i>FfxFsr2Context</i></c> is created, you should use the
  184. /// <c><i>ffxFsr2ContextDispatch</i></c> function each frame where FSR2
  185. /// upscaling should be applied. See the documentation of
  186. /// <c><i>ffxFsr2ContextDispatch</i></c> for more details.
  187. ///
  188. /// The <c><i>FfxFsr2Context</i></c> should be destroyed when use of it is
  189. /// completed, typically when an application is unloaded or FSR2 upscaling is
  190. /// disabled by a user. To destroy the FSR2 context you should call
  191. /// <c><i>ffxFsr2ContextDestroy</i></c>.
  192. ///
  193. /// @param [out] context A pointer to a <c><i>FfxFsr2Context</i></c> structure to populate.
  194. /// @param [in] contextDescription A pointer to a <c><i>FfxFsr2ContextDescription</i></c> structure.
  195. ///
  196. /// @retval
  197. /// FFX_OK The operation completed successfully.
  198. /// @retval
  199. /// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>contextDescription</i></c> was <c><i>NULL</i></c>.
  200. /// @retval
  201. /// FFX_ERROR_INCOMPLETE_INTERFACE The operation failed because the <c><i>FfxFsr2ContextDescription.callbacks</i></c> was not fully specified.
  202. /// @retval
  203. /// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
  204. ///
  205. /// @ingroup FSR2
  206. FFX_API FfxErrorCode ffxFsr2ContextCreate(FfxFsr2Context* context, const FfxFsr2ContextDescription* contextDescription);
  207. /// Dispatch the various passes that constitute FidelityFX Super Resolution 2.
  208. ///
  209. /// FSR2 is a composite effect, meaning that it is compromised of multiple
  210. /// constituent passes (implemented as one or more clears, copies and compute
  211. /// dispatches). The <c><i>ffxFsr2ContextDispatch</i></c> function is the
  212. /// function which (via the use of the functions contained in the
  213. /// <c><i>callbacks</i></c> field of the <c><i>FfxFsr2Context</i></c>
  214. /// structure) utlimately generates the sequence of graphics API calls required
  215. /// each frame.
  216. ///
  217. /// As with the creation of the <c><i>FfxFsr2Context</i></c> correctly
  218. /// programming the <c><i>FfxFsr2DispatchDescription</i></c> is key to ensuring
  219. /// the correct operation of FSR2. It is particularly important to ensure that
  220. /// camera jitter is correctly applied to your application's projection matrix
  221. /// (or camera origin for raytraced applications). FSR2 provides the
  222. /// <c><i>ffxFsr2GetJitterPhaseCount</i></c> and
  223. /// <c><i>ffxFsr2GetJitterOffset</i></c> entry points to help applications
  224. /// correctly compute the camera jitter. Whatever jitter pattern is used by the
  225. /// application it should be correctly programmed to the
  226. /// <c><i>jitterOffset</i></c> field of the <c><i>dispatchDescription</i></c>
  227. /// structure. For more guidance on camera jitter please consult the
  228. /// documentation for <c><i>ffxFsr2GetJitterOffset</i></c> as well as the
  229. /// accompanying overview documentation for FSR2.
  230. ///
  231. /// @param [in] context A pointer to a <c><i>FfxFsr2Context</i></c> structure.
  232. /// @param [in] dispatchDescription A pointer to a <c><i>FfxFsr2DispatchDescription</i></c> structure.
  233. ///
  234. /// @retval
  235. /// FFX_OK The operation completed successfully.
  236. /// @retval
  237. /// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> or <c><i>dispatchDescription</i></c> was <c><i>NULL</i></c>.
  238. /// @retval
  239. /// FFX_ERROR_OUT_OF_RANGE The operation failed because <c><i>dispatchDescription.renderSize</i></c> was larger than the maximum render resolution.
  240. /// @retval
  241. /// FFX_ERROR_NULL_DEVICE The operation failed because the device inside the context was <c><i>NULL</i></c>.
  242. /// @retval
  243. /// FFX_ERROR_BACKEND_API_ERROR The operation failed because of an error returned from the backend.
  244. ///
  245. /// @ingroup FSR2
  246. FFX_API FfxErrorCode ffxFsr2ContextDispatch(FfxFsr2Context* context, const FfxFsr2DispatchDescription* dispatchDescription);
  247. /// A helper function generate a Reactive mask from an opaque only texure and one containing translucent objects.
  248. ///
  249. /// @param [in] context A pointer to a <c><i>FfxFsr2Context</i></c> structure.
  250. /// @param [in] params A pointer to a <c><i>FfxFsr2GenerateReactiveDescription</i></c> structure
  251. ///
  252. /// @retval
  253. /// FFX_OK The operation completed successfully.
  254. ///
  255. /// @ingroup FSR2
  256. FFX_API FfxErrorCode ffxFsr2ContextGenerateReactiveMask(FfxFsr2Context* context, const FfxFsr2GenerateReactiveDescription* params);
  257. /// Destroy the FidelityFX Super Resolution context.
  258. ///
  259. /// @param [out] context A pointer to a <c><i>FfxFsr2Context</i></c> structure to destroy.
  260. ///
  261. /// @retval
  262. /// FFX_OK The operation completed successfully.
  263. /// @retval
  264. /// FFX_ERROR_CODE_NULL_POINTER The operation failed because either <c><i>context</i></c> was <c><i>NULL</i></c>.
  265. ///
  266. /// @ingroup FSR2
  267. FFX_API FfxErrorCode ffxFsr2ContextDestroy(FfxFsr2Context* context);
  268. /// Get the upscale ratio from the quality mode.
  269. ///
  270. /// The following table enumerates the mapping of the quality modes to
  271. /// per-dimension scaling ratios.
  272. ///
  273. /// Quality preset | Scale factor
  274. /// ----------------------------------------------------- | -------------
  275. /// <c><i>FFX_FSR2_QUALITY_MODE_QUALITY</i></c> | 1.5x
  276. /// <c><i>FFX_FSR2_QUALITY_MODE_BALANCED</i></c> | 1.7x
  277. /// <c><i>FFX_FSR2_QUALITY_MODE_PERFORMANCE</i></c> | 2.0x
  278. /// <c><i>FFX_FSR2_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> | 3.0x
  279. ///
  280. /// Passing an invalid <c><i>qualityMode</i></c> will return 0.0f.
  281. ///
  282. /// @param [in] qualityMode The quality mode preset.
  283. ///
  284. /// @returns
  285. /// The upscaling the per-dimension upscaling ratio for
  286. /// <c><i>qualityMode</i></c> according to the table above.
  287. ///
  288. /// @ingroup FSR2
  289. FFX_API float ffxFsr2GetUpscaleRatioFromQualityMode(FfxFsr2QualityMode qualityMode);
  290. /// A helper function to calculate the rendering resolution from a target
  291. /// resolution and desired quality level.
  292. ///
  293. /// This function applies the scaling factor returned by
  294. /// <c><i>ffxFsr2GetUpscaleRatioFromQualityMode</i></c> to each dimension.
  295. ///
  296. /// @param [out] renderWidth A pointer to a <c>uint32_t</c> which will hold the calculated render resolution width.
  297. /// @param [out] renderHeight A pointer to a <c>uint32_t</c> which will hold the calculated render resolution height.
  298. /// @param [in] displayWidth The target display resolution width.
  299. /// @param [in] displayHeight The target display resolution height.
  300. /// @param [in] qualityMode The desired quality mode for FSR 2 upscaling.
  301. ///
  302. /// @retval
  303. /// FFX_OK The operation completed successfully.
  304. /// @retval
  305. /// FFX_ERROR_INVALID_POINTER Either <c><i>renderWidth</i></c> or <c><i>renderHeight</i></c> was <c>NULL</c>.
  306. /// @retval
  307. /// FFX_ERROR_INVALID_ENUM An invalid quality mode was specified.
  308. ///
  309. /// @ingroup FSR2
  310. FFX_API FfxErrorCode ffxFsr2GetRenderResolutionFromQualityMode(
  311. uint32_t* renderWidth,
  312. uint32_t* renderHeight,
  313. uint32_t displayWidth,
  314. uint32_t displayHeight,
  315. FfxFsr2QualityMode qualityMode);
  316. /// A helper function to calculate the jitter phase count from display
  317. /// resolution.
  318. ///
  319. /// For more detailed information about the application of camera jitter to
  320. /// your application's rendering please refer to the
  321. /// <c><i>ffxFsr2GetJitterOffset</i></c> function.
  322. ///
  323. /// The table below shows the jitter phase count which this function
  324. /// would return for each of the quality presets.
  325. ///
  326. /// Quality preset | Scale factor | Phase count
  327. /// ----------------------------------------------------- | ------------- | ---------------
  328. /// <c><i>FFX_FSR2_QUALITY_MODE_QUALITY</i></c> | 1.5x | 18
  329. /// <c><i>FFX_FSR2_QUALITY_MODE_BALANCED</i></c> | 1.7x | 23
  330. /// <c><i>FFX_FSR2_QUALITY_MODE_PERFORMANCE</i></c> | 2.0x | 32
  331. /// <c><i>FFX_FSR2_QUALITY_MODE_ULTRA_PERFORMANCE</i></c> | 3.0x | 72
  332. /// Custom | [1..n]x | ceil(8*n^2)
  333. ///
  334. /// @param [in] renderWidth The render resolution width.
  335. /// @param [in] displayWidth The display resolution width.
  336. ///
  337. /// @returns
  338. /// The jitter phase count for the scaling factor between <c><i>renderWidth</i></c> and <c><i>displayWidth</i></c>.
  339. ///
  340. /// @ingroup FSR2
  341. FFX_API int32_t ffxFsr2GetJitterPhaseCount(int32_t renderWidth, int32_t displayWidth);
  342. /// A helper function to calculate the subpixel jitter offset.
  343. ///
  344. /// FSR2 relies on the application to apply sub-pixel jittering while rendering.
  345. /// This is typically included in the projection matrix of the camera. To make
  346. /// the application of camera jitter simple, the FSR2 API provides a small set
  347. /// of utility function which computes the sub-pixel jitter offset for a
  348. /// particular frame within a sequence of separate jitter offsets. To begin, the
  349. /// index within the jitter phase must be computed. To calculate the
  350. /// sequence's length, you can call the <c><i>ffxFsr2GetJitterPhaseCount</i></c>
  351. /// function. The index should be a value which is incremented each frame modulo
  352. /// the length of the sequence computed by <c><i>ffxFsr2GetJitterPhaseCount</i></c>.
  353. /// The index within the jitter phase is passed to
  354. /// <c><i>ffxFsr2GetJitterOffset</i></c> via the <c><i>index</i></c> parameter.
  355. ///
  356. /// This function uses a Halton(2,3) sequence to compute the jitter offset.
  357. /// The ultimate index used for the sequence is <c><i>index</i></c> %
  358. /// <c><i>phaseCount</i></c>.
  359. ///
  360. /// It is important to understand that the values returned from the
  361. /// <c><i>ffxFsr2GetJitterOffset</i></c> function are in unit pixel space, and
  362. /// in order to composite this correctly into a projection matrix we must
  363. /// convert them into projection offsets. This is done as per the pseudo code
  364. /// listing which is shown below.
  365. ///
  366. /// const int32_t jitterPhaseCount = ffxFsr2GetJitterPhaseCount(renderWidth, displayWidth);
  367. ///
  368. /// float jitterX = 0;
  369. /// float jitterY = 0;
  370. /// ffxFsr2GetJitterOffset(&jitterX, &jitterY, index, jitterPhaseCount);
  371. ///
  372. /// const float jitterX = 2.0f * jitterX / (float)renderWidth;
  373. /// const float jitterY = -2.0f * jitterY / (float)renderHeight;
  374. /// const Matrix4 jitterTranslationMatrix = translateMatrix(Matrix3::identity, Vector3(jitterX, jitterY, 0));
  375. /// const Matrix4 jitteredProjectionMatrix = jitterTranslationMatrix * projectionMatrix;
  376. ///
  377. /// Jitter should be applied to all rendering. This includes opaque, alpha
  378. /// transparent, and raytraced objects. For rasterized objects, the sub-pixel
  379. /// jittering values calculated by the <c><i>iffxFsr2GetJitterOffset</i></c>
  380. /// function can be applied to the camera projection matrix which is ultimately
  381. /// used to perform transformations during vertex shading. For raytraced
  382. /// rendering, the sub-pixel jitter should be applied to the ray's origin,
  383. /// often the camera's position.
  384. ///
  385. /// Whether you elect to use the <c><i>ffxFsr2GetJitterOffset</i></c> function
  386. /// or your own sequence generator, you must program the
  387. /// <c><i>jitterOffset</i></c> field of the
  388. /// <c><i>FfxFsr2DispatchParameters</i></c> structure in order to inform FSR2
  389. /// of the jitter offset that has been applied in order to render each frame.
  390. ///
  391. /// If not using the recommended <c><i>ffxFsr2GetJitterOffset</i></c> function,
  392. /// care should be taken that your jitter sequence never generates a null vector;
  393. /// that is value of 0 in both the X and Y dimensions.
  394. ///
  395. /// @param [out] outX A pointer to a <c>float</c> which will contain the subpixel jitter offset for the x dimension.
  396. /// @param [out] outY A pointer to a <c>float</c> which will contain the subpixel jitter offset for the y dimension.
  397. /// @param [in] index The index within the jitter sequence.
  398. /// @param [in] phaseCount The length of jitter phase. See <c><i>ffxFsr2GetJitterPhaseCount</i></c>.
  399. ///
  400. /// @retval
  401. /// FFX_OK The operation completed successfully.
  402. /// @retval
  403. /// FFX_ERROR_INVALID_POINTER Either <c><i>outX</i></c> or <c><i>outY</i></c> was <c>NULL</c>.
  404. /// @retval
  405. /// FFX_ERROR_INVALID_ARGUMENT Argument <c><i>phaseCount</i></c> must be greater than 0.
  406. ///
  407. /// @ingroup FSR2
  408. FFX_API FfxErrorCode ffxFsr2GetJitterOffset(float* outX, float* outY, int32_t index, int32_t phaseCount);
  409. /// A helper function to check if a resource is
  410. /// <c><i>FFX_FSR2_RESOURCE_IDENTIFIER_NULL</i></c>.
  411. ///
  412. /// @param [in] resource A <c><i>FfxResource</i></c>.
  413. ///
  414. /// @returns
  415. /// true The <c><i>resource</i></c> was not <c><i>FFX_FSR2_RESOURCE_IDENTIFIER_NULL</i></c>.
  416. /// @returns
  417. /// false The <c><i>resource</i></c> was <c><i>FFX_FSR2_RESOURCE_IDENTIFIER_NULL</i></c>.
  418. ///
  419. /// @ingroup FSR2
  420. FFX_API bool ffxFsr2ResourceIsNull(FfxResource resource);
  421. #if defined(__cplusplus)
  422. }
  423. #endif // #if defined(__cplusplus)