Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/amd-fsr2/shaders/ffx_fsr2_callbacks_glsl.h
9900 views
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
#include "ffx_fsr2_resources.h"
22
23
#if defined(FFX_GPU)
24
#include "ffx_core.h"
25
#endif // #if defined(FFX_GPU)
26
27
#if defined(FFX_GPU)
28
#ifndef FFX_FSR2_PREFER_WAVE64
29
#define FFX_FSR2_PREFER_WAVE64
30
#endif // #if defined(FFX_GPU)
31
32
#if defined(FSR2_BIND_CB_FSR2)
33
layout (set = 1, binding = FSR2_BIND_CB_FSR2, std140) uniform cbFSR2_t
34
{
35
FfxInt32x2 iRenderSize;
36
FfxInt32x2 iMaxRenderSize;
37
FfxInt32x2 iDisplaySize;
38
FfxInt32x2 iInputColorResourceDimensions;
39
FfxInt32x2 iLumaMipDimensions;
40
FfxInt32 iLumaMipLevelToUse;
41
FfxInt32 iFrameIndex;
42
43
FfxFloat32x4 fDeviceToViewDepth;
44
FfxFloat32x2 fJitter;
45
FfxFloat32x2 fMotionVectorScale;
46
FfxFloat32x2 fDownscaleFactor;
47
FfxFloat32x2 fMotionVectorJitterCancellation;
48
FfxFloat32 fPreExposure;
49
FfxFloat32 fPreviousFramePreExposure;
50
FfxFloat32 fTanHalfFOV;
51
FfxFloat32 fJitterSequenceLength;
52
FfxFloat32 fDeltaTime;
53
FfxFloat32 fDynamicResChangeFactor;
54
FfxFloat32 fViewSpaceToMetersFactor;
55
56
FfxFloat32 fPad;
57
mat4 mReprojectionMatrix;
58
} cbFSR2;
59
#endif
60
61
FfxInt32x2 RenderSize()
62
{
63
return cbFSR2.iRenderSize;
64
}
65
66
FfxInt32x2 MaxRenderSize()
67
{
68
return cbFSR2.iMaxRenderSize;
69
}
70
71
FfxInt32x2 DisplaySize()
72
{
73
return cbFSR2.iDisplaySize;
74
}
75
76
FfxInt32x2 InputColorResourceDimensions()
77
{
78
return cbFSR2.iInputColorResourceDimensions;
79
}
80
81
FfxInt32x2 LumaMipDimensions()
82
{
83
return cbFSR2.iLumaMipDimensions;
84
}
85
86
FfxInt32 LumaMipLevelToUse()
87
{
88
return cbFSR2.iLumaMipLevelToUse;
89
}
90
91
FfxInt32 FrameIndex()
92
{
93
return cbFSR2.iFrameIndex;
94
}
95
96
FfxFloat32x4 DeviceToViewSpaceTransformFactors()
97
{
98
return cbFSR2.fDeviceToViewDepth;
99
}
100
101
FfxFloat32x2 Jitter()
102
{
103
return cbFSR2.fJitter;
104
}
105
106
FfxFloat32x2 MotionVectorScale()
107
{
108
return cbFSR2.fMotionVectorScale;
109
}
110
111
FfxFloat32x2 DownscaleFactor()
112
{
113
return cbFSR2.fDownscaleFactor;
114
}
115
116
FfxFloat32x2 MotionVectorJitterCancellation()
117
{
118
return cbFSR2.fMotionVectorJitterCancellation;
119
}
120
121
FfxFloat32 PreExposure()
122
{
123
return cbFSR2.fPreExposure;
124
}
125
126
FfxFloat32 PreviousFramePreExposure()
127
{
128
return cbFSR2.fPreviousFramePreExposure;
129
}
130
131
FfxFloat32 TanHalfFoV()
132
{
133
return cbFSR2.fTanHalfFOV;
134
}
135
136
FfxFloat32 JitterSequenceLength()
137
{
138
return cbFSR2.fJitterSequenceLength;
139
}
140
141
FfxFloat32 DeltaTime()
142
{
143
return cbFSR2.fDeltaTime;
144
}
145
146
FfxFloat32 DynamicResChangeFactor()
147
{
148
return cbFSR2.fDynamicResChangeFactor;
149
}
150
151
FfxFloat32 ViewSpaceToMetersFactor()
152
{
153
return cbFSR2.fViewSpaceToMetersFactor;
154
}
155
156
layout (set = 0, binding = 0) uniform sampler s_PointClamp;
157
layout (set = 0, binding = 1) uniform sampler s_LinearClamp;
158
159
// SRVs
160
#if defined(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY)
161
layout (set = 1, binding = FSR2_BIND_SRV_INPUT_OPAQUE_ONLY) uniform texture2D r_input_opaque_only;
162
#endif
163
#if defined(FSR2_BIND_SRV_INPUT_COLOR)
164
layout (set = 1, binding = FSR2_BIND_SRV_INPUT_COLOR) uniform texture2D r_input_color_jittered;
165
#endif
166
#if defined(FSR2_BIND_SRV_INPUT_MOTION_VECTORS)
167
layout (set = 1, binding = FSR2_BIND_SRV_INPUT_MOTION_VECTORS) uniform texture2D r_input_motion_vectors;
168
#endif
169
#if defined(FSR2_BIND_SRV_INPUT_DEPTH)
170
layout (set = 1, binding = FSR2_BIND_SRV_INPUT_DEPTH) uniform texture2D r_input_depth;
171
#endif
172
#if defined(FSR2_BIND_SRV_INPUT_EXPOSURE)
173
layout (set = 1, binding = FSR2_BIND_SRV_INPUT_EXPOSURE) uniform texture2D r_input_exposure;
174
#endif
175
#if defined(FSR2_BIND_SRV_AUTO_EXPOSURE)
176
layout(set = 1, binding = FSR2_BIND_SRV_AUTO_EXPOSURE) uniform texture2D r_auto_exposure;
177
#endif
178
#if defined(FSR2_BIND_SRV_REACTIVE_MASK)
179
layout (set = 1, binding = FSR2_BIND_SRV_REACTIVE_MASK) uniform texture2D r_reactive_mask;
180
#endif
181
#if defined(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK)
182
layout (set = 1, binding = FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK) uniform texture2D r_transparency_and_composition_mask;
183
#endif
184
#if defined(FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH)
185
layout (set = 1, binding = FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH) uniform utexture2D r_reconstructed_previous_nearest_depth;
186
#endif
187
#if defined(FSR2_BIND_SRV_DILATED_MOTION_VECTORS)
188
layout (set = 1, binding = FSR2_BIND_SRV_DILATED_MOTION_VECTORS) uniform texture2D r_dilated_motion_vectors;
189
#endif
190
#if defined (FSR2_BIND_SRV_PREVIOUS_DILATED_MOTION_VECTORS)
191
layout(set = 1, binding = FSR2_BIND_SRV_PREVIOUS_DILATED_MOTION_VECTORS) uniform texture2D r_previous_dilated_motion_vectors;
192
#endif
193
#if defined(FSR2_BIND_SRV_DILATED_DEPTH)
194
layout (set = 1, binding = FSR2_BIND_SRV_DILATED_DEPTH) uniform texture2D r_dilatedDepth;
195
#endif
196
#if defined(FSR2_BIND_SRV_INTERNAL_UPSCALED)
197
layout (set = 1, binding = FSR2_BIND_SRV_INTERNAL_UPSCALED) uniform texture2D r_internal_upscaled_color;
198
#endif
199
#if defined(FSR2_BIND_SRV_LOCK_STATUS)
200
layout (set = 1, binding = FSR2_BIND_SRV_LOCK_STATUS) uniform texture2D r_lock_status;
201
#endif
202
#if defined(FSR2_BIND_SRV_LOCK_INPUT_LUMA)
203
layout (set = 1, binding = FSR2_BIND_SRV_LOCK_INPUT_LUMA) uniform texture2D r_lock_input_luma;
204
#endif
205
#if defined(FSR2_BIND_SRV_NEW_LOCKS)
206
layout(set = 1, binding = FSR2_BIND_SRV_NEW_LOCKS) uniform texture2D r_new_locks;
207
#endif
208
#if defined(FSR2_BIND_SRV_PREPARED_INPUT_COLOR)
209
layout (set = 1, binding = FSR2_BIND_SRV_PREPARED_INPUT_COLOR) uniform texture2D r_prepared_input_color;
210
#endif
211
#if defined(FSR2_BIND_SRV_LUMA_HISTORY)
212
layout (set = 1, binding = FSR2_BIND_SRV_LUMA_HISTORY) uniform texture2D r_luma_history;
213
#endif
214
#if defined(FSR2_BIND_SRV_RCAS_INPUT)
215
layout (set = 1, binding = FSR2_BIND_SRV_RCAS_INPUT) uniform texture2D r_rcas_input;
216
#endif
217
#if defined(FSR2_BIND_SRV_LANCZOS_LUT)
218
layout (set = 1, binding = FSR2_BIND_SRV_LANCZOS_LUT) uniform texture2D r_lanczos_lut;
219
#endif
220
#if defined(FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS)
221
layout (set = 1, binding = FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS) uniform texture2D r_imgMips;
222
#endif
223
#if defined(FSR2_BIND_SRV_UPSCALE_MAXIMUM_BIAS_LUT)
224
layout (set = 1, binding = FSR2_BIND_SRV_UPSCALE_MAXIMUM_BIAS_LUT) uniform texture2D r_upsample_maximum_bias_lut;
225
#endif
226
#if defined(FSR2_BIND_SRV_DILATED_REACTIVE_MASKS)
227
layout (set = 1, binding = FSR2_BIND_SRV_DILATED_REACTIVE_MASKS) uniform texture2D r_dilated_reactive_masks;
228
#endif
229
#if defined(FSR2_BIND_SRV_PREV_PRE_ALPHA_COLOR)
230
layout(set = 1, binding = FSR2_BIND_SRV_PREV_PRE_ALPHA_COLOR) uniform texture2D r_input_prev_color_pre_alpha;
231
#endif
232
#if defined(FSR2_BIND_SRV_PREV_POST_ALPHA_COLOR)
233
layout(set = 1, binding = FSR2_BIND_SRV_PREV_POST_ALPHA_COLOR) uniform texture2D r_input_prev_color_post_alpha;
234
#endif
235
236
// UAV
237
#if defined FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH
238
layout (set = 1, binding = FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH, r32ui) uniform uimage2D rw_reconstructed_previous_nearest_depth;
239
#endif
240
#if defined FSR2_BIND_UAV_DILATED_MOTION_VECTORS
241
layout (set = 1, binding = FSR2_BIND_UAV_DILATED_MOTION_VECTORS, rg16f) writeonly uniform image2D rw_dilated_motion_vectors;
242
#endif
243
#if defined FSR2_BIND_UAV_DILATED_DEPTH
244
layout (set = 1, binding = FSR2_BIND_UAV_DILATED_DEPTH, r16f) writeonly uniform image2D rw_dilatedDepth;
245
#endif
246
#if defined FSR2_BIND_UAV_INTERNAL_UPSCALED
247
layout (set = 1, binding = FSR2_BIND_UAV_INTERNAL_UPSCALED, rgba16f) writeonly uniform image2D rw_internal_upscaled_color;
248
#endif
249
#if defined FSR2_BIND_UAV_LOCK_STATUS
250
layout (set = 1, binding = FSR2_BIND_UAV_LOCK_STATUS, rg16f) uniform image2D rw_lock_status;
251
#endif
252
#if defined(FSR2_BIND_UAV_LOCK_INPUT_LUMA)
253
layout(set = 1, binding = FSR2_BIND_UAV_LOCK_INPUT_LUMA, r16f) writeonly uniform image2D rw_lock_input_luma;
254
#endif
255
#if defined FSR2_BIND_UAV_NEW_LOCKS
256
layout(set = 1, binding = FSR2_BIND_UAV_NEW_LOCKS, r8) uniform image2D rw_new_locks;
257
#endif
258
#if defined FSR2_BIND_UAV_PREPARED_INPUT_COLOR
259
layout (set = 1, binding = FSR2_BIND_UAV_PREPARED_INPUT_COLOR, rgba16) writeonly uniform image2D rw_prepared_input_color;
260
#endif
261
#if defined FSR2_BIND_UAV_LUMA_HISTORY
262
layout (set = 1, binding = FSR2_BIND_UAV_LUMA_HISTORY, rgba8) uniform image2D rw_luma_history;
263
#endif
264
#if defined FSR2_BIND_UAV_UPSCALED_OUTPUT
265
layout (set = 1, binding = FSR2_BIND_UAV_UPSCALED_OUTPUT /* app controlled format */) writeonly uniform image2D rw_upscaled_output;
266
#endif
267
#if defined FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE
268
layout (set = 1, binding = FSR2_BIND_UAV_EXPOSURE_MIP_LUMA_CHANGE, r16f) coherent uniform image2D rw_img_mip_shading_change;
269
#endif
270
#if defined FSR2_BIND_UAV_EXPOSURE_MIP_5
271
layout (set = 1, binding = FSR2_BIND_UAV_EXPOSURE_MIP_5, r16f) coherent uniform image2D rw_img_mip_5;
272
#endif
273
#if defined FSR2_BIND_UAV_DILATED_REACTIVE_MASKS
274
layout (set = 1, binding = FSR2_BIND_UAV_DILATED_REACTIVE_MASKS, rg8) writeonly uniform image2D rw_dilated_reactive_masks;
275
#endif
276
#if defined FSR2_BIND_UAV_EXPOSURE
277
layout (set = 1, binding = FSR2_BIND_UAV_EXPOSURE, rg32f) uniform image2D rw_exposure;
278
#endif
279
#if defined FSR2_BIND_UAV_AUTO_EXPOSURE
280
layout(set = 1, binding = FSR2_BIND_UAV_AUTO_EXPOSURE, rg32f) uniform image2D rw_auto_exposure;
281
#endif
282
#if defined FSR2_BIND_UAV_SPD_GLOBAL_ATOMIC
283
layout (set = 1, binding = FSR2_BIND_UAV_SPD_GLOBAL_ATOMIC, r32ui) coherent uniform uimage2D rw_spd_global_atomic;
284
#endif
285
286
#if defined FSR2_BIND_UAV_AUTOREACTIVE
287
layout(set = 1, binding = FSR2_BIND_UAV_AUTOREACTIVE, r32f) uniform image2D rw_output_autoreactive;
288
#endif
289
#if defined FSR2_BIND_UAV_AUTOCOMPOSITION
290
layout(set = 1, binding = FSR2_BIND_UAV_AUTOCOMPOSITION, r32f) uniform image2D rw_output_autocomposition;
291
#endif
292
#if defined FSR2_BIND_UAV_PREV_PRE_ALPHA_COLOR
293
layout(set = 1, binding = FSR2_BIND_UAV_PREV_PRE_ALPHA_COLOR, r11f_g11f_b10f) uniform image2D rw_output_prev_color_pre_alpha;
294
#endif
295
#if defined FSR2_BIND_UAV_PREV_POST_ALPHA_COLOR
296
layout(set = 1, binding = FSR2_BIND_UAV_PREV_POST_ALPHA_COLOR, r11f_g11f_b10f) uniform image2D rw_output_prev_color_post_alpha;
297
#endif
298
299
#if defined(FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS)
300
FfxFloat32 LoadMipLuma(FfxInt32x2 iPxPos, FfxInt32 mipLevel)
301
{
302
return texelFetch(r_imgMips, iPxPos, FfxInt32(mipLevel)).r;
303
}
304
#endif
305
306
#if defined(FSR2_BIND_SRV_SCENE_LUMINANCE_MIPS)
307
FfxFloat32 SampleMipLuma(FfxFloat32x2 fUV, FfxInt32 mipLevel)
308
{
309
return textureLod(sampler2D(r_imgMips, s_LinearClamp), fUV, FfxFloat32(mipLevel)).r;
310
}
311
#endif
312
313
#if defined(FSR2_BIND_SRV_INPUT_DEPTH)
314
FfxFloat32 LoadInputDepth(FfxInt32x2 iPxPos)
315
{
316
return texelFetch(r_input_depth, iPxPos, 0).r;
317
}
318
#endif
319
320
#if defined(FSR2_BIND_SRV_REACTIVE_MASK)
321
FfxFloat32 LoadReactiveMask(FfxInt32x2 iPxPos)
322
{
323
#if FFX_FSR2_OPTION_GODOT_REACTIVE_MASK_CLAMP
324
return min(texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r, 0.9f);
325
#else
326
return texelFetch(r_reactive_mask, FfxInt32x2(iPxPos), 0).r;
327
#endif
328
}
329
#endif
330
331
#if defined(FSR2_BIND_SRV_TRANSPARENCY_AND_COMPOSITION_MASK)
332
FfxFloat32 LoadTransparencyAndCompositionMask(FfxUInt32x2 iPxPos)
333
{
334
return texelFetch(r_transparency_and_composition_mask, FfxInt32x2(iPxPos), 0).r;
335
}
336
#endif
337
338
#if defined(FSR2_BIND_SRV_INPUT_COLOR)
339
FfxFloat32x3 LoadInputColor(FfxInt32x2 iPxPos)
340
{
341
return texelFetch(r_input_color_jittered, iPxPos, 0).rgb;
342
}
343
#endif
344
345
#if defined(FSR2_BIND_SRV_INPUT_COLOR)
346
FfxFloat32x3 SampleInputColor(FfxFloat32x2 fUV)
347
{
348
return textureLod(sampler2D(r_input_color_jittered, s_LinearClamp), fUV, 0.0f).rgb;
349
}
350
#endif
351
352
#if defined(FSR2_BIND_SRV_PREPARED_INPUT_COLOR)
353
FfxFloat32x3 LoadPreparedInputColor(FfxInt32x2 iPxPos)
354
{
355
return texelFetch(r_prepared_input_color, iPxPos, 0).xyz;
356
}
357
#endif
358
359
#if defined(FSR2_BIND_SRV_INPUT_MOTION_VECTORS)
360
FfxFloat32x2 LoadInputMotionVector(FfxInt32x2 iPxDilatedMotionVectorPos)
361
{
362
FfxFloat32x2 fSrcMotionVector = texelFetch(r_input_motion_vectors, iPxDilatedMotionVectorPos, 0).xy;
363
364
#if FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS
365
bool bInvalidMotionVector = all(lessThanEqual(fSrcMotionVector, vec2(-1.0f, -1.0f)));
366
if (bInvalidMotionVector)
367
{
368
FfxFloat32 fSrcDepth = LoadInputDepth(iPxDilatedMotionVectorPos);
369
FfxFloat32x2 fUv = (iPxDilatedMotionVectorPos + FfxFloat32(0.5)) / RenderSize();
370
fSrcMotionVector = FFX_FSR2_OPTION_GODOT_DERIVE_INVALID_MOTION_VECTORS_FUNCTION(fUv, fSrcDepth, cbFSR2.mReprojectionMatrix);
371
}
372
#endif
373
374
FfxFloat32x2 fUvMotionVector = fSrcMotionVector * MotionVectorScale();
375
376
#if FFX_FSR2_OPTION_JITTERED_MOTION_VECTORS
377
fUvMotionVector -= MotionVectorJitterCancellation();
378
#endif
379
380
return fUvMotionVector;
381
}
382
#endif
383
384
#if defined(FSR2_BIND_SRV_INTERNAL_UPSCALED)
385
FfxFloat32x4 LoadHistory(FfxInt32x2 iPxHistory)
386
{
387
return texelFetch(r_internal_upscaled_color, iPxHistory, 0);
388
}
389
#endif
390
391
#if defined(FSR2_BIND_UAV_LUMA_HISTORY)
392
void StoreLumaHistory(FfxInt32x2 iPxPos, FfxFloat32x4 fLumaHistory)
393
{
394
imageStore(rw_luma_history, FfxInt32x2(iPxPos), fLumaHistory);
395
}
396
#endif
397
398
#if defined(FSR2_BIND_SRV_LUMA_HISTORY)
399
FfxFloat32x4 SampleLumaHistory(FfxFloat32x2 fUV)
400
{
401
return textureLod(sampler2D(r_luma_history, s_LinearClamp), fUV, 0.0f);
402
}
403
#endif
404
405
#if defined(FSR2_BIND_UAV_INTERNAL_UPSCALED)
406
void StoreReprojectedHistory(FfxInt32x2 iPxHistory, FfxFloat32x4 fHistory)
407
{
408
imageStore(rw_internal_upscaled_color, iPxHistory, fHistory);
409
}
410
#endif
411
412
#if defined(FSR2_BIND_UAV_INTERNAL_UPSCALED)
413
void StoreInternalColorAndWeight(FfxInt32x2 iPxPos, FfxFloat32x4 fColorAndWeight)
414
{
415
imageStore(rw_internal_upscaled_color, FfxInt32x2(iPxPos), fColorAndWeight);
416
}
417
#endif
418
419
#if defined(FSR2_BIND_UAV_UPSCALED_OUTPUT)
420
void StoreUpscaledOutput(FfxInt32x2 iPxPos, FfxFloat32x3 fColor)
421
{
422
imageStore(rw_upscaled_output, FfxInt32x2(iPxPos), FfxFloat32x4(fColor, 1.f));
423
}
424
#endif
425
426
#if defined(FSR2_BIND_SRV_LOCK_STATUS)
427
FfxFloat32x2 LoadLockStatus(FfxInt32x2 iPxPos)
428
{
429
FfxFloat32x2 fLockStatus = texelFetch(r_lock_status, iPxPos, 0).rg;
430
431
return fLockStatus;
432
}
433
#endif
434
435
#if defined(FSR2_BIND_UAV_LOCK_STATUS)
436
void StoreLockStatus(FfxInt32x2 iPxPos, FfxFloat32x2 fLockstatus)
437
{
438
imageStore(rw_lock_status, iPxPos, vec4(fLockstatus, 0.0f, 0.0f));
439
}
440
#endif
441
442
#if defined(FSR2_BIND_SRV_LOCK_INPUT_LUMA)
443
FfxFloat32 LoadLockInputLuma(FfxInt32x2 iPxPos)
444
{
445
return texelFetch(r_lock_input_luma, iPxPos, 0).r;
446
}
447
#endif
448
449
#if defined(FSR2_BIND_UAV_LOCK_INPUT_LUMA)
450
void StoreLockInputLuma(FfxInt32x2 iPxPos, FfxFloat32 fLuma)
451
{
452
imageStore(rw_lock_input_luma, iPxPos, vec4(fLuma, 0, 0, 0));
453
}
454
#endif
455
456
#if defined(FSR2_BIND_SRV_NEW_LOCKS)
457
FfxFloat32 LoadNewLocks(FfxInt32x2 iPxPos)
458
{
459
return texelFetch(r_new_locks, iPxPos, 0).r;
460
}
461
#endif
462
463
#if defined(FSR2_BIND_UAV_NEW_LOCKS)
464
FfxFloat32 LoadRwNewLocks(FfxInt32x2 iPxPos)
465
{
466
return imageLoad(rw_new_locks, iPxPos).r;
467
}
468
#endif
469
470
#if defined(FSR2_BIND_UAV_NEW_LOCKS)
471
void StoreNewLocks(FfxInt32x2 iPxPos, FfxFloat32 newLock)
472
{
473
imageStore(rw_new_locks, iPxPos, vec4(newLock, 0, 0, 0));
474
}
475
#endif
476
477
#if defined(FSR2_BIND_UAV_PREPARED_INPUT_COLOR)
478
void StorePreparedInputColor(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x4 fTonemapped)
479
{
480
imageStore(rw_prepared_input_color, iPxPos, fTonemapped);
481
}
482
#endif
483
484
#if defined(FSR2_BIND_SRV_PREPARED_INPUT_COLOR)
485
FfxFloat32 SampleDepthClip(FfxFloat32x2 fUV)
486
{
487
return textureLod(sampler2D(r_prepared_input_color, s_LinearClamp), fUV, 0.0f).w;
488
}
489
#endif
490
491
#if defined(FSR2_BIND_SRV_LOCK_STATUS)
492
FfxFloat32x2 SampleLockStatus(FfxFloat32x2 fUV)
493
{
494
FfxFloat32x2 fLockStatus = textureLod(sampler2D(r_lock_status, s_LinearClamp), fUV, 0.0f).rg;
495
return fLockStatus;
496
}
497
#endif
498
499
#if defined(FSR2_BIND_SRV_DEPTH)
500
FfxFloat32 LoadSceneDepth(FfxInt32x2 iPxInput)
501
{
502
return texelFetch(r_input_depth, iPxInput, 0).r;
503
}
504
#endif
505
506
#if defined(FSR2_BIND_SRV_RECONSTRUCTED_PREV_NEAREST_DEPTH)
507
FfxFloat32 LoadReconstructedPrevDepth(FfxInt32x2 iPxPos)
508
{
509
return uintBitsToFloat(texelFetch(r_reconstructed_previous_nearest_depth, iPxPos, 0).r);
510
}
511
#endif
512
513
#if defined(FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH)
514
void StoreReconstructedDepth(FfxInt32x2 iPxSample, FfxFloat32 fDepth)
515
{
516
FfxUInt32 uDepth = floatBitsToUint(fDepth);
517
518
#if FFX_FSR2_OPTION_INVERTED_DEPTH
519
imageAtomicMax(rw_reconstructed_previous_nearest_depth, iPxSample, uDepth);
520
#else
521
imageAtomicMin(rw_reconstructed_previous_nearest_depth, iPxSample, uDepth); // min for standard, max for inverted depth
522
#endif
523
}
524
#endif
525
526
#if defined(FSR2_BIND_UAV_RECONSTRUCTED_PREV_NEAREST_DEPTH)
527
void SetReconstructedDepth(FfxInt32x2 iPxSample, FfxUInt32 uValue)
528
{
529
imageStore(rw_reconstructed_previous_nearest_depth, iPxSample, uvec4(uValue, 0, 0, 0));
530
}
531
#endif
532
533
#if defined(FSR2_BIND_UAV_DILATED_DEPTH)
534
void StoreDilatedDepth(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32 fDepth)
535
{
536
//FfxUInt32 uDepth = f32tof16(fDepth);
537
imageStore(rw_dilatedDepth, iPxPos, vec4(fDepth, 0.0f, 0.0f, 0.0f));
538
}
539
#endif
540
541
#if defined(FSR2_BIND_UAV_DILATED_MOTION_VECTORS)
542
void StoreDilatedMotionVector(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 fMotionVector)
543
{
544
imageStore(rw_dilated_motion_vectors, iPxPos, vec4(fMotionVector, 0.0f, 0.0f));
545
}
546
#endif
547
548
#if defined(FSR2_BIND_SRV_DILATED_MOTION_VECTORS)
549
FfxFloat32x2 LoadDilatedMotionVector(FfxInt32x2 iPxInput)
550
{
551
return texelFetch(r_dilated_motion_vectors, iPxInput, 0).rg;
552
}
553
#endif
554
555
#if defined(FSR2_BIND_SRV_DILATED_MOTION_VECTORS)
556
FfxFloat32x2 SampleDilatedMotionVector(FfxFloat32x2 fUV)
557
{
558
return textureLod(sampler2D(r_dilated_motion_vectors, s_LinearClamp), fUV, 0.0f).rg;
559
}
560
#endif
561
562
#if defined(FSR2_BIND_SRV_PREVIOUS_DILATED_MOTION_VECTORS)
563
FfxFloat32x2 LoadPreviousDilatedMotionVector(FfxInt32x2 iPxInput)
564
{
565
return texelFetch(r_previous_dilated_motion_vectors, iPxInput, 0).rg;
566
}
567
568
FfxFloat32x2 SamplePreviousDilatedMotionVector(FfxFloat32x2 fUV)
569
{
570
return textureLod(sampler2D(r_previous_dilated_motion_vectors, s_LinearClamp), fUV, 0.0f).xy;
571
}
572
#endif
573
574
#if defined(FSR2_BIND_SRV_DILATED_DEPTH)
575
FfxFloat32 LoadDilatedDepth(FfxInt32x2 iPxInput)
576
{
577
return texelFetch(r_dilatedDepth, iPxInput, 0).r;
578
}
579
#endif
580
581
#if defined(FSR2_BIND_SRV_INPUT_EXPOSURE)
582
FfxFloat32 Exposure()
583
{
584
FfxFloat32 exposure = texelFetch(r_input_exposure, FfxInt32x2(0, 0), 0).x;
585
586
if (exposure == 0.0f) {
587
exposure = 1.0f;
588
}
589
590
return exposure;
591
}
592
#endif
593
594
#if defined(FSR2_BIND_SRV_AUTO_EXPOSURE)
595
FfxFloat32 AutoExposure()
596
{
597
FfxFloat32 exposure = texelFetch(r_auto_exposure, FfxInt32x2(0, 0), 0).x;
598
599
if (exposure == 0.0f) {
600
exposure = 1.0f;
601
}
602
603
return exposure;
604
}
605
#endif
606
607
FfxFloat32 SampleLanczos2Weight(FfxFloat32 x)
608
{
609
#if defined(FSR2_BIND_SRV_LANCZOS_LUT)
610
return textureLod(sampler2D(r_lanczos_lut, s_LinearClamp), FfxFloat32x2(x / 2.0f, 0.5f), 0.0f).x;
611
#else
612
return 0.f;
613
#endif
614
}
615
616
#if defined(FSR2_BIND_SRV_UPSCALE_MAXIMUM_BIAS_LUT)
617
FfxFloat32 SampleUpsampleMaximumBias(FfxFloat32x2 uv)
618
{
619
// Stored as a SNORM, so make sure to multiply by 2 to retrieve the actual expected range.
620
return FfxFloat32(2.0f) * FfxFloat32(textureLod(sampler2D(r_upsample_maximum_bias_lut, s_LinearClamp), abs(uv) * 2.0f, 0.0f).r);
621
}
622
#endif
623
624
#if defined(FSR2_BIND_SRV_DILATED_REACTIVE_MASKS)
625
FfxFloat32x2 SampleDilatedReactiveMasks(FfxFloat32x2 fUV)
626
{
627
return textureLod(sampler2D(r_dilated_reactive_masks, s_LinearClamp), fUV, 0.0f).rg;
628
}
629
#endif
630
631
#if defined(FSR2_BIND_SRV_DILATED_REACTIVE_MASKS)
632
FfxFloat32x2 LoadDilatedReactiveMasks(FFX_PARAMETER_IN FfxInt32x2 iPxPos)
633
{
634
return texelFetch(r_dilated_reactive_masks, iPxPos, 0).rg;
635
}
636
#endif
637
638
#if defined(FSR2_BIND_UAV_DILATED_REACTIVE_MASKS)
639
void StoreDilatedReactiveMasks(FFX_PARAMETER_IN FfxInt32x2 iPxPos, FFX_PARAMETER_IN FfxFloat32x2 fDilatedReactiveMasks)
640
{
641
imageStore(rw_dilated_reactive_masks, iPxPos, vec4(fDilatedReactiveMasks, 0.0f, 0.0f));
642
}
643
#endif
644
645
#if defined(FFX_INTERNAL)
646
FfxFloat32x4 SampleDebug(FfxFloat32x2 fUV)
647
{
648
return textureLod(sampler2D(r_debug_out, s_LinearClamp), fUV, 0.0f).rgba;
649
}
650
#endif
651
652
#if defined(FSR2_BIND_SRV_INPUT_OPAQUE_ONLY)
653
FfxFloat32x3 LoadOpaqueOnly(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
654
{
655
return texelFetch(r_input_opaque_only, iPxPos, 0).xyz;
656
}
657
#endif
658
659
#if defined(FSR2_BIND_SRV_PREV_PRE_ALPHA_COLOR)
660
FfxFloat32x3 LoadPrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
661
{
662
return texelFetch(r_input_prev_color_pre_alpha, iPxPos, 0).xyz;
663
}
664
#endif
665
666
#if defined(FSR2_BIND_SRV_PREV_POST_ALPHA_COLOR)
667
FfxFloat32x3 LoadPrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos)
668
{
669
return texelFetch(r_input_prev_color_post_alpha, iPxPos, 0).xyz;
670
}
671
#endif
672
673
#if defined(FSR2_BIND_UAV_AUTOREACTIVE)
674
#if defined(FSR2_BIND_UAV_AUTOCOMPOSITION)
675
void StoreAutoReactive(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F2 fReactive)
676
{
677
imageStore(rw_output_autoreactive, iPxPos, vec4(FfxFloat32(fReactive.x), 0.0f, 0.0f, 0.0f));
678
679
imageStore(rw_output_autocomposition, iPxPos, vec4(FfxFloat32(fReactive.y), 0.0f, 0.0f, 0.0f));
680
}
681
#endif
682
#endif
683
684
#if defined(FSR2_BIND_UAV_PREV_PRE_ALPHA_COLOR)
685
void StorePrevPreAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)
686
{
687
imageStore(rw_output_prev_color_pre_alpha, iPxPos, vec4(color, 0.0f));
688
}
689
#endif
690
691
#if defined(FSR2_BIND_UAV_PREV_POST_ALPHA_COLOR)
692
void StorePrevPostAlpha(FFX_PARAMETER_IN FFX_MIN16_I2 iPxPos, FFX_PARAMETER_IN FFX_MIN16_F3 color)
693
{
694
imageStore(rw_output_prev_color_post_alpha, iPxPos, vec4(color, 0.0f));
695
}
696
#endif
697
698
#endif // #if defined(FFX_GPU)
699
700