ffx_types.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. #pragma once
  22. #include <stdint.h>
  23. #include <stdlib.h>
  24. #if defined (FFX_GCC)
  25. /// FidelityFX exported functions
  26. #define FFX_API
  27. #else
  28. /// FidelityFX exported functions
  29. #define FFX_API __declspec(dllexport)
  30. #endif // #if defined (FFX_GCC)
  31. /// Maximum supported number of simultaneously bound SRVs.
  32. #define FFX_MAX_NUM_SRVS 16
  33. /// Maximum supported number of simultaneously bound UAVs.
  34. #define FFX_MAX_NUM_UAVS 8
  35. /// Maximum number of constant buffers bound.
  36. #define FFX_MAX_NUM_CONST_BUFFERS 2
  37. /// Maximum size of bound constant buffers.
  38. #define FFX_MAX_CONST_SIZE 64
  39. /// Off by default warnings
  40. #if defined(_MSC_VER)
  41. #pragma warning(disable : 4365 4710 4820 5039)
  42. #elif defined(__clang__)
  43. #pragma clang diagnostic ignored "-Wunused-parameter"
  44. #pragma clang diagnostic ignored "-Wmissing-field-initializers"
  45. #pragma clang diagnostic ignored "-Wsign-compare"
  46. #pragma clang diagnostic ignored "-Wunused-function"
  47. #pragma clang diagnostic ignored "-Wignored-qualifiers"
  48. #elif defined(__GNUC__)
  49. #pragma GCC diagnostic ignored "-Wunused-function"
  50. #endif
  51. #ifdef __cplusplus
  52. extern "C" {
  53. #endif // #ifdef __cplusplus
  54. /// An enumeration of surface formats.
  55. typedef enum FfxSurfaceFormat {
  56. FFX_SURFACE_FORMAT_UNKNOWN, ///< Unknown format
  57. FFX_SURFACE_FORMAT_R32G32B32A32_TYPELESS, ///< 32 bit per channel, 4 channel typeless format
  58. FFX_SURFACE_FORMAT_R32G32B32A32_FLOAT, ///< 32 bit per channel, 4 channel float format
  59. FFX_SURFACE_FORMAT_R16G16B16A16_FLOAT, ///< 16 bit per channel, 4 channel float format
  60. FFX_SURFACE_FORMAT_R16G16B16A16_UNORM, ///< 16 bit per channel, 4 channel unsigned normalized format
  61. FFX_SURFACE_FORMAT_R32G32_FLOAT, ///< 32 bit per channel, 2 channel float format
  62. FFX_SURFACE_FORMAT_R32_UINT, ///< 32 bit per channel, 1 channel float format
  63. FFX_SURFACE_FORMAT_R8G8B8A8_TYPELESS, ///< 8 bit per channel, 4 channel float format
  64. FFX_SURFACE_FORMAT_R8G8B8A8_UNORM, ///< 8 bit per channel, 4 channel unsigned normalized format
  65. FFX_SURFACE_FORMAT_R11G11B10_FLOAT, ///< 32 bit 3 channel float format
  66. FFX_SURFACE_FORMAT_R16G16_FLOAT, ///< 16 bit per channel, 2 channel float format
  67. FFX_SURFACE_FORMAT_R16G16_UINT, ///< 16 bit per channel, 2 channel unsigned int format
  68. FFX_SURFACE_FORMAT_R16_FLOAT, ///< 16 bit per channel, 1 channel float format
  69. FFX_SURFACE_FORMAT_R16_UINT, ///< 16 bit per channel, 1 channel unsigned int format
  70. FFX_SURFACE_FORMAT_R16_UNORM, ///< 16 bit per channel, 1 channel unsigned normalized format
  71. FFX_SURFACE_FORMAT_R16_SNORM, ///< 16 bit per channel, 1 channel signed normalized format
  72. FFX_SURFACE_FORMAT_R8_UNORM, ///< 8 bit per channel, 1 channel unsigned normalized format
  73. FFX_SURFACE_FORMAT_R8_UINT, ///< 8 bit per channel, 1 channel unsigned int format
  74. FFX_SURFACE_FORMAT_R8G8_UNORM, ///< 8 bit per channel, 2 channel unsigned normalized format
  75. FFX_SURFACE_FORMAT_R32_FLOAT ///< 32 bit per channel, 1 channel float format
  76. } FfxSurfaceFormat;
  77. /// An enumeration of resource usage.
  78. typedef enum FfxResourceUsage {
  79. FFX_RESOURCE_USAGE_READ_ONLY = 0, ///< No usage flags indicate a resource is read only.
  80. FFX_RESOURCE_USAGE_RENDERTARGET = (1<<0), ///< Indicates a resource will be used as render target.
  81. FFX_RESOURCE_USAGE_UAV = (1<<1), ///< Indicates a resource will be used as UAV.
  82. } FfxResourceUsage;
  83. /// An enumeration of resource states.
  84. typedef enum FfxResourceStates {
  85. FFX_RESOURCE_STATE_UNORDERED_ACCESS = (1<<0), ///< Indicates a resource is in the state to be used as UAV.
  86. FFX_RESOURCE_STATE_COMPUTE_READ = (1 << 1), ///< Indicates a resource is in the state to be read by compute shaders.
  87. FFX_RESOURCE_STATE_COPY_SRC = (1 << 2), ///< Indicates a resource is in the state to be used as source in a copy command.
  88. FFX_RESOURCE_STATE_COPY_DEST = (1 << 3), ///< Indicates a resource is in the state to be used as destination in a copy command.
  89. FFX_RESOURCE_STATE_GENERIC_READ = (FFX_RESOURCE_STATE_COPY_SRC | FFX_RESOURCE_STATE_COMPUTE_READ), ///< Indicates a resource is in generic (slow) read state.
  90. } FfxResourceStates;
  91. /// An enumeration of surface dimensions.
  92. typedef enum FfxResourceDimension {
  93. FFX_RESOURCE_DIMENSION_TEXTURE_1D, ///< A resource with a single dimension.
  94. FFX_RESOURCE_DIMENSION_TEXTURE_2D, ///< A resource with two dimensions.
  95. } FfxResourceDimension;
  96. /// An enumeration of surface dimensions.
  97. typedef enum FfxResourceFlags {
  98. FFX_RESOURCE_FLAGS_NONE = 0, ///< No flags.
  99. FFX_RESOURCE_FLAGS_ALIASABLE = (1<<0), ///< A bit indicating a resource does not need to persist across frames.
  100. } FfxResourceFlags;
  101. /// An enumeration of all resource view types.
  102. typedef enum FfxResourceViewType {
  103. FFX_RESOURCE_VIEW_UNORDERED_ACCESS, ///< The resource view is an unordered access view (UAV).
  104. FFX_RESOURCE_VIEW_SHADER_READ, ///< The resource view is a shader resource view (SRV).
  105. } FfxResourceViewType;
  106. /// The type of filtering to perform when reading a texture.
  107. typedef enum FfxFilterType {
  108. FFX_FILTER_TYPE_POINT, ///< Point sampling.
  109. FFX_FILTER_TYPE_LINEAR ///< Sampling with interpolation.
  110. } FfxFilterType;
  111. /// An enumeration of all supported shader models.
  112. typedef enum FfxShaderModel {
  113. FFX_SHADER_MODEL_5_1, ///< Shader model 5.1.
  114. FFX_SHADER_MODEL_6_0, ///< Shader model 6.0.
  115. FFX_SHADER_MODEL_6_1, ///< Shader model 6.1.
  116. FFX_SHADER_MODEL_6_2, ///< Shader model 6.2.
  117. FFX_SHADER_MODEL_6_3, ///< Shader model 6.3.
  118. FFX_SHADER_MODEL_6_4, ///< Shader model 6.4.
  119. FFX_SHADER_MODEL_6_5, ///< Shader model 6.5.
  120. FFX_SHADER_MODEL_6_6, ///< Shader model 6.6.
  121. FFX_SHADER_MODEL_6_7, ///< Shader model 6.7.
  122. } FfxShaderModel;
  123. // An enumeration for different resource types
  124. typedef enum FfxResourceType {
  125. FFX_RESOURCE_TYPE_BUFFER, ///< The resource is a buffer.
  126. FFX_RESOURCE_TYPE_TEXTURE1D, ///< The resource is a 1-dimensional texture.
  127. FFX_RESOURCE_TYPE_TEXTURE2D, ///< The resource is a 2-dimensional texture.
  128. FFX_RESOURCE_TYPE_TEXTURE3D, ///< The resource is a 3-dimensional texture.
  129. } FfxResourceType;
  130. /// An enumeration for different heap types
  131. typedef enum FfxHeapType {
  132. FFX_HEAP_TYPE_DEFAULT = 0, ///< Local memory.
  133. FFX_HEAP_TYPE_UPLOAD ///< Heap used for uploading resources.
  134. } FfxHeapType;
  135. /// An enumberation for different render job types
  136. typedef enum FfxGpuJobType {
  137. FFX_GPU_JOB_CLEAR_FLOAT = 0, ///< The GPU job is performing a floating-point clear.
  138. FFX_GPU_JOB_COPY = 1, ///< The GPU job is performing a copy.
  139. FFX_GPU_JOB_COMPUTE = 2, ///< The GPU job is performing a compute dispatch.
  140. } FfxGpuJobType;
  141. /// A typedef representing the graphics device.
  142. typedef void* FfxDevice;
  143. /// A typedef representing a command list or command buffer.
  144. typedef void* FfxCommandList;
  145. /// A typedef for a root signature.
  146. typedef void* FfxRootSignature;
  147. /// A typedef for a pipeline state object.
  148. typedef void* FfxPipeline;
  149. /// A structure encapasulating a collection of device capabilities.
  150. typedef struct FfxDeviceCapabilities {
  151. FfxShaderModel minimumSupportedShaderModel; ///< The minimum shader model supported by the device.
  152. uint32_t waveLaneCountMin; ///< The minimum supported wavefront width.
  153. uint32_t waveLaneCountMax; ///< The maximum supported wavefront width.
  154. bool fp16Supported; ///< The device supports FP16 in hardware.
  155. bool raytracingSupported; ///< The device supports raytracing.
  156. } FfxDeviceCapabilities;
  157. /// A structure encapsulating a 2-dimensional point, using 32bit unsigned integers.
  158. typedef struct FfxDimensions2D {
  159. uint32_t width; ///< The width of a 2-dimensional range.
  160. uint32_t height; ///< The height of a 2-dimensional range.
  161. } FfxDimensions2D;
  162. /// A structure encapsulating a 2-dimensional point,
  163. typedef struct FfxIntCoords2D {
  164. int32_t x; ///< The x coordinate of a 2-dimensional point.
  165. int32_t y; ///< The y coordinate of a 2-dimensional point.
  166. } FfxIntCoords2D;
  167. /// A structure encapsulating a 2-dimensional set of floating point coordinates.
  168. typedef struct FfxFloatCoords2D {
  169. float x; ///< The x coordinate of a 2-dimensional point.
  170. float y; ///< The y coordinate of a 2-dimensional point.
  171. } FfxFloatCoords2D;
  172. /// A structure describing a resource.
  173. typedef struct FfxResourceDescription {
  174. FfxResourceType type; ///< The type of the resource.
  175. FfxSurfaceFormat format; ///< The surface format.
  176. uint32_t width; ///< The width of the resource.
  177. uint32_t height; ///< The height of the resource.
  178. uint32_t depth; ///< The depth of the resource.
  179. uint32_t mipCount; ///< Number of mips (or 0 for full mipchain).
  180. FfxResourceFlags flags; ///< A set of <c><i>FfxResourceFlags</i></c> flags.
  181. } FfxResourceDescription;
  182. /// An outward facing structure containing a resource
  183. typedef struct FfxResource {
  184. void* resource; ///< pointer to the resource.
  185. wchar_t name[64];
  186. FfxResourceDescription description;
  187. FfxResourceStates state;
  188. bool isDepth;
  189. uint64_t descriptorData;
  190. } FfxResource;
  191. /// An internal structure containing a handle to a resource and resource views
  192. typedef struct FfxResourceInternal {
  193. int32_t internalIndex; ///< The index of the resource.
  194. } FfxResourceInternal;
  195. /// A structure defining a resource bind point
  196. typedef struct FfxResourceBinding
  197. {
  198. uint32_t slotIndex;
  199. uint32_t resourceIdentifier;
  200. wchar_t name[64];
  201. }FfxResourceBinding;
  202. /// A structure encapsulating a single pass of an algorithm.
  203. typedef struct FfxPipelineState {
  204. FfxRootSignature rootSignature; ///< The pipelines rootSignature
  205. FfxPipeline pipeline; ///< The pipeline object
  206. uint32_t uavCount; ///< Count of UAVs used in this pipeline
  207. uint32_t srvCount; ///< Count of SRVs used in this pipeline
  208. uint32_t constCount; ///< Count of constant buffers used in this pipeline
  209. FfxResourceBinding uavResourceBindings[FFX_MAX_NUM_UAVS]; ///< Array of ResourceIdentifiers bound as UAVs
  210. FfxResourceBinding srvResourceBindings[FFX_MAX_NUM_SRVS]; ///< Array of ResourceIdentifiers bound as SRVs
  211. FfxResourceBinding cbResourceBindings[FFX_MAX_NUM_CONST_BUFFERS]; ///< Array of ResourceIdentifiers bound as CBs
  212. } FfxPipelineState;
  213. /// A structure containing the data required to create a resource.
  214. typedef struct FfxCreateResourceDescription {
  215. FfxHeapType heapType; ///< The heap type to hold the resource, typically <c><i>FFX_HEAP_TYPE_DEFAULT</i></c>.
  216. FfxResourceDescription resourceDescription; ///< A resource description.
  217. FfxResourceStates initalState; ///< The initial resource state.
  218. uint32_t initDataSize; ///< Size of initial data buffer.
  219. void* initData; ///< Buffer containing data to fill the resource.
  220. const wchar_t* name; ///< Name of the resource.
  221. FfxResourceUsage usage; ///< Resource usage flags.
  222. uint32_t id; ///< Internal resource ID.
  223. } FfxCreateResourceDescription;
  224. /// A structure containing the description used to create a
  225. /// <c><i>FfxPipeline</i></c> structure.
  226. ///
  227. /// A pipeline is the name given to a shader and the collection of state that
  228. /// is required to dispatch it. In the context of FSR2 and its architecture
  229. /// this means that a <c><i>FfxPipelineDescription</i></c> will map to either a
  230. /// monolithic object in an explicit API (such as a
  231. /// <c><i>PipelineStateObject</i></c> in DirectX 12). Or a shader and some
  232. /// ancillary API objects (in something like DirectX 11).
  233. ///
  234. /// The <c><i>contextFlags</i></c> field contains a copy of the flags passed
  235. /// to <c><i>ffxFsr2ContextCreate</i></c> via the <c><i>flags</i></c> field of
  236. /// the <c><i>FfxFsr2InitializationParams</i></c> structure. These flags are
  237. /// used to determine which permutation of a pipeline for a specific
  238. /// <c><i>FfxFsr2Pass</i></c> should be used to implement the features required
  239. /// by each application, as well as to acheive the best performance on specific
  240. /// target hardware configurations.
  241. ///
  242. /// When using one of the provided backends for FSR2 (such as DirectX 12 or
  243. /// Vulkan) the data required to create a pipeline is compiled offline and
  244. /// included into the backend library that you are using. For cases where the
  245. /// backend interface is overriden by providing custom callback function
  246. /// implementations care should be taken to respect the contents of the
  247. /// <c><i>contextFlags</i></c> field in order to correctly support the options
  248. /// provided by FSR2, and acheive best performance.
  249. ///
  250. /// @ingroup FSR2
  251. typedef struct FfxPipelineDescription {
  252. uint32_t contextFlags; ///< A collection of <c><i>FfxFsr2InitializationFlagBits</i></c> which were passed to the context.
  253. FfxFilterType* samplers; ///< Array of static samplers.
  254. size_t samplerCount; ///< The number of samples contained inside <c><i>samplers</i></c>.
  255. const uint32_t* rootConstantBufferSizes; ///< Array containing the sizes of the root constant buffers (count of 32 bit elements).
  256. uint32_t rootConstantBufferCount; ///< The number of root constants contained within <c><i>rootConstantBufferSizes</i></c>.
  257. } FfxPipelineDescription;
  258. /// A structure containing a constant buffer.
  259. typedef struct FfxConstantBuffer {
  260. uint32_t uint32Size; ///< Size of 32 bit chunks used in the constant buffer
  261. uint32_t data[FFX_MAX_CONST_SIZE]; ///< Constant buffer data
  262. }FfxConstantBuffer;
  263. /// A structure describing a clear render job.
  264. typedef struct FfxClearFloatJobDescription {
  265. float color[4]; ///< The clear color of the resource.
  266. FfxResourceInternal target; ///< The resource to be cleared.
  267. } FfxClearFloatJobDescription;
  268. /// A structure describing a compute render job.
  269. typedef struct FfxComputeJobDescription {
  270. FfxPipelineState pipeline; ///< Compute pipeline for the render job.
  271. uint32_t dimensions[3]; ///< Dispatch dimensions.
  272. FfxResourceInternal srvs[FFX_MAX_NUM_SRVS]; ///< SRV resources to be bound in the compute job.
  273. wchar_t srvNames[FFX_MAX_NUM_SRVS][64];
  274. FfxResourceInternal uavs[FFX_MAX_NUM_UAVS]; ///< UAV resources to be bound in the compute job.
  275. uint32_t uavMip[FFX_MAX_NUM_UAVS]; ///< Mip level of UAV resources to be bound in the compute job.
  276. wchar_t uavNames[FFX_MAX_NUM_UAVS][64];
  277. FfxConstantBuffer cbs[FFX_MAX_NUM_CONST_BUFFERS]; ///< Constant buffers to be bound in the compute job.
  278. wchar_t cbNames[FFX_MAX_NUM_CONST_BUFFERS][64];
  279. uint32_t cbSlotIndex[FFX_MAX_NUM_CONST_BUFFERS]; ///< Slot index in the descriptor table
  280. } FfxComputeJobDescription;
  281. /// A structure describing a copy render job.
  282. typedef struct FfxCopyJobDescription
  283. {
  284. FfxResourceInternal src; ///< Source resource for the copy.
  285. FfxResourceInternal dst; ///< Destination resource for the copy.
  286. } FfxCopyJobDescription;
  287. /// A structure describing a single render job.
  288. typedef struct FfxGpuJobDescription{
  289. FfxGpuJobType jobType; ///< Type of the job.
  290. union {
  291. FfxClearFloatJobDescription clearJobDescriptor; ///< Clear job descriptor. Valid when <c><i>jobType</i></c> is <c><i>FFX_RENDER_JOB_CLEAR_FLOAT</i></c>.
  292. FfxCopyJobDescription copyJobDescriptor; ///< Copy job descriptor. Valid when <c><i>jobType</i></c> is <c><i>FFX_RENDER_JOB_COPY</i></c>.
  293. FfxComputeJobDescription computeJobDescriptor; ///< Compute job descriptor. Valid when <c><i>jobType</i></c> is <c><i>FFX_RENDER_JOB_COMPUTE</i></c>.
  294. };
  295. } FfxGpuJobDescription;
  296. #ifdef __cplusplus
  297. }
  298. #endif // #ifdef __cplusplus