From 679c2dde27d1ba198f73ae10f401e52d27f40c73 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Thu, 16 Aug 2018 02:03:45 -0300 Subject: [PATCH] Handle format types --- Ryujinx.Graphics/Gal/GalImageFormat.cs | 230 +++++++++++--- Ryujinx.Graphics/Gal/GalTextureType.cs | 13 + Ryujinx.Graphics/Gal/ImageFormatConverter.cs | 296 ++++++++++++------ .../Gal/OpenGL/OGLEnumConverter.cs | 73 +++-- Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs | 2 +- Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs | 85 ++--- Ryujinx.Graphics/Gal/OpenGL/TCE.cs | 7 + Ryujinx.HLE/Gpu/Texture/TextureFactory.cs | 7 +- Ryujinx.HLE/Gpu/Texture/TextureHelper.cs | 105 ++++--- 9 files changed, 587 insertions(+), 231 deletions(-) create mode 100644 Ryujinx.Graphics/Gal/GalTextureType.cs diff --git a/Ryujinx.Graphics/Gal/GalImageFormat.cs b/Ryujinx.Graphics/Gal/GalImageFormat.cs index 904de16118..6fcded4164 100644 --- a/Ryujinx.Graphics/Gal/GalImageFormat.cs +++ b/Ryujinx.Graphics/Gal/GalImageFormat.cs @@ -1,46 +1,198 @@ namespace Ryujinx.Graphics.Gal { + //These are Vulkan-based enumerations, do not take them as Tegra values public enum GalImageFormat { - R32G32B32A32, - R16G16B16A16, - A8B8G8R8, - A2B10G10R10, - R32, - BC6H_SF16, - BC6H_UF16, - A1B5G5R5, - B5G6R5, - BC7U, - G16R16, - G8R8, - R16, - R8, - BF10GF11RF11, - BC1, - BC2, - BC3, - BC4, - BC5, - Z24S8, - ZF32, - Z16, + Undefined = 0, - ConvertedBegin, - Astc2D4x4, - Astc2D5x5, - Astc2D6x6, - Astc2D8x8, - Astc2D10x10, - Astc2D12x12, - Astc2D5x4, - Astc2D6x5, - Astc2D8x6, - Astc2D10x8, - Astc2D12x10, - Astc2D8x5, - Astc2D10x5, - Astc2D10x6, - ConvertedEnd + 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, + + ASTC_BEGIN = ASTC_4x4_UNORM_BLOCK, + + 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_END = ASTC_12x12_SRGB_BLOCK, } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Gal/GalTextureType.cs b/Ryujinx.Graphics/Gal/GalTextureType.cs new file mode 100644 index 0000000000..f7dd16d15a --- /dev/null +++ b/Ryujinx.Graphics/Gal/GalTextureType.cs @@ -0,0 +1,13 @@ +namespace Ryujinx.Graphics.Gal +{ + public enum GalTextureType + { + Snorm = 1, + Unorm = 2, + Sint = 3, + Uint = 4, + Snorm_Force_Fp16 = 5, + Unorm_Force_Fp16 = 6, + Float = 7 + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics/Gal/ImageFormatConverter.cs b/Ryujinx.Graphics/Gal/ImageFormatConverter.cs index 07385545c5..305f192f76 100644 --- a/Ryujinx.Graphics/Gal/ImageFormatConverter.cs +++ b/Ryujinx.Graphics/Gal/ImageFormatConverter.cs @@ -4,66 +4,147 @@ namespace Ryujinx.Graphics.Gal { public static class ImageFormatConverter { - public static GalImageFormat ConvertTexture(GalTextureFormat Format) + public static GalImageFormat ConvertTexture( + GalTextureFormat Format, + GalTextureType RType, + GalTextureType GType, + GalTextureType BType, + GalTextureType AType) { - switch (Format) + if (RType != GType || RType != BType || RType != AType) { - case GalTextureFormat.R32G32B32A32: return GalImageFormat.R32G32B32A32; - case GalTextureFormat.R16G16B16A16: return GalImageFormat.R16G16B16A16; - case GalTextureFormat.A8B8G8R8: return GalImageFormat.A8B8G8R8; - case GalTextureFormat.A2B10G10R10: return GalImageFormat.A2B10G10R10; - case GalTextureFormat.R32: return GalImageFormat.R32; - case GalTextureFormat.BC6H_SF16: return GalImageFormat.BC6H_SF16; - case GalTextureFormat.BC6H_UF16: return GalImageFormat.BC6H_UF16; - case GalTextureFormat.A1B5G5R5: return GalImageFormat.A1B5G5R5; - case GalTextureFormat.B5G6R5: return GalImageFormat.B5G6R5; - case GalTextureFormat.BC7U: return GalImageFormat.BC7U; - case GalTextureFormat.G8R8: return GalImageFormat.G8R8; - case GalTextureFormat.R16: return GalImageFormat.R16; - case GalTextureFormat.R8: return GalImageFormat.R8; - case GalTextureFormat.BF10GF11RF11: return GalImageFormat.BF10GF11RF11; - case GalTextureFormat.BC1: return GalImageFormat.BC1; - case GalTextureFormat.BC2: return GalImageFormat.BC2; - case GalTextureFormat.BC3: return GalImageFormat.BC3; - case GalTextureFormat.BC4: return GalImageFormat.BC4; - case GalTextureFormat.BC5: return GalImageFormat.BC5; - case GalTextureFormat.Z24S8: return GalImageFormat.Z24S8; - case GalTextureFormat.ZF32: return GalImageFormat.ZF32; - case GalTextureFormat.Astc2D4x4: return GalImageFormat.Astc2D4x4; - case GalTextureFormat.Astc2D5x5: return GalImageFormat.Astc2D5x5; - case GalTextureFormat.Astc2D6x6: return GalImageFormat.Astc2D6x6; - case GalTextureFormat.Astc2D8x8: return GalImageFormat.Astc2D8x8; - case GalTextureFormat.Astc2D10x10: return GalImageFormat.Astc2D10x10; - case GalTextureFormat.Astc2D12x12: return GalImageFormat.Astc2D12x12; - case GalTextureFormat.Astc2D5x4: return GalImageFormat.Astc2D5x4; - case GalTextureFormat.Astc2D6x5: return GalImageFormat.Astc2D6x5; - case GalTextureFormat.Astc2D8x6: return GalImageFormat.Astc2D8x6; - case GalTextureFormat.Astc2D10x8: return GalImageFormat.Astc2D10x8; - case GalTextureFormat.Astc2D12x10: return GalImageFormat.Astc2D12x10; - case GalTextureFormat.Astc2D8x5: return GalImageFormat.Astc2D8x5; - case GalTextureFormat.Astc2D10x5: return GalImageFormat.Astc2D10x5; - case GalTextureFormat.Astc2D10x6: return GalImageFormat.Astc2D10x6; + throw new NotImplementedException("Per component types are not implemented"); } - throw new NotImplementedException(Format.ToString()); + GalTextureType Type = RType; + + switch (Type) + { + case GalTextureType.Snorm: + switch (Format) + { + case GalTextureFormat.R16G16B16A16: return GalImageFormat.R16G16B16A16_SNORM; + case GalTextureFormat.A8B8G8R8: return GalImageFormat.A8B8G8R8_SNORM_PACK32; + case GalTextureFormat.A2B10G10R10: return GalImageFormat.A2B10G10R10_SNORM_PACK32; + case GalTextureFormat.G8R8: return GalImageFormat.R8G8_SNORM; + case GalTextureFormat.R16: return GalImageFormat.R16_SNORM; + case GalTextureFormat.R8: return GalImageFormat.R8_SNORM; + case GalTextureFormat.BC4: return GalImageFormat.BC4_SNORM_BLOCK; + case GalTextureFormat.BC5: return GalImageFormat.BC5_SNORM_BLOCK; + } + break; + + case GalTextureType.Unorm: + switch (Format) + { + case GalTextureFormat.R16G16B16A16: return GalImageFormat.R16G16B16A16_UNORM; + case GalTextureFormat.A8B8G8R8: return GalImageFormat.A8B8G8R8_UNORM_PACK32; + case GalTextureFormat.A2B10G10R10: return GalImageFormat.A2B10G10R10_UNORM_PACK32; + case GalTextureFormat.A1B5G5R5: return GalImageFormat.A1R5G5B5_UNORM_PACK16; + case GalTextureFormat.B5G6R5: return GalImageFormat.B5G6R5_UNORM_PACK16; + case GalTextureFormat.BC7U: return GalImageFormat.BC7_UNORM_BLOCK; + case GalTextureFormat.G8R8: return GalImageFormat.R8G8_UNORM; + case GalTextureFormat.R16: return GalImageFormat.R16_UNORM; + case GalTextureFormat.R8: return GalImageFormat.R8_UNORM; + case GalTextureFormat.BC1: return GalImageFormat.BC1_RGBA_UNORM_BLOCK; + case GalTextureFormat.BC2: return GalImageFormat.BC2_UNORM_BLOCK; + case GalTextureFormat.BC3: return GalImageFormat.BC3_UNORM_BLOCK; + case GalTextureFormat.BC4: return GalImageFormat.BC4_UNORM_BLOCK; + case GalTextureFormat.BC5: return GalImageFormat.BC5_UNORM_BLOCK; + case GalTextureFormat.Z24S8: return GalImageFormat.D24_UNORM_S8_UINT; + case GalTextureFormat.Astc2D4x4: return GalImageFormat.ASTC_4x4_UNORM_BLOCK; + case GalTextureFormat.Astc2D5x5: return GalImageFormat.ASTC_5x5_UNORM_BLOCK; + case GalTextureFormat.Astc2D6x6: return GalImageFormat.ASTC_6x6_UNORM_BLOCK; + case GalTextureFormat.Astc2D8x8: return GalImageFormat.ASTC_8x8_UNORM_BLOCK; + case GalTextureFormat.Astc2D10x10: return GalImageFormat.ASTC_10x10_UNORM_BLOCK; + case GalTextureFormat.Astc2D12x12: return GalImageFormat.ASTC_12x12_UNORM_BLOCK; + case GalTextureFormat.Astc2D5x4: return GalImageFormat.ASTC_5x4_UNORM_BLOCK; + case GalTextureFormat.Astc2D6x5: return GalImageFormat.ASTC_6x5_UNORM_BLOCK; + case GalTextureFormat.Astc2D8x6: return GalImageFormat.ASTC_8x6_UNORM_BLOCK; + case GalTextureFormat.Astc2D10x8: return GalImageFormat.ASTC_10x8_UNORM_BLOCK; + case GalTextureFormat.Astc2D12x10: return GalImageFormat.ASTC_12x10_UNORM_BLOCK; + case GalTextureFormat.Astc2D8x5: return GalImageFormat.ASTC_8x5_UNORM_BLOCK; + case GalTextureFormat.Astc2D10x5: return GalImageFormat.ASTC_10x5_UNORM_BLOCK; + case GalTextureFormat.Astc2D10x6: return GalImageFormat.ASTC_10x6_UNORM_BLOCK; + } + break; + + case GalTextureType.Sint: + switch (Format) + { + case GalTextureFormat.R32G32B32A32: return GalImageFormat.R32G32B32A32_SINT; + case GalTextureFormat.R16G16B16A16: return GalImageFormat.R16G16B16A16_SINT; + case GalTextureFormat.A8B8G8R8: return GalImageFormat.A8B8G8R8_SINT_PACK32; + case GalTextureFormat.A2B10G10R10: return GalImageFormat.A2B10G10R10_SINT_PACK32; + case GalTextureFormat.R32: return GalImageFormat.R32_SINT; + case GalTextureFormat.G8R8: return GalImageFormat.R8G8_SINT; + case GalTextureFormat.R16: return GalImageFormat.R16_SINT; + case GalTextureFormat.R8: return GalImageFormat.R8_SINT; + } + break; + + case GalTextureType.Uint: + switch (Format) + { + case GalTextureFormat.R32G32B32A32: return GalImageFormat.R32G32B32A32_UINT; + case GalTextureFormat.R16G16B16A16: return GalImageFormat.R16G16B16A16_UINT; + case GalTextureFormat.A8B8G8R8: return GalImageFormat.A8B8G8R8_UINT_PACK32; + case GalTextureFormat.A2B10G10R10: return GalImageFormat.A2B10G10R10_UINT_PACK32; + case GalTextureFormat.R32: return GalImageFormat.R32_UINT; + case GalTextureFormat.G8R8: return GalImageFormat.R8G8_UINT; + case GalTextureFormat.R16: return GalImageFormat.R16_UINT; + case GalTextureFormat.R8: return GalImageFormat.R8_UINT; + } + break; + + case GalTextureType.Snorm_Force_Fp16: + switch (Format) + { + //TODO + } + break; + + case GalTextureType.Unorm_Force_Fp16: + switch (Format) + { + //TODO + } + break; + + case GalTextureType.Float: + switch (Format) + { + case GalTextureFormat.R32G32B32A32: return GalImageFormat.R32G32B32A32_SFLOAT; + case GalTextureFormat.R16G16B16A16: return GalImageFormat.R16G16B16A16_SFLOAT; + case GalTextureFormat.R32: return GalImageFormat.R32_SFLOAT; + case GalTextureFormat.BC6H_SF16: return GalImageFormat.BC6H_SFLOAT_BLOCK; + case GalTextureFormat.BC6H_UF16: return GalImageFormat.BC6H_UFLOAT_BLOCK; + case GalTextureFormat.R16: return GalImageFormat.R16_SFLOAT; + case GalTextureFormat.BF10GF11RF11: return GalImageFormat.B10G11R11_UFLOAT_PACK32; + case GalTextureFormat.ZF32: return GalImageFormat.D32_SFLOAT; + } + break; + } + + throw new NotImplementedException(Format.ToString() + " " + Type.ToString()); } public static GalImageFormat ConvertFrameBuffer(GalFrameBufferFormat Format) { switch (Format) { - case GalFrameBufferFormat.R32Float: return GalImageFormat.R32; - case GalFrameBufferFormat.RGB10A2Unorm: return GalImageFormat.A2B10G10R10; - case GalFrameBufferFormat.RGBA8Srgb: return GalImageFormat.A8B8G8R8; //Stubbed - case GalFrameBufferFormat.RGBA16Float: return GalImageFormat.R16G16B16A16; - case GalFrameBufferFormat.R16Float: return GalImageFormat.R16; - case GalFrameBufferFormat.R8Unorm: return GalImageFormat.R8; - case GalFrameBufferFormat.RGBA8Unorm: return GalImageFormat.A8B8G8R8; - case GalFrameBufferFormat.R11G11B10Float: return GalImageFormat.BF10GF11RF11; - case GalFrameBufferFormat.RGBA32Float: return GalImageFormat.R32G32B32A32; - case GalFrameBufferFormat.RG16Snorm: return GalImageFormat.G16R16; - case GalFrameBufferFormat.RG16Float: return GalImageFormat.G16R16; //Stubbed - case GalFrameBufferFormat.RG8Snorm: return GalImageFormat.R8; //Stubbed + 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; } throw new NotImplementedException(Format.ToString()); @@ -73,9 +154,9 @@ namespace Ryujinx.Graphics.Gal { switch (Format) { - case GalZetaFormat.Z32Float: return GalImageFormat.ZF32; - case GalZetaFormat.S8Z24Unorm: return GalImageFormat.Z24S8; - case GalZetaFormat.Z16Unorm: return GalImageFormat.Z16; + case GalZetaFormat.Z32Float: return GalImageFormat.D32_SFLOAT; + case GalZetaFormat.S8Z24Unorm: return GalImageFormat.D24_UNORM_S8_UINT; + case GalZetaFormat.Z16Unorm: return GalImageFormat.D16_UNORM; } throw new NotImplementedException(Format.ToString()); @@ -85,56 +166,87 @@ namespace Ryujinx.Graphics.Gal { switch (Format) { - case GalImageFormat.R32G32B32A32: - case GalImageFormat.R16G16B16A16: - case GalImageFormat.A8B8G8R8: - case GalImageFormat.A2B10G10R10: - case GalImageFormat.R32: - case GalImageFormat.BC6H_SF16: - case GalImageFormat.BC6H_UF16: - case GalImageFormat.A1B5G5R5: - case GalImageFormat.B5G6R5: - case GalImageFormat.BC7U: - case GalImageFormat.G16R16: - case GalImageFormat.G8R8: - case GalImageFormat.R16: - case GalImageFormat.R8: - case GalImageFormat.BF10GF11RF11: - case GalImageFormat.BC1: - case GalImageFormat.BC2: - case GalImageFormat.BC3: - case GalImageFormat.BC4: - case GalImageFormat.BC5: - case GalImageFormat.Astc2D4x4: - case GalImageFormat.Astc2D5x5: - case GalImageFormat.Astc2D6x6: - case GalImageFormat.Astc2D8x8: - case GalImageFormat.Astc2D10x10: - case GalImageFormat.Astc2D12x12: - case GalImageFormat.Astc2D5x4: - case GalImageFormat.Astc2D6x5: - case GalImageFormat.Astc2D8x6: - case GalImageFormat.Astc2D10x8: - case GalImageFormat.Astc2D12x10: - case GalImageFormat.Astc2D8x5: - case GalImageFormat.Astc2D10x5: - case GalImageFormat.Astc2D10x6: + case GalImageFormat.R32G32B32A32_SFLOAT: + case GalImageFormat.R32G32B32A32_SINT: + case GalImageFormat.R32G32B32A32_UINT: + case GalImageFormat.R16G16B16A16_SFLOAT: + case GalImageFormat.R16G16B16A16_SINT: + case GalImageFormat.R16G16B16A16_UINT: + case GalImageFormat.A8B8G8R8_SNORM_PACK32: + case GalImageFormat.A8B8G8R8_UNORM_PACK32: + case GalImageFormat.A8B8G8R8_SINT_PACK32: + case GalImageFormat.A8B8G8R8_UINT_PACK32: + case GalImageFormat.A2B10G10R10_SINT_PACK32: + case GalImageFormat.A2B10G10R10_SNORM_PACK32: + case GalImageFormat.A2B10G10R10_UINT_PACK32: + case GalImageFormat.A2B10G10R10_UNORM_PACK32: + case GalImageFormat.R32_SFLOAT: + case GalImageFormat.R32_SINT: + case GalImageFormat.R32_UINT: + case GalImageFormat.BC6H_SFLOAT_BLOCK: + case GalImageFormat.BC6H_UFLOAT_BLOCK: + case GalImageFormat.A1R5G5B5_UNORM_PACK16: + case GalImageFormat.B5G6R5_UNORM_PACK16: + case GalImageFormat.BC7_UNORM_BLOCK: + case GalImageFormat.R16G16_SFLOAT: + case GalImageFormat.R16G16_SINT: + case GalImageFormat.R16G16_SNORM: + case GalImageFormat.R16G16_UNORM: + 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.R8_SINT: + case GalImageFormat.R8_SNORM: + case GalImageFormat.R8_UINT: + case GalImageFormat.R8_UNORM: + case GalImageFormat.B10G11R11_UFLOAT_PACK32: + case GalImageFormat.BC1_RGBA_UNORM_BLOCK: + case GalImageFormat.BC2_UNORM_BLOCK: + case GalImageFormat.BC3_UNORM_BLOCK: + case GalImageFormat.BC4_UNORM_BLOCK: + case GalImageFormat.BC5_UNORM_BLOCK: + case GalImageFormat.ASTC_4x4_UNORM_BLOCK: + case GalImageFormat.ASTC_5x5_UNORM_BLOCK: + case GalImageFormat.ASTC_6x6_UNORM_BLOCK: + case GalImageFormat.ASTC_8x8_UNORM_BLOCK: + case GalImageFormat.ASTC_10x10_UNORM_BLOCK: + case GalImageFormat.ASTC_12x12_UNORM_BLOCK: + case GalImageFormat.ASTC_5x4_UNORM_BLOCK: + case GalImageFormat.ASTC_6x5_UNORM_BLOCK: + case GalImageFormat.ASTC_8x6_UNORM_BLOCK: + case GalImageFormat.ASTC_10x8_UNORM_BLOCK: + case GalImageFormat.ASTC_12x10_UNORM_BLOCK: + case GalImageFormat.ASTC_8x5_UNORM_BLOCK: + case GalImageFormat.ASTC_10x5_UNORM_BLOCK: + case GalImageFormat.ASTC_10x6_UNORM_BLOCK: + return true; + + case GalImageFormat.D24_UNORM_S8_UINT: + case GalImageFormat.D32_SFLOAT: + case GalImageFormat.D16_UNORM: return true; } - return false; + throw new NotImplementedException(Format.ToString()); } public static bool HasDepth(GalImageFormat Format) { switch (Format) { - case GalImageFormat.Z24S8: - case GalImageFormat.ZF32: - case GalImageFormat.Z16: + case GalImageFormat.D24_UNORM_S8_UINT: + case GalImageFormat.D32_SFLOAT: + case GalImageFormat.D16_UNORM: return true; } + //Depth formats are easier to maintain so not false case, just return false return false; } @@ -142,7 +254,7 @@ namespace Ryujinx.Graphics.Gal { switch (Format) { - case GalImageFormat.Z24S8: + case GalImageFormat.D24_UNORM_S8_UINT: return true; } diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs index 525d3facfc..49fca698f6 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs @@ -129,21 +129,46 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.R32G32B32A32: return (PixelInternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float); - case GalImageFormat.R16G16B16A16: return (PixelInternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat); - case GalImageFormat.A8B8G8R8: return (PixelInternalFormat.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte); - case GalImageFormat.A2B10G10R10: return (PixelInternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Reversed); - case GalImageFormat.R32: return (PixelInternalFormat.R32f, PixelFormat.Red, PixelType.Float); - case GalImageFormat.A1B5G5R5: return (PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551); - case GalImageFormat.B5G6R5: return (PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565); //Stubbed. - case GalImageFormat.G16R16: return (PixelInternalFormat.Rg16f, PixelFormat.Rg, PixelType.HalfFloat); - case GalImageFormat.G8R8: return (PixelInternalFormat.Rg8, PixelFormat.Rg, PixelType.UnsignedByte); - case GalImageFormat.R16: return (PixelInternalFormat.R16, PixelFormat.Red, PixelType.HalfFloat); - case GalImageFormat.R8: return (PixelInternalFormat.R8, PixelFormat.Red, PixelType.UnsignedByte); - case GalImageFormat.ZF32: return (PixelInternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float); - case GalImageFormat.Z16: return (PixelInternalFormat.DepthComponent16, PixelFormat.DepthComponent, PixelType.HalfFloat); - case GalImageFormat.BF10GF11RF11: return (PixelInternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10F11F11FRev); - case GalImageFormat.Z24S8: return (PixelInternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248); + 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.Float); + case GalImageFormat.R16G16B16A16_SINT: return (PixelInternalFormat.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short); + case GalImageFormat.R16G16B16A16_UINT: return (PixelInternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort); + 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.Float); + 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.Float); + 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.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); } throw new NotImplementedException(Format.ToString()); @@ -153,14 +178,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.BC6H_UF16: return InternalFormat.CompressedRgbBptcUnsignedFloat; - case GalImageFormat.BC6H_SF16: return InternalFormat.CompressedRgbBptcSignedFloat; - case GalImageFormat.BC7U: return InternalFormat.CompressedRgbaBptcUnorm; - case GalImageFormat.BC1: return InternalFormat.CompressedRgbaS3tcDxt1Ext; - case GalImageFormat.BC2: return InternalFormat.CompressedRgbaS3tcDxt3Ext; - case GalImageFormat.BC3: return InternalFormat.CompressedRgbaS3tcDxt5Ext; - case GalImageFormat.BC4: return InternalFormat.CompressedRedRgtc1; - case GalImageFormat.BC5: return InternalFormat.CompressedSignedRgRgtc2; + 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; } throw new NotImplementedException(Format.ToString()); diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs index 4c573d1016..7f8cb63ffc 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLFrameBuffer.cs @@ -38,7 +38,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL private const int NativeWidth = 1280; private const int NativeHeight = 720; - private const GalImageFormat RawFormat = GalImageFormat.A8B8G8R8; + private const GalImageFormat RawFormat = GalImageFormat.A8B8G8R8_UNORM_PACK32; private OGLTexture Texture; diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs index 24dd83b006..fe865cf422 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs @@ -55,7 +55,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL } else { - if (Image.Format > GalImageFormat.ConvertedBegin && Image.Format < GalImageFormat.ConvertedEnd) + if (Image.Format >= GalImageFormat.ASTC_BEGIN && Image.Format <= GalImageFormat.ASTC_END) { int TextureBlockWidth = GetAstcBlockWidth(Image.Format); int TextureBlockHeight = GetAstcBlockHeight(Image.Format); @@ -67,11 +67,13 @@ namespace Ryujinx.Graphics.Gal.OpenGL Image.Width, Image.Height, 1); - Image.Format = GalImageFormat.A8B8G8R8; + Image.Format = GalImageFormat.A8B8G8R8_UNORM_PACK32; } (PixelInternalFormat InternalFormat, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format); + GL.GetError(); + GL.TexImage2D( TextureTarget.Texture2D, Level, @@ -82,6 +84,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL Format, Type, Data); + + if (GL.GetError() != ErrorCode.NoError) + { + throw new InvalidOperationException($"{InternalFormat} {Format} {Type}"); + } } int SwizzleR = (int)OGLEnumConverter.GetTextureSwizzle(Image.XSource); @@ -123,20 +130,20 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.Astc2D4x4: return 4; - case GalImageFormat.Astc2D5x5: return 5; - case GalImageFormat.Astc2D6x6: return 6; - case GalImageFormat.Astc2D8x8: return 8; - case GalImageFormat.Astc2D10x10: return 10; - case GalImageFormat.Astc2D12x12: return 12; - case GalImageFormat.Astc2D5x4: return 5; - case GalImageFormat.Astc2D6x5: return 6; - case GalImageFormat.Astc2D8x6: return 8; - case GalImageFormat.Astc2D10x8: return 10; - case GalImageFormat.Astc2D12x10: return 12; - case GalImageFormat.Astc2D8x5: return 8; - case GalImageFormat.Astc2D10x5: return 10; - case GalImageFormat.Astc2D10x6: return 10; + 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; } throw new ArgumentException(nameof(Format)); @@ -146,20 +153,20 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.Astc2D4x4: return 4; - case GalImageFormat.Astc2D5x5: return 5; - case GalImageFormat.Astc2D6x6: return 6; - case GalImageFormat.Astc2D8x8: return 8; - case GalImageFormat.Astc2D10x10: return 10; - case GalImageFormat.Astc2D12x12: return 12; - case GalImageFormat.Astc2D5x4: return 4; - case GalImageFormat.Astc2D6x5: return 5; - case GalImageFormat.Astc2D8x6: return 6; - case GalImageFormat.Astc2D10x8: return 8; - case GalImageFormat.Astc2D12x10: return 10; - case GalImageFormat.Astc2D8x5: return 5; - case GalImageFormat.Astc2D10x5: return 5; - case GalImageFormat.Astc2D10x6: return 6; + 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; } throw new ArgumentException(nameof(Format)); @@ -221,14 +228,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL { switch (Format) { - case GalImageFormat.BC6H_UF16: - case GalImageFormat.BC6H_SF16: - case GalImageFormat.BC7U: - case GalImageFormat.BC1: - case GalImageFormat.BC2: - case GalImageFormat.BC3: - case GalImageFormat.BC4: - case GalImageFormat.BC5: + 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: return true; } diff --git a/Ryujinx.Graphics/Gal/OpenGL/TCE.cs b/Ryujinx.Graphics/Gal/OpenGL/TCE.cs index 5f7cff8fc9..ea130e086b 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/TCE.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/TCE.cs @@ -89,6 +89,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL const int Level = 0; const int Border = 0; + GL.GetError(); + GL.TexImage2D( TextureTarget.Texture2D, Level, @@ -100,6 +102,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL PixelType, IntPtr.Zero); + if (GL.GetError() != ErrorCode.NoError) + { + throw new InvalidOperationException($"{InternalFormat} {PixelFormat} {PixelType}"); + } + if (Initialized) { GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); diff --git a/Ryujinx.HLE/Gpu/Texture/TextureFactory.cs b/Ryujinx.HLE/Gpu/Texture/TextureFactory.cs index a9fa6dbd1e..0ef33d3b72 100644 --- a/Ryujinx.HLE/Gpu/Texture/TextureFactory.cs +++ b/Ryujinx.HLE/Gpu/Texture/TextureFactory.cs @@ -10,7 +10,12 @@ namespace Ryujinx.HLE.Gpu.Texture { int[] Tic = ReadWords(Vmm, TicPosition, 8); - GalImageFormat Format = ImageFormatConverter.ConvertTexture((GalTextureFormat)(Tic[0] & 0x7f)); + GalTextureType RType = (GalTextureType)((Tic[0] >> 7) & 7); + GalTextureType GType = (GalTextureType)((Tic[0] >> 10) & 7); + GalTextureType BType = (GalTextureType)((Tic[0] >> 13) & 7); + GalTextureType AType = (GalTextureType)((Tic[0] >> 16) & 7); + + GalImageFormat Format = ImageFormatConverter.ConvertTexture((GalTextureFormat)(Tic[0] & 0x7f), RType, GType, BType, AType); GalTextureSource XSource = (GalTextureSource)((Tic[0] >> 19) & 7); GalTextureSource YSource = (GalTextureSource)((Tic[0] >> 22) & 7); diff --git a/Ryujinx.HLE/Gpu/Texture/TextureHelper.cs b/Ryujinx.HLE/Gpu/Texture/TextureHelper.cs index bcfe4a7e25..c3501cc2eb 100644 --- a/Ryujinx.HLE/Gpu/Texture/TextureHelper.cs +++ b/Ryujinx.HLE/Gpu/Texture/TextureHelper.cs @@ -34,109 +34,140 @@ namespace Ryujinx.HLE.Gpu.Texture { switch (Image.Format) { - case GalImageFormat.R32G32B32A32: + case GalImageFormat.R32G32B32A32_SFLOAT: + case GalImageFormat.R32G32B32A32_SINT: + case GalImageFormat.R32G32B32A32_UINT: return Image.Width * Image.Height * 16; - case GalImageFormat.R16G16B16A16: + case GalImageFormat.R16G16B16A16_SFLOAT: + case GalImageFormat.R16G16B16A16_SINT: + case GalImageFormat.R16G16B16A16_SNORM: + case GalImageFormat.R16G16B16A16_UINT: + case GalImageFormat.R16G16B16A16_UNORM: return Image.Width * Image.Height * 8; - case GalImageFormat.A8B8G8R8: - case GalImageFormat.A2B10G10R10: - case GalImageFormat.G16R16: - case GalImageFormat.R32: - case GalImageFormat.ZF32: - case GalImageFormat.BF10GF11RF11: - case GalImageFormat.Z24S8: + 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: return Image.Width * Image.Height * 4; - case GalImageFormat.A1B5G5R5: - case GalImageFormat.B5G6R5: - case GalImageFormat.G8R8: - case GalImageFormat.R16: - case GalImageFormat.Z16: + 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: return Image.Width * Image.Height * 2; - case GalImageFormat.R8: + case GalImageFormat.R8_SINT: + case GalImageFormat.R8_SNORM: + case GalImageFormat.R8_UINT: + case GalImageFormat.R8_UNORM: return Image.Width * Image.Height; - case GalImageFormat.BC1: - case GalImageFormat.BC4: + case GalImageFormat.BC1_RGBA_UNORM_BLOCK: + case GalImageFormat.BC4_SNORM_BLOCK: + case GalImageFormat.BC4_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 4, 4, 8); } - case GalImageFormat.BC6H_SF16: - case GalImageFormat.BC6H_UF16: - case GalImageFormat.BC7U: - case GalImageFormat.BC2: - case GalImageFormat.BC3: - case GalImageFormat.BC5: - case GalImageFormat.Astc2D4x4: + 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: { return CompressedTextureSize(Image.Width, Image.Height, 4, 4, 16); } - case GalImageFormat.Astc2D5x5: + case GalImageFormat.ASTC_5x5_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 5, 5, 16); } - case GalImageFormat.Astc2D6x6: + case GalImageFormat.ASTC_6x6_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 6, 6, 16); } - case GalImageFormat.Astc2D8x8: + case GalImageFormat.ASTC_8x8_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 8, 8, 16); } - case GalImageFormat.Astc2D10x10: + case GalImageFormat.ASTC_10x10_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 10, 10, 16); } - case GalImageFormat.Astc2D12x12: + case GalImageFormat.ASTC_12x12_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 12, 12, 16); } - case GalImageFormat.Astc2D5x4: + case GalImageFormat.ASTC_5x4_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 5, 4, 16); } - case GalImageFormat.Astc2D6x5: + case GalImageFormat.ASTC_6x5_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 6, 5, 16); } - case GalImageFormat.Astc2D8x6: + case GalImageFormat.ASTC_8x6_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 8, 6, 16); } - case GalImageFormat.Astc2D10x8: + case GalImageFormat.ASTC_10x8_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 10, 8, 16); } - case GalImageFormat.Astc2D12x10: + case GalImageFormat.ASTC_12x10_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 12, 10, 16); } - case GalImageFormat.Astc2D8x5: + case GalImageFormat.ASTC_8x5_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 8, 5, 16); } - case GalImageFormat.Astc2D10x5: + case GalImageFormat.ASTC_10x5_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 10, 5, 16); } - case GalImageFormat.Astc2D10x6: + case GalImageFormat.ASTC_10x6_UNORM_BLOCK: { return CompressedTextureSize(Image.Width, Image.Height, 10, 6, 16); }