Debian Codegraph @

thirdparty/amd-fsr2/shaders/ffx_fsr2_lock.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 #ifndef FFX_FSR2_LOCK_H
23 #define FFX_FSR2_LOCK_H
24
25 void ClearResourcesForNextFrame(in FfxInt32x2 iPxHrPos)
26 {
27 if (all(FFX_LESS_THAN(iPxHrPos, FfxInt32x2(RenderSize()))))
28 {
29 #if FFX_FSR2_OPTION_INVERTED_DEPTH
30 const FfxUInt32 farZ = 0x0;
31 #else
32 const FfxUInt32 farZ = 0x3f800000;
33 #endif
34 SetReconstructedDepth(iPxHrPos, farZ);
35 }
36 }
37
38 FfxBoolean ComputeThinFeatureConfidence(FfxInt32x2 pos)
39 {
40 const FfxInt32 RADIUS = 1;
41
42 FfxFloat32 fNucleus = LoadLockInputLuma(pos);
43
44 FfxFloat32 similar_threshold = 1.05f;
45 FfxFloat32 dissimilarLumaMin = FSR2_FLT_MAX;
46 FfxFloat32 dissimilarLumaMax = 0;
47
48 /*
49 0 1 2
50 3 4 5
51 6 7 8
52 */
53
54 #define SETBIT(x) (1U << x)
55
56 FfxUInt32 mask = SETBIT(4); //flag fNucleus as similar
57
58 const FfxUInt32 uNumRejectionMasks = 4;
59 const FfxUInt32 uRejectionMasks[uNumRejectionMasks] = {
60 SETBIT(0) | SETBIT(1) | SETBIT(3) | SETBIT(4), //Upper left
61 SETBIT(1) | SETBIT(2) | SETBIT(4) | SETBIT(5), //Upper right
62 SETBIT(3) | SETBIT(4) | SETBIT(6) | SETBIT(7), //Lower left
63 SETBIT(4) | SETBIT(5) | SETBIT(7) | SETBIT(8), //Lower right
64 };
65
66 FfxInt32 idx = 0;
67 FFX_UNROLL
68 for (FfxInt32 y = -RADIUS; y <= RADIUS; y++) {
69 FFX_UNROLL
70 for (FfxInt32 x = -RADIUS; x <= RADIUS; x++, idx++) {
71 if (x == 0 && y == 0) continue;
72
73 FfxInt32x2 samplePos = ClampLoad(pos, FfxInt32x2(x, y), FfxInt32x2(RenderSize()));
74
75 FfxFloat32 sampleLuma = LoadLockInputLuma(samplePos);
76 FfxFloat32 difference = ffxMax(sampleLuma, fNucleus) / ffxMin(sampleLuma, fNucleus);
77
78 if (difference > 0 && (difference < similar_threshold)) {
79 mask |= SETBIT(idx);
80 } else {
81 dissimilarLumaMin = ffxMin(dissimilarLumaMin, sampleLuma);
82 dissimilarLumaMax = ffxMax(dissimilarLumaMax, sampleLuma);
83 }
84 }
85 }
86
87 FfxBoolean isRidge = fNucleus > dissimilarLumaMax || fNucleus < dissimilarLumaMin;
88
89 if (FFX_FALSE == isRidge) {
90
91 return false;
92 }
93
94 FFX_UNROLL
95 for (FfxInt32 i = 0; i < 4; i++) {
96
97 if ((mask & uRejectionMasks[i]) == uRejectionMasks[i]) {
98 return false;
99 }
100 }
101
102 return true;
103 }
104
105 void ComputeLock(FfxInt32x2 iPxLrPos)
106 {
107 if (ComputeThinFeatureConfidence(iPxLrPos))
108 {
109 StoreNewLocks(ComputeHrPosFromLrPos(iPxLrPos), 1.f);
110 }
111
112 ClearResourcesForNextFrame(iPxLrPos);
113 }
114
115 #endif // FFX_FSR2_LOCK_H