Some improvements for nvnflinger (#555)

* Initial fixes for last release of libnx

For now, the framebuffer aren't okay but it will not crash/

* Improve code reaadability in NvFlinger parsing

* Make surfaces access more userfriendly

* Add ColorFormat

* Fix code style in ColorFormat.cs

* Add multiple framebuffer support in nvnflinger

This fix libnx console rendering

* Move ReadStruct/WriteStruct to Ryujinx.Common

* fix the last nit

* Fix inverted color for R5G6B5

Also add some other format that libnx might uses.

* Remove hardcoded BlockHeight in nvflinger
This commit is contained in:
Thomas Guillemard 2019-01-05 22:26:16 +01:00 committed by Ac_K
parent 290f5e812e
commit b4d91402c6
9 changed files with 693 additions and 84 deletions

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace Ryujinx.Common
{
public static class StructIOExtension
{
public unsafe static T ReadStruct<T>(this BinaryReader reader) where T : struct
{
int size = Marshal.SizeOf<T>();
byte[] data = reader.ReadBytes(size);
fixed (byte* ptr = data)
{
return Marshal.PtrToStructure<T>((IntPtr)ptr);
}
}
public unsafe static void WriteStruct<T>(this BinaryWriter writer, T value) where T : struct
{
long size = Marshal.SizeOf<T>();
byte[] data = new byte[size];
fixed (byte* ptr = data)
{
Marshal.StructureToPtr<T>(value, (IntPtr)ptr, false);
}
writer.Write(data);
}
}
}

View File

@ -24,6 +24,7 @@ namespace Ryujinx.Graphics.Gal
RGBA4,
RGB565,
BGR565,
BGR5A1,
RGB5A1,
R8,

View File

@ -157,6 +157,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
case GalImageFormat.BGR5A1 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551);
case GalImageFormat.RGB5A1 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort1555Reversed);
case GalImageFormat.RGB565 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565Reversed);
case GalImageFormat.BGR565 | GalImageFormat.Unorm: return (PixelInternalFormat.Rgba, PixelFormat.Rgb, PixelType.UnsignedShort565);
case GalImageFormat.RG16 | GalImageFormat.Float: return (PixelInternalFormat.Rg16f, PixelFormat.Rg, PixelType.HalfFloat);
case GalImageFormat.RG16 | GalImageFormat.Sint: return (PixelInternalFormat.Rg16i, PixelFormat.RgInteger, PixelType.Short);
case GalImageFormat.RG16 | GalImageFormat.Snorm: return (PixelInternalFormat.Rg16Snorm, PixelFormat.Rg, PixelType.Short);

View File

@ -106,6 +106,7 @@ namespace Ryujinx.Graphics.Texture
{ GalImageFormat.BGR5A1, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) },
{ GalImageFormat.RGB5A1, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) },
{ GalImageFormat.RGB565, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) },
{ GalImageFormat.BGR565, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) },
{ GalImageFormat.BptcUnorm, new ImageDescriptor(16, 4, 4, TargetBuffer.Color) },
{ GalImageFormat.RG16, new ImageDescriptor(4, 1, 1, TargetBuffer.Color) },
{ GalImageFormat.RG8, new ImageDescriptor(2, 1, 1, TargetBuffer.Color) },

View File

@ -0,0 +1,366 @@
namespace Ryujinx.HLE.HOS.Services.Android
{
class ColorShift
{
public const int Swizzle = 16;
public const int DataType = 14;
// FIXME: check this one
public const int Space = 32;
public const int Component = 8;
}
enum ColorSwizzle
{
XYZW = 0x688 << ColorShift.Swizzle,
ZYXW = 0x60a << ColorShift.Swizzle,
WZYX = 0x053 << ColorShift.Swizzle,
YZWX = 0x0d1 << ColorShift.Swizzle,
XYZ1 = 0xa88 << ColorShift.Swizzle,
YZW1 = 0xad1 << ColorShift.Swizzle,
XXX1 = 0xa00 << ColorShift.Swizzle,
XZY1 = 0xa50 << ColorShift.Swizzle,
ZYX1 = 0xa0a << ColorShift.Swizzle,
WZY1 = 0xa53 << ColorShift.Swizzle,
X000 = 0x920 << ColorShift.Swizzle,
Y000 = 0x921 << ColorShift.Swizzle,
XY01 = 0xb08 << ColorShift.Swizzle,
X001 = 0xb20 << ColorShift.Swizzle,
X00X = 0x121 << ColorShift.Swizzle,
X00Y = 0x320 << ColorShift.Swizzle,
_0YX0 = 0x80c << ColorShift.Swizzle,
_0ZY0 = 0x814 << ColorShift.Swizzle,
_0XZ0 = 0x884 << ColorShift.Swizzle,
_0X00 = 0x904 << ColorShift.Swizzle,
_00X0 = 0x824 << ColorShift.Swizzle,
_000X = 0x124 << ColorShift.Swizzle,
_0XY0 = 0x844 << ColorShift.Swizzle,
XXXY = 0x200 << ColorShift.Swizzle,
YYYX = 0x049 << ColorShift.Swizzle
}
enum ColorBytePerPixel
{
Bpp1 = 1,
Bpp2 = 2,
Bpp4 = 4,
Bpp8 = 8,
Bpp16 = 16,
Bpp24 = 24,
Bpp32 = 32,
Bpp48 = 48,
Bpp64 = 64,
Bpp96 = 96,
Bpp128 = 128
}
enum ColorComponent : uint
{
X1 = (0x01 << ColorShift.Component) | ColorBytePerPixel.Bpp1,
X2 = (0x02 << ColorShift.Component) | ColorBytePerPixel.Bpp2,
X4 = (0x03 << ColorShift.Component) | ColorBytePerPixel.Bpp4,
X8 = (0x04 << ColorShift.Component) | ColorBytePerPixel.Bpp8,
Y4X4 = (0x05 << ColorShift.Component) | ColorBytePerPixel.Bpp8,
X3Y3Z2 = (0x06 << ColorShift.Component) | ColorBytePerPixel.Bpp8,
X8Y8 = (0x07 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X8Y8X8Z8 = (0x08 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
Y8X8Z8X8 = (0x09 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X16 = (0x0A << ColorShift.Component) | ColorBytePerPixel.Bpp16,
Y2X14 = (0x0B << ColorShift.Component) | ColorBytePerPixel.Bpp16,
Y4X12 = (0x0C << ColorShift.Component) | ColorBytePerPixel.Bpp16,
Y6X10 = (0x0D << ColorShift.Component) | ColorBytePerPixel.Bpp16,
Y8X8 = (0x0E << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X10 = (0x0F << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X12 = (0x10 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
Z5Y5X6 = (0x11 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X5Y6Z5 = (0x12 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X6Y5Z5 = (0x13 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X1Y5Z5W5 = (0x14 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X4Y4Z4W4 = (0x15 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X5Y1Z5W5 = (0x16 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X5Y5Z1W5 = (0x17 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X5Y5Z5W1 = (0x18 << ColorShift.Component) | ColorBytePerPixel.Bpp16,
X8Y8Z8 = (0x19 << ColorShift.Component) | ColorBytePerPixel.Bpp24,
X24 = (0x1A << ColorShift.Component) | ColorBytePerPixel.Bpp24,
X32 = (0x1C << ColorShift.Component) | ColorBytePerPixel.Bpp32,
X16Y16 = (0x1D << ColorShift.Component) | ColorBytePerPixel.Bpp32,
X11Y11Z10 = (0x1E << ColorShift.Component) | ColorBytePerPixel.Bpp32,
X2Y10Z10W10 = (0x20 << ColorShift.Component) | ColorBytePerPixel.Bpp32,
X8Y8Z8W8 = (0x21 << ColorShift.Component) | ColorBytePerPixel.Bpp32,
Y10X10 = (0x22 << ColorShift.Component) | ColorBytePerPixel.Bpp32,
X10Y10Z10W2 = (0x23 << ColorShift.Component) | ColorBytePerPixel.Bpp32,
Y12X12 = (0x24 << ColorShift.Component) | ColorBytePerPixel.Bpp32,
X20Y20Z20 = (0x26 << ColorShift.Component) | ColorBytePerPixel.Bpp64,
X16Y16Z16W16 = (0x27 << ColorShift.Component) | ColorBytePerPixel.Bpp64,
}
enum ColorDataType
{
Integer = 0x0 << ColorShift.DataType,
Float = 0x1 << ColorShift.DataType,
Stencil = 0x2 << ColorShift.DataType
}
enum ColorSpace : ulong
{
NonColor = 0x0L << ColorShift.Space,
LinearRGBA = 0x1L << ColorShift.Space,
SRGB = 0x2L << ColorShift.Space,
Unknown3 = 0x3L << ColorShift.Space,
Unknown4 = 0x4L << ColorShift.Space,
Unknown5 = 0x5L << ColorShift.Space,
Unknown6 = 0x6L << ColorShift.Space,
Unknown7 = 0x7L << ColorShift.Space,
Unknown8 = 0x8L << ColorShift.Space,
ColorIndex = 0x9L << ColorShift.Space,
YCbCr601 = 0xAL << ColorShift.Space,
YCbCr601_RR = 0xBL << ColorShift.Space,
UnknownC = 0xCL << ColorShift.Space,
YCbCr709 = 0xDL << ColorShift.Space,
UnknownE = 0xEL << ColorShift.Space,
BayerRGGB = 0x10L << ColorShift.Space,
BayerBGGR = 0x11L << ColorShift.Space,
BayerGRBG = 0x12L << ColorShift.Space,
BayerGBRG = 0x13L << ColorShift.Space,
Unknown14 = 0x14L << ColorShift.Space,
}
enum ColorFormat : ulong
{
NonColor8 = ColorSpace.NonColor | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
NonColor16 = ColorSpace.NonColor | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Integer,
NonColor24 = ColorSpace.NonColor | ColorSwizzle.X000 | ColorComponent.X24 | ColorDataType.Integer,
NonColor32 = ColorSpace.NonColor | ColorSwizzle.X000 | ColorComponent.X32 | ColorDataType.Integer,
X4C4 = ColorSpace.NonColor | ColorSwizzle.Y000 | ColorComponent.Y4X4 | ColorDataType.Integer,
A4L4 = ColorSpace.LinearRGBA | ColorSwizzle.YYYX | ColorComponent.Y4X4 | ColorDataType.Integer,
A8L8 = ColorSpace.LinearRGBA | ColorSwizzle.YYYX | ColorComponent.Y8X8 | ColorDataType.Integer,
Float_A16L16 = ColorSpace.LinearRGBA | ColorSwizzle.YYYX | ColorComponent.X16Y16 | ColorDataType.Float,
A1B5G5R5 = ColorSpace.LinearRGBA | ColorSwizzle.WZYX | ColorComponent.X1Y5Z5W5 | ColorDataType.Integer,
A4B4G4R4 = ColorSpace.LinearRGBA | ColorSwizzle.WZYX | ColorComponent.X4Y4Z4W4 | ColorDataType.Integer,
A5B5G5R1 = ColorSpace.LinearRGBA | ColorSwizzle.WZYX | ColorComponent.X5Y5Z5W1 | ColorDataType.Integer,
A2B10G10R10 = ColorSpace.LinearRGBA | ColorSwizzle.WZYX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
A8B8G8R8 = ColorSpace.LinearRGBA | ColorSwizzle.WZYX | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
A16B16G16R16 = ColorSpace.LinearRGBA | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
Float_A16B16G16R16 = ColorSpace.LinearRGBA | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Float,
A1R5G5B5 = ColorSpace.LinearRGBA | ColorSwizzle.YZWX | ColorComponent.X1Y5Z5W5 | ColorDataType.Integer,
A4R4G4B4 = ColorSpace.LinearRGBA | ColorSwizzle.YZWX | ColorComponent.X4Y4Z4W4 | ColorDataType.Integer,
A5R1G5B5 = ColorSpace.LinearRGBA | ColorSwizzle.YZWX | ColorComponent.X5Y1Z5W5 | ColorDataType.Integer,
A2R10G10B10 = ColorSpace.LinearRGBA | ColorSwizzle.YZWX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
A8R8G8B8 = ColorSpace.LinearRGBA | ColorSwizzle.YZWX | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
A1 = ColorSpace.LinearRGBA | ColorSwizzle._000X | ColorComponent.X1 | ColorDataType.Integer,
A2 = ColorSpace.LinearRGBA | ColorSwizzle._000X | ColorComponent.X2 | ColorDataType.Integer,
A4 = ColorSpace.LinearRGBA | ColorSwizzle._000X | ColorComponent.X4 | ColorDataType.Integer,
A8 = ColorSpace.LinearRGBA | ColorSwizzle._000X | ColorComponent.X8 | ColorDataType.Integer,
A16 = ColorSpace.LinearRGBA | ColorSwizzle._000X | ColorComponent.X16 | ColorDataType.Integer,
A32 = ColorSpace.LinearRGBA | ColorSwizzle._000X | ColorComponent.X32 | ColorDataType.Integer,
Float_A16 = ColorSpace.LinearRGBA | ColorSwizzle._000X | ColorComponent.X16 | ColorDataType.Float,
L4A4 = ColorSpace.LinearRGBA | ColorSwizzle.XXXY | ColorComponent.Y4X4 | ColorDataType.Integer,
L8A8 = ColorSpace.LinearRGBA | ColorSwizzle.XXXY | ColorComponent.Y8X8 | ColorDataType.Integer,
B4G4R4A4 = ColorSpace.LinearRGBA | ColorSwizzle.ZYXW | ColorComponent.X4Y4Z4W4 | ColorDataType.Integer,
B5G5R1A5 = ColorSpace.LinearRGBA | ColorSwizzle.ZYXW | ColorComponent.X5Y5Z1W5 | ColorDataType.Integer,
B5G5R5A1 = ColorSpace.LinearRGBA | ColorSwizzle.ZYXW | ColorComponent.X5Y5Z5W1 | ColorDataType.Integer,
B8G8R8A8 = ColorSpace.LinearRGBA | ColorSwizzle.ZYXW | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
B10G10R10A2 = ColorSpace.LinearRGBA | ColorSwizzle.ZYXW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
R1G5B5A5 = ColorSpace.LinearRGBA | ColorSwizzle.XYZW | ColorComponent.X1Y5Z5W5 | ColorDataType.Integer,
R4G4B4A4 = ColorSpace.LinearRGBA | ColorSwizzle.XYZW | ColorComponent.X4Y4Z4W4 | ColorDataType.Integer,
R5G5B5A1 = ColorSpace.LinearRGBA | ColorSwizzle.XYZW | ColorComponent.X5Y5Z5W1 | ColorDataType.Integer,
R8G8B8A8 = ColorSpace.LinearRGBA | ColorSwizzle.XYZW | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
R10G10B10A2 = ColorSpace.LinearRGBA | ColorSwizzle.XYZW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
L1 = ColorSpace.LinearRGBA | ColorSwizzle.XXX1 | ColorComponent.X1 | ColorDataType.Integer,
L2 = ColorSpace.LinearRGBA | ColorSwizzle.XXX1 | ColorComponent.X2 | ColorDataType.Integer,
L4 = ColorSpace.LinearRGBA | ColorSwizzle.XXX1 | ColorComponent.X4 | ColorDataType.Integer,
L8 = ColorSpace.LinearRGBA | ColorSwizzle.XXX1 | ColorComponent.X8 | ColorDataType.Integer,
L16 = ColorSpace.LinearRGBA | ColorSwizzle.XXX1 | ColorComponent.X16 | ColorDataType.Integer,
L32 = ColorSpace.LinearRGBA | ColorSwizzle.XXX1 | ColorComponent.X32 | ColorDataType.Integer,
Float_L16 = ColorSpace.LinearRGBA | ColorSwizzle.XXX1 | ColorComponent.X16 | ColorDataType.Float,
B5G6R5 = ColorSpace.LinearRGBA | ColorSwizzle.ZYX1 | ColorComponent.X5Y6Z5 | ColorDataType.Integer,
B6G5R5 = ColorSpace.LinearRGBA | ColorSwizzle.ZYX1 | ColorComponent.X6Y5Z5 | ColorDataType.Integer,
B5G5R5X1 = ColorSpace.LinearRGBA | ColorSwizzle.ZYX1 | ColorComponent.X5Y5Z5W1 | ColorDataType.Integer,
B8_G8_R8 = ColorSpace.LinearRGBA | ColorSwizzle.ZYX1 | ColorComponent.X8Y8Z8 | ColorDataType.Integer,
B8G8R8X8 = ColorSpace.LinearRGBA | ColorSwizzle.ZYX1 | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
Float_B10G11R11 = ColorSpace.LinearRGBA | ColorSwizzle.ZYX1 | ColorComponent.X11Y11Z10 | ColorDataType.Float,
X1B5G5R5 = ColorSpace.LinearRGBA | ColorSwizzle.WZY1 | ColorComponent.X1Y5Z5W5 | ColorDataType.Integer,
X8B8G8R8 = ColorSpace.LinearRGBA | ColorSwizzle.WZY1 | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
X16B16G16R16 = ColorSpace.LinearRGBA | ColorSwizzle.WZY1 | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
Float_X16B16G16R16 = ColorSpace.LinearRGBA | ColorSwizzle.WZY1 | ColorComponent.X16Y16Z16W16 | ColorDataType.Float,
R3G3B2 = ColorSpace.LinearRGBA | ColorSwizzle.XYZ1 | ColorComponent.X3Y3Z2 | ColorDataType.Integer,
R5G5B6 = ColorSpace.LinearRGBA | ColorSwizzle.XYZ1 | ColorComponent.Z5Y5X6 | ColorDataType.Integer,
R5G6B5 = ColorSpace.LinearRGBA | ColorSwizzle.XYZ1 | ColorComponent.X5Y6Z5 | ColorDataType.Integer,
R5G5B5X1 = ColorSpace.LinearRGBA | ColorSwizzle.XYZ1 | ColorComponent.X5Y5Z5W1 | ColorDataType.Integer,
R8_G8_B8 = ColorSpace.LinearRGBA | ColorSwizzle.XYZ1 | ColorComponent.X8Y8Z8 | ColorDataType.Integer,
R8G8B8X8 = ColorSpace.LinearRGBA | ColorSwizzle.XYZ1 | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
X1R5G5B5 = ColorSpace.LinearRGBA | ColorSwizzle.YZW1 | ColorComponent.X1Y5Z5W5 | ColorDataType.Integer,
X8R8G8B8 = ColorSpace.LinearRGBA | ColorSwizzle.YZW1 | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
RG8 = ColorSpace.LinearRGBA | ColorSwizzle.XY01 | ColorComponent.Y8X8 | ColorDataType.Integer,
R16G16 = ColorSpace.LinearRGBA | ColorSwizzle.XY01 | ColorComponent.X16Y16 | ColorDataType.Integer,
Float_R16G16 = ColorSpace.LinearRGBA | ColorSwizzle.XY01 | ColorComponent.X16Y16 | ColorDataType.Float,
R8 = ColorSpace.LinearRGBA | ColorSwizzle.X001 | ColorComponent.X8 | ColorDataType.Integer,
R16 = ColorSpace.LinearRGBA | ColorSwizzle.X001 | ColorComponent.X16 | ColorDataType.Integer,
Float_R16 = ColorSpace.LinearRGBA | ColorSwizzle.X001 | ColorComponent.X16 | ColorDataType.Float,
A2B10G10R10_sRGB = ColorSpace.SRGB | ColorSwizzle.WZYX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
A8B8G8R8_sRGB = ColorSpace.SRGB | ColorSwizzle.WZYX | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
A16B16G16R16_sRGB = ColorSpace.SRGB | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
A2R10G10B10_sRGB = ColorSpace.SRGB | ColorSwizzle.YZWX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
B10G10R10A2_sRGB = ColorSpace.SRGB | ColorSwizzle.ZYXW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
R10G10B10A2_sRGB = ColorSpace.SRGB | ColorSwizzle.XYZW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
X8B8G8R8_sRGB = ColorSpace.SRGB | ColorSwizzle.WZY1 | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
X16B16G16R16_sRGB = ColorSpace.SRGB | ColorSwizzle.WZY1 | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
A2B10G10R10_709 = ColorSpace.Unknown3 | ColorSwizzle.WZYX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
A8B8G8R8_709 = ColorSpace.Unknown3 | ColorSwizzle.WZYX | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
A16B16G16R16_709 = ColorSpace.Unknown3 | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
A2R10G10B10_709 = ColorSpace.Unknown3 | ColorSwizzle.YZWX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
B10G10R10A2_709 = ColorSpace.Unknown3 | ColorSwizzle.ZYXW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
R10G10B10A2_709 = ColorSpace.Unknown3 | ColorSwizzle.XYZW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
X8B8G8R8_709 = ColorSpace.Unknown3 | ColorSwizzle.WZY1 | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
X16B16G16R16_709 = ColorSpace.Unknown3 | ColorSwizzle.WZY1 | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
A2B10G10R10_709_Linear = ColorSpace.Unknown4 | ColorSwizzle.WZYX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
A8B8G8R8_709_Linear = ColorSpace.Unknown4 | ColorSwizzle.WZYX | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
A16B16G16R16_709_Linear = ColorSpace.Unknown4 | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
A2R10G10B10_709_Linear = ColorSpace.Unknown4 | ColorSwizzle.YZWX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
B10G10R10A2_709_Linear = ColorSpace.Unknown4 | ColorSwizzle.ZYXW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
R10G10B10A2_709_Linear = ColorSpace.Unknown4 | ColorSwizzle.XYZW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
X8B8G8R8_709_Linear = ColorSpace.Unknown4 | ColorSwizzle.WZY1 | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
X16B16G16R16_709_Linear = ColorSpace.Unknown4 | ColorSwizzle.WZY1 | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
Float_A16B16G16R16_scRGB_Linear = ColorSpace.Unknown5 | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Float,
A2B10G10R10_2020 = ColorSpace.Unknown6 | ColorSwizzle.WZYX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
A8B8G8R8_2020 = ColorSpace.Unknown6 | ColorSwizzle.WZYX | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
A16B16G16R16_2020 = ColorSpace.Unknown6 | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
A2R10G10B10_2020 = ColorSpace.Unknown6 | ColorSwizzle.YZWX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
B10G10R10A2_2020 = ColorSpace.Unknown6 | ColorSwizzle.ZYXW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
R10G10B10A2_2020 = ColorSpace.Unknown6 | ColorSwizzle.XYZW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
X8B8G8R8_2020 = ColorSpace.Unknown6 | ColorSwizzle.WZY1 | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
X16B16G16R16_2020 = ColorSpace.Unknown6 | ColorSwizzle.WZY1 | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
A2B10G10R10_2020_Linear = ColorSpace.Unknown7 | ColorSwizzle.WZYX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
A8B8G8R8_2020_Linear = ColorSpace.Unknown7 | ColorSwizzle.WZYX | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
A16B16G16R16_2020_Linear = ColorSpace.Unknown7 | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
Float_A16B16G16R16_2020_Linear = ColorSpace.Unknown7 | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Float,
A2R10G10B10_2020_Linear = ColorSpace.Unknown7 | ColorSwizzle.YZWX | ColorComponent.X2Y10Z10W10 | ColorDataType.Integer,
B10G10R10A2_2020_Linear = ColorSpace.Unknown7 | ColorSwizzle.ZYXW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
R10G10B10A2_2020_Linear = ColorSpace.Unknown7 | ColorSwizzle.XYZW | ColorComponent.X10Y10Z10W2 | ColorDataType.Integer,
X8B8G8R8_2020_Linear = ColorSpace.Unknown7 | ColorSwizzle.WZY1 | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
X16B16G16R16_2020_Linear = ColorSpace.Unknown7 | ColorSwizzle.WZY1 | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
Float_A16B16G16R16_2020_PQ = ColorSpace.Unknown8 | ColorSwizzle.WZYX | ColorComponent.X16Y16Z16W16 | ColorDataType.Float,
A4I4 = ColorSpace.ColorIndex | ColorSwizzle.X00X | ColorComponent.Y4X4 | ColorDataType.Integer,
A8I8 = ColorSpace.ColorIndex | ColorSwizzle.X00X | ColorComponent.Y8X8 | ColorDataType.Integer,
I4A4 = ColorSpace.ColorIndex | ColorSwizzle.X00Y | ColorComponent.Y4X4 | ColorDataType.Integer,
I8A8 = ColorSpace.ColorIndex | ColorSwizzle.X00Y | ColorComponent.Y8X8 | ColorDataType.Integer,
I1 = ColorSpace.ColorIndex | ColorSwizzle.X000 | ColorComponent.X1 | ColorDataType.Integer,
I2 = ColorSpace.ColorIndex | ColorSwizzle.X000 | ColorComponent.X2 | ColorDataType.Integer,
I4 = ColorSpace.ColorIndex | ColorSwizzle.X000 | ColorComponent.X4 | ColorDataType.Integer,
I8 = ColorSpace.ColorIndex | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
A8Y8U8V8 = ColorSpace.YCbCr601 | ColorSwizzle.YZWX | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
A16Y16U16V16 = ColorSpace.YCbCr601 | ColorSwizzle.YZWX | ColorComponent.X16Y16Z16W16 | ColorDataType.Integer,
Y8U8V8A8 = ColorSpace.YCbCr601 | ColorSwizzle.XYZW | ColorComponent.X8Y8Z8W8 | ColorDataType.Integer,
V8_U8 = ColorSpace.YCbCr601 | ColorSwizzle._0YX0 | ColorComponent.X8Y8 | ColorDataType.Integer,
V8U8 = ColorSpace.YCbCr601 | ColorSwizzle._0YX0 | ColorComponent.Y8X8 | ColorDataType.Integer,
V10U10 = ColorSpace.YCbCr601 | ColorSwizzle._0ZY0 | ColorComponent.Y10X10 | ColorDataType.Integer,
V12U12 = ColorSpace.YCbCr601 | ColorSwizzle._0ZY0 | ColorComponent.Y12X12 | ColorDataType.Integer,
V8 = ColorSpace.YCbCr601 | ColorSwizzle._00X0 | ColorComponent.X8 | ColorDataType.Integer,
V10 = ColorSpace.YCbCr601 | ColorSwizzle._00X0 | ColorComponent.X10 | ColorDataType.Integer,
V12 = ColorSpace.YCbCr601 | ColorSwizzle._00X0 | ColorComponent.X12 | ColorDataType.Integer,
U8_V8 = ColorSpace.YCbCr601 | ColorSwizzle._0XY0 | ColorComponent.X8Y8 | ColorDataType.Integer,
U8V8 = ColorSpace.YCbCr601 | ColorSwizzle._0XY0 | ColorComponent.Y8X8 | ColorDataType.Integer,
U10V10 = ColorSpace.YCbCr601 | ColorSwizzle._0XZ0 | ColorComponent.Y10X10 | ColorDataType.Integer,
U12V12 = ColorSpace.YCbCr601 | ColorSwizzle._0XZ0 | ColorComponent.Y12X12 | ColorDataType.Integer,
U8 = ColorSpace.YCbCr601 | ColorSwizzle._0X00 | ColorComponent.X8 | ColorDataType.Integer,
U10 = ColorSpace.YCbCr601 | ColorSwizzle._0X00 | ColorComponent.X10 | ColorDataType.Integer,
U12 = ColorSpace.YCbCr601 | ColorSwizzle._0X00 | ColorComponent.X12 | ColorDataType.Integer,
Y8 = ColorSpace.YCbCr601 | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
Y10 = ColorSpace.YCbCr601 | ColorSwizzle.X000 | ColorComponent.X10 | ColorDataType.Integer,
Y12 = ColorSpace.YCbCr601 | ColorSwizzle.X000 | ColorComponent.X12 | ColorDataType.Integer,
YVYU = ColorSpace.YCbCr601 | ColorSwizzle.XZY1 | ColorComponent.X8Y8X8Z8 | ColorDataType.Integer,
VYUY = ColorSpace.YCbCr601 | ColorSwizzle.XZY1 | ColorComponent.Y8X8Z8X8 | ColorDataType.Integer,
UYVY = ColorSpace.YCbCr601 | ColorSwizzle.XYZ1 | ColorComponent.Y8X8Z8X8 | ColorDataType.Integer,
YUYV = ColorSpace.YCbCr601 | ColorSwizzle.XYZ1 | ColorComponent.X8Y8X8Z8 | ColorDataType.Integer,
Y8_U8_V8 = ColorSpace.YCbCr601 | ColorSwizzle.XYZ1 | ColorComponent.X8Y8Z8 | ColorDataType.Integer,
V8_U8_RR = ColorSpace.YCbCr601_RR | ColorSwizzle._0YX0 | ColorComponent.X8Y8 | ColorDataType.Integer,
V8U8_RR = ColorSpace.YCbCr601_RR | ColorSwizzle._0YX0 | ColorComponent.Y8X8 | ColorDataType.Integer,
V8_RR = ColorSpace.YCbCr601_RR | ColorSwizzle._00X0 | ColorComponent.X8 | ColorDataType.Integer,
U8_V8_RR = ColorSpace.YCbCr601_RR | ColorSwizzle._0XY0 | ColorComponent.X8Y8 | ColorDataType.Integer,
U8V8_RR = ColorSpace.YCbCr601_RR | ColorSwizzle._0XY0 | ColorComponent.Y8X8 | ColorDataType.Integer,
U8_RR = ColorSpace.YCbCr601_RR | ColorSwizzle._0X00 | ColorComponent.X8 | ColorDataType.Integer,
Y8_RR = ColorSpace.YCbCr601_RR | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
V8_U8_ER = ColorSpace.UnknownC | ColorSwizzle._0YX0 | ColorComponent.X8Y8 | ColorDataType.Integer,
V8U8_ER = ColorSpace.UnknownC | ColorSwizzle._0YX0 | ColorComponent.Y8X8 | ColorDataType.Integer,
V8_ER = ColorSpace.UnknownC | ColorSwizzle._00X0 | ColorComponent.X8 | ColorDataType.Integer,
U8_V8_ER = ColorSpace.UnknownC | ColorSwizzle._0XY0 | ColorComponent.X8Y8 | ColorDataType.Integer,
U8V8_ER = ColorSpace.UnknownC | ColorSwizzle._0XY0 | ColorComponent.Y8X8 | ColorDataType.Integer,
U8_ER = ColorSpace.UnknownC | ColorSwizzle._0X00 | ColorComponent.X8 | ColorDataType.Integer,
Y8_ER = ColorSpace.UnknownC | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
V8_U8_709 = ColorSpace.YCbCr709 | ColorSwizzle._0YX0 | ColorComponent.X8Y8 | ColorDataType.Integer,
V8U8_709 = ColorSpace.YCbCr709 | ColorSwizzle._0YX0 | ColorComponent.Y8X8 | ColorDataType.Integer,
V10U10_709 = ColorSpace.YCbCr709 | ColorSwizzle._0ZY0 | ColorComponent.Y10X10 | ColorDataType.Integer,
V12U12_709 = ColorSpace.YCbCr709 | ColorSwizzle._0ZY0 | ColorComponent.Y12X12 | ColorDataType.Integer,
V8_709 = ColorSpace.YCbCr709 | ColorSwizzle._00X0 | ColorComponent.X8 | ColorDataType.Integer,
V10_709 = ColorSpace.YCbCr709 | ColorSwizzle._00X0 | ColorComponent.X10 | ColorDataType.Integer,
V12_709 = ColorSpace.YCbCr709 | ColorSwizzle._00X0 | ColorComponent.X12 | ColorDataType.Integer,
U8_V8_709 = ColorSpace.YCbCr709 | ColorSwizzle._0XY0 | ColorComponent.X8Y8 | ColorDataType.Integer,
U8V8_709 = ColorSpace.YCbCr709 | ColorSwizzle._0XY0 | ColorComponent.Y8X8 | ColorDataType.Integer,
U10V10_709 = ColorSpace.YCbCr709 | ColorSwizzle._0XZ0 | ColorComponent.Y10X10 | ColorDataType.Integer,
U12V12_709 = ColorSpace.YCbCr709 | ColorSwizzle._0XZ0 | ColorComponent.Y12X12 | ColorDataType.Integer,
U8_709 = ColorSpace.YCbCr709 | ColorSwizzle._0X00 | ColorComponent.X8 | ColorDataType.Integer,
U10_709 = ColorSpace.YCbCr709 | ColorSwizzle._0X00 | ColorComponent.X10 | ColorDataType.Integer,
U12_709 = ColorSpace.YCbCr709 | ColorSwizzle._0X00 | ColorComponent.X12 | ColorDataType.Integer,
Y8_709 = ColorSpace.YCbCr709 | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
Y10_709 = ColorSpace.YCbCr709 | ColorSwizzle.X000 | ColorComponent.X10 | ColorDataType.Integer,
Y12_709 = ColorSpace.YCbCr709 | ColorSwizzle.X000 | ColorComponent.X12 | ColorDataType.Integer,
V8_U8_709_ER = ColorSpace.UnknownE | ColorSwizzle._0YX0 | ColorComponent.X8Y8 | ColorDataType.Integer,
V8U8_709_ER = ColorSpace.UnknownE | ColorSwizzle._0YX0 | ColorComponent.Y8X8 | ColorDataType.Integer,
V10U10_709_ER = ColorSpace.UnknownE | ColorSwizzle._0ZY0 | ColorComponent.Y10X10 | ColorDataType.Integer,
V12U12_709_ER = ColorSpace.UnknownE | ColorSwizzle._0ZY0 | ColorComponent.Y12X12 | ColorDataType.Integer,
V8_709_ER = ColorSpace.UnknownE | ColorSwizzle._00X0 | ColorComponent.X8 | ColorDataType.Integer,
V10_709_ER = ColorSpace.UnknownE | ColorSwizzle._00X0 | ColorComponent.X10 | ColorDataType.Integer,
V12_709_ER = ColorSpace.UnknownE | ColorSwizzle._00X0 | ColorComponent.X12 | ColorDataType.Integer,
U8_V8_709_ER = ColorSpace.UnknownE | ColorSwizzle._0XY0 | ColorComponent.X8Y8 | ColorDataType.Integer,
U8V8_709_ER = ColorSpace.UnknownE | ColorSwizzle._0XY0 | ColorComponent.Y8X8 | ColorDataType.Integer,
U10V10_709_ER = ColorSpace.UnknownE | ColorSwizzle._0XZ0 | ColorComponent.Y10X10 | ColorDataType.Integer,
U12V12_709_ER = ColorSpace.UnknownE | ColorSwizzle._0XZ0 | ColorComponent.Y12X12 | ColorDataType.Integer,
U8_709_ER = ColorSpace.UnknownE | ColorSwizzle._0X00 | ColorComponent.X8 | ColorDataType.Integer,
U10_709_ER = ColorSpace.UnknownE | ColorSwizzle._0X00 | ColorComponent.X10 | ColorDataType.Integer,
U12_709_ER = ColorSpace.UnknownE | ColorSwizzle._0X00 | ColorComponent.X12 | ColorDataType.Integer,
Y8_709_ER = ColorSpace.UnknownE | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
Y10_709_ER = ColorSpace.UnknownE | ColorSwizzle.X000 | ColorComponent.X10 | ColorDataType.Integer,
Y12_709_ER = ColorSpace.UnknownE | ColorSwizzle.X000 | ColorComponent.X12 | ColorDataType.Integer,
V10U10_2020 = ColorSpace.UnknownE | ColorSwizzle._0ZY0 | ColorComponent.Y10X10 | ColorDataType.Integer,
V12U12_2020 = ColorSpace.UnknownE | ColorSwizzle._0ZY0 | ColorComponent.Y12X12 | ColorDataType.Integer,
V10_2020 = ColorSpace.UnknownE | ColorSwizzle._00X0 | ColorComponent.X10 | ColorDataType.Integer,
V12_2020 = ColorSpace.UnknownE | ColorSwizzle._00X0 | ColorComponent.X12 | ColorDataType.Integer,
U10V10_2020 = ColorSpace.UnknownE | ColorSwizzle._0XZ0 | ColorComponent.Y10X10 | ColorDataType.Integer,
U12V12_2020 = ColorSpace.UnknownE | ColorSwizzle._0XZ0 | ColorComponent.Y12X12 | ColorDataType.Integer,
U10_2020 = ColorSpace.UnknownE | ColorSwizzle._0X00 | ColorComponent.X10 | ColorDataType.Integer,
U12_2020 = ColorSpace.UnknownE | ColorSwizzle._0X00 | ColorComponent.X12 | ColorDataType.Integer,
Y10_2020 = ColorSpace.UnknownE | ColorSwizzle.X000 | ColorComponent.X10 | ColorDataType.Integer,
Y12_2020 = ColorSpace.UnknownE | ColorSwizzle.X000 | ColorComponent.X12 | ColorDataType.Integer,
Bayer8RGGB = ColorSpace.BayerRGGB | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
Bayer16RGGB = ColorSpace.BayerRGGB | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Integer,
BayerS16RGGB = ColorSpace.BayerRGGB | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Stencil,
X2Bayer14RGGB = ColorSpace.BayerRGGB | ColorSwizzle.Y000 | ColorComponent.Y2X14 | ColorDataType.Integer,
X4Bayer12RGGB = ColorSpace.BayerRGGB | ColorSwizzle.Y000 | ColorComponent.Y4X12 | ColorDataType.Integer,
X6Bayer10RGGB = ColorSpace.BayerRGGB | ColorSwizzle.Y000 | ColorComponent.Y6X10 | ColorDataType.Integer,
Bayer8BGGR = ColorSpace.BayerBGGR | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
Bayer16BGGR = ColorSpace.BayerBGGR | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Integer,
BayerS16BGGR = ColorSpace.BayerBGGR | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Stencil,
X2Bayer14BGGR = ColorSpace.BayerBGGR | ColorSwizzle.Y000 | ColorComponent.Y2X14 | ColorDataType.Integer,
X4Bayer12BGGR = ColorSpace.BayerBGGR | ColorSwizzle.Y000 | ColorComponent.Y4X12 | ColorDataType.Integer,
X6Bayer10BGGR = ColorSpace.BayerBGGR | ColorSwizzle.Y000 | ColorComponent.Y6X10 | ColorDataType.Integer,
Bayer8GRBG = ColorSpace.BayerGRBG | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
Bayer16GRBG = ColorSpace.BayerGRBG | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Integer,
BayerS16GRBG = ColorSpace.BayerGRBG | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Stencil,
X2Bayer14GRBG = ColorSpace.BayerGRBG | ColorSwizzle.Y000 | ColorComponent.Y2X14 | ColorDataType.Integer,
X4Bayer12GRBG = ColorSpace.BayerGRBG | ColorSwizzle.Y000 | ColorComponent.Y4X12 | ColorDataType.Integer,
X6Bayer10GRBG = ColorSpace.BayerGRBG | ColorSwizzle.Y000 | ColorComponent.Y6X10 | ColorDataType.Integer,
Bayer8GBRG = ColorSpace.BayerGBRG | ColorSwizzle.X000 | ColorComponent.X8 | ColorDataType.Integer,
Bayer16GBRG = ColorSpace.BayerGBRG | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Integer,
BayerS16GBRG = ColorSpace.BayerGBRG | ColorSwizzle.X000 | ColorComponent.X16 | ColorDataType.Stencil,
X2Bayer14GBRG = ColorSpace.BayerGBRG | ColorSwizzle.Y000 | ColorComponent.Y2X14 | ColorDataType.Integer,
X4Bayer12GBRG = ColorSpace.BayerGBRG | ColorSwizzle.Y000 | ColorComponent.Y4X12 | ColorDataType.Integer,
X6Bayer10GBRG = ColorSpace.BayerGBRG | ColorSwizzle.Y000 | ColorComponent.Y6X10 | ColorDataType.Integer,
XYZ = ColorSpace.Unknown14 | ColorSwizzle.XYZ1 | ColorComponent.X20Y20Z20 | ColorDataType.Float,
}
}

View File

@ -1,60 +1,165 @@
using Ryujinx.Common;
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace Ryujinx.HLE.HOS.Services.Android
{
[StructLayout(LayoutKind.Sequential, Size = 0x28)]
struct GraphicBufferHeader
{
public int Magic;
public int Width;
public int Height;
public int Stride;
public int Format;
public int Usage;
public int Pid;
public int RefCount;
public int FdsCount;
public int IntsCount;
}
[StructLayout(LayoutKind.Explicit, Size = 0x58)]
struct NvGraphicBufferSurface
{
[FieldOffset(0)]
public uint Width;
[FieldOffset(0x4)]
public uint Height;
[FieldOffset(0x8)]
public ColorFormat ColorFormat;
[FieldOffset(0x10)]
public int Layout;
[FieldOffset(0x14)]
public int Pitch;
[FieldOffset(0x18)]
public int NvMapHandle;
[FieldOffset(0x1C)]
public int Offset;
[FieldOffset(0x20)]
public int Kind;
[FieldOffset(0x24)]
public int BlockHeightLog2;
[FieldOffset(0x28)]
public int ScanFormat;
[FieldOffset(0x30)]
public long Flags;
[FieldOffset(0x38)]
public long Size;
}
[StructLayout(LayoutKind.Explicit)]
struct NvGraphicBufferSurfaceArray
{
[FieldOffset(0x0)]
private NvGraphicBufferSurface Surface0;
[FieldOffset(0x58)]
private NvGraphicBufferSurface Surface1;
[FieldOffset(0xb0)]
private NvGraphicBufferSurface Surface2;
public NvGraphicBufferSurface this[int index]
{
get
{
if (index == 0)
{
return Surface0;
}
else if (index == 1)
{
return Surface1;
}
else if (index == 2)
{
return Surface2;
}
throw new IndexOutOfRangeException();
}
}
}
[StructLayout(LayoutKind.Explicit, Size = 0x144)]
struct NvGraphicBuffer
{
[FieldOffset(0x4)]
public int NvMapId;
[FieldOffset(0xC)]
public int Magic;
[FieldOffset(0x10)]
public int Pid;
[FieldOffset(0x14)]
public int Type;
[FieldOffset(0x18)]
public int Usage;
[FieldOffset(0x1C)]
public int PixelFormat;
[FieldOffset(0x20)]
public int ExternalPixelFormat;
[FieldOffset(0x24)]
public int Stride;
[FieldOffset(0x28)]
public int FrameBufferSize;
[FieldOffset(0x2C)]
public int PlanesCount;
[FieldOffset(0x34)]
public NvGraphicBufferSurfaceArray Surfaces;
}
struct GbpBuffer
{
public int Magic { get; private set; }
public int Width { get; private set; }
public int Height { get; private set; }
public int Stride { get; private set; }
public int Format { get; private set; }
public int Usage { get; private set; }
public GraphicBufferHeader Header { get; private set; }
public NvGraphicBuffer Buffer { get; private set; }
public int Pid { get; private set; }
public int RefCount { get; private set; }
public int FdsCount { get; private set; }
public int IntsCount { get; private set; }
public byte[] RawData { get; private set; }
public int Size => RawData.Length + 10 * 4;
public int Size => Marshal.SizeOf<NvGraphicBuffer>() + Marshal.SizeOf<GraphicBufferHeader>();
public GbpBuffer(BinaryReader reader)
{
Magic = reader.ReadInt32();
Width = reader.ReadInt32();
Height = reader.ReadInt32();
Stride = reader.ReadInt32();
Format = reader.ReadInt32();
Usage = reader.ReadInt32();
Header = reader.ReadStruct<GraphicBufferHeader>();
Pid = reader.ReadInt32();
RefCount = reader.ReadInt32();
// ignore fds
// TODO: check if that is used in official implementation
reader.BaseStream.Position += Header.FdsCount * 4;
FdsCount = reader.ReadInt32();
IntsCount = reader.ReadInt32();
if (Header.IntsCount != 0x51)
{
throw new System.NotImplementedException($"Unexpected Graphic Buffer ints count (expected 0x51, found 0x{Header.IntsCount:x}");
}
RawData = reader.ReadBytes((FdsCount + IntsCount) * 4);
Buffer = reader.ReadStruct<NvGraphicBuffer>();
}
public void Write(BinaryWriter writer)
{
writer.Write(Magic);
writer.Write(Width);
writer.Write(Height);
writer.Write(Stride);
writer.Write(Format);
writer.Write(Usage);
writer.Write(Pid);
writer.Write(RefCount);
writer.Write(FdsCount);
writer.Write(IntsCount);
writer.Write(RawData);
writer.WriteStruct(Header);
writer.WriteStruct(Buffer);
}
}
}

View File

@ -52,7 +52,7 @@ namespace Ryujinx.HLE.HOS.Services.Vi
public long GetSystemDisplayService(ServiceCtx context)
{
MakeObject(context, new ISystemDisplayService());
MakeObject(context, new ISystemDisplayService(this));
return 0;
}

View File

@ -10,13 +10,14 @@ namespace Ryujinx.HLE.HOS.Services.Vi
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
public ISystemDisplayService()
public ISystemDisplayService(IApplicationDisplayService applicationDisplayService)
{
_commands = new Dictionary<int, ServiceProcessRequest>
{
{ 2205, SetLayerZ },
{ 2207, SetLayerVisibility },
{ 3200, GetDisplayMode }
{ 2205, SetLayerZ },
{ 2207, SetLayerVisibility },
{ 2312, applicationDisplayService.CreateStrayLayer },
{ 3200, GetDisplayMode }
};
}

View File

@ -7,6 +7,7 @@ using Ryujinx.HLE.HOS.Services.Nv.NvMap;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
@ -30,9 +31,11 @@ namespace Ryujinx.HLE.HOS.Services.Android
[Flags]
private enum HalTransform
{
FlipX = 1 << 0,
FlipY = 1 << 1,
Rotate90 = 1 << 2
FlipX = 1,
FlipY = 2,
Rotate90 = 4,
Rotate180 = FlipX | FlipY,
Rotate270 = Rotate90 | Rotate180,
}
private enum BufferState
@ -43,6 +46,33 @@ namespace Ryujinx.HLE.HOS.Services.Android
Acquired
}
[StructLayout(LayoutKind.Sequential, Size = 0x8)]
private struct Fence
{
public int id;
public int value;
}
[StructLayout(LayoutKind.Explicit, Size = 0x24)]
private struct MultiFence
{
[FieldOffset(0x0)]
public int FenceCount;
[FieldOffset(0x4)]
public Fence Fence0;
[FieldOffset(0xC)]
public Fence Fence1;
[FieldOffset(0x14)]
public Fence Fence2;
[FieldOffset(0x1C)]
public Fence Fence3;
}
[StructLayout(LayoutKind.Sequential, Size = 0x10)]
private struct Rect
{
public int Top;
@ -51,6 +81,37 @@ namespace Ryujinx.HLE.HOS.Services.Android
public int Bottom;
}
[StructLayout(LayoutKind.Explicit)]
private struct QueueBufferObject
{
[FieldOffset(0x0)]
public long Timestamp;
[FieldOffset(0x8)]
public int IsAutoTimestamp;
[FieldOffset(0xC)]
public Rect Crop;
[FieldOffset(0x1C)]
public int ScalingMode;
[FieldOffset(0x20)]
public HalTransform Transform;
[FieldOffset(0x24)]
public int StickyTransform;
[FieldOffset(0x28)]
public int Unknown;
[FieldOffset(0x2C)]
public int SwapInterval;
[FieldOffset(0x30)]
public MultiFence Fence;
}
private struct BufferEntry
{
public BufferState State;
@ -169,32 +230,15 @@ namespace Ryujinx.HLE.HOS.Services.Android
//TODO: Errors.
int slot = parcelReader.ReadInt32();
int unknown4 = parcelReader.ReadInt32();
int unknown8 = parcelReader.ReadInt32();
int unknownC = parcelReader.ReadInt32();
int timestamp = parcelReader.ReadInt32();
int isAutoTimestamp = parcelReader.ReadInt32();
int cropTop = parcelReader.ReadInt32();
int cropLeft = parcelReader.ReadInt32();
int cropRight = parcelReader.ReadInt32();
int cropBottom = parcelReader.ReadInt32();
int scalingMode = parcelReader.ReadInt32();
int transform = parcelReader.ReadInt32();
int stickyTransform = parcelReader.ReadInt32();
int unknown34 = parcelReader.ReadInt32();
int unknown38 = parcelReader.ReadInt32();
int isFenceValid = parcelReader.ReadInt32();
int fence0Id = parcelReader.ReadInt32();
int fence0Value = parcelReader.ReadInt32();
int fence1Id = parcelReader.ReadInt32();
int fence1Value = parcelReader.ReadInt32();
_bufferQueue[slot].Transform = (HalTransform)transform;
long Position = parcelReader.BaseStream.Position;
_bufferQueue[slot].Crop.Top = cropTop;
_bufferQueue[slot].Crop.Left = cropLeft;
_bufferQueue[slot].Crop.Right = cropRight;
_bufferQueue[slot].Crop.Bottom = cropBottom;
QueueBufferObject queueBufferObject = ReadFlattenedObject<QueueBufferObject>(parcelReader);
parcelReader.BaseStream.Position = Position;
_bufferQueue[slot].Transform = queueBufferObject.Transform;
_bufferQueue[slot].Crop = queueBufferObject.Crop;
_bufferQueue[slot].State = BufferState.Queued;
@ -218,6 +262,8 @@ namespace Ryujinx.HLE.HOS.Services.Android
//TODO: Errors.
int slot = parcelReader.ReadInt32();
MultiFence fence = ReadFlattenedObject<MultiFence>(parcelReader);
_bufferQueue[slot].State = BufferState.Free;
_waitBufferFree.Set();
@ -244,20 +290,41 @@ namespace Ryujinx.HLE.HOS.Services.Android
{
int slot = parcelReader.ReadInt32();
int bufferCount = parcelReader.ReadInt32();
bool hasInput = parcelReader.ReadInt32() == 1;
if (bufferCount > 0)
if (hasInput)
{
long bufferSize = parcelReader.ReadInt64();
byte[] graphicBuffer = ReadFlattenedObject(parcelReader);
_bufferQueue[slot].State = BufferState.Free;
_bufferQueue[slot].Data = new GbpBuffer(parcelReader);
using (BinaryReader graphicBufferReader = new BinaryReader(new MemoryStream(graphicBuffer)))
{
_bufferQueue[slot].Data = new GbpBuffer(graphicBufferReader);
}
}
return MakeReplyParcel(context, 0);
}
private byte[] ReadFlattenedObject(BinaryReader reader)
{
long flattenedObjectSize = reader.ReadInt64();
return reader.ReadBytes((int)flattenedObjectSize);
}
private unsafe T ReadFlattenedObject<T>(BinaryReader reader) where T: struct
{
byte[] data = ReadFlattenedObject(reader);
fixed (byte* ptr = data)
{
return Marshal.PtrToStructure<T>((IntPtr)ptr);
}
}
private long MakeReplyParcel(ServiceCtx context, params int[] ints)
{
using (MemoryStream ms = new MemoryStream())
@ -284,13 +351,39 @@ namespace Ryujinx.HLE.HOS.Services.Android
return 0;
}
private GalImageFormat ConvertColorFormat(ColorFormat colorFormat)
{
switch (colorFormat)
{
case ColorFormat.A8B8G8R8:
return GalImageFormat.RGBA8 | GalImageFormat.Unorm;
case ColorFormat.X8B8G8R8:
return GalImageFormat.RGBX8 | GalImageFormat.Unorm;
case ColorFormat.R5G6B5:
return GalImageFormat.BGR565 | GalImageFormat.Unorm;
case ColorFormat.A8R8G8B8:
return GalImageFormat.BGRA8 | GalImageFormat.Unorm;
case ColorFormat.A4B4G4R4:
return GalImageFormat.RGBA4 | GalImageFormat.Unorm;
default:
throw new NotImplementedException($"Color Format \"{colorFormat}\" not implemented!");
}
}
// TODO: support multi surface
private void SendFrameBuffer(ServiceCtx context, int slot)
{
int fbWidth = _bufferQueue[slot].Data.Width;
int fbHeight = _bufferQueue[slot].Data.Height;
int fbWidth = _bufferQueue[slot].Data.Header.Width;
int fbHeight = _bufferQueue[slot].Data.Header.Height;
int nvMapHandle = BitConverter.ToInt32(_bufferQueue[slot].Data.RawData, 0x4c);
int bufferOffset = BitConverter.ToInt32(_bufferQueue[slot].Data.RawData, 0x50);
int nvMapHandle = _bufferQueue[slot].Data.Buffer.Surfaces[0].NvMapHandle;
if (nvMapHandle == 0)
{
nvMapHandle = _bufferQueue[slot].Data.Buffer.NvMapId;
}
int bufferOffset = _bufferQueue[slot].Data.Buffer.Surfaces[0].Offset;
NvMapHandle map = NvMapIoctl.GetNvMap(context, nvMapHandle);
@ -303,6 +396,10 @@ namespace Ryujinx.HLE.HOS.Services.Android
bool flipX = _bufferQueue[slot].Transform.HasFlag(HalTransform.FlipX);
bool flipY = _bufferQueue[slot].Transform.HasFlag(HalTransform.FlipY);
GalImageFormat imageFormat = ConvertColorFormat(_bufferQueue[slot].Data.Buffer.Surfaces[0].ColorFormat);
int BlockHeight = 1 << _bufferQueue[slot].Data.Buffer.Surfaces[0].BlockHeightLog2;
//Note: Rotation is being ignored.
int top = crop.Top;
@ -318,9 +415,9 @@ namespace Ryujinx.HLE.HOS.Services.Android
{
image = new GalImage(
fbWidth,
fbHeight, 1, 16,
fbHeight, 1, BlockHeight,
GalMemoryLayout.BlockLinear,
GalImageFormat.RGBA8 | GalImageFormat.Unorm);
imageFormat);
}
context.Device.Gpu.ResourceManager.ClearPbCache();
@ -378,8 +475,8 @@ namespace Ryujinx.HLE.HOS.Services.Android
GbpBuffer data = _bufferQueue[slot].Data;
if (data.Width == width &&
data.Height == height)
if (data.Header.Width == width &&
data.Header.Height == height)
{
_bufferQueue[slot].State = BufferState.Dequeued;