From e5ad1dfa48590685fd93443a2adfd8568f6c1db0 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Mon, 14 Mar 2022 23:42:08 -0300
Subject: Implement S8D24 texture format and tweak depth range detection
 (#2458)

---
 Ryujinx.Graphics.OpenGL/Image/TextureView.cs | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

(limited to 'Ryujinx.Graphics.OpenGL/Image/TextureView.cs')

diff --git a/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
index f03653c4..909a0620 100644
--- a/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
+++ b/Ryujinx.Graphics.OpenGL/Image/TextureView.cs
@@ -140,9 +140,11 @@ namespace Ryujinx.Graphics.OpenGL.Image
                 size += Info.GetMipSize(level);
             }
 
+            ReadOnlySpan<byte> data;
+
             if (HwCapabilities.UsePersistentBufferForFlush)
             {
-                return _renderer.PersistentBuffers.Default.GetTextureData(this, size);
+                data = _renderer.PersistentBuffers.Default.GetTextureData(this, size);
             }
             else
             {
@@ -150,8 +152,15 @@ namespace Ryujinx.Graphics.OpenGL.Image
 
                 WriteTo(target);
 
-                return new ReadOnlySpan<byte>(target.ToPointer(), size);
+                data = new ReadOnlySpan<byte>(target.ToPointer(), size);
+            }
+
+            if (Format == Format.S8UintD24Unorm)
+            {
+                data = FormatConverter.ConvertD24S8ToS8D24(data);
             }
+
+            return data;
         }
 
         public unsafe ReadOnlySpan<byte> GetData(int layer, int level)
@@ -285,6 +294,11 @@ namespace Ryujinx.Graphics.OpenGL.Image
 
         public void SetData(ReadOnlySpan<byte> data)
         {
+            if (Format == Format.S8UintD24Unorm)
+            {
+                data = FormatConverter.ConvertS8D24ToD24S8(data);
+            }
+
             unsafe
             {
                 fixed (byte* ptr = data)
@@ -296,6 +310,11 @@ namespace Ryujinx.Graphics.OpenGL.Image
 
         public void SetData(ReadOnlySpan<byte> data, int layer, int level)
         {
+            if (Format == Format.S8UintD24Unorm)
+            {
+                data = FormatConverter.ConvertS8D24ToD24S8(data);
+            }
+
             unsafe
             {
                 fixed (byte* ptr = data)
-- 
cgit v1.2.3-70-g09d2