Debian Codegraph @

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

raw
1 #[vertex]
2
3 #version 450
4
5 #VERSION_DEFINES
6
7 #ifdef USE_MULTIVIEW
8 #extension GL_EXT_multiview : enable
9 #define ViewIndex gl_ViewIndex
10 #endif //USE_MULTIVIEW
11
12 #ifdef USE_MULTIVIEW
13 layout(location = 0) out vec3 uv_interp;
14 #else
15 layout(location = 0) out vec2 uv_interp;
16 #endif
17
18 layout(push_constant, std430) uniform Params {
19 float max_texel_factor;
20 float res1;
21 float res2;
22 float res3;
23 }
24 params;
25
26 void main() {
27 vec2 base_arr[3] = vec2[](vec2(-1.0, -1.0), vec2(-1.0, 3.0), vec2(3.0, -1.0));
28 gl_Position = vec4(base_arr[gl_VertexIndex], 0.0, 1.0);
29 uv_interp.xy = clamp(gl_Position.xy, vec2(0.0, 0.0), vec2(1.0, 1.0)) * 2.0; // saturate(x) * 2.0
30 #ifdef USE_MULTIVIEW
31 uv_interp.z = ViewIndex;
32 #endif
33 }
34
35 #[fragment]
36
37 #version 450
38
39 #VERSION_DEFINES
40
41 #ifdef USE_MULTIVIEW
42 layout(location = 0) in vec3 uv_interp;
43 layout(set = 0, binding = 0) uniform sampler2DArray source_color;
44 #else /* USE_MULTIVIEW */
45 layout(location = 0) in vec2 uv_interp;
46 layout(set = 0, binding = 0) uniform sampler2D source_color;
47 #endif /* USE_MULTIVIEW */
48
49 #ifdef SPLIT_RG
50 layout(location = 0) out vec2 frag_color;
51 #else
52 layout(location = 0) out uint frag_color;
53 #endif
54
55 layout(push_constant, std430) uniform Params {
56 float max_texel_factor;
57 float res1;
58 float res2;
59 float res3;
60 }
61 params;
62
63 void main() {
64 #ifdef USE_MULTIVIEW
65 vec3 uv = uv_interp;
66 #else
67 vec2 uv = uv_interp;
68 #endif
69
70 // Input is standardized. R for X, G for Y, 0.0 (0) = 1, 0.33 (85) = 2, 0.66 (170) = 3, 1.0 (255) = 8
71 vec4 color = textureLod(source_color, uv, 0.0);
72
73 #ifdef SPLIT_RG
74 // Density map for VRS according to VK_EXT_fragment_density_map, we can use as is.
75 frag_color = max(vec2(1.0f) - color.rg, vec2(1.0f / 255.0f));
76 #else
77 // Output image shading rate image for VRS according to VK_KHR_fragment_shading_rate.
78 color.r = clamp(floor(color.r * params.max_texel_factor + 0.1), 0.0, params.max_texel_factor);
79 color.g = clamp(floor(color.g * params.max_texel_factor + 0.1), 0.0, params.max_texel_factor);
80
81 // Note 1x4, 4x1, 1x8, 8x1, 2x8 and 8x2 are not supported:
82 if (color.r < (color.g - 1.0)) {
83 color.r = color.g - 1.0;
84 }
85 if (color.g < (color.r - 1.0)) {
86 color.g = color.r - 1.0;
87 }
88
89 // Encode to frag_color;
90 frag_color = int(color.r + 0.1) << 2;
91 frag_color += int(color.g + 0.1);
92 #endif
93 }