From 2492e7e808a3979ff54c5d28496d747e0a17fd5a Mon Sep 17 00:00:00 2001 From: gdkchan Date: Tue, 13 Sep 2022 02:59:38 -0300 Subject: [PATCH] Fix R4G4B4A4 format on Vulkan (#3696) --- Ryujinx.Graphics.Vulkan/FormatCapabilities.cs | 4 ++++ Ryujinx.Graphics.Vulkan/FormatTable.cs | 10 +++++----- Ryujinx.Graphics.Vulkan/TextureView.cs | 12 +----------- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs b/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs index 741d8956..0cac08bf 100644 --- a/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs +++ b/Ryujinx.Graphics.Vulkan/FormatCapabilities.cs @@ -108,6 +108,10 @@ namespace Ryujinx.Graphics.Vulkan { format = VkFormat.D32SfloatS8Uint; } + else if (srcFormat == GAL.Format.R4G4B4A4Unorm) + { + format = VkFormat.R4G4B4A4UnormPack16; + } else { Logger.Error?.Print(LogClass.Gpu, $"Format {srcFormat} is not supported by the host."); diff --git a/Ryujinx.Graphics.Vulkan/FormatTable.cs b/Ryujinx.Graphics.Vulkan/FormatTable.cs index b5739623..45fc46ad 100644 --- a/Ryujinx.Graphics.Vulkan/FormatTable.cs +++ b/Ryujinx.Graphics.Vulkan/FormatTable.cs @@ -6,11 +6,11 @@ namespace Ryujinx.Graphics.Vulkan { static class FormatTable { - private static readonly VkFormat[] Table; + private static readonly VkFormat[] _table; static FormatTable() { - Table = new VkFormat[Enum.GetNames(typeof(Format)).Length]; + _table = new VkFormat[Enum.GetNames(typeof(Format)).Length]; Add(Format.R8Unorm, VkFormat.R8Unorm); Add(Format.R8Snorm, VkFormat.R8SNorm); @@ -68,7 +68,7 @@ namespace Ryujinx.Graphics.Vulkan Add(Format.D32FloatS8Uint, VkFormat.D32SfloatS8Uint); Add(Format.R8G8B8A8Srgb, VkFormat.R8G8B8A8Srgb); Add(Format.R4G4Unorm, VkFormat.R4G4UnormPack8); - Add(Format.R4G4B4A4Unorm, VkFormat.R4G4B4A4UnormPack16); + Add(Format.R4G4B4A4Unorm, VkFormat.A4B4G4R4UnormPack16Ext); Add(Format.R5G5B5X1Unorm, VkFormat.A1R5G5B5UnormPack16); Add(Format.R5G5B5A1Unorm, VkFormat.A1R5G5B5UnormPack16); Add(Format.R5G6B5Unorm, VkFormat.R5G6B5UnormPack16); @@ -161,12 +161,12 @@ namespace Ryujinx.Graphics.Vulkan private static void Add(Format format, VkFormat vkFormat) { - Table[(int)format] = vkFormat; + _table[(int)format] = vkFormat; } public static VkFormat GetFormat(Format format) { - return Table[(int)format]; + return _table[(int)format]; } } } diff --git a/Ryujinx.Graphics.Vulkan/TextureView.cs b/Ryujinx.Graphics.Vulkan/TextureView.cs index 2eeafae9..fbe32eca 100644 --- a/Ryujinx.Graphics.Vulkan/TextureView.cs +++ b/Ryujinx.Graphics.Vulkan/TextureView.cs @@ -74,17 +74,7 @@ namespace Ryujinx.Graphics.Vulkan swizzleR = swizzleB; swizzleB = temp; } - else if (info.Format == GAL.Format.R4G4B4A4Unorm) - { - var tempG = swizzleG; - var tempB = swizzleB; - - swizzleB = swizzleA; - swizzleG = swizzleR; - swizzleR = tempG; - swizzleA = tempB; - } - else if (info.Format == GAL.Format.A1B5G5R5Unorm) + else if (VkFormat == VkFormat.R4G4B4A4UnormPack16 || info.Format == GAL.Format.A1B5G5R5Unorm) { var tempB = swizzleB; var tempA = swizzleA;