From 42c75dbb8f9472f434d0324a37a87e91ee7b50f3 Mon Sep 17 00:00:00 2001
From: gdkchan <gab.dark.100@gmail.com>
Date: Sat, 22 Jan 2022 15:23:00 -0300
Subject: Add support for BC1/2/3 decompression (for 3D textures) (#2987)

* Add support for BC1/2/3 decompression (for 3D textures)

* Optimize and clean up

* Unsafe not needed here

* Fix alpha value interpolation when a0 <= a1
---
 Ryujinx.Graphics.Gpu/Image/Texture.cs | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

(limited to 'Ryujinx.Graphics.Gpu/Image/Texture.cs')

diff --git a/Ryujinx.Graphics.Gpu/Image/Texture.cs b/Ryujinx.Graphics.Gpu/Image/Texture.cs
index b2fa15a2..e1f00606 100644
--- a/Ryujinx.Graphics.Gpu/Image/Texture.cs
+++ b/Ryujinx.Graphics.Gpu/Image/Texture.cs
@@ -834,13 +834,31 @@ namespace Ryujinx.Graphics.Gpu.Image
             {
                 data = PixelConverter.ConvertR4G4ToR4G4B4A4(data);
             }
-            else if (Target == Target.Texture3D && Format.IsBc4())
+            else if (!_context.Capabilities.Supports3DTextureCompression && Target == Target.Texture3D)
             {
-                data = BCnDecoder.DecodeBC4(data, width, height, depth, levels, layers, Info.FormatInfo.Format == Format.Bc4Snorm);
-            }
-            else if (Target == Target.Texture3D && Format.IsBc5())
-            {
-                data = BCnDecoder.DecodeBC5(data, width, height, depth, levels, layers, Info.FormatInfo.Format == Format.Bc5Snorm);
+                switch (Format)
+                {
+                    case Format.Bc1RgbaSrgb:
+                    case Format.Bc1RgbaUnorm:
+                        data = BCnDecoder.DecodeBC1(data, width, height, depth, levels, layers);
+                        break;
+                    case Format.Bc2Srgb:
+                    case Format.Bc2Unorm:
+                        data = BCnDecoder.DecodeBC2(data, width, height, depth, levels, layers);
+                        break;
+                    case Format.Bc3Srgb:
+                    case Format.Bc3Unorm:
+                        data = BCnDecoder.DecodeBC3(data, width, height, depth, levels, layers);
+                        break;
+                    case Format.Bc4Snorm:
+                    case Format.Bc4Unorm:
+                        data = BCnDecoder.DecodeBC4(data, width, height, depth, levels, layers, Format == Format.Bc4Snorm);
+                        break;
+                    case Format.Bc5Snorm:
+                    case Format.Bc5Unorm:
+                        data = BCnDecoder.DecodeBC5(data, width, height, depth, levels, layers, Format == Format.Bc5Snorm);
+                        break;
+                }
             }
 
             return data;
-- 
cgit v1.2.3-70-g09d2