From 6272bffb4d41f1bfb5a999f23f051d7b31f135e2 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Tue, 4 Sep 2018 21:25:09 -0300 Subject: [PATCH] Simplify image table --- Ryujinx.Graphics/Gal/GalImageFormat.cs | 273 ++++------- .../Gal/OpenGL/OGLEnumConverter.cs | 108 ++--- Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs | 2 +- Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs | 78 ++- Ryujinx.Graphics/Texture/ImageTable.cs | 443 ++++++++---------- Ryujinx.Graphics/Texture/TextureDescriptor.cs | 26 +- 6 files changed, 366 insertions(+), 564 deletions(-) diff --git a/Ryujinx.Graphics/Gal/GalImageFormat.cs b/Ryujinx.Graphics/Gal/GalImageFormat.cs index 4e84067bbb..9a29c26608 100644 --- a/Ryujinx.Graphics/Gal/GalImageFormat.cs +++ b/Ryujinx.Graphics/Gal/GalImageFormat.cs @@ -1,203 +1,96 @@ -namespace Ryujinx.Graphics.Gal +using System; + +namespace Ryujinx.Graphics.Gal { - //These are Vulkan-based enumerations, do not take them as Tegra values + [Flags] public enum GalImageFormat { - Undefined = 0, + Snorm = 1 << 27, + Unorm = 1 << 28, + Sint = 1 << 29, + Uint = 1 << 30, + Sfloat = 1 << 31, - R4G4_UNORM_PACK8 = 1, - R4G4B4A4_UNORM_PACK16 = 2, - B4G4R4A4_UNORM_PACK16 = 3, - R5G6B5_UNORM_PACK16 = 4, - B5G6R5_UNORM_PACK16 = 5, - R5G5B5A1_UNORM_PACK16 = 6, - B5G5R5A1_UNORM_PACK16 = 7, - A1R5G5B5_UNORM_PACK16 = 8, - R8_UNORM = 9, - R8_SNORM = 10, - R8_USCALED = 11, - R8_SSCALED = 12, - R8_UINT = 13, - R8_SINT = 14, - R8_SRGB = 15, - R8G8_UNORM = 16, - R8G8_SNORM = 17, - R8G8_USCALED = 18, - R8G8_SSCALED = 19, - R8G8_UINT = 20, - R8G8_SINT = 21, - R8G8_SRGB = 22, - R8G8B8_UNORM = 23, - R8G8B8_SNORM = 24, - R8G8B8_USCALED = 25, - R8G8B8_SSCALED = 26, - R8G8B8_UINT = 27, - R8G8B8_SINT = 28, - R8G8B8_SRGB = 29, - B8G8R8_UNORM = 30, - B8G8R8_SNORM = 31, - B8G8R8_USCALED = 32, - B8G8R8_SSCALED = 33, - B8G8R8_UINT = 34, - B8G8R8_SINT = 35, - B8G8R8_SRGB = 36, - R8G8B8A8_UNORM = 37, - R8G8B8A8_SNORM = 38, - R8G8B8A8_USCALED = 39, - R8G8B8A8_SSCALED = 40, - R8G8B8A8_UINT = 41, - R8G8B8A8_SINT = 42, - R8G8B8A8_SRGB = 43, - B8G8R8A8_UNORM = 44, - B8G8R8A8_SNORM = 45, - B8G8R8A8_USCALED = 46, - B8G8R8A8_SSCALED = 47, - B8G8R8A8_UINT = 48, - B8G8R8A8_SINT = 49, - B8G8R8A8_SRGB = 50, - A8B8G8R8_UNORM_PACK32 = 51, - A8B8G8R8_SNORM_PACK32 = 52, - A8B8G8R8_USCALED_PACK32 = 53, - A8B8G8R8_SSCALED_PACK32 = 54, - A8B8G8R8_UINT_PACK32 = 55, - A8B8G8R8_SINT_PACK32 = 56, - A8B8G8R8_SRGB_PACK32 = 57, - A2R10G10B10_UNORM_PACK32 = 58, - A2R10G10B10_SNORM_PACK32 = 59, - A2R10G10B10_USCALED_PACK32 = 60, - A2R10G10B10_SSCALED_PACK32 = 61, - A2R10G10B10_UINT_PACK32 = 62, - A2R10G10B10_SINT_PACK32 = 63, - A2B10G10R10_UNORM_PACK32 = 64, - A2B10G10R10_SNORM_PACK32 = 65, - A2B10G10R10_USCALED_PACK32 = 66, - A2B10G10R10_SSCALED_PACK32 = 67, - A2B10G10R10_UINT_PACK32 = 68, - A2B10G10R10_SINT_PACK32 = 69, - R16_UNORM = 70, - R16_SNORM = 71, - R16_USCALED = 72, - R16_SSCALED = 73, - R16_UINT = 74, - R16_SINT = 75, - R16_SFLOAT = 76, - R16G16_UNORM = 77, - R16G16_SNORM = 78, - R16G16_USCALED = 79, - R16G16_SSCALED = 80, - R16G16_UINT = 81, - R16G16_SINT = 82, - R16G16_SFLOAT = 83, - R16G16B16_UNORM = 84, - R16G16B16_SNORM = 85, - R16G16B16_USCALED = 86, - R16G16B16_SSCALED = 87, - R16G16B16_UINT = 88, - R16G16B16_SINT = 89, - R16G16B16_SFLOAT = 90, - R16G16B16A16_UNORM = 91, - R16G16B16A16_SNORM = 92, - R16G16B16A16_USCALED = 93, - R16G16B16A16_SSCALED = 94, - R16G16B16A16_UINT = 95, - R16G16B16A16_SINT = 96, - R16G16B16A16_SFLOAT = 97, - R32_UINT = 98, - R32_SINT = 99, - R32_SFLOAT = 100, - R32G32_UINT = 101, - R32G32_SINT = 102, - R32G32_SFLOAT = 103, - R32G32B32_UINT = 104, - R32G32B32_SINT = 105, - R32G32B32_SFLOAT = 106, - R32G32B32A32_UINT = 107, - R32G32B32A32_SINT = 108, - R32G32B32A32_SFLOAT = 109, - R64_UINT = 110, - R64_SINT = 111, - R64_SFLOAT = 112, - R64G64_UINT = 113, - R64G64_SINT = 114, - R64G64_SFLOAT = 115, - R64G64B64_UINT = 116, - R64G64B64_SINT = 117, - R64G64B64_SFLOAT = 118, - R64G64B64A64_UINT = 119, - R64G64B64A64_SINT = 120, - R64G64B64A64_SFLOAT = 121, - B10G11R11_UFLOAT_PACK32 = 122, - E5B9G9R9_UFLOAT_PACK32 = 123, - D16_UNORM = 124, - X8_D24_UNORM_PACK32 = 125, - D32_SFLOAT = 126, - S8_UINT = 127, - D16_UNORM_S8_UINT = 128, - D24_UNORM_S8_UINT = 129, - D32_SFLOAT_S8_UINT = 130, - BC1_RGB_UNORM_BLOCK = 131, - BC1_RGB_SRGB_BLOCK = 132, - BC1_RGBA_UNORM_BLOCK = 133, - BC1_RGBA_SRGB_BLOCK = 134, - BC2_UNORM_BLOCK = 135, - BC2_SRGB_BLOCK = 136, - BC3_UNORM_BLOCK = 137, - BC3_SRGB_BLOCK = 138, - BC4_UNORM_BLOCK = 139, - BC4_SNORM_BLOCK = 140, - BC5_UNORM_BLOCK = 141, - BC5_SNORM_BLOCK = 142, - BC6H_UFLOAT_BLOCK = 143, - BC6H_SFLOAT_BLOCK = 144, - BC7_UNORM_BLOCK = 145, - BC7_SRGB_BLOCK = 146, - ETC2_R8G8B8_UNORM_BLOCK = 147, - ETC2_R8G8B8_SRGB_BLOCK = 148, - ETC2_R8G8B8A1_UNORM_BLOCK = 149, - ETC2_R8G8B8A1_SRGB_BLOCK = 150, - ETC2_R8G8B8A8_UNORM_BLOCK = 151, - ETC2_R8G8B8A8_SRGB_BLOCK = 152, - EAC_R11_UNORM_BLOCK = 153, - EAC_R11_SNORM_BLOCK = 154, - EAC_R11G11_UNORM_BLOCK = 155, - EAC_R11G11_SNORM_BLOCK = 156, + TypeMask = Snorm | Unorm | Sint | Uint | Sfloat, - ASTC_BEGIN = ASTC_4x4_UNORM_BLOCK, + FormatMask = ~TypeMask, - ASTC_4x4_UNORM_BLOCK = 157, - ASTC_4x4_SRGB_BLOCK = 158, - ASTC_5x4_UNORM_BLOCK = 159, - ASTC_5x4_SRGB_BLOCK = 160, - ASTC_5x5_UNORM_BLOCK = 161, - ASTC_5x5_SRGB_BLOCK = 162, - ASTC_6x5_UNORM_BLOCK = 163, - ASTC_6x5_SRGB_BLOCK = 164, - ASTC_6x6_UNORM_BLOCK = 165, - ASTC_6x6_SRGB_BLOCK = 166, - ASTC_8x5_UNORM_BLOCK = 167, - ASTC_8x5_SRGB_BLOCK = 168, - ASTC_8x6_UNORM_BLOCK = 169, - ASTC_8x6_SRGB_BLOCK = 170, - ASTC_8x8_UNORM_BLOCK = 171, - ASTC_8x8_SRGB_BLOCK = 172, - ASTC_10x5_UNORM_BLOCK = 173, - ASTC_10x5_SRGB_BLOCK = 174, - ASTC_10x6_UNORM_BLOCK = 175, - ASTC_10x6_SRGB_BLOCK = 176, - ASTC_10x8_UNORM_BLOCK = 177, - ASTC_10x8_SRGB_BLOCK = 178, - ASTC_10x10_UNORM_BLOCK = 179, - ASTC_10x10_SRGB_BLOCK = 180, - ASTC_12x10_UNORM_BLOCK = 181, - ASTC_12x10_SRGB_BLOCK = 182, - ASTC_12x12_UNORM_BLOCK = 183, - ASTC_12x12_SRGB_BLOCK = 184, + ASTC_BEGIN = ASTC_4x4, - ASTC_END = ASTC_12x12_SRGB_BLOCK, + ASTC_4x4 = 0, + ASTC_5x4, + ASTC_5x5, + ASTC_6x5, + ASTC_6x6, + ASTC_8x5, + ASTC_8x6, + ASTC_8x8, + ASTC_10x5, + ASTC_10x6, + ASTC_10x8, + ASTC_10x10, + ASTC_12x10, + ASTC_12x12, + + ASTC_END = ASTC_12x12, + + R4G4, + R4G4B4A4, + B4G4R4A4, + R5G6B5, + B5G6R5, + R5G5B5A1, + B5G5R5A1, + A1R5G5B5, + R8, + R8G8, + R8G8B8, + B8G8R8, + R8G8B8A8, + B8G8R8A8, + A8B8G8R8, + A8B8G8R8_SRGB, + A2R10G10B10, + A2B10G10R10, + R16, + R16G16, + R16G16B16, + R16G16B16A16, + R32, + R32G32, + R32G32B32, + R32G32B32A32, + R64, + R64G64, + R64G64B64, + R64G64B64A64, + B10G11R11, + E5B9G9R9, + D16, + X8_D24, + D32, + S8, + D16_S8, + D24_S8, + D32_S8, + BC1_RGB, + BC1_RGBA, + BC2, + BC3, + BC4, + BC5, + BC6H_SF16, + BC6H_UF16, + BC7, + ETC2_R8G8B8, + ETC2_R8G8B8A1, + ETC2_R8G8B8A8, + EAC_R11, + EAC_R11G11, REVERSED_BEGIN, - R4G4B4A4_UNORM_PACK16_REVERSED = REVERSED_BEGIN, + R4G4B4A4_REVERSED = REVERSED_BEGIN, REVERSED_END } diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs index 959d0e3292..7f2c631fdf 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs @@ -129,52 +129,52 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.R32G32B32A32_SFLOAT: return (PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float); - case GalImageFormat.R32G32B32A32_SINT: return (PixelInternalFormat.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int); - case GalImageFormat.R32G32B32A32_UINT: return (PixelInternalFormat.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt); - case GalImageFormat.R16G16B16A16_SFLOAT: return (PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat); - case GalImageFormat.R16G16B16A16_SINT: return (PixelInternalFormat.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short); - case GalImageFormat.R16G16B16A16_UINT: return (PixelInternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort); - case GalImageFormat.R32G32_SFLOAT: return (PixelInternalFormat.Rg32f, PixelFormat.Rg, PixelType.Float); - case GalImageFormat.R32G32_SINT: return (PixelInternalFormat.Rg32i, PixelFormat.RgInteger, PixelType.Int); - case GalImageFormat.R32G32_UINT: return (PixelInternalFormat.Rg32ui, PixelFormat.RgInteger, PixelType.UnsignedInt); - case GalImageFormat.A8B8G8R8_SNORM_PACK32: return (PixelInternalFormat.Rgba8Snorm, PixelFormat.Rgba, PixelType.Byte); - case GalImageFormat.A8B8G8R8_UNORM_PACK32: return (PixelInternalFormat.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte); - case GalImageFormat.A8B8G8R8_SINT_PACK32: return (PixelInternalFormat.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte); - case GalImageFormat.A8B8G8R8_UINT_PACK32: return (PixelInternalFormat.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte); - case GalImageFormat.A8B8G8R8_SRGB_PACK32: return (PixelInternalFormat.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte); - case GalImageFormat.A2B10G10R10_UINT_PACK32: return (PixelInternalFormat.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed); - case GalImageFormat.A2B10G10R10_UNORM_PACK32: return (PixelInternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Reversed); - case GalImageFormat.R32_SFLOAT: return (PixelInternalFormat.R32f, PixelFormat.Red, PixelType.Float); - case GalImageFormat.R32_SINT: return (PixelInternalFormat.R32i, PixelFormat.Red, PixelType.Int); - case GalImageFormat.R32_UINT: return (PixelInternalFormat.R32ui, PixelFormat.Red, PixelType.UnsignedInt); - case GalImageFormat.A1R5G5B5_UNORM_PACK16: return (PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551); - case GalImageFormat.B5G6R5_UNORM_PACK16: return (PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565); - case GalImageFormat.R16G16_SFLOAT: return (PixelInternalFormat.Rg16f, PixelFormat.Rg, PixelType.HalfFloat); - case GalImageFormat.R16G16_SINT: return (PixelInternalFormat.Rg16i, PixelFormat.RgInteger, PixelType.Short); - case GalImageFormat.R16G16_SNORM: return (PixelInternalFormat.Rg16Snorm, PixelFormat.Rg, PixelType.Byte); - case GalImageFormat.R16G16_UNORM: return (PixelInternalFormat.Rg16, PixelFormat.Rg, PixelType.UnsignedShort); - case GalImageFormat.R8G8_SINT: return (PixelInternalFormat.Rg8i, PixelFormat.RgInteger, PixelType.Byte); - case GalImageFormat.R8G8_SNORM: return (PixelInternalFormat.Rg8Snorm, PixelFormat.Rg, PixelType.Byte); - case GalImageFormat.R8G8_UINT: return (PixelInternalFormat.Rg8ui, PixelFormat.RgInteger, PixelType.UnsignedByte); - case GalImageFormat.R8G8_UNORM: return (PixelInternalFormat.Rg8, PixelFormat.Rg, PixelType.UnsignedByte); - case GalImageFormat.R16_SFLOAT: return (PixelInternalFormat.R16f, PixelFormat.Red, PixelType.HalfFloat); - case GalImageFormat.R16_SINT: return (PixelInternalFormat.R16i, PixelFormat.RedInteger, PixelType.Short); - case GalImageFormat.R16_SNORM: return (PixelInternalFormat.R16Snorm, PixelFormat.Red, PixelType.Byte); - case GalImageFormat.R16_UINT: return (PixelInternalFormat.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort); - case GalImageFormat.R16_UNORM: return (PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedShort); - case GalImageFormat.R8_SINT: return (PixelInternalFormat.R8i, PixelFormat.RedInteger, PixelType.Byte); - case GalImageFormat.R8_SNORM: return (PixelInternalFormat.R8Snorm, PixelFormat.Red, PixelType.Byte); - case GalImageFormat.R8_UINT: return (PixelInternalFormat.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte); - case GalImageFormat.R8_UNORM: return (PixelInternalFormat.R8, PixelFormat.Red, PixelType.UnsignedByte); - case GalImageFormat.B10G11R11_UFLOAT_PACK32: return (PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10F11F11FRev); + case GalImageFormat.R32G32B32A32 | GalImageFormat.Sfloat: return (PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float); + case GalImageFormat.R32G32B32A32 | GalImageFormat.Sint: return (PixelInternalFormat.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int); + case GalImageFormat.R32G32B32A32 | GalImageFormat.Uint: return (PixelInternalFormat.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt); + case GalImageFormat.R16G16B16A16 | GalImageFormat.Sfloat: return (PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat); + case GalImageFormat.R16G16B16A16 | GalImageFormat.Sint: return (PixelInternalFormat.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short); + case GalImageFormat.R16G16B16A16 | GalImageFormat.Uint: return (PixelInternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort); + case GalImageFormat.R32G32 | GalImageFormat.Sfloat: return (PixelInternalFormat.Rg32f, PixelFormat.Rg, PixelType.Float); + case GalImageFormat.R32G32 | GalImageFormat.Sint: return (PixelInternalFormat.Rg32i, PixelFormat.RgInteger, PixelType.Int); + case GalImageFormat.R32G32 | GalImageFormat.Uint: return (PixelInternalFormat.Rg32ui, PixelFormat.RgInteger, PixelType.UnsignedInt); + case GalImageFormat.A8B8G8R8 | GalImageFormat.Snorm: return (PixelInternalFormat.Rgba8Snorm, PixelFormat.Rgba, PixelType.Byte); + case GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte); + case GalImageFormat.A8B8G8R8 | GalImageFormat.Sint: return (PixelInternalFormat.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte); + case GalImageFormat.A8B8G8R8 | GalImageFormat.Uint: return (PixelInternalFormat.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte); + case GalImageFormat.A8B8G8R8_SRGB: return (PixelInternalFormat.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte); + case GalImageFormat.A2B10G10R10 | GalImageFormat.Uint: return (PixelInternalFormat.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed); + case GalImageFormat.A2B10G10R10 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Reversed); + case GalImageFormat.R32 | GalImageFormat.Sfloat: return (PixelInternalFormat.R32f, PixelFormat.Red, PixelType.Float); + case GalImageFormat.R32 | GalImageFormat.Sint: return (PixelInternalFormat.R32i, PixelFormat.Red, PixelType.Int); + case GalImageFormat.R32 | GalImageFormat.Uint: return (PixelInternalFormat.R32ui, PixelFormat.Red, PixelType.UnsignedInt); + case GalImageFormat.A1R5G5B5 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551); + case GalImageFormat.B5G6R5 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565); + case GalImageFormat.R16G16 | GalImageFormat.Sfloat: return (PixelInternalFormat.Rg16f, PixelFormat.Rg, PixelType.HalfFloat); + case GalImageFormat.R16G16 | GalImageFormat.Sint: return (PixelInternalFormat.Rg16i, PixelFormat.RgInteger, PixelType.Short); + case GalImageFormat.R16G16 | GalImageFormat.Snorm: return (PixelInternalFormat.Rg16Snorm, PixelFormat.Rg, PixelType.Byte); + case GalImageFormat.R16G16 | GalImageFormat.Unorm: return (PixelInternalFormat.Rg16, PixelFormat.Rg, PixelType.UnsignedShort); + case GalImageFormat.R8G8 | GalImageFormat.Sint: return (PixelInternalFormat.Rg8i, PixelFormat.RgInteger, PixelType.Byte); + case GalImageFormat.R8G8 | GalImageFormat.Snorm: return (PixelInternalFormat.Rg8Snorm, PixelFormat.Rg, PixelType.Byte); + case GalImageFormat.R8G8 | GalImageFormat.Uint: return (PixelInternalFormat.Rg8ui, PixelFormat.RgInteger, PixelType.UnsignedByte); + case GalImageFormat.R8G8 | GalImageFormat.Unorm: return (PixelInternalFormat.Rg8, PixelFormat.Rg, PixelType.UnsignedByte); + case GalImageFormat.R16 | GalImageFormat.Sfloat: return (PixelInternalFormat.R16f, PixelFormat.Red, PixelType.HalfFloat); + case GalImageFormat.R16 | GalImageFormat.Sint: return (PixelInternalFormat.R16i, PixelFormat.RedInteger, PixelType.Short); + case GalImageFormat.R16 | GalImageFormat.Snorm: return (PixelInternalFormat.R16Snorm, PixelFormat.Red, PixelType.Byte); + case GalImageFormat.R16 | GalImageFormat.Uint: return (PixelInternalFormat.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort); + case GalImageFormat.R16 | GalImageFormat.Unorm: return (PixelInternalFormat.R16, PixelFormat.Red, PixelType.UnsignedShort); + case GalImageFormat.R8 | GalImageFormat.Sint: return (PixelInternalFormat.R8i, PixelFormat.RedInteger, PixelType.Byte); + case GalImageFormat.R8 | GalImageFormat.Snorm: return (PixelInternalFormat.R8Snorm, PixelFormat.Red, PixelType.Byte); + case GalImageFormat.R8 | GalImageFormat.Uint: return (PixelInternalFormat.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte); + case GalImageFormat.R8 | GalImageFormat.Unorm: return (PixelInternalFormat.R8, PixelFormat.Red, PixelType.UnsignedByte); + case GalImageFormat.B10G11R11 | GalImageFormat.Sfloat: return (PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10F11F11FRev); - case GalImageFormat.R4G4B4A4_UNORM_PACK16_REVERSED: return (PixelInternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed); + case GalImageFormat.R4G4B4A4_REVERSED | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed); - case GalImageFormat.D24_UNORM_S8_UINT: return (PixelInternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248); - case GalImageFormat.D32_SFLOAT: return (PixelInternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float); - case GalImageFormat.D16_UNORM: return (PixelInternalFormat.DepthComponent16, PixelFormat.DepthComponent, PixelType.UnsignedShort); - case GalImageFormat.D32_SFLOAT_S8_UINT: return (PixelInternalFormat.Depth32fStencil8, PixelFormat.DepthStencil, PixelType.Float32UnsignedInt248Rev); + case GalImageFormat.D24_S8 | GalImageFormat.Unorm: return (PixelInternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248); + case GalImageFormat.D32 | GalImageFormat.Sfloat: return (PixelInternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float); + case GalImageFormat.D16 | GalImageFormat.Unorm: return (PixelInternalFormat.DepthComponent16, PixelFormat.DepthComponent, PixelType.UnsignedShort); + case GalImageFormat.D32_S8 | GalImageFormat.Uint: return (PixelInternalFormat.Depth32fStencil8, PixelFormat.DepthStencil, PixelType.Float32UnsignedInt248Rev); } throw new NotImplementedException(Format.ToString()); @@ -184,16 +184,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.BC6H_UFLOAT_BLOCK: return InternalFormat.CompressedRgbBptcUnsignedFloat; - case GalImageFormat.BC6H_SFLOAT_BLOCK: return InternalFormat.CompressedRgbBptcSignedFloat; - case GalImageFormat.BC7_UNORM_BLOCK: return InternalFormat.CompressedRgbaBptcUnorm; - case GalImageFormat.BC1_RGBA_UNORM_BLOCK: return InternalFormat.CompressedRgbaS3tcDxt1Ext; - case GalImageFormat.BC2_UNORM_BLOCK: return InternalFormat.CompressedRgbaS3tcDxt3Ext; - case GalImageFormat.BC3_UNORM_BLOCK: return InternalFormat.CompressedRgbaS3tcDxt5Ext; - case GalImageFormat.BC4_SNORM_BLOCK: return InternalFormat.CompressedSignedRedRgtc1; - case GalImageFormat.BC4_UNORM_BLOCK: return InternalFormat.CompressedRedRgtc1; - case GalImageFormat.BC5_SNORM_BLOCK: return InternalFormat.CompressedSignedRgRgtc2; - case GalImageFormat.BC5_UNORM_BLOCK: return InternalFormat.CompressedRgRgtc2; + case GalImageFormat.BC6H_UF16 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbBptcUnsignedFloat; + case GalImageFormat.BC6H_SF16 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbBptcSignedFloat; + case GalImageFormat.BC7 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaBptcUnorm; + case GalImageFormat.BC1_RGBA | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt1Ext; + case GalImageFormat.BC2 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt3Ext; + case GalImageFormat.BC3 | GalImageFormat.Unorm: return InternalFormat.CompressedRgbaS3tcDxt5Ext; + case GalImageFormat.BC4 | GalImageFormat.Snorm: return InternalFormat.CompressedSignedRedRgtc1; + case GalImageFormat.BC4 | GalImageFormat.Unorm: return InternalFormat.CompressedRedRgtc1; + case GalImageFormat.BC5 | GalImageFormat.Snorm: return InternalFormat.CompressedSignedRgRgtc2; + case GalImageFormat.BC5 | GalImageFormat.Unorm: return InternalFormat.CompressedRgRgtc2; } throw new NotImplementedException(Format.ToString()); diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs index 12239c4f06..b04b24aa95 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs @@ -24,7 +24,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL private const int NativeWidth = 1280; private const int NativeHeight = 720; - private const GalImageFormat RawFormat = GalImageFormat.A8B8G8R8_UNORM_PACK32; + private const GalImageFormat RawFormat = GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm; private OGLTexture Texture; diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs index dc3599eb30..e4e52261c0 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs @@ -67,7 +67,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL Image.Width, Image.Height, 1); - Image.Format = GalImageFormat.A8B8G8R8_UNORM_PACK32; + Image.Format = GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm; } (PixelInternalFormat InternalFormat, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format); @@ -123,20 +123,20 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.ASTC_4x4_UNORM_BLOCK: return 4; - case GalImageFormat.ASTC_5x5_UNORM_BLOCK: return 5; - case GalImageFormat.ASTC_6x6_UNORM_BLOCK: return 6; - case GalImageFormat.ASTC_8x8_UNORM_BLOCK: return 8; - case GalImageFormat.ASTC_10x10_UNORM_BLOCK: return 10; - case GalImageFormat.ASTC_12x12_UNORM_BLOCK: return 12; - case GalImageFormat.ASTC_5x4_UNORM_BLOCK: return 5; - case GalImageFormat.ASTC_6x5_UNORM_BLOCK: return 6; - case GalImageFormat.ASTC_8x6_UNORM_BLOCK: return 8; - case GalImageFormat.ASTC_10x8_UNORM_BLOCK: return 10; - case GalImageFormat.ASTC_12x10_UNORM_BLOCK: return 12; - case GalImageFormat.ASTC_8x5_UNORM_BLOCK: return 8; - case GalImageFormat.ASTC_10x5_UNORM_BLOCK: return 10; - case GalImageFormat.ASTC_10x6_UNORM_BLOCK: return 10; + case GalImageFormat.ASTC_4x4 | GalImageFormat.Unorm: return 4; + case GalImageFormat.ASTC_5x5 | GalImageFormat.Unorm: return 5; + case GalImageFormat.ASTC_6x6 | GalImageFormat.Unorm: return 6; + case GalImageFormat.ASTC_8x8 | GalImageFormat.Unorm: return 8; + case GalImageFormat.ASTC_10x10 | GalImageFormat.Unorm: return 10; + case GalImageFormat.ASTC_12x12 | GalImageFormat.Unorm: return 12; + case GalImageFormat.ASTC_5x4 | GalImageFormat.Unorm: return 5; + case GalImageFormat.ASTC_6x5 | GalImageFormat.Unorm: return 6; + case GalImageFormat.ASTC_8x6 | GalImageFormat.Unorm: return 8; + case GalImageFormat.ASTC_10x8 | GalImageFormat.Unorm: return 10; + case GalImageFormat.ASTC_12x10 | GalImageFormat.Unorm: return 12; + case GalImageFormat.ASTC_8x5 | GalImageFormat.Unorm: return 8; + case GalImageFormat.ASTC_10x5 | GalImageFormat.Unorm: return 10; + case GalImageFormat.ASTC_10x6 | GalImageFormat.Unorm: return 10; } throw new ArgumentException(nameof(Format)); @@ -146,20 +146,20 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.ASTC_4x4_UNORM_BLOCK: return 4; - case GalImageFormat.ASTC_5x5_UNORM_BLOCK: return 5; - case GalImageFormat.ASTC_6x6_UNORM_BLOCK: return 6; - case GalImageFormat.ASTC_8x8_UNORM_BLOCK: return 8; - case GalImageFormat.ASTC_10x10_UNORM_BLOCK: return 10; - case GalImageFormat.ASTC_12x12_UNORM_BLOCK: return 12; - case GalImageFormat.ASTC_5x4_UNORM_BLOCK: return 4; - case GalImageFormat.ASTC_6x5_UNORM_BLOCK: return 5; - case GalImageFormat.ASTC_8x6_UNORM_BLOCK: return 6; - case GalImageFormat.ASTC_10x8_UNORM_BLOCK: return 8; - case GalImageFormat.ASTC_12x10_UNORM_BLOCK: return 10; - case GalImageFormat.ASTC_8x5_UNORM_BLOCK: return 5; - case GalImageFormat.ASTC_10x5_UNORM_BLOCK: return 5; - case GalImageFormat.ASTC_10x6_UNORM_BLOCK: return 6; + case GalImageFormat.ASTC_4x4 | GalImageFormat.Unorm: return 4; + case GalImageFormat.ASTC_5x5 | GalImageFormat.Unorm: return 5; + case GalImageFormat.ASTC_6x6 | GalImageFormat.Unorm: return 6; + case GalImageFormat.ASTC_8x8 | GalImageFormat.Unorm: return 8; + case GalImageFormat.ASTC_10x10 | GalImageFormat.Unorm: return 10; + case GalImageFormat.ASTC_12x12 | GalImageFormat.Unorm: return 12; + case GalImageFormat.ASTC_5x4 | GalImageFormat.Unorm: return 4; + case GalImageFormat.ASTC_6x5 | GalImageFormat.Unorm: return 5; + case GalImageFormat.ASTC_8x6 | GalImageFormat.Unorm: return 6; + case GalImageFormat.ASTC_10x8 | GalImageFormat.Unorm: return 8; + case GalImageFormat.ASTC_12x10 | GalImageFormat.Unorm: return 10; + case GalImageFormat.ASTC_8x5 | GalImageFormat.Unorm: return 5; + case GalImageFormat.ASTC_10x5 | GalImageFormat.Unorm: return 5; + case GalImageFormat.ASTC_10x6 | GalImageFormat.Unorm: return 6; } throw new ArgumentException(nameof(Format)); @@ -219,18 +219,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL private static bool IsCompressedTextureFormat(GalImageFormat Format) { - switch (Format) + switch (Format & GalImageFormat.FormatMask) { - case GalImageFormat.BC6H_UFLOAT_BLOCK: - case GalImageFormat.BC6H_SFLOAT_BLOCK: - case GalImageFormat.BC7_UNORM_BLOCK: - case GalImageFormat.BC1_RGBA_UNORM_BLOCK: - case GalImageFormat.BC2_UNORM_BLOCK: - case GalImageFormat.BC3_UNORM_BLOCK: - case GalImageFormat.BC4_SNORM_BLOCK: - case GalImageFormat.BC4_UNORM_BLOCK: - case GalImageFormat.BC5_SNORM_BLOCK: - case GalImageFormat.BC5_UNORM_BLOCK: + case GalImageFormat.BC6H_UF16: + case GalImageFormat.BC6H_SF16: + case GalImageFormat.BC7: + case GalImageFormat.BC1_RGBA: + case GalImageFormat.BC2: + case GalImageFormat.BC3: + case GalImageFormat.BC4: + case GalImageFormat.BC5: return true; } diff --git a/Ryujinx.Graphics/Texture/ImageTable.cs b/Ryujinx.Graphics/Texture/ImageTable.cs index 4b898dec38..bdc4467b5d 100644 --- a/Ryujinx.Graphics/Texture/ImageTable.cs +++ b/Ryujinx.Graphics/Texture/ImageTable.cs @@ -23,129 +23,103 @@ namespace Ryujinx.Graphics.Texture } } + private const GalImageFormat Snorm = GalImageFormat.Snorm; + private const GalImageFormat Unorm = GalImageFormat.Unorm; + private const GalImageFormat Sint = GalImageFormat.Sint; + private const GalImageFormat Uint = GalImageFormat.Uint; + private const GalImageFormat Sfloat = GalImageFormat.Sfloat; + private static readonly Dictionary s_TextureTable = new Dictionary() { - { GalTextureFormat.R16G16B16A16, new TextureDescriptor(TextureReader.Read8Bpp, GalImageFormat.R16G16B16A16_SNORM, GalImageFormat.R16G16B16A16_UNORM, GalImageFormat.R16G16B16A16_SINT, GalImageFormat.R16G16B16A16_UINT, GalImageFormat.R16G16B16A16_SFLOAT, null, null) }, - { GalTextureFormat.A8B8G8R8, new TextureDescriptor(TextureReader.Read4Bpp, GalImageFormat.A8B8G8R8_SNORM_PACK32, GalImageFormat.A8B8G8R8_UNORM_PACK32, GalImageFormat.A8B8G8R8_SINT_PACK32, GalImageFormat.A8B8G8R8_UINT_PACK32, null, null, null) }, - { GalTextureFormat.A2B10G10R10, new TextureDescriptor(TextureReader.Read4Bpp, GalImageFormat.A2B10G10R10_SNORM_PACK32, GalImageFormat.A2B10G10R10_UNORM_PACK32, GalImageFormat.A2B10G10R10_SINT_PACK32, GalImageFormat.A2B10G10R10_UINT_PACK32, null, null, null) }, - { GalTextureFormat.G8R8, new TextureDescriptor(TextureReader.Read2Bpp, GalImageFormat.R8G8_SNORM, GalImageFormat.R8G8_UNORM, GalImageFormat.R8G8_SINT, GalImageFormat.R8G8_UINT, null, null, null) }, - { GalTextureFormat.R16, new TextureDescriptor(TextureReader.Read2Bpp, GalImageFormat.R16_SNORM, GalImageFormat.R16_UNORM, GalImageFormat.R16_SINT, GalImageFormat.R16_UINT, GalImageFormat.R16_SFLOAT, null, null) }, - { GalTextureFormat.R8, new TextureDescriptor(TextureReader.Read1Bpp, GalImageFormat.R8_SNORM, GalImageFormat.R8_UNORM, GalImageFormat.R8_SINT, GalImageFormat.R8_UINT, null, null, null) }, - { GalTextureFormat.R32G32B32A32, new TextureDescriptor(TextureReader.Read16Bpp, null, null, GalImageFormat.R32G32B32A32_SINT, GalImageFormat.R32G32B32A32_UINT, GalImageFormat.R32G32B32A32_SFLOAT, null, null) }, - { GalTextureFormat.R32G32, new TextureDescriptor(TextureReader.Read8Bpp, null, null, GalImageFormat.R32G32_SINT, GalImageFormat.R32G32_UINT, GalImageFormat.R32G32_SFLOAT, null, null) }, - { GalTextureFormat.R32, new TextureDescriptor(TextureReader.Read4Bpp, null, null, GalImageFormat.R32_SINT, GalImageFormat.R32_UINT, GalImageFormat.R32_SFLOAT, null, null) }, - - { GalTextureFormat.A4B4G4R4, new TextureDescriptor(TextureReader.Read2Bpp, Unorm: GalImageFormat.R4G4B4A4_UNORM_PACK16_REVERSED) }, //TODO: Reverse this one in the reader - { GalTextureFormat.A1B5G5R5, new TextureDescriptor(TextureReader.Read5551, Unorm: GalImageFormat.A1R5G5B5_UNORM_PACK16) }, - { GalTextureFormat.B5G6R5, new TextureDescriptor(TextureReader.Read565, Unorm: GalImageFormat.B5G6R5_UNORM_PACK16) }, - { GalTextureFormat.BF10GF11RF11, new TextureDescriptor(TextureReader.Read4Bpp, Float: GalImageFormat.B10G11R11_UFLOAT_PACK32) }, - - //Zeta formats - { GalTextureFormat.ZF32, new TextureDescriptor(TextureReader.Read4Bpp, Float: GalImageFormat.D32_SFLOAT) }, - { GalTextureFormat.Z24S8, new TextureDescriptor(TextureReader.Read4Bpp, Unorm: GalImageFormat.D24_UNORM_S8_UINT) }, - { GalTextureFormat.ZF32_X24S8, new TextureDescriptor(TextureReader.Read8Bpp, Unorm: GalImageFormat.D32_SFLOAT_S8_UINT) }, + { GalTextureFormat.R32G32B32A32, new TextureDescriptor(TextureReader.Read16Bpp, GalImageFormat.R32G32B32A32 | Sint | Uint | Sfloat) }, + { GalTextureFormat.R16G16B16A16, new TextureDescriptor(TextureReader.Read8Bpp, GalImageFormat.R16G16B16A16 | Snorm | Unorm | Sint | Uint | Sfloat) }, + { GalTextureFormat.R32G32, new TextureDescriptor(TextureReader.Read8Bpp, GalImageFormat.R32G32 | Sint | Uint | Sfloat) }, + { GalTextureFormat.A8B8G8R8, new TextureDescriptor(TextureReader.Read4Bpp, GalImageFormat.A8B8G8R8 | Snorm | Unorm | Sint | Uint ) }, + { GalTextureFormat.A2B10G10R10, new TextureDescriptor(TextureReader.Read4Bpp, GalImageFormat.A2B10G10R10 | Snorm | Unorm | Sint | Uint ) }, + { GalTextureFormat.G8R8, new TextureDescriptor(TextureReader.Read2Bpp, GalImageFormat.R8G8 | Snorm | Unorm | Sint | Uint ) }, + { GalTextureFormat.R16, new TextureDescriptor(TextureReader.Read2Bpp, GalImageFormat.R16 | Snorm | Unorm | Sint | Uint | Sfloat) }, + { GalTextureFormat.R8, new TextureDescriptor(TextureReader.Read1Bpp, GalImageFormat.R8 | Snorm | Unorm | Sint | Uint ) }, + { GalTextureFormat.R32, new TextureDescriptor(TextureReader.Read4Bpp, GalImageFormat.R32 | Sint | Uint | Sfloat) }, + //TODO: Reverse this one in the reader + { GalTextureFormat.A4B4G4R4, new TextureDescriptor(TextureReader.Read2Bpp, GalImageFormat.R4G4B4A4_REVERSED | Unorm ) }, + { GalTextureFormat.A1B5G5R5, new TextureDescriptor(TextureReader.Read5551, GalImageFormat.A1R5G5B5 | Unorm ) }, + { GalTextureFormat.B5G6R5, new TextureDescriptor(TextureReader.Read565, GalImageFormat.B5G6R5 | Unorm ) }, + { GalTextureFormat.BF10GF11RF11, new TextureDescriptor(TextureReader.Read4Bpp, GalImageFormat.B10G11R11 | Sfloat) }, + { GalTextureFormat.Z24S8, new TextureDescriptor(TextureReader.Read4Bpp, GalImageFormat.D24_S8 | Unorm ) }, + { GalTextureFormat.ZF32, new TextureDescriptor(TextureReader.Read4Bpp, GalImageFormat.D32 | Sfloat) }, + { GalTextureFormat.ZF32_X24S8, new TextureDescriptor(TextureReader.Read8Bpp, GalImageFormat.D32_S8 | Unorm ) }, //Compressed formats - { GalTextureFormat.BC4, new TextureDescriptor(TextureReader.Read8Bpt4x4, Snorm: GalImageFormat.BC4_SNORM_BLOCK, Unorm: GalImageFormat.BC4_UNORM_BLOCK) }, - { GalTextureFormat.BC5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, Snorm: GalImageFormat.BC5_SNORM_BLOCK, Unorm: GalImageFormat.BC5_UNORM_BLOCK) }, - - { GalTextureFormat.BC7U, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, Unorm: GalImageFormat.BC7_UNORM_BLOCK) }, - { GalTextureFormat.BC1, new TextureDescriptor(TextureReader.Read8Bpt4x4, Unorm: GalImageFormat.BC1_RGBA_UNORM_BLOCK) }, - { GalTextureFormat.BC2, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, Unorm: GalImageFormat.BC2_UNORM_BLOCK) }, - { GalTextureFormat.BC3, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, Unorm: GalImageFormat.BC3_UNORM_BLOCK) }, - { GalTextureFormat.BC6H_SF16, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, Unorm: GalImageFormat.BC6H_SFLOAT_BLOCK) }, - { GalTextureFormat.BC6H_UF16, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, Unorm: GalImageFormat.BC6H_UFLOAT_BLOCK) }, - - { GalTextureFormat.Astc2D4x4, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, Unorm: GalImageFormat.ASTC_4x4_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D5x5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture5x5, Unorm: GalImageFormat.ASTC_5x5_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D6x6, new TextureDescriptor(TextureReader.Read16BptCompressedTexture6x6, Unorm: GalImageFormat.ASTC_6x6_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D8x8, new TextureDescriptor(TextureReader.Read16BptCompressedTexture8x8, Unorm: GalImageFormat.ASTC_8x8_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D10x10, new TextureDescriptor(TextureReader.Read16BptCompressedTexture10x10, Unorm: GalImageFormat.ASTC_10x10_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D12x12, new TextureDescriptor(TextureReader.Read16BptCompressedTexture12x12, Unorm: GalImageFormat.ASTC_12x12_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D5x4, new TextureDescriptor(TextureReader.Read16BptCompressedTexture5x4, Unorm: GalImageFormat.ASTC_5x4_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D6x5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture6x5, Unorm: GalImageFormat.ASTC_6x5_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D8x6, new TextureDescriptor(TextureReader.Read16BptCompressedTexture8x6, Unorm: GalImageFormat.ASTC_8x6_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D10x8, new TextureDescriptor(TextureReader.Read16BptCompressedTexture10x8, Unorm: GalImageFormat.ASTC_10x8_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D12x10, new TextureDescriptor(TextureReader.Read16BptCompressedTexture12x10, Unorm: GalImageFormat.ASTC_12x10_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D8x5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture8x5, Unorm: GalImageFormat.ASTC_8x5_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D10x5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture10x5, Unorm: GalImageFormat.ASTC_10x5_UNORM_BLOCK) }, - { GalTextureFormat.Astc2D10x6, new TextureDescriptor(TextureReader.Read16BptCompressedTexture10x6, Unorm: GalImageFormat.ASTC_10x6_UNORM_BLOCK) }, - + { GalTextureFormat.BC6H_SF16, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, GalImageFormat.BC6H_SF16 | Unorm ) }, + { GalTextureFormat.BC6H_UF16, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, GalImageFormat.BC6H_UF16 | Unorm ) }, + { GalTextureFormat.BC7U, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, GalImageFormat.BC7 | Unorm ) }, + { GalTextureFormat.BC1, new TextureDescriptor(TextureReader.Read8Bpt4x4, GalImageFormat.BC1_RGBA | Unorm ) }, + { GalTextureFormat.BC2, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, GalImageFormat.BC2 | Unorm ) }, + { GalTextureFormat.BC3, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, GalImageFormat.BC3 | Unorm ) }, + { GalTextureFormat.BC4, new TextureDescriptor(TextureReader.Read8Bpt4x4, GalImageFormat.BC4 | Unorm | Snorm) }, + { GalTextureFormat.BC5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, GalImageFormat.BC5 | Unorm | Snorm) }, + { GalTextureFormat.Astc2D4x4, new TextureDescriptor(TextureReader.Read16BptCompressedTexture4x4, GalImageFormat.ASTC_4x4 | Unorm ) }, + { GalTextureFormat.Astc2D5x5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture5x5, GalImageFormat.ASTC_5x5 | Unorm ) }, + { GalTextureFormat.Astc2D6x6, new TextureDescriptor(TextureReader.Read16BptCompressedTexture6x6, GalImageFormat.ASTC_6x6 | Unorm ) }, + { GalTextureFormat.Astc2D8x8, new TextureDescriptor(TextureReader.Read16BptCompressedTexture8x8, GalImageFormat.ASTC_8x8 | Unorm ) }, + { GalTextureFormat.Astc2D10x10, new TextureDescriptor(TextureReader.Read16BptCompressedTexture10x10, GalImageFormat.ASTC_10x10 | Unorm ) }, + { GalTextureFormat.Astc2D12x12, new TextureDescriptor(TextureReader.Read16BptCompressedTexture12x12, GalImageFormat.ASTC_12x12 | Unorm ) }, + { GalTextureFormat.Astc2D5x4, new TextureDescriptor(TextureReader.Read16BptCompressedTexture5x4, GalImageFormat.ASTC_5x4 | Unorm ) }, + { GalTextureFormat.Astc2D6x5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture6x5, GalImageFormat.ASTC_6x5 | Unorm ) }, + { GalTextureFormat.Astc2D8x6, new TextureDescriptor(TextureReader.Read16BptCompressedTexture8x6, GalImageFormat.ASTC_8x6 | Unorm ) }, + { GalTextureFormat.Astc2D10x8, new TextureDescriptor(TextureReader.Read16BptCompressedTexture10x8, GalImageFormat.ASTC_10x8 | Unorm ) }, + { GalTextureFormat.Astc2D12x10, new TextureDescriptor(TextureReader.Read16BptCompressedTexture12x10, GalImageFormat.ASTC_12x10 | Unorm ) }, + { GalTextureFormat.Astc2D8x5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture8x5, GalImageFormat.ASTC_8x5 | Unorm ) }, + { GalTextureFormat.Astc2D10x5, new TextureDescriptor(TextureReader.Read16BptCompressedTexture10x5, GalImageFormat.ASTC_10x5 | Unorm ) }, + { GalTextureFormat.Astc2D10x6, new TextureDescriptor(TextureReader.Read16BptCompressedTexture10x6, GalImageFormat.ASTC_10x6 | Unorm ) } }; private static readonly Dictionary s_ImageTable = new Dictionary() { - { GalImageFormat.R32G32B32A32_SFLOAT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R32G32B32A32_SINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R32G32B32A32_UINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16G16B16A16_SFLOAT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16G16B16A16_SINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16G16B16A16_UINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R32G32_SFLOAT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R32G32_SINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R32G32_UINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.A8B8G8R8_SNORM_PACK32, new ImageDescriptor(true, false, false) }, - { GalImageFormat.A8B8G8R8_UNORM_PACK32, new ImageDescriptor(true, false, false) }, - { GalImageFormat.A8B8G8R8_SINT_PACK32, new ImageDescriptor(true, false, false) }, - { GalImageFormat.A8B8G8R8_UINT_PACK32, new ImageDescriptor(true, false, false) }, - { GalImageFormat.A2B10G10R10_SINT_PACK32, new ImageDescriptor(true, false, false) }, - { GalImageFormat.A2B10G10R10_SNORM_PACK32, new ImageDescriptor(true, false, false) }, - { GalImageFormat.A2B10G10R10_UINT_PACK32, new ImageDescriptor(true, false, false) }, - { GalImageFormat.A2B10G10R10_UNORM_PACK32, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R32_SFLOAT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R32_SINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R32_UINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.BC6H_SFLOAT_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.BC6H_UFLOAT_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.A1R5G5B5_UNORM_PACK16, new ImageDescriptor(true, false, false) }, - { GalImageFormat.B5G6R5_UNORM_PACK16, new ImageDescriptor(true, false, false) }, - { GalImageFormat.BC7_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16G16_SFLOAT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16G16_SINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16G16_SNORM, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16G16_UNORM, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R8G8_SINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R8G8_SNORM, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R8G8_UINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R8G8_UNORM, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16_SFLOAT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16_SINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16_SNORM, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16_UINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R16_UNORM, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R8_SINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R8_SNORM, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R8_UINT, new ImageDescriptor(true, false, false) }, - { GalImageFormat.R8_UNORM, new ImageDescriptor(true, false, false) }, - { GalImageFormat.B10G11R11_UFLOAT_PACK32, new ImageDescriptor(true, false, false) }, - { GalImageFormat.BC1_RGBA_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.BC2_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.BC3_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.BC4_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.BC5_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_4x4_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_5x5_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_6x6_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_8x8_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_10x10_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_12x12_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_5x4_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_6x5_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_8x6_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_10x8_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_12x10_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_8x5_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_10x5_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, - { GalImageFormat.ASTC_10x6_UNORM_BLOCK, new ImageDescriptor(true, false, false) }, + { GalImageFormat.R32G32B32A32, new ImageDescriptor(true, false, false) }, + { GalImageFormat.R16G16B16A16, new ImageDescriptor(true, false, false) }, + { GalImageFormat.R32G32, new ImageDescriptor(true, false, false) }, + { GalImageFormat.A8B8G8R8, new ImageDescriptor(true, false, false) }, + { GalImageFormat.A2B10G10R10, new ImageDescriptor(true, false, false) }, + { GalImageFormat.R32, new ImageDescriptor(true, false, false) }, + { GalImageFormat.BC6H_SF16, new ImageDescriptor(true, false, false) }, + { GalImageFormat.BC6H_UF16, new ImageDescriptor(true, false, false) }, + { GalImageFormat.A1R5G5B5, new ImageDescriptor(true, false, false) }, + { GalImageFormat.B5G6R5, new ImageDescriptor(true, false, false) }, + { GalImageFormat.BC7, new ImageDescriptor(true, false, false) }, + { GalImageFormat.R16G16, new ImageDescriptor(true, false, false) }, + { GalImageFormat.R8G8, new ImageDescriptor(true, false, false) }, + { GalImageFormat.R16, new ImageDescriptor(true, false, false) }, + { GalImageFormat.R8, new ImageDescriptor(true, false, false) }, + { GalImageFormat.B10G11R11, new ImageDescriptor(true, false, false) }, + { GalImageFormat.BC1_RGBA, new ImageDescriptor(true, false, false) }, + { GalImageFormat.BC2, new ImageDescriptor(true, false, false) }, + { GalImageFormat.BC3, new ImageDescriptor(true, false, false) }, + { GalImageFormat.BC4, new ImageDescriptor(true, false, false) }, + { GalImageFormat.BC5, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_4x4, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_5x5, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_6x6, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_8x8, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_10x10, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_12x12, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_5x4, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_6x5, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_8x6, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_10x8, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_12x10, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_8x5, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_10x5, new ImageDescriptor(true, false, false) }, + { GalImageFormat.ASTC_10x6, new ImageDescriptor(true, false, false) }, - { GalImageFormat.D24_UNORM_S8_UINT, new ImageDescriptor(false, true, true) }, - { GalImageFormat.D32_SFLOAT, new ImageDescriptor(false, true, false) }, - { GalImageFormat.D16_UNORM, new ImageDescriptor(false, true, false) }, - { GalImageFormat.D32_SFLOAT_S8_UINT, new ImageDescriptor(false, true, true) }, + { GalImageFormat.D24_S8, new ImageDescriptor(false, true, true) }, + { GalImageFormat.D32, new ImageDescriptor(false, true, false) }, + { GalImageFormat.D16, new ImageDescriptor(false, true, false) }, + { GalImageFormat.D32_S8, new ImageDescriptor(false, true, true) }, - { GalImageFormat.R4G4B4A4_UNORM_PACK16_REVERSED, new ImageDescriptor(true, false, false) } + { GalImageFormat.R4G4B4A4_REVERSED, new ImageDescriptor(true, false, false) } }; public static GalImageFormat ConvertTexture( @@ -160,57 +134,46 @@ namespace Ryujinx.Graphics.Texture throw new NotImplementedException("Per component types are not implemented"); } - TextureDescriptor Descriptor = GetTextureDescriptor(Format); - GalTextureType Type = RType; - GalImageFormat? ImageFormat; + GalImageFormat ImageFormat = GetTextureDescriptor(Format).Format; - switch (Type) + GalImageFormat FormatType = GetFormatType(RType); + + if (ImageFormat.HasFlag(FormatType)) { - case GalTextureType.Snorm: ImageFormat = Descriptor.Snorm; break; - case GalTextureType.Unorm: ImageFormat = Descriptor.Unorm; break; - case GalTextureType.Sint: ImageFormat = Descriptor.Sint; break; - case GalTextureType.Uint: ImageFormat = Descriptor.Uint; break; - case GalTextureType.Float: ImageFormat = Descriptor.Float; break; - case GalTextureType.Snorm_Force_Fp16: ImageFormat = Descriptor.Snorm_Force_Fp16; break; - case GalTextureType.Unorm_Force_Fp16: ImageFormat = Descriptor.Unorm_Force_Fp16; break; - - default: throw new NotImplementedException("Unknown component type " + ((int)Type).ToString("x2")); + return (ImageFormat & GalImageFormat.FormatMask) | FormatType; } - - if (!ImageFormat.HasValue) + else { throw new NotImplementedException("Texture with format " + Format + " and component type " + Type + " is not implemented"); } - - return ImageFormat.Value; } public static GalImageFormat ConvertFrameBuffer(GalFrameBufferFormat Format) { switch (Format) { - case GalFrameBufferFormat.R32Float: return GalImageFormat.R32_SFLOAT; - case GalFrameBufferFormat.RGB10A2Unorm: return GalImageFormat.A2B10G10R10_UNORM_PACK32; - case GalFrameBufferFormat.RGBA8Srgb: return GalImageFormat.A8B8G8R8_SRGB_PACK32; - case GalFrameBufferFormat.RGBA16Float: return GalImageFormat.R16G16B16A16_SFLOAT; - case GalFrameBufferFormat.R16Float: return GalImageFormat.R16_SFLOAT; - case GalFrameBufferFormat.R8Unorm: return GalImageFormat.R8_UNORM; - case GalFrameBufferFormat.RGBA8Unorm: return GalImageFormat.A8B8G8R8_UNORM_PACK32; - case GalFrameBufferFormat.R11G11B10Float: return GalImageFormat.B10G11R11_UFLOAT_PACK32; - case GalFrameBufferFormat.RGBA32Float: return GalImageFormat.R32G32B32A32_SFLOAT; - case GalFrameBufferFormat.RG16Snorm: return GalImageFormat.R16G16_SNORM; - case GalFrameBufferFormat.RG16Float: return GalImageFormat.R16G16_SFLOAT; - case GalFrameBufferFormat.RG8Snorm: return GalImageFormat.R8_SNORM; - case GalFrameBufferFormat.RGBA8Snorm: return GalImageFormat.A8B8G8R8_SNORM_PACK32; - case GalFrameBufferFormat.RG8Unorm: return GalImageFormat.R8G8_UNORM; - case GalFrameBufferFormat.BGRA8Unorm: return GalImageFormat.A8B8G8R8_UNORM_PACK32; - case GalFrameBufferFormat.BGRA8Srgb: return GalImageFormat.A8B8G8R8_SRGB_PACK32; - case GalFrameBufferFormat.RG32Float: return GalImageFormat.R32G32_SFLOAT; - case GalFrameBufferFormat.RG32Sint: return GalImageFormat.R32G32_SINT; - case GalFrameBufferFormat.RG32Uint: return GalImageFormat.R32G32_UINT; + case GalFrameBufferFormat.RGBA32Float: return GalImageFormat.R32G32B32A32 | Sfloat; + case GalFrameBufferFormat.RGBA16Float: return GalImageFormat.R16G16B16A16 | Sfloat; + case GalFrameBufferFormat.RG32Float: return GalImageFormat.R32G32 | Sfloat; + case GalFrameBufferFormat.RG32Sint: return GalImageFormat.R32G32 | Sint; + case GalFrameBufferFormat.RG32Uint: return GalImageFormat.R32G32 | Uint; + case GalFrameBufferFormat.BGRA8Unorm: return GalImageFormat.R8G8B8A8 | Unorm; //Is this right? + case GalFrameBufferFormat.BGRA8Srgb: return GalImageFormat.A8B8G8R8_SRGB; //This one might be wrong + case GalFrameBufferFormat.RGB10A2Unorm: return GalImageFormat.A2B10G10R10 | Unorm; + case GalFrameBufferFormat.RGBA8Unorm: return GalImageFormat.A8B8G8R8 | Unorm; + case GalFrameBufferFormat.RGBA8Srgb: return GalImageFormat.A8B8G8R8_SRGB; + case GalFrameBufferFormat.RGBA8Snorm: return GalImageFormat.A8B8G8R8 | Snorm; + case GalFrameBufferFormat.RG16Snorm: return GalImageFormat.R16G16 | Snorm; + case GalFrameBufferFormat.RG16Float: return GalImageFormat.R16G16 | Sfloat; + case GalFrameBufferFormat.R11G11B10Float: return GalImageFormat.B10G11R11 | Sfloat; + case GalFrameBufferFormat.R32Float: return GalImageFormat.R32 | Sfloat; + case GalFrameBufferFormat.RG8Unorm: return GalImageFormat.R8G8 | Unorm; + case GalFrameBufferFormat.RG8Snorm: return GalImageFormat.R8 | Snorm; + case GalFrameBufferFormat.R16Float: return GalImageFormat.R16 | Sfloat; + case GalFrameBufferFormat.R8Unorm: return GalImageFormat.R8 | Unorm; } throw new NotImplementedException(Format.ToString()); @@ -220,10 +183,11 @@ namespace Ryujinx.Graphics.Texture { switch (Format) { - case GalZetaFormat.Z32Float: return GalImageFormat.D32_SFLOAT; - case GalZetaFormat.S8Z24Unorm: return GalImageFormat.D24_UNORM_S8_UINT; - case GalZetaFormat.Z16Unorm: return GalImageFormat.D16_UNORM; - case GalZetaFormat.Z32S8X24Float: return GalImageFormat.D32_SFLOAT_S8_UINT; + case GalZetaFormat.Z32Float: return GalImageFormat.D32 | Sfloat; + case GalZetaFormat.S8Z24Unorm: return GalImageFormat.D24_S8 | Unorm; + case GalZetaFormat.Z16Unorm: return GalImageFormat.D16 | Unorm; + //This one might not be Uint, change when a texture uses this format + case GalZetaFormat.Z32S8X24Float: return GalImageFormat.D32_S8 | Uint; } throw new NotImplementedException(Format.ToString()); @@ -231,168 +195,107 @@ namespace Ryujinx.Graphics.Texture public static int GetImageSize(GalImage Image) { - switch (Image.Format) + switch (Image.Format & GalImageFormat.FormatMask) { - case GalImageFormat.R32G32B32A32_SFLOAT: - case GalImageFormat.R32G32B32A32_SINT: - case GalImageFormat.R32G32B32A32_UINT: + case GalImageFormat.R32G32B32A32: return Image.Width * Image.Height * 16; - case GalImageFormat.R16G16B16A16_SFLOAT: - case GalImageFormat.R16G16B16A16_SINT: - case GalImageFormat.R16G16B16A16_SNORM: - case GalImageFormat.R16G16B16A16_UINT: - case GalImageFormat.R16G16B16A16_UNORM: - case GalImageFormat.D32_SFLOAT_S8_UINT: - case GalImageFormat.R32G32_SFLOAT: - case GalImageFormat.R32G32_SINT: - case GalImageFormat.R32G32_UINT: + case GalImageFormat.R16G16B16A16: + case GalImageFormat.D32_S8: + case GalImageFormat.R32G32: return Image.Width * Image.Height * 8; - case GalImageFormat.A8B8G8R8_SINT_PACK32: - case GalImageFormat.A8B8G8R8_SNORM_PACK32: - case GalImageFormat.A8B8G8R8_UINT_PACK32: - case GalImageFormat.A8B8G8R8_UNORM_PACK32: - case GalImageFormat.A8B8G8R8_SRGB_PACK32: - case GalImageFormat.A2B10G10R10_SINT_PACK32: - case GalImageFormat.A2B10G10R10_SNORM_PACK32: - case GalImageFormat.A2B10G10R10_UINT_PACK32: - case GalImageFormat.A2B10G10R10_UNORM_PACK32: - case GalImageFormat.R16G16_SFLOAT: - case GalImageFormat.R16G16_SINT: - case GalImageFormat.R16G16_SNORM: - case GalImageFormat.R16G16_UINT: - case GalImageFormat.R16G16_UNORM: - case GalImageFormat.R32_SFLOAT: - case GalImageFormat.R32_SINT: - case GalImageFormat.R32_UINT: - case GalImageFormat.D32_SFLOAT: - case GalImageFormat.B10G11R11_UFLOAT_PACK32: - case GalImageFormat.D24_UNORM_S8_UINT: + case GalImageFormat.A8B8G8R8: + case GalImageFormat.A2B10G10R10: + case GalImageFormat.R16G16: + case GalImageFormat.R32: + case GalImageFormat.D32: + case GalImageFormat.B10G11R11: + case GalImageFormat.D24_S8: return Image.Width * Image.Height * 4; - case GalImageFormat.B4G4R4A4_UNORM_PACK16: - case GalImageFormat.A1R5G5B5_UNORM_PACK16: - case GalImageFormat.B5G6R5_UNORM_PACK16: - case GalImageFormat.R8G8_SINT: - case GalImageFormat.R8G8_SNORM: - case GalImageFormat.R8G8_UINT: - case GalImageFormat.R8G8_UNORM: - case GalImageFormat.R16_SFLOAT: - case GalImageFormat.R16_SINT: - case GalImageFormat.R16_SNORM: - case GalImageFormat.R16_UINT: - case GalImageFormat.R16_UNORM: - case GalImageFormat.D16_UNORM: + case GalImageFormat.B4G4R4A4: + case GalImageFormat.A1R5G5B5: + case GalImageFormat.B5G6R5: + case GalImageFormat.R8G8: + case GalImageFormat.R16: + case GalImageFormat.D16: return Image.Width * Image.Height * 2; - case GalImageFormat.R8_SINT: - case GalImageFormat.R8_SNORM: - case GalImageFormat.R8_UINT: - case GalImageFormat.R8_UNORM: + case GalImageFormat.R8: return Image.Width * Image.Height; - case GalImageFormat.BC1_RGBA_UNORM_BLOCK: - case GalImageFormat.BC4_SNORM_BLOCK: - case GalImageFormat.BC4_UNORM_BLOCK: + case GalImageFormat.BC1_RGBA: + case GalImageFormat.BC4: { return CompressedTextureSize(Image.Width, Image.Height, 4, 4, 8); } - case GalImageFormat.BC6H_SFLOAT_BLOCK: - case GalImageFormat.BC6H_UFLOAT_BLOCK: - case GalImageFormat.BC7_UNORM_BLOCK: - case GalImageFormat.BC2_UNORM_BLOCK: - case GalImageFormat.BC3_UNORM_BLOCK: - case GalImageFormat.BC5_SNORM_BLOCK: - case GalImageFormat.BC5_UNORM_BLOCK: - case GalImageFormat.ASTC_4x4_UNORM_BLOCK: - { + case GalImageFormat.BC6H_SF16: + case GalImageFormat.BC6H_UF16: + case GalImageFormat.BC7: + case GalImageFormat.BC2: + case GalImageFormat.BC3: + case GalImageFormat.BC5: + case GalImageFormat.ASTC_4x4: return CompressedTextureSize(Image.Width, Image.Height, 4, 4, 16); - } - case GalImageFormat.ASTC_5x5_UNORM_BLOCK: - { + case GalImageFormat.ASTC_5x5: return CompressedTextureSize(Image.Width, Image.Height, 5, 5, 16); - } - case GalImageFormat.ASTC_6x6_UNORM_BLOCK: - { + case GalImageFormat.ASTC_6x6: return CompressedTextureSize(Image.Width, Image.Height, 6, 6, 16); - } - case GalImageFormat.ASTC_8x8_UNORM_BLOCK: - { + case GalImageFormat.ASTC_8x8: return CompressedTextureSize(Image.Width, Image.Height, 8, 8, 16); - } - case GalImageFormat.ASTC_10x10_UNORM_BLOCK: - { + case GalImageFormat.ASTC_10x10: return CompressedTextureSize(Image.Width, Image.Height, 10, 10, 16); - } - case GalImageFormat.ASTC_12x12_UNORM_BLOCK: - { + case GalImageFormat.ASTC_12x12: return CompressedTextureSize(Image.Width, Image.Height, 12, 12, 16); - } - case GalImageFormat.ASTC_5x4_UNORM_BLOCK: - { + case GalImageFormat.ASTC_5x4: return CompressedTextureSize(Image.Width, Image.Height, 5, 4, 16); - } - case GalImageFormat.ASTC_6x5_UNORM_BLOCK: - { + case GalImageFormat.ASTC_6x5: return CompressedTextureSize(Image.Width, Image.Height, 6, 5, 16); - } - case GalImageFormat.ASTC_8x6_UNORM_BLOCK: - { + case GalImageFormat.ASTC_8x6: return CompressedTextureSize(Image.Width, Image.Height, 8, 6, 16); - } - case GalImageFormat.ASTC_10x8_UNORM_BLOCK: - { + case GalImageFormat.ASTC_10x8: return CompressedTextureSize(Image.Width, Image.Height, 10, 8, 16); - } - case GalImageFormat.ASTC_12x10_UNORM_BLOCK: - { + case GalImageFormat.ASTC_12x10: return CompressedTextureSize(Image.Width, Image.Height, 12, 10, 16); - } - case GalImageFormat.ASTC_8x5_UNORM_BLOCK: - { + case GalImageFormat.ASTC_8x5: return CompressedTextureSize(Image.Width, Image.Height, 8, 5, 16); - } - case GalImageFormat.ASTC_10x5_UNORM_BLOCK: - { + case GalImageFormat.ASTC_10x5: return CompressedTextureSize(Image.Width, Image.Height, 10, 5, 16); - } - case GalImageFormat.ASTC_10x6_UNORM_BLOCK: - { + case GalImageFormat.ASTC_10x6: return CompressedTextureSize(Image.Width, Image.Height, 10, 6, 16); - } } - throw new NotImplementedException(Image.Format.ToString()); + throw new NotImplementedException((Image.Format & GalImageFormat.FormatMask).ToString()); } public static bool HasColor(GalImage Image) { - return s_ImageTable[Image.Format].HasColor; + return GetImageDescriptor(Image.Format).HasColor; } public static bool HasDepth(GalImage Image) { - return s_ImageTable[Image.Format].HasDepth; + return GetImageDescriptor(Image.Format).HasDepth; } public static bool HasStencil(GalImage Image) { - return s_ImageTable[Image.Format].HasStencil; + return GetImageDescriptor(Image.Format).HasStencil; } public static TextureDescriptor GetTextureDescriptor(GalTextureFormat Format) @@ -405,6 +308,32 @@ namespace Ryujinx.Graphics.Texture throw new NotImplementedException("Texture with format code " + ((int)Format).ToString("x2") + " not implemented"); } + private static ImageDescriptor GetImageDescriptor(GalImageFormat Format) + { + GalImageFormat TypeLess = (Format & GalImageFormat.FormatMask); + + if (s_ImageTable.TryGetValue(TypeLess, out ImageDescriptor Descriptor)) + { + return Descriptor; + } + + throw new NotImplementedException("Image with format " + TypeLess.ToString() + "not implemented"); + } + + private static GalImageFormat GetFormatType(GalTextureType Type) + { + switch (Type) + { + case GalTextureType.Snorm: return Snorm; + case GalTextureType.Unorm: return Unorm; + case GalTextureType.Sint: return Sint; + case GalTextureType.Uint: return Uint; + case GalTextureType.Float: return Sfloat; + + default: throw new NotImplementedException(((int)Type).ToString()); + } + } + private static int CompressedTextureSize(int TextureWidth, int TextureHeight, int BlockWidth, int BlockHeight, int Bpb) { int W = (TextureWidth + (BlockWidth - 1)) / BlockWidth; diff --git a/Ryujinx.Graphics/Texture/TextureDescriptor.cs b/Ryujinx.Graphics/Texture/TextureDescriptor.cs index e7558a9bf0..7c4a1291f7 100644 --- a/Ryujinx.Graphics/Texture/TextureDescriptor.cs +++ b/Ryujinx.Graphics/Texture/TextureDescriptor.cs @@ -6,32 +6,14 @@ namespace Ryujinx.Graphics.Texture { public TextureReaderDelegate Reader; - public GalImageFormat? Snorm; - public GalImageFormat? Unorm; - public GalImageFormat? Sint; - public GalImageFormat? Uint; - public GalImageFormat? Float; - public GalImageFormat? Snorm_Force_Fp16; - public GalImageFormat? Unorm_Force_Fp16; + public GalImageFormat Format; public TextureDescriptor( TextureReaderDelegate Reader, - GalImageFormat? Snorm = null, - GalImageFormat? Unorm = null, - GalImageFormat? Sint = null, - GalImageFormat? Uint = null, - GalImageFormat? Float = null, - GalImageFormat? Snorm_Force_Fp16 = null, - GalImageFormat? Unorm_Force_Fp16 = null) + GalImageFormat Format) { - this.Reader = Reader; - this.Snorm = Snorm; - this.Unorm = Unorm; - this.Sint = Sint; - this.Uint = Uint; - this.Float = Float; - this.Snorm_Force_Fp16 = Snorm_Force_Fp16; - this.Unorm_Force_Fp16 = Unorm_Force_Fp16; + this.Reader = Reader; + this.Format = Format; } } } \ No newline at end of file