diff --git a/Ryujinx.Graphics/Gal/GalImageFormat.cs b/Ryujinx.Graphics/Gal/GalImageFormat.cs index 94c45bb803..ba555684f2 100644 --- a/Ryujinx.Graphics/Gal/GalImageFormat.cs +++ b/Ryujinx.Graphics/Gal/GalImageFormat.cs @@ -37,6 +37,7 @@ namespace Ryujinx.Graphics.Gal R4G4, R4G4B4A4, B4G4R4A4, + A4B4G4R4, R5G6B5, B5G6R5, R5G5B5A1, @@ -44,6 +45,7 @@ namespace Ryujinx.Graphics.Gal A1R5G5B5, R8, R8G8, + G8R8, R8G8B8, B8G8R8, R8G8B8A8, @@ -87,11 +89,5 @@ namespace Ryujinx.Graphics.Gal ETC2_R8G8B8A8, EAC_R11, EAC_R11G11, - - REVERSED_BEGIN, - - R4G4B4A4_REVERSED = REVERSED_BEGIN, - - REVERSED_END } } \ No newline at end of file diff --git a/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs b/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs index 56ddf820ac..e0ed7e5440 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/ImageHandler.cs @@ -58,7 +58,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL int CurrentSize = Math.Max(ImageTable.GetImageSize(NewImage), ImageTable.GetImageSize(Image)); - GL.BindBuffer(BufferTarget.PixelPackBuffer, CopyBuffer); + GL.BindBuffer(BufferTarget.PixelPackBuffer, CopyBuffer); GL.BindBuffer(BufferTarget.PixelUnpackBuffer, CopyBuffer); if (CopyBufferSize < CurrentSize) @@ -113,8 +113,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL } } - public bool HasColor { get => ImageTable.HasColor(Image); } - public bool HasDepth { get => ImageTable.HasDepth(Image); } - public bool HasStencil { get => ImageTable.HasStencil(Image); } + public bool HasColor => ImageTable.HasColor(Image.Format); + public bool HasDepth => ImageTable.HasDepth(Image.Format); + public bool HasStencil => ImageTable.HasStencil(Image.Format); } } diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs index 7f2c631fdf..1d4f4cf777 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLEnumConverter.cs @@ -143,6 +143,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL 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.A4B4G4R4 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed); 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); @@ -169,8 +170,6 @@ namespace Ryujinx.Graphics.Gal.OpenGL 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_REVERSED | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed); - 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); diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs index ad3ab2a945..e87c35755e 100644 --- a/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs +++ b/Ryujinx.Graphics/Gal/OpenGL/OGLTexture.cs @@ -57,6 +57,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL { GalImageFormat TypeLess = Image.Format & GalImageFormat.FormatMask; + //TODO: Use KHR_texture_compression_astc_hdr when available if (TypeLess >= GalImageFormat.ASTC_BEGIN && TypeLess <= GalImageFormat.ASTC_END) { int TextureBlockWidth = GetAstcBlockWidth(Image.Format); @@ -71,6 +72,16 @@ namespace Ryujinx.Graphics.Gal.OpenGL Image.Format = GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm; } + else if (TypeLess == GalImageFormat.G8R8) + { + Data = ImageConverter.G8R8ToR8G8( + Data, + Image.Width, + Image.Height, + 1); + + Image.Format = GalImageFormat.R8G8 | (Image.Format & GalImageFormat.FormatMask); + } (PixelInternalFormat InternalFormat, PixelFormat Format, PixelType Type) = OGLEnumConverter.GetImageFormat(Image.Format); diff --git a/Ryujinx.Graphics/NvGpuEngine2d.cs b/Ryujinx.Graphics/NvGpuEngine2d.cs index 77a03694ee..f26b00204b 100644 --- a/Ryujinx.Graphics/NvGpuEngine2d.cs +++ b/Ryujinx.Graphics/NvGpuEngine2d.cs @@ -103,7 +103,7 @@ namespace Ryujinx.Graphics SrcPitch, SrcBlockHeight, 1, SrcSwizzle, - GalTextureFormat.A8B8G8R8); + GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm); } TextureInfo DstTexture() @@ -115,7 +115,7 @@ namespace Ryujinx.Graphics DstPitch, DstBlockHeight, 1, DstSwizzle, - GalTextureFormat.A8B8G8R8); + GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm); } //TODO: fb -> fb copies, tex -> fb copies, formats other than RGBA8, diff --git a/Ryujinx.Graphics/Texture/ImageConverter.cs b/Ryujinx.Graphics/Texture/ImageConverter.cs new file mode 100644 index 0000000000..89529061fd --- /dev/null +++ b/Ryujinx.Graphics/Texture/ImageConverter.cs @@ -0,0 +1,24 @@ +namespace Ryujinx.Graphics.Texture +{ + static class ImageConverter + { + public static byte[] G8R8ToR8G8( + byte[] Data, + int Width, + int Height, + int Depth) + { + int Texels = Width * Height * Depth; + + byte[] Output = new byte[Texels * 2]; + + for (int Texel = 0; Texel < Texels; Texel++) + { + Output[Texel * 2 + 0] = Data[Texel * 2 + 1]; + Output[Texel * 2 + 1] = Data[Texel * 2 + 0]; + } + + return Output; + } + } +} \ No newline at end of file diff --git a/Ryujinx.Graphics/Texture/ImageTable.cs b/Ryujinx.Graphics/Texture/ImageTable.cs index dece1aeca3..880a99ada6 100644 --- a/Ryujinx.Graphics/Texture/ImageTable.cs +++ b/Ryujinx.Graphics/Texture/ImageTable.cs @@ -8,17 +8,21 @@ namespace Ryujinx.Graphics.Texture { struct ImageDescriptor { + public TextureReaderDelegate Reader; + public bool HasColor; public bool HasDepth; public bool HasStencil; public ImageDescriptor( - bool HasColor, - bool HasDepth, - bool HasStencil) + TextureReaderDelegate Reader, + bool HasColor, + bool HasDepth, + bool HasStencil) { - this.HasColor = HasColor; - this.HasDepth = HasDepth; + this.Reader = Reader; + this.HasColor = HasColor; + this.HasDepth = HasDepth; this.HasStencil = HasStencil; } } @@ -29,97 +33,96 @@ namespace Ryujinx.Graphics.Texture private const GalImageFormat Uint = GalImageFormat.Uint; private const GalImageFormat Sfloat = GalImageFormat.Sfloat; - private static readonly Dictionary s_TextureTable = - new Dictionary() + private static readonly Dictionary s_TextureTable = + new Dictionary() { - { 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 ) }, + { GalTextureFormat.R32G32B32A32, GalImageFormat.R32G32B32A32 | Sint | Uint | Sfloat }, + { GalTextureFormat.R16G16B16A16, GalImageFormat.R16G16B16A16 | Snorm | Unorm | Sint | Uint | Sfloat }, + { GalTextureFormat.R32G32, GalImageFormat.R32G32 | Sint | Uint | Sfloat }, + { GalTextureFormat.A8B8G8R8, GalImageFormat.A8B8G8R8 | Snorm | Unorm | Sint | Uint }, + { GalTextureFormat.A2B10G10R10, GalImageFormat.A2B10G10R10 | Snorm | Unorm | Sint | Uint }, + { GalTextureFormat.G8R8, GalImageFormat.G8R8 | Snorm | Unorm | Sint | Uint }, + { GalTextureFormat.R16, GalImageFormat.R16 | Snorm | Unorm | Sint | Uint | Sfloat }, + { GalTextureFormat.R8, GalImageFormat.R8 | Snorm | Unorm | Sint | Uint }, + { GalTextureFormat.R32, GalImageFormat.R32 | Sint | Uint | Sfloat }, + { GalTextureFormat.A4B4G4R4, GalImageFormat.A4B4G4R4 | Unorm }, + { GalTextureFormat.A1B5G5R5, GalImageFormat.A1R5G5B5 | Unorm }, + { GalTextureFormat.B5G6R5, GalImageFormat.B5G6R5 | Unorm }, + { GalTextureFormat.BF10GF11RF11, GalImageFormat.B10G11R11 | Sfloat }, + { GalTextureFormat.Z24S8, GalImageFormat.D24_S8 | Unorm }, + { GalTextureFormat.ZF32, GalImageFormat.D32 | Sfloat }, + { GalTextureFormat.ZF32_X24S8, GalImageFormat.D32_S8 | Unorm }, //Compressed formats - { 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 ) } + { GalTextureFormat.BC6H_SF16, GalImageFormat.BC6H_SF16 | Unorm }, + { GalTextureFormat.BC6H_UF16, GalImageFormat.BC6H_UF16 | Unorm }, + { GalTextureFormat.BC7U, GalImageFormat.BC7 | Unorm }, + { GalTextureFormat.BC1, GalImageFormat.BC1_RGBA | Unorm }, + { GalTextureFormat.BC2, GalImageFormat.BC2 | Unorm }, + { GalTextureFormat.BC3, GalImageFormat.BC3 | Unorm }, + { GalTextureFormat.BC4, GalImageFormat.BC4 | Unorm | Snorm }, + { GalTextureFormat.BC5, GalImageFormat.BC5 | Unorm | Snorm }, + { GalTextureFormat.Astc2D4x4, GalImageFormat.ASTC_4x4 | Unorm }, + { GalTextureFormat.Astc2D5x5, GalImageFormat.ASTC_5x5 | Unorm }, + { GalTextureFormat.Astc2D6x6, GalImageFormat.ASTC_6x6 | Unorm }, + { GalTextureFormat.Astc2D8x8, GalImageFormat.ASTC_8x8 | Unorm }, + { GalTextureFormat.Astc2D10x10, GalImageFormat.ASTC_10x10 | Unorm }, + { GalTextureFormat.Astc2D12x12, GalImageFormat.ASTC_12x12 | Unorm }, + { GalTextureFormat.Astc2D5x4, GalImageFormat.ASTC_5x4 | Unorm }, + { GalTextureFormat.Astc2D6x5, GalImageFormat.ASTC_6x5 | Unorm }, + { GalTextureFormat.Astc2D8x6, GalImageFormat.ASTC_8x6 | Unorm }, + { GalTextureFormat.Astc2D10x8, GalImageFormat.ASTC_10x8 | Unorm }, + { GalTextureFormat.Astc2D12x10, GalImageFormat.ASTC_12x10 | Unorm }, + { GalTextureFormat.Astc2D8x5, GalImageFormat.ASTC_8x5 | Unorm }, + { GalTextureFormat.Astc2D10x5, GalImageFormat.ASTC_10x5 | Unorm }, + { GalTextureFormat.Astc2D10x6, GalImageFormat.ASTC_10x6 | Unorm } }; private static readonly Dictionary s_ImageTable = new Dictionary() { - { 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.R32G32B32A32, new ImageDescriptor(TextureReader.Read16Bpp, true, false, false) }, + { GalImageFormat.R16G16B16A16, new ImageDescriptor(TextureReader.Read8Bpp, true, false, false) }, + { GalImageFormat.R32G32, new ImageDescriptor(TextureReader.Read8Bpp, true, false, false) }, + { GalImageFormat.A8B8G8R8, new ImageDescriptor(TextureReader.Read4Bpp, true, false, false) }, + { GalImageFormat.A2B10G10R10, new ImageDescriptor(TextureReader.Read4Bpp, true, false, false) }, + { GalImageFormat.R32, new ImageDescriptor(TextureReader.Read4Bpp, true, false, false) }, + { GalImageFormat.A4B4G4R4, new ImageDescriptor(TextureReader.Read2Bpp, true, false, false) }, + { GalImageFormat.BC6H_SF16, new ImageDescriptor(TextureReader.Read16BptCompressedTexture4x4, true, false, false) }, + { GalImageFormat.BC6H_UF16, new ImageDescriptor(TextureReader.Read16BptCompressedTexture4x4, true, false, false) }, + { GalImageFormat.A1R5G5B5, new ImageDescriptor(TextureReader.Read5551, true, false, false) }, + { GalImageFormat.B5G6R5, new ImageDescriptor(TextureReader.Read565, true, false, false) }, + { GalImageFormat.BC7, new ImageDescriptor(TextureReader.Read16BptCompressedTexture4x4, true, false, false) }, + { GalImageFormat.R16G16, new ImageDescriptor(TextureReader.Read4Bpp, true, false, false) }, + { GalImageFormat.R8G8, new ImageDescriptor(TextureReader.Read2Bpp, true, false, false) }, + { GalImageFormat.G8R8, new ImageDescriptor(TextureReader.Read2Bpp, true, false, false) }, + { GalImageFormat.R16, new ImageDescriptor(TextureReader.Read2Bpp, true, false, false) }, + { GalImageFormat.R8, new ImageDescriptor(TextureReader.Read1Bpp, true, false, false) }, + { GalImageFormat.B10G11R11, new ImageDescriptor(TextureReader.Read4Bpp, true, false, false) }, + { GalImageFormat.BC1_RGBA, new ImageDescriptor(TextureReader.Read8Bpt4x4, true, false, false) }, + { GalImageFormat.BC2, new ImageDescriptor(TextureReader.Read16BptCompressedTexture4x4, true, false, false) }, + { GalImageFormat.BC3, new ImageDescriptor(TextureReader.Read16BptCompressedTexture4x4, true, false, false) }, + { GalImageFormat.BC4, new ImageDescriptor(TextureReader.Read8Bpt4x4, true, false, false) }, + { GalImageFormat.BC5, new ImageDescriptor(TextureReader.Read16BptCompressedTexture4x4, true, false, false) }, + { GalImageFormat.ASTC_4x4, new ImageDescriptor(TextureReader.Read16BptCompressedTexture4x4, true, false, false) }, + { GalImageFormat.ASTC_5x5, new ImageDescriptor(TextureReader.Read16BptCompressedTexture5x5, true, false, false) }, + { GalImageFormat.ASTC_6x6, new ImageDescriptor(TextureReader.Read16BptCompressedTexture6x6, true, false, false) }, + { GalImageFormat.ASTC_8x8, new ImageDescriptor(TextureReader.Read16BptCompressedTexture8x8, true, false, false) }, + { GalImageFormat.ASTC_10x10, new ImageDescriptor(TextureReader.Read16BptCompressedTexture10x10, true, false, false) }, + { GalImageFormat.ASTC_12x12, new ImageDescriptor(TextureReader.Read16BptCompressedTexture12x12, true, false, false) }, + { GalImageFormat.ASTC_5x4, new ImageDescriptor(TextureReader.Read16BptCompressedTexture5x4, true, false, false) }, + { GalImageFormat.ASTC_6x5, new ImageDescriptor(TextureReader.Read16BptCompressedTexture6x5, true, false, false) }, + { GalImageFormat.ASTC_8x6, new ImageDescriptor(TextureReader.Read16BptCompressedTexture8x6, true, false, false) }, + { GalImageFormat.ASTC_10x8, new ImageDescriptor(TextureReader.Read16BptCompressedTexture10x8, true, false, false) }, + { GalImageFormat.ASTC_12x10, new ImageDescriptor(TextureReader.Read16BptCompressedTexture12x10, true, false, false) }, + { GalImageFormat.ASTC_8x5, new ImageDescriptor(TextureReader.Read16BptCompressedTexture8x5, true, false, false) }, + { GalImageFormat.ASTC_10x5, new ImageDescriptor(TextureReader.Read16BptCompressedTexture10x5, true, false, false) }, + { GalImageFormat.ASTC_10x6, new ImageDescriptor(TextureReader.Read16BptCompressedTexture10x6, true, false, false) }, - { 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_REVERSED, new ImageDescriptor(true, false, false) } + { GalImageFormat.D24_S8, new ImageDescriptor(TextureReader.Read4Bpp, false, true, true) }, + { GalImageFormat.D32, new ImageDescriptor(TextureReader.Read4Bpp, false, true, false) }, + { GalImageFormat.D16, new ImageDescriptor(TextureReader.Read2Bpp, false, true, false) }, + { GalImageFormat.D32_S8, new ImageDescriptor(TextureReader.Read8Bpp, false, true, true) }, }; public static GalImageFormat ConvertTexture( @@ -134,9 +137,12 @@ namespace Ryujinx.Graphics.Texture throw new NotImplementedException("Per component types are not implemented"); } - GalTextureType Type = RType; + if (!s_TextureTable.TryGetValue(Format, out GalImageFormat ImageFormat)) + { + throw new NotImplementedException("Texture with format " + ((int)Format).ToString("x2") + " not implemented"); + } - GalImageFormat ImageFormat = GetTextureDescriptor(Format).Format; + GalTextureType Type = RType; GalImageFormat FormatType = GetFormatType(RType); @@ -193,6 +199,11 @@ namespace Ryujinx.Graphics.Texture throw new NotImplementedException(Format.ToString()); } + public static TextureReaderDelegate GetReader(GalImageFormat Format) + { + return GetImageDescriptor(Format).Reader; + } + public static int GetImageSize(GalImage Image) { switch (Image.Format & GalImageFormat.FormatMask) @@ -284,29 +295,19 @@ namespace Ryujinx.Graphics.Texture throw new NotImplementedException((Image.Format & GalImageFormat.FormatMask).ToString()); } - public static bool HasColor(GalImage Image) + public static bool HasColor(GalImageFormat Format) { - return GetImageDescriptor(Image.Format).HasColor; + return GetImageDescriptor(Format).HasColor; } - public static bool HasDepth(GalImage Image) + public static bool HasDepth(GalImageFormat Format) { - return GetImageDescriptor(Image.Format).HasDepth; + return GetImageDescriptor(Format).HasDepth; } - public static bool HasStencil(GalImage Image) + public static bool HasStencil(GalImageFormat Format) { - return GetImageDescriptor(Image.Format).HasStencil; - } - - public static TextureDescriptor GetTextureDescriptor(GalTextureFormat Format) - { - if (s_TextureTable.TryGetValue(Format, out TextureDescriptor Descriptor)) - { - return Descriptor; - } - - throw new NotImplementedException("Texture with format code " + ((int)Format).ToString("x2") + " not implemented"); + return GetImageDescriptor(Format).HasStencil; } private static ImageDescriptor GetImageDescriptor(GalImageFormat Format) diff --git a/Ryujinx.Graphics/Texture/TextureDescriptor.cs b/Ryujinx.Graphics/Texture/TextureDescriptor.cs deleted file mode 100644 index 7c4a1291f7..0000000000 --- a/Ryujinx.Graphics/Texture/TextureDescriptor.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Ryujinx.Graphics.Gal; - -namespace Ryujinx.Graphics.Texture -{ - struct TextureDescriptor - { - public TextureReaderDelegate Reader; - - public GalImageFormat Format; - - public TextureDescriptor( - TextureReaderDelegate Reader, - GalImageFormat Format) - { - this.Reader = Reader; - this.Format = Format; - } - } -} \ No newline at end of file diff --git a/Ryujinx.Graphics/Texture/TextureFactory.cs b/Ryujinx.Graphics/Texture/TextureFactory.cs index c5b22d348a..824687ccc5 100644 --- a/Ryujinx.Graphics/Texture/TextureFactory.cs +++ b/Ryujinx.Graphics/Texture/TextureFactory.cs @@ -10,12 +10,7 @@ namespace Ryujinx.Graphics.Texture { int[] Tic = ReadWords(Vmm, TicPosition, 8); - 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 = ImageTable.ConvertTexture((GalTextureFormat)(Tic[0] & 0x7f), RType, GType, BType, AType); + GalImageFormat Format = GetImageFormat(Tic); GalTextureSource XSource = (GalTextureSource)((Tic[0] >> 19) & 7); GalTextureSource YSource = (GalTextureSource)((Tic[0] >> 22) & 7); @@ -39,7 +34,7 @@ namespace Ryujinx.Graphics.Texture { int[] Tic = ReadWords(Vmm, TicPosition, 8); - GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f); + GalImageFormat Format = GetImageFormat(Tic); long TextureAddress = (uint)Tic[1]; @@ -110,6 +105,18 @@ namespace Ryujinx.Graphics.Texture BorderColor); } + private static GalImageFormat GetImageFormat(int[] Tic) + { + 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); + + GalTextureFormat Format = (GalTextureFormat)(Tic[0] & 0x7f); + + return ImageTable.ConvertTexture(Format, RType, GType, BType, AType); + } + private static int[] ReadWords(NvGpuVmm Vmm, long Position, int Count) { int[] Words = new int[Count]; diff --git a/Ryujinx.Graphics/Texture/TextureInfo.cs b/Ryujinx.Graphics/Texture/TextureInfo.cs index 3c591eed82..66445dcce7 100644 --- a/Ryujinx.Graphics/Texture/TextureInfo.cs +++ b/Ryujinx.Graphics/Texture/TextureInfo.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Texture public TextureSwizzle Swizzle { get; private set; } - public GalTextureFormat Format { get; private set; } + public GalImageFormat Format { get; private set; } public TextureInfo( long Position, @@ -34,7 +34,7 @@ namespace Ryujinx.Graphics.Texture Swizzle = TextureSwizzle.BlockLinear; - Format = GalTextureFormat.A8B8G8R8; + Format = GalImageFormat.A8B8G8R8 | GalImageFormat.Unorm; } public TextureInfo( @@ -45,7 +45,7 @@ namespace Ryujinx.Graphics.Texture int BlockHeight, int TileWidth, TextureSwizzle Swizzle, - GalTextureFormat Format) + GalImageFormat Format) { this.Position = Position; this.Width = Width; diff --git a/Ryujinx.Graphics/Texture/TextureReader.cs b/Ryujinx.Graphics/Texture/TextureReader.cs index 86a9bc0a89..d38e27cb64 100644 --- a/Ryujinx.Graphics/Texture/TextureReader.cs +++ b/Ryujinx.Graphics/Texture/TextureReader.cs @@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Texture { public static byte[] Read(IAMemory Memory, TextureInfo Texture) { - TextureReaderDelegate Reader = ImageTable.GetTextureDescriptor(Texture.Format).Reader; + TextureReaderDelegate Reader = ImageTable.GetReader(Texture.Format); return Reader(Memory, Texture); }