Move GPU emulation from Ryujinx.HLE to Ryujinx.Graphics and misc changes (#402)

* Move GPU LLE emulation from HLE to Graphics

* Graphics: Move Gal/Texture to Texture

* Remove Engines/ directory and namespace

* Use tables for image formats

* Abstract OpCode decoding

* Simplify image table

* Do not leak Read* symbols in TextureReader

* Fixups

* Rename IGalFrameBuffer -> IGalRenderTarget

* Remove MaxBpp hardcoded value

* Change yet again texture data and add G8R8 flipping

* Rename GalFrameBufferFormat to GalSurfaceFormat

* Unident EnsureSetup in ImageHandler

* Add IsCompressed

* Address some feedback
This commit is contained in:
ReinUsesLisp 2018-09-08 14:51:50 -03:00 committed by gdkchan
parent a0c78f7920
commit ce1d5be212
58 changed files with 3378 additions and 3448 deletions

View file

@ -1,5 +1,5 @@
using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.Gal.Texture;
using Ryujinx.Graphics.Texture;
using System;
namespace Ryujinx.Graphics.Gal.OpenGL
@ -39,7 +39,11 @@ namespace Ryujinx.Graphics.Gal.OpenGL
const int Level = 0; //TODO: Support mipmap textures.
const int Border = 0;
if (IsCompressedTextureFormat(Image.Format))
GalImageFormat TypeLess = Image.Format & GalImageFormat.FormatMask;
bool IsASTC = TypeLess >= GalImageFormat.ASTC_BEGIN && TypeLess <= GalImageFormat.ASTC_END;
if (ImageUtils.IsCompressed(Image.Format) && !IsASTC)
{
InternalFormat InternalFmt = OGLEnumConverter.GetCompressedImageFormat(Image.Format);
@ -55,7 +59,8 @@ namespace Ryujinx.Graphics.Gal.OpenGL
}
else
{
if (Image.Format >= GalImageFormat.ASTC_BEGIN && Image.Format <= GalImageFormat.ASTC_END)
//TODO: Use KHR_texture_compression_astc_hdr when available
if (IsASTC)
{
int TextureBlockWidth = GetAstcBlockWidth(Image.Format);
int TextureBlockHeight = GetAstcBlockHeight(Image.Format);
@ -67,7 +72,17 @@ namespace Ryujinx.Graphics.Gal.OpenGL
Image.Width,
Image.Height, 1);
Image.Format = GalImageFormat.A8B8G8R8_UNORM_PACK32;
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);
@ -123,20 +138,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 +161,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));
@ -216,25 +231,5 @@ namespace Ryujinx.Graphics.Gal.OpenGL
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureBorderColor, Color);
}
private static bool IsCompressedTextureFormat(GalImageFormat Format)
{
switch (Format)
{
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;
}
return false;
}
}
}