Debian Codegraph @

thirdparty/amd-fsr2/ffx_types.h

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