summaryrefslogtreecommitdiffstats
path: root/src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag
diff options
context:
space:
mode:
authorFernando Sahmkow <fsahmkow27@gmail.com>2021-11-21 20:52:39 +0100
committerFernando Sahmkow <fsahmkow27@gmail.com>2021-11-21 21:04:04 +0100
commitb96caf200d047b81554c3839c7a6a7c35b251944 (patch)
treeac8093a52aa4c9c29824db09ac938699e2891684 /src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag
parentTextureCache: Eliminate format deduction as full depth conversion has been supported. (diff)
downloadyuzu-b96caf200d047b81554c3839c7a6a7c35b251944.tar
yuzu-b96caf200d047b81554c3839c7a6a7c35b251944.tar.gz
yuzu-b96caf200d047b81554c3839c7a6a7c35b251944.tar.bz2
yuzu-b96caf200d047b81554c3839c7a6a7c35b251944.tar.lz
yuzu-b96caf200d047b81554c3839c7a6a7c35b251944.tar.xz
yuzu-b96caf200d047b81554c3839c7a6a7c35b251944.tar.zst
yuzu-b96caf200d047b81554c3839c7a6a7c35b251944.zip
Diffstat (limited to '')
-rw-r--r--src/video_core/host_shaders/convert_b10g11r11_to_d24s8.frag18
1 files changed, 13 insertions, 5 deletions
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 @@
layout(binding = 0) uniform sampler2D color_texture;
+uint conv_from_float(float value_f, uint mantissa_bits) {
+ uint value = floatBitsToInt(value_f);
+ uint exp = (value >> 23) & 0x1Fu;
+ uint mantissa_shift = 32u - mantissa_bits;
+ uint mantissa = (value << 9u) >> mantissa_shift;
+ return (exp << mantissa_bits) | mantissa;
+}
+
void main() {
ivec2 coord = ivec2(gl_FragCoord.xy);
vec4 color = texelFetch(color_texture, coord, 0).rgba;
- uint depth_stencil_unorm = (uint(color.b * (exp2(10) - 1.0f)) << 22)
- | (uint(color.g * (exp2(11) - 1.0f)) << 11)
- | (uint(color.r * (exp2(11) - 1.0f)));
+ uint depth_stencil_unorm = (conv_from_float(color.r, 6u) << 21)
+ | (conv_from_float(color.g, 6u) << 10)
+ | conv_from_float(color.b, 5u);
- gl_FragDepth = float(depth_stencil_unorm >> 8) / (exp2(24.0) - 1.0f);
- gl_FragStencilRefARB = int(depth_stencil_unorm & 0x00FF);
+ gl_FragDepth = float(depth_stencil_unorm & 0x00FFFFFFu) / (exp2(24.0) - 1.0f);
+ gl_FragStencilRefARB = int(depth_stencil_unorm >> 24);
}