Debian Codegraph @

servers/rendering/renderer_rd/shaders/effects/fsr_upscale.glsl

raw
1 /**************************************************************************/
2 /* fsr_upscale.glsl */
3 /**************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* https://godotengine.org */
7 /**************************************************************************/
8 /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9 /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10 /* */
11 /* Permission is hereby granted, free of charge, to any person obtaining */
12 /* a copy of this software and associated documentation files (the */
13 /* "Software"), to deal in the Software without restriction, including */
14 /* without limitation the rights to use, copy, modify, merge, publish, */
15 /* distribute, sublicense, and/or sell copies of the Software, and to */
16 /* permit persons to whom the Software is furnished to do so, subject to */
17 /* the following conditions: */
18 /* */
19 /* The above copyright notice and this permission notice shall be */
20 /* included in all copies or substantial portions of the Software. */
21 /* */
22 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29 /**************************************************************************/
30
31 #[compute]
32
33 #version 450
34
35 #VERSION_DEFINES
36
37 #define A_GPU
38 #define A_GLSL
39
40 #ifdef MODE_FSR_UPSCALE_NORMAL
41
42 #define A_HALF
43
44 #endif
45
46 #include "thirdparty/amd-fsr/ffx_a.h"
47
48 layout(local_size_x = 64, local_size_y = 1, local_size_z = 1) in;
49
50 layout(rgba16f, set = 1, binding = 0) uniform restrict writeonly image2D fsr_image;
51 layout(set = 0, binding = 0) uniform sampler2D source_image;
52
53 #define FSR_UPSCALE_PASS_TYPE_EASU 0
54 #define FSR_UPSCALE_PASS_TYPE_RCAS 1
55
56 layout(push_constant, std430) uniform Params {
57 float resolution_width;
58 float resolution_height;
59 float upscaled_width;
60 float upscaled_height;
61 float sharpness;
62 int pass;
63 }
64 params;
65
66 AU4 Const0, Const1, Const2, Const3;
67
68 #ifdef MODE_FSR_UPSCALE_FALLBACK
69
70 #define FSR_EASU_F
71 AF4 FsrEasuRF(AF2 p) {
72 AF4 res = textureGather(source_image, p, 0);
73 return res;
74 }
75 AF4 FsrEasuGF(AF2 p) {
76 AF4 res = textureGather(source_image, p, 1);
77 return res;
78 }
79 AF4 FsrEasuBF(AF2 p) {
80 AF4 res = textureGather(source_image, p, 2);
81 return res;
82 }
83
84 #define FSR_RCAS_F
85 AF4 FsrRcasLoadF(ASU2 p) {
86 return AF4(texelFetch(source_image, ASU2(p), 0));
87 }
88 void FsrRcasInputF(inout AF1 r, inout AF1 g, inout AF1 b) {}
89
90 #else
91
92 #define FSR_EASU_H
93 AH4 FsrEasuRH(AF2 p) {
94 AH4 res = AH4(textureGather(source_image, p, 0));
95 return res;
96 }
97 AH4 FsrEasuGH(AF2 p) {
98 AH4 res = AH4(textureGather(source_image, p, 1));
99 return res;
100 }
101 AH4 FsrEasuBH(AF2 p) {
102 AH4 res = AH4(textureGather(source_image, p, 2));
103 return res;
104 }
105
106 #define FSR_RCAS_H
107 AH4 FsrRcasLoadH(ASW2 p) {
108 return AH4(texelFetch(source_image, ASU2(p), 0));
109 }
110 void FsrRcasInputH(inout AH1 r, inout AH1 g, inout AH1 b) {}
111
112 #endif
113
114 #include "thirdparty/amd-fsr/ffx_fsr1.h"
115
116 void fsr_easu_pass(AU2 pos) {
117 #ifdef MODE_FSR_UPSCALE_NORMAL
118
119 AH3 Gamma2Color = AH3(0, 0, 0);
120 FsrEasuH(Gamma2Color, pos, Const0, Const1, Const2, Const3);
121 imageStore(fsr_image, ASU2(pos), AH4(Gamma2Color, 1));
122
123 #else
124
125 AF3 Gamma2Color = AF3(0, 0, 0);
126 FsrEasuF(Gamma2Color, pos, Const0, Const1, Const2, Const3);
127 imageStore(fsr_image, ASU2(pos), AF4(Gamma2Color, 1));
128
129 #endif
130 }
131
132 void fsr_rcas_pass(AU2 pos) {
133 #ifdef MODE_FSR_UPSCALE_NORMAL
134
135 AH3 Gamma2Color = AH3(0, 0, 0);
136 FsrRcasH(Gamma2Color.r, Gamma2Color.g, Gamma2Color.b, pos, Const0);
137 imageStore(fsr_image, ASU2(pos), AH4(Gamma2Color, 1));
138
139 #else
140
141 AF3 Gamma2Color = AF3(0, 0, 0);
142 FsrRcasF(Gamma2Color.r, Gamma2Color.g, Gamma2Color.b, pos, Const0);
143 imageStore(fsr_image, ASU2(pos), AF4(Gamma2Color, 1));
144
145 #endif
146 }
147
148 void fsr_pass(AU2 pos) {
149 if (params.pass == FSR_UPSCALE_PASS_TYPE_EASU) {
150 fsr_easu_pass(pos);
151 } else if (params.pass == FSR_UPSCALE_PASS_TYPE_RCAS) {
152 fsr_rcas_pass(pos);
153 }
154 }
155
156 void main() {
157 // Clang does not like unused functions. If ffx_a.h is included in the binary, clang will throw a fit and not compile so we must configure FSR in this shader
158 if (params.pass == FSR_UPSCALE_PASS_TYPE_EASU) {
159 FsrEasuCon(Const0, Const1, Const2, Const3, params.resolution_width, params.resolution_height, params.resolution_width, params.resolution_height, params.upscaled_width, params.upscaled_height);
160 } else if (params.pass == FSR_UPSCALE_PASS_TYPE_RCAS) {
161 FsrRcasCon(Const0, params.sharpness);
162 }
163
164 AU2 gxy = ARmp8x8(gl_LocalInvocationID.x) + AU2(gl_WorkGroupID.x << 4u, gl_WorkGroupID.y << 4u);
165
166 fsr_pass(gxy);
167 gxy.x += 8u;
168 fsr_pass(gxy);
169 gxy.y += 8u;
170 fsr_pass(gxy);
171 gxy.x -= 8u;
172 fsr_pass(gxy);
173 }