summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2021-11-21 20:52:39 +0100
committerGravatar Fernando Sahmkow2021-11-21 21:04:04 +0100
commitb96caf200d047b81554c3839c7a6a7c35b251944 (patch)
treeac8093a52aa4c9c29824db09ac938699e2891684
parentTextureCache: Eliminate format deduction as full depth conversion has been su... (diff)
downloadyuzu-b96caf200d047b81554c3839c7a6a7c35b251944.tar.gz
yuzu-b96caf200d047b81554c3839c7a6a7c35b251944.tar.xz
yuzu-b96caf200d047b81554c3839c7a6a7c35b251944.zip
HostShaders: Fix D24S8 convertion shaders.
-rw-r--r--src/video_core/host_shaders/convert_abgr8_to_d24s8.frag7
-rw-r--r--src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag18
-rw-r--r--src/video_core/host_shaders/convert_d24s8_to_abgr8.frag10
-rw-r--r--src/video_core/host_shaders/convert_d24s8_to_b10g11r11.frag19
-rw-r--r--src/video_core/host_shaders/convert_d24s8_to_r16g16.frag7
-rw-r--r--src/video_core/host_shaders/convert_r16g16_to_d24s8.frag9
6 files changed, 47 insertions, 23 deletions
diff --git a/src/video_core/host_shaders/convert_abgr8_to_d24s8.frag b/src/video_core/host_shaders/convert_abgr8_to_d24s8.frag
index 4e4ab6a26..d51397a0c 100644
--- a/src/video_core/host_shaders/convert_abgr8_to_d24s8.frag
+++ b/src/video_core/host_shaders/convert_abgr8_to_d24s8.frag
@@ -10,8 +10,9 @@ layout(binding = 0) uniform sampler2D color_texture;
10void main() { 10void main() {
11 ivec2 coord = ivec2(gl_FragCoord.xy); 11 ivec2 coord = ivec2(gl_FragCoord.xy);
12 uvec4 color = uvec4(texelFetch(color_texture, coord, 0).rgba * (exp2(8) - 1.0f)); 12 uvec4 color = uvec4(texelFetch(color_texture, coord, 0).rgba * (exp2(8) - 1.0f));
13 uint depth_unorm = (color.r << 16) | (color.g << 8) | color.b; 13 uvec4 bytes = color << uvec4(24, 16, 8, 0);
14 uint depth_stencil_unorm = bytes.x | bytes.y | bytes.z | bytes.w;
14 15
15 gl_FragDepth = float(depth_unorm) / (exp2(24.0) - 1.0f); 16 gl_FragDepth = float(depth_stencil_unorm & 0x00FFFFFFu) / (exp2(24.0) - 1.0f);
16 gl_FragStencilRefARB = int(color.a); 17 gl_FragStencilRefARB = int(depth_stencil_unorm >> 24);
17} 18}
diff --git a/src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag b/src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag
index 2999a84cf..11bdd861d 100644
--- a/src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag
+++ b/src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag
@@ -7,13 +7,21 @@
7 7
8layout(binding = 0) uniform sampler2D color_texture; 8layout(binding = 0) uniform sampler2D color_texture;
9 9
10uint conv_from_float(float value_f, uint mantissa_bits) {
11 uint value = floatBitsToInt(value_f);
12 uint exp = (value >> 23) & 0x1Fu;
13 uint mantissa_shift = 32u - mantissa_bits;
14 uint mantissa = (value << 9u) >> mantissa_shift;
15 return (exp << mantissa_bits) | mantissa;
16}
17
10void main() { 18void main() {
11 ivec2 coord = ivec2(gl_FragCoord.xy); 19 ivec2 coord = ivec2(gl_FragCoord.xy);
12 vec4 color = texelFetch(color_texture, coord, 0).rgba; 20 vec4 color = texelFetch(color_texture, coord, 0).rgba;
13 uint depth_stencil_unorm = (uint(color.b * (exp2(10) - 1.0f)) << 22) 21 uint depth_stencil_unorm = (conv_from_float(color.r, 6u) << 21)
14 | (uint(color.g * (exp2(11) - 1.0f)) << 11) 22 | (conv_from_float(color.g, 6u) << 10)
15 | (uint(color.r * (exp2(11) - 1.0f))); 23 | conv_from_float(color.b, 5u);
16 24
17 gl_FragDepth = float(depth_stencil_unorm >> 8) / (exp2(24.0) - 1.0f); 25 gl_FragDepth = float(depth_stencil_unorm & 0x00FFFFFFu) / (exp2(24.0) - 1.0f);
18 gl_FragStencilRefARB = int(depth_stencil_unorm & 0x00FF); 26 gl_FragStencilRefARB = int(depth_stencil_unorm >> 24);
19} 27}
diff --git a/src/video_core/host_shaders/convert_d24s8_to_abgr8.frag b/src/video_core/host_shaders/convert_d24s8_to_abgr8.frag
index ff3bf8209..47f9c1abc 100644
--- a/src/video_core/host_shaders/convert_d24s8_to_abgr8.frag
+++ b/src/video_core/host_shaders/convert_d24s8_to_abgr8.frag
@@ -14,8 +14,10 @@ void main() {
14 uint depth = uint(textureLod(depth_tex, coord, 0).r * (exp2(24.0) - 1.0f)); 14 uint depth = uint(textureLod(depth_tex, coord, 0).r * (exp2(24.0) - 1.0f));
15 uint stencil = uint(textureLod(stencil_tex, coord, 0).r); 15 uint stencil = uint(textureLod(stencil_tex, coord, 0).r);
16 16
17 color.r = float(depth >> 16) / (exp2(8) - 1.0); 17 highp uint depth_val =
18 color.g = float((depth >> 8) & 0x00FF) / (exp2(8) - 1.0); 18 uint(textureLod(depth_tex, coord, 0).r * (exp2(32.0) - 1.0));
19 color.b = float(depth & 0x00FF) / (exp2(8) - 1.0); 19 lowp uint stencil_val = textureLod(stencil_tex, coord, 0).r;
20 color.a = float(stencil) / (exp2(8) - 1.0); 20 highp uvec4 components =
21 uvec4(stencil_val, (uvec3(depth_val) >> uvec3(24u, 16u, 8u)) & 0x000000FFu);
22 color = vec4(components) / (exp2(8.0) - 1.0);
21} 23}
diff --git a/src/video_core/host_shaders/convert_d24s8_to_b10g11r11.frag b/src/video_core/host_shaders/convert_d24s8_to_b10g11r11.frag
index c743d3a13..c2d935fcd 100644
--- a/src/video_core/host_shaders/convert_d24s8_to_b10g11r11.frag
+++ b/src/video_core/host_shaders/convert_d24s8_to_b10g11r11.frag
@@ -9,13 +9,24 @@ layout(binding = 1) uniform isampler2D stencil_tex;
9 9
10layout(location = 0) out vec4 color; 10layout(location = 0) out vec4 color;
11 11
12float conv_to_float(uint value, uint mantissa_bits) {
13 uint exp = (value >> mantissa_bits) & 0x1Fu;
14 uint mantissa_shift = 32u - mantissa_bits;
15 uint mantissa = (value << mantissa_shift) >> mantissa_shift;
16 return uintBitsToFloat((exp << 23) | (mantissa << (23 - mantissa_bits)));
17}
18
12void main() { 19void main() {
13 ivec2 coord = ivec2(gl_FragCoord.xy); 20 ivec2 coord = ivec2(gl_FragCoord.xy);
14 uint depth = uint(textureLod(depth_tex, coord, 0).r * (exp2(24.0) - 1.0f)); 21 uint depth = uint(textureLod(depth_tex, coord, 0).r * (exp2(32.0) - 1.0f));
15 uint stencil = uint(textureLod(stencil_tex, coord, 0).r); 22 uint stencil = uint(textureLod(stencil_tex, coord, 0).r);
23 uint depth_stencil = (stencil << 24) | (depth >> 8);
24 uint red_int = (depth_stencil >> 21) & 0x07FF;
25 uint green_int = (depth_stencil >> 10) & 0x07FF;
26 uint blue_int = depth_stencil & 0x03FF;
16 27
17 color.b = float(depth >> 22) / (exp2(10) - 1.0); 28 color.r = conv_to_float(red_int, 6u);
18 color.g = float((depth >> 11) & 0x00FF) / (exp2(11) - 1.0); 29 color.g = conv_to_float(green_int, 6u);
19 color.r = float(depth & 0x00FF) / (exp2(11) - 1.0); 30 color.b = conv_to_float(blue_int, 5u);
20 color.a = 1.0f; 31 color.a = 1.0f;
21} 32}
diff --git a/src/video_core/host_shaders/convert_d24s8_to_r16g16.frag b/src/video_core/host_shaders/convert_d24s8_to_r16g16.frag
index 2a9443d3d..c48a7ac66 100644
--- a/src/video_core/host_shaders/convert_d24s8_to_r16g16.frag
+++ b/src/video_core/host_shaders/convert_d24s8_to_r16g16.frag
@@ -11,11 +11,12 @@ layout(location = 0) out vec4 color;
11 11
12void main() { 12void main() {
13 ivec2 coord = ivec2(gl_FragCoord.xy); 13 ivec2 coord = ivec2(gl_FragCoord.xy);
14 uint depth = uint(textureLod(depth_tex, coord, 0).r * (exp2(24.0) - 1.0f)); 14 uint depth = uint(textureLod(depth_tex, coord, 0).r * (exp2(32.0) - 1.0f));
15 uint stencil = uint(textureLod(stencil_tex, coord, 0).r); 15 uint stencil = uint(textureLod(stencil_tex, coord, 0).r);
16 uint depth_stencil = (stencil << 24) | (depth >> 8);
16 17
17 color.r = float(depth >> 16) / (exp2(16) - 1.0); 18 color.r = float(depth_stencil & 0x0000FFFFu) / (exp2(16) - 1.0);
18 color.g = float((depth >> 16) & 0x00FF) / (exp2(16) - 1.0); 19 color.g = float(depth_stencil >> 16) / (exp2(16) - 1.0);
19 color.b = 0.0f; 20 color.b = 0.0f;
20 color.a = 1.0f; 21 color.a = 1.0f;
21} 22}
diff --git a/src/video_core/host_shaders/convert_r16g16_to_d24s8.frag b/src/video_core/host_shaders/convert_r16g16_to_d24s8.frag
index 3df70575e..beb2d1284 100644
--- a/src/video_core/host_shaders/convert_r16g16_to_d24s8.frag
+++ b/src/video_core/host_shaders/convert_r16g16_to_d24s8.frag
@@ -10,9 +10,10 @@ layout(binding = 0) uniform sampler2D color_texture;
10void main() { 10void main() {
11 ivec2 coord = ivec2(gl_FragCoord.xy); 11 ivec2 coord = ivec2(gl_FragCoord.xy);
12 vec4 color = texelFetch(color_texture, coord, 0).rgba; 12 vec4 color = texelFetch(color_texture, coord, 0).rgba;
13 uint depth_stencil_unorm = (uint(color.r * (exp2(16) - 1.0f)) << 16) 13 uvec2 bytes = uvec2(color.rg * (exp2(16) - 1.0f)) << uvec2(0, 16);
14 | (uint(color.g * (exp2(16) - 1.0f)) << 16); 14 uint depth_stencil_unorm =
15 uint(color.r * (exp2(16) - 1.0f)) | (uint(color.g * (exp2(16) - 1.0f)) << 16);
15 16
16 gl_FragDepth = float(depth_stencil_unorm >> 8) / (exp2(24.0) - 1.0f); 17 gl_FragDepth = float(depth_stencil_unorm & 0x00FFFFFFu) / (exp2(24.0) - 1.0f);
17 gl_FragStencilRefARB = int(depth_stencil_unorm & 0x00FF); 18 gl_FragStencilRefARB = int(depth_stencil_unorm >> 24);
18} 19}