From 870988fcba8fce8201b66714e135e00342be7a22 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 8 May 2024 21:38:57 -0400 Subject: [PATCH 01/35] Migrate FormatTable --- src/Ryujinx.Graphics.OpenGL/FormatInfo.cs | 12 +- src/Ryujinx.Graphics.OpenGL/FormatTable.cs | 330 ++++++++++----------- 2 files changed, 171 insertions(+), 171 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/FormatInfo.cs b/src/Ryujinx.Graphics.OpenGL/FormatInfo.cs index c1a97e81a2..3cded38f93 100644 --- a/src/Ryujinx.Graphics.OpenGL/FormatInfo.cs +++ b/src/Ryujinx.Graphics.OpenGL/FormatInfo.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; namespace Ryujinx.Graphics.OpenGL { @@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.OpenGL public bool Normalized { get; } public bool Scaled { get; } - public PixelInternalFormat PixelInternalFormat { get; } + public InternalFormat InternalFormat { get; } public PixelFormat PixelFormat { get; } public PixelType PixelType { get; } @@ -18,25 +18,25 @@ namespace Ryujinx.Graphics.OpenGL int components, bool normalized, bool scaled, - All pixelInternalFormat, + InternalFormat internalFormat, PixelFormat pixelFormat, PixelType pixelType) { Components = components; Normalized = normalized; Scaled = scaled; - PixelInternalFormat = (PixelInternalFormat)pixelInternalFormat; + InternalFormat = internalFormat; PixelFormat = pixelFormat; PixelType = pixelType; IsCompressed = false; } - public FormatInfo(int components, bool normalized, bool scaled, All pixelFormat) + public FormatInfo(int components, bool normalized, bool scaled, InternalFormat pixelFormat) { Components = components; Normalized = normalized; Scaled = scaled; - PixelInternalFormat = 0; + InternalFormat = 0; PixelFormat = (PixelFormat)pixelFormat; PixelType = 0; IsCompressed = true; diff --git a/src/Ryujinx.Graphics.OpenGL/FormatTable.cs b/src/Ryujinx.Graphics.OpenGL/FormatTable.cs index 4cf4dc760f..ce2b63e67d 100644 --- a/src/Ryujinx.Graphics.OpenGL/FormatTable.cs +++ b/src/Ryujinx.Graphics.OpenGL/FormatTable.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; using System; @@ -17,192 +17,192 @@ namespace Ryujinx.Graphics.OpenGL _tableImage = new SizedInternalFormat[tableSize]; #pragma warning disable IDE0055 // Disable formatting - Add(Format.R8Unorm, new FormatInfo(1, true, false, All.R8, PixelFormat.Red, PixelType.UnsignedByte)); - Add(Format.R8Snorm, new FormatInfo(1, true, false, All.R8Snorm, PixelFormat.Red, PixelType.Byte)); - Add(Format.R8Uint, new FormatInfo(1, false, false, All.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte)); - Add(Format.R8Sint, new FormatInfo(1, false, false, All.R8i, PixelFormat.RedInteger, PixelType.Byte)); - Add(Format.R16Float, new FormatInfo(1, false, false, All.R16f, PixelFormat.Red, PixelType.HalfFloat)); - Add(Format.R16Unorm, new FormatInfo(1, true, false, All.R16, PixelFormat.Red, PixelType.UnsignedShort)); - Add(Format.R16Snorm, new FormatInfo(1, true, false, All.R16Snorm, PixelFormat.Red, PixelType.Short)); - Add(Format.R16Uint, new FormatInfo(1, false, false, All.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort)); - Add(Format.R16Sint, new FormatInfo(1, false, false, All.R16i, PixelFormat.RedInteger, PixelType.Short)); - Add(Format.R32Float, new FormatInfo(1, false, false, All.R32f, PixelFormat.Red, PixelType.Float)); - Add(Format.R32Uint, new FormatInfo(1, false, false, All.R32ui, PixelFormat.RedInteger, PixelType.UnsignedInt)); - Add(Format.R32Sint, new FormatInfo(1, false, false, All.R32i, PixelFormat.RedInteger, PixelType.Int)); - Add(Format.R8G8Unorm, new FormatInfo(2, true, false, All.Rg8, PixelFormat.Rg, PixelType.UnsignedByte)); - Add(Format.R8G8Snorm, new FormatInfo(2, true, false, All.Rg8Snorm, PixelFormat.Rg, PixelType.Byte)); - Add(Format.R8G8Uint, new FormatInfo(2, false, false, All.Rg8ui, PixelFormat.RgInteger, PixelType.UnsignedByte)); - Add(Format.R8G8Sint, new FormatInfo(2, false, false, All.Rg8i, PixelFormat.RgInteger, PixelType.Byte)); - Add(Format.R16G16Float, new FormatInfo(2, false, false, All.Rg16f, PixelFormat.Rg, PixelType.HalfFloat)); - Add(Format.R16G16Unorm, new FormatInfo(2, true, false, All.Rg16, PixelFormat.Rg, PixelType.UnsignedShort)); - Add(Format.R16G16Snorm, new FormatInfo(2, true, false, All.Rg16Snorm, PixelFormat.Rg, PixelType.Short)); - Add(Format.R16G16Uint, new FormatInfo(2, false, false, All.Rg16ui, PixelFormat.RgInteger, PixelType.UnsignedShort)); - Add(Format.R16G16Sint, new FormatInfo(2, false, false, All.Rg16i, PixelFormat.RgInteger, PixelType.Short)); - Add(Format.R32G32Float, new FormatInfo(2, false, false, All.Rg32f, PixelFormat.Rg, PixelType.Float)); - Add(Format.R32G32Uint, new FormatInfo(2, false, false, All.Rg32ui, PixelFormat.RgInteger, PixelType.UnsignedInt)); - Add(Format.R32G32Sint, new FormatInfo(2, false, false, All.Rg32i, PixelFormat.RgInteger, PixelType.Int)); - Add(Format.R8G8B8Unorm, new FormatInfo(3, true, false, All.Rgb8, PixelFormat.Rgb, PixelType.UnsignedByte)); - Add(Format.R8G8B8Snorm, new FormatInfo(3, true, false, All.Rgb8Snorm, PixelFormat.Rgb, PixelType.Byte)); - Add(Format.R8G8B8Uint, new FormatInfo(3, false, false, All.Rgb8ui, PixelFormat.RgbInteger, PixelType.UnsignedByte)); - Add(Format.R8G8B8Sint, new FormatInfo(3, false, false, All.Rgb8i, PixelFormat.RgbInteger, PixelType.Byte)); - Add(Format.R16G16B16Float, new FormatInfo(3, false, false, All.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat)); - Add(Format.R16G16B16Unorm, new FormatInfo(3, true, false, All.Rgb16, PixelFormat.Rgb, PixelType.UnsignedShort)); - Add(Format.R16G16B16Snorm, new FormatInfo(3, true, false, All.Rgb16Snorm, PixelFormat.Rgb, PixelType.Short)); - Add(Format.R16G16B16Uint, new FormatInfo(3, false, false, All.Rgb16ui, PixelFormat.RgbInteger, PixelType.UnsignedShort)); - Add(Format.R16G16B16Sint, new FormatInfo(3, false, false, All.Rgb16i, PixelFormat.RgbInteger, PixelType.Short)); - Add(Format.R32G32B32Float, new FormatInfo(3, false, false, All.Rgb32f, PixelFormat.Rgb, PixelType.Float)); - Add(Format.R32G32B32Uint, new FormatInfo(3, false, false, All.Rgb32ui, PixelFormat.RgbInteger, PixelType.UnsignedInt)); - Add(Format.R32G32B32Sint, new FormatInfo(3, false, false, All.Rgb32i, PixelFormat.RgbInteger, PixelType.Int)); - Add(Format.R8G8B8A8Unorm, new FormatInfo(4, true, false, All.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte)); - Add(Format.R8G8B8A8Snorm, new FormatInfo(4, true, false, All.Rgba8Snorm, PixelFormat.Rgba, PixelType.Byte)); - Add(Format.R8G8B8A8Uint, new FormatInfo(4, false, false, All.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte)); - Add(Format.R8G8B8A8Sint, new FormatInfo(4, false, false, All.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte)); - Add(Format.R16G16B16A16Float, new FormatInfo(4, false, false, All.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat)); - Add(Format.R16G16B16A16Unorm, new FormatInfo(4, true, false, All.Rgba16, PixelFormat.Rgba, PixelType.UnsignedShort)); - Add(Format.R16G16B16A16Snorm, new FormatInfo(4, true, false, All.Rgba16Snorm, PixelFormat.Rgba, PixelType.Short)); - Add(Format.R16G16B16A16Uint, new FormatInfo(4, false, false, All.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort)); - Add(Format.R16G16B16A16Sint, new FormatInfo(4, false, false, All.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short)); - Add(Format.R32G32B32A32Float, new FormatInfo(4, false, false, All.Rgba32f, PixelFormat.Rgba, PixelType.Float)); - Add(Format.R32G32B32A32Uint, new FormatInfo(4, false, false, All.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt)); - Add(Format.R32G32B32A32Sint, new FormatInfo(4, false, false, All.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int)); - Add(Format.S8Uint, new FormatInfo(1, false, false, All.StencilIndex8, PixelFormat.StencilIndex, PixelType.UnsignedByte)); - Add(Format.D16Unorm, new FormatInfo(1, false, false, All.DepthComponent16, PixelFormat.DepthComponent, PixelType.UnsignedShort)); - Add(Format.S8UintD24Unorm, new FormatInfo(1, false, false, All.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248)); - Add(Format.X8UintD24Unorm, new FormatInfo(1, false, false, All.DepthComponent24, PixelFormat.DepthComponent, PixelType.UnsignedInt)); - Add(Format.D32Float, new FormatInfo(1, false, false, All.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float)); - Add(Format.D24UnormS8Uint, new FormatInfo(1, false, false, All.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248)); - Add(Format.D32FloatS8Uint, new FormatInfo(1, false, false, All.Depth32fStencil8, PixelFormat.DepthStencil, PixelType.Float32UnsignedInt248Rev)); - Add(Format.R8G8B8A8Srgb, new FormatInfo(4, false, false, All.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte)); - Add(Format.R4G4B4A4Unorm, new FormatInfo(4, true, false, All.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Reversed)); - Add(Format.R5G5B5X1Unorm, new FormatInfo(4, true, false, All.Rgb5, PixelFormat.Rgb, PixelType.UnsignedShort1555Reversed)); - Add(Format.R5G5B5A1Unorm, new FormatInfo(4, true, false, All.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort1555Reversed)); - Add(Format.R5G6B5Unorm, new FormatInfo(3, true, false, All.Rgb565, PixelFormat.Rgb, PixelType.UnsignedShort565Reversed)); - Add(Format.R10G10B10A2Unorm, new FormatInfo(4, true, false, All.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Reversed)); - Add(Format.R10G10B10A2Uint, new FormatInfo(4, false, false, All.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed)); - Add(Format.R11G11B10Float, new FormatInfo(3, false, false, All.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10F11F11FRev)); - Add(Format.R9G9B9E5Float, new FormatInfo(3, false, false, All.Rgb9E5, PixelFormat.Rgb, PixelType.UnsignedInt5999Rev)); - Add(Format.Bc1RgbaUnorm, new FormatInfo(4, true, false, All.CompressedRgbaS3tcDxt1Ext)); - Add(Format.Bc2Unorm, new FormatInfo(4, true, false, All.CompressedRgbaS3tcDxt3Ext)); - Add(Format.Bc3Unorm, new FormatInfo(4, true, false, All.CompressedRgbaS3tcDxt5Ext)); - Add(Format.Bc1RgbaSrgb, new FormatInfo(4, true, false, All.CompressedSrgbAlphaS3tcDxt1Ext)); - Add(Format.Bc2Srgb, new FormatInfo(4, false, false, All.CompressedSrgbAlphaS3tcDxt3Ext)); - Add(Format.Bc3Srgb, new FormatInfo(4, false, false, All.CompressedSrgbAlphaS3tcDxt5Ext)); - Add(Format.Bc4Unorm, new FormatInfo(1, true, false, All.CompressedRedRgtc1)); - Add(Format.Bc4Snorm, new FormatInfo(1, true, false, All.CompressedSignedRedRgtc1)); - Add(Format.Bc5Unorm, new FormatInfo(2, true, false, All.CompressedRgRgtc2)); - Add(Format.Bc5Snorm, new FormatInfo(2, true, false, All.CompressedSignedRgRgtc2)); - Add(Format.Bc7Unorm, new FormatInfo(4, true, false, All.CompressedRgbaBptcUnorm)); - Add(Format.Bc7Srgb, new FormatInfo(4, false, false, All.CompressedSrgbAlphaBptcUnorm)); - Add(Format.Bc6HSfloat, new FormatInfo(4, false, false, All.CompressedRgbBptcSignedFloat)); - Add(Format.Bc6HUfloat, new FormatInfo(4, false, false, All.CompressedRgbBptcUnsignedFloat)); - Add(Format.Etc2RgbUnorm, new FormatInfo(4, false, false, All.CompressedRgb8Etc2)); - Add(Format.Etc2RgbaUnorm, new FormatInfo(4, false, false, All.CompressedRgba8Etc2Eac)); - Add(Format.Etc2RgbPtaUnorm, new FormatInfo(4, false, false, All.CompressedRgb8PunchthroughAlpha1Etc2)); - Add(Format.Etc2RgbSrgb, new FormatInfo(4, false, false, All.CompressedSrgb8Etc2)); - Add(Format.Etc2RgbaSrgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Etc2Eac)); - Add(Format.Etc2RgbPtaSrgb, new FormatInfo(4, false, false, All.CompressedSrgb8PunchthroughAlpha1Etc2)); - Add(Format.R8Uscaled, new FormatInfo(1, false, true, All.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte)); - Add(Format.R8Sscaled, new FormatInfo(1, false, true, All.R8i, PixelFormat.RedInteger, PixelType.Byte)); - Add(Format.R16Uscaled, new FormatInfo(1, false, true, All.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort)); - Add(Format.R16Sscaled, new FormatInfo(1, false, true, All.R16i, PixelFormat.RedInteger, PixelType.Short)); - Add(Format.R32Uscaled, new FormatInfo(1, false, true, All.R32ui, PixelFormat.RedInteger, PixelType.UnsignedInt)); - Add(Format.R32Sscaled, new FormatInfo(1, false, true, All.R32i, PixelFormat.RedInteger, PixelType.Int)); - Add(Format.R8G8Uscaled, new FormatInfo(2, false, true, All.Rg8ui, PixelFormat.RgInteger, PixelType.UnsignedByte)); - Add(Format.R8G8Sscaled, new FormatInfo(2, false, true, All.Rg8i, PixelFormat.RgInteger, PixelType.Byte)); - Add(Format.R16G16Uscaled, new FormatInfo(2, false, true, All.Rg16ui, PixelFormat.RgInteger, PixelType.UnsignedShort)); - Add(Format.R16G16Sscaled, new FormatInfo(2, false, true, All.Rg16i, PixelFormat.RgInteger, PixelType.Short)); - Add(Format.R32G32Uscaled, new FormatInfo(2, false, true, All.Rg32ui, PixelFormat.RgInteger, PixelType.UnsignedInt)); - Add(Format.R32G32Sscaled, new FormatInfo(2, false, true, All.Rg32i, PixelFormat.RgInteger, PixelType.Int)); - Add(Format.R8G8B8Uscaled, new FormatInfo(3, false, true, All.Rgb8ui, PixelFormat.RgbInteger, PixelType.UnsignedByte)); - Add(Format.R8G8B8Sscaled, new FormatInfo(3, false, true, All.Rgb8i, PixelFormat.RgbInteger, PixelType.Byte)); - Add(Format.R16G16B16Uscaled, new FormatInfo(3, false, true, All.Rgb16ui, PixelFormat.RgbInteger, PixelType.UnsignedShort)); - Add(Format.R16G16B16Sscaled, new FormatInfo(3, false, true, All.Rgb16i, PixelFormat.RgbInteger, PixelType.Short)); - Add(Format.R32G32B32Uscaled, new FormatInfo(3, false, true, All.Rgb32ui, PixelFormat.RgbInteger, PixelType.UnsignedInt)); - Add(Format.R32G32B32Sscaled, new FormatInfo(3, false, true, All.Rgb32i, PixelFormat.RgbInteger, PixelType.Int)); - Add(Format.R8G8B8A8Uscaled, new FormatInfo(4, false, true, All.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte)); - Add(Format.R8G8B8A8Sscaled, new FormatInfo(4, false, true, All.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte)); - Add(Format.R16G16B16A16Uscaled, new FormatInfo(4, false, true, All.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort)); - Add(Format.R16G16B16A16Sscaled, new FormatInfo(4, false, true, All.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short)); - Add(Format.R32G32B32A32Uscaled, new FormatInfo(4, false, true, All.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt)); - Add(Format.R32G32B32A32Sscaled, new FormatInfo(4, false, true, All.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int)); - Add(Format.R10G10B10A2Snorm, new FormatInfo(4, true, false, All.Rgb10A2, PixelFormat.Rgba, (PixelType)All.Int2101010Rev)); - Add(Format.R10G10B10A2Sint, new FormatInfo(4, false, false, All.Rgb10A2, PixelFormat.RgbaInteger, (PixelType)All.Int2101010Rev)); - Add(Format.R10G10B10A2Uscaled, new FormatInfo(4, false, true, All.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed)); - Add(Format.R10G10B10A2Sscaled, new FormatInfo(4, false, true, All.Rgb10A2, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Reversed)); - Add(Format.Astc4x4Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc4X4Khr)); - Add(Format.Astc5x4Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc5X4Khr)); - Add(Format.Astc5x5Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc5X5Khr)); - Add(Format.Astc6x5Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc6X5Khr)); - Add(Format.Astc6x6Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc6X6Khr)); - Add(Format.Astc8x5Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc8X5Khr)); - Add(Format.Astc8x6Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc8X6Khr)); - Add(Format.Astc8x8Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc8X8Khr)); - Add(Format.Astc10x5Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc10X5Khr)); - Add(Format.Astc10x6Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc10X6Khr)); - Add(Format.Astc10x8Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc10X8Khr)); - Add(Format.Astc10x10Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc10X10Khr)); - Add(Format.Astc12x10Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc12X10Khr)); - Add(Format.Astc12x12Unorm, new FormatInfo(4, true, false, All.CompressedRgbaAstc12X12Khr)); - Add(Format.Astc4x4Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc4X4Khr)); - Add(Format.Astc5x4Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc5X4Khr)); - Add(Format.Astc5x5Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc5X5Khr)); - Add(Format.Astc6x5Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc6X5Khr)); - Add(Format.Astc6x6Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc6X6Khr)); - Add(Format.Astc8x5Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc8X5Khr)); - Add(Format.Astc8x6Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc8X6Khr)); - Add(Format.Astc8x8Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc8X8Khr)); - Add(Format.Astc10x5Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc10X5Khr)); - Add(Format.Astc10x6Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc10X6Khr)); - Add(Format.Astc10x8Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc10X8Khr)); - Add(Format.Astc10x10Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc10X10Khr)); - Add(Format.Astc12x10Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc12X10Khr)); - Add(Format.Astc12x12Srgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Astc12X12Khr)); - Add(Format.B5G6R5Unorm, new FormatInfo(3, true, false, All.Rgb565, PixelFormat.Rgb, PixelType.UnsignedShort565Reversed)); - Add(Format.B5G5R5A1Unorm, new FormatInfo(4, true, false, All.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort1555Reversed)); - Add(Format.A1B5G5R5Unorm, new FormatInfo(4, true, false, All.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551)); - Add(Format.B8G8R8A8Unorm, new FormatInfo(4, true, false, All.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte)); - Add(Format.B8G8R8A8Srgb, new FormatInfo(4, false, false, All.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte)); - Add(Format.B10G10R10A2Unorm, new FormatInfo(4, false, false, All.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Reversed)); + Add(Format.R8Unorm, new FormatInfo(1, true, false, InternalFormat.R8, PixelFormat.Red, PixelType.UnsignedByte)); + Add(Format.R8Snorm, new FormatInfo(1, true, false, InternalFormat.R8SNorm, PixelFormat.Red, PixelType.Byte)); + Add(Format.R8Uint, new FormatInfo(1, false, false, InternalFormat.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte)); + Add(Format.R8Sint, new FormatInfo(1, false, false, InternalFormat.R8i, PixelFormat.RedInteger, PixelType.Byte)); + Add(Format.R16Float, new FormatInfo(1, false, false, InternalFormat.R16f, PixelFormat.Red, PixelType.HalfFloat)); + Add(Format.R16Unorm, new FormatInfo(1, true, false, InternalFormat.R16, PixelFormat.Red, PixelType.UnsignedShort)); + Add(Format.R16Snorm, new FormatInfo(1, true, false, InternalFormat.R16SNorm, PixelFormat.Red, PixelType.Short)); + Add(Format.R16Uint, new FormatInfo(1, false, false, InternalFormat.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort)); + Add(Format.R16Sint, new FormatInfo(1, false, false, InternalFormat.R16i, PixelFormat.RedInteger, PixelType.Short)); + Add(Format.R32Float, new FormatInfo(1, false, false, InternalFormat.R32f, PixelFormat.Red, PixelType.Float)); + Add(Format.R32Uint, new FormatInfo(1, false, false, InternalFormat.R32ui, PixelFormat.RedInteger, PixelType.UnsignedInt)); + Add(Format.R32Sint, new FormatInfo(1, false, false, InternalFormat.R32i, PixelFormat.RedInteger, PixelType.Int)); + Add(Format.R8G8Unorm, new FormatInfo(2, true, false, InternalFormat.RG8, PixelFormat.RG, PixelType.UnsignedByte)); + Add(Format.R8G8Snorm, new FormatInfo(2, true, false, InternalFormat.RG8SNorm, PixelFormat.RG, PixelType.Byte)); + Add(Format.R8G8Uint, new FormatInfo(2, false, false, InternalFormat.RG8ui, PixelFormat.RGInteger, PixelType.UnsignedByte)); + Add(Format.R8G8Sint, new FormatInfo(2, false, false, InternalFormat.RG8i, PixelFormat.RGInteger, PixelType.Byte)); + Add(Format.R16G16Float, new FormatInfo(2, false, false, InternalFormat.RG16f, PixelFormat.RG, PixelType.HalfFloat)); + Add(Format.R16G16Unorm, new FormatInfo(2, true, false, InternalFormat.RG16, PixelFormat.RG, PixelType.UnsignedShort)); + Add(Format.R16G16Snorm, new FormatInfo(2, true, false, InternalFormat.RG16SNorm, PixelFormat.RG, PixelType.Short)); + Add(Format.R16G16Uint, new FormatInfo(2, false, false, InternalFormat.RG16ui, PixelFormat.RGInteger, PixelType.UnsignedShort)); + Add(Format.R16G16Sint, new FormatInfo(2, false, false, InternalFormat.RG16i, PixelFormat.RGInteger, PixelType.Short)); + Add(Format.R32G32Float, new FormatInfo(2, false, false, InternalFormat.RG32f, PixelFormat.RG, PixelType.Float)); + Add(Format.R32G32Uint, new FormatInfo(2, false, false, InternalFormat.RG32ui, PixelFormat.RGInteger, PixelType.UnsignedInt)); + Add(Format.R32G32Sint, new FormatInfo(2, false, false, InternalFormat.RG32i, PixelFormat.RGInteger, PixelType.Int)); + Add(Format.R8G8B8Unorm, new FormatInfo(3, true, false, InternalFormat.Rgb8, PixelFormat.Rgb, PixelType.UnsignedByte)); + Add(Format.R8G8B8Snorm, new FormatInfo(3, true, false, InternalFormat.Rgb8SNorm, PixelFormat.Rgb, PixelType.Byte)); + Add(Format.R8G8B8Uint, new FormatInfo(3, false, false, InternalFormat.Rgb8ui, PixelFormat.RgbInteger, PixelType.UnsignedByte)); + Add(Format.R8G8B8Sint, new FormatInfo(3, false, false, InternalFormat.Rgb8i, PixelFormat.RgbInteger, PixelType.Byte)); + Add(Format.R16G16B16Float, new FormatInfo(3, false, false, InternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat)); + Add(Format.R16G16B16Unorm, new FormatInfo(3, true, false, InternalFormat.Rgb16, PixelFormat.Rgb, PixelType.UnsignedShort)); + Add(Format.R16G16B16Snorm, new FormatInfo(3, true, false, InternalFormat.Rgb16SNorm, PixelFormat.Rgb, PixelType.Short)); + Add(Format.R16G16B16Uint, new FormatInfo(3, false, false, InternalFormat.Rgb16ui, PixelFormat.RgbInteger, PixelType.UnsignedShort)); + Add(Format.R16G16B16Sint, new FormatInfo(3, false, false, InternalFormat.Rgb16i, PixelFormat.RgbInteger, PixelType.Short)); + Add(Format.R32G32B32Float, new FormatInfo(3, false, false, InternalFormat.Rgb32f, PixelFormat.Rgb, PixelType.Float)); + Add(Format.R32G32B32Uint, new FormatInfo(3, false, false, InternalFormat.Rgb32ui, PixelFormat.RgbInteger, PixelType.UnsignedInt)); + Add(Format.R32G32B32Sint, new FormatInfo(3, false, false, InternalFormat.Rgb32i, PixelFormat.RgbInteger, PixelType.Int)); + Add(Format.R8G8B8A8Unorm, new FormatInfo(4, true, false, InternalFormat.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte)); + Add(Format.R8G8B8A8Snorm, new FormatInfo(4, true, false, InternalFormat.Rgba8SNorm, PixelFormat.Rgba, PixelType.Byte)); + Add(Format.R8G8B8A8Uint, new FormatInfo(4, false, false, InternalFormat.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte)); + Add(Format.R8G8B8A8Sint, new FormatInfo(4, false, false, InternalFormat.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte)); + Add(Format.R16G16B16A16Float, new FormatInfo(4, false, false, InternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat)); + Add(Format.R16G16B16A16Unorm, new FormatInfo(4, true, false, InternalFormat.Rgba16, PixelFormat.Rgba, PixelType.UnsignedShort)); + Add(Format.R16G16B16A16Snorm, new FormatInfo(4, true, false, InternalFormat.Rgba16SNorm, PixelFormat.Rgba, PixelType.Short)); + Add(Format.R16G16B16A16Uint, new FormatInfo(4, false, false, InternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort)); + Add(Format.R16G16B16A16Sint, new FormatInfo(4, false, false, InternalFormat.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short)); + Add(Format.R32G32B32A32Float, new FormatInfo(4, false, false, InternalFormat.Rgba32f, PixelFormat.Rgba, PixelType.Float)); + Add(Format.R32G32B32A32Uint, new FormatInfo(4, false, false, InternalFormat.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt)); + Add(Format.R32G32B32A32Sint, new FormatInfo(4, false, false, InternalFormat.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int)); + Add(Format.S8Uint, new FormatInfo(1, false, false, InternalFormat.StencilIndex8, PixelFormat.StencilIndex, PixelType.UnsignedByte)); + Add(Format.D16Unorm, new FormatInfo(1, false, false, InternalFormat.DepthComponent16, PixelFormat.DepthComponent, PixelType.UnsignedShort)); + Add(Format.S8UintD24Unorm, new FormatInfo(1, false, false, InternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248)); + Add(Format.X8UintD24Unorm, new FormatInfo(1, false, false, InternalFormat.DepthComponent24, PixelFormat.DepthComponent, PixelType.UnsignedInt)); + Add(Format.D32Float, new FormatInfo(1, false, false, InternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float)); + Add(Format.D24UnormS8Uint, new FormatInfo(1, false, false, InternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248)); + Add(Format.D32FloatS8Uint, new FormatInfo(1, false, false, InternalFormat.Depth32fStencil8, PixelFormat.DepthStencil, PixelType.Float32UnsignedInt248Rev)); + Add(Format.R8G8B8A8Srgb, new FormatInfo(4, false, false, InternalFormat.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte)); + Add(Format.R4G4B4A4Unorm, new FormatInfo(4, true, false, InternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Rev)); + Add(Format.R5G5B5X1Unorm, new FormatInfo(4, true, false, InternalFormat.Rgb5, PixelFormat.Rgb, PixelType.UnsignedShort1555Rev)); + Add(Format.R5G5B5A1Unorm, new FormatInfo(4, true, false, InternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort1555Rev)); + Add(Format.R5G6B5Unorm, new FormatInfo(3, true, false, InternalFormat.Rgb565, PixelFormat.Rgb, PixelType.UnsignedShort565Rev)); + Add(Format.R10G10B10A2Unorm, new FormatInfo(4, true, false, InternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Rev)); + Add(Format.R10G10B10A2Uint, new FormatInfo(4, false, false, InternalFormat.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Rev)); + Add(Format.R11G11B10Float, new FormatInfo(3, false, false, InternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10f11f11fRev)); + Add(Format.R9G9B9E5Float, new FormatInfo(3, false, false, InternalFormat.Rgb9E5, PixelFormat.Rgb, PixelType.UnsignedInt5999Rev)); + Add(Format.Bc1RgbaUnorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaS3TCDxt1Ext)); + Add(Format.Bc2Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaS3TCDxt3Ext)); + Add(Format.Bc3Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaS3TCDxt5Ext)); + Add(Format.Bc1RgbaSrgb, new FormatInfo(4, true, false, InternalFormat.CompressedSrgbAlphaS3TCDxt1Ext)); + Add(Format.Bc2Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgbAlphaS3TCDxt3Ext)); + Add(Format.Bc3Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgbAlphaS3TCDxt5Ext)); + Add(Format.Bc4Unorm, new FormatInfo(1, true, false, InternalFormat.CompressedRedRgtc1)); + Add(Format.Bc4Snorm, new FormatInfo(1, true, false, InternalFormat.CompressedSignedRedRgtc1)); + Add(Format.Bc5Unorm, new FormatInfo(2, true, false, InternalFormat.CompressedRGRgtc2)); + Add(Format.Bc5Snorm, new FormatInfo(2, true, false, InternalFormat.CompressedSignedRGRgtc2)); + Add(Format.Bc7Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaBptcUnorm)); + Add(Format.Bc7Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgbAlphaBptcUnorm)); + Add(Format.Bc6HSfloat, new FormatInfo(4, false, false, InternalFormat.CompressedRgbBptcSignedFloat)); + Add(Format.Bc6HUfloat, new FormatInfo(4, false, false, InternalFormat.CompressedRgbBptcUnsignedFloat)); + Add(Format.Etc2RgbUnorm, new FormatInfo(4, false, false, InternalFormat.CompressedRgb8Etc2)); + Add(Format.Etc2RgbaUnorm, new FormatInfo(4, false, false, InternalFormat.CompressedRgba8Etc2Eac)); + Add(Format.Etc2RgbPtaUnorm, new FormatInfo(4, false, false, InternalFormat.CompressedRgb8PunchthroughAlpha1Etc2)); + Add(Format.Etc2RgbSrgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Etc2)); + Add(Format.Etc2RgbaSrgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Etc2Eac)); + Add(Format.Etc2RgbPtaSrgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8PunchthroughAlpha1Etc2)); + Add(Format.R8Uscaled, new FormatInfo(1, false, true, InternalFormat.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte)); + Add(Format.R8Sscaled, new FormatInfo(1, false, true, InternalFormat.R8i, PixelFormat.RedInteger, PixelType.Byte)); + Add(Format.R16Uscaled, new FormatInfo(1, false, true, InternalFormat.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort)); + Add(Format.R16Sscaled, new FormatInfo(1, false, true, InternalFormat.R16i, PixelFormat.RedInteger, PixelType.Short)); + Add(Format.R32Uscaled, new FormatInfo(1, false, true, InternalFormat.R32ui, PixelFormat.RedInteger, PixelType.UnsignedInt)); + Add(Format.R32Sscaled, new FormatInfo(1, false, true, InternalFormat.R32i, PixelFormat.RedInteger, PixelType.Int)); + Add(Format.R8G8Uscaled, new FormatInfo(2, false, true, InternalFormat.RG8ui, PixelFormat.RGInteger, PixelType.UnsignedByte)); + Add(Format.R8G8Sscaled, new FormatInfo(2, false, true, InternalFormat.RG8i, PixelFormat.RGInteger, PixelType.Byte)); + Add(Format.R16G16Uscaled, new FormatInfo(2, false, true, InternalFormat.RG16ui, PixelFormat.RGInteger, PixelType.UnsignedShort)); + Add(Format.R16G16Sscaled, new FormatInfo(2, false, true, InternalFormat.RG16i, PixelFormat.RGInteger, PixelType.Short)); + Add(Format.R32G32Uscaled, new FormatInfo(2, false, true, InternalFormat.RG32ui, PixelFormat.RGInteger, PixelType.UnsignedInt)); + Add(Format.R32G32Sscaled, new FormatInfo(2, false, true, InternalFormat.RG32i, PixelFormat.RGInteger, PixelType.Int)); + Add(Format.R8G8B8Uscaled, new FormatInfo(3, false, true, InternalFormat.Rgb8ui, PixelFormat.RgbInteger, PixelType.UnsignedByte)); + Add(Format.R8G8B8Sscaled, new FormatInfo(3, false, true, InternalFormat.Rgb8i, PixelFormat.RgbInteger, PixelType.Byte)); + Add(Format.R16G16B16Uscaled, new FormatInfo(3, false, true, InternalFormat.Rgb16ui, PixelFormat.RgbInteger, PixelType.UnsignedShort)); + Add(Format.R16G16B16Sscaled, new FormatInfo(3, false, true, InternalFormat.Rgb16i, PixelFormat.RgbInteger, PixelType.Short)); + Add(Format.R32G32B32Uscaled, new FormatInfo(3, false, true, InternalFormat.Rgb32ui, PixelFormat.RgbInteger, PixelType.UnsignedInt)); + Add(Format.R32G32B32Sscaled, new FormatInfo(3, false, true, InternalFormat.Rgb32i, PixelFormat.RgbInteger, PixelType.Int)); + Add(Format.R8G8B8A8Uscaled, new FormatInfo(4, false, true, InternalFormat.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte)); + Add(Format.R8G8B8A8Sscaled, new FormatInfo(4, false, true, InternalFormat.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte)); + Add(Format.R16G16B16A16Uscaled, new FormatInfo(4, false, true, InternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort)); + Add(Format.R16G16B16A16Sscaled, new FormatInfo(4, false, true, InternalFormat.Rgba16i, PixelFormat.RgbaInteger, PixelType.Short)); + Add(Format.R32G32B32A32Uscaled, new FormatInfo(4, false, true, InternalFormat.Rgba32ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt)); + Add(Format.R32G32B32A32Sscaled, new FormatInfo(4, false, true, InternalFormat.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int)); + Add(Format.R10G10B10A2Snorm, new FormatInfo(4, true, false, InternalFormat.Rgb10A2, PixelFormat.Rgba, (PixelType)GLEnum.Int2101010Rev)); + Add(Format.R10G10B10A2Sint, new FormatInfo(4, false, false, InternalFormat.Rgb10A2, PixelFormat.RgbaInteger, (PixelType)GLEnum.Int2101010Rev)); + Add(Format.R10G10B10A2Uscaled, new FormatInfo(4, false, true, InternalFormat.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Rev)); + Add(Format.R10G10B10A2Sscaled, new FormatInfo(4, false, true, InternalFormat.Rgb10A2, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Rev)); + Add(Format.Astc4x4Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc4x4Khr)); + Add(Format.Astc5x4Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc5x4Khr)); + Add(Format.Astc5x5Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc5x5Khr)); + Add(Format.Astc6x5Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc6x5Khr)); + Add(Format.Astc6x6Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc6x6Khr)); + Add(Format.Astc8x5Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc8x5Khr)); + Add(Format.Astc8x6Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc8x6Khr)); + Add(Format.Astc8x8Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc8x8Khr)); + Add(Format.Astc10x5Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc10x5Khr)); + Add(Format.Astc10x6Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc10x6Khr)); + Add(Format.Astc10x8Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc10x8Khr)); + Add(Format.Astc10x10Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc10x10Khr)); + Add(Format.Astc12x10Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc12x10Khr)); + Add(Format.Astc12x12Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaAstc12x12Khr)); + Add(Format.Astc4x4Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc4x4Khr)); + Add(Format.Astc5x4Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc5x4Khr)); + Add(Format.Astc5x5Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc5x5Khr)); + Add(Format.Astc6x5Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc6x5Khr)); + Add(Format.Astc6x6Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc6x6Khr)); + Add(Format.Astc8x5Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc8x5Khr)); + Add(Format.Astc8x6Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc8x6Khr)); + Add(Format.Astc8x8Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc8x8Khr)); + Add(Format.Astc10x5Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc10x5Khr)); + Add(Format.Astc10x6Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc10x6Khr)); + Add(Format.Astc10x8Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc10x8Khr)); + Add(Format.Astc10x10Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc10x10Khr)); + Add(Format.Astc12x10Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc12x10Khr)); + Add(Format.Astc12x12Srgb, new FormatInfo(4, false, false, InternalFormat.CompressedSrgb8Alpha8Astc12x12Khr)); + Add(Format.B5G6R5Unorm, new FormatInfo(3, true, false, InternalFormat.Rgb565, PixelFormat.Rgb, PixelType.UnsignedShort565Rev)); + Add(Format.B5G5R5A1Unorm, new FormatInfo(4, true, false, InternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort1555Rev)); + Add(Format.A1B5G5R5Unorm, new FormatInfo(4, true, false, InternalFormat.Rgb5A1, PixelFormat.Rgba, PixelType.UnsignedShort5551)); + Add(Format.B8G8R8A8Unorm, new FormatInfo(4, true, false, InternalFormat.Rgba8, PixelFormat.Rgba, PixelType.UnsignedByte)); + Add(Format.B8G8R8A8Srgb, new FormatInfo(4, false, false, InternalFormat.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte)); + Add(Format.B10G10R10A2Unorm, new FormatInfo(4, false, false, InternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Rev)); Add(Format.R8Unorm, SizedInternalFormat.R8); Add(Format.R8Uint, SizedInternalFormat.R8ui); Add(Format.R8Sint, SizedInternalFormat.R8i); Add(Format.R16Float, SizedInternalFormat.R16f); Add(Format.R16Unorm, SizedInternalFormat.R16); - Add(Format.R16Snorm, (SizedInternalFormat)All.R16Snorm); + Add(Format.R16Snorm, SizedInternalFormat.R16SNorm); Add(Format.R16Uint, SizedInternalFormat.R16ui); Add(Format.R16Sint, SizedInternalFormat.R16i); Add(Format.R32Float, SizedInternalFormat.R32f); Add(Format.R32Uint, SizedInternalFormat.R32ui); Add(Format.R32Sint, SizedInternalFormat.R32i); - Add(Format.R8G8Unorm, SizedInternalFormat.Rg8); - Add(Format.R8G8Snorm, (SizedInternalFormat)All.Rg8Snorm); - Add(Format.R8G8Uint, SizedInternalFormat.Rg8ui); - Add(Format.R8G8Sint, SizedInternalFormat.Rg8i); - Add(Format.R16G16Float, SizedInternalFormat.Rg16f); - Add(Format.R16G16Unorm, SizedInternalFormat.Rg16); - Add(Format.R16G16Snorm, (SizedInternalFormat)All.Rg16Snorm); - Add(Format.R16G16Uint, SizedInternalFormat.Rg16ui); - Add(Format.R16G16Sint, SizedInternalFormat.Rg16i); - Add(Format.R32G32Float, SizedInternalFormat.Rg32f); - Add(Format.R32G32Uint, SizedInternalFormat.Rg32ui); - Add(Format.R32G32Sint, SizedInternalFormat.Rg32i); + Add(Format.R8G8Unorm, SizedInternalFormat.RG8); + Add(Format.R8G8Snorm, SizedInternalFormat.RG8SNorm); + Add(Format.R8G8Uint, SizedInternalFormat.RG8ui); + Add(Format.R8G8Sint, SizedInternalFormat.RG8i); + Add(Format.R16G16Float, SizedInternalFormat.RG16f); + Add(Format.R16G16Unorm, SizedInternalFormat.RG16); + Add(Format.R16G16Snorm, SizedInternalFormat.RG16SNorm); + Add(Format.R16G16Uint, SizedInternalFormat.RG16ui); + Add(Format.R16G16Sint, SizedInternalFormat.RG16i); + Add(Format.R32G32Float, SizedInternalFormat.RG32f); + Add(Format.R32G32Uint, SizedInternalFormat.RG32ui); + Add(Format.R32G32Sint, SizedInternalFormat.RG32i); Add(Format.R8G8B8A8Unorm, SizedInternalFormat.Rgba8); - Add(Format.R8G8B8A8Snorm, (SizedInternalFormat)All.Rgba8Snorm); + Add(Format.R8G8B8A8Snorm, SizedInternalFormat.Rgba8SNorm); Add(Format.R8G8B8A8Uint, SizedInternalFormat.Rgba8ui); Add(Format.R8G8B8A8Sint, SizedInternalFormat.Rgba8i); Add(Format.R16G16B16A16Float, SizedInternalFormat.Rgba16f); Add(Format.R16G16B16A16Unorm, SizedInternalFormat.Rgba16); - Add(Format.R16G16B16A16Snorm, (SizedInternalFormat)All.Rgba16Snorm); + Add(Format.R16G16B16A16Snorm, SizedInternalFormat.Rgba16SNorm); Add(Format.R16G16B16A16Uint, SizedInternalFormat.Rgba16ui); Add(Format.R16G16B16A16Sint, SizedInternalFormat.Rgba16i); Add(Format.R32G32B32A32Float, SizedInternalFormat.Rgba32f); Add(Format.R32G32B32A32Uint, SizedInternalFormat.Rgba32ui); Add(Format.R32G32B32A32Sint, SizedInternalFormat.Rgba32i); Add(Format.R8G8B8A8Srgb, SizedInternalFormat.Rgba8); - Add(Format.R10G10B10A2Unorm, (SizedInternalFormat)All.Rgb10A2); - Add(Format.R10G10B10A2Uint, (SizedInternalFormat)All.Rgb10A2ui); - Add(Format.R11G11B10Float, (SizedInternalFormat)All.R11fG11fB10f); + Add(Format.R10G10B10A2Unorm, SizedInternalFormat.Rgb10A2); + Add(Format.R10G10B10A2Uint, SizedInternalFormat.Rgb10A2ui); + Add(Format.R11G11B10Float, SizedInternalFormat.R11fG11fB10f); #pragma warning restore IDE0055 } From c1c0ccbaf598cb0f85ff84306faec41f2d7984b4 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 8 May 2024 22:00:37 -0400 Subject: [PATCH 02/35] Trivial renames --- Directory.Packages.props | 5 +- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 44 ++--- src/Ryujinx.Graphics.OpenGL/Debugger.cs | 16 +- .../DrawTextureEmulation.cs | 2 +- .../Effects/FsrScalingFilter.cs | 10 +- .../Effects/FxaaPostProcessingEffect.cs | 2 +- .../Effects/ShaderHelper.cs | 2 +- .../Effects/SmaaPostProcessingEffect.cs | 14 +- src/Ryujinx.Graphics.OpenGL/EnumConversion.cs | 158 +++++++++--------- src/Ryujinx.Graphics.OpenGL/Framebuffer.cs | 6 +- src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs | 12 +- .../Image/ImageArray.cs | 7 +- src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs | 26 +-- .../Image/TextureBase.cs | 2 +- .../Image/TextureBuffer.cs | 6 +- .../Image/TextureCopy.cs | 38 ++--- .../Image/TextureCopyIncompatible.cs | 12 +- .../Image/TextureCopyMS.cs | 14 +- .../Image/TextureStorage.cs | 22 +-- .../Image/TextureView.cs | 16 +- src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 4 +- .../PersistentBuffers.cs | 32 ++-- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 16 +- src/Ryujinx.Graphics.OpenGL/Program.cs | 2 +- .../Queries/BufferedQuery.cs | 16 +- .../Queries/CounterQueue.cs | 2 +- .../Queries/CounterQueueEvent.cs | 4 +- .../Ryujinx.Graphics.OpenGL.csproj | 3 +- src/Ryujinx.Graphics.OpenGL/Sync.cs | 2 +- src/Ryujinx.Graphics.OpenGL/VertexArray.cs | 8 +- src/Ryujinx.Graphics.OpenGL/Window.cs | 2 +- src/Ryujinx.Gtk3/Ryujinx.Gtk3.csproj | 1 - src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs | 2 +- src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs | 2 +- .../OpenGL/OpenGLWindow.cs | 2 +- 35 files changed, 256 insertions(+), 256 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index ef274125a4..5e68c02442 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -28,7 +28,6 @@ - @@ -39,6 +38,8 @@ + + @@ -49,4 +50,4 @@ - + \ No newline at end of file diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index 2a5143101d..d464172c6c 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; using System; @@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.OpenGL { public static void Clear(BufferHandle destination, int offset, int size, uint value) { - GL.BindBuffer(BufferTarget.CopyWriteBuffer, destination.ToInt32()); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, destination.ToInt32()); unsafe { @@ -17,8 +17,8 @@ namespace Ryujinx.Graphics.OpenGL valueArr[0] = value; GL.ClearBufferSubData( - BufferTarget.CopyWriteBuffer, - PixelInternalFormat.Rgba8ui, + BufferTargetARB.CopyWriteBuffer, + InternalFormat.Rgba8ui, (IntPtr)offset, (IntPtr)size, PixelFormat.RgbaInteger, @@ -36,8 +36,8 @@ namespace Ryujinx.Graphics.OpenGL { int handle = GL.GenBuffer(); - GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle); - GL.BufferData(BufferTarget.CopyWriteBuffer, size, IntPtr.Zero, BufferUsageHint.DynamicDraw); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); + GL.BufferData(BufferTargetARB.CopyWriteBuffer, size, IntPtr.Zero, BufferUsageARB.DynamicDraw); return Handle.FromInt32(handle); } @@ -46,24 +46,24 @@ namespace Ryujinx.Graphics.OpenGL { int handle = GL.GenBuffer(); - GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle); - GL.BufferStorage(BufferTarget.CopyWriteBuffer, size, IntPtr.Zero, - BufferStorageFlags.MapPersistentBit | - BufferStorageFlags.MapCoherentBit | - BufferStorageFlags.ClientStorageBit | - BufferStorageFlags.MapReadBit); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); + GL.BufferStorage(BufferTargetARB.CopyWriteBuffer, size, IntPtr.Zero, + BufferStorageMask.MapPersistentBit | + BufferStorageMask.MapCoherentBit | + BufferStorageMask.ClientStorageBit | + BufferStorageMask.MapReadBit); return Handle.FromInt32(handle); } public static void Copy(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size) { - GL.BindBuffer(BufferTarget.CopyReadBuffer, source.ToInt32()); - GL.BindBuffer(BufferTarget.CopyWriteBuffer, destination.ToInt32()); + GL.BindBuffer(BufferTargetARB.CopyReadBuffer, source.ToInt32()); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, destination.ToInt32()); GL.CopyBufferSubData( - BufferTarget.CopyReadBuffer, - BufferTarget.CopyWriteBuffer, + BufferTargetARB.CopyReadBuffer, + BufferTargetARB.CopyWriteBuffer, (IntPtr)srcOffset, (IntPtr)dstOffset, (IntPtr)size); @@ -86,9 +86,9 @@ namespace Ryujinx.Graphics.OpenGL { IntPtr target = renderer.PersistentBuffers.Default.GetHostArray(size); - GL.BindBuffer(BufferTarget.CopyReadBuffer, buffer.ToInt32()); + GL.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToInt32()); - GL.GetBufferSubData(BufferTarget.CopyReadBuffer, (IntPtr)offset, size, target); + GL.GetBufferSubData(BufferTargetARB.CopyReadBuffer, (IntPtr)offset, size, target); return new PinnedSpan(target.ToPointer(), size); } @@ -96,19 +96,19 @@ namespace Ryujinx.Graphics.OpenGL public static void Resize(BufferHandle handle, int size) { - GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle.ToInt32()); - GL.BufferData(BufferTarget.CopyWriteBuffer, size, IntPtr.Zero, BufferUsageHint.StreamCopy); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToInt32()); + GL.BufferData(BufferTargetARB.CopyWriteBuffer, size, IntPtr.Zero, BufferUsageARB.StreamCopy); } public static void SetData(BufferHandle buffer, int offset, ReadOnlySpan data) { - GL.BindBuffer(BufferTarget.CopyWriteBuffer, buffer.ToInt32()); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, buffer.ToInt32()); unsafe { fixed (byte* ptr = data) { - GL.BufferSubData(BufferTarget.CopyWriteBuffer, (IntPtr)offset, data.Length, (IntPtr)ptr); + GL.BufferSubData(BufferTargetARB.CopyWriteBuffer, (IntPtr)offset, data.Length, (IntPtr)ptr); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Debugger.cs b/src/Ryujinx.Graphics.OpenGL/Debugger.cs index 7606bdbfd7..498928743e 100644 --- a/src/Ryujinx.Graphics.OpenGL/Debugger.cs +++ b/src/Ryujinx.Graphics.OpenGL/Debugger.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using System; @@ -16,7 +16,7 @@ namespace Ryujinx.Graphics.OpenGL public static void Initialize(GraphicsDebugLevel logLevel) { // Disable everything - GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, (int[])null, false); + GL.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, false); if (logLevel == GraphicsDebugLevel.None) { @@ -30,16 +30,16 @@ namespace Ryujinx.Graphics.OpenGL if (logLevel == GraphicsDebugLevel.Error) { - GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DebugTypeError, DebugSeverityControl.DontCare, 0, (int[])null, true); + GL.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); } else if (logLevel == GraphicsDebugLevel.Slowdowns) { - GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DebugTypeError, DebugSeverityControl.DontCare, 0, (int[])null, true); - GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DebugTypePerformance, DebugSeverityControl.DontCare, 0, (int[])null, true); + GL.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); + GL.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypePerformance, DebugSeverity.DontCare, 0, (int[])null, true); } else { - GL.DebugMessageControl(DebugSourceControl.DontCare, DebugTypeControl.DontCare, DebugSeverityControl.DontCare, 0, (int[])null, true); + GL.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, true); } _counter = 0; @@ -93,7 +93,7 @@ namespace Ryujinx.Graphics.OpenGL { int counter = Interlocked.Increment(ref _counter); - GL.PushDebugGroup(DebugSourceExternal.DebugSourceApplication, counter, dbgMsg.Length, dbgMsg); + GL.PushDebugGroup(DebugSource.DebugSourceApplication, counter, dbgMsg.Length, dbgMsg); } public static void PopGroup() @@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.OpenGL public static void Print(string dbgMsg, DebugType type = DebugType.DebugTypeMarker, DebugSeverity severity = DebugSeverity.DebugSeverityNotification, int id = 999999) { - GL.DebugMessageInsert(DebugSourceExternal.DebugSourceApplication, type, id, severity, dbgMsg.Length, dbgMsg); + GL.DebugMessageInsert(DebugSource.DebugSourceApplication, type, id, severity, dbgMsg.Length, dbgMsg); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs index 7a6af95ea2..7b33ceda0d 100644 --- a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs +++ b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.OpenGL.Image; using System; diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs index 1a130bebb3..20ab0cf44b 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; @@ -125,7 +125,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects GL.ActiveTexture(TextureUnit.Texture0); int previousTextureBinding = GL.GetInteger(GetPName.TextureBinding2D); - GL.BindImageTexture(0, textureView.Handle, 0, false, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); + GL.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); int threadGroupWorkRegionDim = 16; int dispatchX = (width + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; @@ -152,11 +152,11 @@ namespace Ryujinx.Graphics.OpenGL.Effects GL.Uniform1(_scaleYUniform, scaleY); GL.DispatchCompute(dispatchX, dispatchY, 1); - GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); + GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); // Sharpening Pass GL.UseProgram(_sharpeningShaderProgram); - GL.BindImageTexture(0, destinationTexture.Handle, 0, false, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); + GL.BindImageTexture(0, destinationTexture.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); textureView.Bind(0); GL.Uniform1(_inputUniform, 0); GL.Uniform1(_outputUniform, 0); @@ -164,7 +164,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects GL.DispatchCompute(dispatchX, dispatchY, 1); GL.UseProgram(previousProgram); - GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); + GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); (_renderer.Pipeline as Pipeline).RestoreImages1And2(); diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs index 4e92efe6d8..53f96c8063 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common; using Ryujinx.Graphics.OpenGL.Image; diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs b/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs index c25fe5b258..dea858f34e 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; namespace Ryujinx.Graphics.OpenGL.Effects { diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs index a6c5e4acab..2834106bfa 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; @@ -210,16 +210,16 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); int previousProgram = GL.GetInteger(GetPName.CurrentProgram); - GL.BindImageTexture(0, edgeOutput.Handle, 0, false, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); + GL.BindImageTexture(0, edgeOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); GL.UseProgram(_edgeShaderPrograms[Quality]); view.Bind(0); GL.Uniform1(_inputUniform, 0); GL.Uniform1(_outputUniform, 0); GL.Uniform2(_resolutionUniform, (float)view.Width, (float)view.Height); GL.DispatchCompute(dispatchX, dispatchY, 1); - GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); + GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - GL.BindImageTexture(0, blendOutput.Handle, 0, false, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); + GL.BindImageTexture(0, blendOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); GL.UseProgram(_blendShaderPrograms[Quality]); edgeOutput.Bind(0); areaTexture.Bind(1); @@ -230,9 +230,9 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa GL.Uniform1(_samplerSearchUniform, 2); GL.Uniform2(_resolutionUniform, (float)view.Width, (float)view.Height); GL.DispatchCompute(dispatchX, dispatchY, 1); - GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); + GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - GL.BindImageTexture(0, textureView.Handle, 0, false, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); + GL.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); GL.UseProgram(_neighbourShaderPrograms[Quality]); view.Bind(0); blendOutput.Bind(1); @@ -241,7 +241,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa GL.Uniform1(_samplerBlendUniform, 1); GL.Uniform2(_resolutionUniform, (float)view.Width, (float)view.Height); GL.DispatchCompute(dispatchX, dispatchY, 1); - GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); + GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); (_renderer.Pipeline as Pipeline).RestoreImages1And2(); diff --git a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs index a92c1ce89d..6c02e48752 100644 --- a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; @@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.OpenGL switch (mode) { case AddressMode.Clamp: - return TextureWrapMode.Clamp; + return GLEnum.Clamp; case AddressMode.Repeat: return TextureWrapMode.Repeat; case AddressMode.MirrorClamp: @@ -154,94 +154,94 @@ namespace Ryujinx.Graphics.OpenGL return All.UncorrelatedNv; } - public static All Convert(this BlendFactor factor) + public static GLEnum Convert(this BlendFactor factor) { switch (factor) { case BlendFactor.Zero: case BlendFactor.ZeroGl: - return All.Zero; + return GLEnum.Zero; case BlendFactor.One: case BlendFactor.OneGl: - return All.One; + return GLEnum.One; case BlendFactor.SrcColor: case BlendFactor.SrcColorGl: - return All.SrcColor; + return GLEnum.SrcColor; case BlendFactor.OneMinusSrcColor: case BlendFactor.OneMinusSrcColorGl: - return All.OneMinusSrcColor; + return GLEnum.OneMinusSrcColor; case BlendFactor.SrcAlpha: case BlendFactor.SrcAlphaGl: - return All.SrcAlpha; + return GLEnum.SrcAlpha; case BlendFactor.OneMinusSrcAlpha: case BlendFactor.OneMinusSrcAlphaGl: - return All.OneMinusSrcAlpha; + return GLEnum.OneMinusSrcAlpha; case BlendFactor.DstAlpha: case BlendFactor.DstAlphaGl: - return All.DstAlpha; + return GLEnum.DstAlpha; case BlendFactor.OneMinusDstAlpha: case BlendFactor.OneMinusDstAlphaGl: - return All.OneMinusDstAlpha; + return GLEnum.OneMinusDstAlpha; case BlendFactor.DstColor: case BlendFactor.DstColorGl: - return All.DstColor; + return GLEnum.DstColor; case BlendFactor.OneMinusDstColor: case BlendFactor.OneMinusDstColorGl: - return All.OneMinusDstColor; + return GLEnum.OneMinusDstColor; case BlendFactor.SrcAlphaSaturate: case BlendFactor.SrcAlphaSaturateGl: - return All.SrcAlphaSaturate; + return GLEnum.SrcAlphaSaturate; case BlendFactor.Src1Color: case BlendFactor.Src1ColorGl: - return All.Src1Color; + return GLEnum.Src1Color; case BlendFactor.OneMinusSrc1Color: case BlendFactor.OneMinusSrc1ColorGl: - return All.OneMinusSrc1Color; + return GLEnum.OneMinusSrc1Color; case BlendFactor.Src1Alpha: case BlendFactor.Src1AlphaGl: - return All.Src1Alpha; + return GLEnum.Src1Alpha; case BlendFactor.OneMinusSrc1Alpha: case BlendFactor.OneMinusSrc1AlphaGl: - return All.OneMinusSrc1Alpha; + return GLEnum.OneMinusSrc1Alpha; case BlendFactor.ConstantColor: - return All.ConstantColor; + return GLEnum.ConstantColor; case BlendFactor.OneMinusConstantColor: - return All.OneMinusConstantColor; + return GLEnum.OneMinusConstantColor; case BlendFactor.ConstantAlpha: - return All.ConstantAlpha; + return GLEnum.ConstantAlpha; case BlendFactor.OneMinusConstantAlpha: - return All.OneMinusConstantAlpha; + return GLEnum.OneMinusConstantAlpha; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(BlendFactor)} enum value: {factor}."); - return All.Zero; + return GLEnum.Zero; } - public static BlendEquationMode Convert(this BlendOp op) + public static GLEnum Convert(this BlendOp op) { switch (op) { case BlendOp.Add: case BlendOp.AddGl: - return BlendEquationMode.FuncAdd; + return GLEnum.FuncAdd; case BlendOp.Minimum: case BlendOp.MinimumGl: - return BlendEquationMode.Min; + return GLEnum.Min; case BlendOp.Maximum: case BlendOp.MaximumGl: - return BlendEquationMode.Max; + return GLEnum.Max; case BlendOp.Subtract: case BlendOp.SubtractGl: - return BlendEquationMode.FuncSubtract; + return GLEnum.FuncSubtract; case BlendOp.ReverseSubtract: case BlendOp.ReverseSubtractGl: - return BlendEquationMode.FuncReverseSubtract; + return GLEnum.FuncReverseSubtract; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(BlendOp)} enum value: {op}."); - return BlendEquationMode.FuncAdd; + return GLEnum.FuncAdd; } public static TextureCompareMode Convert(this CompareMode mode) @@ -251,7 +251,7 @@ namespace Ryujinx.Graphics.OpenGL case CompareMode.None: return TextureCompareMode.None; case CompareMode.CompareRToTexture: - return TextureCompareMode.CompareRToTexture; + return TextureCompareMode.CompareRefToTexture; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(CompareMode)} enum value: {mode}."); @@ -259,86 +259,86 @@ namespace Ryujinx.Graphics.OpenGL return TextureCompareMode.None; } - public static All Convert(this CompareOp op) + public static GLEnum Convert(this CompareOp op) { switch (op) { case CompareOp.Never: case CompareOp.NeverGl: - return All.Never; + return GLEnum.Never; case CompareOp.Less: case CompareOp.LessGl: - return All.Less; + return GLEnum.Less; case CompareOp.Equal: case CompareOp.EqualGl: - return All.Equal; + return GLEnum.Equal; case CompareOp.LessOrEqual: case CompareOp.LessOrEqualGl: - return All.Lequal; + return GLEnum.Lequal; case CompareOp.Greater: case CompareOp.GreaterGl: - return All.Greater; + return GLEnum.Greater; case CompareOp.NotEqual: case CompareOp.NotEqualGl: - return All.Notequal; + return GLEnum.Notequal; case CompareOp.GreaterOrEqual: case CompareOp.GreaterOrEqualGl: - return All.Gequal; + return GLEnum.Gequal; case CompareOp.Always: case CompareOp.AlwaysGl: - return All.Always; + return GLEnum.Always; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(CompareOp)} enum value: {op}."); - return All.Never; + return GLEnum.Never; } - public static ClipDepthMode Convert(this DepthMode mode) + public static GLEnum Convert(this DepthMode mode) { switch (mode) { case DepthMode.MinusOneToOne: - return ClipDepthMode.NegativeOneToOne; + return GLEnum.NegativeOneToOne; case DepthMode.ZeroToOne: - return ClipDepthMode.ZeroToOne; + return GLEnum.ZeroToOne; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(DepthMode)} enum value: {mode}."); - return ClipDepthMode.NegativeOneToOne; + return GLEnum.NegativeOneToOne; } - public static All Convert(this DepthStencilMode mode) + public static GLEnum Convert(this DepthStencilMode mode) { switch (mode) { case DepthStencilMode.Depth: - return All.DepthComponent; + return GLEnum.DepthComponent; case DepthStencilMode.Stencil: - return All.StencilIndex; + return GLEnum.StencilIndex; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(DepthStencilMode)} enum value: {mode}."); - return All.Depth; + return GLEnum.Depth; } - public static CullFaceMode Convert(this Face face) + public static GLEnum Convert(this Face face) { switch (face) { case Face.Back: - return CullFaceMode.Back; + return GLEnum.Back; case Face.Front: - return CullFaceMode.Front; + return GLEnum.Front; case Face.FrontAndBack: - return CullFaceMode.FrontAndBack; + return GLEnum.FrontAndBack; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(Face)} enum value: {face}."); - return CullFaceMode.Back; + return GLEnum.Back; } public static FrontFaceDirection Convert(this FrontFace frontFace) @@ -346,14 +346,14 @@ namespace Ryujinx.Graphics.OpenGL switch (frontFace) { case FrontFace.Clockwise: - return FrontFaceDirection.Cw; + return FrontFaceDirection.CW; case FrontFace.CounterClockwise: return FrontFaceDirection.Ccw; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(FrontFace)} enum value: {frontFace}."); - return FrontFaceDirection.Cw; + return FrontFaceDirection.CW; } public static DrawElementsType Convert(this IndexType type) @@ -411,21 +411,21 @@ namespace Ryujinx.Graphics.OpenGL return TextureMinFilter.Nearest; } - public static OpenTK.Graphics.OpenGL.PolygonMode Convert(this GAL.PolygonMode mode) + public static Silk.NET.OpenGL.PolygonMode Convert(this GAL.PolygonMode mode) { switch (mode) { case GAL.PolygonMode.Point: - return OpenTK.Graphics.OpenGL.PolygonMode.Point; + return Silk.NET.OpenGL.PolygonMode.Point; case GAL.PolygonMode.Line: - return OpenTK.Graphics.OpenGL.PolygonMode.Line; + return Silk.NET.OpenGL.PolygonMode.Line; case GAL.PolygonMode.Fill: - return OpenTK.Graphics.OpenGL.PolygonMode.Fill; + return Silk.NET.OpenGL.PolygonMode.Fill; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(GAL.PolygonMode)} enum value: {mode}."); - return OpenTK.Graphics.OpenGL.PolygonMode.Fill; + return Silk.NET.OpenGL.PolygonMode.Fill; } public static PrimitiveType Convert(this PrimitiveTopology topology) @@ -615,47 +615,47 @@ namespace Ryujinx.Graphics.OpenGL return NvViewportSwizzle.ViewportSwizzlePositiveXNv; } - public static All Convert(this LogicalOp op) + public static GLEnum Convert(this LogicalOp op) { switch (op) { case LogicalOp.Clear: - return All.Clear; + return GLEnum.Clear; case LogicalOp.And: - return All.And; + return GLEnum.And; case LogicalOp.AndReverse: - return All.AndReverse; + return GLEnum.AndReverse; case LogicalOp.Copy: - return All.Copy; + return GLEnum.Copy; case LogicalOp.AndInverted: - return All.AndInverted; + return GLEnum.AndInverted; case LogicalOp.Noop: - return All.Noop; + return GLEnum.Noop; case LogicalOp.Xor: - return All.Xor; + return GLEnum.Xor; case LogicalOp.Or: - return All.Or; + return GLEnum.Or; case LogicalOp.Nor: - return All.Nor; + return GLEnum.Nor; case LogicalOp.Equiv: - return All.Equiv; + return GLEnum.Equiv; case LogicalOp.Invert: - return All.Invert; + return GLEnum.Invert; case LogicalOp.OrReverse: - return All.OrReverse; + return GLEnum.OrReverse; case LogicalOp.CopyInverted: - return All.CopyInverted; + return GLEnum.CopyInverted; case LogicalOp.OrInverted: - return All.OrInverted; + return GLEnum.OrInverted; case LogicalOp.Nand: - return All.Nand; + return GLEnum.Nand; case LogicalOp.Set: - return All.Set; + return GLEnum.Set; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(LogicalOp)} enum value: {op}."); - return All.Never; + return GLEnum.Never; } public static ShaderType Convert(this ShaderStage stage) diff --git a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs index 394b8bc76a..1c1334d3aa 100644 --- a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; using System; @@ -107,11 +107,11 @@ namespace Ryujinx.Graphics.OpenGL private static void SetDrawBuffersImpl(int colorsCount) { - DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[colorsCount]; + DrawBufferMode[] drawBuffers = new DrawBufferMode[colorsCount]; for (int index = 0; index < colorsCount; index++) { - drawBuffers[index] = DrawBuffersEnum.ColorAttachment0 + index; + drawBuffers[index] = DrawBufferMode.ColorAttachment0 + index; } GL.DrawBuffers(colorsCount, drawBuffers); diff --git a/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs b/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs index cf0b0645c9..a7a47b075c 100644 --- a/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs +++ b/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using System; namespace Ryujinx.Graphics.OpenGL @@ -27,9 +27,9 @@ namespace Ryujinx.Graphics.OpenGL private static readonly Lazy _supportsTextureShadowLod = new(() => HasExtension("GL_EXT_texture_shadow_lod")); private static readonly Lazy _supportsViewportSwizzle = new(() => HasExtension("GL_NV_viewport_swizzle")); - private static readonly Lazy _maximumComputeSharedMemorySize = new(() => GetLimit(All.MaxComputeSharedMemorySize)); - private static readonly Lazy _storageBufferOffsetAlignment = new(() => GetLimit(All.ShaderStorageBufferOffsetAlignment)); - private static readonly Lazy _textureBufferOffsetAlignment = new(() => GetLimit(All.TextureBufferOffsetAlignment)); + private static readonly Lazy _maximumComputeSharedMemorySize = new(() => GetLimit(GLEnum.MaxComputeSharedMemorySize)); + private static readonly Lazy _storageBufferOffsetAlignment = new(() => GetLimit(GLEnum.ShaderStorageBufferOffsetAlignment)); + private static readonly Lazy _textureBufferOffsetAlignment = new(() => GetLimit(GLEnum.TextureBufferOffsetAlignment)); public enum GpuVendor { @@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.OpenGL public static GpuVendor Vendor => _gpuVendor.Value; - private static readonly Lazy _maxSupportedAnisotropy = new(GL.GetFloat((GetPName)All.MaxTextureMaxAnisotropy)); + private static readonly Lazy _maxSupportedAnisotropy = new(GL.GetFloat((GetPName)GLEnum.MaxTextureMaxAnisotropy)); public static bool UsePersistentBufferForFlush => _gpuVendor.Value == GpuVendor.AmdWindows || _gpuVendor.Value == GpuVendor.Nvidia; @@ -98,7 +98,7 @@ namespace Ryujinx.Graphics.OpenGL return false; } - private static int GetLimit(All name) + private static int GetLimit(GLEnum name) { return GL.GetInteger((GetPName)name); } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs index 1c5acedf3a..6e1a0819be 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs @@ -1,6 +1,5 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; -using System; namespace Ryujinx.Graphics.OpenGL.Image { @@ -50,7 +49,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { if (_images[i].Handle == 0) { - GL.BindImageTexture(baseBinding + i, 0, 0, true, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); + GL.BindImageTexture(baseBinding + i, 0, 0, true, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); } else { @@ -58,7 +57,7 @@ namespace Ryujinx.Graphics.OpenGL.Image if (format != 0) { - GL.BindImageTexture(baseBinding + i, _images[i].Handle, 0, true, 0, TextureAccess.ReadWrite, format); + GL.BindImageTexture(baseBinding + i, _images[i].Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs index 6cf0482967..e06e6b22dc 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.OpenGL.Image @@ -11,20 +11,20 @@ namespace Ryujinx.Graphics.OpenGL.Image { Handle = GL.GenSampler(); - GL.SamplerParameter(Handle, SamplerParameterName.TextureMinFilter, (int)info.MinFilter.Convert()); - GL.SamplerParameter(Handle, SamplerParameterName.TextureMagFilter, (int)info.MagFilter.Convert()); + GL.SamplerParameter(Handle, SamplerParameterI.MinFilter, (int)info.MinFilter.Convert()); + GL.SamplerParameter(Handle, SamplerParameterI.MagFilter, (int)info.MagFilter.Convert()); if (HwCapabilities.SupportsSeamlessCubemapPerTexture) { GL.SamplerParameter(Handle, (SamplerParameterName)ArbSeamlessCubemapPerTexture.TextureCubeMapSeamless, info.SeamlessCubemap ? 1 : 0); } - GL.SamplerParameter(Handle, SamplerParameterName.TextureWrapS, (int)info.AddressU.Convert()); - GL.SamplerParameter(Handle, SamplerParameterName.TextureWrapT, (int)info.AddressV.Convert()); - GL.SamplerParameter(Handle, SamplerParameterName.TextureWrapR, (int)info.AddressP.Convert()); + GL.SamplerParameter(Handle, SamplerParameterI.WrapS, (int)info.AddressU.Convert()); + GL.SamplerParameter(Handle, SamplerParameterI.WrapT, (int)info.AddressV.Convert()); + GL.SamplerParameter(Handle, SamplerParameterI.WrapR, (int)info.AddressP.Convert()); - GL.SamplerParameter(Handle, SamplerParameterName.TextureCompareMode, (int)info.CompareMode.Convert()); - GL.SamplerParameter(Handle, SamplerParameterName.TextureCompareFunc, (int)info.CompareOp.Convert()); + GL.SamplerParameter(Handle, SamplerParameterI.CompareMode, (int)info.CompareMode.Convert()); + GL.SamplerParameter(Handle, SamplerParameterI.CompareFunc, (int)info.CompareOp.Convert()); unsafe { @@ -36,14 +36,14 @@ namespace Ryujinx.Graphics.OpenGL.Image info.BorderColor.Alpha, }; - GL.SamplerParameter(Handle, SamplerParameterName.TextureBorderColor, borderColor); + GL.SamplerParameter(Handle, SamplerParameterF.BorderColor, borderColor); } - GL.SamplerParameter(Handle, SamplerParameterName.TextureMinLod, info.MinLod); - GL.SamplerParameter(Handle, SamplerParameterName.TextureMaxLod, info.MaxLod); - GL.SamplerParameter(Handle, SamplerParameterName.TextureLodBias, info.MipLodBias); + GL.SamplerParameter(Handle, SamplerParameterF.TextureMinLod, info.MinLod); + GL.SamplerParameter(Handle, SamplerParameterF.TextureMaxLod, info.MaxLod); + GL.SamplerParameter(Handle, SamplerParameterF.TextureLodBias, info.MipLodBias); - GL.SamplerParameter(Handle, SamplerParameterName.TextureMaxAnisotropyExt, info.MaxAnisotropy); + GL.SamplerParameter(Handle, SamplerParameterF.MaxAnisotropy, info.MaxAnisotropy); } public void Bind(int unit) diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs index df8453830a..084d8003a4 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.OpenGL.Image diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs index a8196541a1..755364c33b 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; using System; using System.Buffers; @@ -95,9 +95,9 @@ namespace Ryujinx.Graphics.OpenGL.Image Bind(0); - SizedInternalFormat format = (SizedInternalFormat)FormatTable.GetFormatInfo(Info.Format).PixelInternalFormat; + SizedInternalFormat format = (SizedInternalFormat)FormatTable.GetFormatInfo(Info.Format).InternalFormat; - GL.TexBufferRange(TextureBufferTarget.TextureBuffer, format, _buffer.ToInt32(), (IntPtr)buffer.Offset, buffer.Size); + GL.TexBufferRange(TextureTarget.TextureBuffer, format, _buffer.ToInt32(), (IntPtr)buffer.Offset, buffer.Size); } public void Dispose() diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index 89bd5e4ff3..2b3fd891f5 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using System; @@ -348,16 +348,16 @@ namespace Ryujinx.Graphics.OpenGL.Image EnsurePbo(from); - GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyPboHandle); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); from.WriteToPbo(0, forceBgra: true); - GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, _copyPboHandle); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); + GL.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); to.ReadFromPbo(0, _copyPboSize); - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); + GL.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); return to; } @@ -393,7 +393,7 @@ namespace Ryujinx.Graphics.OpenGL.Image EnsurePbo(from); - GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyPboHandle); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); // The source texture is written out in full, then the destination is taken as a slice from the data using unpack params. // The offset points to the base at which the requested layer is at. @@ -412,15 +412,15 @@ namespace Ryujinx.Graphics.OpenGL.Image if (to.Info.IsCompressed) { - GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockWidth, to.Info.BlockWidth); - GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockHeight, to.Info.BlockHeight); - GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockDepth, 1); - GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockSize, to.Info.BytesPerPixel); + GL.PixelStore(GLEnum.UnpackCompressedBlockWidth, to.Info.BlockWidth); + GL.PixelStore(GLEnum.UnpackCompressedBlockHeight, to.Info.BlockHeight); + GL.PixelStore(GLEnum.UnpackCompressedBlockDepth, 1); + GL.PixelStore(GLEnum.UnpackCompressedBlockSize, to.Info.BytesPerPixel); } } - GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, _copyPboHandle); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); + GL.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); to.ReadFromPbo2D(offset, dstLayer, dstLevel, dstWidth, dstHeight); @@ -432,14 +432,14 @@ namespace Ryujinx.Graphics.OpenGL.Image if (to.Info.IsCompressed) { - GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockWidth, 0); - GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockHeight, 0); - GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockDepth, 0); - GL.PixelStore(PixelStoreParameter.UnpackCompressedBlockSize, 0); + GL.PixelStore(GLEnum.UnpackCompressedBlockWidth, 0); + GL.PixelStore(GLEnum.UnpackCompressedBlockHeight, 0); + GL.PixelStore(GLEnum.UnpackCompressedBlockDepth, 0); + GL.PixelStore(GLEnum.UnpackCompressedBlockSize, 0); } } - GL.BindBuffer(BufferTarget.PixelUnpackBuffer, 0); + GL.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); } private void EnsurePbo(TextureView view) @@ -463,8 +463,8 @@ namespace Ryujinx.Graphics.OpenGL.Image _copyPboHandle = GL.GenBuffer(); _copyPboSize = requiredSize; - GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyPboHandle); - GL.BufferData(BufferTarget.PixelPackBuffer, requiredSize, IntPtr.Zero, BufferUsageHint.DynamicCopy); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); + GL.BufferData(BufferTargetARB.PixelPackBuffer, requiredSize, IntPtr.Zero, BufferUsageARB.DynamicCopy); } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs index 082e6ccf8b..af6f7b32f3 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using System; using System.Collections.Generic; using System.Globalization; @@ -111,8 +111,8 @@ void main() for (int z = 0; z < depth; z++) { - GL.BindImageTexture(0, src.Handle, srcLevel + l, false, srcLayer + z, TextureAccess.ReadOnly, srcFormat); - GL.BindImageTexture(1, dst.Handle, dstLevel + l, false, dstLayer + z, TextureAccess.WriteOnly, dstFormat); + GL.BindImageTexture(0, src.Handle, srcLevel + l, false, srcLayer + z, BufferAccessARB.ReadOnly, srcFormat); + GL.BindImageTexture(1, dst.Handle, dstLevel + l, false, dstLayer + z, BufferAccessARB.WriteOnly, dstFormat); GL.DispatchCompute((width + 31) / 32, (height + 31) / 32, 1); } @@ -131,7 +131,7 @@ void main() return componentsCount switch { 1 => SizedInternalFormat.R8ui, - 2 => SizedInternalFormat.Rg8ui, + 2 => SizedInternalFormat.RG8ui, 4 => SizedInternalFormat.Rgba8ui, _ => throw new ArgumentException($"Invalid components count {componentsCount}."), }; @@ -141,7 +141,7 @@ void main() return componentsCount switch { 1 => SizedInternalFormat.R16ui, - 2 => SizedInternalFormat.Rg16ui, + 2 => SizedInternalFormat.RG16ui, 4 => SizedInternalFormat.Rgba16ui, _ => throw new ArgumentException($"Invalid components count {componentsCount}."), }; @@ -151,7 +151,7 @@ void main() return componentsCount switch { 1 => SizedInternalFormat.R32ui, - 2 => SizedInternalFormat.Rg32ui, + 2 => SizedInternalFormat.RG32ui, 4 => SizedInternalFormat.Rgba32ui, _ => throw new ArgumentException($"Invalid components count {componentsCount}."), }; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs index 0fa6453dc1..ba86985c4f 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; using System; using System.Numerics; @@ -119,8 +119,8 @@ void main() for (int z = 0; z < depth; z++) { - GL.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, TextureAccess.ReadOnly, GetFormat(srcInfo.BytesPerPixel)); - GL.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, TextureAccess.WriteOnly, GetFormat(dstInfo.BytesPerPixel)); + GL.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, GetFormat(srcInfo.BytesPerPixel)); + GL.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, GetFormat(dstInfo.BytesPerPixel)); GL.DispatchCompute((dstWidth + 31) / 32, (dstHeight + 31) / 32, 1); } @@ -149,8 +149,8 @@ void main() for (int z = 0; z < depth; z++) { - GL.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, TextureAccess.ReadOnly, GetFormat(srcInfo.BytesPerPixel)); - GL.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, TextureAccess.WriteOnly, GetFormat(dstInfo.BytesPerPixel)); + GL.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, GetFormat(srcInfo.BytesPerPixel)); + GL.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, GetFormat(dstInfo.BytesPerPixel)); GL.DispatchCompute((srcWidth + 31) / 32, (srcHeight + 31) / 32, 1); } @@ -171,7 +171,7 @@ void main() 1 => SizedInternalFormat.R8ui, 2 => SizedInternalFormat.R16ui, 4 => SizedInternalFormat.R32ui, - 8 => SizedInternalFormat.Rg32ui, + 8 => SizedInternalFormat.RG32ui, 16 => SizedInternalFormat.Rgba32ui, _ => throw new ArgumentException($"Invalid bytes per pixel {bytesPerPixel}."), }; @@ -189,7 +189,7 @@ void main() handle, texture.Info.Target.Convert(), texture.Storage.Handle, - PixelInternalFormat.Rgba8, + InternalFormat.Rgba8, texture.FirstLevel, 1, texture.FirstLayer, diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs index 79c6cb685b..dc31143ac4 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; @@ -45,7 +45,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } else { - internalFormat = (SizedInternalFormat)format.PixelInternalFormat; + internalFormat = (SizedInternalFormat)format.InternalFormat; } int levels = Info.GetLevelsClamped(); @@ -54,7 +54,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { case Target.Texture1D: GL.TexStorage1D( - TextureTarget1d.Texture1D, + TextureTarget.Texture1D, levels, internalFormat, Info.Width); @@ -62,7 +62,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture1DArray: GL.TexStorage2D( - TextureTarget2d.Texture1DArray, + TextureTarget.Texture1DArray, levels, internalFormat, Info.Width, @@ -71,7 +71,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture2D: GL.TexStorage2D( - TextureTarget2d.Texture2D, + TextureTarget.Texture2D, levels, internalFormat, Info.Width, @@ -80,7 +80,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture2DArray: GL.TexStorage3D( - TextureTarget3d.Texture2DArray, + TextureTarget.Texture2DArray, levels, internalFormat, Info.Width, @@ -90,7 +90,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture2DMultisample: GL.TexStorage2DMultisample( - TextureTargetMultisample2d.Texture2DMultisample, + TextureTarget.Texture2DMultisample, Info.Samples, internalFormat, Info.Width, @@ -100,7 +100,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture2DMultisampleArray: GL.TexStorage3DMultisample( - TextureTargetMultisample3d.Texture2DMultisampleArray, + TextureTarget.Texture2DMultisampleArray, Info.Samples, internalFormat, Info.Width, @@ -111,7 +111,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture3D: GL.TexStorage3D( - TextureTarget3d.Texture3D, + TextureTarget.Texture3D, levels, internalFormat, Info.Width, @@ -121,7 +121,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Cubemap: GL.TexStorage2D( - TextureTarget2d.TextureCubeMap, + TextureTarget.TextureCubeMap, levels, internalFormat, Info.Width, @@ -130,7 +130,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.CubemapArray: GL.TexStorage3D( - (TextureTarget3d)All.TextureCubeMapArray, + TextureTarget.TextureCubeMapArray, levels, internalFormat, Info.Width, diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index 8a18e6132a..3d65c8a29a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using System; @@ -40,15 +40,15 @@ namespace Ryujinx.Graphics.OpenGL.Image FormatInfo format = FormatTable.GetFormatInfo(Info.Format); - PixelInternalFormat pixelInternalFormat; + InternalFormat pixelInternalFormat; if (format.IsCompressed) { - pixelInternalFormat = (PixelInternalFormat)format.PixelFormat; + pixelInternalFormat = (InternalFormat)format.PixelFormat; } else { - pixelInternalFormat = format.PixelInternalFormat; + pixelInternalFormat = format.InternalFormat; } int levels = Info.GetLevelsClamped(); @@ -322,7 +322,7 @@ namespace Ryujinx.Graphics.OpenGL.Image throw new NotSupportedException("Stride conversion for texture copy to buffer not supported."); } - GL.BindBuffer(BufferTarget.PixelPackBuffer, range.Handle.ToInt32()); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, range.Handle.ToInt32()); FormatInfo format = FormatTable.GetFormatInfo(Info.Format); if (format.PixelFormat == PixelFormat.DepthStencil) @@ -334,7 +334,7 @@ namespace Ryujinx.Graphics.OpenGL.Image Debug.Assert(offset == 0); - GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); } public void WriteToPbo(int offset, bool forceBgra) @@ -405,9 +405,9 @@ namespace Ryujinx.Graphics.OpenGL.Image { if (pixelType == PixelType.UnsignedShort565) { - pixelType = PixelType.UnsignedShort565Reversed; + pixelType = PixelType.UnsignedShort565Rev; } - else if (pixelType == PixelType.UnsignedShort565Reversed) + else if (pixelType == PixelType.UnsignedShort565Rev) { pixelType = PixelType.UnsignedShort565; } diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index d56c40af46..0d3a7e2187 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; @@ -238,7 +238,7 @@ namespace Ryujinx.Graphics.OpenGL // This call is expected to fail if we're running with a core profile, // as this clamp target was deprecated, but that's fine as a core profile // should already have the desired behaviour were outputs are not clamped. - GL.ClampColor(ClampColorTarget.ClampFragmentColor, ClampColorMode.False); + GL.ClampColor(ClampColorTargetARB.FragmentColorArb, ClampColorModeARB.False); } private void PrintGpuInformation() diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index ebfe3ad644..e809e966fd 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; @@ -26,8 +26,8 @@ namespace Ryujinx.Graphics.OpenGL public void Map(BufferHandle handle, int size) { - GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle.ToInt32()); - IntPtr ptr = GL.MapBufferRange(BufferTarget.CopyWriteBuffer, IntPtr.Zero, size, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToInt32()); + IntPtr ptr = GL.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, size, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); _maps[handle] = ptr; } @@ -36,8 +36,8 @@ namespace Ryujinx.Graphics.OpenGL { if (_maps.ContainsKey(handle)) { - GL.BindBuffer(BufferTarget.CopyWriteBuffer, handle.ToInt32()); - GL.UnmapBuffer(BufferTarget.CopyWriteBuffer); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToInt32()); + GL.UnmapBuffer(BufferTargetARB.CopyWriteBuffer); _maps.Remove(handle); } @@ -72,10 +72,10 @@ namespace Ryujinx.Graphics.OpenGL _copyBufferHandle = GL.GenBuffer(); _copyBufferSize = requiredSize; - GL.BindBuffer(BufferTarget.CopyWriteBuffer, _copyBufferHandle); - GL.BufferStorage(BufferTarget.CopyWriteBuffer, requiredSize, IntPtr.Zero, BufferStorageFlags.MapReadBit | BufferStorageFlags.MapPersistentBit); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); + GL.BufferStorage(BufferTargetARB.CopyWriteBuffer, requiredSize, IntPtr.Zero, BufferStorageFlags.MapReadBit | BufferStorageFlags.MapPersistentBit); - _bufferMap = GL.MapBufferRange(BufferTarget.CopyWriteBuffer, IntPtr.Zero, requiredSize, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); + _bufferMap = GL.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, requiredSize, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); } } @@ -110,11 +110,11 @@ namespace Ryujinx.Graphics.OpenGL { EnsureBuffer(size); - GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyBufferHandle); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyBufferHandle); view.WriteToPbo(0, false); - GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); Sync(); @@ -125,11 +125,11 @@ namespace Ryujinx.Graphics.OpenGL { EnsureBuffer(size); - GL.BindBuffer(BufferTarget.PixelPackBuffer, _copyBufferHandle); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyBufferHandle); int offset = view.WriteToPbo2D(0, layer, level); - GL.BindBuffer(BufferTarget.PixelPackBuffer, 0); + GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); Sync(); @@ -140,12 +140,12 @@ namespace Ryujinx.Graphics.OpenGL { EnsureBuffer(size); - GL.BindBuffer(BufferTarget.CopyReadBuffer, buffer.ToInt32()); - GL.BindBuffer(BufferTarget.CopyWriteBuffer, _copyBufferHandle); + GL.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToInt32()); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); - GL.CopyBufferSubData(BufferTarget.CopyReadBuffer, BufferTarget.CopyWriteBuffer, (IntPtr)offset, IntPtr.Zero, size); + GL.CopyBufferSubData(BufferTargetARB.CopyReadBuffer, BufferTargetARB.CopyWriteBuffer, (IntPtr)offset, IntPtr.Zero, size); - GL.BindBuffer(BufferTarget.CopyWriteBuffer, 0); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, 0); Sync(); diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 6d066bb676..8624782206 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; @@ -119,14 +119,14 @@ namespace Ryujinx.Graphics.OpenGL { _framebuffer.AttachColorLayerForClear(index, l); - GL.ClearBuffer(OpenTK.Graphics.OpenGL.ClearBuffer.Color, index, colors); + GL.ClearBuffer(BufferKind.Color, index, colors); } _framebuffer.DetachColorLayerForClear(index); } else { - GL.ClearBuffer(OpenTK.Graphics.OpenGL.ClearBuffer.Color, index, colors); + GL.ClearBuffer(BufferKind.Color, index, colors); } RestoreComponentMask(index); @@ -187,11 +187,11 @@ namespace Ryujinx.Graphics.OpenGL } else if (depthMask) { - GL.ClearBuffer(OpenTK.Graphics.OpenGL.ClearBuffer.Depth, 0, ref depthValue); + GL.ClearBuffer(BufferKind.Depth, 0, ref depthValue); } else if (stencilMask != 0) { - GL.ClearBuffer(OpenTK.Graphics.OpenGL.ClearBuffer.Stencil, 0, ref stencilValue); + GL.ClearBuffer(BufferKind.Stencil, 0, ref stencilValue); } } @@ -634,7 +634,7 @@ namespace Ryujinx.Graphics.OpenGL PreDrawVbUnbounded(); - GL.BindBuffer((BufferTarget)All.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); + GL.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); GL.DrawArraysIndirect(_primitiveType, (IntPtr)indirectBuffer.Offset); @@ -651,8 +651,8 @@ namespace Ryujinx.Graphics.OpenGL PreDrawVbUnbounded(); - GL.BindBuffer((BufferTarget)All.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); - GL.BindBuffer((BufferTarget)All.ParameterBuffer, parameterBuffer.Handle.ToInt32()); + GL.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); + GL.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToInt32()); GL.MultiDrawArraysIndirectCount( _primitiveType, diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index 19de06f8f2..a593e79df4 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs index 0a85970d75..05e18659d1 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Logging; using System; using System.Runtime.InteropServices; @@ -24,14 +24,14 @@ namespace Ryujinx.Graphics.OpenGL.Queries Query = GL.GenQuery(); _type = type; - GL.BindBuffer(BufferTarget.QueryBuffer, _buffer); + GL.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); unsafe { long defaultValue = DefaultValue; - GL.BufferStorage(BufferTarget.QueryBuffer, sizeof(long), (IntPtr)(&defaultValue), BufferStorageFlags.MapReadBit | BufferStorageFlags.MapWriteBit | BufferStorageFlags.MapPersistentBit); + GL.BufferStorage(BufferTargetARB.QueryBuffer, sizeof(long), (IntPtr)(&defaultValue), BufferStorageMask.MapReadBit | BufferStorageMask.MapWriteBit | BufferStorageMask.MapPersistentBit); } - _bufferMap = GL.MapBufferRange(BufferTarget.QueryBuffer, IntPtr.Zero, sizeof(long), BufferAccessMask.MapReadBit | BufferAccessMask.MapWriteBit | BufferAccessMask.MapPersistentBit); + _bufferMap = GL.MapBufferRange(BufferTargetARB.QueryBuffer, IntPtr.Zero, sizeof(long), MapBufferAccessMask.ReadBit | MapBufferAccessMask.WriteBit | MapBufferAccessMask.PersistentBit); } public void Reset() @@ -51,11 +51,11 @@ namespace Ryujinx.Graphics.OpenGL.Queries if (withResult) { - GL.BindBuffer(BufferTarget.QueryBuffer, _buffer); + GL.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); Marshal.WriteInt64(_bufferMap, -1L); GL.GetQueryObject(Query, GetQueryObjectParam.QueryResult, (long*)0); - GL.MemoryBarrier(MemoryBarrierFlags.QueryBufferBarrierBit | MemoryBarrierFlags.ClientMappedBufferBarrierBit); + GL.MemoryBarrier(MemoryBarrierMask.QueryBufferBarrierBit | MemoryBarrierMask.ClientMappedBufferBarrierBit); } else { @@ -111,8 +111,8 @@ namespace Ryujinx.Graphics.OpenGL.Queries public void Dispose() { - GL.BindBuffer(BufferTarget.QueryBuffer, _buffer); - GL.UnmapBuffer(BufferTarget.QueryBuffer); + GL.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); + GL.UnmapBuffer(BufferTargetARB.QueryBuffer); GL.DeleteBuffer(_buffer); GL.DeleteQuery(Query); } diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs index 345a99ffa1..0a2f35036e 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; using System; using System.Collections.Generic; diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs index 32b75c615e..d37aeae4fe 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; using System; using System.Threading; @@ -62,7 +62,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries return true; } - if (ClearCounter || Type == QueryTarget.Timestamp) + if (ClearCounter || Type == QueryTarget.TimeElapsed) { result = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj b/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj index 3d64da99bc..0c85af38cc 100644 --- a/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj +++ b/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj @@ -6,7 +6,8 @@ - + + diff --git a/src/Ryujinx.Graphics.OpenGL/Sync.cs b/src/Ryujinx.Graphics.OpenGL/Sync.cs index eba1638a35..4699378898 100644 --- a/src/Ryujinx.Graphics.OpenGL/Sync.cs +++ b/src/Ryujinx.Graphics.OpenGL/Sync.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Logging; using System; using System.Collections.Generic; diff --git a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs index 32211e7831..6cde939eb2 100644 --- a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; using System; using System.Numerics; @@ -134,19 +134,19 @@ namespace Ryujinx.Graphics.OpenGL public void SetIndexBuffer(BufferRange range) { _indexBuffer = range; - GL.BindBuffer(BufferTarget.ElementArrayBuffer, range.Handle.ToInt32()); + GL.BindBuffer(BufferTargetARB.ElementArrayBuffer, range.Handle.ToInt32()); } public void SetRangeOfIndexBuffer() { Buffer.Resize(_tempIndexBuffer, _indexBuffer.Size); Buffer.Copy(_indexBuffer.Handle, _tempIndexBuffer, _indexBuffer.Offset, 0, _indexBuffer.Size); - GL.BindBuffer(BufferTarget.ElementArrayBuffer, _tempIndexBuffer.ToInt32()); + GL.BindBuffer(BufferTargetARB.ElementArrayBuffer, _tempIndexBuffer.ToInt32()); } public void RestoreIndexBuffer() { - GL.BindBuffer(BufferTarget.ElementArrayBuffer, _indexBuffer.Handle.ToInt32()); + GL.BindBuffer(BufferTargetARB.ElementArrayBuffer, _indexBuffer.Handle.ToInt32()); } public void PreDraw(int vertexCount) diff --git a/src/Ryujinx.Graphics.OpenGL/Window.cs b/src/Ryujinx.Graphics.OpenGL/Window.cs index 6bcfefa4ed..69bbe7034a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Window.cs +++ b/src/Ryujinx.Graphics.OpenGL/Window.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Effects; using Ryujinx.Graphics.OpenGL.Effects.Smaa; diff --git a/src/Ryujinx.Gtk3/Ryujinx.Gtk3.csproj b/src/Ryujinx.Gtk3/Ryujinx.Gtk3.csproj index 68bf98981e..7679c8230e 100644 --- a/src/Ryujinx.Gtk3/Ryujinx.Gtk3.csproj +++ b/src/Ryujinx.Gtk3/Ryujinx.Gtk3.csproj @@ -27,7 +27,6 @@ - diff --git a/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs b/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs index 1fdabc754b..6133c8be05 100644 --- a/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs +++ b/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Input.HLE; diff --git a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs index 97feb43454..fde1762209 100644 --- a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs +++ b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Graphics.OpenGL; using SPB.Graphics; using SPB.Graphics.OpenGL; diff --git a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs index 7ea6e14813..9ac0408abb 100644 --- a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs +++ b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs @@ -1,5 +1,5 @@ using OpenTK; -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.OpenGL; From 0d72c7650a6c4d37e070a3f3f2d02749210a5a44 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 8 May 2024 22:36:19 -0400 Subject: [PATCH 03/35] Slowly but surely --- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 76 +++++----- src/Ryujinx.Graphics.OpenGL/Debugger.cs | 38 ++--- .../DrawTextureEmulation.cs | 65 ++++----- src/Ryujinx.Graphics.OpenGL/EnumConversion.cs | 4 +- src/Ryujinx.Graphics.OpenGL/Framebuffer.cs | 40 +++--- src/Ryujinx.Graphics.OpenGL/Handle.cs | 8 +- src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs | 10 +- .../Image/ITextureInfo.cs | 2 +- .../Image/ImageArray.cs | 16 ++- src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs | 40 +++--- .../Image/TextureArray.cs | 11 +- .../Image/TextureBase.cs | 23 +-- .../Image/TextureBuffer.cs | 10 +- .../Image/TextureCopy.cs | 132 +++++++++--------- src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 9 +- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 6 +- 16 files changed, 253 insertions(+), 237 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index d464172c6c..6a56638b64 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -6,9 +6,9 @@ namespace Ryujinx.Graphics.OpenGL { static class Buffer { - public static void Clear(BufferHandle destination, int offset, int size, uint value) + public static void Clear(GL api, BufferHandle destination, int offset, uint size, uint value) { - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, destination.ToInt32()); + api.BindBuffer(BufferTargetARB.CopyWriteBuffer, destination.ToUInt32()); unsafe { @@ -16,60 +16,60 @@ namespace Ryujinx.Graphics.OpenGL valueArr[0] = value; - GL.ClearBufferSubData( + api.ClearBufferSubData( BufferTargetARB.CopyWriteBuffer, - InternalFormat.Rgba8ui, - (IntPtr)offset, - (IntPtr)size, + SizedInternalFormat.Rgba8ui, + offset, + size, PixelFormat.RgbaInteger, PixelType.UnsignedByte, (IntPtr)valueArr); } } - public static BufferHandle Create() + public static BufferHandle Create(GL api) { - return Handle.FromInt32(GL.GenBuffer()); + return Handle.FromUInt32(api.GenBuffer()); } - public static BufferHandle Create(int size) + public static BufferHandle Create(GL api, int size) { - int handle = GL.GenBuffer(); + uint handle = api.GenBuffer(); - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); - GL.BufferData(BufferTargetARB.CopyWriteBuffer, size, IntPtr.Zero, BufferUsageARB.DynamicDraw); + api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); + api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, UIntPtr.Zero, BufferUsageARB.DynamicDraw); - return Handle.FromInt32(handle); + return Handle.FromUInt32(handle); } - public static BufferHandle CreatePersistent(int size) + public static BufferHandle CreatePersistent(GL api, int size) { - int handle = GL.GenBuffer(); + uint handle = api.GenBuffer(); - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); - GL.BufferStorage(BufferTargetARB.CopyWriteBuffer, size, IntPtr.Zero, + api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); + api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)size, UIntPtr.Zero, BufferStorageMask.MapPersistentBit | BufferStorageMask.MapCoherentBit | BufferStorageMask.ClientStorageBit | BufferStorageMask.MapReadBit); - return Handle.FromInt32(handle); + return Handle.FromUInt32(handle); } - public static void Copy(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size) + public static void Copy(GL api, BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size) { - GL.BindBuffer(BufferTargetARB.CopyReadBuffer, source.ToInt32()); - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, destination.ToInt32()); + api.BindBuffer(BufferTargetARB.CopyReadBuffer, source.ToUInt32()); + api.BindBuffer(BufferTargetARB.CopyWriteBuffer, destination.ToUInt32()); - GL.CopyBufferSubData( - BufferTargetARB.CopyReadBuffer, - BufferTargetARB.CopyWriteBuffer, - (IntPtr)srcOffset, - (IntPtr)dstOffset, - (IntPtr)size); + api.CopyBufferSubData( + CopyBufferSubDataTarget.CopyReadBuffer, + CopyBufferSubDataTarget.CopyWriteBuffer, + srcOffset, + dstOffset, + (uint)size); } - public static unsafe PinnedSpan GetData(OpenGLRenderer renderer, BufferHandle buffer, int offset, int size) + public static unsafe PinnedSpan GetData(GL api, OpenGLRenderer renderer, BufferHandle buffer, int offset, int size) { // Data in the persistent buffer and host array is guaranteed to be available // until the next time the host thread requests data. @@ -86,36 +86,36 @@ namespace Ryujinx.Graphics.OpenGL { IntPtr target = renderer.PersistentBuffers.Default.GetHostArray(size); - GL.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToInt32()); + api.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToUInt32()); - GL.GetBufferSubData(BufferTargetARB.CopyReadBuffer, (IntPtr)offset, size, target); + api.GetBufferSubData(BufferTargetARB.CopyReadBuffer, offset, (uint)size, target); return new PinnedSpan(target.ToPointer(), size); } } - public static void Resize(BufferHandle handle, int size) + public static void Resize(GL api, BufferHandle handle, int size) { - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToInt32()); - GL.BufferData(BufferTargetARB.CopyWriteBuffer, size, IntPtr.Zero, BufferUsageARB.StreamCopy); + api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); + api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, UIntPtr.Zero, BufferUsageARB.StreamCopy); } - public static void SetData(BufferHandle buffer, int offset, ReadOnlySpan data) + public static void SetData(GL api, BufferHandle buffer, int offset, ReadOnlySpan data) { - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, buffer.ToInt32()); + api.BindBuffer(BufferTargetARB.CopyWriteBuffer, buffer.ToUInt32()); unsafe { fixed (byte* ptr = data) { - GL.BufferSubData(BufferTargetARB.CopyWriteBuffer, (IntPtr)offset, data.Length, (IntPtr)ptr); + api.BufferSubData(BufferTargetARB.CopyWriteBuffer, offset, (uint)data.Length, (IntPtr)ptr); } } } - public static void Delete(BufferHandle buffer) + public static void Delete(GL api, BufferHandle buffer) { - GL.DeleteBuffer(buffer.ToInt32()); + api.DeleteBuffer(buffer.ToUInt32()); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Debugger.cs b/src/Ryujinx.Graphics.OpenGL/Debugger.cs index 498928743e..0969ede504 100644 --- a/src/Ryujinx.Graphics.OpenGL/Debugger.cs +++ b/src/Ryujinx.Graphics.OpenGL/Debugger.cs @@ -13,48 +13,48 @@ namespace Ryujinx.Graphics.OpenGL private static int _counter; - public static void Initialize(GraphicsDebugLevel logLevel) + public static void Initialize(GL gl, GraphicsDebugLevel logLevel) { // Disable everything - GL.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, false); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, false); if (logLevel == GraphicsDebugLevel.None) { - GL.Disable(EnableCap.DebugOutputSynchronous); - GL.DebugMessageCallback(null, IntPtr.Zero); + gl.Disable(EnableCap.DebugOutputSynchronous); + gl.DebugMessageCallback(null, IntPtr.Zero); return; } - GL.Enable(EnableCap.DebugOutputSynchronous); + gl.Enable(EnableCap.DebugOutputSynchronous); if (logLevel == GraphicsDebugLevel.Error) { - GL.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); } else if (logLevel == GraphicsDebugLevel.Slowdowns) { - GL.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); - GL.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypePerformance, DebugSeverity.DontCare, 0, (int[])null, true); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypePerformance, DebugSeverity.DontCare, 0, (int[])null, true); } else { - GL.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, true); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, true); } _counter = 0; _debugCallback = GLDebugHandler; - GL.DebugMessageCallback(_debugCallback, IntPtr.Zero); + gl.DebugMessageCallback(_debugCallback, IntPtr.Zero); Logger.Warning?.Print(LogClass.Gpu, "OpenGL Debugging is enabled. Performance will be negatively impacted."); } private static void GLDebugHandler( - DebugSource source, - DebugType type, + GLEnum source, + GLEnum type, int id, - DebugSeverity severity, + GLEnum severity, int length, IntPtr message, IntPtr userParam) @@ -89,21 +89,21 @@ namespace Ryujinx.Graphics.OpenGL } // Useful debug helpers - public static void PushGroup(string dbgMsg) + public static void PushGroup(GL gl, string dbgMsg) { int counter = Interlocked.Increment(ref _counter); - GL.PushDebugGroup(DebugSource.DebugSourceApplication, counter, dbgMsg.Length, dbgMsg); + gl.PushDebugGroup(DebugSource.DebugSourceApplication, counter, dbgMsg.Length, dbgMsg); } - public static void PopGroup() + public static void PopGroup(GL gl) { - GL.PopDebugGroup(); + gl.PopDebugGroup(); } - public static void Print(string dbgMsg, DebugType type = DebugType.DebugTypeMarker, DebugSeverity severity = DebugSeverity.DebugSeverityNotification, int id = 999999) + public static void Print(GL gl, string dbgMsg, DebugType type = DebugType.DebugTypeMarker, DebugSeverity severity = DebugSeverity.DebugSeverityNotification, int id = 999999) { - GL.DebugMessageInsert(DebugSource.DebugSourceApplication, type, id, severity, dbgMsg.Length, dbgMsg); + gl.DebugMessageInsert(DebugSource.DebugSourceApplication, type, id, severity, dbgMsg.Length, dbgMsg); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs index 7b33ceda0d..0d13fe7917 100644 --- a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs +++ b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs @@ -35,9 +35,9 @@ void main() colour = texture(tex, texcoord); }"; - private int _vsHandle; - private int _fsHandle; - private int _programHandle; + private uint _vsHandle; + private uint _fsHandle; + private uint _programHandle; private int _uniformSrcX0Location; private int _uniformSrcY0Location; private int _uniformSrcX1Location; @@ -45,6 +45,7 @@ void main() private bool _initialized; public void Draw( + GL api, TextureView texture, Sampler sampler, float x0, @@ -56,9 +57,9 @@ void main() float s1, float t1) { - EnsureInitialized(); + EnsureInitialized(api); - GL.UseProgram(_programHandle); + api.UseProgram(_programHandle); texture.Bind(0); sampler.Bind(0); @@ -73,17 +74,17 @@ void main() (t1, t0) = (t0, t1); } - GL.Uniform1(_uniformSrcX0Location, s0); - GL.Uniform1(_uniformSrcY0Location, t0); - GL.Uniform1(_uniformSrcX1Location, s1); - GL.Uniform1(_uniformSrcY1Location, t1); + api.Uniform1(_uniformSrcX0Location, s0); + api.Uniform1(_uniformSrcY0Location, t0); + api.Uniform1(_uniformSrcX1Location, s1); + api.Uniform1(_uniformSrcY1Location, t1); - GL.ViewportIndexed(0, MathF.Min(x0, x1), MathF.Min(y0, y1), MathF.Abs(x1 - x0), MathF.Abs(y1 - y0)); + api.ViewportIndexed(0, MathF.Min(x0, x1), MathF.Min(y0, y1), MathF.Abs(x1 - x0), MathF.Abs(y1 - y0)); - GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4); + api.DrawArrays(PrimitiveType.TriangleStrip, 0, 4); } - private void EnsureInitialized() + private void EnsureInitialized(GL api) { if (_initialized) { @@ -92,41 +93,41 @@ void main() _initialized = true; - _vsHandle = GL.CreateShader(ShaderType.VertexShader); - _fsHandle = GL.CreateShader(ShaderType.FragmentShader); + _vsHandle = api.CreateShader(ShaderType.VertexShader); + _fsHandle = api.CreateShader(ShaderType.FragmentShader); - GL.ShaderSource(_vsHandle, VertexShader); - GL.ShaderSource(_fsHandle, FragmentShader); + api.ShaderSource(_vsHandle, VertexShader); + api.ShaderSource(_fsHandle, FragmentShader); - GL.CompileShader(_vsHandle); - GL.CompileShader(_fsHandle); + api.CompileShader(_vsHandle); + api.CompileShader(_fsHandle); - _programHandle = GL.CreateProgram(); + _programHandle = api.CreateProgram(); - GL.AttachShader(_programHandle, _vsHandle); - GL.AttachShader(_programHandle, _fsHandle); + api.AttachShader(_programHandle, _vsHandle); + api.AttachShader(_programHandle, _fsHandle); - GL.LinkProgram(_programHandle); + api.LinkProgram(_programHandle); - GL.DetachShader(_programHandle, _vsHandle); - GL.DetachShader(_programHandle, _fsHandle); + api.DetachShader(_programHandle, _vsHandle); + api.DetachShader(_programHandle, _fsHandle); - _uniformSrcX0Location = GL.GetUniformLocation(_programHandle, "srcX0"); - _uniformSrcY0Location = GL.GetUniformLocation(_programHandle, "srcY0"); - _uniformSrcX1Location = GL.GetUniformLocation(_programHandle, "srcX1"); - _uniformSrcY1Location = GL.GetUniformLocation(_programHandle, "srcY1"); + _uniformSrcX0Location = api.GetUniformLocation(_programHandle, "srcX0"); + _uniformSrcY0Location = api.GetUniformLocation(_programHandle, "srcY0"); + _uniformSrcX1Location = api.GetUniformLocation(_programHandle, "srcX1"); + _uniformSrcY1Location = api.GetUniformLocation(_programHandle, "srcY1"); } - public void Dispose() + public void Dispose(GL api) { if (!_initialized) { return; } - GL.DeleteShader(_vsHandle); - GL.DeleteShader(_fsHandle); - GL.DeleteProgram(_programHandle); + api.DeleteShader(_vsHandle); + api.DeleteShader(_fsHandle); + api.DeleteProgram(_programHandle); _initialized = false; } diff --git a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs index 6c02e48752..24df59aa06 100644 --- a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -552,9 +552,9 @@ namespace Ryujinx.Graphics.OpenGL return All.Zero; } - public static ImageTarget ConvertToImageTarget(this Target target) + public static CopyImageSubDataTarget ConvertToImageTarget(this Target target) { - return (ImageTarget)target.Convert(); + return (CopyImageSubDataTarget)target.Convert(); } public static TextureTarget Convert(this Target target) diff --git a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs index 1c1334d3aa..4c63b15064 100644 --- a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -8,8 +8,8 @@ namespace Ryujinx.Graphics.OpenGL { class Framebuffer : IDisposable { - public int Handle { get; private set; } - private int _clearFbHandle; + public uint Handle { get; private set; } + private uint _clearFbHandle; private bool _clearFbInitialized; private FramebufferAttachment _lastDsAttachment; @@ -19,18 +19,20 @@ namespace Ryujinx.Graphics.OpenGL private int _colorsCount; private bool _dualSourceBlend; + private GL _api; - public Framebuffer() + public Framebuffer(GL api) { Handle = GL.GenFramebuffer(); _clearFbHandle = GL.GenFramebuffer(); _colors = new TextureView[8]; + _api = api; } public int Bind() { - GL.BindFramebuffer(FramebufferTarget.Framebuffer, Handle); + _api.BindFramebuffer(FramebufferTarget.Framebuffer, Handle); return Handle; } @@ -44,7 +46,7 @@ namespace Ryujinx.Graphics.OpenGL FramebufferAttachment attachment = FramebufferAttachment.ColorAttachment0 + index; - GL.FramebufferTexture(FramebufferTarget.Framebuffer, attachment, color?.Handle ?? 0, 0); + _api.FramebufferTexture(FramebufferTarget.Framebuffer, attachment, color?.Handle ?? 0, 0); _colors[index] = color; } @@ -54,14 +56,14 @@ namespace Ryujinx.Graphics.OpenGL // Detach the last depth/stencil buffer if there is any. if (_lastDsAttachment != 0) { - GL.FramebufferTexture(FramebufferTarget.Framebuffer, _lastDsAttachment, 0, 0); + _api.FramebufferTexture(FramebufferTarget.Framebuffer, _lastDsAttachment, 0, 0); } if (depthStencil != null) { FramebufferAttachment attachment = GetAttachment(depthStencil.Format); - GL.FramebufferTexture( + _api.FramebufferTexture( FramebufferTarget.Framebuffer, attachment, depthStencil.Handle, @@ -87,11 +89,11 @@ namespace Ryujinx.Graphics.OpenGL // we can only have one draw buffer. if (enable) { - GL.DrawBuffer(DrawBufferMode.ColorAttachment0); + _api.DrawBuffer(DrawBufferMode.ColorAttachment0); } else if (oldEnable) { - SetDrawBuffersImpl(_colorsCount); + SetDrawBuffersImpl(_api, _colorsCount); } } @@ -99,13 +101,13 @@ namespace Ryujinx.Graphics.OpenGL { if (_colorsCount != colorsCount && !_dualSourceBlend) { - SetDrawBuffersImpl(colorsCount); + SetDrawBuffersImpl(_api, colorsCount); } _colorsCount = colorsCount; } - private static void SetDrawBuffersImpl(int colorsCount) + private static void SetDrawBuffersImpl(GL api, int colorsCount) { DrawBufferMode[] drawBuffers = new DrawBufferMode[colorsCount]; @@ -114,7 +116,7 @@ namespace Ryujinx.Graphics.OpenGL drawBuffers[index] = DrawBufferMode.ColorAttachment0 + index; } - GL.DrawBuffers(colorsCount, drawBuffers); + api.DrawBuffers(colorsCount, drawBuffers); } private static FramebufferAttachment GetAttachment(Format format) @@ -153,7 +155,7 @@ namespace Ryujinx.Graphics.OpenGL } BindClearFb(); - GL.FramebufferTextureLayer(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + index, color.Handle, 0, layer); + _api.FramebufferTextureLayer(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + index, color.Handle, 0, layer); } public void DetachColorLayerForClear(int index) @@ -165,7 +167,7 @@ namespace Ryujinx.Graphics.OpenGL return; } - GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + index, 0, 0); + _api.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + index, 0, 0); Bind(); } @@ -179,7 +181,7 @@ namespace Ryujinx.Graphics.OpenGL } BindClearFb(); - GL.FramebufferTextureLayer(FramebufferTarget.Framebuffer, GetAttachment(depthStencil.Format), depthStencil.Handle, 0, layer); + _api.FramebufferTextureLayer(FramebufferTarget.Framebuffer, GetAttachment(depthStencil.Format), depthStencil.Handle, 0, layer); } public void DetachDepthStencilLayerForClear() @@ -191,13 +193,13 @@ namespace Ryujinx.Graphics.OpenGL return; } - GL.FramebufferTexture(FramebufferTarget.Framebuffer, GetAttachment(depthStencil.Format), 0, 0); + _api.FramebufferTexture(FramebufferTarget.Framebuffer, GetAttachment(depthStencil.Format), 0, 0); Bind(); } private void BindClearFb() { - GL.BindFramebuffer(FramebufferTarget.Framebuffer, _clearFbHandle); + _api.BindFramebuffer(FramebufferTarget.Framebuffer, _clearFbHandle); if (!_clearFbInitialized) { @@ -219,14 +221,14 @@ namespace Ryujinx.Graphics.OpenGL { if (Handle != 0) { - GL.DeleteFramebuffer(Handle); + _api.DeleteFramebuffer(Handle); Handle = 0; } if (_clearFbHandle != 0) { - GL.DeleteFramebuffer(_clearFbHandle); + _api.DeleteFramebuffer(_clearFbHandle); _clearFbHandle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Handle.cs b/src/Ryujinx.Graphics.OpenGL/Handle.cs index b63e8f946f..e630f950f1 100644 --- a/src/Ryujinx.Graphics.OpenGL/Handle.cs +++ b/src/Ryujinx.Graphics.OpenGL/Handle.cs @@ -6,18 +6,18 @@ namespace Ryujinx.Graphics.OpenGL { static class Handle { - public static T FromInt32(int handle) where T : unmanaged + public static T FromUInt32(uint handle) where T : unmanaged { Debug.Assert(Unsafe.SizeOf() == sizeof(ulong)); - ulong handle64 = (uint)handle; + ulong handle64 = handle; return Unsafe.As(ref handle64); } - public static int ToInt32(this BufferHandle handle) + public static uint ToUInt32(this BufferHandle handle) { - return (int)Unsafe.As(ref handle); + return (uint)Unsafe.As(ref handle); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs b/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs index a7a47b075c..0788a5736c 100644 --- a/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs +++ b/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs @@ -131,13 +131,13 @@ namespace Ryujinx.Graphics.OpenGL } } - private static bool SupportsQuadsCheck() + private static bool SupportsQuadsCheck(GL api) { - GL.GetError(); // Clear any existing error. - GL.Begin(PrimitiveType.Quads); - GL.End(); + api.GetError(); // Clear any existing error. + api.Begin(PrimitiveType.Quads); + api.End(); - return GL.GetError() == ErrorCode.NoError; + return api.GetError() == ErrorCode.NoError; } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/ITextureInfo.cs b/src/Ryujinx.Graphics.OpenGL/Image/ITextureInfo.cs index fecde6dd08..464d005bfe 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/ITextureInfo.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/ITextureInfo.cs @@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.OpenGL.Image interface ITextureInfo { ITextureInfo Storage { get; } - int Handle { get; } + uint Handle { get; } int FirstLayer => 0; int FirstLevel => 0; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs index 6e1a0819be..697039742a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs @@ -7,18 +7,20 @@ namespace Ryujinx.Graphics.OpenGL.Image { private record struct TextureRef { - public int Handle; + public uint Handle; public Format Format; } private readonly TextureRef[] _images; + private GL _api; - public ImageArray(int size) + public ImageArray(GL api, int size) { + _api = api; _images = new TextureRef[size]; } - public void SetFormats(int index, GAL.Format[] imageFormats) + public void SetFormats(int index, Format[] imageFormats) { for (int i = 0; i < imageFormats.Length; i++) { @@ -43,21 +45,21 @@ namespace Ryujinx.Graphics.OpenGL.Image } } - public void Bind(int baseBinding) + public void Bind(uint baseBinding) { for (int i = 0; i < _images.Length; i++) { if (_images[i].Handle == 0) { - GL.BindImageTexture(baseBinding + i, 0, 0, true, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _api.BindImageTexture((uint)(baseBinding + i), 0, 0, true, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); } else { - SizedInternalFormat format = FormatTable.GetImageFormat(_images[i].Format); + InternalFormat format = (InternalFormat)FormatTable.GetImageFormat(_images[i].Format); if (format != 0) { - GL.BindImageTexture(baseBinding + i, _images[i].Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); + _api.BindImageTexture((uint)(baseBinding + i), _images[i].Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs index e06e6b22dc..08e44dfbd7 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs @@ -5,26 +5,28 @@ namespace Ryujinx.Graphics.OpenGL.Image { class Sampler : ISampler { - public int Handle { get; private set; } + public uint Handle { get; private set; } + private GL _api; - public Sampler(SamplerCreateInfo info) + public Sampler(GL api, SamplerCreateInfo info) { - Handle = GL.GenSampler(); + _api = api; + Handle = _api.GenSampler(); - GL.SamplerParameter(Handle, SamplerParameterI.MinFilter, (int)info.MinFilter.Convert()); - GL.SamplerParameter(Handle, SamplerParameterI.MagFilter, (int)info.MagFilter.Convert()); + _api.SamplerParameter(Handle, SamplerParameterI.MinFilter, (int)info.MinFilter.Convert()); + _api.SamplerParameter(Handle, SamplerParameterI.MagFilter, (int)info.MagFilter.Convert()); if (HwCapabilities.SupportsSeamlessCubemapPerTexture) { - GL.SamplerParameter(Handle, (SamplerParameterName)ArbSeamlessCubemapPerTexture.TextureCubeMapSeamless, info.SeamlessCubemap ? 1 : 0); + _api.SamplerParameter(Handle, GLEnum.TextureCubeMapSeamless, info.SeamlessCubemap ? 1 : 0); } - GL.SamplerParameter(Handle, SamplerParameterI.WrapS, (int)info.AddressU.Convert()); - GL.SamplerParameter(Handle, SamplerParameterI.WrapT, (int)info.AddressV.Convert()); - GL.SamplerParameter(Handle, SamplerParameterI.WrapR, (int)info.AddressP.Convert()); + _api.SamplerParameter(Handle, SamplerParameterI.WrapS, (int)info.AddressU.Convert()); + _api.SamplerParameter(Handle, SamplerParameterI.WrapT, (int)info.AddressV.Convert()); + _api.SamplerParameter(Handle, SamplerParameterI.WrapR, (int)info.AddressP.Convert()); - GL.SamplerParameter(Handle, SamplerParameterI.CompareMode, (int)info.CompareMode.Convert()); - GL.SamplerParameter(Handle, SamplerParameterI.CompareFunc, (int)info.CompareOp.Convert()); + _api.SamplerParameter(Handle, SamplerParameterI.CompareMode, (int)info.CompareMode.Convert()); + _api.SamplerParameter(Handle, SamplerParameterI.CompareFunc, (int)info.CompareOp.Convert()); unsafe { @@ -36,26 +38,26 @@ namespace Ryujinx.Graphics.OpenGL.Image info.BorderColor.Alpha, }; - GL.SamplerParameter(Handle, SamplerParameterF.BorderColor, borderColor); + _api.SamplerParameter(Handle, SamplerParameterF.BorderColor, borderColor); } - GL.SamplerParameter(Handle, SamplerParameterF.TextureMinLod, info.MinLod); - GL.SamplerParameter(Handle, SamplerParameterF.TextureMaxLod, info.MaxLod); - GL.SamplerParameter(Handle, SamplerParameterF.TextureLodBias, info.MipLodBias); + _api.SamplerParameter(Handle, SamplerParameterF.TextureMinLod, info.MinLod); + _api.SamplerParameter(Handle, SamplerParameterF.TextureMaxLod, info.MaxLod); + _api.SamplerParameter(Handle, SamplerParameterF.TextureLodBias, info.MipLodBias); - GL.SamplerParameter(Handle, SamplerParameterF.MaxAnisotropy, info.MaxAnisotropy); + _api.SamplerParameter(Handle, SamplerParameterF.MaxAnisotropy, info.MaxAnisotropy); } - public void Bind(int unit) + public void Bind(uint unit) { - GL.BindSampler(unit, Handle); + _api.BindSampler(unit, Handle); } public void Dispose() { if (Handle != 0) { - GL.DeleteSampler(Handle); + _api.DeleteSampler(Handle); Handle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs index d70b0a0081..7172971448 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs @@ -1,4 +1,5 @@ using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL; namespace Ryujinx.Graphics.OpenGL.Image { @@ -11,9 +12,11 @@ namespace Ryujinx.Graphics.OpenGL.Image } private readonly TextureRef[] _textureRefs; + private GL _api; - public TextureArray(int size) + public TextureArray(GL api, int size) { + _api = api; _textureRefs = new TextureRef[size]; } @@ -33,9 +36,9 @@ namespace Ryujinx.Graphics.OpenGL.Image } } - public void Bind(int baseBinding) + public void Bind(uint baseBinding) { - for (int i = 0; i < _textureRefs.Length; i++) + for (uint i = 0; i < _textureRefs.Length; i++) { if (_textureRefs[i].Texture != null) { @@ -44,7 +47,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } else { - TextureBase.ClearBinding(baseBinding + i); + TextureBase.ClearBinding(_api, baseBinding + i); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs index 084d8003a4..6dc5ae6d4d 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs @@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { class TextureBase { - public int Handle { get; protected set; } + public uint Handle { get; protected set; } public TextureCreateInfo Info { get; } @@ -15,28 +15,31 @@ namespace Ryujinx.Graphics.OpenGL.Image public Target Target => Info.Target; public Format Format => Info.Format; - public TextureBase(TextureCreateInfo info) + private protected GL _api; + + public TextureBase(GL api, TextureCreateInfo info) { + _api = api; Info = info; - Handle = GL.GenTexture(); + Handle = _api.GenTexture(); } - public void Bind(int unit) + public void Bind(uint unit) { Bind(Target.Convert(), unit); } - protected void Bind(TextureTarget target, int unit) + protected void Bind(TextureTarget target, uint unit) { - GL.ActiveTexture(TextureUnit.Texture0 + unit); - GL.BindTexture(target, Handle); + _api.ActiveTexture((TextureUnit)((uint)TextureUnit.Texture0 + unit)); + _api.BindTexture(target, Handle); } - public static void ClearBinding(int unit) + public static void ClearBinding(GL api, uint unit) { - GL.ActiveTexture(TextureUnit.Texture0 + unit); - GL.BindTextureUnit(unit, 0); + api.ActiveTexture((TextureUnit)((uint)TextureUnit.Texture0 + unit)); + api.BindTextureUnit(unit, 0); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs index 755364c33b..5f75638d96 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs @@ -14,7 +14,7 @@ namespace Ryujinx.Graphics.OpenGL.Image private BufferHandle _buffer; - public TextureBuffer(OpenGLRenderer renderer, TextureCreateInfo info) : base(info) + public TextureBuffer(GL api, OpenGLRenderer renderer, TextureCreateInfo info) : base(api, info) { _renderer = renderer; } @@ -41,7 +41,7 @@ namespace Ryujinx.Graphics.OpenGL.Image public PinnedSpan GetData() { - return Buffer.GetData(_renderer, _buffer, _bufferOffset, _bufferSize); + return Buffer.GetData(_api, _renderer, _buffer, _bufferOffset, _bufferSize); } public PinnedSpan GetData(int layer, int level) @@ -59,7 +59,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { var dataSpan = data.Memory.Span; - Buffer.SetData(_buffer, _bufferOffset, dataSpan[..Math.Min(dataSpan.Length, _bufferSize)]); + Buffer.SetData(_api, _buffer, _bufferOffset, dataSpan[..Math.Min(dataSpan.Length, _bufferSize)]); data.Dispose(); } @@ -97,14 +97,14 @@ namespace Ryujinx.Graphics.OpenGL.Image SizedInternalFormat format = (SizedInternalFormat)FormatTable.GetFormatInfo(Info.Format).InternalFormat; - GL.TexBufferRange(TextureTarget.TextureBuffer, format, _buffer.ToInt32(), (IntPtr)buffer.Offset, buffer.Size); + _api.TexBufferRange(TextureTarget.TextureBuffer, format, _buffer.ToUInt32(), buffer.Offset, (uint)buffer.Size); } public void Dispose() { if (Handle != 0) { - GL.DeleteTexture(Handle); + _api.DeleteTexture(Handle); Handle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index 2b3fd891f5..4667dd6f72 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -7,18 +7,20 @@ namespace Ryujinx.Graphics.OpenGL.Image { class TextureCopy : IDisposable { + private GL _api; private readonly OpenGLRenderer _renderer; - private int _srcFramebuffer; - private int _dstFramebuffer; + private uint _srcFramebuffer; + private uint _dstFramebuffer; - private int _copyPboHandle; + private uint _copyPboHandle; private int _copyPboSize; public IntermediatePool IntermediatePool { get; } - public TextureCopy(OpenGLRenderer renderer) + public TextureCopy(GL api, OpenGLRenderer renderer) { + _api = api; _renderer = renderer; IntermediatePool = new IntermediatePool(renderer); } @@ -55,10 +57,10 @@ namespace Ryujinx.Graphics.OpenGL.Image { TextureView srcConverted = src.Format.IsBgr() != dst.Format.IsBgr() ? BgraSwap(src) : src; - (int oldDrawFramebufferHandle, int oldReadFramebufferHandle) = ((Pipeline)_renderer.Pipeline).GetBoundFramebuffers(); + (uint oldDrawFramebufferHandle, uint oldReadFramebufferHandle) = ((Pipeline)_renderer.Pipeline).GetBoundFramebuffers(); - GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, GetSrcFramebufferLazy()); - GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, GetDstFramebufferLazy()); + _api.BindFramebuffer(FramebufferTarget.ReadFramebuffer, GetSrcFramebufferLazy()); + _api.BindFramebuffer(FramebufferTarget.DrawFramebuffer, GetDstFramebufferLazy()); if (srcLevel != 0) { @@ -76,13 +78,13 @@ namespace Ryujinx.Graphics.OpenGL.Image { if ((srcLayer | dstLayer) != 0 || layers > 1) { - Attach(FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, srcLevel + level, srcLayer + layer); - Attach(FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, dstLevel + level, dstLayer + layer); + Attach(_api, FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, srcLevel + level, srcLayer + layer); + Attach(_api, FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, dstLevel + level, dstLayer + layer); } else { - Attach(FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, srcLevel + level); - Attach(FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, dstLevel + level); + Attach(_api, FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, srcLevel + level); + Attach(_api, FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, dstLevel + level); } ClearBufferMask mask = GetMask(src.Format); @@ -96,13 +98,13 @@ namespace Ryujinx.Graphics.OpenGL.Image ? BlitFramebufferFilter.Linear : BlitFramebufferFilter.Nearest; - GL.ReadBuffer(ReadBufferMode.ColorAttachment0); - GL.DrawBuffer(DrawBufferMode.ColorAttachment0); + _api.ReadBuffer(ReadBufferMode.ColorAttachment0); + _api.DrawBuffer(DrawBufferMode.ColorAttachment0); - GL.Disable(EnableCap.RasterizerDiscard); - GL.Disable(IndexedEnableCap.ScissorTest, 0); + _api.Disable(EnableCap.RasterizerDiscard); + _api.Disable(EnableCap.ScissorTest, 0); - GL.BlitFramebuffer( + _api.BlitFramebuffer( srcRegion.X1, srcRegion.Y1, srcRegion.X2, @@ -122,11 +124,11 @@ namespace Ryujinx.Graphics.OpenGL.Image } } - Attach(FramebufferTarget.ReadFramebuffer, src.Format, 0); - Attach(FramebufferTarget.DrawFramebuffer, dst.Format, 0); + Attach(_api, FramebufferTarget.ReadFramebuffer, src.Format, 0); + Attach(_api, FramebufferTarget.DrawFramebuffer, dst.Format, 0); - GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, oldReadFramebufferHandle); - GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, oldDrawFramebufferHandle); + _api.BindFramebuffer(FramebufferTarget.ReadFramebuffer, oldReadFramebufferHandle); + _api.BindFramebuffer(FramebufferTarget.DrawFramebuffer, oldDrawFramebufferHandle); ((Pipeline)_renderer.Pipeline).RestoreScissor0Enable(); ((Pipeline)_renderer.Pipeline).RestoreRasterizerDiscard(); @@ -178,8 +180,8 @@ namespace Ryujinx.Graphics.OpenGL.Image TextureCreateInfo srcInfo = src.Info; TextureCreateInfo dstInfo = dst.Info; - int srcHandle = src.Handle; - int dstHandle = dst.Handle; + uint srcHandle = (uint)src.Handle; + uint dstHandle = (uint)dst.Handle; int srcWidth = srcInfo.Width; int srcHeight = srcInfo.Height; @@ -240,7 +242,7 @@ namespace Ryujinx.Graphics.OpenGL.Image if (HwCapabilities.Vendor == HwCapabilities.GpuVendor.IntelWindows) { - GL.CopyImageSubData( + _api.CopyImageSubData( src.Storage.Handle, src.Storage.Info.Target.ConvertToImageTarget(), src.FirstLevel + srcLevel + level, @@ -253,13 +255,13 @@ namespace Ryujinx.Graphics.OpenGL.Image 0, 0, dst.FirstLayer + dstLayer, - copyWidth, - copyHeight, - depth); + (uint)copyWidth, + (uint)copyHeight, + (uint)depth); } else { - GL.CopyImageSubData( + _api.CopyImageSubData( srcHandle, srcInfo.Target.ConvertToImageTarget(), srcLevel + level, @@ -272,9 +274,9 @@ namespace Ryujinx.Graphics.OpenGL.Image 0, 0, dstLayer, - copyWidth, - copyHeight, - depth); + (uint)copyWidth, + (uint)copyHeight, + (uint)depth); } } @@ -308,18 +310,18 @@ namespace Ryujinx.Graphics.OpenGL.Image } } - private static void Attach(FramebufferTarget target, Format format, int handle, int level = 0) + private static void Attach(GL api, FramebufferTarget target, Format format, uint handle, int level = 0) { FramebufferAttachment attachment = AttachmentForFormat(format); - GL.FramebufferTexture(target, attachment, handle, level); + api.FramebufferTexture(target, attachment, handle, level); } - private static void Attach(FramebufferTarget target, Format format, int handle, int level, int layer) + private static void Attach(GL api, FramebufferTarget target, Format format, uint handle, int level, int layer) { FramebufferAttachment attachment = AttachmentForFormat(format); - GL.FramebufferTextureLayer(target, attachment, handle, level, layer); + api.FramebufferTextureLayer(target, attachment, handle, level, layer); } private static ClearBufferMask GetMask(Format format) @@ -348,16 +350,16 @@ namespace Ryujinx.Graphics.OpenGL.Image EnsurePbo(from); - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); + _api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); from.WriteToPbo(0, forceBgra: true); - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); - GL.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); + _api.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); + _api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); to.ReadFromPbo(0, _copyPboSize); - GL.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); + _api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); return to; } @@ -393,7 +395,7 @@ namespace Ryujinx.Graphics.OpenGL.Image EnsurePbo(from); - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); + _api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); // The source texture is written out in full, then the destination is taken as a slice from the data using unpack params. // The offset points to the base at which the requested layer is at. @@ -407,39 +409,39 @@ namespace Ryujinx.Graphics.OpenGL.Image if (slice) { // Set unpack parameters to take a slice of width/height: - GL.PixelStore(PixelStoreParameter.UnpackRowLength, unpackWidth); - GL.PixelStore(PixelStoreParameter.UnpackImageHeight, unpackHeight); + _api.PixelStore(PixelStoreParameter.UnpackRowLength, unpackWidth); + _api.PixelStore(PixelStoreParameter.UnpackImageHeight, unpackHeight); if (to.Info.IsCompressed) { - GL.PixelStore(GLEnum.UnpackCompressedBlockWidth, to.Info.BlockWidth); - GL.PixelStore(GLEnum.UnpackCompressedBlockHeight, to.Info.BlockHeight); - GL.PixelStore(GLEnum.UnpackCompressedBlockDepth, 1); - GL.PixelStore(GLEnum.UnpackCompressedBlockSize, to.Info.BytesPerPixel); + _api.PixelStore(GLEnum.UnpackCompressedBlockWidth, to.Info.BlockWidth); + _api.PixelStore(GLEnum.UnpackCompressedBlockHeight, to.Info.BlockHeight); + _api.PixelStore(GLEnum.UnpackCompressedBlockDepth, 1); + _api.PixelStore(GLEnum.UnpackCompressedBlockSize, to.Info.BytesPerPixel); } } - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); - GL.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); + _api.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); + _api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); to.ReadFromPbo2D(offset, dstLayer, dstLevel, dstWidth, dstHeight); if (slice) { // Reset unpack parameters - GL.PixelStore(PixelStoreParameter.UnpackRowLength, 0); - GL.PixelStore(PixelStoreParameter.UnpackImageHeight, 0); + _api.PixelStore(PixelStoreParameter.UnpackRowLength, 0); + _api.PixelStore(PixelStoreParameter.UnpackImageHeight, 0); if (to.Info.IsCompressed) { - GL.PixelStore(GLEnum.UnpackCompressedBlockWidth, 0); - GL.PixelStore(GLEnum.UnpackCompressedBlockHeight, 0); - GL.PixelStore(GLEnum.UnpackCompressedBlockDepth, 0); - GL.PixelStore(GLEnum.UnpackCompressedBlockSize, 0); + _api.PixelStore(GLEnum.UnpackCompressedBlockWidth, 0); + _api.PixelStore(GLEnum.UnpackCompressedBlockHeight, 0); + _api.PixelStore(GLEnum.UnpackCompressedBlockDepth, 0); + _api.PixelStore(GLEnum.UnpackCompressedBlockSize, 0); } } - GL.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); + _api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); } private void EnsurePbo(TextureView view) @@ -453,36 +455,36 @@ namespace Ryujinx.Graphics.OpenGL.Image if (_copyPboSize < requiredSize && _copyPboHandle != 0) { - GL.DeleteBuffer(_copyPboHandle); + _api.DeleteBuffer(_copyPboHandle); _copyPboHandle = 0; } if (_copyPboHandle == 0) { - _copyPboHandle = GL.GenBuffer(); + _copyPboHandle = _api.GenBuffer(); _copyPboSize = requiredSize; - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); - GL.BufferData(BufferTargetARB.PixelPackBuffer, requiredSize, IntPtr.Zero, BufferUsageARB.DynamicCopy); + _api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); + _api.BufferData(BufferTargetARB.PixelPackBuffer, (uint)requiredSize, IntPtr.Zero, BufferUsageARB.DynamicCopy); } } - private int GetSrcFramebufferLazy() + private uint GetSrcFramebufferLazy() { if (_srcFramebuffer == 0) { - _srcFramebuffer = GL.GenFramebuffer(); + _srcFramebuffer = _api.GenFramebuffer(); } return _srcFramebuffer; } - private int GetDstFramebufferLazy() + private uint GetDstFramebufferLazy() { if (_dstFramebuffer == 0) { - _dstFramebuffer = GL.GenFramebuffer(); + _dstFramebuffer = _api.GenFramebuffer(); } return _dstFramebuffer; @@ -492,21 +494,21 @@ namespace Ryujinx.Graphics.OpenGL.Image { if (_srcFramebuffer != 0) { - GL.DeleteFramebuffer(_srcFramebuffer); + _api.DeleteFramebuffer(_srcFramebuffer); _srcFramebuffer = 0; } if (_dstFramebuffer != 0) { - GL.DeleteFramebuffer(_dstFramebuffer); + _api.DeleteFramebuffer(_dstFramebuffer); _dstFramebuffer = 0; } if (_copyPboHandle != 0) { - GL.DeleteBuffer(_copyPboHandle); + _api.DeleteBuffer(_copyPboHandle); _copyPboHandle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index 0d3a7e2187..c30aebf6eb 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -11,6 +11,7 @@ namespace Ryujinx.Graphics.OpenGL { public sealed class OpenGLRenderer : IRenderer { + private GL _api; private readonly Pipeline _pipeline; public IPipeline Pipeline => _pipeline; @@ -57,13 +58,13 @@ namespace Ryujinx.Graphics.OpenGL ResourcePool = new ResourcePool(); } - public BufferHandle CreateBuffer(int size, GAL.BufferAccess access) + public BufferHandle CreateBuffer(int size, BufferAccess access) { BufferCount++; - if (access.HasFlag(GAL.BufferAccess.FlushPersistent)) + if (access.HasFlag(BufferAccess.FlushPersistent)) { - BufferHandle handle = Buffer.CreatePersistent(size); + BufferHandle handle = Buffer.CreatePersistent(_api, size); PersistentBuffers.Map(handle, size); @@ -71,7 +72,7 @@ namespace Ryujinx.Graphics.OpenGL } else { - return Buffer.Create(size); + return Buffer.Create(_api, size); } } diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 8624782206..b547fadd2f 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -38,8 +38,8 @@ namespace Ryujinx.Graphics.OpenGL private float[] _viewportArray = Array.Empty(); private double[] _depthRangeArray = Array.Empty(); - private int _boundDrawFramebuffer; - private int _boundReadFramebuffer; + private uint _boundDrawFramebuffer; + private uint _boundReadFramebuffer; private CounterQueueEvent _activeConditionalRender; @@ -1496,7 +1496,7 @@ namespace Ryujinx.Graphics.OpenGL } } - internal (int drawHandle, int readHandle) GetBoundFramebuffers() + internal (uint drawHandle, uint readHandle) GetBoundFramebuffers() { if (BackgroundContextWorker.InBackground) { From 4301dbaca6b7f741f1a8e4bcd5c1d9cb85bab729 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 8 May 2024 22:54:35 -0400 Subject: [PATCH 04/35] Queries --- .../Image/FormatConverter.cs | 48 +++++++++---------- .../Image/ImageArray.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs | 6 +-- .../Image/TextureArray.cs | 2 +- .../Image/TextureBase.cs | 11 ++--- .../Image/TextureBuffer.cs | 8 ++-- .../Image/TextureCopy.cs | 2 +- .../Image/TextureCopyMS.cs | 10 ++-- .../Image/TextureStorage.cs | 2 +- .../Queries/BufferedQuery.cs | 44 +++++++++-------- .../Queries/CounterQueue.cs | 14 +++--- .../Queries/CounterQueueEvent.cs | 6 +-- .../Queries/Counters.cs | 9 ++-- 13 files changed, 86 insertions(+), 78 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Image/FormatConverter.cs b/src/Ryujinx.Graphics.OpenGL/Image/FormatConverter.cs index 434f25900c..5f392c74ad 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/FormatConverter.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/FormatConverter.cs @@ -21,14 +21,14 @@ namespace Ryujinx.Graphics.OpenGL.Image if (Avx2.IsSupported) { var mask = Vector256.Create( - (byte)3, (byte)0, (byte)1, (byte)2, - (byte)7, (byte)4, (byte)5, (byte)6, - (byte)11, (byte)8, (byte)9, (byte)10, - (byte)15, (byte)12, (byte)13, (byte)14, - (byte)19, (byte)16, (byte)17, (byte)18, - (byte)23, (byte)20, (byte)21, (byte)22, - (byte)27, (byte)24, (byte)25, (byte)26, - (byte)31, (byte)28, (byte)29, (byte)30); + 3, 0, 1, 2, + 7, 4, 5, 6, + 11, 8, 9, 10, + 15, 12, 13, 14, + 19, 16, 17, 18, + 23, 20, 21, 22, + 27, 24, 25, 26, + 31, 28, 29, (byte)30); int sizeAligned = data.Length & ~31; @@ -49,10 +49,10 @@ namespace Ryujinx.Graphics.OpenGL.Image else if (Ssse3.IsSupported) { var mask = Vector128.Create( - (byte)3, (byte)0, (byte)1, (byte)2, - (byte)7, (byte)4, (byte)5, (byte)6, - (byte)11, (byte)8, (byte)9, (byte)10, - (byte)15, (byte)12, (byte)13, (byte)14); + 3, 0, 1, 2, + 7, 4, 5, 6, + 11, 8, 9, 10, + 15, 12, 13, (byte)14); int sizeAligned = data.Length & ~15; @@ -90,14 +90,14 @@ namespace Ryujinx.Graphics.OpenGL.Image if (Avx2.IsSupported) { var mask = Vector256.Create( - (byte)1, (byte)2, (byte)3, (byte)0, - (byte)5, (byte)6, (byte)7, (byte)4, - (byte)9, (byte)10, (byte)11, (byte)8, - (byte)13, (byte)14, (byte)15, (byte)12, - (byte)17, (byte)18, (byte)19, (byte)16, - (byte)21, (byte)22, (byte)23, (byte)20, - (byte)25, (byte)26, (byte)27, (byte)24, - (byte)29, (byte)30, (byte)31, (byte)28); + 1, 2, 3, 0, + 5, 6, 7, 4, + 9, 10, 11, 8, + 13, 14, 15, 12, + 17, 18, 19, 16, + 21, 22, 23, 20, + 25, 26, 27, 24, + 29, 30, 31, (byte)28); int sizeAligned = data.Length & ~31; @@ -118,10 +118,10 @@ namespace Ryujinx.Graphics.OpenGL.Image else if (Ssse3.IsSupported) { var mask = Vector128.Create( - (byte)1, (byte)2, (byte)3, (byte)0, - (byte)5, (byte)6, (byte)7, (byte)4, - (byte)9, (byte)10, (byte)11, (byte)8, - (byte)13, (byte)14, (byte)15, (byte)12); + 1, 2, 3, 0, + 5, 6, 7, 4, + 9, 10, 11, 8, + 13, 14, 15, (byte)12); int sizeAligned = data.Length & ~15; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs index 697039742a..288613350a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs @@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } private readonly TextureRef[] _images; - private GL _api; + private readonly GL _api; public ImageArray(GL api, int size) { diff --git a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs index 08e44dfbd7..1eafbf3c19 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs @@ -41,9 +41,9 @@ namespace Ryujinx.Graphics.OpenGL.Image _api.SamplerParameter(Handle, SamplerParameterF.BorderColor, borderColor); } - _api.SamplerParameter(Handle, SamplerParameterF.TextureMinLod, info.MinLod); - _api.SamplerParameter(Handle, SamplerParameterF.TextureMaxLod, info.MaxLod); - _api.SamplerParameter(Handle, SamplerParameterF.TextureLodBias, info.MipLodBias); + _api.SamplerParameter(Handle, SamplerParameterF.MinLod, info.MinLod); + _api.SamplerParameter(Handle, SamplerParameterF.MaxLod, info.MaxLod); + _api.SamplerParameter(Handle, SamplerParameterF.LodBias, info.MipLodBias); _api.SamplerParameter(Handle, SamplerParameterF.MaxAnisotropy, info.MaxAnisotropy); } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs index 7172971448..9efae111de 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs @@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } private readonly TextureRef[] _textureRefs; - private GL _api; + private readonly GL _api; public TextureArray(GL api, int size) { diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs index 6dc5ae6d4d..cec527dd6a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs @@ -5,6 +5,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { class TextureBase { + private readonly protected GL Api; public uint Handle { get; protected set; } public TextureCreateInfo Info { get; } @@ -15,14 +16,12 @@ namespace Ryujinx.Graphics.OpenGL.Image public Target Target => Info.Target; public Format Format => Info.Format; - private protected GL _api; - public TextureBase(GL api, TextureCreateInfo info) { - _api = api; + Api = api; Info = info; - Handle = _api.GenTexture(); + Handle = Api.GenTexture(); } public void Bind(uint unit) @@ -32,8 +31,8 @@ namespace Ryujinx.Graphics.OpenGL.Image protected void Bind(TextureTarget target, uint unit) { - _api.ActiveTexture((TextureUnit)((uint)TextureUnit.Texture0 + unit)); - _api.BindTexture(target, Handle); + Api.ActiveTexture((TextureUnit)((uint)TextureUnit.Texture0 + unit)); + Api.BindTexture(target, Handle); } public static void ClearBinding(GL api, uint unit) diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs index 5f75638d96..de18ecfbad 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs @@ -41,7 +41,7 @@ namespace Ryujinx.Graphics.OpenGL.Image public PinnedSpan GetData() { - return Buffer.GetData(_api, _renderer, _buffer, _bufferOffset, _bufferSize); + return Buffer.GetData(Api, _renderer, _buffer, _bufferOffset, _bufferSize); } public PinnedSpan GetData(int layer, int level) @@ -59,7 +59,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { var dataSpan = data.Memory.Span; - Buffer.SetData(_api, _buffer, _bufferOffset, dataSpan[..Math.Min(dataSpan.Length, _bufferSize)]); + Buffer.SetData(Api, _buffer, _bufferOffset, dataSpan[..Math.Min(dataSpan.Length, _bufferSize)]); data.Dispose(); } @@ -97,14 +97,14 @@ namespace Ryujinx.Graphics.OpenGL.Image SizedInternalFormat format = (SizedInternalFormat)FormatTable.GetFormatInfo(Info.Format).InternalFormat; - _api.TexBufferRange(TextureTarget.TextureBuffer, format, _buffer.ToUInt32(), buffer.Offset, (uint)buffer.Size); + Api.TexBufferRange(TextureTarget.TextureBuffer, format, _buffer.ToUInt32(), buffer.Offset, (uint)buffer.Size); } public void Dispose() { if (Handle != 0) { - _api.DeleteTexture(Handle); + Api.DeleteTexture(Handle); Handle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index 4667dd6f72..5ddf023bcd 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -7,7 +7,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { class TextureCopy : IDisposable { - private GL _api; + private readonly GL _api; private readonly OpenGLRenderer _renderer; private uint _srcFramebuffer; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs index ba86985c4f..0764382a11 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs @@ -94,14 +94,14 @@ void main() }"; private readonly OpenGLRenderer _renderer; - private readonly int[] _msToNonMSProgramHandles; - private readonly int[] _nonMSToMSProgramHandles; + private readonly uint[] _msToNonMSProgramHandles; + private readonly uint[] _nonMSToMSProgramHandles; public TextureCopyMS(OpenGLRenderer renderer) { _renderer = renderer; - _msToNonMSProgramHandles = new int[5]; - _nonMSToMSProgramHandles = new int[5]; + _msToNonMSProgramHandles = new uint[5]; + _nonMSToMSProgramHandles = new uint[5]; } public void CopyMSToNonMS(ITextureInfo src, ITextureInfo dst, int srcLayer, int dstLayer, int depth) @@ -177,7 +177,7 @@ void main() }; } - private static int CreateViewIfNeeded(ITextureInfo texture) + private static uint CreateViewIfNeeded(ITextureInfo texture) { // Binding sRGB textures as images doesn't work on NVIDIA, // we need to create and bind a RGBA view for it to work. diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs index dc31143ac4..5294fc212a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs @@ -7,7 +7,7 @@ namespace Ryujinx.Graphics.OpenGL.Image class TextureStorage : ITextureInfo { public ITextureInfo Storage => this; - public int Handle { get; private set; } + public uint Handle { get; private set; } public TextureCreateInfo Info { get; } diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs index 05e18659d1..4201378d0f 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs @@ -12,50 +12,56 @@ namespace Ryujinx.Graphics.OpenGL.Queries private const long DefaultValue = -1; private const ulong HighMask = 0xFFFFFFFF00000000; - public int Query { get; } + public uint Query { get; } - private readonly int _buffer; + private readonly uint _buffer; private readonly IntPtr _bufferMap; private readonly QueryTarget _type; + private readonly GL _api; - public BufferedQuery(QueryTarget type) + public BufferedQuery(GL api, QueryTarget type) { - _buffer = GL.GenBuffer(); - Query = GL.GenQuery(); + _api = api; + _buffer = _api.GenBuffer(); + Query = _api.GenQuery(); _type = type; - GL.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); + _api.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); unsafe { long defaultValue = DefaultValue; - GL.BufferStorage(BufferTargetARB.QueryBuffer, sizeof(long), (IntPtr)(&defaultValue), BufferStorageMask.MapReadBit | BufferStorageMask.MapWriteBit | BufferStorageMask.MapPersistentBit); + _api.BufferStorage(BufferStorageTarget.QueryBuffer, sizeof(long), (IntPtr)(&defaultValue), BufferStorageMask.MapReadBit | BufferStorageMask.MapWriteBit | BufferStorageMask.MapPersistentBit); + } + + unsafe + { + _bufferMap = new IntPtr(_api.MapBufferRange(BufferTargetARB.QueryBuffer, IntPtr.Zero, sizeof(long), MapBufferAccessMask.ReadBit | MapBufferAccessMask.WriteBit | MapBufferAccessMask.PersistentBit)); } - _bufferMap = GL.MapBufferRange(BufferTargetARB.QueryBuffer, IntPtr.Zero, sizeof(long), MapBufferAccessMask.ReadBit | MapBufferAccessMask.WriteBit | MapBufferAccessMask.PersistentBit); } public void Reset() { - GL.EndQuery(_type); - GL.BeginQuery(_type, Query); + _api.EndQuery(_type); + _api.BeginQuery(_type, Query); } public void Begin() { - GL.BeginQuery(_type, Query); + _api.BeginQuery(_type, Query); } public unsafe void End(bool withResult) { - GL.EndQuery(_type); + _api.EndQuery(_type); if (withResult) { - GL.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); + _api.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); Marshal.WriteInt64(_bufferMap, -1L); - GL.GetQueryObject(Query, GetQueryObjectParam.QueryResult, (long*)0); - GL.MemoryBarrier(MemoryBarrierMask.QueryBufferBarrierBit | MemoryBarrierMask.ClientMappedBufferBarrierBit); + _api.GetQueryObject(Query,QueryObjectParameterName.Result, (long*)0); + _api.MemoryBarrier(MemoryBarrierMask.QueryBufferBarrierBit | MemoryBarrierMask.ClientMappedBufferBarrierBit); } else { @@ -111,10 +117,10 @@ namespace Ryujinx.Graphics.OpenGL.Queries public void Dispose() { - GL.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); - GL.UnmapBuffer(BufferTargetARB.QueryBuffer); - GL.DeleteBuffer(_buffer); - GL.DeleteQuery(Query); + _api.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); + _api.UnmapBuffer(BufferTargetARB.QueryBuffer); + _api.DeleteBuffer(_buffer); + _api.DeleteQuery(Query); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs index 0a2f35036e..0ccd3f90ed 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs @@ -28,7 +28,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries private readonly Thread _consumerThread; - internal CounterQueue(CounterType type) + internal CounterQueue(GL api, CounterType type) { Type = type; @@ -37,10 +37,10 @@ namespace Ryujinx.Graphics.OpenGL.Queries _queryPool = new Queue(QueryPoolInitialSize); for (int i = 0; i < QueryPoolInitialSize; i++) { - _queryPool.Enqueue(new BufferedQuery(glType)); + _queryPool.Enqueue(new BufferedQuery(api, glType)); } - _current = new CounterQueueEvent(this, glType, 0); + _current = new CounterQueueEvent(api, this, glType, 0); _consumerThread = new Thread(EventConsumer); _consumerThread.Start(); @@ -76,7 +76,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries } } - internal BufferedQuery GetQueryObject() + internal BufferedQuery GetQueryObject(GL api) { // Creating/disposing query objects on a context we're sharing with will cause issues. // So instead, make a lot of query objects on the main thread and reuse them. @@ -90,7 +90,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries } else { - return new BufferedQuery(GetTarget(Type)); + return new BufferedQuery(api, GetTarget(Type)); } } } @@ -103,7 +103,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries } } - public CounterQueueEvent QueueReport(EventHandler resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved) + public CounterQueueEvent QueueReport(GL api, EventHandler resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved) { CounterQueueEvent result; ulong draws = lastDrawIndex - _current.DrawIndex; @@ -126,7 +126,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries result = _current; - _current = new CounterQueueEvent(this, GetTarget(Type), lastDrawIndex); + _current = new CounterQueueEvent(api, this, GetTarget(Type), lastDrawIndex); } _queuedEvent.Set(); diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs index d37aeae4fe..ddd1040b0d 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs @@ -11,7 +11,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries public QueryTarget Type { get; } public bool ClearCounter { get; private set; } - public int Query => _counter.Query; + public uint Query => _counter.Query; public bool Disposed { get; private set; } public bool Invalid { get; set; } @@ -28,11 +28,11 @@ namespace Ryujinx.Graphics.OpenGL.Queries private ulong _result = ulong.MaxValue; private double _divisor = 1f; - public CounterQueueEvent(CounterQueue queue, QueryTarget type, ulong drawIndex) + public CounterQueueEvent(GL api, CounterQueue queue, QueryTarget type, ulong drawIndex) { _queue = queue; - _counter = queue.GetQueryObject(); + _counter = queue.GetQueryObject(api); Type = type; DrawIndex = drawIndex; diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs b/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs index 1530c9d263..bac6c9f55c 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs @@ -1,4 +1,5 @@ using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL; using System; namespace Ryujinx.Graphics.OpenGL.Queries @@ -6,12 +7,14 @@ namespace Ryujinx.Graphics.OpenGL.Queries class Counters : IDisposable { private readonly CounterQueue[] _counterQueues; + private readonly GL _api; - public Counters() + public Counters(GL api) { int count = Enum.GetNames().Length; _counterQueues = new CounterQueue[count]; + _api = api; } public void Initialize() @@ -19,13 +22,13 @@ namespace Ryujinx.Graphics.OpenGL.Queries for (int index = 0; index < _counterQueues.Length; index++) { CounterType type = (CounterType)index; - _counterQueues[index] = new CounterQueue(type); + _counterQueues[index] = new CounterQueue(_api, type); } } public CounterQueueEvent QueueReport(CounterType type, EventHandler resultHandler, float divisor, ulong lastDrawIndex, bool hostReserved) { - return _counterQueues[(int)type].QueueReport(resultHandler, divisor, lastDrawIndex, hostReserved); + return _counterQueues[(int)type].QueueReport(_api, resultHandler, divisor, lastDrawIndex, hostReserved); } public void QueueReset(CounterType type) From 5f1c880805c4d6b8ecf9c49fe867e5c16a6d3b0f Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Wed, 8 May 2024 23:08:42 -0400 Subject: [PATCH 05/35] Image Subclasses --- .../Image/ITextureInfo.cs | 4 +- .../Image/TextureCopy.cs | 8 +- .../Image/TextureCopyIncompatible.cs | 66 +++++++-------- .../Image/TextureCopyMS.cs | 80 ++++++++++--------- .../Image/TextureStorage.cs | 78 +++++++++--------- 5 files changed, 121 insertions(+), 115 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Image/ITextureInfo.cs b/src/Ryujinx.Graphics.OpenGL/Image/ITextureInfo.cs index 464d005bfe..d422942e89 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/ITextureInfo.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/ITextureInfo.cs @@ -6,8 +6,8 @@ namespace Ryujinx.Graphics.OpenGL.Image { ITextureInfo Storage { get; } uint Handle { get; } - int FirstLayer => 0; - int FirstLevel => 0; + uint FirstLayer => 0; + uint FirstLevel => 0; TextureCreateInfo Info { get; } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index 5ddf023bcd..3f2bc73349 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -245,16 +245,16 @@ namespace Ryujinx.Graphics.OpenGL.Image _api.CopyImageSubData( src.Storage.Handle, src.Storage.Info.Target.ConvertToImageTarget(), - src.FirstLevel + srcLevel + level, + (int)src.FirstLevel + srcLevel + level, 0, 0, - src.FirstLayer + srcLayer, + (int)src.FirstLayer + srcLayer, dst.Storage.Handle, dst.Storage.Info.Target.ConvertToImageTarget(), - dst.FirstLevel + dstLevel + level, + (int)dst.FirstLevel + dstLevel + level, 0, 0, - dst.FirstLayer + dstLayer, + (int)dst.FirstLayer + dstLayer, (uint)copyWidth, (uint)copyHeight, (uint)depth); diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs index af6f7b32f3..271f66ff58 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs @@ -67,15 +67,17 @@ void main() imageStore(dst, ivec2(coords), uvec4(r, g, b, a)); }"; + private readonly GL _api; private readonly OpenGLRenderer _renderer; - private readonly Dictionary _shorteningProgramHandles; - private readonly Dictionary _wideningProgramHandles; + private readonly Dictionary _shorteningProgramHandles; + private readonly Dictionary _wideningProgramHandles; - public TextureCopyIncompatible(OpenGLRenderer renderer) + public TextureCopyIncompatible(GL api, OpenGLRenderer renderer) { + _api = api; _renderer = renderer; - _shorteningProgramHandles = new Dictionary(); - _wideningProgramHandles = new Dictionary(); + _shorteningProgramHandles = new Dictionary(); + _wideningProgramHandles = new Dictionary(); } public void CopyIncompatibleFormats(ITextureInfo src, ITextureInfo dst, int srcLayer, int dstLayer, int srcLevel, int dstLevel, int depth, int levels) @@ -91,10 +93,10 @@ void main() int srcComponentsCount = srcBpp / componentSize; int dstComponentsCount = dstBpp / componentSize; - var srcFormat = GetFormat(componentSize, srcComponentsCount); - var dstFormat = GetFormat(componentSize, dstComponentsCount); + var srcFormat = (InternalFormat)GetFormat(componentSize, srcComponentsCount); + var dstFormat = (InternalFormat)GetFormat(componentSize, dstComponentsCount); - GL.UseProgram(srcBpp < dstBpp + _api.UseProgram(srcBpp < dstBpp ? GetWideningShader(componentSize, srcComponentsCount, dstComponentsCount) : GetShorteningShader(componentSize, srcComponentsCount, dstComponentsCount)); @@ -106,15 +108,15 @@ void main() int dstWidth = Math.Max(1, dst.Info.Width >> l); int dstHeight = Math.Max(1, dst.Info.Height >> l); - int width = Math.Min(srcWidth, dstWidth); - int height = Math.Min(srcHeight, dstHeight); + uint width = (uint)Math.Min(srcWidth, dstWidth); + uint height = (uint)Math.Min(srcHeight, dstHeight); for (int z = 0; z < depth; z++) { - GL.BindImageTexture(0, src.Handle, srcLevel + l, false, srcLayer + z, BufferAccessARB.ReadOnly, srcFormat); - GL.BindImageTexture(1, dst.Handle, dstLevel + l, false, dstLayer + z, BufferAccessARB.WriteOnly, dstFormat); + _api.BindImageTexture(0, src.Handle, srcLevel + l, false, srcLayer + z, BufferAccessARB.ReadOnly, srcFormat); + _api.BindImageTexture(1, dst.Handle, dstLevel + l, false, dstLayer + z, BufferAccessARB.WriteOnly, dstFormat); - GL.DispatchCompute((width + 31) / 32, (height + 31) / 32, 1); + _api.DispatchCompute((width + 31) / 32, (height + 31) / 32, 1); } } @@ -162,19 +164,19 @@ void main() } } - private int GetShorteningShader(int componentSize, int srcComponentsCount, int dstComponentsCount) + private uint GetShorteningShader(int componentSize, int srcComponentsCount, int dstComponentsCount) { return GetShader(ComputeShaderShortening, _shorteningProgramHandles, componentSize, srcComponentsCount, dstComponentsCount); } - private int GetWideningShader(int componentSize, int srcComponentsCount, int dstComponentsCount) + private uint GetWideningShader(int componentSize, int srcComponentsCount, int dstComponentsCount) { return GetShader(ComputeShaderWidening, _wideningProgramHandles, componentSize, srcComponentsCount, dstComponentsCount); } - private static int GetShader( + private uint GetShader( string code, - Dictionary programHandles, + Dictionary programHandles, int componentSize, int srcComponentsCount, int dstComponentsCount) @@ -186,9 +188,9 @@ void main() int key = srcIndex | (dstIndex << 8); - if (!programHandles.TryGetValue(key, out int programHandle)) + if (!programHandles.TryGetValue(key, out uint programHandle)) { - int csHandle = GL.CreateShader(ShaderType.ComputeShader); + uint csHandle = _api.CreateShader(ShaderType.ComputeShader); string[] formatTable = new[] { "r8ui", "r16ui", "r32ui", "rg8ui", "rg16ui", "rg32ui", "rgba8ui", "rgba16ui", "rgba32ui" }; @@ -201,25 +203,25 @@ void main() int ratio = srcBpp < dstBpp ? dstBpp / srcBpp : srcBpp / dstBpp; int ratioLog2 = BitOperations.Log2((uint)ratio); - GL.ShaderSource(csHandle, code + _api.ShaderSource(csHandle, code .Replace("$SRC_FORMAT$", srcFormat) .Replace("$DST_FORMAT$", dstFormat) .Replace("$RATIO_LOG2$", ratioLog2.ToString(CultureInfo.InvariantCulture))); - GL.CompileShader(csHandle); + _api.CompileShader(csHandle); - programHandle = GL.CreateProgram(); + programHandle = _api.CreateProgram(); - GL.AttachShader(programHandle, csHandle); - GL.LinkProgram(programHandle); - GL.DetachShader(programHandle, csHandle); - GL.DeleteShader(csHandle); + _api.AttachShader(programHandle, csHandle); + _api.LinkProgram(programHandle); + _api.DetachShader(programHandle, csHandle); + _api.DeleteShader(csHandle); - GL.GetProgram(programHandle, GetProgramParameterName.LinkStatus, out int status); + _api.GetProgram(programHandle, ProgramPropertyARB.LinkStatus, out int status); if (status == 0) { - throw new Exception(GL.GetProgramInfoLog(programHandle)); + throw new Exception(_api.GetProgramInfoLog(programHandle)); } programHandles.Add(key, programHandle); @@ -230,16 +232,16 @@ void main() public void Dispose() { - foreach (int handle in _shorteningProgramHandles.Values) + foreach (uint handle in _shorteningProgramHandles.Values) { - GL.DeleteProgram(handle); + _api.DeleteProgram(handle); } _shorteningProgramHandles.Clear(); - foreach (int handle in _wideningProgramHandles.Values) + foreach (uint handle in _wideningProgramHandles.Values) { - GL.DeleteProgram(handle); + _api.DeleteProgram(handle); } _wideningProgramHandles.Clear(); diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs index 0764382a11..473fd44bda 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs @@ -93,12 +93,14 @@ void main() imageStore(imgOut, ivec2(int(coords.x) >> samplesInXLog2, int(coords.y) >> samplesInYLog2), sampleIdx, value); }"; + private readonly GL _api; private readonly OpenGLRenderer _renderer; private readonly uint[] _msToNonMSProgramHandles; private readonly uint[] _nonMSToMSProgramHandles; - public TextureCopyMS(OpenGLRenderer renderer) + public TextureCopyMS(GL api, OpenGLRenderer renderer) { + _api = api; _renderer = renderer; _msToNonMSProgramHandles = new uint[5]; _nonMSToMSProgramHandles = new uint[5]; @@ -109,20 +111,20 @@ void main() TextureCreateInfo srcInfo = src.Info; TextureCreateInfo dstInfo = dst.Info; - int srcHandle = CreateViewIfNeeded(src); - int dstHandle = CreateViewIfNeeded(dst); + uint srcHandle = CreateViewIfNeeded(src); + uint dstHandle = CreateViewIfNeeded(dst); - int dstWidth = dstInfo.Width; - int dstHeight = dstInfo.Height; + uint dstWidth = (uint)dstInfo.Width; + uint dstHeight = (uint)dstInfo.Height; - GL.UseProgram(GetMSToNonMSShader(srcInfo.BytesPerPixel)); + _api.UseProgram(GetMSToNonMSShader(srcInfo.BytesPerPixel)); for (int z = 0; z < depth; z++) { - GL.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, GetFormat(srcInfo.BytesPerPixel)); - GL.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, GetFormat(dstInfo.BytesPerPixel)); + _api.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, (InternalFormat)GetFormat(srcInfo.BytesPerPixel)); + _api.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, (InternalFormat)GetFormat(dstInfo.BytesPerPixel)); - GL.DispatchCompute((dstWidth + 31) / 32, (dstHeight + 31) / 32, 1); + _api.DispatchCompute((dstWidth + 31) / 32, (dstHeight + 31) / 32, 1); } Pipeline pipeline = (Pipeline)_renderer.Pipeline; @@ -139,20 +141,20 @@ void main() TextureCreateInfo srcInfo = src.Info; TextureCreateInfo dstInfo = dst.Info; - int srcHandle = CreateViewIfNeeded(src); - int dstHandle = CreateViewIfNeeded(dst); + uint srcHandle = CreateViewIfNeeded(src); + uint dstHandle = CreateViewIfNeeded(dst); - int srcWidth = srcInfo.Width; - int srcHeight = srcInfo.Height; + uint srcWidth = (uint)srcInfo.Width; + uint srcHeight = (uint)srcInfo.Height; - GL.UseProgram(GetNonMSToMSShader(srcInfo.BytesPerPixel)); + _api.UseProgram(GetNonMSToMSShader(srcInfo.BytesPerPixel)); for (int z = 0; z < depth; z++) { - GL.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, GetFormat(srcInfo.BytesPerPixel)); - GL.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, GetFormat(dstInfo.BytesPerPixel)); + _api.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, (InternalFormat)GetFormat(srcInfo.BytesPerPixel)); + _api.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, (InternalFormat)GetFormat(dstInfo.BytesPerPixel)); - GL.DispatchCompute((srcWidth + 31) / 32, (srcHeight + 31) / 32, 1); + _api.DispatchCompute((srcWidth + 31) / 32, (srcHeight + 31) / 32, 1); } Pipeline pipeline = (Pipeline)_renderer.Pipeline; @@ -177,23 +179,23 @@ void main() }; } - private static uint CreateViewIfNeeded(ITextureInfo texture) + private uint CreateViewIfNeeded(ITextureInfo texture) { // Binding sRGB textures as images doesn't work on NVIDIA, // we need to create and bind a RGBA view for it to work. if (texture.Info.Format == Format.R8G8B8A8Srgb) { - int handle = GL.GenTexture(); + uint handle = _api.GenTexture(); - GL.TextureView( + _api.TextureView( handle, texture.Info.Target.Convert(), texture.Storage.Handle, - InternalFormat.Rgba8, + SizedInternalFormat.Rgba8, texture.FirstLevel, 1, texture.FirstLayer, - texture.Info.GetLayers()); + (uint)texture.Info.GetLayers()); return handle; } @@ -201,49 +203,49 @@ void main() return texture.Handle; } - private static void DestroyViewIfNeeded(ITextureInfo info, int handle) + private void DestroyViewIfNeeded(ITextureInfo info, uint handle) { if (info.Handle != handle) { - GL.DeleteTexture(handle); + _api.DeleteTexture(handle); } } - private int GetMSToNonMSShader(int bytesPerPixel) + private uint GetMSToNonMSShader(int bytesPerPixel) { return GetShader(ComputeShaderMSToNonMS, _msToNonMSProgramHandles, bytesPerPixel); } - private int GetNonMSToMSShader(int bytesPerPixel) + private uint GetNonMSToMSShader(int bytesPerPixel) { return GetShader(ComputeShaderNonMSToMS, _nonMSToMSProgramHandles, bytesPerPixel); } - private static int GetShader(string code, int[] programHandles, int bytesPerPixel) + private uint GetShader(string code, uint[] programHandles, int bytesPerPixel) { int index = BitOperations.Log2((uint)bytesPerPixel); if (programHandles[index] == 0) { - int csHandle = GL.CreateShader(ShaderType.ComputeShader); + uint csHandle = _api.CreateShader(ShaderType.ComputeShader); string format = new[] { "r8ui", "r16ui", "r32ui", "rg32ui", "rgba32ui" }[index]; - GL.ShaderSource(csHandle, code.Replace("$FORMAT$", format)); - GL.CompileShader(csHandle); + _api.ShaderSource(csHandle, code.Replace("$FORMAT$", format)); + _api.CompileShader(csHandle); - int programHandle = GL.CreateProgram(); + uint programHandle = _api.CreateProgram(); - GL.AttachShader(programHandle, csHandle); - GL.LinkProgram(programHandle); - GL.DetachShader(programHandle, csHandle); - GL.DeleteShader(csHandle); + _api.AttachShader(programHandle, csHandle); + _api.LinkProgram(programHandle); + _api.DetachShader(programHandle, csHandle); + _api.DeleteShader(csHandle); - GL.GetProgram(programHandle, GetProgramParameterName.LinkStatus, out int status); + _api.GetProgram(programHandle, ProgramPropertyARB.LinkStatus, out int status); if (status == 0) { - throw new Exception(GL.GetProgramInfoLog(programHandle)); + throw new Exception(_api.GetProgramInfoLog(programHandle)); } programHandles[index] = programHandle; @@ -258,7 +260,7 @@ void main() { if (_msToNonMSProgramHandles[i] != 0) { - GL.DeleteProgram(_msToNonMSProgramHandles[i]); + _api.DeleteProgram(_msToNonMSProgramHandles[i]); _msToNonMSProgramHandles[i] = 0; } } @@ -267,7 +269,7 @@ void main() { if (_nonMSToMSProgramHandles[i] != 0) { - GL.DeleteProgram(_nonMSToMSProgramHandles[i]); + _api.DeleteProgram(_nonMSToMSProgramHandles[i]); _nonMSToMSProgramHandles[i] = 0; } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs index 5294fc212a..8c0be4b7d6 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs @@ -12,17 +12,19 @@ namespace Ryujinx.Graphics.OpenGL.Image public TextureCreateInfo Info { get; } private readonly OpenGLRenderer _renderer; + private readonly GL _api; private int _viewsCount; internal ITexture DefaultView { get; private set; } - public TextureStorage(OpenGLRenderer renderer, TextureCreateInfo info) + public TextureStorage(GL api, OpenGLRenderer renderer, TextureCreateInfo info) { + _api = api; _renderer = renderer; Info = info; - Handle = GL.GenTexture(); + Handle = _api.GenTexture(); CreateImmutableStorage(); } @@ -31,9 +33,9 @@ namespace Ryujinx.Graphics.OpenGL.Image { TextureTarget target = Info.Target.Convert(); - GL.ActiveTexture(TextureUnit.Texture0); + _api.ActiveTexture(TextureUnit.Texture0); - GL.BindTexture(target, Handle); + _api.BindTexture(target, Handle); FormatInfo format = FormatTable.GetFormatInfo(Info.Format); @@ -48,94 +50,94 @@ namespace Ryujinx.Graphics.OpenGL.Image internalFormat = (SizedInternalFormat)format.InternalFormat; } - int levels = Info.GetLevelsClamped(); + uint levels = (uint)Info.GetLevelsClamped(); switch (Info.Target) { case Target.Texture1D: - GL.TexStorage1D( + _api.TexStorage1D( TextureTarget.Texture1D, levels, internalFormat, - Info.Width); + (uint)Info.Width); break; case Target.Texture1DArray: - GL.TexStorage2D( + _api.TexStorage2D( TextureTarget.Texture1DArray, levels, internalFormat, - Info.Width, - Info.Height); + (uint)Info.Width, + (uint)Info.Height); break; case Target.Texture2D: - GL.TexStorage2D( + _api.TexStorage2D( TextureTarget.Texture2D, levels, internalFormat, - Info.Width, - Info.Height); + (uint)Info.Width, + (uint)Info.Height); break; case Target.Texture2DArray: - GL.TexStorage3D( + _api.TexStorage3D( TextureTarget.Texture2DArray, levels, internalFormat, - Info.Width, - Info.Height, - Info.Depth); + (uint)Info.Width, + (uint)Info.Height, + (uint)Info.Depth); break; case Target.Texture2DMultisample: - GL.TexStorage2DMultisample( + _api.TexStorage2DMultisample( TextureTarget.Texture2DMultisample, - Info.Samples, + (uint)Info.Samples, internalFormat, - Info.Width, - Info.Height, + (uint)Info.Width, + (uint)Info.Height, true); break; case Target.Texture2DMultisampleArray: - GL.TexStorage3DMultisample( + _api.TexStorage3DMultisample( TextureTarget.Texture2DMultisampleArray, - Info.Samples, + (uint)Info.Samples, internalFormat, - Info.Width, - Info.Height, - Info.Depth, + (uint)Info.Width, + (uint)Info.Height, + (uint)Info.Depth, true); break; case Target.Texture3D: - GL.TexStorage3D( + _api.TexStorage3D( TextureTarget.Texture3D, levels, internalFormat, - Info.Width, - Info.Height, - Info.Depth); + (uint)Info.Width, + (uint)Info.Height, + (uint)Info.Depth); break; case Target.Cubemap: - GL.TexStorage2D( + _api.TexStorage2D( TextureTarget.TextureCubeMap, levels, internalFormat, - Info.Width, - Info.Height); + (uint)Info.Width, + (uint)Info.Height); break; case Target.CubemapArray: - GL.TexStorage3D( + _api.TexStorage3D( TextureTarget.TextureCubeMapArray, levels, internalFormat, - Info.Width, - Info.Height, - Info.Depth); + (uint)Info.Width, + (uint)Info.Height, + (uint)Info.Depth); break; default: @@ -201,7 +203,7 @@ namespace Ryujinx.Graphics.OpenGL.Image if (Handle != 0) { - GL.DeleteTexture(Handle); + _api.DeleteTexture(Handle); Handle = 0; } From 4ee4b0f3ac465548aa19834b44e05443764f652b Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 11:46:39 -0400 Subject: [PATCH 06/35] More progress --- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 12 +- .../DrawTextureEmulation.cs | 1 + .../Effects/FsrScalingFilter.cs | 110 +++--- .../Effects/FxaaPostProcessingEffect.cs | 50 +-- .../Effects/ShaderHelper.cs | 36 +- .../Effects/SmaaPostProcessingEffect.cs | 152 +++---- src/Ryujinx.Graphics.OpenGL/Framebuffer.cs | 11 +- src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs | 2 +- .../Image/TextureBase.cs | 12 +- .../Image/TextureBuffer.cs | 17 +- .../Image/TextureCopy.cs | 114 +++--- .../Image/TextureCopyIncompatible.cs | 42 +- .../Image/TextureCopyMS.cs | 58 ++- .../Image/TextureStorage.cs | 40 +- .../Image/TextureView.cs | 201 +++++----- src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 32 +- .../PersistentBuffers.cs | 4 +- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 372 +++++++++--------- src/Ryujinx.Graphics.OpenGL/Program.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Sync.cs | 28 +- src/Ryujinx.Graphics.OpenGL/Window.cs | 96 ++--- 21 files changed, 697 insertions(+), 695 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index 6a56638b64..9aeb662004 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -69,26 +69,26 @@ namespace Ryujinx.Graphics.OpenGL (uint)size); } - public static unsafe PinnedSpan GetData(GL api, OpenGLRenderer renderer, BufferHandle buffer, int offset, int size) + public static unsafe PinnedSpan GetData(OpenGLRenderer gd, BufferHandle buffer, int offset, int size) { // Data in the persistent buffer and host array is guaranteed to be available // until the next time the host thread requests data. - if (renderer.PersistentBuffers.TryGet(buffer, out IntPtr ptr)) + if (gd.PersistentBuffers.TryGet(buffer, out IntPtr ptr)) { return new PinnedSpan(IntPtr.Add(ptr, offset).ToPointer(), size); } else if (HwCapabilities.UsePersistentBufferForFlush) { - return PinnedSpan.UnsafeFromSpan(renderer.PersistentBuffers.Default.GetBufferData(buffer, offset, size)); + return PinnedSpan.UnsafeFromSpan(gd.PersistentBuffers.Default.GetBufferData(buffer, offset, size)); } else { - IntPtr target = renderer.PersistentBuffers.Default.GetHostArray(size); + IntPtr target = gd.PersistentBuffers.Default.GetHostArray(size); - api.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToUInt32()); + gd.Api.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToUInt32()); - api.GetBufferSubData(BufferTargetARB.CopyReadBuffer, offset, (uint)size, target); + gd.Api.GetBufferSubData(BufferTargetARB.CopyReadBuffer, offset, (uint)size, target); return new PinnedSpan(target.ToPointer(), size); } diff --git a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs index 0d13fe7917..7d2f89f18b 100644 --- a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs +++ b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs @@ -1,6 +1,7 @@ using Silk.NET.OpenGL; using Ryujinx.Graphics.OpenGL.Image; using System; +using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; namespace Ryujinx.Graphics.OpenGL { diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs index 20ab0cf44b..6f10f290a2 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs @@ -9,15 +9,15 @@ namespace Ryujinx.Graphics.OpenGL.Effects { internal class FsrScalingFilter : IScalingFilter { - private readonly OpenGLRenderer _renderer; + private readonly OpenGLRenderer _gd; private int _inputUniform; private int _outputUniform; private int _sharpeningUniform; private int _srcX0Uniform; private int _srcX1Uniform; private int _srcY0Uniform; - private int _scalingShaderProgram; - private int _sharpeningShaderProgram; + private uint _scalingShaderProgram; + private uint _sharpeningShaderProgram; private float _scale = 1; private int _srcY1Uniform; private int _dstX0Uniform; @@ -37,19 +37,19 @@ namespace Ryujinx.Graphics.OpenGL.Effects } } - public FsrScalingFilter(OpenGLRenderer renderer) + public FsrScalingFilter(OpenGLRenderer gd) { Initialize(); - _renderer = renderer; + _gd = gd; } public void Dispose() { if (_scalingShaderProgram != 0) { - GL.DeleteProgram(_scalingShaderProgram); - GL.DeleteProgram(_sharpeningShaderProgram); + _gd.Api.DeleteProgram(_scalingShaderProgram); + _gd.Api.DeleteProgram(_sharpeningShaderProgram); } _intermediaryTexture?.Dispose(); @@ -67,23 +67,23 @@ namespace Ryujinx.Graphics.OpenGL.Effects sharpeningShader = sharpeningShader.Replace("#include \"ffx_a.h\"", fsrA); sharpeningShader = sharpeningShader.Replace("#include \"ffx_fsr1.h\"", fsr1); - _scalingShaderProgram = CompileProgram(scalingShader, ShaderType.ComputeShader); - _sharpeningShaderProgram = CompileProgram(sharpeningShader, ShaderType.ComputeShader); + _scalingShaderProgram = CompileProgram(_gd.Api, scalingShader, ShaderType.ComputeShader); + _sharpeningShaderProgram = CompileProgram(_gd.Api, sharpeningShader, ShaderType.ComputeShader); - _inputUniform = GL.GetUniformLocation(_scalingShaderProgram, "Source"); - _outputUniform = GL.GetUniformLocation(_scalingShaderProgram, "imgOutput"); - _sharpeningUniform = GL.GetUniformLocation(_sharpeningShaderProgram, "sharpening"); + _inputUniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "Source"); + _outputUniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "imgOutput"); + _sharpeningUniform = _gd.Api.GetUniformLocation(_sharpeningShaderProgram, "sharpening"); - _srcX0Uniform = GL.GetUniformLocation(_scalingShaderProgram, "srcX0"); - _srcX1Uniform = GL.GetUniformLocation(_scalingShaderProgram, "srcX1"); - _srcY0Uniform = GL.GetUniformLocation(_scalingShaderProgram, "srcY0"); - _srcY1Uniform = GL.GetUniformLocation(_scalingShaderProgram, "srcY1"); - _dstX0Uniform = GL.GetUniformLocation(_scalingShaderProgram, "dstX0"); - _dstX1Uniform = GL.GetUniformLocation(_scalingShaderProgram, "dstX1"); - _dstY0Uniform = GL.GetUniformLocation(_scalingShaderProgram, "dstY0"); - _dstY1Uniform = GL.GetUniformLocation(_scalingShaderProgram, "dstY1"); - _scaleXUniform = GL.GetUniformLocation(_scalingShaderProgram, "scaleX"); - _scaleYUniform = GL.GetUniformLocation(_scalingShaderProgram, "scaleY"); + _srcX0Uniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "srcX0"); + _srcX1Uniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "srcX1"); + _srcY0Uniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "srcY0"); + _srcY1Uniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "srcY1"); + _dstX0Uniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "dstX0"); + _dstX1Uniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "dstX1"); + _dstY0Uniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "dstY0"); + _dstY1Uniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "dstY1"); + _scaleXUniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "scaleX"); + _scaleYUniform = _gd.Api.GetUniformLocation(_scalingShaderProgram, "scaleY"); } public void Run( @@ -114,18 +114,18 @@ namespace Ryujinx.Graphics.OpenGL.Effects originalInfo.SwizzleB, originalInfo.SwizzleA); - _intermediaryTexture = new TextureStorage(_renderer, info); + _intermediaryTexture = new TextureStorage(_gd, info); _intermediaryTexture.CreateDefaultView(); } var textureView = _intermediaryTexture.CreateView(_intermediaryTexture.Info, 0, 0) as TextureView; - int previousProgram = GL.GetInteger(GetPName.CurrentProgram); - int previousUnit = GL.GetInteger(GetPName.ActiveTexture); - GL.ActiveTexture(TextureUnit.Texture0); - int previousTextureBinding = GL.GetInteger(GetPName.TextureBinding2D); + uint previousProgram = (uint)_gd.Api.GetInteger(GetPName.CurrentProgram); + int previousUnit = _gd.Api.GetInteger(GetPName.ActiveTexture); + _gd.Api.ActiveTexture(TextureUnit.Texture0); + int previousTextureBinding = _gd.Api.GetInteger(GetPName.TextureBinding2D); - GL.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); int threadGroupWorkRegionDim = 16; int dispatchX = (width + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; @@ -136,42 +136,42 @@ namespace Ryujinx.Graphics.OpenGL.Effects float srcHeight = Math.Abs(source.Y2 - source.Y1); float scaleX = srcWidth / view.Width; float scaleY = srcHeight / view.Height; - GL.UseProgram(_scalingShaderProgram); + _gd.Api.UseProgram(_scalingShaderProgram); view.Bind(0); - GL.Uniform1(_inputUniform, 0); - GL.Uniform1(_outputUniform, 0); - GL.Uniform1(_srcX0Uniform, (float)source.X1); - GL.Uniform1(_srcX1Uniform, (float)source.X2); - GL.Uniform1(_srcY0Uniform, (float)source.Y1); - GL.Uniform1(_srcY1Uniform, (float)source.Y2); - GL.Uniform1(_dstX0Uniform, (float)destination.X1); - GL.Uniform1(_dstX1Uniform, (float)destination.X2); - GL.Uniform1(_dstY0Uniform, (float)destination.Y1); - GL.Uniform1(_dstY1Uniform, (float)destination.Y2); - GL.Uniform1(_scaleXUniform, scaleX); - GL.Uniform1(_scaleYUniform, scaleY); - GL.DispatchCompute(dispatchX, dispatchY, 1); + _gd.Api.Uniform1(_inputUniform, 0); + _gd.Api.Uniform1(_outputUniform, 0); + _gd.Api.Uniform1(_srcX0Uniform, (float)source.X1); + _gd.Api.Uniform1(_srcX1Uniform, (float)source.X2); + _gd.Api.Uniform1(_srcY0Uniform, (float)source.Y1); + _gd.Api.Uniform1(_srcY1Uniform, (float)source.Y2); + _gd.Api.Uniform1(_dstX0Uniform, (float)destination.X1); + _gd.Api.Uniform1(_dstX1Uniform, (float)destination.X2); + _gd.Api.Uniform1(_dstY0Uniform, (float)destination.Y1); + _gd.Api.Uniform1(_dstY1Uniform, (float)destination.Y2); + _gd.Api.Uniform1(_scaleXUniform, scaleX); + _gd.Api.Uniform1(_scaleYUniform, scaleY); + _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); - GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); + _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); // Sharpening Pass - GL.UseProgram(_sharpeningShaderProgram); - GL.BindImageTexture(0, destinationTexture.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.UseProgram(_sharpeningShaderProgram); + _gd.Api.BindImageTexture(0, destinationTexture.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); textureView.Bind(0); - GL.Uniform1(_inputUniform, 0); - GL.Uniform1(_outputUniform, 0); - GL.Uniform1(_sharpeningUniform, 1.5f - (Level * 0.01f * 1.5f)); - GL.DispatchCompute(dispatchX, dispatchY, 1); + _gd.Api.Uniform1(_inputUniform, 0); + _gd.Api.Uniform1(_outputUniform, 0); + _gd.Api.Uniform1(_sharpeningUniform, 1.5f - (Level * 0.01f * 1.5f)); + _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); - GL.UseProgram(previousProgram); - GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); + _gd.Api.UseProgram(previousProgram); + _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - (_renderer.Pipeline as Pipeline).RestoreImages1And2(); + (_gd.Pipeline as Pipeline).RestoreImages1And2(); - GL.ActiveTexture(TextureUnit.Texture0); - GL.BindTexture(TextureTarget.Texture2D, previousTextureBinding); + _gd.Api.ActiveTexture(TextureUnit.Texture0); + _gd.Api.BindTexture(TextureTarget.Texture2D, previousTextureBinding); - GL.ActiveTexture((TextureUnit)previousUnit); + _gd.Api.ActiveTexture((TextureUnit)previousUnit); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs index 53f96c8063..d3dc44581c 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs @@ -6,25 +6,25 @@ namespace Ryujinx.Graphics.OpenGL.Effects { internal class FxaaPostProcessingEffect : IPostProcessingEffect { - private readonly OpenGLRenderer _renderer; + private readonly OpenGLRenderer _gd; private int _resolutionUniform; private int _inputUniform; private int _outputUniform; - private int _shaderProgram; + private uint _shaderProgram; private TextureStorage _textureStorage; - public FxaaPostProcessingEffect(OpenGLRenderer renderer) + public FxaaPostProcessingEffect(OpenGLRenderer gd) { Initialize(); - _renderer = renderer; + _gd = gd; } public void Dispose() { if (_shaderProgram != 0) { - GL.DeleteProgram(_shaderProgram); + _gd.Api.DeleteProgram(_shaderProgram); _textureStorage?.Dispose(); } } @@ -33,9 +33,9 @@ namespace Ryujinx.Graphics.OpenGL.Effects { _shaderProgram = ShaderHelper.CompileProgram(EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/fxaa.glsl"), ShaderType.ComputeShader); - _resolutionUniform = GL.GetUniformLocation(_shaderProgram, "invResolution"); - _inputUniform = GL.GetUniformLocation(_shaderProgram, "inputTexture"); - _outputUniform = GL.GetUniformLocation(_shaderProgram, "imgOutput"); + _resolutionUniform = _gd.Api.GetUniformLocation(_shaderProgram, "invResolution"); + _inputUniform = _gd.Api.GetUniformLocation(_shaderProgram, "inputTexture"); + _outputUniform = _gd.Api.GetUniformLocation(_shaderProgram, "imgOutput"); } public TextureView Run(TextureView view, int width, int height) @@ -43,37 +43,37 @@ namespace Ryujinx.Graphics.OpenGL.Effects if (_textureStorage == null || _textureStorage.Info.Width != view.Width || _textureStorage.Info.Height != view.Height) { _textureStorage?.Dispose(); - _textureStorage = new TextureStorage(_renderer, view.Info); + _textureStorage = new TextureStorage(_gd, view.Info); _textureStorage.CreateDefaultView(); } var textureView = _textureStorage.CreateView(view.Info, 0, 0) as TextureView; - int previousProgram = GL.GetInteger(GetPName.CurrentProgram); - int previousUnit = GL.GetInteger(GetPName.ActiveTexture); - GL.ActiveTexture(TextureUnit.Texture0); - int previousTextureBinding = GL.GetInteger(GetPName.TextureBinding2D); + int previousProgram = _gd.Api.GetInteger(GetPName.CurrentProgram); + int previousUnit = _gd.Api.GetInteger(GetPName.ActiveTexture); + _gd.Api.ActiveTexture(TextureUnit.Texture0); + int previousTextureBinding = _gd.Api.GetInteger(GetPName.TextureBinding2D); - GL.BindImageTexture(0, textureView.Handle, 0, false, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); - GL.UseProgram(_shaderProgram); + _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.UseProgram(_shaderProgram); var dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize); var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); view.Bind(0); - GL.Uniform1(_inputUniform, 0); - GL.Uniform1(_outputUniform, 0); - GL.Uniform2(_resolutionUniform, (float)view.Width, (float)view.Height); - GL.DispatchCompute(dispatchX, dispatchY, 1); - GL.UseProgram(previousProgram); - GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); + _gd.Api.Uniform1(_inputUniform, 0); + _gd.Api.Uniform1(_outputUniform, 0); + _gd.Api.Uniform2(_resolutionUniform, (float)view.Width, (float)view.Height); + _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); + _gd.Api.UseProgram(previousProgram); + _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - (_renderer.Pipeline as Pipeline).RestoreImages1And2(); + (_gd.Pipeline as Pipeline).RestoreImages1And2(); - GL.ActiveTexture(TextureUnit.Texture0); - GL.BindTexture(TextureTarget.Texture2D, previousTextureBinding); + _gd.Api.ActiveTexture(TextureUnit.Texture0); + _gd.Api.BindTexture(TextureTarget.Texture2D, previousTextureBinding); - GL.ActiveTexture((TextureUnit)previousUnit); + _gd.Api.ActiveTexture((TextureUnit)previousUnit); return textureView; } diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs b/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs index dea858f34e..30a0b364d9 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs @@ -4,34 +4,34 @@ namespace Ryujinx.Graphics.OpenGL.Effects { internal static class ShaderHelper { - public static int CompileProgram(string shaderCode, ShaderType shaderType) + public static uint CompileProgram(GL api, string shaderCode, ShaderType shaderType) { - var shader = GL.CreateShader(shaderType); - GL.ShaderSource(shader, shaderCode); - GL.CompileShader(shader); + var shader = api.CreateShader(shaderType); + api.ShaderSource(shader, shaderCode); + api.CompileShader(shader); - var program = GL.CreateProgram(); - GL.AttachShader(program, shader); - GL.LinkProgram(program); + var program = api.CreateProgram(); + api.AttachShader(program, shader); + api.LinkProgram(program); - GL.DetachShader(program, shader); - GL.DeleteShader(shader); + api.DetachShader(program, shader); + api.DeleteShader(shader); return program; } - public static int CompileProgram(string[] shaders, ShaderType shaderType) + public static uint CompileProgram(GL api, string[] shaders, ShaderType shaderType) { - var shader = GL.CreateShader(shaderType); - GL.ShaderSource(shader, shaders.Length, shaders, (int[])null); - GL.CompileShader(shader); + var shader = api.CreateShader(shaderType); + api.ShaderSource(shader, (uint)shaders.Length, shaders, 0); + api.CompileShader(shader); - var program = GL.CreateProgram(); - GL.AttachShader(program, shader); - GL.LinkProgram(program); + var program = api.CreateProgram(); + api.AttachShader(program, shader); + api.LinkProgram(program); - GL.DetachShader(program, shader); - GL.DeleteShader(shader); + api.DetachShader(program, shader); + api.DeleteShader(shader); return program; } diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs index 2834106bfa..173fb98755 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs @@ -6,20 +6,20 @@ using System; namespace Ryujinx.Graphics.OpenGL.Effects.Smaa { - internal partial class SmaaPostProcessingEffect : IPostProcessingEffect + internal class SmaaPostProcessingEffect : IPostProcessingEffect { public const int AreaWidth = 160; public const int AreaHeight = 560; public const int SearchWidth = 64; public const int SearchHeight = 16; - private readonly OpenGLRenderer _renderer; + private readonly OpenGLRenderer _gd; private TextureStorage _outputTexture; private TextureStorage _searchTexture; private TextureStorage _areaTexture; - private int[] _edgeShaderPrograms; - private int[] _blendShaderPrograms; - private int[] _neighbourShaderPrograms; + private uint[] _edgeShaderPrograms; + private uint[] _blendShaderPrograms; + private uint[] _neighbourShaderPrograms; private TextureStorage _edgeOutputTexture; private TextureStorage _blendOutputTexture; private readonly string[] _qualities; @@ -39,15 +39,15 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa _quality = Math.Clamp(value, 0, _qualities.Length - 1); } } - public SmaaPostProcessingEffect(OpenGLRenderer renderer, int quality) + public SmaaPostProcessingEffect(OpenGLRenderer gd, int quality) { - _renderer = renderer; + _gd = gd; - _edgeShaderPrograms = Array.Empty(); - _blendShaderPrograms = Array.Empty(); - _neighbourShaderPrograms = Array.Empty(); + _edgeShaderPrograms = Array.Empty(); + _blendShaderPrograms = Array.Empty(); + _neighbourShaderPrograms = Array.Empty(); - _qualities = new string[] { "SMAA_PRESET_LOW", "SMAA_PRESET_MEDIUM", "SMAA_PRESET_HIGH", "SMAA_PRESET_ULTRA" }; + _qualities = ["SMAA_PRESET_LOW", "SMAA_PRESET_MEDIUM", "SMAA_PRESET_HIGH", "SMAA_PRESET_ULTRA"]; Quality = quality; @@ -69,9 +69,9 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa { for (int i = 0; i < _edgeShaderPrograms.Length; i++) { - GL.DeleteProgram(_edgeShaderPrograms[i]); - GL.DeleteProgram(_blendShaderPrograms[i]); - GL.DeleteProgram(_neighbourShaderPrograms[i]); + _gd.Api.DeleteProgram(_edgeShaderPrograms[i]); + _gd.Api.DeleteProgram(_blendShaderPrograms[i]); + _gd.Api.DeleteProgram(_neighbourShaderPrograms[i]); } } @@ -80,9 +80,9 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa string baseShader = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/smaa.hlsl"); var pixelSizeDefine = $"#define SMAA_RT_METRICS float4(1.0 / {width}.0, 1.0 / {height}.0, {width}, {height}) \n"; - _edgeShaderPrograms = new int[_qualities.Length]; - _blendShaderPrograms = new int[_qualities.Length]; - _neighbourShaderPrograms = new int[_qualities.Length]; + _edgeShaderPrograms = new uint[_qualities.Length]; + _blendShaderPrograms = new uint[_qualities.Length]; + _neighbourShaderPrograms = new uint[_qualities.Length]; for (int i = 0; i < +_edgeShaderPrograms.Length; i++) { @@ -106,12 +106,12 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa _neighbourShaderPrograms[i] = neighbourProgram; } - _inputUniform = GL.GetUniformLocation(_edgeShaderPrograms[0], "inputTexture"); - _outputUniform = GL.GetUniformLocation(_edgeShaderPrograms[0], "imgOutput"); - _samplerAreaUniform = GL.GetUniformLocation(_blendShaderPrograms[0], "samplerArea"); - _samplerSearchUniform = GL.GetUniformLocation(_blendShaderPrograms[0], "samplerSearch"); - _samplerBlendUniform = GL.GetUniformLocation(_neighbourShaderPrograms[0], "samplerBlend"); - _resolutionUniform = GL.GetUniformLocation(_edgeShaderPrograms[0], "invResolution"); + _inputUniform = _gd.Api.GetUniformLocation(_edgeShaderPrograms[0], "inputTexture"); + _outputUniform = _gd.Api.GetUniformLocation(_edgeShaderPrograms[0], "imgOutput"); + _samplerAreaUniform = _gd.Api.GetUniformLocation(_blendShaderPrograms[0], "samplerArea"); + _samplerSearchUniform = _gd.Api.GetUniformLocation(_blendShaderPrograms[0], "samplerSearch"); + _samplerBlendUniform = _gd.Api.GetUniformLocation(_neighbourShaderPrograms[0], "samplerBlend"); + _resolutionUniform = _gd.Api.GetUniformLocation(_edgeShaderPrograms[0], "invResolution"); } private void Initialize() @@ -148,8 +148,8 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa SwizzleComponent.Blue, SwizzleComponent.Alpha); - _areaTexture = new TextureStorage(_renderer, areaInfo); - _searchTexture = new TextureStorage(_renderer, searchInfo); + _areaTexture = new TextureStorage(_gd, areaInfo); + _searchTexture = new TextureStorage(_gd, searchInfo); var areaTexture = EmbeddedResources.ReadFileToRentedMemory("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaAreaTexture.bin"); var searchTexture = EmbeddedResources.ReadFileToRentedMemory("Ryujinx.Graphics.OpenGL/Effects/Textures/SmaaSearchTexture.bin"); @@ -166,11 +166,11 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa if (_outputTexture == null || _outputTexture.Info.Width != view.Width || _outputTexture.Info.Height != view.Height) { _outputTexture?.Dispose(); - _outputTexture = new TextureStorage(_renderer, view.Info); + _outputTexture = new TextureStorage(_gd, view.Info); _outputTexture.CreateDefaultView(); - _edgeOutputTexture = new TextureStorage(_renderer, view.Info); + _edgeOutputTexture = new TextureStorage(_gd, view.Info); _edgeOutputTexture.CreateDefaultView(); - _blendOutputTexture = new TextureStorage(_renderer, view.Info); + _blendOutputTexture = new TextureStorage(_gd, view.Info); _blendOutputTexture.CreateDefaultView(); DeleteShaders(); @@ -184,77 +184,77 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa var areaTexture = _areaTexture.DefaultView as TextureView; var searchTexture = _searchTexture.DefaultView as TextureView; - var previousFramebuffer = GL.GetInteger(GetPName.FramebufferBinding); - int previousUnit = GL.GetInteger(GetPName.ActiveTexture); - GL.ActiveTexture(TextureUnit.Texture0); - int previousTextureBinding0 = GL.GetInteger(GetPName.TextureBinding2D); - GL.ActiveTexture(TextureUnit.Texture1); - int previousTextureBinding1 = GL.GetInteger(GetPName.TextureBinding2D); - GL.ActiveTexture(TextureUnit.Texture2); - int previousTextureBinding2 = GL.GetInteger(GetPName.TextureBinding2D); + var previousFramebuffer = _gd.Api.GetInteger(GetPName.DrawFramebufferBinding); + int previousUnit = _gd.Api.GetInteger(GetPName.ActiveTexture); + _gd.Api.ActiveTexture(TextureUnit.Texture0); + int previousTextureBinding0 = _gd.Api.GetInteger(GetPName.TextureBinding2D); + _gd.Api.ActiveTexture(TextureUnit.Texture1); + int previousTextureBinding1 = _gd.Api.GetInteger(GetPName.TextureBinding2D); + _gd.Api.ActiveTexture(TextureUnit.Texture2); + int previousTextureBinding2 = _gd.Api.GetInteger(GetPName.TextureBinding2D); - var framebuffer = new Framebuffer(); + var framebuffer = new Framebuffer(_gd.Api); framebuffer.Bind(); framebuffer.AttachColor(0, edgeOutput); - GL.Clear(ClearBufferMask.ColorBufferBit); - GL.ClearColor(0, 0, 0, 0); + _gd.Api.Clear(ClearBufferMask.ColorBufferBit); + _gd.Api.ClearColor(0, 0, 0, 0); framebuffer.AttachColor(0, blendOutput); - GL.Clear(ClearBufferMask.ColorBufferBit); - GL.ClearColor(0, 0, 0, 0); + _gd.Api.Clear(ClearBufferMask.ColorBufferBit); + _gd.Api.ClearColor(0, 0, 0, 0); - GL.BindFramebuffer(FramebufferTarget.Framebuffer, previousFramebuffer); + _gd.Api.BindFramebuffer(FramebufferTarget.Framebuffer, previousFramebuffer); framebuffer.Dispose(); var dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize); var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); - int previousProgram = GL.GetInteger(GetPName.CurrentProgram); - GL.BindImageTexture(0, edgeOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); - GL.UseProgram(_edgeShaderPrograms[Quality]); + uint previousProgram = (uint)_gd.Api.GetInteger(GetPName.CurrentProgram); + _gd.Api.BindImageTexture(0, edgeOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.UseProgram(_edgeShaderPrograms[Quality]); view.Bind(0); - GL.Uniform1(_inputUniform, 0); - GL.Uniform1(_outputUniform, 0); - GL.Uniform2(_resolutionUniform, (float)view.Width, (float)view.Height); - GL.DispatchCompute(dispatchX, dispatchY, 1); - GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); + _gd.Api.Uniform1(_inputUniform, 0); + _gd.Api.Uniform1(_outputUniform, 0); + _gd.Api.Uniform2(_resolutionUniform, view.Width, view.Height); + _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); + _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - GL.BindImageTexture(0, blendOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); - GL.UseProgram(_blendShaderPrograms[Quality]); + _gd.Api.BindImageTexture(0, blendOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.UseProgram(_blendShaderPrograms[Quality]); edgeOutput.Bind(0); areaTexture.Bind(1); searchTexture.Bind(2); - GL.Uniform1(_inputUniform, 0); - GL.Uniform1(_outputUniform, 0); - GL.Uniform1(_samplerAreaUniform, 1); - GL.Uniform1(_samplerSearchUniform, 2); - GL.Uniform2(_resolutionUniform, (float)view.Width, (float)view.Height); - GL.DispatchCompute(dispatchX, dispatchY, 1); - GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); + _gd.Api.Uniform1(_inputUniform, 0); + _gd.Api.Uniform1(_outputUniform, 0); + _gd.Api.Uniform1(_samplerAreaUniform, 1); + _gd.Api.Uniform1(_samplerSearchUniform, 2); + _gd.Api.Uniform2(_resolutionUniform, view.Width, view.Height); + _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); + _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - GL.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); - GL.UseProgram(_neighbourShaderPrograms[Quality]); + _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.UseProgram(_neighbourShaderPrograms[Quality]); view.Bind(0); blendOutput.Bind(1); - GL.Uniform1(_inputUniform, 0); - GL.Uniform1(_outputUniform, 0); - GL.Uniform1(_samplerBlendUniform, 1); - GL.Uniform2(_resolutionUniform, (float)view.Width, (float)view.Height); - GL.DispatchCompute(dispatchX, dispatchY, 1); - GL.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); + _gd.Api.Uniform1(_inputUniform, 0); + _gd.Api.Uniform1(_outputUniform, 0); + _gd.Api.Uniform1(_samplerBlendUniform, 1); + _gd.Api.Uniform2(_resolutionUniform, view.Width, view.Height); + _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); + _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - (_renderer.Pipeline as Pipeline).RestoreImages1And2(); + (_gd.Pipeline as Pipeline).RestoreImages1And2(); - GL.UseProgram(previousProgram); + _gd.Api.UseProgram(previousProgram); - GL.ActiveTexture(TextureUnit.Texture0); - GL.BindTexture(TextureTarget.Texture2D, previousTextureBinding0); - GL.ActiveTexture(TextureUnit.Texture1); - GL.BindTexture(TextureTarget.Texture2D, previousTextureBinding1); - GL.ActiveTexture(TextureUnit.Texture2); - GL.BindTexture(TextureTarget.Texture2D, previousTextureBinding2); + _gd.Api.ActiveTexture(TextureUnit.Texture0); + _gd.Api.BindTexture(TextureTarget.Texture2D, previousTextureBinding0); + _gd.Api.ActiveTexture(TextureUnit.Texture1); + _gd.Api.BindTexture(TextureTarget.Texture2D, previousTextureBinding1); + _gd.Api.ActiveTexture(TextureUnit.Texture2); + _gd.Api.BindTexture(TextureTarget.Texture2D, previousTextureBinding2); - GL.ActiveTexture((TextureUnit)previousUnit); + _gd.Api.ActiveTexture((TextureUnit)previousUnit); return textureView; } diff --git a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs index 4c63b15064..378dcdfc2a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -23,14 +23,15 @@ namespace Ryujinx.Graphics.OpenGL public Framebuffer(GL api) { - Handle = GL.GenFramebuffer(); - _clearFbHandle = GL.GenFramebuffer(); + _api = api; + + Handle = _api.GenFramebuffer(); + _clearFbHandle = _api.GenFramebuffer(); _colors = new TextureView[8]; - _api = api; } - public int Bind() + public uint Bind() { _api.BindFramebuffer(FramebufferTarget.Framebuffer, Handle); return Handle; @@ -203,7 +204,7 @@ namespace Ryujinx.Graphics.OpenGL if (!_clearFbInitialized) { - SetDrawBuffersImpl(Constants.MaxRenderTargets); + SetDrawBuffersImpl(_api, Constants.MaxRenderTargets); _clearFbInitialized = true; } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs index 1eafbf3c19..84fb553e08 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs @@ -6,7 +6,7 @@ namespace Ryujinx.Graphics.OpenGL.Image class Sampler : ISampler { public uint Handle { get; private set; } - private GL _api; + private readonly GL _api; public Sampler(GL api, SamplerCreateInfo info) { diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs index cec527dd6a..2436d035da 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs @@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { class TextureBase { - private readonly protected GL Api; + private readonly protected OpenGLRenderer _gd; public uint Handle { get; protected set; } public TextureCreateInfo Info { get; } @@ -16,12 +16,12 @@ namespace Ryujinx.Graphics.OpenGL.Image public Target Target => Info.Target; public Format Format => Info.Format; - public TextureBase(GL api, TextureCreateInfo info) + public TextureBase(OpenGLRenderer gd, TextureCreateInfo info) { - Api = api; + _gd = gd; Info = info; - Handle = Api.GenTexture(); + Handle = _gd.Api.GenTexture(); } public void Bind(uint unit) @@ -31,8 +31,8 @@ namespace Ryujinx.Graphics.OpenGL.Image protected void Bind(TextureTarget target, uint unit) { - Api.ActiveTexture((TextureUnit)((uint)TextureUnit.Texture0 + unit)); - Api.BindTexture(target, Handle); + _gd.Api.ActiveTexture((TextureUnit)((uint)TextureUnit.Texture0 + unit)); + _gd.Api.BindTexture(target, Handle); } public static void ClearBinding(GL api, uint unit) diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs index de18ecfbad..197a1076df 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs @@ -7,16 +7,15 @@ namespace Ryujinx.Graphics.OpenGL.Image { class TextureBuffer : TextureBase, ITexture { - private readonly OpenGLRenderer _renderer; private int _bufferOffset; private int _bufferSize; private int _bufferCount; private BufferHandle _buffer; - public TextureBuffer(GL api, OpenGLRenderer renderer, TextureCreateInfo info) : base(api, info) + public TextureBuffer(OpenGLRenderer gd, TextureCreateInfo info) : base(gd, info) { - _renderer = renderer; + } public void CopyTo(ITexture destination, int firstLayer, int firstLevel) @@ -41,7 +40,7 @@ namespace Ryujinx.Graphics.OpenGL.Image public PinnedSpan GetData() { - return Buffer.GetData(Api, _renderer, _buffer, _bufferOffset, _bufferSize); + return Buffer.GetData(_gd, _buffer, _bufferOffset, _bufferSize); } public PinnedSpan GetData(int layer, int level) @@ -59,7 +58,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { var dataSpan = data.Memory.Span; - Buffer.SetData(Api, _buffer, _bufferOffset, dataSpan[..Math.Min(dataSpan.Length, _bufferSize)]); + Buffer.SetData(_gd.Api, _buffer, _bufferOffset, dataSpan[..Math.Min(dataSpan.Length, _bufferSize)]); data.Dispose(); } @@ -82,7 +81,7 @@ namespace Ryujinx.Graphics.OpenGL.Image _buffer == buffer.Handle && buffer.Offset == _bufferOffset && buffer.Size == _bufferSize && - _renderer.BufferCount == _bufferCount) + _gd.BufferCount == _bufferCount) { // Only rebind the buffer when more have been created. return; @@ -91,20 +90,20 @@ namespace Ryujinx.Graphics.OpenGL.Image _buffer = buffer.Handle; _bufferOffset = buffer.Offset; _bufferSize = buffer.Size; - _bufferCount = _renderer.BufferCount; + _bufferCount = _gd.BufferCount; Bind(0); SizedInternalFormat format = (SizedInternalFormat)FormatTable.GetFormatInfo(Info.Format).InternalFormat; - Api.TexBufferRange(TextureTarget.TextureBuffer, format, _buffer.ToUInt32(), buffer.Offset, (uint)buffer.Size); + _gd.Api.TexBufferRange(TextureTarget.TextureBuffer, format, _buffer.ToUInt32(), buffer.Offset, (uint)buffer.Size); } public void Dispose() { if (Handle != 0) { - Api.DeleteTexture(Handle); + _gd.Api.DeleteTexture(Handle); Handle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index 3f2bc73349..e48ef6152b 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -7,8 +7,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { class TextureCopy : IDisposable { - private readonly GL _api; - private readonly OpenGLRenderer _renderer; + private readonly OpenGLRenderer _gd; private uint _srcFramebuffer; private uint _dstFramebuffer; @@ -18,11 +17,10 @@ namespace Ryujinx.Graphics.OpenGL.Image public IntermediatePool IntermediatePool { get; } - public TextureCopy(GL api, OpenGLRenderer renderer) + public TextureCopy(OpenGLRenderer gd) { - _api = api; - _renderer = renderer; - IntermediatePool = new IntermediatePool(renderer); + _gd = gd; + IntermediatePool = new IntermediatePool(gd); } public void Copy( @@ -57,10 +55,10 @@ namespace Ryujinx.Graphics.OpenGL.Image { TextureView srcConverted = src.Format.IsBgr() != dst.Format.IsBgr() ? BgraSwap(src) : src; - (uint oldDrawFramebufferHandle, uint oldReadFramebufferHandle) = ((Pipeline)_renderer.Pipeline).GetBoundFramebuffers(); + (uint oldDrawFramebufferHandle, uint oldReadFramebufferHandle) = ((Pipeline)_gd.Pipeline).GetBoundFramebuffers(); - _api.BindFramebuffer(FramebufferTarget.ReadFramebuffer, GetSrcFramebufferLazy()); - _api.BindFramebuffer(FramebufferTarget.DrawFramebuffer, GetDstFramebufferLazy()); + _gd.Api.BindFramebuffer(FramebufferTarget.ReadFramebuffer, GetSrcFramebufferLazy()); + _gd.Api.BindFramebuffer(FramebufferTarget.DrawFramebuffer, GetDstFramebufferLazy()); if (srcLevel != 0) { @@ -78,13 +76,13 @@ namespace Ryujinx.Graphics.OpenGL.Image { if ((srcLayer | dstLayer) != 0 || layers > 1) { - Attach(_api, FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, srcLevel + level, srcLayer + layer); - Attach(_api, FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, dstLevel + level, dstLayer + layer); + Attach(_gd.Api, FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, srcLevel + level, srcLayer + layer); + Attach(_gd.Api, FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, dstLevel + level, dstLayer + layer); } else { - Attach(_api, FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, srcLevel + level); - Attach(_api, FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, dstLevel + level); + Attach(_gd.Api, FramebufferTarget.ReadFramebuffer, src.Format, srcConverted.Handle, srcLevel + level); + Attach(_gd.Api, FramebufferTarget.DrawFramebuffer, dst.Format, dst.Handle, dstLevel + level); } ClearBufferMask mask = GetMask(src.Format); @@ -98,13 +96,13 @@ namespace Ryujinx.Graphics.OpenGL.Image ? BlitFramebufferFilter.Linear : BlitFramebufferFilter.Nearest; - _api.ReadBuffer(ReadBufferMode.ColorAttachment0); - _api.DrawBuffer(DrawBufferMode.ColorAttachment0); + _gd.Api.ReadBuffer(ReadBufferMode.ColorAttachment0); + _gd.Api.DrawBuffer(DrawBufferMode.ColorAttachment0); - _api.Disable(EnableCap.RasterizerDiscard); - _api.Disable(EnableCap.ScissorTest, 0); + _gd.Api.Disable(EnableCap.RasterizerDiscard); + _gd.Api.Disable(EnableCap.ScissorTest, 0); - _api.BlitFramebuffer( + _gd.Api.BlitFramebuffer( srcRegion.X1, srcRegion.Y1, srcRegion.X2, @@ -124,14 +122,14 @@ namespace Ryujinx.Graphics.OpenGL.Image } } - Attach(_api, FramebufferTarget.ReadFramebuffer, src.Format, 0); - Attach(_api, FramebufferTarget.DrawFramebuffer, dst.Format, 0); + Attach(_gd.Api, FramebufferTarget.ReadFramebuffer, src.Format, 0); + Attach(_gd.Api, FramebufferTarget.DrawFramebuffer, dst.Format, 0); - _api.BindFramebuffer(FramebufferTarget.ReadFramebuffer, oldReadFramebufferHandle); - _api.BindFramebuffer(FramebufferTarget.DrawFramebuffer, oldDrawFramebufferHandle); + _gd.Api.BindFramebuffer(FramebufferTarget.ReadFramebuffer, oldReadFramebufferHandle); + _gd.Api.BindFramebuffer(FramebufferTarget.DrawFramebuffer, oldDrawFramebufferHandle); - ((Pipeline)_renderer.Pipeline).RestoreScissor0Enable(); - ((Pipeline)_renderer.Pipeline).RestoreRasterizerDiscard(); + ((Pipeline)_gd.Pipeline).RestoreScissor0Enable(); + ((Pipeline)_gd.Pipeline).RestoreRasterizerDiscard(); if (srcConverted != src) { @@ -180,8 +178,8 @@ namespace Ryujinx.Graphics.OpenGL.Image TextureCreateInfo srcInfo = src.Info; TextureCreateInfo dstInfo = dst.Info; - uint srcHandle = (uint)src.Handle; - uint dstHandle = (uint)dst.Handle; + uint srcHandle = src.Handle; + uint dstHandle = dst.Handle; int srcWidth = srcInfo.Width; int srcHeight = srcInfo.Height; @@ -242,7 +240,7 @@ namespace Ryujinx.Graphics.OpenGL.Image if (HwCapabilities.Vendor == HwCapabilities.GpuVendor.IntelWindows) { - _api.CopyImageSubData( + _gd.Api.CopyImageSubData( src.Storage.Handle, src.Storage.Info.Target.ConvertToImageTarget(), (int)src.FirstLevel + srcLevel + level, @@ -261,7 +259,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } else { - _api.CopyImageSubData( + _gd.Api.CopyImageSubData( srcHandle, srcInfo.Target.ConvertToImageTarget(), srcLevel + level, @@ -346,20 +344,20 @@ namespace Ryujinx.Graphics.OpenGL.Image public TextureView BgraSwap(TextureView from) { - TextureView to = (TextureView)_renderer.CreateTexture(from.Info); + TextureView to = (TextureView)_gd.CreateTexture(from.Info); EnsurePbo(from); - _api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); + _gd.Api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); from.WriteToPbo(0, forceBgra: true); - _api.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); - _api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); + _gd.Api.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); + _gd.Api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); to.ReadFromPbo(0, _copyPboSize); - _api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); + _gd.Api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); return to; } @@ -395,7 +393,7 @@ namespace Ryujinx.Graphics.OpenGL.Image EnsurePbo(from); - _api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); + _gd.Api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); // The source texture is written out in full, then the destination is taken as a slice from the data using unpack params. // The offset points to the base at which the requested layer is at. @@ -409,39 +407,39 @@ namespace Ryujinx.Graphics.OpenGL.Image if (slice) { // Set unpack parameters to take a slice of width/height: - _api.PixelStore(PixelStoreParameter.UnpackRowLength, unpackWidth); - _api.PixelStore(PixelStoreParameter.UnpackImageHeight, unpackHeight); + _gd.Api.PixelStore(PixelStoreParameter.UnpackRowLength, unpackWidth); + _gd.Api.PixelStore(PixelStoreParameter.UnpackImageHeight, unpackHeight); if (to.Info.IsCompressed) { - _api.PixelStore(GLEnum.UnpackCompressedBlockWidth, to.Info.BlockWidth); - _api.PixelStore(GLEnum.UnpackCompressedBlockHeight, to.Info.BlockHeight); - _api.PixelStore(GLEnum.UnpackCompressedBlockDepth, 1); - _api.PixelStore(GLEnum.UnpackCompressedBlockSize, to.Info.BytesPerPixel); + _gd.Api.PixelStore(GLEnum.UnpackCompressedBlockWidth, to.Info.BlockWidth); + _gd.Api.PixelStore(GLEnum.UnpackCompressedBlockHeight, to.Info.BlockHeight); + _gd.Api.PixelStore(GLEnum.UnpackCompressedBlockDepth, 1); + _gd.Api.PixelStore(GLEnum.UnpackCompressedBlockSize, to.Info.BytesPerPixel); } } - _api.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); - _api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); + _gd.Api.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); + _gd.Api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, _copyPboHandle); to.ReadFromPbo2D(offset, dstLayer, dstLevel, dstWidth, dstHeight); if (slice) { // Reset unpack parameters - _api.PixelStore(PixelStoreParameter.UnpackRowLength, 0); - _api.PixelStore(PixelStoreParameter.UnpackImageHeight, 0); + _gd.Api.PixelStore(PixelStoreParameter.UnpackRowLength, 0); + _gd.Api.PixelStore(PixelStoreParameter.UnpackImageHeight, 0); if (to.Info.IsCompressed) { - _api.PixelStore(GLEnum.UnpackCompressedBlockWidth, 0); - _api.PixelStore(GLEnum.UnpackCompressedBlockHeight, 0); - _api.PixelStore(GLEnum.UnpackCompressedBlockDepth, 0); - _api.PixelStore(GLEnum.UnpackCompressedBlockSize, 0); + _gd.Api.PixelStore(GLEnum.UnpackCompressedBlockWidth, 0); + _gd.Api.PixelStore(GLEnum.UnpackCompressedBlockHeight, 0); + _gd.Api.PixelStore(GLEnum.UnpackCompressedBlockDepth, 0); + _gd.Api.PixelStore(GLEnum.UnpackCompressedBlockSize, 0); } } - _api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); + _gd.Api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); } private void EnsurePbo(TextureView view) @@ -455,18 +453,18 @@ namespace Ryujinx.Graphics.OpenGL.Image if (_copyPboSize < requiredSize && _copyPboHandle != 0) { - _api.DeleteBuffer(_copyPboHandle); + _gd.Api.DeleteBuffer(_copyPboHandle); _copyPboHandle = 0; } if (_copyPboHandle == 0) { - _copyPboHandle = _api.GenBuffer(); + _copyPboHandle = _gd.Api.GenBuffer(); _copyPboSize = requiredSize; - _api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); - _api.BufferData(BufferTargetARB.PixelPackBuffer, (uint)requiredSize, IntPtr.Zero, BufferUsageARB.DynamicCopy); + _gd.Api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); + _gd.Api.BufferData(BufferTargetARB.PixelPackBuffer, (uint)requiredSize, IntPtr.Zero, BufferUsageARB.DynamicCopy); } } @@ -474,7 +472,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { if (_srcFramebuffer == 0) { - _srcFramebuffer = _api.GenFramebuffer(); + _srcFramebuffer = _gd.Api.GenFramebuffer(); } return _srcFramebuffer; @@ -484,7 +482,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { if (_dstFramebuffer == 0) { - _dstFramebuffer = _api.GenFramebuffer(); + _dstFramebuffer = _gd.Api.GenFramebuffer(); } return _dstFramebuffer; @@ -494,21 +492,21 @@ namespace Ryujinx.Graphics.OpenGL.Image { if (_srcFramebuffer != 0) { - _api.DeleteFramebuffer(_srcFramebuffer); + _gd.Api.DeleteFramebuffer(_srcFramebuffer); _srcFramebuffer = 0; } if (_dstFramebuffer != 0) { - _api.DeleteFramebuffer(_dstFramebuffer); + _gd.Api.DeleteFramebuffer(_dstFramebuffer); _dstFramebuffer = 0; } if (_copyPboHandle != 0) { - _api.DeleteBuffer(_copyPboHandle); + _gd.Api.DeleteBuffer(_copyPboHandle); _copyPboHandle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs index 271f66ff58..5aaa1cebea 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs @@ -67,15 +67,13 @@ void main() imageStore(dst, ivec2(coords), uvec4(r, g, b, a)); }"; - private readonly GL _api; - private readonly OpenGLRenderer _renderer; + private readonly OpenGLRenderer _gd; private readonly Dictionary _shorteningProgramHandles; private readonly Dictionary _wideningProgramHandles; - public TextureCopyIncompatible(GL api, OpenGLRenderer renderer) + public TextureCopyIncompatible(OpenGLRenderer gd) { - _api = api; - _renderer = renderer; + _gd = gd; _shorteningProgramHandles = new Dictionary(); _wideningProgramHandles = new Dictionary(); } @@ -96,7 +94,7 @@ void main() var srcFormat = (InternalFormat)GetFormat(componentSize, srcComponentsCount); var dstFormat = (InternalFormat)GetFormat(componentSize, dstComponentsCount); - _api.UseProgram(srcBpp < dstBpp + _gd.Api.UseProgram(srcBpp < dstBpp ? GetWideningShader(componentSize, srcComponentsCount, dstComponentsCount) : GetShorteningShader(componentSize, srcComponentsCount, dstComponentsCount)); @@ -113,14 +111,14 @@ void main() for (int z = 0; z < depth; z++) { - _api.BindImageTexture(0, src.Handle, srcLevel + l, false, srcLayer + z, BufferAccessARB.ReadOnly, srcFormat); - _api.BindImageTexture(1, dst.Handle, dstLevel + l, false, dstLayer + z, BufferAccessARB.WriteOnly, dstFormat); + _gd.Api.BindImageTexture(0, src.Handle, srcLevel + l, false, srcLayer + z, BufferAccessARB.ReadOnly, srcFormat); + _gd.Api.BindImageTexture(1, dst.Handle, dstLevel + l, false, dstLayer + z, BufferAccessARB.WriteOnly, dstFormat); - _api.DispatchCompute((width + 31) / 32, (height + 31) / 32, 1); + _gd.Api.DispatchCompute((width + 31) / 32, (height + 31) / 32, 1); } } - Pipeline pipeline = (Pipeline)_renderer.Pipeline; + Pipeline pipeline = (Pipeline)_gd.Pipeline; pipeline.RestoreProgram(); pipeline.RestoreImages1And2(); @@ -190,7 +188,7 @@ void main() if (!programHandles.TryGetValue(key, out uint programHandle)) { - uint csHandle = _api.CreateShader(ShaderType.ComputeShader); + uint csHandle = _gd.Api.CreateShader(ShaderType.ComputeShader); string[] formatTable = new[] { "r8ui", "r16ui", "r32ui", "rg8ui", "rg16ui", "rg32ui", "rgba8ui", "rgba16ui", "rgba32ui" }; @@ -203,25 +201,25 @@ void main() int ratio = srcBpp < dstBpp ? dstBpp / srcBpp : srcBpp / dstBpp; int ratioLog2 = BitOperations.Log2((uint)ratio); - _api.ShaderSource(csHandle, code + _gd.Api.ShaderSource(csHandle, code .Replace("$SRC_FORMAT$", srcFormat) .Replace("$DST_FORMAT$", dstFormat) .Replace("$RATIO_LOG2$", ratioLog2.ToString(CultureInfo.InvariantCulture))); - _api.CompileShader(csHandle); + _gd.Api.CompileShader(csHandle); - programHandle = _api.CreateProgram(); + programHandle = _gd.Api.CreateProgram(); - _api.AttachShader(programHandle, csHandle); - _api.LinkProgram(programHandle); - _api.DetachShader(programHandle, csHandle); - _api.DeleteShader(csHandle); + _gd.Api.AttachShader(programHandle, csHandle); + _gd.Api.LinkProgram(programHandle); + _gd.Api.DetachShader(programHandle, csHandle); + _gd.Api.DeleteShader(csHandle); - _api.GetProgram(programHandle, ProgramPropertyARB.LinkStatus, out int status); + _gd.Api.GetProgram(programHandle, ProgramPropertyARB.LinkStatus, out int status); if (status == 0) { - throw new Exception(_api.GetProgramInfoLog(programHandle)); + throw new Exception(_gd.Api.GetProgramInfoLog(programHandle)); } programHandles.Add(key, programHandle); @@ -234,14 +232,14 @@ void main() { foreach (uint handle in _shorteningProgramHandles.Values) { - _api.DeleteProgram(handle); + _gd.Api.DeleteProgram(handle); } _shorteningProgramHandles.Clear(); foreach (uint handle in _wideningProgramHandles.Values) { - _api.DeleteProgram(handle); + _gd.Api.DeleteProgram(handle); } _wideningProgramHandles.Clear(); diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs index 473fd44bda..844e3489c9 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs @@ -93,15 +93,13 @@ void main() imageStore(imgOut, ivec2(int(coords.x) >> samplesInXLog2, int(coords.y) >> samplesInYLog2), sampleIdx, value); }"; - private readonly GL _api; - private readonly OpenGLRenderer _renderer; + private readonly OpenGLRenderer _gd; private readonly uint[] _msToNonMSProgramHandles; private readonly uint[] _nonMSToMSProgramHandles; - public TextureCopyMS(GL api, OpenGLRenderer renderer) + public TextureCopyMS(OpenGLRenderer gd) { - _api = api; - _renderer = renderer; + _gd = gd; _msToNonMSProgramHandles = new uint[5]; _nonMSToMSProgramHandles = new uint[5]; } @@ -117,17 +115,17 @@ void main() uint dstWidth = (uint)dstInfo.Width; uint dstHeight = (uint)dstInfo.Height; - _api.UseProgram(GetMSToNonMSShader(srcInfo.BytesPerPixel)); + _gd.Api.UseProgram(GetMSToNonMSShader(srcInfo.BytesPerPixel)); for (int z = 0; z < depth; z++) { - _api.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, (InternalFormat)GetFormat(srcInfo.BytesPerPixel)); - _api.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, (InternalFormat)GetFormat(dstInfo.BytesPerPixel)); + _gd.Api.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, (InternalFormat)GetFormat(srcInfo.BytesPerPixel)); + _gd.Api.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, (InternalFormat)GetFormat(dstInfo.BytesPerPixel)); - _api.DispatchCompute((dstWidth + 31) / 32, (dstHeight + 31) / 32, 1); + _gd.Api.DispatchCompute((dstWidth + 31) / 32, (dstHeight + 31) / 32, 1); } - Pipeline pipeline = (Pipeline)_renderer.Pipeline; + Pipeline pipeline = (Pipeline)_gd.Pipeline; pipeline.RestoreProgram(); pipeline.RestoreImages1And2(); @@ -147,17 +145,17 @@ void main() uint srcWidth = (uint)srcInfo.Width; uint srcHeight = (uint)srcInfo.Height; - _api.UseProgram(GetNonMSToMSShader(srcInfo.BytesPerPixel)); + _gd.Api.UseProgram(GetNonMSToMSShader(srcInfo.BytesPerPixel)); for (int z = 0; z < depth; z++) { - _api.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, (InternalFormat)GetFormat(srcInfo.BytesPerPixel)); - _api.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, (InternalFormat)GetFormat(dstInfo.BytesPerPixel)); + _gd.Api.BindImageTexture(0, srcHandle, 0, false, srcLayer + z, BufferAccessARB.ReadOnly, (InternalFormat)GetFormat(srcInfo.BytesPerPixel)); + _gd.Api.BindImageTexture(1, dstHandle, 0, false, dstLayer + z, BufferAccessARB.WriteOnly, (InternalFormat)GetFormat(dstInfo.BytesPerPixel)); - _api.DispatchCompute((srcWidth + 31) / 32, (srcHeight + 31) / 32, 1); + _gd.Api.DispatchCompute((srcWidth + 31) / 32, (srcHeight + 31) / 32, 1); } - Pipeline pipeline = (Pipeline)_renderer.Pipeline; + Pipeline pipeline = (Pipeline)_gd.Pipeline; pipeline.RestoreProgram(); pipeline.RestoreImages1And2(); @@ -185,9 +183,9 @@ void main() // we need to create and bind a RGBA view for it to work. if (texture.Info.Format == Format.R8G8B8A8Srgb) { - uint handle = _api.GenTexture(); + uint handle = _gd.Api.GenTexture(); - _api.TextureView( + _gd.Api.TextureView( handle, texture.Info.Target.Convert(), texture.Storage.Handle, @@ -207,7 +205,7 @@ void main() { if (info.Handle != handle) { - _api.DeleteTexture(handle); + _gd.Api.DeleteTexture(handle); } } @@ -227,25 +225,25 @@ void main() if (programHandles[index] == 0) { - uint csHandle = _api.CreateShader(ShaderType.ComputeShader); + uint csHandle = _gd.Api.CreateShader(ShaderType.ComputeShader); string format = new[] { "r8ui", "r16ui", "r32ui", "rg32ui", "rgba32ui" }[index]; - _api.ShaderSource(csHandle, code.Replace("$FORMAT$", format)); - _api.CompileShader(csHandle); + _gd.Api.ShaderSource(csHandle, code.Replace("$FORMAT$", format)); + _gd.Api.CompileShader(csHandle); - uint programHandle = _api.CreateProgram(); + uint programHandle = _gd.Api.CreateProgram(); - _api.AttachShader(programHandle, csHandle); - _api.LinkProgram(programHandle); - _api.DetachShader(programHandle, csHandle); - _api.DeleteShader(csHandle); + _gd.Api.AttachShader(programHandle, csHandle); + _gd.Api.LinkProgram(programHandle); + _gd.Api.DetachShader(programHandle, csHandle); + _gd.Api.DeleteShader(csHandle); - _api.GetProgram(programHandle, ProgramPropertyARB.LinkStatus, out int status); + _gd.Api.GetProgram(programHandle, ProgramPropertyARB.LinkStatus, out int status); if (status == 0) { - throw new Exception(_api.GetProgramInfoLog(programHandle)); + throw new Exception(_gd.Api.GetProgramInfoLog(programHandle)); } programHandles[index] = programHandle; @@ -260,7 +258,7 @@ void main() { if (_msToNonMSProgramHandles[i] != 0) { - _api.DeleteProgram(_msToNonMSProgramHandles[i]); + _gd.Api.DeleteProgram(_msToNonMSProgramHandles[i]); _msToNonMSProgramHandles[i] = 0; } } @@ -269,7 +267,7 @@ void main() { if (_nonMSToMSProgramHandles[i] != 0) { - _api.DeleteProgram(_nonMSToMSProgramHandles[i]); + _gd.Api.DeleteProgram(_nonMSToMSProgramHandles[i]); _nonMSToMSProgramHandles[i] = 0; } } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs index 8c0be4b7d6..936e076509 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs @@ -11,20 +11,18 @@ namespace Ryujinx.Graphics.OpenGL.Image public TextureCreateInfo Info { get; } - private readonly OpenGLRenderer _renderer; - private readonly GL _api; + private readonly OpenGLRenderer _gd; private int _viewsCount; internal ITexture DefaultView { get; private set; } - public TextureStorage(GL api, OpenGLRenderer renderer, TextureCreateInfo info) + public TextureStorage(OpenGLRenderer gd, TextureCreateInfo info) { - _api = api; - _renderer = renderer; + _gd = gd; Info = info; - Handle = _api.GenTexture(); + Handle = _gd.Api.GenTexture(); CreateImmutableStorage(); } @@ -33,9 +31,9 @@ namespace Ryujinx.Graphics.OpenGL.Image { TextureTarget target = Info.Target.Convert(); - _api.ActiveTexture(TextureUnit.Texture0); + _gd.Api.ActiveTexture(TextureUnit.Texture0); - _api.BindTexture(target, Handle); + _gd.Api.BindTexture(target, Handle); FormatInfo format = FormatTable.GetFormatInfo(Info.Format); @@ -55,7 +53,7 @@ namespace Ryujinx.Graphics.OpenGL.Image switch (Info.Target) { case Target.Texture1D: - _api.TexStorage1D( + _gd.Api.TexStorage1D( TextureTarget.Texture1D, levels, internalFormat, @@ -63,7 +61,7 @@ namespace Ryujinx.Graphics.OpenGL.Image break; case Target.Texture1DArray: - _api.TexStorage2D( + _gd.Api.TexStorage2D( TextureTarget.Texture1DArray, levels, internalFormat, @@ -72,7 +70,7 @@ namespace Ryujinx.Graphics.OpenGL.Image break; case Target.Texture2D: - _api.TexStorage2D( + _gd.Api.TexStorage2D( TextureTarget.Texture2D, levels, internalFormat, @@ -81,7 +79,7 @@ namespace Ryujinx.Graphics.OpenGL.Image break; case Target.Texture2DArray: - _api.TexStorage3D( + _gd.Api.TexStorage3D( TextureTarget.Texture2DArray, levels, internalFormat, @@ -91,7 +89,7 @@ namespace Ryujinx.Graphics.OpenGL.Image break; case Target.Texture2DMultisample: - _api.TexStorage2DMultisample( + _gd.Api.TexStorage2DMultisample( TextureTarget.Texture2DMultisample, (uint)Info.Samples, internalFormat, @@ -101,7 +99,7 @@ namespace Ryujinx.Graphics.OpenGL.Image break; case Target.Texture2DMultisampleArray: - _api.TexStorage3DMultisample( + _gd.Api.TexStorage3DMultisample( TextureTarget.Texture2DMultisampleArray, (uint)Info.Samples, internalFormat, @@ -112,7 +110,7 @@ namespace Ryujinx.Graphics.OpenGL.Image break; case Target.Texture3D: - _api.TexStorage3D( + _gd.Api.TexStorage3D( TextureTarget.Texture3D, levels, internalFormat, @@ -122,7 +120,7 @@ namespace Ryujinx.Graphics.OpenGL.Image break; case Target.Cubemap: - _api.TexStorage2D( + _gd.Api.TexStorage2D( TextureTarget.TextureCubeMap, levels, internalFormat, @@ -131,7 +129,7 @@ namespace Ryujinx.Graphics.OpenGL.Image break; case Target.CubemapArray: - _api.TexStorage3D( + _gd.Api.TexStorage3D( TextureTarget.TextureCubeMapArray, levels, internalFormat, @@ -153,11 +151,11 @@ namespace Ryujinx.Graphics.OpenGL.Image return DefaultView; } - public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel) + public ITexture CreateView(TextureCreateInfo info, uint firstLayer, uint firstLevel) { IncrementViewsCount(); - return new TextureView(_renderer, this, info, firstLayer, firstLevel); + return new TextureView(_gd, this, info, firstLayer, firstLevel); } private void IncrementViewsCount() @@ -189,7 +187,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { _viewsCount = 1; // When we are used again, we will have the default view. - _renderer.ResourcePool.AddTexture((TextureView)DefaultView); + _gd.ResourcePool.AddTexture((TextureView)DefaultView); } public void DeleteDefault() @@ -203,7 +201,7 @@ namespace Ryujinx.Graphics.OpenGL.Image if (Handle != 0) { - _api.DeleteTexture(Handle); + _gd.Api.DeleteTexture(Handle); Handle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index 3d65c8a29a..5519c11fd4 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -9,23 +9,20 @@ namespace Ryujinx.Graphics.OpenGL.Image { class TextureView : TextureBase, ITexture, ITextureInfo { - private readonly OpenGLRenderer _renderer; - private readonly TextureStorage _parent; public ITextureInfo Storage => _parent; - public int FirstLayer { get; private set; } - public int FirstLevel { get; private set; } + public uint FirstLayer { get; private set; } + public uint FirstLevel { get; private set; } public TextureView( - OpenGLRenderer renderer, + OpenGLRenderer gd, TextureStorage parent, TextureCreateInfo info, - int firstLayer, - int firstLevel) : base(info) + uint firstLayer, + uint firstLevel) : base(gd, info) { - _renderer = renderer; _parent = parent; FirstLayer = firstLayer; @@ -40,20 +37,20 @@ namespace Ryujinx.Graphics.OpenGL.Image FormatInfo format = FormatTable.GetFormatInfo(Info.Format); - InternalFormat pixelInternalFormat; + SizedInternalFormat pixelInternalFormat; if (format.IsCompressed) { - pixelInternalFormat = (InternalFormat)format.PixelFormat; + pixelInternalFormat = (SizedInternalFormat)format.PixelFormat; } else { - pixelInternalFormat = format.InternalFormat; + pixelInternalFormat = (SizedInternalFormat)format.InternalFormat; } - int levels = Info.GetLevelsClamped(); + uint levels = (uint)Info.GetLevelsClamped(); - GL.TextureView( + _gd.Api.TextureView( Handle, target, _parent.Handle, @@ -61,11 +58,11 @@ namespace Ryujinx.Graphics.OpenGL.Image FirstLevel, levels, FirstLayer, - Info.GetLayers()); + (uint)Info.GetLayers()); - GL.ActiveTexture(TextureUnit.Texture0); + _gd.Api.ActiveTexture(TextureUnit.Texture0); - GL.BindTexture(target, Handle); + _gd.Api.BindTexture(target, Handle); int[] swizzleRgba = new int[] { @@ -91,20 +88,20 @@ namespace Ryujinx.Graphics.OpenGL.Image (swizzleRgba[2], swizzleRgba[0]) = (swizzleRgba[0], swizzleRgba[2]); } - GL.TexParameter(target, TextureParameterName.TextureSwizzleRgba, swizzleRgba); + _gd.Api.TexParameter(target, TextureParameterName.TextureSwizzleRgba, swizzleRgba); - int maxLevel = levels - 1; + uint maxLevel = levels - 1; if (maxLevel < 0) { maxLevel = 0; } - GL.TexParameter(target, TextureParameterName.TextureMaxLevel, maxLevel); - GL.TexParameter(target, TextureParameterName.DepthStencilTextureMode, (int)Info.DepthStencilMode.Convert()); + _gd.Api.TexParameter(target, TextureParameterName.TextureMaxLevel, maxLevel); + _gd.Api.TexParameter(target, TextureParameterName.DepthStencilTextureMode, (int)Info.DepthStencilMode.Convert()); } - public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel) + public ITexture CreateView(TextureCreateInfo info, uint firstLayer, uint firstLevel) { firstLayer += FirstLayer; firstLevel += FirstLevel; @@ -112,7 +109,7 @@ namespace Ryujinx.Graphics.OpenGL.Image return _parent.CreateView(info, firstLayer, firstLevel); } - public void CopyTo(ITexture destination, int firstLayer, int firstLevel) + public void CopyTo(ITexture destination, uint firstLayer, uint firstLevel) { TextureView destinationView = (TextureView)destination; @@ -121,24 +118,24 @@ namespace Ryujinx.Graphics.OpenGL.Image if (dstIsMultisample != srcIsMultisample && Info.Format.IsDepthOrStencil()) { - int layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); + uint layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); CopyWithBlitForDepthMS(destinationView, 0, firstLayer, layers); } else if (!dstIsMultisample && srcIsMultisample) { - int layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); - _renderer.TextureCopyMS.CopyMSToNonMS(this, destinationView, 0, firstLayer, layers); + uint layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); + _gd.TextureCopyMS.CopyMSToNonMS(this, destinationView, 0, firstLayer, layers); } else if (dstIsMultisample && !srcIsMultisample) { - int layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); - _renderer.TextureCopyMS.CopyNonMSToMS(this, destinationView, 0, firstLayer, layers); + uint layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); + _gd.TextureCopyMS.CopyNonMSToMS(this, destinationView, 0, firstLayer, layers); } else if (destinationView.Info.BytesPerPixel != Info.BytesPerPixel) { int layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); int levels = Math.Min(Info.Levels, destinationView.Info.Levels - firstLevel); - _renderer.TextureCopyIncompatible.CopyIncompatibleFormats(this, destinationView, 0, firstLayer, 0, firstLevel, layers, levels); + _gd.TextureCopyIncompatible.CopyIncompatibleFormats(this, destinationView, 0, firstLayer, 0, firstLevel, layers, levels); } else if (destinationView.Format.IsDepthOrStencil() != Format.IsDepthOrStencil()) { @@ -158,13 +155,13 @@ namespace Ryujinx.Graphics.OpenGL.Image for (int layer = 0; layer < layers; layer++) { - _renderer.TextureCopy.PboCopy(this, destinationView, 0, firstLayer + layer, 0, firstLevel + level, minWidth, minHeight); + _gd.TextureCopy.PboCopy(this, destinationView, 0, firstLayer + layer, 0, firstLevel + level, minWidth, minHeight); } } } else { - _renderer.TextureCopy.CopyUnscaled(this, destinationView, 0, firstLayer, 0, firstLevel); + _gd.TextureCopy.CopyUnscaled(this, destinationView, 0, firstLayer, 0, firstLevel); } } @@ -181,30 +178,30 @@ namespace Ryujinx.Graphics.OpenGL.Image } else if (!dstIsMultisample && srcIsMultisample) { - _renderer.TextureCopyMS.CopyMSToNonMS(this, destinationView, srcLayer, dstLayer, 1); + _gd.TextureCopyMS.CopyMSToNonMS(this, destinationView, srcLayer, dstLayer, 1); } else if (dstIsMultisample && !srcIsMultisample) { - _renderer.TextureCopyMS.CopyNonMSToMS(this, destinationView, srcLayer, dstLayer, 1); + _gd.TextureCopyMS.CopyNonMSToMS(this, destinationView, srcLayer, dstLayer, 1); } else if (destinationView.Info.BytesPerPixel != Info.BytesPerPixel) { - _renderer.TextureCopyIncompatible.CopyIncompatibleFormats(this, destinationView, srcLayer, dstLayer, srcLevel, dstLevel, 1, 1); + _gd.TextureCopyIncompatible.CopyIncompatibleFormats(this, destinationView, srcLayer, dstLayer, srcLevel, dstLevel, 1, 1); } else if (destinationView.Format.IsDepthOrStencil() != Format.IsDepthOrStencil()) { int minWidth = Math.Min(Width, destinationView.Width); int minHeight = Math.Min(Height, destinationView.Height); - _renderer.TextureCopy.PboCopy(this, destinationView, srcLayer, dstLayer, srcLevel, dstLevel, minWidth, minHeight); + _gd.TextureCopy.PboCopy(this, destinationView, srcLayer, dstLayer, srcLevel, dstLevel, minWidth, minHeight); } else { - _renderer.TextureCopy.CopyUnscaled(this, destinationView, srcLayer, dstLayer, srcLevel, dstLevel, 1, 1); + _gd.TextureCopy.CopyUnscaled(this, destinationView, srcLayer, dstLayer, srcLevel, dstLevel, 1, 1); } } - private void CopyWithBlitForDepthMS(TextureView destinationView, int srcLayer, int dstLayer, int layers) + private void CopyWithBlitForDepthMS(TextureView destinationView, int srcLayer, int dstLayer, uint layers) { // This is currently used for multisample <-> non-multisample copies. // We can't do that with compute because it's not possible to write depth textures on compute. @@ -218,7 +215,7 @@ namespace Ryujinx.Graphics.OpenGL.Image if (destinationView.Target.IsMultisample()) { - TextureView intermmediate = _renderer.TextureCopy.IntermediatePool.GetOrCreateWithAtLeast( + TextureView intermmediate = _gd.TextureCopy.IntermediatePool.GetOrCreateWithAtLeast( Info.Target, Info.BlockWidth, Info.BlockHeight, @@ -230,8 +227,8 @@ namespace Ryujinx.Graphics.OpenGL.Image 1, 1); - _renderer.TextureCopy.Copy(this, intermmediate, srcRegion, dstRegion, false); - _renderer.TextureCopy.Copy(intermmediate, destinationView, dstRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); + _gd.TextureCopy.Copy(this, intermmediate, srcRegion, dstRegion, false); + _gd.TextureCopy.Copy(intermmediate, destinationView, dstRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); } else { @@ -242,7 +239,7 @@ namespace Ryujinx.Graphics.OpenGL.Image _ => Target, }; - TextureView intermmediate = _renderer.TextureCopy.IntermediatePool.GetOrCreateWithAtLeast( + TextureView intermmediate = _gd.TextureCopy.IntermediatePool.GetOrCreateWithAtLeast( target, Info.BlockWidth, Info.BlockHeight, @@ -254,14 +251,14 @@ namespace Ryujinx.Graphics.OpenGL.Image 1, 1); - _renderer.TextureCopy.Copy(this, intermmediate, srcRegion, srcRegion, false); - _renderer.TextureCopy.Copy(intermmediate, destinationView, srcRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); + _gd.TextureCopy.Copy(this, intermmediate, srcRegion, srcRegion, false); + _gd.TextureCopy.Copy(intermmediate, destinationView, srcRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); } } public void CopyTo(ITexture destination, Extents2D srcRegion, Extents2D dstRegion, bool linearFilter) { - _renderer.TextureCopy.Copy(this, (TextureView)destination, srcRegion, dstRegion, linearFilter); + _gd.TextureCopy.Copy(this, (TextureView)destination, srcRegion, dstRegion, linearFilter); } public unsafe PinnedSpan GetData() @@ -278,11 +275,11 @@ namespace Ryujinx.Graphics.OpenGL.Image if (HwCapabilities.UsePersistentBufferForFlush) { - data = _renderer.PersistentBuffers.Default.GetTextureData(this, size); + data = _gd.PersistentBuffers.Default.GetTextureData(this, size); } else { - IntPtr target = _renderer.PersistentBuffers.Default.GetHostArray(size); + IntPtr target = _gd.PersistentBuffers.Default.GetHostArray(size); WriteTo(target); @@ -303,11 +300,11 @@ namespace Ryujinx.Graphics.OpenGL.Image if (HwCapabilities.UsePersistentBufferForFlush) { - return PinnedSpan.UnsafeFromSpan(_renderer.PersistentBuffers.Default.GetTextureData(this, size, layer, level)); + return PinnedSpan.UnsafeFromSpan(_gd.PersistentBuffers.Default.GetTextureData(this, size, layer, level)); } else { - IntPtr target = _renderer.PersistentBuffers.Default.GetHostArray(size); + IntPtr target = _gd.PersistentBuffers.Default.GetHostArray(size); int offset = WriteTo2D(target, layer, level); @@ -322,7 +319,7 @@ namespace Ryujinx.Graphics.OpenGL.Image throw new NotSupportedException("Stride conversion for texture copy to buffer not supported."); } - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, range.Handle.ToInt32()); + _gd.Api.BindBuffer(BufferTargetARB.PixelPackBuffer, range.Handle.ToUInt32()); FormatInfo format = FormatTable.GetFormatInfo(Info.Format); if (format.PixelFormat == PixelFormat.DepthStencil) @@ -334,7 +331,7 @@ namespace Ryujinx.Graphics.OpenGL.Image Debug.Assert(offset == 0); - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); + _gd.Api.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); } public void WriteToPbo(int offset, bool forceBgra) @@ -367,15 +364,15 @@ namespace Ryujinx.Graphics.OpenGL.Image if (format.IsCompressed) { - GL.GetCompressedTextureSubImage(Handle, level, 0, 0, layer, Math.Max(1, Info.Width >> level), Math.Max(1, Info.Height >> level), 1, mipSize, data); + _gd.Api.GetCompressedTextureSubImage(Handle, level, 0, 0, layer, Math.Max(1, Info.Width >> level), Math.Max(1, Info.Height >> level), 1, mipSize, data); } else if (format.PixelFormat != PixelFormat.DepthStencil) { - GL.GetTextureSubImage(Handle, level, 0, 0, layer, Math.Max(1, Info.Width >> level), Math.Max(1, Info.Height >> level), 1, pixelFormat, pixelType, mipSize, data); + _gd.Api.GetTextureSubImage(Handle, level, 0, 0, layer, Math.Max(1, Info.Width >> level), Math.Max(1, Info.Height >> level), 1, pixelFormat, pixelType, mipSize, data); } else { - GL.GetTexImage(target, level, pixelFormat, pixelType, data); + _gd.Api.GetTexImage(target, level, pixelFormat, pixelType, data); // The GL function returns all layers. Must return the offset of the layer we're interested in. return target switch @@ -436,11 +433,11 @@ namespace Ryujinx.Graphics.OpenGL.Image if (format.IsCompressed) { - GL.GetCompressedTexImage(target + face, level, data + faceOffset); + _gd.Api.GetCompressedTexImage(target + face, level, data + faceOffset); } else { - GL.GetTexImage(target + face, level, pixelFormat, pixelType, data + faceOffset); + _gd.Api.GetTexImage(target + face, level, pixelFormat, pixelType, data + faceOffset); } } @@ -548,22 +545,22 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture1D: if (format.IsCompressed) { - GL.CompressedTexSubImage1D( + _gd.Api.CompressedTexSubImage1D( target, level, x, - width, - format.PixelFormat, - mipSize, + (uint)width, + (InternalFormat)format.PixelFormat, + (uint)mipSize, data); } else { - GL.TexSubImage1D( + _gd.Api.TexSubImage1D( target, level, x, - width, + (uint)width, format.PixelFormat, format.PixelType, data); @@ -573,25 +570,25 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture1DArray: if (format.IsCompressed) { - GL.CompressedTexSubImage2D( + _gd.Api.CompressedTexSubImage2D( target, level, x, layer, - width, + (uint)width, 1, - format.PixelFormat, - mipSize, + (InternalFormat)format.PixelFormat, + (uint)mipSize, data); } else { - GL.TexSubImage2D( + _gd.Api.TexSubImage2D( target, level, x, layer, - width, + (uint)width, 1, format.PixelFormat, format.PixelType, @@ -602,26 +599,26 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture2D: if (format.IsCompressed) { - GL.CompressedTexSubImage2D( + _gd.Api.CompressedTexSubImage2D( target, level, x, y, - width, - height, - format.PixelFormat, - mipSize, + (uint)width, + (uint)height, + (InternalFormat)format.PixelFormat, + (uint)mipSize, data); } else { - GL.TexSubImage2D( + _gd.Api.TexSubImage2D( target, level, x, y, - width, - height, + (uint)width, + (uint)height, format.PixelFormat, format.PixelType, data); @@ -633,29 +630,29 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.CubemapArray: if (format.IsCompressed) { - GL.CompressedTexSubImage3D( + _gd.Api.CompressedTexSubImage3D( target, level, x, y, layer, - width, - height, + (uint)width, + (uint)height, 1, - format.PixelFormat, - mipSize, + (InternalFormat)format.PixelFormat, + (uint)mipSize, data); } else { - GL.TexSubImage3D( + _gd.Api.TexSubImage3D( target, level, x, y, layer, - width, - height, + (uint)width, + (uint)height, 1, format.PixelFormat, format.PixelType, @@ -666,26 +663,26 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Cubemap: if (format.IsCompressed) { - GL.CompressedTexSubImage2D( + _gd.Api.CompressedTexSubImage2D( TextureTarget.TextureCubeMapPositiveX + layer, level, x, y, - width, - height, - format.PixelFormat, - mipSize, + (uint)width, + (uint)height, + (InternalFormat)format.PixelFormat, + (uint)mipSize, data); } else { - GL.TexSubImage2D( + _gd.Api.TexSubImage2D( TextureTarget.TextureCubeMapPositiveX + layer, level, x, y, - width, - height, + (uint)width, + (uint)height, format.PixelFormat, format.PixelType, data); @@ -697,13 +694,13 @@ namespace Ryujinx.Graphics.OpenGL.Image private void ReadFrom(IntPtr data, int size) { TextureTarget target = Target.Convert(); - int baseLevel = 0; + uint baseLevel = 0; // glTexSubImage on cubemap views is broken on Intel, we have to use the storage instead. if (Target == Target.Cubemap && HwCapabilities.Vendor == HwCapabilities.GpuVendor.IntelWindows) { - GL.ActiveTexture(TextureUnit.Texture0); - GL.BindTexture(target, Storage.Handle); + _gd.Api.ActiveTexture(TextureUnit.Texture0); + _gd.Api.BindTexture(target, Storage.Handle); baseLevel = FirstLevel; } else @@ -736,7 +733,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture1D: if (format.IsCompressed) { - GL.CompressedTexSubImage1D( + _gd.Api.CompressedTexSubImage1D( target, level, 0, @@ -747,7 +744,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } else { - GL.TexSubImage1D( + _gd.Api.TexSubImage1D( target, level, 0, @@ -762,7 +759,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.Texture2D: if (format.IsCompressed) { - GL.CompressedTexSubImage2D( + _gd.Api.CompressedTexSubImage2D( target, level, 0, @@ -775,7 +772,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } else { - GL.TexSubImage2D( + _gd.Api.TexSubImage2D( target, level, 0, @@ -793,7 +790,7 @@ namespace Ryujinx.Graphics.OpenGL.Image case Target.CubemapArray: if (format.IsCompressed) { - GL.CompressedTexSubImage3D( + _gd.Api.CompressedTexSubImage3D( target, level, 0, @@ -808,7 +805,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } else { - GL.TexSubImage3D( + _gd.Api.TexSubImage3D( target, level, 0, @@ -830,7 +827,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { if (format.IsCompressed) { - GL.CompressedTexSubImage2D( + _gd.Api.CompressedTexSubImage2D( TextureTarget.TextureCubeMapPositiveX + face, baseLevel + level, 0, @@ -843,7 +840,7 @@ namespace Ryujinx.Graphics.OpenGL.Image } else { - GL.TexSubImage2D( + _gd.Api.TexSubImage2D( TextureTarget.TextureCubeMapPositiveX + face, baseLevel + level, 0, @@ -880,7 +877,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { if (Handle != 0) { - GL.DeleteTexture(Handle); + _gd.Api.DeleteTexture(Handle); Handle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index c30aebf6eb..22abbf9b96 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -6,12 +6,13 @@ using Ryujinx.Graphics.OpenGL.Image; using Ryujinx.Graphics.OpenGL.Queries; using Ryujinx.Graphics.Shader.Translation; using System; +using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; namespace Ryujinx.Graphics.OpenGL { public sealed class OpenGLRenderer : IRenderer { - private GL _api; + public readonly GL Api; private readonly Pipeline _pipeline; public IPipeline Pipeline => _pipeline; @@ -44,10 +45,11 @@ namespace Ryujinx.Graphics.OpenGL public bool PreferThreading => true; - public OpenGLRenderer() + public OpenGLRenderer(GL api) { + Api = api; _pipeline = new Pipeline(); - _counters = new Counters(); + _counters = new Counters(Api); _window = new Window(this); _textureCopy = new TextureCopy(this); _backgroundTextureCopy = new TextureCopy(this); @@ -64,7 +66,7 @@ namespace Ryujinx.Graphics.OpenGL if (access.HasFlag(BufferAccess.FlushPersistent)) { - BufferHandle handle = Buffer.CreatePersistent(_api, size); + BufferHandle handle = Buffer.CreatePersistent(Api, size); PersistentBuffers.Map(handle, size); @@ -72,7 +74,7 @@ namespace Ryujinx.Graphics.OpenGL } else { - return Buffer.Create(_api, size); + return Buffer.Create(Api, size); } } @@ -93,7 +95,7 @@ namespace Ryujinx.Graphics.OpenGL public IImageArray CreateImageArray(int size, bool isBuffer) { - return new ImageArray(size); + return new ImageArray(Api, size); } public IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info) @@ -103,7 +105,7 @@ namespace Ryujinx.Graphics.OpenGL public ISampler CreateSampler(SamplerCreateInfo info) { - return new Sampler(info); + return new Sampler(Api, info); } public ITexture CreateTexture(TextureCreateInfo info) @@ -120,14 +122,14 @@ namespace Ryujinx.Graphics.OpenGL public ITextureArray CreateTextureArray(int size, bool isBuffer) { - return new TextureArray(size); + return new TextureArray(Api, size); } public void DeleteBuffer(BufferHandle buffer) { PersistentBuffers.Unmap(buffer); - Buffer.Delete(buffer); + Buffer.Delete(Api, buffer); } public HardwareInfo GetHardwareInfo() @@ -203,7 +205,7 @@ namespace Ryujinx.Graphics.OpenGL public void SetBufferData(BufferHandle buffer, int offset, ReadOnlySpan data) { - Buffer.SetData(buffer, offset, data); + Buffer.SetData(Api, buffer, offset, data); } public void UpdateCounters() @@ -224,7 +226,7 @@ namespace Ryujinx.Graphics.OpenGL public void Initialize(GraphicsDebugLevel glLogLevel) { - Debugger.Initialize(glLogLevel); + Debugger.Initialize(Api, glLogLevel); PrintGpuInformation(); @@ -239,14 +241,14 @@ namespace Ryujinx.Graphics.OpenGL // This call is expected to fail if we're running with a core profile, // as this clamp target was deprecated, but that's fine as a core profile // should already have the desired behaviour were outputs are not clamped. - GL.ClampColor(ClampColorTargetARB.FragmentColorArb, ClampColorModeARB.False); + Api.ClampColor(ClampColorTargetARB.FragmentColorArb, ClampColorModeARB.False); } private void PrintGpuInformation() { - GpuVendor = GL.GetString(StringName.Vendor); - GpuRenderer = GL.GetString(StringName.Renderer); - GpuVersion = GL.GetString(StringName.Version); + GpuVendor = Api.GetString(StringName.Vendor); + GpuRenderer = Api.GetString(StringName.Renderer); + GpuVersion = Api.GetString(StringName.Version); Logger.Notice.Print(LogClass.Gpu, $"{GpuVendor} {GpuRenderer} ({GpuVersion})"); } diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index e809e966fd..e3fe9c1a9a 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -52,7 +52,7 @@ namespace Ryujinx.Graphics.OpenGL class PersistentBuffer : IDisposable { private IntPtr _bufferMap; - private int _copyBufferHandle; + private uint _copyBufferHandle; private int _copyBufferSize; private byte[] _data; @@ -140,7 +140,7 @@ namespace Ryujinx.Graphics.OpenGL { EnsureBuffer(size); - GL.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToInt32()); + GL.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToUInt32()); GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); GL.CopyBufferSubData(BufferTargetARB.CopyReadBuffer, BufferTargetARB.CopyWriteBuffer, (IntPtr)offset, IntPtr.Zero, size); diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index b547fadd2f..a7da63a876 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -5,6 +5,7 @@ using Ryujinx.Graphics.OpenGL.Image; using Ryujinx.Graphics.OpenGL.Queries; using Ryujinx.Graphics.Shader; using System; +using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; namespace Ryujinx.Graphics.OpenGL { @@ -50,8 +51,8 @@ namespace Ryujinx.Graphics.OpenGL private Sampler _unit0Sampler; private FrontFaceDirection _frontFace; - private ClipOrigin _clipOrigin; - private ClipDepthMode _clipDepthMode; + private ClipControlOrigin _clipOrigin; + private ClipControlDepth _clipDepthMode; private uint _fragmentOutputMap; private uint _componentMasks; @@ -61,19 +62,22 @@ namespace Ryujinx.Graphics.OpenGL private uint _scissorEnables; private bool _tfEnabled; - private TransformFeedbackPrimitiveType _tfTopology; + private PrimitiveType _tfTopology; private readonly BufferHandle[] _tfbs; private readonly BufferRange[] _tfbTargets; private ColorF _blendConstant; - internal Pipeline() + private readonly GL _api; + + internal Pipeline(GL api) { + _api = api; _drawTexture = new DrawTextureEmulation(); _rasterizerDiscard = false; - _clipOrigin = ClipOrigin.LowerLeft; - _clipDepthMode = ClipDepthMode.NegativeOneToOne; + _clipOrigin = ClipControlOrigin.LowerLeft; + _clipDepthMode = ClipControlDepth.NegativeOneToOne; _fragmentOutputMap = uint.MaxValue; _componentMasks = uint.MaxValue; @@ -86,32 +90,32 @@ namespace Ryujinx.Graphics.OpenGL public void Barrier() { - GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits); + _api.MemoryBarrier(MemoryBarrierMask.AllBarrierBits); } public void BeginTransformFeedback(PrimitiveTopology topology) { - GL.BeginTransformFeedback(_tfTopology = topology.ConvertToTfType()); + _api.BeginTransformFeedback(_tfTopology = topology.ConvertToTfType()); _tfEnabled = true; } public void ClearBuffer(BufferHandle destination, int offset, int size, uint value) { - Buffer.Clear(destination, offset, size, value); + Buffer.Clear(_api, destination, offset, size, value); } public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color) { EnsureFramebuffer(); - GL.ColorMask( + _api.ColorMask( index, (componentMask & 1) != 0, (componentMask & 2) != 0, (componentMask & 4) != 0, (componentMask & 8) != 0); - float[] colors = new float[] { color.Red, color.Green, color.Blue, color.Alpha }; + float[] colors = [color.Red, color.Green, color.Blue, color.Alpha]; if (layer != 0 || layerCount != _framebuffer.GetColorLayerCount(index)) { @@ -119,14 +123,14 @@ namespace Ryujinx.Graphics.OpenGL { _framebuffer.AttachColorLayerForClear(index, l); - GL.ClearBuffer(BufferKind.Color, index, colors); + _api.ClearBuffer(BufferKind.Color, index, colors); } _framebuffer.DetachColorLayerForClear(index); } else { - GL.ClearBuffer(BufferKind.Color, index, colors); + _api.ClearBuffer(BufferKind.Color, index, colors); } RestoreComponentMask(index); @@ -144,12 +148,12 @@ namespace Ryujinx.Graphics.OpenGL if (stencilMaskChanged) { - GL.StencilMaskSeparate(StencilFace.Front, stencilMask); + _api.StencilMaskSeparate(TriangleFace.Front, stencilMask); } if (depthMaskChanged) { - GL.DepthMask(depthMask); + _api.DepthMask(depthMask); } if (layer != 0 || layerCount != _framebuffer.GetDepthStencilLayerCount()) @@ -170,39 +174,39 @@ namespace Ryujinx.Graphics.OpenGL if (stencilMaskChanged) { - GL.StencilMaskSeparate(StencilFace.Front, _stencilFrontMask); + _api.StencilMaskSeparate(TriangleFace.Front, _stencilFrontMask); } if (depthMaskChanged) { - GL.DepthMask(_depthMask); + _api.DepthMask(_depthMask); } } - private static void ClearDepthStencil(float depthValue, bool depthMask, int stencilValue, int stencilMask) + private static void ClearDepthStencil(GL api, float depthValue, bool depthMask, int stencilValue, int stencilMask) { if (depthMask && stencilMask != 0) { - GL.ClearBuffer(ClearBufferCombined.DepthStencil, 0, depthValue, stencilValue); + api.ClearBuffer(GLEnum.DepthStencil, 0, depthValue, stencilValue); } else if (depthMask) { - GL.ClearBuffer(BufferKind.Depth, 0, ref depthValue); + api.ClearBuffer(BufferKind.Depth, 0, ref depthValue); } else if (stencilMask != 0) { - GL.ClearBuffer(BufferKind.Stencil, 0, ref stencilValue); + api.ClearBuffer(BufferKind.Stencil, 0, ref stencilValue); } } public void CommandBufferBarrier() { - GL.MemoryBarrier(MemoryBarrierFlags.CommandBarrierBit); + _api.MemoryBarrier(MemoryBarrierMask.CommandBarrierBit); } public void CopyBuffer(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size) { - Buffer.Copy(source, destination, srcOffset, dstOffset, size); + Buffer.Copy(_api, source, destination, srcOffset, dstOffset, size); } public void DispatchCompute(int groupsX, int groupsY, int groupsZ) @@ -215,7 +219,7 @@ namespace Ryujinx.Graphics.OpenGL PrepareForDispatch(); - GL.DispatchCompute(groupsX, groupsY, groupsZ); + _api.DispatchCompute(groupsX, groupsY, groupsZ); } public void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance) @@ -244,7 +248,7 @@ namespace Ryujinx.Graphics.OpenGL PostDraw(); } - private static void DrawQuadsImpl( + private void DrawQuadsImpl( int vertexCount, int instanceCount, int firstVertex, @@ -262,14 +266,14 @@ namespace Ryujinx.Graphics.OpenGL counts[quadIndex] = 4; } - GL.MultiDrawArrays( + _api.MultiDrawArrays( PrimitiveType.TriangleFan, firsts, counts, quadsCount); } - private static void DrawQuadStripImpl( + private void DrawQuadStripImpl( int vertexCount, int instanceCount, int firstVertex, @@ -281,7 +285,7 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - GL.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, instanceCount, firstInstance); + _api.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, instanceCount, firstInstance); } } else @@ -298,7 +302,7 @@ namespace Ryujinx.Graphics.OpenGL counts[quadIndex] = 4; } - GL.MultiDrawArrays( + _api.MultiDrawArrays( PrimitiveType.TriangleFan, firsts, counts, @@ -314,15 +318,15 @@ namespace Ryujinx.Graphics.OpenGL { if (firstInstance == 0 && instanceCount == 1) { - GL.DrawArrays(_primitiveType, firstVertex, vertexCount); + _api.DrawArrays(_primitiveType, firstVertex, vertexCount); } else if (firstInstance == 0) { - GL.DrawArraysInstanced(_primitiveType, firstVertex, vertexCount, instanceCount); + _api.DrawArraysInstanced(_primitiveType, firstVertex, vertexCount, instanceCount); } else { - GL.DrawArraysInstancedBaseInstance( + _api.DrawArraysInstancedBaseInstance( _primitiveType, firstVertex, vertexCount, @@ -409,7 +413,7 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - GL.DrawElementsInstancedBaseVertexBaseInstance( + _api.DrawElementsInstancedBaseVertexBaseInstance( PrimitiveType.TriangleFan, 4, _elementsType, @@ -423,7 +427,7 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - GL.DrawElementsInstancedBaseInstance( + _api.DrawElementsInstancedBaseInstance( PrimitiveType.TriangleFan, 4, _elementsType, @@ -436,7 +440,7 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - GL.DrawElementsInstanced( + _api.DrawElementsInstanced( PrimitiveType.TriangleFan, 4, _elementsType, @@ -462,7 +466,7 @@ namespace Ryujinx.Graphics.OpenGL baseVertices[quadIndex] = firstVertex; } - GL.MultiDrawElementsBaseVertex( + _api.MultiDrawElementsBaseVertex( PrimitiveType.TriangleFan, counts, _elementsType, @@ -504,7 +508,7 @@ namespace Ryujinx.Graphics.OpenGL baseVertices[quadIndex] = firstVertex; } - GL.MultiDrawElementsBaseVertex( + _api.MultiDrawElementsBaseVertex( PrimitiveType.TriangleFan, counts, _elementsType, @@ -522,11 +526,11 @@ namespace Ryujinx.Graphics.OpenGL { if (firstInstance == 0 && firstVertex == 0 && instanceCount == 1) { - GL.DrawElements(_primitiveType, indexCount, _elementsType, indexBaseOffset); + _api.DrawElements(_primitiveType, indexCount, _elementsType, indexBaseOffset); } else if (firstInstance == 0 && instanceCount == 1) { - GL.DrawElementsBaseVertex( + _api.DrawElementsBaseVertex( _primitiveType, indexCount, _elementsType, @@ -535,7 +539,7 @@ namespace Ryujinx.Graphics.OpenGL } else if (firstInstance == 0 && firstVertex == 0) { - GL.DrawElementsInstanced( + _api.DrawElementsInstanced( _primitiveType, indexCount, _elementsType, @@ -544,7 +548,7 @@ namespace Ryujinx.Graphics.OpenGL } else if (firstInstance == 0) { - GL.DrawElementsInstancedBaseVertex( + _api.DrawElementsInstancedBaseVertex( _primitiveType, indexCount, _elementsType, @@ -554,7 +558,7 @@ namespace Ryujinx.Graphics.OpenGL } else if (firstVertex == 0) { - GL.DrawElementsInstancedBaseInstance( + _api.DrawElementsInstancedBaseInstance( _primitiveType, indexCount, _elementsType, @@ -564,7 +568,7 @@ namespace Ryujinx.Graphics.OpenGL } else { - GL.DrawElementsInstancedBaseVertexBaseInstance( + _api.DrawElementsInstancedBaseVertexBaseInstance( _primitiveType, indexCount, _elementsType, @@ -587,9 +591,9 @@ namespace Ryujinx.Graphics.OpenGL _vertexArray.SetRangeOfIndexBuffer(); - GL.BindBuffer((BufferTarget)All.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); + _api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - GL.DrawElementsIndirect(_primitiveType, _elementsType, (IntPtr)indirectBuffer.Offset); + _api.DrawElementsIndirect(_primitiveType, _elementsType, (IntPtr)indirectBuffer.Offset); _vertexArray.RestoreIndexBuffer(); @@ -608,12 +612,12 @@ namespace Ryujinx.Graphics.OpenGL _vertexArray.SetRangeOfIndexBuffer(); - GL.BindBuffer((BufferTarget)All.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); - GL.BindBuffer((BufferTarget)All.ParameterBuffer, parameterBuffer.Handle.ToInt32()); + _api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); + _api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); - GL.MultiDrawElementsIndirectCount( + _api.MultiDrawElementsIndirectCount( _primitiveType, - (All)_elementsType, + _elementsType, (IntPtr)indirectBuffer.Offset, (IntPtr)parameterBuffer.Offset, maxDrawCount, @@ -634,9 +638,9 @@ namespace Ryujinx.Graphics.OpenGL PreDrawVbUnbounded(); - GL.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); + _api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - GL.DrawArraysIndirect(_primitiveType, (IntPtr)indirectBuffer.Offset); + _api.DrawArraysIndirect(_primitiveType, (IntPtr)indirectBuffer.Offset); PostDraw(); } @@ -651,10 +655,10 @@ namespace Ryujinx.Graphics.OpenGL PreDrawVbUnbounded(); - GL.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToInt32()); - GL.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToInt32()); + _api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); + _api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); - GL.MultiDrawArraysIndirectCount( + _api.MultiDrawArraysIndirectCount( _primitiveType, (IntPtr)indirectBuffer.Offset, (IntPtr)parameterBuffer.Offset, @@ -689,7 +693,7 @@ namespace Ryujinx.Graphics.OpenGL { if (enabled) { - GL.Disable(cap); + _api.Disable(cap); } } @@ -697,7 +701,7 @@ namespace Ryujinx.Graphics.OpenGL { if (enabled) { - GL.Enable(cap); + _api.Enable(cap); } } @@ -707,15 +711,15 @@ namespace Ryujinx.Graphics.OpenGL if (_depthMask) { - GL.DepthMask(false); + _api.DepthMask(false); } if (_tfEnabled) { - GL.EndTransformFeedback(); + _api.EndTransformFeedback(); } - GL.ClipControl(ClipOrigin.UpperLeft, ClipDepthMode.NegativeOneToOne); + _api.ClipControl(ClipControlOrigin.UpperLeft, ClipControlDepth.NegativeOneToOne); _drawTexture.Draw( view, @@ -740,12 +744,12 @@ namespace Ryujinx.Graphics.OpenGL if (_depthMask) { - GL.DepthMask(true); + _api.DepthMask(true); } if (_tfEnabled) { - GL.BeginTransformFeedback(_tfTopology); + _api.BeginTransformFeedback(_tfTopology); } RestoreClipControl(); @@ -755,7 +759,7 @@ namespace Ryujinx.Graphics.OpenGL public void EndTransformFeedback() { - GL.EndTransformFeedback(); + _api.EndTransformFeedback(); _tfEnabled = false; } @@ -763,12 +767,12 @@ namespace Ryujinx.Graphics.OpenGL { if (!enable) { - GL.Disable(EnableCap.AlphaTest); + _api.Disable(EnableCap.AlphaTest); return; } - GL.AlphaFunc((AlphaFunction)op.Convert(), reference); - GL.Enable(EnableCap.AlphaTest); + _api.AlphaFunc((AlphaFunction)op.Convert(), reference); + _api.Enable(EnableCap.AlphaTest); } public void SetBlendState(AdvancedBlendDescriptor blend) @@ -787,27 +791,27 @@ namespace Ryujinx.Graphics.OpenGL { if (_advancedBlendEnable) { - GL.Disable(EnableCap.Blend); + _api.Disable(EnableCap.Blend); _advancedBlendEnable = false; } if (!blend.Enable) { - GL.Disable(IndexedEnableCap.Blend, index); + _api.Disable(EnableCap.Blend, index); return; } - GL.BlendEquationSeparate( + _api.BlendEquationSeparate( index, blend.ColorOp.Convert(), blend.AlphaOp.Convert()); - GL.BlendFuncSeparate( + _api.BlendFuncSeparate( index, - (BlendingFactorSrc)blend.ColorSrcFactor.Convert(), - (BlendingFactorDest)blend.ColorDstFactor.Convert(), - (BlendingFactorSrc)blend.AlphaSrcFactor.Convert(), - (BlendingFactorDest)blend.AlphaDstFactor.Convert()); + (BlendingFactor)blend.ColorSrcFactor.Convert(), + (BlendingFactor)blend.ColorDstFactor.Convert(), + (BlendingFactor)blend.AlphaSrcFactor.Convert(), + (BlendingFactor)blend.AlphaDstFactor.Convert()); EnsureFramebuffer(); @@ -821,43 +825,43 @@ namespace Ryujinx.Graphics.OpenGL { _blendConstant = blend.BlendConstant; - GL.BlendColor( + _api.BlendColor( blend.BlendConstant.Red, blend.BlendConstant.Green, blend.BlendConstant.Blue, blend.BlendConstant.Alpha); } - GL.Enable(IndexedEnableCap.Blend, index); + GL.Enable(EnableCap.Blend, index); } public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp) { if ((enables & PolygonModeMask.Point) != 0) { - GL.Enable(EnableCap.PolygonOffsetPoint); + _api.Enable(EnableCap.PolygonOffsetPoint); } else { - GL.Disable(EnableCap.PolygonOffsetPoint); + _api.Disable(EnableCap.PolygonOffsetPoint); } if ((enables & PolygonModeMask.Line) != 0) { - GL.Enable(EnableCap.PolygonOffsetLine); + _api.Enable(EnableCap.PolygonOffsetLine); } else { - GL.Disable(EnableCap.PolygonOffsetLine); + _api.Disable(EnableCap.PolygonOffsetLine); } if ((enables & PolygonModeMask.Fill) != 0) { - GL.Enable(EnableCap.PolygonOffsetFill); + _api.Enable(EnableCap.PolygonOffsetFill); } else { - GL.Disable(EnableCap.PolygonOffsetFill); + _api.Disable(EnableCap.PolygonOffsetFill); } if (enables == 0) @@ -867,11 +871,11 @@ namespace Ryujinx.Graphics.OpenGL if (HwCapabilities.SupportsPolygonOffsetClamp) { - GL.PolygonOffsetClamp(factor, units, clamp); + _api.PolygonOffsetClamp(factor, units, clamp); } else { - GL.PolygonOffset(factor, units); + _api.PolygonOffset(factor, units); } } @@ -879,22 +883,22 @@ namespace Ryujinx.Graphics.OpenGL { if (!clamp) { - GL.Disable(EnableCap.DepthClamp); + _api.Disable(EnableCap.DepthClamp); return; } - GL.Enable(EnableCap.DepthClamp); + _api.Enable(EnableCap.DepthClamp); } public void SetDepthMode(DepthMode mode) { - ClipDepthMode depthMode = mode.Convert(); + ClipControlDepth depthMode = (ClipControlDepth)mode.Convert(); if (_clipDepthMode != depthMode) { _clipDepthMode = depthMode; - GL.ClipControl(_clipOrigin, depthMode); + _api.ClipControl(_clipOrigin, depthMode); } } @@ -902,15 +906,15 @@ namespace Ryujinx.Graphics.OpenGL { if (depthTest.TestEnable) { - GL.Enable(EnableCap.DepthTest); - GL.DepthFunc((DepthFunction)depthTest.Func.Convert()); + _api.Enable(EnableCap.DepthTest); + _api.DepthFunc((DepthFunction)depthTest.Func.Convert()); } else { - GL.Disable(EnableCap.DepthTest); + _api.Disable(EnableCap.DepthTest); } - GL.DepthMask(depthTest.WriteEnable); + _api.DepthMask(depthTest.WriteEnable); _depthMask = depthTest.WriteEnable; _depthTestEnable = depthTest.TestEnable; } @@ -921,13 +925,13 @@ namespace Ryujinx.Graphics.OpenGL if (!enable) { - GL.Disable(EnableCap.CullFace); + _api.Disable(EnableCap.CullFace); return; } - GL.CullFace(face.Convert()); + _api.CullFace(face.Convert()); - GL.Enable(EnableCap.CullFace); + _api.Enable(EnableCap.CullFace); } public void SetFrontFace(FrontFace frontFace) @@ -944,7 +948,7 @@ namespace Ryujinx.Graphics.OpenGL if (texture == null) { - GL.BindImageTexture(binding, 0, 0, true, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); + _api.BindImageTexture(binding, 0, 0, true, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); return; } @@ -954,20 +958,20 @@ namespace Ryujinx.Graphics.OpenGL if (format != 0) { - GL.BindImageTexture(binding, texBase.Handle, 0, true, 0, TextureAccess.ReadWrite, format); + _api.BindImageTexture(binding, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); } } public void SetImageArray(ShaderStage stage, int binding, IImageArray array) { - (array as ImageArray).Bind(binding); + (array as ImageArray).Bind((uint)binding); } public void SetIndexBuffer(BufferRange buffer, IndexType type) { _elementsType = type.Convert(); - _indexBaseOffset = (IntPtr)buffer.Offset; + _indexBaseOffset = buffer.Offset; EnsureVertexArray(); @@ -978,13 +982,13 @@ namespace Ryujinx.Graphics.OpenGL { if (enable) { - GL.Enable(EnableCap.ColorLogicOp); + _api.Enable(EnableCap.ColorLogicOp); - GL.LogicOp((LogicOp)op.Convert()); + _api.LogicOp((LogicOp)op.Convert()); } else { - GL.Disable(EnableCap.ColorLogicOp); + _api.Disable(EnableCap.ColorLogicOp); } } @@ -992,15 +996,15 @@ namespace Ryujinx.Graphics.OpenGL { if (multisample.AlphaToCoverageEnable) { - GL.Enable(EnableCap.SampleAlphaToCoverage); + _api.Enable(EnableCap.SampleAlphaToCoverage); if (multisample.AlphaToOneEnable) { - GL.Enable(EnableCap.SampleAlphaToOne); + _api.Enable(EnableCap.SampleAlphaToOne); } else { - GL.Disable(EnableCap.SampleAlphaToOne); + _api.Disable(EnableCap.SampleAlphaToOne); } if (HwCapabilities.SupportsAlphaToCoverageDitherControl) @@ -1012,7 +1016,7 @@ namespace Ryujinx.Graphics.OpenGL } else { - GL.Disable(EnableCap.SampleAlphaToCoverage); + _api.Disable(EnableCap.SampleAlphaToCoverage); } } @@ -1020,28 +1024,28 @@ namespace Ryujinx.Graphics.OpenGL { if (smooth) { - GL.Enable(EnableCap.LineSmooth); + _api.Enable(EnableCap.LineSmooth); } else { - GL.Disable(EnableCap.LineSmooth); + _api.Disable(EnableCap.LineSmooth); } - GL.LineWidth(width); + _api.LineWidth(width); } public unsafe void SetPatchParameters(int vertices, ReadOnlySpan defaultOuterLevel, ReadOnlySpan defaultInnerLevel) { - GL.PatchParameter(PatchParameterInt.PatchVertices, vertices); + _api.PatchParameter(PatchParameterName.Vertices, vertices); fixed (float* pOuterLevel = defaultOuterLevel) { - GL.PatchParameter(PatchParameterFloat.PatchDefaultOuterLevel, pOuterLevel); + _api.PatchParameter(PatchParameterName.DefaultOuterLevel, pOuterLevel); } fixed (float* pInnerLevel = defaultInnerLevel) { - GL.PatchParameter(PatchParameterFloat.PatchDefaultInnerLevel, pInnerLevel); + _api.PatchParameter(PatchParameterName.DefaultInnerLevel, pInnerLevel); } } @@ -1051,41 +1055,41 @@ namespace Ryujinx.Graphics.OpenGL // As we don't know if the current context is core or compat, it's safer to keep this code. if (enablePointSprite) { - GL.Enable(EnableCap.PointSprite); + _api.Enable(EnableCap.PointSprite); } else { - GL.Disable(EnableCap.PointSprite); + _api.Disable(EnableCap.PointSprite); } if (isProgramPointSize) { - GL.Enable(EnableCap.ProgramPointSize); + _api.Enable(EnableCap.ProgramPointSize); } else { - GL.Disable(EnableCap.ProgramPointSize); + _api.Disable(EnableCap.ProgramPointSize); } - GL.PointParameter(origin == Origin.LowerLeft - ? PointSpriteCoordOriginParameter.LowerLeft - : PointSpriteCoordOriginParameter.UpperLeft); + _api.PointParameter(origin == Origin.LowerLeft + ? GLEnum.LowerLeft + : GLEnum.UpperLeft); // Games seem to set point size to 0 which generates a GL_INVALID_VALUE // From the spec, GL_INVALID_VALUE is generated if size is less than or equal to 0. - GL.PointSize(Math.Max(float.Epsilon, size)); + _api.PointSize(Math.Max(float.Epsilon, size)); } public void SetPolygonMode(GAL.PolygonMode frontMode, GAL.PolygonMode backMode) { if (frontMode == backMode) { - GL.PolygonMode(MaterialFace.FrontAndBack, frontMode.Convert()); + _api.PolygonMode(TriangleFace.FrontAndBack, frontMode.Convert()); } else { - GL.PolygonMode(MaterialFace.Front, frontMode.Convert()); - GL.PolygonMode(MaterialFace.Back, backMode.Convert()); + _api.PolygonMode(TriangleFace.Front, frontMode.Convert()); + _api.PolygonMode(TriangleFace.Back, backMode.Convert()); } } @@ -1093,13 +1097,13 @@ namespace Ryujinx.Graphics.OpenGL { if (!enable) { - GL.Disable(EnableCap.PrimitiveRestart); + _api.Disable(EnableCap.PrimitiveRestart); return; } - GL.PrimitiveRestartIndex(index); + _api.PrimitiveRestartIndex(index); - GL.Enable(EnableCap.PrimitiveRestart); + _api.Enable(EnableCap.PrimitiveRestart); } public void SetPrimitiveTopology(PrimitiveTopology topology) @@ -1113,9 +1117,9 @@ namespace Ryujinx.Graphics.OpenGL if (_tfEnabled) { - GL.EndTransformFeedback(); + _api.EndTransformFeedback(); prg.Bind(); - GL.BeginTransformFeedback(_tfTopology); + _api.BeginTransformFeedback(_tfTopology); } else { @@ -1139,11 +1143,11 @@ namespace Ryujinx.Graphics.OpenGL { if (discard) { - GL.Enable(EnableCap.RasterizerDiscard); + _api.Enable(EnableCap.RasterizerDiscard); } else { - GL.Disable(EnableCap.RasterizerDiscard); + _api.Disable(EnableCap.RasterizerDiscard); } _rasterizerDiscard = discard; @@ -1215,7 +1219,7 @@ namespace Ryujinx.Graphics.OpenGL if ((_scissorEnables & mask) == 0) { _scissorEnables |= mask; - GL.Enable(IndexedEnableCap.ScissorTest, index); + _api.Enable(EnableCap.ScissorTest, index); } } else @@ -1223,12 +1227,12 @@ namespace Ryujinx.Graphics.OpenGL if ((_scissorEnables & mask) != 0) { _scissorEnables &= ~mask; - GL.Disable(IndexedEnableCap.ScissorTest, index); + _api.Disable(EnableCap.ScissorTest, index); } } } - GL.ScissorArray(0, count, ref v[0]); + _api.ScissorArray(0, count, ref v[0]); } public void SetStencilTest(StencilTestDescriptor stencilTest) @@ -1237,39 +1241,39 @@ namespace Ryujinx.Graphics.OpenGL if (!stencilTest.TestEnable) { - GL.Disable(EnableCap.StencilTest); + _api.Disable(EnableCap.StencilTest); return; } - GL.StencilOpSeparate( - StencilFace.Front, + _api.StencilOpSeparate( + TriangleFace.Front, stencilTest.FrontSFail.Convert(), stencilTest.FrontDpFail.Convert(), stencilTest.FrontDpPass.Convert()); - GL.StencilFuncSeparate( - StencilFace.Front, + _api.StencilFuncSeparate( + TriangleFace.Front, (StencilFunction)stencilTest.FrontFunc.Convert(), stencilTest.FrontFuncRef, stencilTest.FrontFuncMask); - GL.StencilMaskSeparate(StencilFace.Front, stencilTest.FrontMask); + _api.StencilMaskSeparate(TriangleFace.Front, stencilTest.FrontMask); - GL.StencilOpSeparate( - StencilFace.Back, + _api.StencilOpSeparate( + TriangleFace.Back, stencilTest.BackSFail.Convert(), stencilTest.BackDpFail.Convert(), stencilTest.BackDpPass.Convert()); - GL.StencilFuncSeparate( - StencilFace.Back, + _api.StencilFuncSeparate( + TriangleFace.Back, (StencilFunction)stencilTest.BackFunc.Convert(), stencilTest.BackFuncRef, stencilTest.BackFuncMask); - GL.StencilMaskSeparate(StencilFace.Back, stencilTest.BackMask); + _api.StencilMaskSeparate(TriangleFace.Back, stencilTest.BackMask); - GL.Enable(EnableCap.StencilTest); + _api.Enable(EnableCap.StencilTest); _stencilFrontMask = stencilTest.FrontMask; } @@ -1289,17 +1293,17 @@ namespace Ryujinx.Graphics.OpenGL } else { - ((TextureBase)texture).Bind(binding); + ((TextureBase)texture).Bind((uint)binding); } } else { - TextureBase.ClearBinding(binding); + TextureBase.ClearBinding(_api, (uint)binding); } Sampler glSampler = (Sampler)sampler; - glSampler?.Bind(binding); + glSampler?.Bind((uint)binding); if (binding == 0) { @@ -1309,14 +1313,14 @@ namespace Ryujinx.Graphics.OpenGL public void SetTextureArray(ShaderStage stage, int binding, ITextureArray array) { - (array as TextureArray).Bind(binding); + (array as TextureArray).Bind((uint)binding); } public void SetTransformFeedbackBuffers(ReadOnlySpan buffers) { if (_tfEnabled) { - GL.EndTransformFeedback(); + _api.EndTransformFeedback(); } int count = Math.Min(buffers.Length, Constants.MaxTransformFeedbackBuffers); @@ -1328,7 +1332,7 @@ namespace Ryujinx.Graphics.OpenGL if (buffer.Handle == BufferHandle.Null) { - GL.BindBufferBase(BufferRangeTarget.TransformFeedbackBuffer, i, 0); + _api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, i, 0); continue; } @@ -1339,12 +1343,12 @@ namespace Ryujinx.Graphics.OpenGL Buffer.Resize(_tfbs[i], buffer.Size); Buffer.Copy(buffer.Handle, _tfbs[i], buffer.Offset, 0, buffer.Size); - GL.BindBufferBase(BufferRangeTarget.TransformFeedbackBuffer, i, _tfbs[i].ToInt32()); + _api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, i, _tfbs[i].ToUInt32()); } if (_tfEnabled) { - GL.BeginTransformFeedback(_tfTopology); + _api.BeginTransformFeedback(_tfTopology); } } @@ -1357,11 +1361,11 @@ namespace Ryujinx.Graphics.OpenGL { if (!enableClip) { - GL.Disable(EnableCap.ClipDistance0 + index); + _api.Disable(EnableCap.ClipDistance0 + index); return; } - GL.Enable(EnableCap.ClipDistance0 + index); + _api.Enable(EnableCap.ClipDistance0 + index); } public void SetVertexAttribs(ReadOnlySpan vertexAttribs) @@ -1413,25 +1417,25 @@ namespace Ryujinx.Graphics.OpenGL bool flipY = viewports.Length != 0 && viewports[0].Region.Height < 0; - SetOrigin(flipY ? ClipOrigin.UpperLeft : ClipOrigin.LowerLeft); + SetOrigin(flipY ? ClipControlOrigin.UpperLeft : ClipControlOrigin.LowerLeft); - GL.ViewportArray(0, viewports.Length, viewportArray); - GL.DepthRangeArray(0, viewports.Length, depthRangeArray); + _api.ViewportArray(0, viewports.Length, viewportArray); + _api.DepthRangeArray(0, viewports.Length, depthRangeArray); } public void TextureBarrier() { - GL.MemoryBarrier(MemoryBarrierFlags.TextureFetchBarrierBit); + _api.MemoryBarrier(MemoryBarrierMask.TextureFetchBarrierBit); } public void TextureBarrierTiled() { - GL.MemoryBarrier(MemoryBarrierFlags.TextureFetchBarrierBit); + _api.MemoryBarrier(MemoryBarrierMask.TextureFetchBarrierBit); } - private static void SetBuffers(ReadOnlySpan buffers, bool isStorage) + private void SetBuffers(ReadOnlySpan buffers, bool isStorage) { - BufferRangeTarget target = isStorage ? BufferRangeTarget.ShaderStorageBuffer : BufferRangeTarget.UniformBuffer; + BufferTargetARB target = isStorage ? BufferTargetARB.ShaderStorageBuffer : BufferTargetARB.UniformBuffer; for (int index = 0; index < buffers.Length; index++) { @@ -1440,21 +1444,21 @@ namespace Ryujinx.Graphics.OpenGL if (buffer.Handle == BufferHandle.Null) { - GL.BindBufferRange(target, assignment.Binding, 0, IntPtr.Zero, 0); + _api.BindBufferRange(target, assignment.Binding, 0, IntPtr.Zero, 0); continue; } - GL.BindBufferRange(target, assignment.Binding, buffer.Handle.ToInt32(), (IntPtr)buffer.Offset, buffer.Size); + _api.BindBufferRange(target, assignment.Binding, buffer.Handle.ToUInt32(), (IntPtr)buffer.Offset, buffer.Size); } } - private void SetOrigin(ClipOrigin origin) + private void SetOrigin(ClipControlOrigin origin) { if (_clipOrigin != origin) { _clipOrigin = origin; - GL.ClipControl(origin, _clipDepthMode); + _api.ClipControl(origin, _clipDepthMode); SetFrontFace(_frontFace); } @@ -1465,12 +1469,12 @@ namespace Ryujinx.Graphics.OpenGL // Changing clip origin will also change the front face to compensate // for the flipped viewport, we flip it again here to compensate as // this effect is undesirable for us. - if (_clipOrigin == ClipOrigin.UpperLeft) + if (_clipOrigin == ClipControlOrigin.UpperLeft) { - frontFace = frontFace == FrontFaceDirection.Ccw ? FrontFaceDirection.Cw : FrontFaceDirection.Ccw; + frontFace = frontFace == FrontFaceDirection.Ccw ? FrontFaceDirection.CW : FrontFaceDirection.Ccw; } - GL.FrontFace(frontFace); + _api.FrontFace(frontFace); } private void EnsureVertexArray() @@ -1487,12 +1491,12 @@ namespace Ryujinx.Graphics.OpenGL { if (_framebuffer == null) { - _framebuffer = new Framebuffer(); + _framebuffer = new Framebuffer(_api); - int boundHandle = _framebuffer.Bind(); + uint boundHandle = _framebuffer.Bind(); _boundDrawFramebuffer = _boundReadFramebuffer = boundHandle; - GL.Enable(EnableCap.FramebufferSrgb); + _api.Enable(EnableCap.FramebufferSrgb); } } @@ -1563,7 +1567,7 @@ namespace Ryujinx.Graphics.OpenGL componentMask >>= shift; componentMask &= 0xfu; - GL.ColorMask( + _api.ColorMask( index, (componentMask & redMask) != 0, (componentMask & 2u) != 0, @@ -1576,14 +1580,14 @@ namespace Ryujinx.Graphics.OpenGL public void RestoreClipControl() { - GL.ClipControl(_clipOrigin, _clipDepthMode); + _api.ClipControl(_clipOrigin, _clipDepthMode); } public void RestoreScissor0Enable() { if ((_scissorEnables & 1u) != 0) { - GL.Enable(IndexedEnableCap.ScissorTest, 0); + _api.Enable(EnableCap.ScissorTest, 0); } } @@ -1591,7 +1595,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_rasterizerDiscard) { - GL.Enable(EnableCap.RasterizerDiscard); + _api.Enable(EnableCap.RasterizerDiscard); } } @@ -1599,7 +1603,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_viewportArray.Length > 0) { - GL.ViewportArray(0, 1, _viewportArray); + _api.ViewportArray(0, 1, _viewportArray); } } @@ -1620,12 +1624,12 @@ namespace Ryujinx.Graphics.OpenGL if (format != 0) { - GL.BindImageTexture(i, texBase.Handle, 0, true, 0, TextureAccess.ReadWrite, format); + _api.BindImageTexture(i, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); continue; } } - GL.BindImageTexture(i, 0, 0, true, 0, TextureAccess.ReadWrite, SizedInternalFormat.Rgba8); + _api.BindImageTexture(i, 0, 0, true, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); } } @@ -1649,7 +1653,7 @@ namespace Ryujinx.Graphics.OpenGL return false; } - GL.BeginConditionalRender(evt.Query, isEqual ? ConditionalRenderType.QueryNoWaitInverted : ConditionalRenderType.QueryNoWait); + _api.BeginConditionalRender(evt.Query, isEqual ? ConditionalRenderMode.NoWaitInverted : ConditionalRenderMode.NoWait); _activeConditionalRender = evt; return true; @@ -1658,19 +1662,19 @@ namespace Ryujinx.Graphics.OpenGL // The GPU will flush the queries to CPU and evaluate the condition there instead. - GL.Flush(); // The thread will be stalled manually flushing the counter, so flush GL commands now. + _api.Flush(); // The thread will be stalled manually flushing the counter, so flush GL commands now. return false; } public bool TryHostConditionalRendering(ICounterEvent value, ICounterEvent compare, bool isEqual) { - GL.Flush(); // The GPU thread will be stalled manually flushing the counter, so flush GL commands now. + _api.Flush(); // The GPU thread will be stalled manually flushing the counter, so flush GL commands now. return false; // We don't currently have a way to compare two counters for conditional rendering. } public void EndHostConditionalRendering() { - GL.EndConditionalRender(); + _api.EndConditionalRender(); _activeConditionalRender?.ReleaseHostAccess(); _activeConditionalRender = null; @@ -1682,7 +1686,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_tfbs[i] != BufferHandle.Null) { - Buffer.Delete(_tfbs[i]); + Buffer.Delete(_api, _tfbs[i]); _tfbs[i] = BufferHandle.Null; } } @@ -1690,7 +1694,7 @@ namespace Ryujinx.Graphics.OpenGL _activeConditionalRender?.ReleaseHostAccess(); _framebuffer?.Dispose(); _vertexArray?.Dispose(); - _drawTexture.Dispose(); + _drawTexture.Dispose(_api); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index a593e79df4..20b7702036 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.OpenGL { Handle = GL.CreateProgram(); - GL.ProgramParameter(Handle, ProgramParameterName.ProgramBinaryRetrievableHint, 1); + GL.ProgramParameter(Handle, ProgramParameterPName.BinaryRetrievableHint, 1); _shaderHandles = new int[shaders.Length]; bool hasFragmentShader = false; diff --git a/src/Ryujinx.Graphics.OpenGL/Sync.cs b/src/Ryujinx.Graphics.OpenGL/Sync.cs index 4699378898..f571f6fd4e 100644 --- a/src/Ryujinx.Graphics.OpenGL/Sync.cs +++ b/src/Ryujinx.Graphics.OpenGL/Sync.cs @@ -15,23 +15,29 @@ namespace Ryujinx.Graphics.OpenGL } private ulong _firstHandle = 0; - private static ClientWaitSyncFlags SyncFlags => HwCapabilities.RequiresSyncFlush ? ClientWaitSyncFlags.None : ClientWaitSyncFlags.SyncFlushCommandsBit; + private static SyncBehaviorFlags SyncFlags => HwCapabilities.RequiresSyncFlush ? SyncBehaviorFlags.None : SyncBehaviorFlags.SyncFlushCommandsBit; private readonly List _handles = new(); + private readonly GL _api; + + public Sync(GL api) + { + _api = api; + } public void Create(ulong id) { SyncHandle handle = new() { ID = id, - Handle = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None), + Handle = _api.FenceSync(SyncCondition.SyncGpuCommandsComplete, SyncBehaviorFlags.None), }; if (HwCapabilities.RequiresSyncFlush) { // Force commands to flush up to the syncpoint. - GL.ClientWaitSync(handle.Handle, ClientWaitSyncFlags.SyncFlushCommandsBit, 0); + _api.ClientWaitSync(handle.Handle, SyncBehaviorFlags.SyncFlushCommandsBit, 0); } lock (_handles) @@ -57,9 +63,9 @@ namespace Ryujinx.Graphics.OpenGL if (handle.ID > lastHandle) { - WaitSyncStatus syncResult = GL.ClientWaitSync(handle.Handle, SyncFlags, 0); + GLEnum syncResult = _api.ClientWaitSync(handle.Handle, SyncFlags, 0); - if (syncResult == WaitSyncStatus.AlreadySignaled) + if (syncResult == GLEnum.AlreadySignaled) { lastHandle = handle.ID; } @@ -101,9 +107,9 @@ namespace Ryujinx.Graphics.OpenGL return; } - WaitSyncStatus syncResult = GL.ClientWaitSync(result.Handle, SyncFlags, 1000000000); + GLEnum syncResult = _api.ClientWaitSync(result.Handle, SyncFlags, 1000000000); - if (syncResult == WaitSyncStatus.TimeoutExpired) + if (syncResult == GLEnum.TimeoutExpired) { Logger.Error?.PrintMsg(LogClass.Gpu, $"GL Sync Object {result.ID} failed to signal within 1000ms. Continuing..."); } @@ -128,9 +134,9 @@ namespace Ryujinx.Graphics.OpenGL break; } - WaitSyncStatus syncResult = GL.ClientWaitSync(first.Handle, SyncFlags, 0); + GLEnum syncResult = _api.ClientWaitSync(first.Handle, SyncFlags, 0); - if (syncResult == WaitSyncStatus.AlreadySignaled) + if (syncResult == GLEnum.AlreadySignaled) { // Delete the sync object. lock (_handles) @@ -139,7 +145,7 @@ namespace Ryujinx.Graphics.OpenGL { _firstHandle = first.ID + 1; _handles.RemoveAt(0); - GL.DeleteSync(first.Handle); + _api.DeleteSync(first.Handle); first.Handle = IntPtr.Zero; } } @@ -160,7 +166,7 @@ namespace Ryujinx.Graphics.OpenGL { lock (handle) { - GL.DeleteSync(handle.Handle); + _api.DeleteSync(handle.Handle); handle.Handle = IntPtr.Zero; } } diff --git a/src/Ryujinx.Graphics.OpenGL/Window.cs b/src/Ryujinx.Graphics.OpenGL/Window.cs index 69bbe7034a..c82c535f6a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Window.cs +++ b/src/Ryujinx.Graphics.OpenGL/Window.cs @@ -9,14 +9,14 @@ namespace Ryujinx.Graphics.OpenGL { class Window : IWindow, IDisposable { - private readonly OpenGLRenderer _renderer; + private readonly OpenGLRenderer _gd; private bool _initialized; private int _width; private int _height; private bool _updateSize; - private int _copyFramebufferHandle; + private uint _copyFramebufferHandle; private IPostProcessingEffect _antiAliasing; private IScalingFilter _scalingFilter; private bool _isLinear; @@ -32,26 +32,26 @@ namespace Ryujinx.Graphics.OpenGL internal bool ScreenCaptureRequested { get; set; } - public Window(OpenGLRenderer renderer) + public Window(OpenGLRenderer gd) { - _renderer = renderer; + _gd = gd; } public void Present(ITexture texture, ImageCrop crop, Action swapBuffersCallback) { - GL.Disable(EnableCap.FramebufferSrgb); + _gd.Api.Disable(EnableCap.FramebufferSrgb); - (int oldDrawFramebufferHandle, int oldReadFramebufferHandle) = ((Pipeline)_renderer.Pipeline).GetBoundFramebuffers(); + (uint oldDrawFramebufferHandle, uint oldReadFramebufferHandle) = ((Pipeline)_gd.Pipeline).GetBoundFramebuffers(); CopyTextureToFrameBufferRGB(0, GetCopyFramebufferHandleLazy(), (TextureView)texture, crop, swapBuffersCallback); - GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, oldReadFramebufferHandle); - GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, oldDrawFramebufferHandle); + _gd.Api.BindFramebuffer(FramebufferTarget.ReadFramebuffer, oldReadFramebufferHandle); + _gd.Api.BindFramebuffer(FramebufferTarget.DrawFramebuffer, oldDrawFramebufferHandle); - GL.Enable(EnableCap.FramebufferSrgb); + _gd.Api.Enable(EnableCap.FramebufferSrgb); // Restore unpack alignment to 4, as performance overlays such as RTSS may change this to load their resources. - GL.PixelStore(PixelStoreParameter.UnpackAlignment, 4); + _gd.Api.PixelStore(PixelStoreParameter.UnpackAlignment, 4); } public void ChangeVSyncMode(bool vsyncEnabled) { } @@ -64,12 +64,12 @@ namespace Ryujinx.Graphics.OpenGL _updateSize = true; } - private void CopyTextureToFrameBufferRGB(int drawFramebuffer, int readFramebuffer, TextureView view, ImageCrop crop, Action swapBuffersCallback) + private void CopyTextureToFrameBufferRGB(uint drawFramebuffer, uint readFramebuffer, TextureView view, ImageCrop crop, Action swapBuffersCallback) { - GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, drawFramebuffer); - GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, readFramebuffer); + _gd.Api.BindFramebuffer(FramebufferTarget.DrawFramebuffer, drawFramebuffer); + _gd.Api.BindFramebuffer(FramebufferTarget.ReadFramebuffer, readFramebuffer); - TextureView viewConverted = view.Format.IsBgr() ? _renderer.TextureCopy.BgraSwap(view) : view; + TextureView viewConverted = view.Format.IsBgr() ? _gd.TextureCopy.BgraSwap(view) : view; UpdateEffect(); @@ -81,7 +81,7 @@ namespace Ryujinx.Graphics.OpenGL if (viewConverted.Format.IsBgr()) { - var swappedView = _renderer.TextureCopy.BgraSwap(viewConverted); + var swappedView = _gd.TextureCopy.BgraSwap(viewConverted); viewConverted?.Dispose(); @@ -94,21 +94,21 @@ namespace Ryujinx.Graphics.OpenGL } } - GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, drawFramebuffer); - GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, readFramebuffer); + _gd.Api.BindFramebuffer(FramebufferTarget.DrawFramebuffer, drawFramebuffer); + _gd.Api.BindFramebuffer(FramebufferTarget.ReadFramebuffer, readFramebuffer); - GL.FramebufferTexture( + _gd.Api.FramebufferTexture( FramebufferTarget.ReadFramebuffer, FramebufferAttachment.ColorAttachment0, viewConverted.Handle, 0); - GL.ReadBuffer(ReadBufferMode.ColorAttachment0); + _gd.Api.ReadBuffer(ReadBufferMode.ColorAttachment0); - GL.Disable(EnableCap.RasterizerDiscard); - GL.Disable(IndexedEnableCap.ScissorTest, 0); + _gd.Api.Disable(EnableCap.RasterizerDiscard); + _gd.Api.Disable(EnableCap.ScissorTest, 0); - GL.Clear(ClearBufferMask.ColorBufferBit); + _gd.Api.Clear(ClearBufferMask.ColorBufferBit); int srcX0, srcX1, srcY0, srcY1; @@ -151,7 +151,7 @@ namespace Ryujinx.Graphics.OpenGL if (ScreenCaptureRequested) { - CaptureFrame(srcX0, srcY0, srcX1, srcY1, view.Format.IsBgr(), crop.FlipX, crop.FlipY); + CaptureFrame(srcX0, srcY0, (uint)srcX1, (uint)srcY1, view.Format.IsBgr(), crop.FlipX, crop.FlipY); ScreenCaptureRequested = false; } @@ -185,14 +185,14 @@ namespace Ryujinx.Graphics.OpenGL srcX1 = dstX1; srcY1 = dstY1; - GL.FramebufferTexture( + _gd.Api.FramebufferTexture( FramebufferTarget.ReadFramebuffer, FramebufferAttachment.ColorAttachment0, _upscaledTexture.Handle, 0); } - GL.BlitFramebuffer( + _gd.Api.BlitFramebuffer( srcX0, srcY0, srcX1, @@ -205,26 +205,26 @@ namespace Ryujinx.Graphics.OpenGL _isLinear ? BlitFramebufferFilter.Linear : BlitFramebufferFilter.Nearest); // Remove Alpha channel - GL.ColorMask(false, false, false, true); - GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); - GL.Clear(ClearBufferMask.ColorBufferBit); + _gd.Api.ColorMask(false, false, false, true); + _gd.Api.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); + _gd.Api.Clear(ClearBufferMask.ColorBufferBit); for (int i = 0; i < Constants.MaxRenderTargets; i++) { - ((Pipeline)_renderer.Pipeline).RestoreComponentMask(i); + ((Pipeline)_gd.Pipeline).RestoreComponentMask(i); } // Set clip control, viewport and the framebuffer to the output to placate overlays and OBS capture. - GL.ClipControl(ClipOrigin.LowerLeft, ClipDepthMode.NegativeOneToOne); - GL.Viewport(0, 0, _width, _height); - GL.BindFramebuffer(FramebufferTarget.Framebuffer, drawFramebuffer); + _gd.Api.ClipControl(ClipControlOrigin.LowerLeft, ClipControlDepth.NegativeOneToOne); + _gd.Api.Viewport(0, 0, (uint)_width, (uint)_height); + _gd.Api.BindFramebuffer(FramebufferTarget.Framebuffer, drawFramebuffer); swapBuffersCallback(); - ((Pipeline)_renderer.Pipeline).RestoreClipControl(); - ((Pipeline)_renderer.Pipeline).RestoreScissor0Enable(); - ((Pipeline)_renderer.Pipeline).RestoreRasterizerDiscard(); - ((Pipeline)_renderer.Pipeline).RestoreViewport0(); + ((Pipeline)_gd.Pipeline).RestoreClipControl(); + ((Pipeline)_gd.Pipeline).RestoreScissor0Enable(); + ((Pipeline)_gd.Pipeline).RestoreRasterizerDiscard(); + ((Pipeline)_gd.Pipeline).RestoreViewport0(); if (viewConverted != view) { @@ -232,13 +232,13 @@ namespace Ryujinx.Graphics.OpenGL } } - private int GetCopyFramebufferHandleLazy() + private uint GetCopyFramebufferHandleLazy() { - int handle = _copyFramebufferHandle; + uint handle = _copyFramebufferHandle; if (handle == 0) { - handle = GL.GenFramebuffer(); + handle = _gd.Api.GenFramebuffer(); _copyFramebufferHandle = handle; } @@ -252,14 +252,14 @@ namespace Ryujinx.Graphics.OpenGL _initialized = true; } - public void CaptureFrame(int x, int y, int width, int height, bool isBgra, bool flipX, bool flipY) + public void CaptureFrame(int x, int y, uint width, uint height, bool isBgra, bool flipX, bool flipY) { - long size = Math.Abs(4 * width * height); + long size = 4 * width * height; byte[] bitmap = new byte[size]; - GL.ReadPixels(x, y, width, height, isBgra ? PixelFormat.Bgra : PixelFormat.Rgba, PixelType.UnsignedByte, bitmap); + _gd.Api.ReadPixels(x, y, width, height, isBgra ? PixelFormat.Bgra : PixelFormat.Rgba, PixelType.UnsignedByte, bitmap); - _renderer.OnScreenCaptured(new ScreenCaptureImageInfo(width, height, isBgra, bitmap, flipX, flipY)); + _gd.OnScreenCaptured(new ScreenCaptureImageInfo((int)width, (int)height, isBgra, bitmap, flipX, flipY)); } public void Dispose() @@ -273,7 +273,7 @@ namespace Ryujinx.Graphics.OpenGL if (_copyFramebufferHandle != 0) { - GL.DeleteFramebuffer(_copyFramebufferHandle); + _gd.Api.DeleteFramebuffer(_copyFramebufferHandle); _copyFramebufferHandle = 0; } @@ -319,7 +319,7 @@ namespace Ryujinx.Graphics.OpenGL { case AntiAliasing.Fxaa: _antiAliasing?.Dispose(); - _antiAliasing = new FxaaPostProcessingEffect(_renderer); + _antiAliasing = new FxaaPostProcessingEffect(_gd); break; case AntiAliasing.None: _antiAliasing?.Dispose(); @@ -337,7 +337,7 @@ namespace Ryujinx.Graphics.OpenGL else { _antiAliasing?.Dispose(); - _antiAliasing = new SmaaPostProcessingEffect(_renderer, quality); + _antiAliasing = new SmaaPostProcessingEffect(_gd, quality); } break; } @@ -368,7 +368,7 @@ namespace Ryujinx.Graphics.OpenGL if (_scalingFilter is not FsrScalingFilter) { _scalingFilter?.Dispose(); - _scalingFilter = new FsrScalingFilter(_renderer); + _scalingFilter = new FsrScalingFilter(_gd); } _isLinear = false; _scalingFilter.Level = _scalingFilterLevel; @@ -401,7 +401,7 @@ namespace Ryujinx.Graphics.OpenGL SwizzleComponent.Alpha); _isBgra = forceBgra; - _upscaledTexture = _renderer.CreateTexture(info) as TextureView; + _upscaledTexture = _gd.CreateTexture(info) as TextureView; } public void SetScalingFilterLevel(float level) From d8b7d87e139e82b0797edd9824f12e8b4da017fc Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 12:10:46 -0400 Subject: [PATCH 07/35] Use Legacy namespace --- Directory.Packages.props | 1 - src/Ryujinx.Graphics.OpenGL/Buffer.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Debugger.cs | 2 +- .../DrawTextureEmulation.cs | 2 +- .../Effects/FsrScalingFilter.cs | 2 +- .../Effects/FxaaPostProcessingEffect.cs | 2 +- .../Effects/ShaderHelper.cs | 2 +- .../Effects/SmaaPostProcessingEffect.cs | 2 +- src/Ryujinx.Graphics.OpenGL/EnumConversion.cs | 14 +++++++------- src/Ryujinx.Graphics.OpenGL/FormatInfo.cs | 2 +- src/Ryujinx.Graphics.OpenGL/FormatTable.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Framebuffer.cs | 2 +- src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs | 2 +- .../Image/TextureCopyIncompatible.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs | 2 +- .../Image/TextureStorage.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs | 2 +- src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 2 +- src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Program.cs | 2 +- .../Queries/BufferedQuery.cs | 2 +- .../Queries/CounterQueue.cs | 2 +- .../Queries/CounterQueueEvent.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs | 2 +- .../Ryujinx.Graphics.OpenGL.csproj | 1 - src/Ryujinx.Graphics.OpenGL/Sync.cs | 2 +- src/Ryujinx.Graphics.OpenGL/VertexArray.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Window.cs | 2 +- src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs | 2 +- src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs | 2 +- src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs | 2 +- 38 files changed, 42 insertions(+), 44 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 5e68c02442..99895efe43 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -38,7 +38,6 @@ - diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index 9aeb662004..a8b4501eaf 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using System; diff --git a/src/Ryujinx.Graphics.OpenGL/Debugger.cs b/src/Ryujinx.Graphics.OpenGL/Debugger.cs index 0969ede504..89af95aff9 100644 --- a/src/Ryujinx.Graphics.OpenGL/Debugger.cs +++ b/src/Ryujinx.Graphics.OpenGL/Debugger.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using System; diff --git a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs index 7d2f89f18b..a58d3668db 100644 --- a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs +++ b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.OpenGL.Image; using System; using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs index 6f10f290a2..4e4a1f8493 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs index d3dc44581c..24a72a23a3 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.OpenGL.Image; diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs b/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs index 30a0b364d9..dc406e84ae 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; namespace Ryujinx.Graphics.OpenGL.Effects { diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs index 173fb98755..4b9d4983d2 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; diff --git a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs index 24df59aa06..c5f367f70f 100644 --- a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; @@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.OpenGL switch (mode) { case AddressMode.Clamp: - return GLEnum.Clamp; + return TextureWrapMode.Clamp; case AddressMode.Repeat: return TextureWrapMode.Repeat; case AddressMode.MirrorClamp: @@ -411,21 +411,21 @@ namespace Ryujinx.Graphics.OpenGL return TextureMinFilter.Nearest; } - public static Silk.NET.OpenGL.PolygonMode Convert(this GAL.PolygonMode mode) + public static Silk.NET.OpenGL.Legacy.PolygonMode Convert(this GAL.PolygonMode mode) { switch (mode) { case GAL.PolygonMode.Point: - return Silk.NET.OpenGL.PolygonMode.Point; + return Silk.NET.OpenGL.Legacy.PolygonMode.Point; case GAL.PolygonMode.Line: - return Silk.NET.OpenGL.PolygonMode.Line; + return Silk.NET.OpenGL.Legacy.PolygonMode.Line; case GAL.PolygonMode.Fill: - return Silk.NET.OpenGL.PolygonMode.Fill; + return Silk.NET.OpenGL.Legacy.PolygonMode.Fill; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(GAL.PolygonMode)} enum value: {mode}."); - return Silk.NET.OpenGL.PolygonMode.Fill; + return Silk.NET.OpenGL.Legacy.PolygonMode.Fill; } public static PrimitiveType Convert(this PrimitiveTopology topology) diff --git a/src/Ryujinx.Graphics.OpenGL/FormatInfo.cs b/src/Ryujinx.Graphics.OpenGL/FormatInfo.cs index 3cded38f93..34962d1183 100644 --- a/src/Ryujinx.Graphics.OpenGL/FormatInfo.cs +++ b/src/Ryujinx.Graphics.OpenGL/FormatInfo.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; namespace Ryujinx.Graphics.OpenGL { diff --git a/src/Ryujinx.Graphics.OpenGL/FormatTable.cs b/src/Ryujinx.Graphics.OpenGL/FormatTable.cs index ce2b63e67d..e4f37b96c8 100644 --- a/src/Ryujinx.Graphics.OpenGL/FormatTable.cs +++ b/src/Ryujinx.Graphics.OpenGL/FormatTable.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using System; diff --git a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs index 378dcdfc2a..80cb4348eb 100644 --- a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; using System; diff --git a/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs b/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs index 0788a5736c..bd44379e72 100644 --- a/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs +++ b/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using System; namespace Ryujinx.Graphics.OpenGL diff --git a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs index 288613350a..527b9393df 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.OpenGL.Image diff --git a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs index 84fb553e08..47372deed7 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.OpenGL.Image diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs index 9efae111de..570fad58d8 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureArray.cs @@ -1,5 +1,5 @@ using Ryujinx.Graphics.GAL; -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; namespace Ryujinx.Graphics.OpenGL.Image { diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs index 2436d035da..53ea85eb56 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; namespace Ryujinx.Graphics.OpenGL.Image diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs index 197a1076df..074cbe4a88 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using System; using System.Buffers; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index e48ef6152b..c5beb9d790 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using System; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs index 5aaa1cebea..26d14f5fb7 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using System; using System.Collections.Generic; using System.Globalization; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs index 844e3489c9..2025d5f1fe 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using System; using System.Numerics; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs index 936e076509..09e68702d3 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index 5519c11fd4..365f44805e 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using System; diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index 22abbf9b96..5b0825520f 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index e3fe9c1a9a..978263ce7e 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index a7da63a876..cf74a4523a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index 20b7702036..a0d88ecc52 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs index 4201378d0f..f5fc24c4fe 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using System; using System.Runtime.InteropServices; diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs index 0ccd3f90ed..676723d8cc 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using System; using System.Collections.Generic; diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs index ddd1040b0d..578328665f 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using System; using System.Threading; diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs b/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs index bac6c9f55c..8c0aafddd2 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/Counters.cs @@ -1,5 +1,5 @@ using Ryujinx.Graphics.GAL; -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using System; namespace Ryujinx.Graphics.OpenGL.Queries diff --git a/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj b/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj index 0c85af38cc..ba40f10de8 100644 --- a/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj +++ b/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj @@ -6,7 +6,6 @@ - diff --git a/src/Ryujinx.Graphics.OpenGL/Sync.cs b/src/Ryujinx.Graphics.OpenGL/Sync.cs index f571f6fd4e..7b03349686 100644 --- a/src/Ryujinx.Graphics.OpenGL/Sync.cs +++ b/src/Ryujinx.Graphics.OpenGL/Sync.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using System; using System.Collections.Generic; diff --git a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs index 6cde939eb2..c3aa2184f9 100644 --- a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using System; using System.Numerics; diff --git a/src/Ryujinx.Graphics.OpenGL/Window.cs b/src/Ryujinx.Graphics.OpenGL/Window.cs index c82c535f6a..2347b89558 100644 --- a/src/Ryujinx.Graphics.OpenGL/Window.cs +++ b/src/Ryujinx.Graphics.OpenGL/Window.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Effects; using Ryujinx.Graphics.OpenGL.Effects.Smaa; diff --git a/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs b/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs index 6133c8be05..02a9e0388e 100644 --- a/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs +++ b/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Input.HLE; diff --git a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs index fde1762209..5833411d32 100644 --- a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs +++ b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs @@ -1,4 +1,4 @@ -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.OpenGL; using SPB.Graphics; using SPB.Graphics.OpenGL; diff --git a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs index 9ac0408abb..4b5e8ddeb7 100644 --- a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs +++ b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs @@ -1,5 +1,5 @@ using OpenTK; -using Silk.NET.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.OpenGL; From 5d6d8a43110956fe7870a139d2f41b64b88b7a7f Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 12:12:36 -0400 Subject: [PATCH 08/35] Stencil Ops --- src/Ryujinx.Graphics.OpenGL/EnumConversion.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs index c5f367f70f..66c0bfff0f 100644 --- a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -494,62 +494,62 @@ namespace Ryujinx.Graphics.OpenGL return TransformFeedbackPrimitiveType.Points; } - public static OpenTK.Graphics.OpenGL.StencilOp Convert(this GAL.StencilOp op) + public static Silk.NET.OpenGL.Legacy.StencilOp Convert(this GAL.StencilOp op) { switch (op) { case GAL.StencilOp.Keep: case GAL.StencilOp.KeepGl: - return OpenTK.Graphics.OpenGL.StencilOp.Keep; + return Silk.NET.OpenGL.Legacy.StencilOp.Keep; case GAL.StencilOp.Zero: case GAL.StencilOp.ZeroGl: - return OpenTK.Graphics.OpenGL.StencilOp.Zero; + return Silk.NET.OpenGL.Legacy.StencilOp.Zero; case GAL.StencilOp.Replace: case GAL.StencilOp.ReplaceGl: - return OpenTK.Graphics.OpenGL.StencilOp.Replace; + return Silk.NET.OpenGL.Legacy.StencilOp.Replace; case GAL.StencilOp.IncrementAndClamp: case GAL.StencilOp.IncrementAndClampGl: - return OpenTK.Graphics.OpenGL.StencilOp.Incr; + return Silk.NET.OpenGL.Legacy.StencilOp.Incr; case GAL.StencilOp.DecrementAndClamp: case GAL.StencilOp.DecrementAndClampGl: - return OpenTK.Graphics.OpenGL.StencilOp.Decr; + return Silk.NET.OpenGL.Legacy.StencilOp.Decr; case GAL.StencilOp.Invert: case GAL.StencilOp.InvertGl: - return OpenTK.Graphics.OpenGL.StencilOp.Invert; + return Silk.NET.OpenGL.Legacy.StencilOp.Invert; case GAL.StencilOp.IncrementAndWrap: case GAL.StencilOp.IncrementAndWrapGl: - return OpenTK.Graphics.OpenGL.StencilOp.IncrWrap; + return Silk.NET.OpenGL.Legacy.StencilOp.IncrWrap; case GAL.StencilOp.DecrementAndWrap: case GAL.StencilOp.DecrementAndWrapGl: - return OpenTK.Graphics.OpenGL.StencilOp.DecrWrap; + return Silk.NET.OpenGL.Legacy.StencilOp.DecrWrap; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(GAL.StencilOp)} enum value: {op}."); - return OpenTK.Graphics.OpenGL.StencilOp.Keep; + return Silk.NET.OpenGL.Legacy.StencilOp.Keep; } - public static All Convert(this SwizzleComponent swizzleComponent) + public static GLEnum Convert(this SwizzleComponent swizzleComponent) { switch (swizzleComponent) { case SwizzleComponent.Zero: - return All.Zero; + return GLEnum.Zero; case SwizzleComponent.One: - return All.One; + return GLEnum.One; case SwizzleComponent.Red: - return All.Red; + return GLEnum.Red; case SwizzleComponent.Green: - return All.Green; + return GLEnum.Green; case SwizzleComponent.Blue: - return All.Blue; + return GLEnum.Blue; case SwizzleComponent.Alpha: - return All.Alpha; + return GLEnum.Alpha; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(SwizzleComponent)} enum value: {swizzleComponent}."); - return All.Zero; + return GLEnum.Zero; } public static CopyImageSubDataTarget ConvertToImageTarget(this Target target) From 21c3dd3bcb6348b9787fbc8d8068b1af197f65c8 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 12:19:24 -0400 Subject: [PATCH 09/35] Extensions --- Directory.Packages.props | 2 + src/Ryujinx.Graphics.OpenGL/EnumConversion.cs | 144 +++++++++--------- .../Ryujinx.Graphics.OpenGL.csproj | 2 + 3 files changed, 77 insertions(+), 71 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 99895efe43..69b3ccdac1 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -39,6 +39,8 @@ + + diff --git a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs index 66c0bfff0f..9a5015544d 100644 --- a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -1,4 +1,6 @@ using Silk.NET.OpenGL.Legacy; +using Silk.NET.OpenGL.Legacy.Extensions.NV; +using Silk.NET.OpenGL.Legacy.Extensions.EXT; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; @@ -16,11 +18,11 @@ namespace Ryujinx.Graphics.OpenGL case AddressMode.Repeat: return TextureWrapMode.Repeat; case AddressMode.MirrorClamp: - return (TextureWrapMode)ExtTextureMirrorClamp.MirrorClampExt; + return (TextureWrapMode)EXT.MirrorClampExt; case AddressMode.MirrorClampToEdge: - return (TextureWrapMode)ExtTextureMirrorClamp.MirrorClampToEdgeExt; + return (TextureWrapMode)EXT.MirrorClampToEdgeExt; case AddressMode.MirrorClampToBorder: - return (TextureWrapMode)ExtTextureMirrorClamp.MirrorClampToBorderExt; + return (TextureWrapMode)EXT.MirrorClampToBorderExt; case AddressMode.ClampToBorder: return TextureWrapMode.ClampToBorder; case AddressMode.MirroredRepeat: @@ -34,124 +36,124 @@ namespace Ryujinx.Graphics.OpenGL return TextureWrapMode.Clamp; } - public static NvBlendEquationAdvanced Convert(this AdvancedBlendOp op) + public static NV Convert(this AdvancedBlendOp op) { switch (op) { case AdvancedBlendOp.Zero: - return NvBlendEquationAdvanced.Zero; + return NV.Zero; case AdvancedBlendOp.Src: - return NvBlendEquationAdvanced.SrcNv; + return NV.SrcNV; case AdvancedBlendOp.Dst: - return NvBlendEquationAdvanced.DstNv; + return NV.DstNV; case AdvancedBlendOp.SrcOver: - return NvBlendEquationAdvanced.SrcOverNv; + return NV.SrcOverNV; case AdvancedBlendOp.DstOver: - return NvBlendEquationAdvanced.DstOverNv; + return NV.DstOverNV; case AdvancedBlendOp.SrcIn: - return NvBlendEquationAdvanced.SrcInNv; + return NV.SrcInNV; case AdvancedBlendOp.DstIn: - return NvBlendEquationAdvanced.DstInNv; + return NV.DstInNV; case AdvancedBlendOp.SrcOut: - return NvBlendEquationAdvanced.SrcOutNv; + return NV.SrcOutNV; case AdvancedBlendOp.DstOut: - return NvBlendEquationAdvanced.DstOutNv; + return NV.DstOutNV; case AdvancedBlendOp.SrcAtop: - return NvBlendEquationAdvanced.SrcAtopNv; + return NV.SrcAtopNV; case AdvancedBlendOp.DstAtop: - return NvBlendEquationAdvanced.DstAtopNv; + return NV.DstAtopNV; case AdvancedBlendOp.Xor: - return NvBlendEquationAdvanced.XorNv; + return NV.XorNV; case AdvancedBlendOp.Plus: - return NvBlendEquationAdvanced.PlusNv; + return NV.PlusNV; case AdvancedBlendOp.PlusClamped: - return NvBlendEquationAdvanced.PlusClampedNv; + return NV.PlusClampedNV; case AdvancedBlendOp.PlusClampedAlpha: - return NvBlendEquationAdvanced.PlusClampedAlphaNv; + return NV.PlusClampedAlphaNV; case AdvancedBlendOp.PlusDarker: - return NvBlendEquationAdvanced.PlusDarkerNv; + return NV.PlusDarkerNV; case AdvancedBlendOp.Multiply: - return NvBlendEquationAdvanced.MultiplyNv; + return NV.MultiplyNV; case AdvancedBlendOp.Screen: - return NvBlendEquationAdvanced.ScreenNv; + return NV.ScreenNV; case AdvancedBlendOp.Overlay: - return NvBlendEquationAdvanced.OverlayNv; + return NV.OverlayNV; case AdvancedBlendOp.Darken: - return NvBlendEquationAdvanced.DarkenNv; + return NV.DarkenNV; case AdvancedBlendOp.Lighten: - return NvBlendEquationAdvanced.LightenNv; + return NV.LightenNV; case AdvancedBlendOp.ColorDodge: - return NvBlendEquationAdvanced.ColordodgeNv; + return NV.ColordodgeNV; case AdvancedBlendOp.ColorBurn: - return NvBlendEquationAdvanced.ColorburnNv; + return NV.ColorburnNV; case AdvancedBlendOp.HardLight: - return NvBlendEquationAdvanced.HardlightNv; + return NV.HardlightNV; case AdvancedBlendOp.SoftLight: - return NvBlendEquationAdvanced.SoftlightNv; + return NV.SoftlightNV; case AdvancedBlendOp.Difference: - return NvBlendEquationAdvanced.DifferenceNv; + return NV.DifferenceNV; case AdvancedBlendOp.Minus: - return NvBlendEquationAdvanced.MinusNv; + return NV.MinusNV; case AdvancedBlendOp.MinusClamped: - return NvBlendEquationAdvanced.MinusClampedNv; + return NV.MinusClampedNV; case AdvancedBlendOp.Exclusion: - return NvBlendEquationAdvanced.ExclusionNv; + return NV.ExclusionNV; case AdvancedBlendOp.Contrast: - return NvBlendEquationAdvanced.ContrastNv; + return NV.ContrastNV; case AdvancedBlendOp.Invert: - return NvBlendEquationAdvanced.Invert; + return NV.Invert; case AdvancedBlendOp.InvertRGB: - return NvBlendEquationAdvanced.InvertRgbNv; + return NV.InvertRgbNV; case AdvancedBlendOp.InvertOvg: - return NvBlendEquationAdvanced.InvertOvgNv; + return NV.InvertOvgNV; case AdvancedBlendOp.LinearDodge: - return NvBlendEquationAdvanced.LineardodgeNv; + return NV.LineardodgeNV; case AdvancedBlendOp.LinearBurn: - return NvBlendEquationAdvanced.LinearburnNv; + return NV.LinearburnNV; case AdvancedBlendOp.VividLight: - return NvBlendEquationAdvanced.VividlightNv; + return NV.VividlightNV; case AdvancedBlendOp.LinearLight: - return NvBlendEquationAdvanced.LinearlightNv; + return NV.LinearlightNV; case AdvancedBlendOp.PinLight: - return NvBlendEquationAdvanced.PinlightNv; + return NV.PinlightNV; case AdvancedBlendOp.HardMix: - return NvBlendEquationAdvanced.HardmixNv; + return NV.HardmixNV; case AdvancedBlendOp.Red: - return NvBlendEquationAdvanced.RedNv; + return NV.RedNV; case AdvancedBlendOp.Green: - return NvBlendEquationAdvanced.GreenNv; + return NV.GreenNV; case AdvancedBlendOp.Blue: - return NvBlendEquationAdvanced.BlueNv; + return NV.BlueNV; case AdvancedBlendOp.HslHue: - return NvBlendEquationAdvanced.HslHueNv; + return NV.HslHueNV; case AdvancedBlendOp.HslSaturation: - return NvBlendEquationAdvanced.HslSaturationNv; + return NV.HslSaturationNV; case AdvancedBlendOp.HslColor: - return NvBlendEquationAdvanced.HslColorNv; + return NV.HslColorNV; case AdvancedBlendOp.HslLuminosity: - return NvBlendEquationAdvanced.HslLuminosityNv; + return NV.HslLuminosityNV; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(AdvancedBlendOp)} enum value: {op}."); - return NvBlendEquationAdvanced.Zero; + return NV.Zero; } - public static All Convert(this AdvancedBlendOverlap overlap) + public static NV Convert(this AdvancedBlendOverlap overlap) { switch (overlap) { case AdvancedBlendOverlap.Uncorrelated: - return All.UncorrelatedNv; + return NV.UncorrelatedNV; case AdvancedBlendOverlap.Disjoint: - return All.DisjointNv; + return NV.DisjointNV; case AdvancedBlendOverlap.Conjoint: - return All.ConjointNv; + return NV.ConjointNV; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(AdvancedBlendOverlap)} enum value: {overlap}."); - return All.UncorrelatedNv; + return NV.UncorrelatedNV; } public static GLEnum Convert(this BlendFactor factor) @@ -469,29 +471,29 @@ namespace Ryujinx.Graphics.OpenGL return PrimitiveType.Points; } - public static TransformFeedbackPrimitiveType ConvertToTfType(this PrimitiveTopology topology) + public static PrimitiveType ConvertToTfType(this PrimitiveTopology topology) { switch (topology) { case PrimitiveTopology.Points: - return TransformFeedbackPrimitiveType.Points; + return PrimitiveType.Points; case PrimitiveTopology.Lines: case PrimitiveTopology.LineLoop: case PrimitiveTopology.LineStrip: case PrimitiveTopology.LinesAdjacency: case PrimitiveTopology.LineStripAdjacency: - return TransformFeedbackPrimitiveType.Lines; + return PrimitiveType.Lines; case PrimitiveTopology.Triangles: case PrimitiveTopology.TriangleStrip: case PrimitiveTopology.TriangleFan: case PrimitiveTopology.TrianglesAdjacency: case PrimitiveTopology.TriangleStripAdjacency: - return TransformFeedbackPrimitiveType.Triangles; + return PrimitiveType.Triangles; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(PrimitiveTopology)} enum value: {topology}."); - return TransformFeedbackPrimitiveType.Points; + return PrimitiveType.Points; } public static Silk.NET.OpenGL.Legacy.StencilOp Convert(this GAL.StencilOp op) @@ -588,31 +590,31 @@ namespace Ryujinx.Graphics.OpenGL return TextureTarget.Texture2D; } - public static NvViewportSwizzle Convert(this ViewportSwizzle swizzle) + public static NV Convert(this ViewportSwizzle swizzle) { switch (swizzle) { case ViewportSwizzle.PositiveX: - return NvViewportSwizzle.ViewportSwizzlePositiveXNv; + return NV.ViewportSwizzlePositiveXNV; case ViewportSwizzle.PositiveY: - return NvViewportSwizzle.ViewportSwizzlePositiveYNv; + return NV.ViewportSwizzlePositiveYNV; case ViewportSwizzle.PositiveZ: - return NvViewportSwizzle.ViewportSwizzlePositiveZNv; + return NV.ViewportSwizzlePositiveZNV; case ViewportSwizzle.PositiveW: - return NvViewportSwizzle.ViewportSwizzlePositiveWNv; + return NV.ViewportSwizzlePositiveWNV; case ViewportSwizzle.NegativeX: - return NvViewportSwizzle.ViewportSwizzleNegativeXNv; + return NV.ViewportSwizzleNegativeXNV; case ViewportSwizzle.NegativeY: - return NvViewportSwizzle.ViewportSwizzleNegativeYNv; + return NV.ViewportSwizzleNegativeYNV; case ViewportSwizzle.NegativeZ: - return NvViewportSwizzle.ViewportSwizzleNegativeZNv; + return NV.ViewportSwizzleNegativeZNV; case ViewportSwizzle.NegativeW: - return NvViewportSwizzle.ViewportSwizzleNegativeWNv; + return NV.ViewportSwizzleNegativeWNV; } Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(ViewportSwizzle)} enum value: {swizzle}."); - return NvViewportSwizzle.ViewportSwizzlePositiveXNv; + return NV.ViewportSwizzlePositiveXNV; } public static GLEnum Convert(this LogicalOp op) diff --git a/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj b/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj index ba40f10de8..bcfde22369 100644 --- a/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj +++ b/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj @@ -7,6 +7,8 @@ + + From 914f6d6af33721b1e71dfdb7c3f2b0e41623818f Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 12:38:23 -0400 Subject: [PATCH 10/35] NV Usage --- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Framebuffer.cs | 1 + src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 8 +-- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 55 ++++++++++-------- src/Ryujinx.Graphics.OpenGL/Program.cs | 57 ++++++++++--------- 5 files changed, 68 insertions(+), 55 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index a8b4501eaf..722b28abcd 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -88,7 +88,7 @@ namespace Ryujinx.Graphics.OpenGL gd.Api.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToUInt32()); - gd.Api.GetBufferSubData(BufferTargetARB.CopyReadBuffer, offset, (uint)size, target); + gd.Api.GetBufferSubData(BufferTargetARB.CopyReadBuffer, offset, (uint)size, (void*)target); return new PinnedSpan(target.ToPointer(), size); } diff --git a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs index 80cb4348eb..7aa720eace 100644 --- a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -1,6 +1,7 @@ using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; +using Silk.NET.OpenGL.Legacy.Extensions.NV; using System; using System.Runtime.CompilerServices; diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index 5b0825520f..176b3527b4 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -48,14 +48,14 @@ namespace Ryujinx.Graphics.OpenGL public OpenGLRenderer(GL api) { Api = api; - _pipeline = new Pipeline(); + _pipeline = new Pipeline(Api); _counters = new Counters(Api); _window = new Window(this); _textureCopy = new TextureCopy(this); _backgroundTextureCopy = new TextureCopy(this); TextureCopyIncompatible = new TextureCopyIncompatible(this); TextureCopyMS = new TextureCopyMS(this); - _sync = new Sync(); + _sync = new Sync(Api); PersistentBuffers = new PersistentBuffers(); ResourcePool = new ResourcePool(); } @@ -100,7 +100,7 @@ namespace Ryujinx.Graphics.OpenGL public IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info) { - return new Program(shaders, info.FragmentOutputMap); + return new Program(Api, shaders, info.FragmentOutputMap); } public ISampler CreateSampler(SamplerCreateInfo info) @@ -292,7 +292,7 @@ namespace Ryujinx.Graphics.OpenGL public IProgram LoadProgramBinary(byte[] programBinary, bool hasFragmentShader, ShaderInfo info) { - return new Program(programBinary, hasFragmentShader, info.FragmentOutputMap); + return new Program(Api, programBinary, hasFragmentShader, info.FragmentOutputMap); } public void CreateSync(ulong id, bool strict) diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index cf74a4523a..a652d8c2cb 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -4,6 +4,7 @@ using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; using Ryujinx.Graphics.OpenGL.Queries; using Ryujinx.Graphics.Shader; +using Silk.NET.OpenGL.Legacy.Extensions.NV; using System; using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; @@ -674,7 +675,9 @@ namespace Ryujinx.Graphics.OpenGL { if (HwCapabilities.SupportsDrawTexture) { - GL.NV.DrawTexture( + _api.TryGetExtension(out NVDrawTexture drawTexture); + + drawTexture.DrawTexture( view.Handle, samp.Handle, dstRegion.X1, @@ -689,25 +692,25 @@ namespace Ryujinx.Graphics.OpenGL } else { - static void Disable(EnableCap cap, bool enabled) + static void Disable(GL api, EnableCap cap, bool enabled) { if (enabled) { - _api.Disable(cap); + api.Disable(cap); } } - static void Enable(EnableCap cap, bool enabled) + static void Enable(GL api, EnableCap cap, bool enabled) { if (enabled) { - _api.Enable(cap); + api.Enable(cap); } } - Disable(EnableCap.CullFace, _cullEnable); - Disable(EnableCap.StencilTest, _stencilTestEnable); - Disable(EnableCap.DepthTest, _depthTestEnable); + Disable(_api, EnableCap.CullFace, _cullEnable); + Disable(_api, EnableCap.StencilTest, _stencilTestEnable); + Disable(_api, EnableCap.DepthTest, _depthTestEnable); if (_depthMask) { @@ -779,10 +782,12 @@ namespace Ryujinx.Graphics.OpenGL { if (HwCapabilities.SupportsBlendEquationAdvanced) { - GL.BlendEquation((BlendEquationMode)blend.Op.Convert()); - GL.NV.BlendParameter(NvBlendEquationAdvanced.BlendOverlapNv, (int)blend.Overlap.Convert()); - GL.NV.BlendParameter(NvBlendEquationAdvanced.BlendPremultipliedSrcNv, blend.SrcPreMultiplied ? 1 : 0); - GL.Enable(EnableCap.Blend); + _api.BlendEquation((GLEnum)blend.Op.Convert()); + + _api.TryGetExtension(out NVBlendEquationAdvanced nvBlendEquationAdvanced); + nvBlendEquationAdvanced.BlendParameter(NV.BlendOverlapNV, (int)blend.Overlap.Convert()); + nvBlendEquationAdvanced.BlendParameter(NV.BlendPremultipliedSrcNV, blend.SrcPreMultiplied ? 1 : 0); + _api.Enable(EnableCap.Blend); _advancedBlendEnable = true; } } @@ -832,7 +837,7 @@ namespace Ryujinx.Graphics.OpenGL blend.BlendConstant.Alpha); } - GL.Enable(EnableCap.Blend, index); + _api.Enable(EnableCap.Blend, index); } public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp) @@ -1009,9 +1014,11 @@ namespace Ryujinx.Graphics.OpenGL if (HwCapabilities.SupportsAlphaToCoverageDitherControl) { - GL.NV.AlphaToCoverageDitherControl(multisample.AlphaToCoverageDitherEnable - ? NvAlphaToCoverageDitherControl.AlphaToCoverageDitherEnableNv - : NvAlphaToCoverageDitherControl.AlphaToCoverageDitherDisableNv); + _api.TryGetExtension(out NVAlphaToCoverageDitherControl nvAlphaToCoverageDitherControl); + + nvAlphaToCoverageDitherControl.AlphaToCoverageDitherControl(multisample.AlphaToCoverageDitherEnable + ? NV.AlphaToCoverageDitherEnableNV + : NV.AlphaToCoverageDitherDisableNV); } } else @@ -1055,11 +1062,11 @@ namespace Ryujinx.Graphics.OpenGL // As we don't know if the current context is core or compat, it's safer to keep this code. if (enablePointSprite) { - _api.Enable(EnableCap.PointSprite); + _api.Enable(GLEnum.PointSprite); } else { - _api.Disable(EnableCap.PointSprite); + _api.Disable(GLEnum.PointSprite); } if (isProgramPointSize) @@ -1390,11 +1397,11 @@ namespace Ryujinx.Graphics.OpenGL float[] viewportArray = _viewportArray; double[] depthRangeArray = _depthRangeArray; - for (int index = 0; index < viewports.Length; index++) + for (uint index = 0; index < viewports.Length; index++) { - int viewportElemIndex = index * 4; + uint viewportElemIndex = index * 4; - Viewport viewport = viewports[index]; + Viewport viewport = viewports[(int)index]; viewportArray[viewportElemIndex + 0] = viewport.Region.X; viewportArray[viewportElemIndex + 1] = viewport.Region.Y + (viewport.Region.Height < 0 ? viewport.Region.Height : 0); @@ -1403,7 +1410,9 @@ namespace Ryujinx.Graphics.OpenGL if (HwCapabilities.SupportsViewportSwizzle) { - GL.NV.ViewportSwizzle( + _api.TryGetExtension(out NVViewportSwizzle nvViewportSwizzle); + + nvViewportSwizzle.ViewportSwizzle( index, viewport.SwizzleX.Convert(), viewport.SwizzleY.Convert(), @@ -1568,7 +1577,7 @@ namespace Ryujinx.Graphics.OpenGL componentMask &= 0xfu; _api.ColorMask( - index, + (uint)index, (componentMask & redMask) != 0, (componentMask & 2u) != 0, (componentMask & blueMask) != 0, diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index a0d88ecc52..602032baf7 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.OpenGL { private const int MaxShaderLogLength = 2048; - public int Handle { get; private set; } + public uint Handle { get; private set; } public bool IsLinked { @@ -27,18 +27,20 @@ namespace Ryujinx.Graphics.OpenGL } } + private readonly GL _api; private ProgramLinkStatus _status = ProgramLinkStatus.Incomplete; - private int[] _shaderHandles; + private uint[] _shaderHandles; public int FragmentOutputMap { get; } - public Program(ShaderSource[] shaders, int fragmentOutputMap) + public Program(GL api, ShaderSource[] shaders, int fragmentOutputMap) { - Handle = GL.CreateProgram(); + _api = api; + Handle = _api.CreateProgram(); - GL.ProgramParameter(Handle, ProgramParameterPName.BinaryRetrievableHint, 1); + _api.ProgramParameter(Handle, ProgramParameterPName.BinaryRetrievableHint, 1); - _shaderHandles = new int[shaders.Length]; + _shaderHandles = new uint[shaders.Length]; bool hasFragmentShader = false; for (int index = 0; index < shaders.Length; index++) @@ -50,43 +52,44 @@ namespace Ryujinx.Graphics.OpenGL hasFragmentShader = true; } - int shaderHandle = GL.CreateShader(shader.Stage.Convert()); + uint shaderHandle = _api.CreateShader(shader.Stage.Convert()); switch (shader.Language) { case TargetLanguage.Glsl: - GL.ShaderSource(shaderHandle, shader.Code); - GL.CompileShader(shaderHandle); + _api.ShaderSource(shaderHandle, shader.Code); + _api.CompileShader(shaderHandle); break; case TargetLanguage.Spirv: - GL.ShaderBinary(1, ref shaderHandle, (BinaryFormat)All.ShaderBinaryFormatSpirVArb, shader.BinaryCode, shader.BinaryCode.Length); - GL.SpecializeShader(shaderHandle, "main", 0, (int[])null, (int[])null); + _api.ShaderBinary(1, ref shaderHandle, ShaderBinaryFormat.ShaderBinaryFormatSpirV, shader.BinaryCode, shader.BinaryCode.Length); + _api.SpecializeShader(shaderHandle, "main", 0, (int[])null, (int[])null); break; } - GL.AttachShader(Handle, shaderHandle); + _api.AttachShader(Handle, shaderHandle); _shaderHandles[index] = shaderHandle; } - GL.LinkProgram(Handle); + _api.LinkProgram(Handle); FragmentOutputMap = hasFragmentShader ? fragmentOutputMap : 0; } - public Program(ReadOnlySpan code, bool hasFragmentShader, int fragmentOutputMap) + public Program(GL api, ReadOnlySpan code, bool hasFragmentShader, int fragmentOutputMap) { - Handle = GL.CreateProgram(); + _api = api; + Handle = _api.CreateProgram(); if (code.Length >= 4) { - BinaryFormat binaryFormat = (BinaryFormat)BinaryPrimitives.ReadInt32LittleEndian(code.Slice(code.Length - 4, 4)); + ShaderBinaryFormat binaryFormat = (ShaderBinaryFormat)BinaryPrimitives.ReadInt32LittleEndian(code.Slice(code.Length - 4, 4)); unsafe { fixed (byte* ptr = code) { - GL.ProgramBinary(Handle, binaryFormat, (IntPtr)ptr, code.Length - 4); + _api.ProgramBinary(Handle, binaryFormat, (IntPtr)ptr, code.Length - 4); } } } @@ -96,14 +99,14 @@ namespace Ryujinx.Graphics.OpenGL public void Bind() { - GL.UseProgram(Handle); + _api.UseProgram(Handle); } public ProgramLinkStatus CheckProgramLink(bool blocking) { if (!blocking && HwCapabilities.SupportsParallelShaderCompile) { - GL.GetProgram(Handle, (GetProgramParameterName)ArbParallelShaderCompile.CompletionStatusArb, out int completed); + _api.GetProgram(Handle, (GetProgramParameterName)ArbParallelShaderCompile.CompletionStatusArb, out int completed); if (completed == 0) { @@ -111,14 +114,14 @@ namespace Ryujinx.Graphics.OpenGL } } - GL.GetProgram(Handle, GetProgramParameterName.LinkStatus, out int status); + _api.GetProgram(Handle, ProgramPropertyARB.LinkStatus, out int status); DeleteShaders(); if (status == 0) { _status = ProgramLinkStatus.Failure; - string log = GL.GetProgramInfoLog(Handle); + string log = _api.GetProgramInfoLog(Handle); if (log.Length > MaxShaderLogLength) { @@ -137,11 +140,11 @@ namespace Ryujinx.Graphics.OpenGL public byte[] GetBinary() { - GL.GetProgram(Handle, (GetProgramParameterName)All.ProgramBinaryLength, out int size); + _api.GetProgram(Handle, ProgramPropertyARB.ProgramBinaryLength, out int size); byte[] data = new byte[size + 4]; - GL.GetProgramBinary(Handle, size, out _, out BinaryFormat binFormat, data); + _api.GetProgramBinary(Handle, size, out _, out ShaderBinaryFormat binFormat, data); BinaryPrimitives.WriteInt32LittleEndian(data.AsSpan(size, 4), (int)binFormat); @@ -152,10 +155,10 @@ namespace Ryujinx.Graphics.OpenGL { if (_shaderHandles != null) { - foreach (int shaderHandle in _shaderHandles) + foreach (uint shaderHandle in _shaderHandles) { - GL.DetachShader(Handle, shaderHandle); - GL.DeleteShader(shaderHandle); + _api.DetachShader(Handle, shaderHandle); + _api.DeleteShader(shaderHandle); } _shaderHandles = null; @@ -167,7 +170,7 @@ namespace Ryujinx.Graphics.OpenGL if (Handle != 0) { DeleteShaders(); - GL.DeleteProgram(Handle); + _api.DeleteProgram(Handle); Handle = 0; } From 65abc70edc963d24809b6ec0f0406814cb042ed9 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 16:32:14 -0400 Subject: [PATCH 11/35] Almost there --- src/Ryujinx.Graphics.OpenGL/Framebuffer.cs | 2 +- .../PersistentBuffers.cs | 6 +- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 88 +++++++++---------- src/Ryujinx.Graphics.OpenGL/Program.cs | 2 +- src/Ryujinx.Graphics.OpenGL/VertexArray.cs | 56 ++++++------ src/Ryujinx.Graphics.OpenGL/Window.cs | 7 +- 6 files changed, 82 insertions(+), 79 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs index 7aa720eace..37b9a14cf6 100644 --- a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -118,7 +118,7 @@ namespace Ryujinx.Graphics.OpenGL drawBuffers[index] = DrawBufferMode.ColorAttachment0 + index; } - api.DrawBuffers(colorsCount, drawBuffers); + api.DrawBuffers((uint)colorsCount, drawBuffers); } private static FramebufferAttachment GetAttachment(Format format) diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index 978263ce7e..3ba8b1e196 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -26,7 +26,7 @@ namespace Ryujinx.Graphics.OpenGL public void Map(BufferHandle handle, int size) { - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToInt32()); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); IntPtr ptr = GL.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, size, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); _maps[handle] = ptr; @@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_maps.ContainsKey(handle)) { - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToInt32()); + GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); GL.UnmapBuffer(BufferTargetARB.CopyWriteBuffer); _maps.Remove(handle); @@ -93,7 +93,7 @@ namespace Ryujinx.Graphics.OpenGL private static void Sync() { - GL.MemoryBarrier(MemoryBarrierFlags.ClientMappedBufferBarrierBit); + GL.MemoryBarrier(MemoryBarrierMask.ClientMappedBufferBarrierBit); IntPtr sync = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None); WaitSyncStatus syncResult = GL.ClientWaitSync(sync, ClientWaitSyncFlags.SyncFlushCommandsBit, 1000000000); diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index a652d8c2cb..5af2da645c 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -37,8 +37,8 @@ namespace Ryujinx.Graphics.OpenGL private bool _stencilTestEnable; private bool _cullEnable; - private float[] _viewportArray = Array.Empty(); - private double[] _depthRangeArray = Array.Empty(); + private float[] _viewportArray = []; + private double[] _depthRangeArray = []; private uint _boundDrawFramebuffer; private uint _boundReadFramebuffer; @@ -102,7 +102,7 @@ namespace Ryujinx.Graphics.OpenGL public void ClearBuffer(BufferHandle destination, int offset, int size, uint value) { - Buffer.Clear(_api, destination, offset, size, value); + Buffer.Clear(_api, destination, offset, (uint)size, value); } public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color) @@ -110,7 +110,7 @@ namespace Ryujinx.Graphics.OpenGL EnsureFramebuffer(); _api.ColorMask( - index, + (uint)index, (componentMask & 1) != 0, (componentMask & 2) != 0, (componentMask & 4) != 0, @@ -149,7 +149,7 @@ namespace Ryujinx.Graphics.OpenGL if (stencilMaskChanged) { - _api.StencilMaskSeparate(TriangleFace.Front, stencilMask); + _api.StencilMaskSeparate(TriangleFace.Front, (uint)stencilMask); } if (depthMaskChanged) @@ -175,7 +175,7 @@ namespace Ryujinx.Graphics.OpenGL if (stencilMaskChanged) { - _api.StencilMaskSeparate(TriangleFace.Front, _stencilFrontMask); + _api.StencilMaskSeparate(TriangleFace.Front, (uint)_stencilFrontMask); } if (depthMaskChanged) @@ -184,19 +184,19 @@ namespace Ryujinx.Graphics.OpenGL } } - private static void ClearDepthStencil(GL api, float depthValue, bool depthMask, int stencilValue, int stencilMask) + private void ClearDepthStencil(float depthValue, bool depthMask, int stencilValue, int stencilMask) { if (depthMask && stencilMask != 0) { - api.ClearBuffer(GLEnum.DepthStencil, 0, depthValue, stencilValue); + _api.ClearBuffer(GLEnum.DepthStencil, 0, depthValue, stencilValue); } else if (depthMask) { - api.ClearBuffer(BufferKind.Depth, 0, ref depthValue); + _api.ClearBuffer(BufferKind.Depth, 0, ref depthValue); } else if (stencilMask != 0) { - api.ClearBuffer(BufferKind.Stencil, 0, ref stencilValue); + _api.ClearBuffer(BufferKind.Stencil, 0, ref stencilValue); } } @@ -741,9 +741,9 @@ namespace Ryujinx.Graphics.OpenGL RestoreViewport0(); - Enable(EnableCap.CullFace, _cullEnable); - Enable(EnableCap.StencilTest, _stencilTestEnable); - Enable(EnableCap.DepthTest, _depthTestEnable); + Enable(_api, EnableCap.CullFace, _cullEnable); + Enable(_api, EnableCap.StencilTest, _stencilTestEnable); + Enable(_api, EnableCap.DepthTest, _depthTestEnable); if (_depthMask) { @@ -802,17 +802,17 @@ namespace Ryujinx.Graphics.OpenGL if (!blend.Enable) { - _api.Disable(EnableCap.Blend, index); + _api.Disable(EnableCap.Blend, (uint)index); return; } _api.BlendEquationSeparate( - index, + (uint)index, blend.ColorOp.Convert(), blend.AlphaOp.Convert()); _api.BlendFuncSeparate( - index, + (uint)index, (BlendingFactor)blend.ColorSrcFactor.Convert(), (BlendingFactor)blend.ColorDstFactor.Convert(), (BlendingFactor)blend.AlphaSrcFactor.Convert(), @@ -837,7 +837,7 @@ namespace Ryujinx.Graphics.OpenGL blend.BlendConstant.Alpha); } - _api.Enable(EnableCap.Blend, index); + _api.Enable(EnableCap.Blend, (uint)index); } public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp) @@ -953,17 +953,17 @@ namespace Ryujinx.Graphics.OpenGL if (texture == null) { - _api.BindImageTexture(binding, 0, 0, true, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _api.BindImageTexture((uint)binding, 0, 0, true, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); return; } TextureBase texBase = (TextureBase)texture; - SizedInternalFormat format = FormatTable.GetImageFormat(imageFormat); + InternalFormat format = (InternalFormat)FormatTable.GetImageFormat(imageFormat); if (format != 0) { - _api.BindImageTexture(binding, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); + _api.BindImageTexture((uint)binding, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); } } @@ -1078,9 +1078,9 @@ namespace Ryujinx.Graphics.OpenGL _api.Disable(EnableCap.ProgramPointSize); } - _api.PointParameter(origin == Origin.LowerLeft + _api.PointParameter(GLEnum.PointSpriteCoordOrigin, (int)(origin == Origin.LowerLeft ? GLEnum.LowerLeft - : GLEnum.UpperLeft); + : GLEnum.UpperLeft)); // Games seem to set point size to 0 which generates a GL_INVALID_VALUE // From the spec, GL_INVALID_VALUE is generated if size is less than or equal to 0. @@ -1108,7 +1108,7 @@ namespace Ryujinx.Graphics.OpenGL return; } - _api.PrimitiveRestartIndex(index); + _api.PrimitiveRestartIndex((uint)index); _api.Enable(EnableCap.PrimitiveRestart); } @@ -1226,7 +1226,7 @@ namespace Ryujinx.Graphics.OpenGL if ((_scissorEnables & mask) == 0) { _scissorEnables |= mask; - _api.Enable(EnableCap.ScissorTest, index); + _api.Enable(EnableCap.ScissorTest, (uint)index); } } else @@ -1234,12 +1234,12 @@ namespace Ryujinx.Graphics.OpenGL if ((_scissorEnables & mask) != 0) { _scissorEnables &= ~mask; - _api.Disable(EnableCap.ScissorTest, index); + _api.Disable(EnableCap.ScissorTest, (uint)index); } } } - _api.ScissorArray(0, count, ref v[0]); + _api.ScissorArray(0, (uint)count, ref v[0]); } public void SetStencilTest(StencilTestDescriptor stencilTest) @@ -1262,9 +1262,9 @@ namespace Ryujinx.Graphics.OpenGL TriangleFace.Front, (StencilFunction)stencilTest.FrontFunc.Convert(), stencilTest.FrontFuncRef, - stencilTest.FrontFuncMask); + (uint)stencilTest.FrontFuncMask); - _api.StencilMaskSeparate(TriangleFace.Front, stencilTest.FrontMask); + _api.StencilMaskSeparate(TriangleFace.Front, (uint)stencilTest.FrontMask); _api.StencilOpSeparate( TriangleFace.Back, @@ -1276,9 +1276,9 @@ namespace Ryujinx.Graphics.OpenGL TriangleFace.Back, (StencilFunction)stencilTest.BackFunc.Convert(), stencilTest.BackFuncRef, - stencilTest.BackFuncMask); + (uint)stencilTest.BackFuncMask); - _api.StencilMaskSeparate(TriangleFace.Back, stencilTest.BackMask); + _api.StencilMaskSeparate(TriangleFace.Back, (uint)stencilTest.BackMask); _api.Enable(EnableCap.StencilTest); @@ -1339,18 +1339,18 @@ namespace Ryujinx.Graphics.OpenGL if (buffer.Handle == BufferHandle.Null) { - _api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, i, 0); + _api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, (uint)i, 0); continue; } if (_tfbs[i] == BufferHandle.Null) { - _tfbs[i] = Buffer.Create(); + _tfbs[i] = Buffer.Create(_api); } - Buffer.Resize(_tfbs[i], buffer.Size); - Buffer.Copy(buffer.Handle, _tfbs[i], buffer.Offset, 0, buffer.Size); - _api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, i, _tfbs[i].ToUInt32()); + Buffer.Resize(_api, _tfbs[i], buffer.Size); + Buffer.Copy(_api, buffer.Handle, _tfbs[i], buffer.Offset, 0, buffer.Size); + _api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, (uint)i, _tfbs[i].ToUInt32()); } if (_tfEnabled) @@ -1428,8 +1428,8 @@ namespace Ryujinx.Graphics.OpenGL SetOrigin(flipY ? ClipControlOrigin.UpperLeft : ClipControlOrigin.LowerLeft); - _api.ViewportArray(0, viewports.Length, viewportArray); - _api.DepthRangeArray(0, viewports.Length, depthRangeArray); + _api.ViewportArray(0, (uint)viewports.Length, viewportArray); + _api.DepthRangeArray(0, (uint)viewports.Length, depthRangeArray); } public void TextureBarrier() @@ -1453,11 +1453,11 @@ namespace Ryujinx.Graphics.OpenGL if (buffer.Handle == BufferHandle.Null) { - _api.BindBufferRange(target, assignment.Binding, 0, IntPtr.Zero, 0); + _api.BindBufferRange(target, (uint)assignment.Binding, 0, IntPtr.Zero, 0); continue; } - _api.BindBufferRange(target, assignment.Binding, buffer.Handle.ToUInt32(), (IntPtr)buffer.Offset, buffer.Size); + _api.BindBufferRange(target, (uint)assignment.Binding, buffer.Handle.ToUInt32(), buffer.Offset, (UIntPtr)buffer.Size); } } @@ -1490,7 +1490,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_vertexArray == null) { - _vertexArray = new VertexArray(); + _vertexArray = new VertexArray(_api); _vertexArray.Bind(); } @@ -1551,7 +1551,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_tfbTargets[i].Handle != BufferHandle.Null) { - Buffer.Copy(_tfbs[i], _tfbTargets[i].Handle, 0, _tfbTargets[i].Offset, _tfbTargets[i].Size); + Buffer.Copy(_api, _tfbs[i], _tfbTargets[i].Handle, 0, _tfbTargets[i].Offset, _tfbTargets[i].Size); } } } @@ -1629,16 +1629,16 @@ namespace Ryujinx.Graphics.OpenGL if (texBase != null) { - SizedInternalFormat format = FormatTable.GetImageFormat(imageFormat); + InternalFormat format = (InternalFormat)FormatTable.GetImageFormat(imageFormat); if (format != 0) { - _api.BindImageTexture(i, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); + _api.BindImageTexture((uint)i, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); continue; } } - _api.BindImageTexture(i, 0, 0, true, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _api.BindImageTexture((uint)i, 0, 0, true, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); } } diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index 602032baf7..7938ac9064 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -144,7 +144,7 @@ namespace Ryujinx.Graphics.OpenGL byte[] data = new byte[size + 4]; - _api.GetProgramBinary(Handle, size, out _, out ShaderBinaryFormat binFormat, data); + _api.GetProgramBinary(Handle, (uint)size, out _, out GLEnum binFormat, data); BinaryPrimitives.WriteInt32LittleEndian(data.AsSpan(size, 4), (int)binFormat); diff --git a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs index c3aa2184f9..155f69b158 100644 --- a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.OpenGL { class VertexArray : IDisposable { - public int Handle { get; private set; } + public uint Handle { get; private set; } private readonly VertexAttribDescriptor[] _vertexAttribs; private readonly VertexBufferDescriptor[] _vertexBuffers; @@ -23,20 +23,22 @@ namespace Ryujinx.Graphics.OpenGL private readonly BufferHandle _tempIndexBuffer; private BufferHandle _tempVertexBuffer; private int _tempVertexBufferSize; + private readonly GL _api; - public VertexArray() + public VertexArray(GL api) { - Handle = GL.GenVertexArray(); + _api = api; + Handle = _api.GenVertexArray(); _vertexAttribs = new VertexAttribDescriptor[Constants.MaxVertexAttribs]; _vertexBuffers = new VertexBufferDescriptor[Constants.MaxVertexBuffers]; - _tempIndexBuffer = Buffer.Create(); + _tempIndexBuffer = Buffer.Create(_api); } public void Bind() { - GL.BindVertexArray(Handle); + _api.BindVertexArray(Handle); } public void SetVertexBuffers(ReadOnlySpan vertexBuffers) @@ -56,15 +58,15 @@ namespace Ryujinx.Graphics.OpenGL minVertexCount = vertexCount; } - GL.BindVertexBuffer(bindingIndex, vb.Buffer.Handle.ToInt32(), (IntPtr)vb.Buffer.Offset, vb.Stride); - GL.VertexBindingDivisor(bindingIndex, vb.Divisor); + _api.BindVertexBuffer((uint)bindingIndex, vb.Buffer.Handle.ToUInt32(), vb.Buffer.Offset, (uint)vb.Stride); + _api.VertexBindingDivisor((uint)bindingIndex, (uint)vb.Divisor); _vertexBuffersInUse |= 1u << bindingIndex; } else { if ((_vertexBuffersInUse & (1u << bindingIndex)) != 0) { - GL.BindVertexBuffer(bindingIndex, 0, IntPtr.Zero, 0); + _api.BindVertexBuffer((uint)bindingIndex, 0, IntPtr.Zero, 0); _vertexBuffersInUse &= ~(1u << bindingIndex); } } @@ -111,16 +113,16 @@ namespace Ryujinx.Graphics.OpenGL { VertexAttribType type = (VertexAttribType)fmtInfo.PixelType; - GL.VertexAttribFormat(index, size, type, fmtInfo.Normalized, offset); + _api.VertexAttribFormat((uint)index, size, type, fmtInfo.Normalized, (uint)offset); } else { - VertexAttribIntegerType type = (VertexAttribIntegerType)fmtInfo.PixelType; + VertexAttribIType type = (VertexAttribIType)fmtInfo.PixelType; - GL.VertexAttribIFormat(index, size, type, offset); + _api.VertexAttribIFormat((uint)index, size, type, (uint)offset); } - GL.VertexAttribBinding(index, attrib.BufferIndex); + _api.VertexAttribBinding((uint)index, (uint)attrib.BufferIndex); _vertexAttribs[index] = attrib; } @@ -134,19 +136,19 @@ namespace Ryujinx.Graphics.OpenGL public void SetIndexBuffer(BufferRange range) { _indexBuffer = range; - GL.BindBuffer(BufferTargetARB.ElementArrayBuffer, range.Handle.ToInt32()); + _api.BindBuffer(BufferTargetARB.ElementArrayBuffer, range.Handle.ToUInt32()); } public void SetRangeOfIndexBuffer() { - Buffer.Resize(_tempIndexBuffer, _indexBuffer.Size); - Buffer.Copy(_indexBuffer.Handle, _tempIndexBuffer, _indexBuffer.Offset, 0, _indexBuffer.Size); - GL.BindBuffer(BufferTargetARB.ElementArrayBuffer, _tempIndexBuffer.ToInt32()); + Buffer.Resize(_api, _tempIndexBuffer, _indexBuffer.Size); + Buffer.Copy(_api, _indexBuffer.Handle, _tempIndexBuffer, _indexBuffer.Offset, 0, _indexBuffer.Size); + _api.BindBuffer(BufferTargetARB.ElementArrayBuffer, _tempIndexBuffer.ToUInt32()); } public void RestoreIndexBuffer() { - GL.BindBuffer(BufferTargetARB.ElementArrayBuffer, _indexBuffer.Handle.ToInt32()); + _api.BindBuffer(BufferTargetARB.ElementArrayBuffer, _indexBuffer.Handle.ToUInt32()); } public void PreDraw(int vertexCount) @@ -185,10 +187,10 @@ namespace Ryujinx.Graphics.OpenGL { BufferHandle tempVertexBuffer = EnsureTempVertexBufferSize(currentTempVbOffset + requiredSize); - Buffer.Copy(vb.Buffer.Handle, tempVertexBuffer, vb.Buffer.Offset, currentTempVbOffset, vb.Buffer.Size); - Buffer.Clear(tempVertexBuffer, currentTempVbOffset + vb.Buffer.Size, requiredSize - vb.Buffer.Size, 0); + Buffer.Copy(_api, vb.Buffer.Handle, tempVertexBuffer, vb.Buffer.Offset, currentTempVbOffset, vb.Buffer.Size); + Buffer.Clear(_api, tempVertexBuffer, currentTempVbOffset + vb.Buffer.Size, (uint)(requiredSize - vb.Buffer.Size), 0); - GL.BindVertexBuffer(vbIndex, tempVertexBuffer.ToInt32(), (IntPtr)currentTempVbOffset, vb.Stride); + _api.BindVertexBuffer((uint)vbIndex, tempVertexBuffer.ToUInt32(), (IntPtr)currentTempVbOffset, (uint)vb.Stride); currentTempVbOffset += requiredSize; _vertexBuffersLimited |= 1u << vbIndex; @@ -208,12 +210,12 @@ namespace Ryujinx.Graphics.OpenGL if (tempVertexBuffer == BufferHandle.Null) { - tempVertexBuffer = Buffer.Create(size); + tempVertexBuffer = Buffer.Create(_api, size); _tempVertexBuffer = tempVertexBuffer; return tempVertexBuffer; } - Buffer.Resize(_tempVertexBuffer, size); + Buffer.Resize(_api, _tempVertexBuffer, size); } return tempVertexBuffer; @@ -234,7 +236,7 @@ namespace Ryujinx.Graphics.OpenGL ref var vb = ref _vertexBuffers[vbIndex]; - GL.BindVertexBuffer(vbIndex, vb.Buffer.Handle.ToInt32(), (IntPtr)vb.Buffer.Offset, vb.Stride); + _api.BindVertexBuffer((uint)vbIndex, vb.Buffer.Handle.ToUInt32(), (IntPtr)vb.Buffer.Offset, (uint)vb.Stride); buffersLimited &= ~(1u << vbIndex); } @@ -250,7 +252,7 @@ namespace Ryujinx.Graphics.OpenGL if ((_vertexAttribsInUse & mask) == 0) { _vertexAttribsInUse |= mask; - GL.EnableVertexAttribArray(index); + _api.EnableVertexAttribArray((uint)index); } } @@ -262,8 +264,8 @@ namespace Ryujinx.Graphics.OpenGL if ((_vertexAttribsInUse & mask) != 0) { _vertexAttribsInUse &= ~mask; - GL.DisableVertexAttribArray(index); - GL.VertexAttrib4(index, 0f, 0f, 0f, 1f); + _api.DisableVertexAttribArray((uint)index); + _api.VertexAttrib4((uint)index, 0f, 0f, 0f, 1f); } } @@ -271,7 +273,7 @@ namespace Ryujinx.Graphics.OpenGL { if (Handle != 0) { - GL.DeleteVertexArray(Handle); + _api.DeleteVertexArray(Handle); Handle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Window.cs b/src/Ryujinx.Graphics.OpenGL/Window.cs index 2347b89558..3741a9a9c4 100644 --- a/src/Ryujinx.Graphics.OpenGL/Window.cs +++ b/src/Ryujinx.Graphics.OpenGL/Window.cs @@ -252,12 +252,13 @@ namespace Ryujinx.Graphics.OpenGL _initialized = true; } - public void CaptureFrame(int x, int y, uint width, uint height, bool isBgra, bool flipX, bool flipY) + public unsafe void CaptureFrame(int x, int y, uint width, uint height, bool isBgra, bool flipX, bool flipY) { long size = 4 * width * height; - byte[] bitmap = new byte[size]; - _gd.Api.ReadPixels(x, y, width, height, isBgra ? PixelFormat.Bgra : PixelFormat.Rgba, PixelType.UnsignedByte, bitmap); + _gd.Api.ReadPixels(x, y, width, height, isBgra ? PixelFormat.Bgra : PixelFormat.Rgba, PixelType.UnsignedByte, out int data); + + var bitmap = new Span((void*)data, (int)size).ToArray(); _gd.OnScreenCaptured(new ScreenCaptureImageInfo((int)width, (int)height, isBgra, bitmap, flipX, flipY)); } From 740842d6003a04f84ca77d3e1af5252fa95aaab9 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 19:00:02 -0400 Subject: [PATCH 12/35] TextureView --- .../Image/TextureView.cs | 86 ++++++++++++------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index 365f44805e..0fd3c05682 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -101,15 +101,15 @@ namespace Ryujinx.Graphics.OpenGL.Image _gd.Api.TexParameter(target, TextureParameterName.DepthStencilTextureMode, (int)Info.DepthStencilMode.Convert()); } - public ITexture CreateView(TextureCreateInfo info, uint firstLayer, uint firstLevel) + public ITexture CreateView(TextureCreateInfo info, int firstLayer, int firstLevel) { - firstLayer += FirstLayer; - firstLevel += FirstLevel; + firstLayer += (int)FirstLayer; + firstLevel += (int)FirstLevel; - return _parent.CreateView(info, firstLayer, firstLevel); + return _parent.CreateView(info, (uint)firstLayer, (uint)firstLevel); } - public void CopyTo(ITexture destination, uint firstLayer, uint firstLevel) + public void CopyTo(ITexture destination, int firstLayer, int firstLevel) { TextureView destinationView = (TextureView)destination; @@ -118,18 +118,18 @@ namespace Ryujinx.Graphics.OpenGL.Image if (dstIsMultisample != srcIsMultisample && Info.Format.IsDepthOrStencil()) { - uint layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); + uint layers = (uint)Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); CopyWithBlitForDepthMS(destinationView, 0, firstLayer, layers); } else if (!dstIsMultisample && srcIsMultisample) { - uint layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); - _gd.TextureCopyMS.CopyMSToNonMS(this, destinationView, 0, firstLayer, layers); + uint layers = (uint)Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); + _gd.TextureCopyMS.CopyMSToNonMS(this, destinationView, 0, firstLayer, (int)layers); } else if (dstIsMultisample && !srcIsMultisample) { - uint layers = Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); - _gd.TextureCopyMS.CopyNonMSToMS(this, destinationView, 0, firstLayer, layers); + uint layers = (uint)Math.Min(Info.GetLayers(), destinationView.Info.GetLayers() - firstLayer); + _gd.TextureCopyMS.CopyNonMSToMS(this, destinationView, 0, firstLayer, (int)layers); } else if (destinationView.Info.BytesPerPixel != Info.BytesPerPixel) { @@ -228,7 +228,7 @@ namespace Ryujinx.Graphics.OpenGL.Image 1); _gd.TextureCopy.Copy(this, intermmediate, srcRegion, dstRegion, false); - _gd.TextureCopy.Copy(intermmediate, destinationView, dstRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); + _gd.TextureCopy.Copy(intermmediate, destinationView, dstRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, (int)layers, 1); } else { @@ -252,7 +252,7 @@ namespace Ryujinx.Graphics.OpenGL.Image 1); _gd.TextureCopy.Copy(this, intermmediate, srcRegion, srcRegion, false); - _gd.TextureCopy.Copy(intermmediate, destinationView, srcRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, layers, 1); + _gd.TextureCopy.Copy(intermmediate, destinationView, srcRegion, dstRegion, false, srcLayer, dstLayer, 0, 0, (int)layers, 1); } } @@ -344,7 +344,7 @@ namespace Ryujinx.Graphics.OpenGL.Image return WriteTo2D(IntPtr.Zero + offset, layer, level); } - private int WriteTo2D(IntPtr data, int layer, int level) + private unsafe int WriteTo2D(IntPtr data, int layer, int level) { TextureTarget target = Target.Convert(); @@ -364,15 +364,37 @@ namespace Ryujinx.Graphics.OpenGL.Image if (format.IsCompressed) { - _gd.Api.GetCompressedTextureSubImage(Handle, level, 0, 0, layer, Math.Max(1, Info.Width >> level), Math.Max(1, Info.Height >> level), 1, mipSize, data); + _gd.Api.GetCompressedTextureSubImage( + Handle, + level, + 0, + 0, + layer, + (uint)Math.Max(1, Info.Width >> level), + (uint)Math.Max(1, Info.Height >> level), + 1, + (uint)mipSize, + (void*)data); } else if (format.PixelFormat != PixelFormat.DepthStencil) { - _gd.Api.GetTextureSubImage(Handle, level, 0, 0, layer, Math.Max(1, Info.Width >> level), Math.Max(1, Info.Height >> level), 1, pixelFormat, pixelType, mipSize, data); + _gd.Api.GetTextureSubImage( + Handle, + level, + 0, + 0, + layer, + (uint)Math.Max(1, Info.Width >> level), + (uint)Math.Max(1, Info.Height >> level), + 1, + pixelFormat, + pixelType, + (uint)mipSize, + (void*)data); } else { - _gd.Api.GetTexImage(target, level, pixelFormat, pixelType, data); + _gd.Api.GetTexImage(target, level, pixelFormat, pixelType, (void*)data); // The GL function returns all layers. Must return the offset of the layer we're interested in. return target switch @@ -387,7 +409,7 @@ namespace Ryujinx.Graphics.OpenGL.Image return 0; } - private void WriteTo(IntPtr data, bool forceBgra = false) + private unsafe void WriteTo(IntPtr data, bool forceBgra = false) { TextureTarget target = Target.Convert(); @@ -433,11 +455,11 @@ namespace Ryujinx.Graphics.OpenGL.Image if (format.IsCompressed) { - _gd.Api.GetCompressedTexImage(target + face, level, data + faceOffset); + _gd.Api.GetCompressedTexImage(target + face, level, (void*)(data + faceOffset)); } else { - _gd.Api.GetTexImage(target + face, level, pixelFormat, pixelType, data + faceOffset); + _gd.Api.GetTexImage(target + face, level, pixelFormat, pixelType, (void*)(data + faceOffset)); } } @@ -710,9 +732,9 @@ namespace Ryujinx.Graphics.OpenGL.Image FormatInfo format = FormatTable.GetFormatInfo(Info.Format); - int width = Info.Width; - int height = Info.Height; - int depth = Info.Depth; + uint width = (uint)Info.Width; + uint height = (uint)Info.Height; + uint depth = (uint)Info.Depth; int levels = Info.GetLevelsClamped(); int offset = 0; @@ -738,8 +760,8 @@ namespace Ryujinx.Graphics.OpenGL.Image level, 0, width, - format.PixelFormat, - mipSize, + (InternalFormat)format.PixelFormat, + (uint)mipSize, data); } else @@ -766,8 +788,8 @@ namespace Ryujinx.Graphics.OpenGL.Image 0, width, height, - format.PixelFormat, - mipSize, + (InternalFormat)format.PixelFormat, + (uint)mipSize, data); } else @@ -799,8 +821,8 @@ namespace Ryujinx.Graphics.OpenGL.Image width, height, depth, - format.PixelFormat, - mipSize, + (InternalFormat)format.PixelFormat, + (uint)mipSize, data); } else @@ -829,20 +851,20 @@ namespace Ryujinx.Graphics.OpenGL.Image { _gd.Api.CompressedTexSubImage2D( TextureTarget.TextureCubeMapPositiveX + face, - baseLevel + level, + (int)baseLevel + level, 0, 0, width, height, - format.PixelFormat, - mipSize / 6, + (InternalFormat)format.PixelFormat, + (uint)mipSize / 6, data + faceOffset); } else { _gd.Api.TexSubImage2D( TextureTarget.TextureCubeMapPositiveX + face, - baseLevel + level, + (int)baseLevel + level, 0, 0, width, From 38d900c9325db6794f4085d01e582d0896b98c87 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 19:13:37 -0400 Subject: [PATCH 13/35] PersistentBuffers & Sync --- Directory.Packages.props | 1 + src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 7 +- .../PersistentBuffers.cs | 72 +++++++++++-------- .../Ryujinx.Graphics.OpenGL.csproj | 1 + src/Ryujinx.Graphics.OpenGL/Sync.cs | 4 +- 5 files changed, 52 insertions(+), 33 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 69b3ccdac1..86fb6c6888 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -39,6 +39,7 @@ + diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index 176b3527b4..60638c6477 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -5,6 +5,7 @@ using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; using Ryujinx.Graphics.OpenGL.Queries; using Ryujinx.Graphics.Shader.Translation; +using Silk.NET.OpenGL.Legacy.Extensions.ARB; using System; using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; @@ -56,7 +57,7 @@ namespace Ryujinx.Graphics.OpenGL TextureCopyIncompatible = new TextureCopyIncompatible(this); TextureCopyMS = new TextureCopyMS(this); _sync = new Sync(Api); - PersistentBuffers = new PersistentBuffers(); + PersistentBuffers = new PersistentBuffers(Api); ResourcePool = new ResourcePool(); } @@ -232,7 +233,9 @@ namespace Ryujinx.Graphics.OpenGL if (HwCapabilities.SupportsParallelShaderCompile) { - GL.Arb.MaxShaderCompilerThreads(Math.Min(Environment.ProcessorCount, 8)); + Api.TryGetExtension(out ArbParallelShaderCompile arbParallelShaderCompile); + + arbParallelShaderCompile.MaxShaderCompilerThreads((uint)Math.Min(Environment.ProcessorCount, 8)); } _counters.Initialize(); diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index 3ba8b1e196..181799d88a 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -11,33 +11,41 @@ namespace Ryujinx.Graphics.OpenGL { class PersistentBuffers : IDisposable { - private readonly PersistentBuffer _main = new(); - private readonly PersistentBuffer _background = new(); + private readonly GL _api; + private readonly PersistentBuffer _main; + private readonly PersistentBuffer _background; private readonly Dictionary _maps = new(); public PersistentBuffer Default => BackgroundContextWorker.InBackground ? _background : _main; + public PersistentBuffers(GL api) + { + _api = api; + _main = new(_api); + _background = new(_api); + } + public void Dispose() { _main?.Dispose(); _background?.Dispose(); } - public void Map(BufferHandle handle, int size) + public unsafe void Map(BufferHandle handle, int size) { - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); - IntPtr ptr = GL.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, size, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); + _api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); + void* ptr = _api.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, (uint)size, MapBufferAccessMask.ReadBit | MapBufferAccessMask.PersistentBit); - _maps[handle] = ptr; + _maps[handle] = new IntPtr(ptr); } public void Unmap(BufferHandle handle) { if (_maps.ContainsKey(handle)) { - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); - GL.UnmapBuffer(BufferTargetARB.CopyWriteBuffer); + _api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); + _api.UnmapBuffer(BufferTargetARB.CopyWriteBuffer); _maps.Remove(handle); } @@ -51,6 +59,7 @@ namespace Ryujinx.Graphics.OpenGL class PersistentBuffer : IDisposable { + private readonly GL _api; private IntPtr _bufferMap; private uint _copyBufferHandle; private int _copyBufferSize; @@ -58,24 +67,29 @@ namespace Ryujinx.Graphics.OpenGL private byte[] _data; private IntPtr _dataMap; - private void EnsureBuffer(int requiredSize) + public PersistentBuffer(GL api) + { + _api = api; + } + + private unsafe void EnsureBuffer(int requiredSize) { if (_copyBufferSize < requiredSize && _copyBufferHandle != 0) { - GL.DeleteBuffer(_copyBufferHandle); + _api.DeleteBuffer(_copyBufferHandle); _copyBufferHandle = 0; } if (_copyBufferHandle == 0) { - _copyBufferHandle = GL.GenBuffer(); + _copyBufferHandle = _api.GenBuffer(); _copyBufferSize = requiredSize; - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); - GL.BufferStorage(BufferTargetARB.CopyWriteBuffer, requiredSize, IntPtr.Zero, BufferStorageFlags.MapReadBit | BufferStorageFlags.MapPersistentBit); + _api.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); + _api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)requiredSize, IntPtr.Zero, BufferStorageMask.MapReadBit | BufferStorageMask.MapPersistentBit); - _bufferMap = GL.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, requiredSize, BufferAccessMask.MapReadBit | BufferAccessMask.MapPersistentBit); + _bufferMap = new IntPtr(_api.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, (uint)requiredSize, MapBufferAccessMask.ReadBit | MapBufferAccessMask.PersistentBit)); } } @@ -91,30 +105,30 @@ namespace Ryujinx.Graphics.OpenGL return _dataMap; } - private static void Sync() + private void Sync() { - GL.MemoryBarrier(MemoryBarrierMask.ClientMappedBufferBarrierBit); + _api.MemoryBarrier(MemoryBarrierMask.ClientMappedBufferBarrierBit); - IntPtr sync = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None); - WaitSyncStatus syncResult = GL.ClientWaitSync(sync, ClientWaitSyncFlags.SyncFlushCommandsBit, 1000000000); + IntPtr sync = _api.FenceSync(SyncCondition.SyncGpuCommandsComplete, SyncBehaviorFlags.None); + GLEnum syncResult = _api.ClientWaitSync(sync, SyncObjectMask.Bit, 1000000000); - if (syncResult == WaitSyncStatus.TimeoutExpired) + if (syncResult == GLEnum.TimeoutExpired) { Logger.Error?.PrintMsg(LogClass.Gpu, $"Failed to sync persistent buffer state within 1000ms. Continuing..."); } - GL.DeleteSync(sync); + _api.DeleteSync(sync); } public unsafe ReadOnlySpan GetTextureData(TextureView view, int size) { EnsureBuffer(size); - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyBufferHandle); + _api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyBufferHandle); view.WriteToPbo(0, false); - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); + _api.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); Sync(); @@ -125,11 +139,11 @@ namespace Ryujinx.Graphics.OpenGL { EnsureBuffer(size); - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyBufferHandle); + _api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyBufferHandle); int offset = view.WriteToPbo2D(0, layer, level); - GL.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); + _api.BindBuffer(BufferTargetARB.PixelPackBuffer, 0); Sync(); @@ -140,12 +154,12 @@ namespace Ryujinx.Graphics.OpenGL { EnsureBuffer(size); - GL.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToUInt32()); - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); + _api.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToUInt32()); + _api.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); - GL.CopyBufferSubData(BufferTargetARB.CopyReadBuffer, BufferTargetARB.CopyWriteBuffer, (IntPtr)offset, IntPtr.Zero, size); + _api.CopyBufferSubData(CopyBufferSubDataTarget.CopyReadBuffer, CopyBufferSubDataTarget.CopyWriteBuffer, offset, IntPtr.Zero, (uint)size); - GL.BindBuffer(BufferTargetARB.CopyWriteBuffer, 0); + _api.BindBuffer(BufferTargetARB.CopyWriteBuffer, 0); Sync(); @@ -156,7 +170,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_copyBufferHandle != 0) { - GL.DeleteBuffer(_copyBufferHandle); + _api.DeleteBuffer(_copyBufferHandle); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj b/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj index bcfde22369..fefc36f98b 100644 --- a/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj +++ b/src/Ryujinx.Graphics.OpenGL/Ryujinx.Graphics.OpenGL.csproj @@ -7,6 +7,7 @@ + diff --git a/src/Ryujinx.Graphics.OpenGL/Sync.cs b/src/Ryujinx.Graphics.OpenGL/Sync.cs index 7b03349686..f853c4f882 100644 --- a/src/Ryujinx.Graphics.OpenGL/Sync.cs +++ b/src/Ryujinx.Graphics.OpenGL/Sync.cs @@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.OpenGL } private ulong _firstHandle = 0; - private static SyncBehaviorFlags SyncFlags => HwCapabilities.RequiresSyncFlush ? SyncBehaviorFlags.None : SyncBehaviorFlags.SyncFlushCommandsBit; + private static SyncObjectMask SyncFlags => HwCapabilities.RequiresSyncFlush ? 0 : SyncObjectMask.Bit; private readonly List _handles = new(); private readonly GL _api; @@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.OpenGL if (HwCapabilities.RequiresSyncFlush) { // Force commands to flush up to the syncpoint. - _api.ClientWaitSync(handle.Handle, SyncBehaviorFlags.SyncFlushCommandsBit, 0); + _api.ClientWaitSync(handle.Handle, SyncObjectMask.Bit, 0); } lock (_handles) From e46b671875ccdefc809d4fc4cc8982ea4ff4adab Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 19:16:26 -0400 Subject: [PATCH 14/35] Cleanup IntPtr casts --- src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 9 +++++---- src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs | 4 ++-- src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index 60638c6477..00b3a439a4 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -7,6 +7,7 @@ using Ryujinx.Graphics.OpenGL.Queries; using Ryujinx.Graphics.Shader.Translation; using Silk.NET.OpenGL.Legacy.Extensions.ARB; using System; +using System.Runtime.InteropServices; using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; namespace Ryujinx.Graphics.OpenGL @@ -247,11 +248,11 @@ namespace Ryujinx.Graphics.OpenGL Api.ClampColor(ClampColorTargetARB.FragmentColorArb, ClampColorModeARB.False); } - private void PrintGpuInformation() + private unsafe void PrintGpuInformation() { - GpuVendor = Api.GetString(StringName.Vendor); - GpuRenderer = Api.GetString(StringName.Renderer); - GpuVersion = Api.GetString(StringName.Version); + GpuVendor = Marshal.PtrToStringAnsi((IntPtr)Api.GetString(StringName.Vendor)); + GpuRenderer = Marshal.PtrToStringAnsi((IntPtr)Api.GetString(StringName.Renderer)); + GpuVersion = Marshal.PtrToStringAnsi((IntPtr)Api.GetString(StringName.Version)); Logger.Notice.Print(LogClass.Gpu, $"{GpuVendor} {GpuRenderer} ({GpuVersion})"); } diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index 181799d88a..050a54370e 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.OpenGL _api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); void* ptr = _api.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, (uint)size, MapBufferAccessMask.ReadBit | MapBufferAccessMask.PersistentBit); - _maps[handle] = new IntPtr(ptr); + _maps[handle] = (IntPtr)ptr; } public void Unmap(BufferHandle handle) @@ -89,7 +89,7 @@ namespace Ryujinx.Graphics.OpenGL _api.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); _api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)requiredSize, IntPtr.Zero, BufferStorageMask.MapReadBit | BufferStorageMask.MapPersistentBit); - _bufferMap = new IntPtr(_api.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, (uint)requiredSize, MapBufferAccessMask.ReadBit | MapBufferAccessMask.PersistentBit)); + _bufferMap = (IntPtr)_api.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, (uint)requiredSize, MapBufferAccessMask.ReadBit | MapBufferAccessMask.PersistentBit); } } diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs index f5fc24c4fe..ad74b28686 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs @@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries unsafe { - _bufferMap = new IntPtr(_api.MapBufferRange(BufferTargetARB.QueryBuffer, IntPtr.Zero, sizeof(long), MapBufferAccessMask.ReadBit | MapBufferAccessMask.WriteBit | MapBufferAccessMask.PersistentBit)); + _bufferMap = (IntPtr)_api.MapBufferRange(BufferTargetARB.QueryBuffer, IntPtr.Zero, sizeof(long), MapBufferAccessMask.ReadBit | MapBufferAccessMask.WriteBit | MapBufferAccessMask.PersistentBit); } } From 8df23211f6196dbb8ee28f6cce51aadaf35e7679 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 19:21:01 -0400 Subject: [PATCH 15/35] Effects --- .../Effects/FsrScalingFilter.cs | 10 ++++---- .../Effects/FxaaPostProcessingEffect.cs | 14 +++++------ .../Effects/SmaaPostProcessingEffect.cs | 24 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs index 4e4a1f8493..d9821a2417 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs @@ -123,13 +123,13 @@ namespace Ryujinx.Graphics.OpenGL.Effects uint previousProgram = (uint)_gd.Api.GetInteger(GetPName.CurrentProgram); int previousUnit = _gd.Api.GetInteger(GetPName.ActiveTexture); _gd.Api.ActiveTexture(TextureUnit.Texture0); - int previousTextureBinding = _gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); - _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); int threadGroupWorkRegionDim = 16; - int dispatchX = (width + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; - int dispatchY = (height + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim; + uint dispatchX = (uint)((width + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim); + uint dispatchY = (uint)((height + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim); // Scaling pass float srcWidth = Math.Abs(source.X2 - source.X1); @@ -156,7 +156,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects // Sharpening Pass _gd.Api.UseProgram(_sharpeningShaderProgram); - _gd.Api.BindImageTexture(0, destinationTexture.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.BindImageTexture(0, destinationTexture.Handle, 0, false, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); textureView.Bind(0); _gd.Api.Uniform1(_inputUniform, 0); _gd.Api.Uniform1(_outputUniform, 0); diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs index 24a72a23a3..ed772b8743 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs @@ -31,7 +31,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects private void Initialize() { - _shaderProgram = ShaderHelper.CompileProgram(EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/fxaa.glsl"), ShaderType.ComputeShader); + _shaderProgram = ShaderHelper.CompileProgram(_gd.Api, EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/fxaa.glsl"), ShaderType.ComputeShader); _resolutionUniform = _gd.Api.GetUniformLocation(_shaderProgram, "invResolution"); _inputUniform = _gd.Api.GetUniformLocation(_shaderProgram, "inputTexture"); @@ -49,21 +49,21 @@ namespace Ryujinx.Graphics.OpenGL.Effects var textureView = _textureStorage.CreateView(view.Info, 0, 0) as TextureView; - int previousProgram = _gd.Api.GetInteger(GetPName.CurrentProgram); + uint previousProgram = (uint)_gd.Api.GetInteger(GetPName.CurrentProgram); int previousUnit = _gd.Api.GetInteger(GetPName.ActiveTexture); _gd.Api.ActiveTexture(TextureUnit.Texture0); - int previousTextureBinding = _gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); - _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); _gd.Api.UseProgram(_shaderProgram); - var dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize); - var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); + uint dispatchX = (uint)BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize); + uint dispatchY = (uint)BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); view.Bind(0); _gd.Api.Uniform1(_inputUniform, 0); _gd.Api.Uniform1(_outputUniform, 0); - _gd.Api.Uniform2(_resolutionUniform, (float)view.Width, (float)view.Height); + _gd.Api.Uniform2(_resolutionUniform, view.Width, view.Height); _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); _gd.Api.UseProgram(previousProgram); _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs index 4b9d4983d2..dfb7073fec 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs @@ -93,13 +93,13 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa var neighbourShaderData = EmbeddedResources.ReadAllText("Ryujinx.Graphics.OpenGL/Effects/Shaders/smaa_neighbour.glsl"); var shaders = new string[] { presets, edgeShaderData }; - var edgeProgram = ShaderHelper.CompileProgram(shaders, ShaderType.ComputeShader); + var edgeProgram = ShaderHelper.CompileProgram(_gd.Api, shaders, ShaderType.ComputeShader); shaders[1] = blendShaderData; - var blendProgram = ShaderHelper.CompileProgram(shaders, ShaderType.ComputeShader); + var blendProgram = ShaderHelper.CompileProgram(_gd.Api, shaders, ShaderType.ComputeShader); shaders[1] = neighbourShaderData; - var neighbourProgram = ShaderHelper.CompileProgram(shaders, ShaderType.ComputeShader); + var neighbourProgram = ShaderHelper.CompileProgram(_gd.Api, shaders, ShaderType.ComputeShader); _edgeShaderPrograms[i] = edgeProgram; _blendShaderPrograms[i] = blendProgram; @@ -184,14 +184,14 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa var areaTexture = _areaTexture.DefaultView as TextureView; var searchTexture = _searchTexture.DefaultView as TextureView; - var previousFramebuffer = _gd.Api.GetInteger(GetPName.DrawFramebufferBinding); + uint previousFramebuffer = (uint)_gd.Api.GetInteger(GetPName.DrawFramebufferBinding); int previousUnit = _gd.Api.GetInteger(GetPName.ActiveTexture); _gd.Api.ActiveTexture(TextureUnit.Texture0); - int previousTextureBinding0 = _gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding0 = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); _gd.Api.ActiveTexture(TextureUnit.Texture1); - int previousTextureBinding1 = _gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding1 = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); _gd.Api.ActiveTexture(TextureUnit.Texture2); - int previousTextureBinding2 = _gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding2 = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); var framebuffer = new Framebuffer(_gd.Api); framebuffer.Bind(); @@ -206,11 +206,11 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa framebuffer.Dispose(); - var dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize); - var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); + uint dispatchX = (uint)BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize); + uint dispatchY = (uint)BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); uint previousProgram = (uint)_gd.Api.GetInteger(GetPName.CurrentProgram); - _gd.Api.BindImageTexture(0, edgeOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.BindImageTexture(0, edgeOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); _gd.Api.UseProgram(_edgeShaderPrograms[Quality]); view.Bind(0); _gd.Api.Uniform1(_inputUniform, 0); @@ -219,7 +219,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - _gd.Api.BindImageTexture(0, blendOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.BindImageTexture(0, blendOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite,InternalFormat.Rgba8); _gd.Api.UseProgram(_blendShaderPrograms[Quality]); edgeOutput.Bind(0); areaTexture.Bind(1); @@ -232,7 +232,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, SizedInternalFormat.Rgba8); + _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); _gd.Api.UseProgram(_neighbourShaderPrograms[Quality]); view.Bind(0); blendOutput.Bind(1); From a9d0dd389301fd85325e0f9cf34c7092a82bea57 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 19:34:19 -0400 Subject: [PATCH 16/35] Convert GetBinary --- src/Ryujinx.Graphics.OpenGL/Program.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index 7938ac9064..dbfaa76fab 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -89,7 +89,7 @@ namespace Ryujinx.Graphics.OpenGL { fixed (byte* ptr = code) { - _api.ProgramBinary(Handle, binaryFormat, (IntPtr)ptr, code.Length - 4); + _api.ProgramBinary(Handle, (GLEnum)binaryFormat, (IntPtr)ptr, (uint)code.Length - 4); } } } @@ -138,17 +138,21 @@ namespace Ryujinx.Graphics.OpenGL return _status; } - public byte[] GetBinary() + public unsafe byte[] GetBinary() { _api.GetProgram(Handle, ProgramPropertyARB.ProgramBinaryLength, out int size); - byte[] data = new byte[size + 4]; + Span data = stackalloc byte[size]; + GLEnum binFormat; - _api.GetProgramBinary(Handle, (uint)size, out _, out GLEnum binFormat, data); + fixed (byte* ptr = data) + { + _api.GetProgramBinary(Handle, (uint)size, out _, out binFormat, ptr); + } - BinaryPrimitives.WriteInt32LittleEndian(data.AsSpan(size, 4), (int)binFormat); + BinaryPrimitives.WriteInt32LittleEndian(data, (int)binFormat); - return data; + return data.ToArray(); } private void DeleteShaders() From 1d18ed2ba206efa683ec457d40688d7f48e2e599 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 19:44:22 -0400 Subject: [PATCH 17/35] Program --- src/Ryujinx.Graphics.OpenGL/Program.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index dbfaa76fab..9d388d301b 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -1,4 +1,5 @@ using Silk.NET.OpenGL.Legacy; +using Silk.NET.OpenGL.Legacy.Extensions.ARB; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; @@ -33,7 +34,7 @@ namespace Ryujinx.Graphics.OpenGL public int FragmentOutputMap { get; } - public Program(GL api, ShaderSource[] shaders, int fragmentOutputMap) + public unsafe Program(GL api, ShaderSource[] shaders, int fragmentOutputMap) { _api = api; Handle = _api.CreateProgram(); @@ -61,8 +62,11 @@ namespace Ryujinx.Graphics.OpenGL _api.CompileShader(shaderHandle); break; case TargetLanguage.Spirv: - _api.ShaderBinary(1, ref shaderHandle, ShaderBinaryFormat.ShaderBinaryFormatSpirV, shader.BinaryCode, shader.BinaryCode.Length); - _api.SpecializeShader(shaderHandle, "main", 0, (int[])null, (int[])null); + fixed (byte* ptr = shader.BinaryCode.AsSpan()) + { + _api.ShaderBinary(1, in shaderHandle, ShaderBinaryFormat.ShaderBinaryFormatSpirV, ptr, (uint)shader.BinaryCode.Length); + } + _api.SpecializeShader(shaderHandle, "main", 0, (uint[])null, (uint[])null); break; } @@ -106,7 +110,7 @@ namespace Ryujinx.Graphics.OpenGL { if (!blocking && HwCapabilities.SupportsParallelShaderCompile) { - _api.GetProgram(Handle, (GetProgramParameterName)ArbParallelShaderCompile.CompletionStatusArb, out int completed); + _api.GetProgram(Handle, (GLEnum)ARB.CompletionStatusArb, out int completed); if (completed == 0) { @@ -142,7 +146,7 @@ namespace Ryujinx.Graphics.OpenGL { _api.GetProgram(Handle, ProgramPropertyARB.ProgramBinaryLength, out int size); - Span data = stackalloc byte[size]; + byte[] data = new byte[size]; GLEnum binFormat; fixed (byte* ptr = data) @@ -152,7 +156,7 @@ namespace Ryujinx.Graphics.OpenGL BinaryPrimitives.WriteInt32LittleEndian(data, (int)binFormat); - return data.ToArray(); + return data; } private void DeleteShaders() From 0c88c23b30a1035575dc4615f8e9f21483d110ba Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 20:04:29 -0400 Subject: [PATCH 18/35] Debugger, Pipeline --- src/Ryujinx.Graphics.OpenGL/Debugger.cs | 21 +++--- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 89 ++++++++++++++----------- 2 files changed, 62 insertions(+), 48 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Debugger.cs b/src/Ryujinx.Graphics.OpenGL/Debugger.cs index 89af95aff9..1428429227 100644 --- a/src/Ryujinx.Graphics.OpenGL/Debugger.cs +++ b/src/Ryujinx.Graphics.OpenGL/Debugger.cs @@ -16,7 +16,7 @@ namespace Ryujinx.Graphics.OpenGL public static void Initialize(GL gl, GraphicsDebugLevel logLevel) { // Disable everything - gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, false); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (uint[])null, false); if (logLevel == GraphicsDebugLevel.None) { @@ -30,16 +30,16 @@ namespace Ryujinx.Graphics.OpenGL if (logLevel == GraphicsDebugLevel.Error) { - gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (uint[])null, true); } else if (logLevel == GraphicsDebugLevel.Slowdowns) { - gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (int[])null, true); - gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypePerformance, DebugSeverity.DontCare, 0, (int[])null, true); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (uint[])null, true); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypePerformance, DebugSeverity.DontCare, 0, (uint[])null, true); } else { - gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (int[])null, true); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (uint[])null, true); } _counter = 0; @@ -61,7 +61,10 @@ namespace Ryujinx.Graphics.OpenGL { string msg = Marshal.PtrToStringUTF8(message).Replace('\n', ' '); - switch (type) + DebugType debugType = (DebugType)type; + DebugSource debugSource = (DebugSource)source; + + switch (debugType) { case DebugType.DebugTypeError: Logger.Error?.Print(LogClass.Gpu, $"{severity}: {msg}\nCallStack={Environment.StackTrace}", "GLERROR"); @@ -76,7 +79,7 @@ namespace Ryujinx.Graphics.OpenGL Logger.Info?.Print(LogClass.Gpu, $"}} ({id}) {severity}: {msg}", "GLINFO"); break; default: - if (source == DebugSource.DebugSourceApplication) + if (debugSource == DebugSource.DebugSourceApplication) { Logger.Info?.Print(LogClass.Gpu, $"{type} {severity}: {msg}", "GLINFO"); } @@ -93,7 +96,7 @@ namespace Ryujinx.Graphics.OpenGL { int counter = Interlocked.Increment(ref _counter); - gl.PushDebugGroup(DebugSource.DebugSourceApplication, counter, dbgMsg.Length, dbgMsg); + gl.PushDebugGroup(DebugSource.DebugSourceApplication, (uint)counter, (uint)dbgMsg.Length, dbgMsg); } public static void PopGroup(GL gl) @@ -103,7 +106,7 @@ namespace Ryujinx.Graphics.OpenGL public static void Print(GL gl, string dbgMsg, DebugType type = DebugType.DebugTypeMarker, DebugSeverity severity = DebugSeverity.DebugSeverityNotification, int id = 999999) { - gl.DebugMessageInsert(DebugSource.DebugSourceApplication, type, id, severity, dbgMsg.Length, dbgMsg); + gl.DebugMessageInsert(DebugSource.DebugSourceApplication, type, (uint)id, severity, (uint)dbgMsg.Length, dbgMsg); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 5af2da645c..6922964636 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -220,7 +220,7 @@ namespace Ryujinx.Graphics.OpenGL PrepareForDispatch(); - _api.DispatchCompute(groupsX, groupsY, groupsZ); + _api.DispatchCompute((uint)groupsX, (uint)groupsY, (uint)groupsZ); } public void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance) @@ -256,10 +256,10 @@ namespace Ryujinx.Graphics.OpenGL int firstInstance) { // TODO: Instanced rendering. - int quadsCount = vertexCount / 4; + uint quadsCount = (uint)(vertexCount / 4); int[] firsts = new int[quadsCount]; - int[] counts = new int[quadsCount]; + uint[] counts = new uint[quadsCount]; for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { @@ -280,19 +280,19 @@ namespace Ryujinx.Graphics.OpenGL int firstVertex, int firstInstance) { - int quadsCount = (vertexCount - 2) / 2; + uint quadsCount = (uint)((vertexCount - 2) / 2); if (firstInstance != 0 || instanceCount != 1) { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - _api.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, instanceCount, firstInstance); + _api.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, (uint)instanceCount, (uint)firstInstance); } } else { int[] firsts = new int[quadsCount]; - int[] counts = new int[quadsCount]; + uint[] counts = new uint[quadsCount]; firsts[0] = firstVertex; counts[0] = 4; @@ -319,20 +319,20 @@ namespace Ryujinx.Graphics.OpenGL { if (firstInstance == 0 && instanceCount == 1) { - _api.DrawArrays(_primitiveType, firstVertex, vertexCount); + _api.DrawArrays(_primitiveType, firstVertex, (uint)vertexCount); } else if (firstInstance == 0) { - _api.DrawArraysInstanced(_primitiveType, firstVertex, vertexCount, instanceCount); + _api.DrawArraysInstanced(_primitiveType, firstVertex, (uint)vertexCount, (uint)instanceCount); } else { _api.DrawArraysInstancedBaseInstance( _primitiveType, firstVertex, - vertexCount, - instanceCount, - firstInstance); + (uint)vertexCount, + (uint)instanceCount, + (uint)firstInstance); } } @@ -398,7 +398,7 @@ namespace Ryujinx.Graphics.OpenGL PostDraw(); } - private void DrawQuadsIndexedImpl( + private unsafe void DrawQuadsIndexedImpl( int indexCount, int instanceCount, IntPtr indexBaseOffset, @@ -419,9 +419,9 @@ namespace Ryujinx.Graphics.OpenGL 4, _elementsType, indexBaseOffset + quadIndex * 4 * indexElemSize, - instanceCount, + (uint)instanceCount, firstVertex, - firstInstance); + (uint)firstInstance); } } else if (firstInstance != 0) @@ -433,8 +433,8 @@ namespace Ryujinx.Graphics.OpenGL 4, _elementsType, indexBaseOffset + quadIndex * 4 * indexElemSize, - instanceCount, - firstInstance); + (uint)instanceCount, + (uint)firstInstance); } } else @@ -446,38 +446,43 @@ namespace Ryujinx.Graphics.OpenGL 4, _elementsType, indexBaseOffset + quadIndex * 4 * indexElemSize, - instanceCount); + (uint)instanceCount); } } } else { - IntPtr[] indices = new IntPtr[quadsCount]; + void*[] indices = new void*[quadsCount]; - int[] counts = new int[quadsCount]; + uint[] counts = new uint[quadsCount]; int[] baseVertices = new int[quadsCount]; for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - indices[quadIndex] = indexBaseOffset + quadIndex * 4 * indexElemSize; + indices[quadIndex] = (void*)(indexBaseOffset + quadIndex * 4 * indexElemSize); counts[quadIndex] = 4; baseVertices[quadIndex] = firstVertex; } - _api.MultiDrawElementsBaseVertex( - PrimitiveType.TriangleFan, - counts, - _elementsType, - indices, - quadsCount, - baseVertices); + fixed (uint* countsPtr = counts) + fixed (void* indicesPtr = indices) + fixed (int* baseVerticesPtr = baseVertices) + { + _api.MultiDrawElementsBaseVertex( + PrimitiveType.TriangleFan, + countsPtr, + _elementsType, + indicesPtr, + (uint)quadsCount, + baseVerticesPtr); + } } } - private void DrawQuadStripIndexedImpl( + private unsafe void DrawQuadStripIndexedImpl( int indexCount, int instanceCount, IntPtr indexBaseOffset, @@ -488,13 +493,13 @@ namespace Ryujinx.Graphics.OpenGL // TODO: Instanced rendering. int quadsCount = (indexCount - 2) / 2; - IntPtr[] indices = new IntPtr[quadsCount]; + void*[] indices = new void*[quadsCount]; - int[] counts = new int[quadsCount]; + uint[] counts = new uint[quadsCount]; int[] baseVertices = new int[quadsCount]; - indices[0] = indexBaseOffset; + indices[0] = (void*)indexBaseOffset; counts[0] = 4; @@ -502,20 +507,25 @@ namespace Ryujinx.Graphics.OpenGL for (int quadIndex = 1; quadIndex < quadsCount; quadIndex++) { - indices[quadIndex] = indexBaseOffset + quadIndex * 2 * indexElemSize; + indices[quadIndex] = (void*)(indexBaseOffset + quadIndex * 2 * indexElemSize); counts[quadIndex] = 4; baseVertices[quadIndex] = firstVertex; } - _api.MultiDrawElementsBaseVertex( - PrimitiveType.TriangleFan, - counts, - _elementsType, - indices, - quadsCount, - baseVertices); + fixed (uint* countsPtr = counts) + fixed (void* indicesPtr = indices) + fixed (int* baseVerticesPtr = baseVertices) + { + _api.MultiDrawElementsBaseVertex( + PrimitiveType.TriangleFan, + countsPtr, + _elementsType, + indicesPtr, + (uint)quadsCount, + baseVerticesPtr); + } } private void DrawIndexedImpl( @@ -725,6 +735,7 @@ namespace Ryujinx.Graphics.OpenGL _api.ClipControl(ClipControlOrigin.UpperLeft, ClipControlDepth.NegativeOneToOne); _drawTexture.Draw( + _api, view, samp, dstRegion.X1, From 15978d9c55eae106aefb359e723175e049d25f15 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 20:28:46 -0400 Subject: [PATCH 19/35] Pipeline --- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 36 ++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 6922964636..7a49f2c9f0 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -537,13 +537,13 @@ namespace Ryujinx.Graphics.OpenGL { if (firstInstance == 0 && firstVertex == 0 && instanceCount == 1) { - _api.DrawElements(_primitiveType, indexCount, _elementsType, indexBaseOffset); + _api.DrawElements(_primitiveType, (uint)indexCount, _elementsType, indexBaseOffset); } else if (firstInstance == 0 && instanceCount == 1) { _api.DrawElementsBaseVertex( _primitiveType, - indexCount, + (uint)indexCount, _elementsType, indexBaseOffset, firstVertex); @@ -552,41 +552,41 @@ namespace Ryujinx.Graphics.OpenGL { _api.DrawElementsInstanced( _primitiveType, - indexCount, + (uint)indexCount, _elementsType, indexBaseOffset, - instanceCount); + (uint)instanceCount); } else if (firstInstance == 0) { _api.DrawElementsInstancedBaseVertex( _primitiveType, - indexCount, + (uint)indexCount, _elementsType, indexBaseOffset, - instanceCount, + (uint)instanceCount, firstVertex); } else if (firstVertex == 0) { _api.DrawElementsInstancedBaseInstance( _primitiveType, - indexCount, + (uint)indexCount, _elementsType, indexBaseOffset, - instanceCount, - firstInstance); + (uint)instanceCount, + (uint)firstInstance); } else { _api.DrawElementsInstancedBaseVertexBaseInstance( _primitiveType, - indexCount, + (uint)indexCount, _elementsType, indexBaseOffset, - instanceCount, + (uint)instanceCount, firstVertex, - firstInstance); + (uint)firstInstance); } } @@ -630,9 +630,9 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, _elementsType, (IntPtr)indirectBuffer.Offset, - (IntPtr)parameterBuffer.Offset, - maxDrawCount, - stride); + parameterBuffer.Offset, + (uint)maxDrawCount, + (uint)stride); _vertexArray.RestoreIndexBuffer(); @@ -672,9 +672,9 @@ namespace Ryujinx.Graphics.OpenGL _api.MultiDrawArraysIndirectCount( _primitiveType, (IntPtr)indirectBuffer.Offset, - (IntPtr)parameterBuffer.Offset, - maxDrawCount, - stride); + parameterBuffer.Offset, + (uint)maxDrawCount, + (uint)stride); PostDraw(); } From 5db3568305ce98c21a23ad73606dd4a958a1c914 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 21:13:22 -0400 Subject: [PATCH 20/35] OpenGL namespace is all done! --- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 2 +- .../HardwareCapabilities.cs | 161 ++++++++ src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs | 143 ------- src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs | 40 +- .../Image/TextureCopy.cs | 2 +- .../Image/TextureView.cs | 6 +- src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 99 +++-- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 357 +++++++++--------- src/Ryujinx.Graphics.OpenGL/Program.cs | 52 +-- src/Ryujinx.Graphics.OpenGL/Sync.cs | 26 +- 10 files changed, 471 insertions(+), 417 deletions(-) create mode 100644 src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs delete mode 100644 src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index 722b28abcd..d09bee156e 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -78,7 +78,7 @@ namespace Ryujinx.Graphics.OpenGL { return new PinnedSpan(IntPtr.Add(ptr, offset).ToPointer(), size); } - else if (HwCapabilities.UsePersistentBufferForFlush) + else if (gd.Capabilities.UsePersistentBufferForFlush) { return PinnedSpan.UnsafeFromSpan(gd.PersistentBuffers.Default.GetBufferData(buffer, offset, size)); } diff --git a/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs b/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs new file mode 100644 index 0000000000..704cbcd027 --- /dev/null +++ b/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs @@ -0,0 +1,161 @@ +using Silk.NET.OpenGL.Legacy; +using System; +using System.Runtime.InteropServices; + +namespace Ryujinx.Graphics.OpenGL +{ + public enum GpuVendor + { + Unknown, + AmdWindows, + AmdUnix, + IntelWindows, + IntelUnix, + Nvidia, + } + + readonly struct HardwareCapabilities + { + public readonly bool SupportsAlphaToCoverageDitherControl; + public readonly bool SupportsAstcCompression; + public readonly bool SupportsBlendEquationAdvanced; + public readonly bool SupportsDrawTexture; + public readonly bool SupportsFragmentShaderInterlock; + public readonly bool SupportsFragmentShaderOrdering; + public readonly bool SupportsGeometryShaderPassthrough; + public readonly bool SupportsImageLoadFormatted; + public readonly bool SupportsIndirectParameters; + public readonly bool SupportsParallelShaderCompile; + public readonly bool SupportsPolygonOffsetClamp; + public readonly bool SupportsQuads; + public readonly bool SupportsSeamlessCubemapPerTexture; + public readonly bool SupportsShaderBallot; + public readonly bool SupportsShaderViewportLayerArray; + public readonly bool SupportsViewportArray2; + public readonly bool SupportsTextureCompressionBptc; + public readonly bool SupportsTextureCompressionRgtc; + public readonly bool SupportsTextureCompressionS3tc; + public readonly bool SupportsTextureShadowLod; + public readonly bool SupportsViewportSwizzle; + + public bool SupportsMismatchingViewFormat => GpuVendor != GpuVendor.AmdWindows && GpuVendor != GpuVendor.IntelWindows; + public bool SupportsNonConstantTextureOffset => GpuVendor == GpuVendor.Nvidia; + public bool RequiresSyncFlush => GpuVendor == GpuVendor.AmdWindows || IsIntel; + public bool UsePersistentBufferForFlush => GpuVendor == GpuVendor.AmdWindows || GpuVendor == GpuVendor.Nvidia; + + public readonly int MaximumComputeSharedMemorySize; + public readonly int StorageBufferOffsetAlignment; + public readonly int TextureBufferOffsetAlignment; + + public readonly float MaximumSupportedAnisotropy; + + public readonly GpuVendor GpuVendor; + + public HardwareCapabilities( + bool supportsAlphaToCoverageDitherControl, + bool supportsAstcCompression, + bool supportsBlendEquationAdvanced, + bool supportsDrawTexture, + bool supportsFragmentShaderInterlock, + bool supportsFragmentShaderOrdering, + bool supportsGeometryShaderPassthrough, + bool supportsImageLoadFormatted, + bool supportsIndirectParameters, + bool supportsParallelShaderCompile, + bool supportsPolygonOffsetClamp, + bool supportsQuads, + bool supportsSeamlessCubemapPerTexture, + bool supportsShaderBallot, + bool supportsShaderViewportLayerArray, + bool supportsViewportArray2, + bool supportsTextureCompressionBptc, + bool supportsTextureCompressionRgtc, + bool supportsTextureCompressionS3Tc, + bool supportsTextureShadowLod, + bool supportsViewportSwizzle, + int maximumComputeSharedMemorySize, + int storageBufferOffsetAlignment, + int textureBufferOffsetAlignment, + float maximumSupportedAnisotropy, + GpuVendor gpuVendor) + { + SupportsAlphaToCoverageDitherControl = supportsAlphaToCoverageDitherControl; + SupportsAstcCompression = supportsAstcCompression; + SupportsBlendEquationAdvanced = supportsBlendEquationAdvanced; + SupportsDrawTexture = supportsDrawTexture; + SupportsFragmentShaderInterlock = supportsFragmentShaderInterlock; + SupportsFragmentShaderOrdering = supportsFragmentShaderOrdering; + SupportsGeometryShaderPassthrough = supportsGeometryShaderPassthrough; + SupportsImageLoadFormatted = supportsImageLoadFormatted; + SupportsIndirectParameters = supportsIndirectParameters; + SupportsParallelShaderCompile = supportsParallelShaderCompile; + SupportsPolygonOffsetClamp = supportsPolygonOffsetClamp; + SupportsQuads = supportsQuads; + SupportsSeamlessCubemapPerTexture = supportsSeamlessCubemapPerTexture; + SupportsShaderBallot = supportsShaderBallot; + SupportsShaderViewportLayerArray = supportsShaderViewportLayerArray; + SupportsViewportArray2 = supportsViewportArray2; + SupportsTextureCompressionBptc = supportsTextureCompressionBptc; + SupportsTextureCompressionRgtc = supportsTextureCompressionRgtc; + SupportsTextureCompressionS3tc = supportsTextureCompressionS3Tc; + SupportsTextureShadowLod = supportsTextureShadowLod; + SupportsViewportSwizzle = supportsViewportSwizzle; + MaximumComputeSharedMemorySize = maximumComputeSharedMemorySize; + StorageBufferOffsetAlignment = storageBufferOffsetAlignment; + TextureBufferOffsetAlignment = textureBufferOffsetAlignment; + MaximumSupportedAnisotropy = maximumSupportedAnisotropy; + GpuVendor = gpuVendor; + } + + public bool IsIntel => GpuVendor == GpuVendor.IntelWindows || GpuVendor == GpuVendor.IntelUnix; + + public static unsafe bool HasExtension(GL api, string name) + { + int numExtensions = api.GetInteger(GetPName.NumExtensions); + + for (uint extension = 0; extension < numExtensions; extension++) + { + if (Marshal.PtrToStringAnsi((IntPtr)api.GetString(StringName.Extensions, extension)) == name) + { + return true; + } + } + + return false; + } + + public static unsafe GpuVendor GetGpuVendor(GL api) + { + string vendor = Marshal.PtrToStringAnsi((IntPtr)api.GetString(StringName.Vendor)).ToLowerInvariant(); + + switch (vendor) + { + case "nvidia corporation": + return GpuVendor.Nvidia; + case "intel": + { + string renderer = Marshal.PtrToStringAnsi((IntPtr)api.GetString(StringName.Renderer)).ToLowerInvariant(); + + return renderer.Contains("mesa") ? GpuVendor.IntelUnix : GpuVendor.IntelWindows; + } + case "ati technologies inc.": + case "advanced micro devices, inc.": + return GpuVendor.AmdWindows; + case "amd": + case "x.org": + return GpuVendor.AmdUnix; + default: + return GpuVendor.Unknown; + } + } + + public static bool SupportsQuadsCheck(GL api) + { + api.GetError(); // Clear any existing error. + api.Begin(PrimitiveType.Quads); + api.End(); + + return api.GetError() == GLEnum.NoError; + } + } +} diff --git a/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs b/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs deleted file mode 100644 index bd44379e72..0000000000 --- a/src/Ryujinx.Graphics.OpenGL/HwCapabilities.cs +++ /dev/null @@ -1,143 +0,0 @@ -using Silk.NET.OpenGL.Legacy; -using System; - -namespace Ryujinx.Graphics.OpenGL -{ - static class HwCapabilities - { - private static readonly Lazy _supportsAlphaToCoverageDitherControl = new(() => HasExtension("GL_NV_alpha_to_coverage_dither_control")); - private static readonly Lazy _supportsAstcCompression = new(() => HasExtension("GL_KHR_texture_compression_astc_ldr")); - private static readonly Lazy _supportsBlendEquationAdvanced = new(() => HasExtension("GL_NV_blend_equation_advanced")); - private static readonly Lazy _supportsDrawTexture = new(() => HasExtension("GL_NV_draw_texture")); - private static readonly Lazy _supportsFragmentShaderInterlock = new(() => HasExtension("GL_ARB_fragment_shader_interlock")); - private static readonly Lazy _supportsFragmentShaderOrdering = new(() => HasExtension("GL_INTEL_fragment_shader_ordering")); - private static readonly Lazy _supportsGeometryShaderPassthrough = new(() => HasExtension("GL_NV_geometry_shader_passthrough")); - private static readonly Lazy _supportsImageLoadFormatted = new(() => HasExtension("GL_EXT_shader_image_load_formatted")); - private static readonly Lazy _supportsIndirectParameters = new(() => HasExtension("GL_ARB_indirect_parameters")); - private static readonly Lazy _supportsParallelShaderCompile = new(() => HasExtension("GL_ARB_parallel_shader_compile")); - private static readonly Lazy _supportsPolygonOffsetClamp = new(() => HasExtension("GL_EXT_polygon_offset_clamp")); - private static readonly Lazy _supportsQuads = new(SupportsQuadsCheck); - private static readonly Lazy _supportsSeamlessCubemapPerTexture = new(() => HasExtension("GL_ARB_seamless_cubemap_per_texture")); - private static readonly Lazy _supportsShaderBallot = new(() => HasExtension("GL_ARB_shader_ballot")); - private static readonly Lazy _supportsShaderViewportLayerArray = new(() => HasExtension("GL_ARB_shader_viewport_layer_array")); - private static readonly Lazy _supportsViewportArray2 = new(() => HasExtension("GL_NV_viewport_array2")); - private static readonly Lazy _supportsTextureCompressionBptc = new(() => HasExtension("GL_EXT_texture_compression_bptc")); - private static readonly Lazy _supportsTextureCompressionRgtc = new(() => HasExtension("GL_EXT_texture_compression_rgtc")); - private static readonly Lazy _supportsTextureCompressionS3tc = new(() => HasExtension("GL_EXT_texture_compression_s3tc")); - private static readonly Lazy _supportsTextureShadowLod = new(() => HasExtension("GL_EXT_texture_shadow_lod")); - private static readonly Lazy _supportsViewportSwizzle = new(() => HasExtension("GL_NV_viewport_swizzle")); - - private static readonly Lazy _maximumComputeSharedMemorySize = new(() => GetLimit(GLEnum.MaxComputeSharedMemorySize)); - private static readonly Lazy _storageBufferOffsetAlignment = new(() => GetLimit(GLEnum.ShaderStorageBufferOffsetAlignment)); - private static readonly Lazy _textureBufferOffsetAlignment = new(() => GetLimit(GLEnum.TextureBufferOffsetAlignment)); - - public enum GpuVendor - { - Unknown, - AmdWindows, - AmdUnix, - IntelWindows, - IntelUnix, - Nvidia, - } - - private static readonly Lazy _gpuVendor = new(GetGpuVendor); - - private static bool IsIntel => _gpuVendor.Value == GpuVendor.IntelWindows || _gpuVendor.Value == GpuVendor.IntelUnix; - - public static GpuVendor Vendor => _gpuVendor.Value; - - private static readonly Lazy _maxSupportedAnisotropy = new(GL.GetFloat((GetPName)GLEnum.MaxTextureMaxAnisotropy)); - - public static bool UsePersistentBufferForFlush => _gpuVendor.Value == GpuVendor.AmdWindows || _gpuVendor.Value == GpuVendor.Nvidia; - - public static bool SupportsAlphaToCoverageDitherControl => _supportsAlphaToCoverageDitherControl.Value; - public static bool SupportsAstcCompression => _supportsAstcCompression.Value; - public static bool SupportsBlendEquationAdvanced => _supportsBlendEquationAdvanced.Value; - public static bool SupportsDrawTexture => _supportsDrawTexture.Value; - public static bool SupportsFragmentShaderInterlock => _supportsFragmentShaderInterlock.Value; - public static bool SupportsFragmentShaderOrdering => _supportsFragmentShaderOrdering.Value; - public static bool SupportsGeometryShaderPassthrough => _supportsGeometryShaderPassthrough.Value; - public static bool SupportsImageLoadFormatted => _supportsImageLoadFormatted.Value; - public static bool SupportsIndirectParameters => _supportsIndirectParameters.Value; - public static bool SupportsParallelShaderCompile => _supportsParallelShaderCompile.Value; - public static bool SupportsPolygonOffsetClamp => _supportsPolygonOffsetClamp.Value; - public static bool SupportsQuads => _supportsQuads.Value; - public static bool SupportsSeamlessCubemapPerTexture => _supportsSeamlessCubemapPerTexture.Value; - public static bool SupportsShaderBallot => _supportsShaderBallot.Value; - public static bool SupportsShaderViewportLayerArray => _supportsShaderViewportLayerArray.Value; - public static bool SupportsViewportArray2 => _supportsViewportArray2.Value; - public static bool SupportsTextureCompressionBptc => _supportsTextureCompressionBptc.Value; - public static bool SupportsTextureCompressionRgtc => _supportsTextureCompressionRgtc.Value; - public static bool SupportsTextureCompressionS3tc => _supportsTextureCompressionS3tc.Value; - public static bool SupportsTextureShadowLod => _supportsTextureShadowLod.Value; - public static bool SupportsViewportSwizzle => _supportsViewportSwizzle.Value; - - public static bool SupportsMismatchingViewFormat => _gpuVendor.Value != GpuVendor.AmdWindows && _gpuVendor.Value != GpuVendor.IntelWindows; - public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia; - public static bool RequiresSyncFlush => _gpuVendor.Value == GpuVendor.AmdWindows || IsIntel; - - public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value; - public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value; - public static int TextureBufferOffsetAlignment => _textureBufferOffsetAlignment.Value; - - public static float MaximumSupportedAnisotropy => _maxSupportedAnisotropy.Value; - - private static bool HasExtension(string name) - { - int numExtensions = GL.GetInteger(GetPName.NumExtensions); - - for (int extension = 0; extension < numExtensions; extension++) - { - if (GL.GetString(StringNameIndexed.Extensions, extension) == name) - { - return true; - } - } - - return false; - } - - private static int GetLimit(GLEnum name) - { - return GL.GetInteger((GetPName)name); - } - - private static GpuVendor GetGpuVendor() - { - string vendor = GL.GetString(StringName.Vendor).ToLowerInvariant(); - - if (vendor == "nvidia corporation") - { - return GpuVendor.Nvidia; - } - else if (vendor == "intel") - { - string renderer = GL.GetString(StringName.Renderer).ToLowerInvariant(); - - return renderer.Contains("mesa") ? GpuVendor.IntelUnix : GpuVendor.IntelWindows; - } - else if (vendor == "ati technologies inc." || vendor == "advanced micro devices, inc.") - { - return GpuVendor.AmdWindows; - } - else if (vendor == "amd" || vendor == "x.org") - { - return GpuVendor.AmdUnix; - } - else - { - return GpuVendor.Unknown; - } - } - - private static bool SupportsQuadsCheck(GL api) - { - api.GetError(); // Clear any existing error. - api.Begin(PrimitiveType.Quads); - api.End(); - - return api.GetError() == ErrorCode.NoError; - } - } -} diff --git a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs index 47372deed7..74e1543b2a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs @@ -6,27 +6,27 @@ namespace Ryujinx.Graphics.OpenGL.Image class Sampler : ISampler { public uint Handle { get; private set; } - private readonly GL _api; + private readonly OpenGLRenderer _gd; - public Sampler(GL api, SamplerCreateInfo info) + public Sampler(OpenGLRenderer gd, SamplerCreateInfo info) { - _api = api; - Handle = _api.GenSampler(); + _gd = gd; + Handle = _gd.Api.GenSampler(); - _api.SamplerParameter(Handle, SamplerParameterI.MinFilter, (int)info.MinFilter.Convert()); - _api.SamplerParameter(Handle, SamplerParameterI.MagFilter, (int)info.MagFilter.Convert()); + _gd.Api.SamplerParameter(Handle, SamplerParameterI.MinFilter, (int)info.MinFilter.Convert()); + _gd.Api.SamplerParameter(Handle, SamplerParameterI.MagFilter, (int)info.MagFilter.Convert()); - if (HwCapabilities.SupportsSeamlessCubemapPerTexture) + if (_gd.Capabilities.SupportsSeamlessCubemapPerTexture) { - _api.SamplerParameter(Handle, GLEnum.TextureCubeMapSeamless, info.SeamlessCubemap ? 1 : 0); + _gd.Api.SamplerParameter(Handle, GLEnum.TextureCubeMapSeamless, info.SeamlessCubemap ? 1 : 0); } - _api.SamplerParameter(Handle, SamplerParameterI.WrapS, (int)info.AddressU.Convert()); - _api.SamplerParameter(Handle, SamplerParameterI.WrapT, (int)info.AddressV.Convert()); - _api.SamplerParameter(Handle, SamplerParameterI.WrapR, (int)info.AddressP.Convert()); + _gd.Api.SamplerParameter(Handle, SamplerParameterI.WrapS, (int)info.AddressU.Convert()); + _gd.Api.SamplerParameter(Handle, SamplerParameterI.WrapT, (int)info.AddressV.Convert()); + _gd.Api.SamplerParameter(Handle, SamplerParameterI.WrapR, (int)info.AddressP.Convert()); - _api.SamplerParameter(Handle, SamplerParameterI.CompareMode, (int)info.CompareMode.Convert()); - _api.SamplerParameter(Handle, SamplerParameterI.CompareFunc, (int)info.CompareOp.Convert()); + _gd.Api.SamplerParameter(Handle, SamplerParameterI.CompareMode, (int)info.CompareMode.Convert()); + _gd.Api.SamplerParameter(Handle, SamplerParameterI.CompareFunc, (int)info.CompareOp.Convert()); unsafe { @@ -38,26 +38,26 @@ namespace Ryujinx.Graphics.OpenGL.Image info.BorderColor.Alpha, }; - _api.SamplerParameter(Handle, SamplerParameterF.BorderColor, borderColor); + _gd.Api.SamplerParameter(Handle, SamplerParameterF.BorderColor, borderColor); } - _api.SamplerParameter(Handle, SamplerParameterF.MinLod, info.MinLod); - _api.SamplerParameter(Handle, SamplerParameterF.MaxLod, info.MaxLod); - _api.SamplerParameter(Handle, SamplerParameterF.LodBias, info.MipLodBias); + _gd.Api.SamplerParameter(Handle, SamplerParameterF.MinLod, info.MinLod); + _gd.Api.SamplerParameter(Handle, SamplerParameterF.MaxLod, info.MaxLod); + _gd.Api.SamplerParameter(Handle, SamplerParameterF.LodBias, info.MipLodBias); - _api.SamplerParameter(Handle, SamplerParameterF.MaxAnisotropy, info.MaxAnisotropy); + _gd.Api.SamplerParameter(Handle, SamplerParameterF.MaxAnisotropy, info.MaxAnisotropy); } public void Bind(uint unit) { - _api.BindSampler(unit, Handle); + _gd.Api.BindSampler(unit, Handle); } public void Dispose() { if (Handle != 0) { - _api.DeleteSampler(Handle); + _gd.Api.DeleteSampler(Handle); Handle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index c5beb9d790..5a07323375 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -238,7 +238,7 @@ namespace Ryujinx.Graphics.OpenGL.Image int copyWidth = sizeInBlocks ? BitUtils.DivRoundUp(width, blockWidth) : width; int copyHeight = sizeInBlocks ? BitUtils.DivRoundUp(height, blockHeight) : height; - if (HwCapabilities.Vendor == HwCapabilities.GpuVendor.IntelWindows) + if (_gd.Capabilities.GpuVendor == GpuVendor.IntelWindows) { _gd.Api.CopyImageSubData( src.Storage.Handle, diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index 0fd3c05682..73b759aaf3 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -273,7 +273,7 @@ namespace Ryujinx.Graphics.OpenGL.Image ReadOnlySpan data; - if (HwCapabilities.UsePersistentBufferForFlush) + if (_gd.Capabilities.UsePersistentBufferForFlush) { data = _gd.PersistentBuffers.Default.GetTextureData(this, size); } @@ -298,7 +298,7 @@ namespace Ryujinx.Graphics.OpenGL.Image { int size = Info.GetMipSize(level); - if (HwCapabilities.UsePersistentBufferForFlush) + if (_gd.Capabilities.UsePersistentBufferForFlush) { return PinnedSpan.UnsafeFromSpan(_gd.PersistentBuffers.Default.GetTextureData(this, size, layer, level)); } @@ -719,7 +719,7 @@ namespace Ryujinx.Graphics.OpenGL.Image uint baseLevel = 0; // glTexSubImage on cubemap views is broken on Intel, we have to use the storage instead. - if (Target == Target.Cubemap && HwCapabilities.Vendor == HwCapabilities.GpuVendor.IntelWindows) + if (Target == Target.Cubemap && _gd.Capabilities.GpuVendor == GpuVendor.IntelWindows) { _gd.Api.ActiveTexture(TextureUnit.Texture0); _gd.Api.BindTexture(target, Storage.Handle); diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index 00b3a439a4..ae11daa259 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -1,11 +1,11 @@ using Silk.NET.OpenGL.Legacy; +using Silk.NET.OpenGL.Legacy.Extensions.ARB; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; using Ryujinx.Graphics.OpenGL.Queries; using Ryujinx.Graphics.Shader.Translation; -using Silk.NET.OpenGL.Legacy.Extensions.ARB; using System; using System.Runtime.InteropServices; using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; @@ -41,6 +41,8 @@ namespace Ryujinx.Graphics.OpenGL internal int BufferCount { get; private set; } + internal HardwareCapabilities Capabilities; + public string GpuVendor { get; private set; } public string GpuRenderer { get; private set; } public string GpuVersion { get; private set; } @@ -50,14 +52,14 @@ namespace Ryujinx.Graphics.OpenGL public OpenGLRenderer(GL api) { Api = api; - _pipeline = new Pipeline(Api); + _pipeline = new Pipeline(this); _counters = new Counters(Api); _window = new Window(this); _textureCopy = new TextureCopy(this); _backgroundTextureCopy = new TextureCopy(this); TextureCopyIncompatible = new TextureCopyIncompatible(this); TextureCopyMS = new TextureCopyMS(this); - _sync = new Sync(Api); + _sync = new Sync(this); PersistentBuffers = new PersistentBuffers(Api); ResourcePool = new ResourcePool(); } @@ -102,12 +104,12 @@ namespace Ryujinx.Graphics.OpenGL public IProgram CreateProgram(ShaderSource[] shaders, ShaderInfo info) { - return new Program(Api, shaders, info.FragmentOutputMap); + return new Program(this, shaders, info.FragmentOutputMap); } public ISampler CreateSampler(SamplerCreateInfo info) { - return new Sampler(Api, info); + return new Sampler(this, info); } public ITexture CreateTexture(TextureCreateInfo info) @@ -146,9 +148,9 @@ namespace Ryujinx.Graphics.OpenGL public Capabilities GetCapabilities() { - bool intelWindows = HwCapabilities.Vendor == HwCapabilities.GpuVendor.IntelWindows; - bool intelUnix = HwCapabilities.Vendor == HwCapabilities.GpuVendor.IntelUnix; - bool amdWindows = HwCapabilities.Vendor == HwCapabilities.GpuVendor.AmdWindows; + bool intelWindows = Capabilities.GpuVendor == OpenGL.GpuVendor.IntelWindows; + bool intelUnix = Capabilities.GpuVendor == OpenGL.GpuVendor.IntelUnix; + bool amdWindows = Capabilities.GpuVendor == OpenGL.GpuVendor.AmdWindows; return new Capabilities( api: TargetApi.OpenGL, @@ -157,9 +159,9 @@ namespace Ryujinx.Graphics.OpenGL hasVectorIndexingBug: amdWindows, needsFragmentOutputSpecialization: false, reduceShaderPrecision: false, - supportsAstcCompression: HwCapabilities.SupportsAstcCompression, - supportsBc123Compression: HwCapabilities.SupportsTextureCompressionS3tc, - supportsBc45Compression: HwCapabilities.SupportsTextureCompressionRgtc, + supportsAstcCompression: Capabilities.SupportsAstcCompression, + supportsBc123Compression: Capabilities.SupportsTextureCompressionS3tc, + supportsBc45Compression: Capabilities.SupportsTextureCompressionRgtc, supportsBc67Compression: true, // Should check BPTC extension, but for some reason NVIDIA is not exposing the extension. supportsEtc2Compression: true, supports3DTextureCompression: false, @@ -169,39 +171,39 @@ namespace Ryujinx.Graphics.OpenGL supportsSnormBufferTextureFormat: false, supports5BitComponentFormat: true, supportsSparseBuffer: false, - supportsBlendEquationAdvanced: HwCapabilities.SupportsBlendEquationAdvanced, - supportsFragmentShaderInterlock: HwCapabilities.SupportsFragmentShaderInterlock, - supportsFragmentShaderOrderingIntel: HwCapabilities.SupportsFragmentShaderOrdering, + supportsBlendEquationAdvanced: Capabilities.SupportsBlendEquationAdvanced, + supportsFragmentShaderInterlock: Capabilities.SupportsFragmentShaderInterlock, + supportsFragmentShaderOrderingIntel: Capabilities.SupportsFragmentShaderOrdering, supportsGeometryShader: true, - supportsGeometryShaderPassthrough: HwCapabilities.SupportsGeometryShaderPassthrough, + supportsGeometryShaderPassthrough: Capabilities.SupportsGeometryShaderPassthrough, supportsTransformFeedback: true, - supportsImageLoadFormatted: HwCapabilities.SupportsImageLoadFormatted, - supportsLayerVertexTessellation: HwCapabilities.SupportsShaderViewportLayerArray, - supportsMismatchingViewFormat: HwCapabilities.SupportsMismatchingViewFormat, + supportsImageLoadFormatted: Capabilities.SupportsImageLoadFormatted, + supportsLayerVertexTessellation: Capabilities.SupportsShaderViewportLayerArray, + supportsMismatchingViewFormat: Capabilities.SupportsMismatchingViewFormat, supportsCubemapView: true, - supportsNonConstantTextureOffset: HwCapabilities.SupportsNonConstantTextureOffset, + supportsNonConstantTextureOffset: Capabilities.SupportsNonConstantTextureOffset, supportsScaledVertexFormats: true, supportsSeparateSampler: false, - supportsShaderBallot: HwCapabilities.SupportsShaderBallot, + supportsShaderBallot: Capabilities.SupportsShaderBallot, supportsShaderBarrierDivergence: !(intelWindows || intelUnix), supportsShaderFloat64: true, supportsTextureGatherOffsets: true, - supportsTextureShadowLod: HwCapabilities.SupportsTextureShadowLod, + supportsTextureShadowLod: Capabilities.SupportsTextureShadowLod, supportsVertexStoreAndAtomics: true, - supportsViewportIndexVertexTessellation: HwCapabilities.SupportsShaderViewportLayerArray, - supportsViewportMask: HwCapabilities.SupportsViewportArray2, - supportsViewportSwizzle: HwCapabilities.SupportsViewportSwizzle, - supportsIndirectParameters: HwCapabilities.SupportsIndirectParameters, + supportsViewportIndexVertexTessellation: Capabilities.SupportsShaderViewportLayerArray, + supportsViewportMask: Capabilities.SupportsViewportArray2, + supportsViewportSwizzle: Capabilities.SupportsViewportSwizzle, + supportsIndirectParameters: Capabilities.SupportsIndirectParameters, supportsDepthClipControl: true, maximumUniformBuffersPerStage: 13, // TODO: Avoid hardcoding those limits here and get from driver? maximumStorageBuffersPerStage: 16, maximumTexturesPerStage: 32, maximumImagesPerStage: 8, - maximumComputeSharedMemorySize: HwCapabilities.MaximumComputeSharedMemorySize, - maximumSupportedAnisotropy: HwCapabilities.MaximumSupportedAnisotropy, + maximumComputeSharedMemorySize: Capabilities.MaximumComputeSharedMemorySize, + maximumSupportedAnisotropy: Capabilities.MaximumSupportedAnisotropy, shaderSubgroupSize: Constants.MaxSubgroupSize, - storageBufferOffsetAlignment: HwCapabilities.StorageBufferOffsetAlignment, - textureBufferOffsetAlignment: HwCapabilities.TextureBufferOffsetAlignment, + storageBufferOffsetAlignment: Capabilities.StorageBufferOffsetAlignment, + textureBufferOffsetAlignment: Capabilities.TextureBufferOffsetAlignment, gatherBiasPrecision: intelWindows || amdWindows ? 8 : 0); // Precision is 8 for these vendors on Vulkan. } @@ -230,9 +232,11 @@ namespace Ryujinx.Graphics.OpenGL { Debugger.Initialize(Api, glLogLevel); + LoadFeatures(); + PrintGpuInformation(); - if (HwCapabilities.SupportsParallelShaderCompile) + if (Capabilities.SupportsParallelShaderCompile) { Api.TryGetExtension(out ArbParallelShaderCompile arbParallelShaderCompile); @@ -244,10 +248,41 @@ namespace Ryujinx.Graphics.OpenGL // This is required to disable [0, 1] clamping for SNorm outputs on compatibility profiles. // This call is expected to fail if we're running with a core profile, // as this clamp target was deprecated, but that's fine as a core profile - // should already have the desired behaviour were outputs are not clamped. + // should already have the desired behaviour when outputs are not clamped. Api.ClampColor(ClampColorTargetARB.FragmentColorArb, ClampColorModeARB.False); } + private void LoadFeatures() + { + Capabilities = new HardwareCapabilities( + HardwareCapabilities.HasExtension(Api, "GL_NV_alpha_to_coverage_dither_control"), + HardwareCapabilities.HasExtension(Api, "GL_KHR_texture_compression_astc_ldr"), + HardwareCapabilities.HasExtension(Api, "GL_NV_blend_equation_advanced"), + HardwareCapabilities.HasExtension(Api, "GL_NV_draw_texture"), + HardwareCapabilities.HasExtension(Api, "GL_ARB_fragment_shader_interlock"), + HardwareCapabilities.HasExtension(Api, "GL_INTEL_fragment_shader_ordering"), + HardwareCapabilities.HasExtension(Api, "GL_NV_geometry_shader_passthrough"), + HardwareCapabilities.HasExtension(Api, "GL_EXT_shader_image_load_formatted"), + HardwareCapabilities.HasExtension(Api, "GL_ARB_indirect_parameters"), + HardwareCapabilities.HasExtension(Api, "GL_ARB_parallel_shader_compile"), + HardwareCapabilities.HasExtension(Api, "GL_EXT_polygon_offset_clamp"), + HardwareCapabilities.SupportsQuadsCheck(Api), + HardwareCapabilities.HasExtension(Api, "GL_ARB_seamless_cubemap_per_texture"), + HardwareCapabilities.HasExtension(Api, "GL_ARB_shader_ballot"), + HardwareCapabilities.HasExtension(Api, "GL_ARB_shader_viewport_layer_array"), + HardwareCapabilities.HasExtension(Api, "GL_NV_viewport_array2"), + HardwareCapabilities.HasExtension(Api, "GL_EXT_texture_compression_bptc"), + HardwareCapabilities.HasExtension(Api, "GL_EXT_texture_compression_rgtc"), + HardwareCapabilities.HasExtension(Api, "GL_EXT_texture_compression_s3tc"), + HardwareCapabilities.HasExtension(Api, "GL_EXT_texture_shadow_lod"), + HardwareCapabilities.HasExtension(Api, "GL_NV_viewport_swizzle"), + Api.GetInteger(GLEnum.MaxComputeSharedMemorySize), + Api.GetInteger(GLEnum.ShaderStorageBufferOffsetAlignment), + Api.GetInteger(GLEnum.TextureBufferOffsetAlignment), + Api.GetFloat(GLEnum.MaxTextureMaxAnisotropy), + HardwareCapabilities.GetGpuVendor(Api)); + } + private unsafe void PrintGpuInformation() { GpuVendor = Marshal.PtrToStringAnsi((IntPtr)Api.GetString(StringName.Vendor)); @@ -296,7 +331,7 @@ namespace Ryujinx.Graphics.OpenGL public IProgram LoadProgramBinary(byte[] programBinary, bool hasFragmentShader, ShaderInfo info) { - return new Program(Api, programBinary, hasFragmentShader, info.FragmentOutputMap); + return new Program(this, programBinary, hasFragmentShader, info.FragmentOutputMap); } public void CreateSync(ulong id, bool strict) diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 7a49f2c9f0..4b3316fa51 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -70,11 +70,12 @@ namespace Ryujinx.Graphics.OpenGL private ColorF _blendConstant; - private readonly GL _api; + private readonly OpenGLRenderer _gd; - internal Pipeline(GL api) + internal Pipeline(OpenGLRenderer gd) { - _api = api; + _gd = gd; + _drawTexture = new DrawTextureEmulation(); _rasterizerDiscard = false; _clipOrigin = ClipControlOrigin.LowerLeft; @@ -91,25 +92,25 @@ namespace Ryujinx.Graphics.OpenGL public void Barrier() { - _api.MemoryBarrier(MemoryBarrierMask.AllBarrierBits); + _gd.Api.MemoryBarrier(MemoryBarrierMask.AllBarrierBits); } public void BeginTransformFeedback(PrimitiveTopology topology) { - _api.BeginTransformFeedback(_tfTopology = topology.ConvertToTfType()); + _gd.Api.BeginTransformFeedback(_tfTopology = topology.ConvertToTfType()); _tfEnabled = true; } public void ClearBuffer(BufferHandle destination, int offset, int size, uint value) { - Buffer.Clear(_api, destination, offset, (uint)size, value); + Buffer.Clear(_gd.Api, destination, offset, (uint)size, value); } public void ClearRenderTargetColor(int index, int layer, int layerCount, uint componentMask, ColorF color) { EnsureFramebuffer(); - _api.ColorMask( + _gd.Api.ColorMask( (uint)index, (componentMask & 1) != 0, (componentMask & 2) != 0, @@ -124,14 +125,14 @@ namespace Ryujinx.Graphics.OpenGL { _framebuffer.AttachColorLayerForClear(index, l); - _api.ClearBuffer(BufferKind.Color, index, colors); + _gd.Api.ClearBuffer(BufferKind.Color, index, colors); } _framebuffer.DetachColorLayerForClear(index); } else { - _api.ClearBuffer(BufferKind.Color, index, colors); + _gd.Api.ClearBuffer(BufferKind.Color, index, colors); } RestoreComponentMask(index); @@ -149,12 +150,12 @@ namespace Ryujinx.Graphics.OpenGL if (stencilMaskChanged) { - _api.StencilMaskSeparate(TriangleFace.Front, (uint)stencilMask); + _gd.Api.StencilMaskSeparate(TriangleFace.Front, (uint)stencilMask); } if (depthMaskChanged) { - _api.DepthMask(depthMask); + _gd.Api.DepthMask(depthMask); } if (layer != 0 || layerCount != _framebuffer.GetDepthStencilLayerCount()) @@ -175,12 +176,12 @@ namespace Ryujinx.Graphics.OpenGL if (stencilMaskChanged) { - _api.StencilMaskSeparate(TriangleFace.Front, (uint)_stencilFrontMask); + _gd.Api.StencilMaskSeparate(TriangleFace.Front, (uint)_stencilFrontMask); } if (depthMaskChanged) { - _api.DepthMask(_depthMask); + _gd.Api.DepthMask(_depthMask); } } @@ -188,26 +189,26 @@ namespace Ryujinx.Graphics.OpenGL { if (depthMask && stencilMask != 0) { - _api.ClearBuffer(GLEnum.DepthStencil, 0, depthValue, stencilValue); + _gd.Api.ClearBuffer(GLEnum.DepthStencil, 0, depthValue, stencilValue); } else if (depthMask) { - _api.ClearBuffer(BufferKind.Depth, 0, ref depthValue); + _gd.Api.ClearBuffer(BufferKind.Depth, 0, ref depthValue); } else if (stencilMask != 0) { - _api.ClearBuffer(BufferKind.Stencil, 0, ref stencilValue); + _gd.Api.ClearBuffer(BufferKind.Stencil, 0, ref stencilValue); } } public void CommandBufferBarrier() { - _api.MemoryBarrier(MemoryBarrierMask.CommandBarrierBit); + _gd.Api.MemoryBarrier(MemoryBarrierMask.CommandBarrierBit); } public void CopyBuffer(BufferHandle source, BufferHandle destination, int srcOffset, int dstOffset, int size) { - Buffer.Copy(_api, source, destination, srcOffset, dstOffset, size); + Buffer.Copy(_gd.Api, source, destination, srcOffset, dstOffset, size); } public void DispatchCompute(int groupsX, int groupsY, int groupsZ) @@ -220,7 +221,7 @@ namespace Ryujinx.Graphics.OpenGL PrepareForDispatch(); - _api.DispatchCompute((uint)groupsX, (uint)groupsY, (uint)groupsZ); + _gd.Api.DispatchCompute((uint)groupsX, (uint)groupsY, (uint)groupsZ); } public void Draw(int vertexCount, int instanceCount, int firstVertex, int firstInstance) @@ -233,11 +234,11 @@ namespace Ryujinx.Graphics.OpenGL PreDraw(vertexCount); - if (_primitiveType == PrimitiveType.Quads && !HwCapabilities.SupportsQuads) + if (_primitiveType == PrimitiveType.Quads && !_gd.Capabilities.SupportsQuads) { DrawQuadsImpl(vertexCount, instanceCount, firstVertex, firstInstance); } - else if (_primitiveType == PrimitiveType.QuadStrip && !HwCapabilities.SupportsQuads) + else if (_primitiveType == PrimitiveType.QuadStrip && !_gd.Capabilities.SupportsQuads) { DrawQuadStripImpl(vertexCount, instanceCount, firstVertex, firstInstance); } @@ -267,7 +268,7 @@ namespace Ryujinx.Graphics.OpenGL counts[quadIndex] = 4; } - _api.MultiDrawArrays( + _gd.Api.MultiDrawArrays( PrimitiveType.TriangleFan, firsts, counts, @@ -286,7 +287,7 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - _api.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, (uint)instanceCount, (uint)firstInstance); + _gd.Api.DrawArraysInstancedBaseInstance(PrimitiveType.TriangleFan, firstVertex + quadIndex * 2, 4, (uint)instanceCount, (uint)firstInstance); } } else @@ -303,7 +304,7 @@ namespace Ryujinx.Graphics.OpenGL counts[quadIndex] = 4; } - _api.MultiDrawArrays( + _gd.Api.MultiDrawArrays( PrimitiveType.TriangleFan, firsts, counts, @@ -319,15 +320,15 @@ namespace Ryujinx.Graphics.OpenGL { if (firstInstance == 0 && instanceCount == 1) { - _api.DrawArrays(_primitiveType, firstVertex, (uint)vertexCount); + _gd.Api.DrawArrays(_primitiveType, firstVertex, (uint)vertexCount); } else if (firstInstance == 0) { - _api.DrawArraysInstanced(_primitiveType, firstVertex, (uint)vertexCount, (uint)instanceCount); + _gd.Api.DrawArraysInstanced(_primitiveType, firstVertex, (uint)vertexCount, (uint)instanceCount); } else { - _api.DrawArraysInstancedBaseInstance( + _gd.Api.DrawArraysInstancedBaseInstance( _primitiveType, firstVertex, (uint)vertexCount, @@ -365,7 +366,7 @@ namespace Ryujinx.Graphics.OpenGL IntPtr indexBaseOffset = _indexBaseOffset + firstIndex * indexElemSize; - if (_primitiveType == PrimitiveType.Quads && !HwCapabilities.SupportsQuads) + if (_primitiveType == PrimitiveType.Quads && !_gd.Capabilities.SupportsQuads) { DrawQuadsIndexedImpl( indexCount, @@ -375,7 +376,7 @@ namespace Ryujinx.Graphics.OpenGL firstVertex, firstInstance); } - else if (_primitiveType == PrimitiveType.QuadStrip && !HwCapabilities.SupportsQuads) + else if (_primitiveType == PrimitiveType.QuadStrip && !_gd.Capabilities.SupportsQuads) { DrawQuadStripIndexedImpl( indexCount, @@ -414,7 +415,7 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - _api.DrawElementsInstancedBaseVertexBaseInstance( + _gd.Api.DrawElementsInstancedBaseVertexBaseInstance( PrimitiveType.TriangleFan, 4, _elementsType, @@ -428,7 +429,7 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - _api.DrawElementsInstancedBaseInstance( + _gd.Api.DrawElementsInstancedBaseInstance( PrimitiveType.TriangleFan, 4, _elementsType, @@ -441,7 +442,7 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - _api.DrawElementsInstanced( + _gd.Api.DrawElementsInstanced( PrimitiveType.TriangleFan, 4, _elementsType, @@ -471,7 +472,7 @@ namespace Ryujinx.Graphics.OpenGL fixed (void* indicesPtr = indices) fixed (int* baseVerticesPtr = baseVertices) { - _api.MultiDrawElementsBaseVertex( + _gd.Api.MultiDrawElementsBaseVertex( PrimitiveType.TriangleFan, countsPtr, _elementsType, @@ -518,7 +519,7 @@ namespace Ryujinx.Graphics.OpenGL fixed (void* indicesPtr = indices) fixed (int* baseVerticesPtr = baseVertices) { - _api.MultiDrawElementsBaseVertex( + _gd.Api.MultiDrawElementsBaseVertex( PrimitiveType.TriangleFan, countsPtr, _elementsType, @@ -537,11 +538,11 @@ namespace Ryujinx.Graphics.OpenGL { if (firstInstance == 0 && firstVertex == 0 && instanceCount == 1) { - _api.DrawElements(_primitiveType, (uint)indexCount, _elementsType, indexBaseOffset); + _gd.Api.DrawElements(_primitiveType, (uint)indexCount, _elementsType, indexBaseOffset); } else if (firstInstance == 0 && instanceCount == 1) { - _api.DrawElementsBaseVertex( + _gd.Api.DrawElementsBaseVertex( _primitiveType, (uint)indexCount, _elementsType, @@ -550,7 +551,7 @@ namespace Ryujinx.Graphics.OpenGL } else if (firstInstance == 0 && firstVertex == 0) { - _api.DrawElementsInstanced( + _gd.Api.DrawElementsInstanced( _primitiveType, (uint)indexCount, _elementsType, @@ -559,7 +560,7 @@ namespace Ryujinx.Graphics.OpenGL } else if (firstInstance == 0) { - _api.DrawElementsInstancedBaseVertex( + _gd.Api.DrawElementsInstancedBaseVertex( _primitiveType, (uint)indexCount, _elementsType, @@ -569,7 +570,7 @@ namespace Ryujinx.Graphics.OpenGL } else if (firstVertex == 0) { - _api.DrawElementsInstancedBaseInstance( + _gd.Api.DrawElementsInstancedBaseInstance( _primitiveType, (uint)indexCount, _elementsType, @@ -579,7 +580,7 @@ namespace Ryujinx.Graphics.OpenGL } else { - _api.DrawElementsInstancedBaseVertexBaseInstance( + _gd.Api.DrawElementsInstancedBaseVertexBaseInstance( _primitiveType, (uint)indexCount, _elementsType, @@ -602,9 +603,9 @@ namespace Ryujinx.Graphics.OpenGL _vertexArray.SetRangeOfIndexBuffer(); - _api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); + _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - _api.DrawElementsIndirect(_primitiveType, _elementsType, (IntPtr)indirectBuffer.Offset); + _gd.Api.DrawElementsIndirect(_primitiveType, _elementsType, (IntPtr)indirectBuffer.Offset); _vertexArray.RestoreIndexBuffer(); @@ -623,10 +624,10 @@ namespace Ryujinx.Graphics.OpenGL _vertexArray.SetRangeOfIndexBuffer(); - _api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - _api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); + _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); + _gd.Api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); - _api.MultiDrawElementsIndirectCount( + _gd.Api.MultiDrawElementsIndirectCount( _primitiveType, _elementsType, (IntPtr)indirectBuffer.Offset, @@ -649,9 +650,9 @@ namespace Ryujinx.Graphics.OpenGL PreDrawVbUnbounded(); - _api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); + _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - _api.DrawArraysIndirect(_primitiveType, (IntPtr)indirectBuffer.Offset); + _gd.Api.DrawArraysIndirect(_primitiveType, (IntPtr)indirectBuffer.Offset); PostDraw(); } @@ -666,10 +667,10 @@ namespace Ryujinx.Graphics.OpenGL PreDrawVbUnbounded(); - _api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - _api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); + _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); + _gd.Api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); - _api.MultiDrawArraysIndirectCount( + _gd.Api.MultiDrawArraysIndirectCount( _primitiveType, (IntPtr)indirectBuffer.Offset, parameterBuffer.Offset, @@ -683,9 +684,9 @@ namespace Ryujinx.Graphics.OpenGL { if (texture is TextureView view && sampler is Sampler samp) { - if (HwCapabilities.SupportsDrawTexture) + if (_gd.Capabilities.SupportsDrawTexture) { - _api.TryGetExtension(out NVDrawTexture drawTexture); + _gd.Api.TryGetExtension(out NVDrawTexture drawTexture); drawTexture.DrawTexture( view.Handle, @@ -718,24 +719,24 @@ namespace Ryujinx.Graphics.OpenGL } } - Disable(_api, EnableCap.CullFace, _cullEnable); - Disable(_api, EnableCap.StencilTest, _stencilTestEnable); - Disable(_api, EnableCap.DepthTest, _depthTestEnable); + Disable(_gd.Api, EnableCap.CullFace, _cullEnable); + Disable(_gd.Api, EnableCap.StencilTest, _stencilTestEnable); + Disable(_gd.Api, EnableCap.DepthTest, _depthTestEnable); if (_depthMask) { - _api.DepthMask(false); + _gd.Api.DepthMask(false); } if (_tfEnabled) { - _api.EndTransformFeedback(); + _gd.Api.EndTransformFeedback(); } - _api.ClipControl(ClipControlOrigin.UpperLeft, ClipControlDepth.NegativeOneToOne); + _gd.Api.ClipControl(ClipControlOrigin.UpperLeft, ClipControlDepth.NegativeOneToOne); _drawTexture.Draw( - _api, + _gd.Api, view, samp, dstRegion.X1, @@ -752,18 +753,18 @@ namespace Ryujinx.Graphics.OpenGL RestoreViewport0(); - Enable(_api, EnableCap.CullFace, _cullEnable); - Enable(_api, EnableCap.StencilTest, _stencilTestEnable); - Enable(_api, EnableCap.DepthTest, _depthTestEnable); + Enable(_gd.Api, EnableCap.CullFace, _cullEnable); + Enable(_gd.Api, EnableCap.StencilTest, _stencilTestEnable); + Enable(_gd.Api, EnableCap.DepthTest, _depthTestEnable); if (_depthMask) { - _api.DepthMask(true); + _gd.Api.DepthMask(true); } if (_tfEnabled) { - _api.BeginTransformFeedback(_tfTopology); + _gd.Api.BeginTransformFeedback(_tfTopology); } RestoreClipControl(); @@ -773,7 +774,7 @@ namespace Ryujinx.Graphics.OpenGL public void EndTransformFeedback() { - _api.EndTransformFeedback(); + _gd.Api.EndTransformFeedback(); _tfEnabled = false; } @@ -781,24 +782,24 @@ namespace Ryujinx.Graphics.OpenGL { if (!enable) { - _api.Disable(EnableCap.AlphaTest); + _gd.Api.Disable(EnableCap.AlphaTest); return; } - _api.AlphaFunc((AlphaFunction)op.Convert(), reference); - _api.Enable(EnableCap.AlphaTest); + _gd.Api.AlphaFunc((AlphaFunction)op.Convert(), reference); + _gd.Api.Enable(EnableCap.AlphaTest); } public void SetBlendState(AdvancedBlendDescriptor blend) { - if (HwCapabilities.SupportsBlendEquationAdvanced) + if (_gd.Capabilities.SupportsBlendEquationAdvanced) { - _api.BlendEquation((GLEnum)blend.Op.Convert()); + _gd.Api.BlendEquation((GLEnum)blend.Op.Convert()); - _api.TryGetExtension(out NVBlendEquationAdvanced nvBlendEquationAdvanced); + _gd.Api.TryGetExtension(out NVBlendEquationAdvanced nvBlendEquationAdvanced); nvBlendEquationAdvanced.BlendParameter(NV.BlendOverlapNV, (int)blend.Overlap.Convert()); nvBlendEquationAdvanced.BlendParameter(NV.BlendPremultipliedSrcNV, blend.SrcPreMultiplied ? 1 : 0); - _api.Enable(EnableCap.Blend); + _gd.Api.Enable(EnableCap.Blend); _advancedBlendEnable = true; } } @@ -807,22 +808,22 @@ namespace Ryujinx.Graphics.OpenGL { if (_advancedBlendEnable) { - _api.Disable(EnableCap.Blend); + _gd.Api.Disable(EnableCap.Blend); _advancedBlendEnable = false; } if (!blend.Enable) { - _api.Disable(EnableCap.Blend, (uint)index); + _gd.Api.Disable(EnableCap.Blend, (uint)index); return; } - _api.BlendEquationSeparate( + _gd.Api.BlendEquationSeparate( (uint)index, blend.ColorOp.Convert(), blend.AlphaOp.Convert()); - _api.BlendFuncSeparate( + _gd.Api.BlendFuncSeparate( (uint)index, (BlendingFactor)blend.ColorSrcFactor.Convert(), (BlendingFactor)blend.ColorDstFactor.Convert(), @@ -841,43 +842,43 @@ namespace Ryujinx.Graphics.OpenGL { _blendConstant = blend.BlendConstant; - _api.BlendColor( + _gd.Api.BlendColor( blend.BlendConstant.Red, blend.BlendConstant.Green, blend.BlendConstant.Blue, blend.BlendConstant.Alpha); } - _api.Enable(EnableCap.Blend, (uint)index); + _gd.Api.Enable(EnableCap.Blend, (uint)index); } public void SetDepthBias(PolygonModeMask enables, float factor, float units, float clamp) { if ((enables & PolygonModeMask.Point) != 0) { - _api.Enable(EnableCap.PolygonOffsetPoint); + _gd.Api.Enable(EnableCap.PolygonOffsetPoint); } else { - _api.Disable(EnableCap.PolygonOffsetPoint); + _gd.Api.Disable(EnableCap.PolygonOffsetPoint); } if ((enables & PolygonModeMask.Line) != 0) { - _api.Enable(EnableCap.PolygonOffsetLine); + _gd.Api.Enable(EnableCap.PolygonOffsetLine); } else { - _api.Disable(EnableCap.PolygonOffsetLine); + _gd.Api.Disable(EnableCap.PolygonOffsetLine); } if ((enables & PolygonModeMask.Fill) != 0) { - _api.Enable(EnableCap.PolygonOffsetFill); + _gd.Api.Enable(EnableCap.PolygonOffsetFill); } else { - _api.Disable(EnableCap.PolygonOffsetFill); + _gd.Api.Disable(EnableCap.PolygonOffsetFill); } if (enables == 0) @@ -885,13 +886,13 @@ namespace Ryujinx.Graphics.OpenGL return; } - if (HwCapabilities.SupportsPolygonOffsetClamp) + if (_gd.Capabilities.SupportsPolygonOffsetClamp) { - _api.PolygonOffsetClamp(factor, units, clamp); + _gd.Api.PolygonOffsetClamp(factor, units, clamp); } else { - _api.PolygonOffset(factor, units); + _gd.Api.PolygonOffset(factor, units); } } @@ -899,11 +900,11 @@ namespace Ryujinx.Graphics.OpenGL { if (!clamp) { - _api.Disable(EnableCap.DepthClamp); + _gd.Api.Disable(EnableCap.DepthClamp); return; } - _api.Enable(EnableCap.DepthClamp); + _gd.Api.Enable(EnableCap.DepthClamp); } public void SetDepthMode(DepthMode mode) @@ -914,7 +915,7 @@ namespace Ryujinx.Graphics.OpenGL { _clipDepthMode = depthMode; - _api.ClipControl(_clipOrigin, depthMode); + _gd.Api.ClipControl(_clipOrigin, depthMode); } } @@ -922,15 +923,15 @@ namespace Ryujinx.Graphics.OpenGL { if (depthTest.TestEnable) { - _api.Enable(EnableCap.DepthTest); - _api.DepthFunc((DepthFunction)depthTest.Func.Convert()); + _gd.Api.Enable(EnableCap.DepthTest); + _gd.Api.DepthFunc((DepthFunction)depthTest.Func.Convert()); } else { - _api.Disable(EnableCap.DepthTest); + _gd.Api.Disable(EnableCap.DepthTest); } - _api.DepthMask(depthTest.WriteEnable); + _gd.Api.DepthMask(depthTest.WriteEnable); _depthMask = depthTest.WriteEnable; _depthTestEnable = depthTest.TestEnable; } @@ -941,13 +942,13 @@ namespace Ryujinx.Graphics.OpenGL if (!enable) { - _api.Disable(EnableCap.CullFace); + _gd.Api.Disable(EnableCap.CullFace); return; } - _api.CullFace(face.Convert()); + _gd.Api.CullFace(face.Convert()); - _api.Enable(EnableCap.CullFace); + _gd.Api.Enable(EnableCap.CullFace); } public void SetFrontFace(FrontFace frontFace) @@ -964,7 +965,7 @@ namespace Ryujinx.Graphics.OpenGL if (texture == null) { - _api.BindImageTexture((uint)binding, 0, 0, true, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); + _gd.Api.BindImageTexture((uint)binding, 0, 0, true, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); return; } @@ -974,7 +975,7 @@ namespace Ryujinx.Graphics.OpenGL if (format != 0) { - _api.BindImageTexture((uint)binding, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); + _gd.Api.BindImageTexture((uint)binding, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); } } @@ -998,13 +999,13 @@ namespace Ryujinx.Graphics.OpenGL { if (enable) { - _api.Enable(EnableCap.ColorLogicOp); + _gd.Api.Enable(EnableCap.ColorLogicOp); - _api.LogicOp((LogicOp)op.Convert()); + _gd.Api.LogicOp((LogicOp)op.Convert()); } else { - _api.Disable(EnableCap.ColorLogicOp); + _gd.Api.Disable(EnableCap.ColorLogicOp); } } @@ -1012,20 +1013,20 @@ namespace Ryujinx.Graphics.OpenGL { if (multisample.AlphaToCoverageEnable) { - _api.Enable(EnableCap.SampleAlphaToCoverage); + _gd.Api.Enable(EnableCap.SampleAlphaToCoverage); if (multisample.AlphaToOneEnable) { - _api.Enable(EnableCap.SampleAlphaToOne); + _gd.Api.Enable(EnableCap.SampleAlphaToOne); } else { - _api.Disable(EnableCap.SampleAlphaToOne); + _gd.Api.Disable(EnableCap.SampleAlphaToOne); } - if (HwCapabilities.SupportsAlphaToCoverageDitherControl) + if (_gd.Capabilities.SupportsAlphaToCoverageDitherControl) { - _api.TryGetExtension(out NVAlphaToCoverageDitherControl nvAlphaToCoverageDitherControl); + _gd.Api.TryGetExtension(out NVAlphaToCoverageDitherControl nvAlphaToCoverageDitherControl); nvAlphaToCoverageDitherControl.AlphaToCoverageDitherControl(multisample.AlphaToCoverageDitherEnable ? NV.AlphaToCoverageDitherEnableNV @@ -1034,7 +1035,7 @@ namespace Ryujinx.Graphics.OpenGL } else { - _api.Disable(EnableCap.SampleAlphaToCoverage); + _gd.Api.Disable(EnableCap.SampleAlphaToCoverage); } } @@ -1042,28 +1043,28 @@ namespace Ryujinx.Graphics.OpenGL { if (smooth) { - _api.Enable(EnableCap.LineSmooth); + _gd.Api.Enable(EnableCap.LineSmooth); } else { - _api.Disable(EnableCap.LineSmooth); + _gd.Api.Disable(EnableCap.LineSmooth); } - _api.LineWidth(width); + _gd.Api.LineWidth(width); } public unsafe void SetPatchParameters(int vertices, ReadOnlySpan defaultOuterLevel, ReadOnlySpan defaultInnerLevel) { - _api.PatchParameter(PatchParameterName.Vertices, vertices); + _gd.Api.PatchParameter(PatchParameterName.Vertices, vertices); fixed (float* pOuterLevel = defaultOuterLevel) { - _api.PatchParameter(PatchParameterName.DefaultOuterLevel, pOuterLevel); + _gd.Api.PatchParameter(PatchParameterName.DefaultOuterLevel, pOuterLevel); } fixed (float* pInnerLevel = defaultInnerLevel) { - _api.PatchParameter(PatchParameterName.DefaultInnerLevel, pInnerLevel); + _gd.Api.PatchParameter(PatchParameterName.DefaultInnerLevel, pInnerLevel); } } @@ -1073,41 +1074,41 @@ namespace Ryujinx.Graphics.OpenGL // As we don't know if the current context is core or compat, it's safer to keep this code. if (enablePointSprite) { - _api.Enable(GLEnum.PointSprite); + _gd.Api.Enable(GLEnum.PointSprite); } else { - _api.Disable(GLEnum.PointSprite); + _gd.Api.Disable(GLEnum.PointSprite); } if (isProgramPointSize) { - _api.Enable(EnableCap.ProgramPointSize); + _gd.Api.Enable(EnableCap.ProgramPointSize); } else { - _api.Disable(EnableCap.ProgramPointSize); + _gd.Api.Disable(EnableCap.ProgramPointSize); } - _api.PointParameter(GLEnum.PointSpriteCoordOrigin, (int)(origin == Origin.LowerLeft + _gd.Api.PointParameter(GLEnum.PointSpriteCoordOrigin, (int)(origin == Origin.LowerLeft ? GLEnum.LowerLeft : GLEnum.UpperLeft)); // Games seem to set point size to 0 which generates a GL_INVALID_VALUE // From the spec, GL_INVALID_VALUE is generated if size is less than or equal to 0. - _api.PointSize(Math.Max(float.Epsilon, size)); + _gd.Api.PointSize(Math.Max(float.Epsilon, size)); } public void SetPolygonMode(GAL.PolygonMode frontMode, GAL.PolygonMode backMode) { if (frontMode == backMode) { - _api.PolygonMode(TriangleFace.FrontAndBack, frontMode.Convert()); + _gd.Api.PolygonMode(TriangleFace.FrontAndBack, frontMode.Convert()); } else { - _api.PolygonMode(TriangleFace.Front, frontMode.Convert()); - _api.PolygonMode(TriangleFace.Back, backMode.Convert()); + _gd.Api.PolygonMode(TriangleFace.Front, frontMode.Convert()); + _gd.Api.PolygonMode(TriangleFace.Back, backMode.Convert()); } } @@ -1115,13 +1116,13 @@ namespace Ryujinx.Graphics.OpenGL { if (!enable) { - _api.Disable(EnableCap.PrimitiveRestart); + _gd.Api.Disable(EnableCap.PrimitiveRestart); return; } - _api.PrimitiveRestartIndex((uint)index); + _gd.Api.PrimitiveRestartIndex((uint)index); - _api.Enable(EnableCap.PrimitiveRestart); + _gd.Api.Enable(EnableCap.PrimitiveRestart); } public void SetPrimitiveTopology(PrimitiveTopology topology) @@ -1135,9 +1136,9 @@ namespace Ryujinx.Graphics.OpenGL if (_tfEnabled) { - _api.EndTransformFeedback(); + _gd.Api.EndTransformFeedback(); prg.Bind(); - _api.BeginTransformFeedback(_tfTopology); + _gd.Api.BeginTransformFeedback(_tfTopology); } else { @@ -1161,11 +1162,11 @@ namespace Ryujinx.Graphics.OpenGL { if (discard) { - _api.Enable(EnableCap.RasterizerDiscard); + _gd.Api.Enable(EnableCap.RasterizerDiscard); } else { - _api.Disable(EnableCap.RasterizerDiscard); + _gd.Api.Disable(EnableCap.RasterizerDiscard); } _rasterizerDiscard = discard; @@ -1237,7 +1238,7 @@ namespace Ryujinx.Graphics.OpenGL if ((_scissorEnables & mask) == 0) { _scissorEnables |= mask; - _api.Enable(EnableCap.ScissorTest, (uint)index); + _gd.Api.Enable(EnableCap.ScissorTest, (uint)index); } } else @@ -1245,12 +1246,12 @@ namespace Ryujinx.Graphics.OpenGL if ((_scissorEnables & mask) != 0) { _scissorEnables &= ~mask; - _api.Disable(EnableCap.ScissorTest, (uint)index); + _gd.Api.Disable(EnableCap.ScissorTest, (uint)index); } } } - _api.ScissorArray(0, (uint)count, ref v[0]); + _gd.Api.ScissorArray(0, (uint)count, ref v[0]); } public void SetStencilTest(StencilTestDescriptor stencilTest) @@ -1259,39 +1260,39 @@ namespace Ryujinx.Graphics.OpenGL if (!stencilTest.TestEnable) { - _api.Disable(EnableCap.StencilTest); + _gd.Api.Disable(EnableCap.StencilTest); return; } - _api.StencilOpSeparate( + _gd.Api.StencilOpSeparate( TriangleFace.Front, stencilTest.FrontSFail.Convert(), stencilTest.FrontDpFail.Convert(), stencilTest.FrontDpPass.Convert()); - _api.StencilFuncSeparate( + _gd.Api.StencilFuncSeparate( TriangleFace.Front, (StencilFunction)stencilTest.FrontFunc.Convert(), stencilTest.FrontFuncRef, (uint)stencilTest.FrontFuncMask); - _api.StencilMaskSeparate(TriangleFace.Front, (uint)stencilTest.FrontMask); + _gd.Api.StencilMaskSeparate(TriangleFace.Front, (uint)stencilTest.FrontMask); - _api.StencilOpSeparate( + _gd.Api.StencilOpSeparate( TriangleFace.Back, stencilTest.BackSFail.Convert(), stencilTest.BackDpFail.Convert(), stencilTest.BackDpPass.Convert()); - _api.StencilFuncSeparate( + _gd.Api.StencilFuncSeparate( TriangleFace.Back, (StencilFunction)stencilTest.BackFunc.Convert(), stencilTest.BackFuncRef, (uint)stencilTest.BackFuncMask); - _api.StencilMaskSeparate(TriangleFace.Back, (uint)stencilTest.BackMask); + _gd.Api.StencilMaskSeparate(TriangleFace.Back, (uint)stencilTest.BackMask); - _api.Enable(EnableCap.StencilTest); + _gd.Api.Enable(EnableCap.StencilTest); _stencilFrontMask = stencilTest.FrontMask; } @@ -1316,7 +1317,7 @@ namespace Ryujinx.Graphics.OpenGL } else { - TextureBase.ClearBinding(_api, (uint)binding); + TextureBase.ClearBinding(_gd.Api, (uint)binding); } Sampler glSampler = (Sampler)sampler; @@ -1338,7 +1339,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_tfEnabled) { - _api.EndTransformFeedback(); + _gd.Api.EndTransformFeedback(); } int count = Math.Min(buffers.Length, Constants.MaxTransformFeedbackBuffers); @@ -1350,23 +1351,23 @@ namespace Ryujinx.Graphics.OpenGL if (buffer.Handle == BufferHandle.Null) { - _api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, (uint)i, 0); + _gd.Api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, (uint)i, 0); continue; } if (_tfbs[i] == BufferHandle.Null) { - _tfbs[i] = Buffer.Create(_api); + _tfbs[i] = Buffer.Create(_gd.Api); } - Buffer.Resize(_api, _tfbs[i], buffer.Size); - Buffer.Copy(_api, buffer.Handle, _tfbs[i], buffer.Offset, 0, buffer.Size); - _api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, (uint)i, _tfbs[i].ToUInt32()); + Buffer.Resize(_gd.Api, _tfbs[i], buffer.Size); + Buffer.Copy(_gd.Api, buffer.Handle, _tfbs[i], buffer.Offset, 0, buffer.Size); + _gd.Api.BindBufferBase(BufferTargetARB.TransformFeedbackBuffer, (uint)i, _tfbs[i].ToUInt32()); } if (_tfEnabled) { - _api.BeginTransformFeedback(_tfTopology); + _gd.Api.BeginTransformFeedback(_tfTopology); } } @@ -1379,11 +1380,11 @@ namespace Ryujinx.Graphics.OpenGL { if (!enableClip) { - _api.Disable(EnableCap.ClipDistance0 + index); + _gd.Api.Disable(EnableCap.ClipDistance0 + index); return; } - _api.Enable(EnableCap.ClipDistance0 + index); + _gd.Api.Enable(EnableCap.ClipDistance0 + index); } public void SetVertexAttribs(ReadOnlySpan vertexAttribs) @@ -1419,9 +1420,9 @@ namespace Ryujinx.Graphics.OpenGL viewportArray[viewportElemIndex + 2] = viewport.Region.Width; viewportArray[viewportElemIndex + 3] = MathF.Abs(viewport.Region.Height); - if (HwCapabilities.SupportsViewportSwizzle) + if (_gd.Capabilities.SupportsViewportSwizzle) { - _api.TryGetExtension(out NVViewportSwizzle nvViewportSwizzle); + _gd.Api.TryGetExtension(out NVViewportSwizzle nvViewportSwizzle); nvViewportSwizzle.ViewportSwizzle( index, @@ -1439,18 +1440,18 @@ namespace Ryujinx.Graphics.OpenGL SetOrigin(flipY ? ClipControlOrigin.UpperLeft : ClipControlOrigin.LowerLeft); - _api.ViewportArray(0, (uint)viewports.Length, viewportArray); - _api.DepthRangeArray(0, (uint)viewports.Length, depthRangeArray); + _gd.Api.ViewportArray(0, (uint)viewports.Length, viewportArray); + _gd.Api.DepthRangeArray(0, (uint)viewports.Length, depthRangeArray); } public void TextureBarrier() { - _api.MemoryBarrier(MemoryBarrierMask.TextureFetchBarrierBit); + _gd.Api.MemoryBarrier(MemoryBarrierMask.TextureFetchBarrierBit); } public void TextureBarrierTiled() { - _api.MemoryBarrier(MemoryBarrierMask.TextureFetchBarrierBit); + _gd.Api.MemoryBarrier(MemoryBarrierMask.TextureFetchBarrierBit); } private void SetBuffers(ReadOnlySpan buffers, bool isStorage) @@ -1464,11 +1465,11 @@ namespace Ryujinx.Graphics.OpenGL if (buffer.Handle == BufferHandle.Null) { - _api.BindBufferRange(target, (uint)assignment.Binding, 0, IntPtr.Zero, 0); + _gd.Api.BindBufferRange(target, (uint)assignment.Binding, 0, IntPtr.Zero, 0); continue; } - _api.BindBufferRange(target, (uint)assignment.Binding, buffer.Handle.ToUInt32(), buffer.Offset, (UIntPtr)buffer.Size); + _gd.Api.BindBufferRange(target, (uint)assignment.Binding, buffer.Handle.ToUInt32(), buffer.Offset, (UIntPtr)buffer.Size); } } @@ -1478,7 +1479,7 @@ namespace Ryujinx.Graphics.OpenGL { _clipOrigin = origin; - _api.ClipControl(origin, _clipDepthMode); + _gd.Api.ClipControl(origin, _clipDepthMode); SetFrontFace(_frontFace); } @@ -1494,14 +1495,14 @@ namespace Ryujinx.Graphics.OpenGL frontFace = frontFace == FrontFaceDirection.Ccw ? FrontFaceDirection.CW : FrontFaceDirection.Ccw; } - _api.FrontFace(frontFace); + _gd.Api.FrontFace(frontFace); } private void EnsureVertexArray() { if (_vertexArray == null) { - _vertexArray = new VertexArray(_api); + _vertexArray = new VertexArray(_gd.Api); _vertexArray.Bind(); } @@ -1511,12 +1512,12 @@ namespace Ryujinx.Graphics.OpenGL { if (_framebuffer == null) { - _framebuffer = new Framebuffer(_api); + _framebuffer = new Framebuffer(_gd.Api); uint boundHandle = _framebuffer.Bind(); _boundDrawFramebuffer = _boundReadFramebuffer = boundHandle; - _api.Enable(EnableCap.FramebufferSrgb); + _gd.Api.Enable(EnableCap.FramebufferSrgb); } } @@ -1562,7 +1563,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_tfbTargets[i].Handle != BufferHandle.Null) { - Buffer.Copy(_api, _tfbs[i], _tfbTargets[i].Handle, 0, _tfbTargets[i].Offset, _tfbTargets[i].Size); + Buffer.Copy(_gd.Api, _tfbs[i], _tfbTargets[i].Handle, 0, _tfbTargets[i].Offset, _tfbTargets[i].Size); } } } @@ -1587,7 +1588,7 @@ namespace Ryujinx.Graphics.OpenGL componentMask >>= shift; componentMask &= 0xfu; - _api.ColorMask( + _gd.Api.ColorMask( (uint)index, (componentMask & redMask) != 0, (componentMask & 2u) != 0, @@ -1600,14 +1601,14 @@ namespace Ryujinx.Graphics.OpenGL public void RestoreClipControl() { - _api.ClipControl(_clipOrigin, _clipDepthMode); + _gd.Api.ClipControl(_clipOrigin, _clipDepthMode); } public void RestoreScissor0Enable() { if ((_scissorEnables & 1u) != 0) { - _api.Enable(EnableCap.ScissorTest, 0); + _gd.Api.Enable(EnableCap.ScissorTest, 0); } } @@ -1615,7 +1616,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_rasterizerDiscard) { - _api.Enable(EnableCap.RasterizerDiscard); + _gd.Api.Enable(EnableCap.RasterizerDiscard); } } @@ -1623,7 +1624,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_viewportArray.Length > 0) { - _api.ViewportArray(0, 1, _viewportArray); + _gd.Api.ViewportArray(0, 1, _viewportArray); } } @@ -1644,12 +1645,12 @@ namespace Ryujinx.Graphics.OpenGL if (format != 0) { - _api.BindImageTexture((uint)i, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); + _gd.Api.BindImageTexture((uint)i, texBase.Handle, 0, true, 0, BufferAccessARB.ReadWrite, format); continue; } } - _api.BindImageTexture((uint)i, 0, 0, true, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); + _gd.Api.BindImageTexture((uint)i, 0, 0, true, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); } } @@ -1673,7 +1674,7 @@ namespace Ryujinx.Graphics.OpenGL return false; } - _api.BeginConditionalRender(evt.Query, isEqual ? ConditionalRenderMode.NoWaitInverted : ConditionalRenderMode.NoWait); + _gd.Api.BeginConditionalRender(evt.Query, isEqual ? ConditionalRenderMode.NoWaitInverted : ConditionalRenderMode.NoWait); _activeConditionalRender = evt; return true; @@ -1682,19 +1683,19 @@ namespace Ryujinx.Graphics.OpenGL // The GPU will flush the queries to CPU and evaluate the condition there instead. - _api.Flush(); // The thread will be stalled manually flushing the counter, so flush GL commands now. + _gd.Api.Flush(); // The thread will be stalled manually flushing the counter, so flush GL commands now. return false; } public bool TryHostConditionalRendering(ICounterEvent value, ICounterEvent compare, bool isEqual) { - _api.Flush(); // The GPU thread will be stalled manually flushing the counter, so flush GL commands now. + _gd.Api.Flush(); // The GPU thread will be stalled manually flushing the counter, so flush GL commands now. return false; // We don't currently have a way to compare two counters for conditional rendering. } public void EndHostConditionalRendering() { - _api.EndConditionalRender(); + _gd.Api.EndConditionalRender(); _activeConditionalRender?.ReleaseHostAccess(); _activeConditionalRender = null; @@ -1706,7 +1707,7 @@ namespace Ryujinx.Graphics.OpenGL { if (_tfbs[i] != BufferHandle.Null) { - Buffer.Delete(_api, _tfbs[i]); + Buffer.Delete(_gd.Api, _tfbs[i]); _tfbs[i] = BufferHandle.Null; } } @@ -1714,7 +1715,7 @@ namespace Ryujinx.Graphics.OpenGL _activeConditionalRender?.ReleaseHostAccess(); _framebuffer?.Dispose(); _vertexArray?.Dispose(); - _drawTexture.Dispose(_api); + _drawTexture.Dispose(_gd.Api); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index 9d388d301b..ba231e65dc 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -28,18 +28,18 @@ namespace Ryujinx.Graphics.OpenGL } } - private readonly GL _api; + private readonly OpenGLRenderer _gd; private ProgramLinkStatus _status = ProgramLinkStatus.Incomplete; private uint[] _shaderHandles; public int FragmentOutputMap { get; } - public unsafe Program(GL api, ShaderSource[] shaders, int fragmentOutputMap) + public unsafe Program(OpenGLRenderer gd, ShaderSource[] shaders, int fragmentOutputMap) { - _api = api; - Handle = _api.CreateProgram(); + _gd = gd; + Handle = _gd.Api.CreateProgram(); - _api.ProgramParameter(Handle, ProgramParameterPName.BinaryRetrievableHint, 1); + _gd.Api.ProgramParameter(Handle, ProgramParameterPName.BinaryRetrievableHint, 1); _shaderHandles = new uint[shaders.Length]; bool hasFragmentShader = false; @@ -53,37 +53,37 @@ namespace Ryujinx.Graphics.OpenGL hasFragmentShader = true; } - uint shaderHandle = _api.CreateShader(shader.Stage.Convert()); + uint shaderHandle = _gd.Api.CreateShader(shader.Stage.Convert()); switch (shader.Language) { case TargetLanguage.Glsl: - _api.ShaderSource(shaderHandle, shader.Code); - _api.CompileShader(shaderHandle); + _gd.Api.ShaderSource(shaderHandle, shader.Code); + _gd.Api.CompileShader(shaderHandle); break; case TargetLanguage.Spirv: fixed (byte* ptr = shader.BinaryCode.AsSpan()) { - _api.ShaderBinary(1, in shaderHandle, ShaderBinaryFormat.ShaderBinaryFormatSpirV, ptr, (uint)shader.BinaryCode.Length); + _gd.Api.ShaderBinary(1, in shaderHandle, ShaderBinaryFormat.ShaderBinaryFormatSpirV, ptr, (uint)shader.BinaryCode.Length); } - _api.SpecializeShader(shaderHandle, "main", 0, (uint[])null, (uint[])null); + _gd.Api.SpecializeShader(shaderHandle, "main", 0, (uint[])null, (uint[])null); break; } - _api.AttachShader(Handle, shaderHandle); + _gd.Api.AttachShader(Handle, shaderHandle); _shaderHandles[index] = shaderHandle; } - _api.LinkProgram(Handle); + _gd.Api.LinkProgram(Handle); FragmentOutputMap = hasFragmentShader ? fragmentOutputMap : 0; } - public Program(GL api, ReadOnlySpan code, bool hasFragmentShader, int fragmentOutputMap) + public Program(OpenGLRenderer gd, ReadOnlySpan code, bool hasFragmentShader, int fragmentOutputMap) { - _api = api; - Handle = _api.CreateProgram(); + _gd = gd; + Handle = _gd.Api.CreateProgram(); if (code.Length >= 4) { @@ -93,7 +93,7 @@ namespace Ryujinx.Graphics.OpenGL { fixed (byte* ptr = code) { - _api.ProgramBinary(Handle, (GLEnum)binaryFormat, (IntPtr)ptr, (uint)code.Length - 4); + _gd.Api.ProgramBinary(Handle, (GLEnum)binaryFormat, (IntPtr)ptr, (uint)code.Length - 4); } } } @@ -103,14 +103,14 @@ namespace Ryujinx.Graphics.OpenGL public void Bind() { - _api.UseProgram(Handle); + _gd.Api.UseProgram(Handle); } public ProgramLinkStatus CheckProgramLink(bool blocking) { - if (!blocking && HwCapabilities.SupportsParallelShaderCompile) + if (!blocking && _gd.Capabilities.SupportsParallelShaderCompile) { - _api.GetProgram(Handle, (GLEnum)ARB.CompletionStatusArb, out int completed); + _gd.Api.GetProgram(Handle, (GLEnum)ARB.CompletionStatusArb, out int completed); if (completed == 0) { @@ -118,14 +118,14 @@ namespace Ryujinx.Graphics.OpenGL } } - _api.GetProgram(Handle, ProgramPropertyARB.LinkStatus, out int status); + _gd.Api.GetProgram(Handle, ProgramPropertyARB.LinkStatus, out int status); DeleteShaders(); if (status == 0) { _status = ProgramLinkStatus.Failure; - string log = _api.GetProgramInfoLog(Handle); + string log = _gd.Api.GetProgramInfoLog(Handle); if (log.Length > MaxShaderLogLength) { @@ -144,14 +144,14 @@ namespace Ryujinx.Graphics.OpenGL public unsafe byte[] GetBinary() { - _api.GetProgram(Handle, ProgramPropertyARB.ProgramBinaryLength, out int size); + _gd.Api.GetProgram(Handle, ProgramPropertyARB.ProgramBinaryLength, out int size); byte[] data = new byte[size]; GLEnum binFormat; fixed (byte* ptr = data) { - _api.GetProgramBinary(Handle, (uint)size, out _, out binFormat, ptr); + _gd.Api.GetProgramBinary(Handle, (uint)size, out _, out binFormat, ptr); } BinaryPrimitives.WriteInt32LittleEndian(data, (int)binFormat); @@ -165,8 +165,8 @@ namespace Ryujinx.Graphics.OpenGL { foreach (uint shaderHandle in _shaderHandles) { - _api.DetachShader(Handle, shaderHandle); - _api.DeleteShader(shaderHandle); + _gd.Api.DetachShader(Handle, shaderHandle); + _gd.Api.DeleteShader(shaderHandle); } _shaderHandles = null; @@ -178,7 +178,7 @@ namespace Ryujinx.Graphics.OpenGL if (Handle != 0) { DeleteShaders(); - _api.DeleteProgram(Handle); + _gd.Api.DeleteProgram(Handle); Handle = 0; } diff --git a/src/Ryujinx.Graphics.OpenGL/Sync.cs b/src/Ryujinx.Graphics.OpenGL/Sync.cs index f853c4f882..fb2acbe482 100644 --- a/src/Ryujinx.Graphics.OpenGL/Sync.cs +++ b/src/Ryujinx.Graphics.OpenGL/Sync.cs @@ -14,15 +14,15 @@ namespace Ryujinx.Graphics.OpenGL public IntPtr Handle; } - private ulong _firstHandle = 0; - private static SyncObjectMask SyncFlags => HwCapabilities.RequiresSyncFlush ? 0 : SyncObjectMask.Bit; + private ulong _firstHandle; + private SyncObjectMask SyncFlags => _gd.Capabilities.RequiresSyncFlush ? 0 : SyncObjectMask.Bit; private readonly List _handles = new(); - private readonly GL _api; + private readonly OpenGLRenderer _gd; - public Sync(GL api) + public Sync(OpenGLRenderer gd) { - _api = api; + _gd = gd; } public void Create(ulong id) @@ -30,14 +30,14 @@ namespace Ryujinx.Graphics.OpenGL SyncHandle handle = new() { ID = id, - Handle = _api.FenceSync(SyncCondition.SyncGpuCommandsComplete, SyncBehaviorFlags.None), + Handle = _gd.Api.FenceSync(SyncCondition.SyncGpuCommandsComplete, SyncBehaviorFlags.None), }; - if (HwCapabilities.RequiresSyncFlush) + if (_gd.Capabilities.RequiresSyncFlush) { // Force commands to flush up to the syncpoint. - _api.ClientWaitSync(handle.Handle, SyncObjectMask.Bit, 0); + _gd.Api.ClientWaitSync(handle.Handle, SyncObjectMask.Bit, 0); } lock (_handles) @@ -63,7 +63,7 @@ namespace Ryujinx.Graphics.OpenGL if (handle.ID > lastHandle) { - GLEnum syncResult = _api.ClientWaitSync(handle.Handle, SyncFlags, 0); + GLEnum syncResult = _gd.Api.ClientWaitSync(handle.Handle, SyncFlags, 0); if (syncResult == GLEnum.AlreadySignaled) { @@ -107,7 +107,7 @@ namespace Ryujinx.Graphics.OpenGL return; } - GLEnum syncResult = _api.ClientWaitSync(result.Handle, SyncFlags, 1000000000); + GLEnum syncResult = _gd.Api.ClientWaitSync(result.Handle, SyncFlags, 1000000000); if (syncResult == GLEnum.TimeoutExpired) { @@ -134,7 +134,7 @@ namespace Ryujinx.Graphics.OpenGL break; } - GLEnum syncResult = _api.ClientWaitSync(first.Handle, SyncFlags, 0); + GLEnum syncResult = _gd.Api.ClientWaitSync(first.Handle, SyncFlags, 0); if (syncResult == GLEnum.AlreadySignaled) { @@ -145,7 +145,7 @@ namespace Ryujinx.Graphics.OpenGL { _firstHandle = first.ID + 1; _handles.RemoveAt(0); - _api.DeleteSync(first.Handle); + _gd.Api.DeleteSync(first.Handle); first.Handle = IntPtr.Zero; } } @@ -166,7 +166,7 @@ namespace Ryujinx.Graphics.OpenGL { lock (handle) { - _api.DeleteSync(handle.Handle); + _gd.Api.DeleteSync(handle.Handle); handle.Handle = IntPtr.Zero; } } From e584f8d37df89fc987df7ac8ecfe2f16e7d1a413 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 21:22:38 -0400 Subject: [PATCH 21/35] Ava Working? --- src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs | 2 +- src/Ryujinx.Headless.SDL2/Program.cs | 3 ++- src/Ryujinx/AppHost.cs | 2 +- src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs | 16 +++++++++------- src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs | 10 ++++++---- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs index 4b5e8ddeb7..bef71e5a68 100644 --- a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs +++ b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs @@ -1,4 +1,4 @@ -using OpenTK; +// using OpenTK; using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; diff --git a/src/Ryujinx.Headless.SDL2/Program.cs b/src/Ryujinx.Headless.SDL2/Program.cs index 85aff67129..38faa6b8dd 100644 --- a/src/Ryujinx.Headless.SDL2/Program.cs +++ b/src/Ryujinx.Headless.SDL2/Program.cs @@ -532,7 +532,8 @@ namespace Ryujinx.Headless.SDL2 preferredGpuId); } - return new OpenGLRenderer(); + var openGlWindow = (OpenGLWindow)window; + return new OpenGLRenderer(window.); } private static Switch InitializeEmulationContext(WindowBase window, IRenderer renderer, Options options) diff --git a/src/Ryujinx/AppHost.cs b/src/Ryujinx/AppHost.cs index d405f32050..cddc7429f1 100644 --- a/src/Ryujinx/AppHost.cs +++ b/src/Ryujinx/AppHost.cs @@ -823,7 +823,7 @@ namespace Ryujinx.Ava } else { - renderer = new OpenGLRenderer(); + renderer = new OpenGLRenderer((RendererHost.EmbeddedWindow as EmbeddedWindowOpenGL).CreateApi()); } BackendThreading threadingMode = ConfigurationState.Instance.Graphics.BackendThreading; diff --git a/src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs b/src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs index 3842301def..92fe2c22e2 100644 --- a/src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs +++ b/src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; @@ -44,6 +44,13 @@ namespace Ryujinx.Ava.UI.Renderer throw new PlatformNotSupportedException(); } + Context.Initialize(_window); + Context.MakeCurrent(_window); + Context.MakeCurrent(null); + } + + public GL CreateApi() + { var flags = OpenGLContextFlags.Compat; if (ConfigurationState.Instance.Logger.GraphicsDebugLevel != GraphicsDebugLevel.None) { @@ -54,12 +61,7 @@ namespace Ryujinx.Ava.UI.Renderer Context = PlatformHelper.CreateOpenGLContext(graphicsMode, 3, 3, flags); - Context.Initialize(_window); - Context.MakeCurrent(_window); - - GL.LoadBindings(new OpenTKBindingsContext(Context.GetProcAddress)); - - Context.MakeCurrent(null); + return GL.GetApi(Context.GetProcAddress); } public void MakeCurrent(bool unbind = false, bool shouldThrow = true) diff --git a/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs b/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs index 63bf6cf7c7..9f94337b35 100644 --- a/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs +++ b/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs @@ -1,4 +1,4 @@ -using OpenTK.Graphics.OpenGL; +using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.OpenGL; using SPB.Graphics; using SPB.Graphics.OpenGL; @@ -9,11 +9,13 @@ namespace Ryujinx.Ava.UI.Renderer { class SPBOpenGLContext : IOpenGLContext { + private readonly GL _api; private readonly OpenGLContextBase _context; private readonly NativeWindowBase _window; - private SPBOpenGLContext(OpenGLContextBase context, NativeWindowBase window) + private SPBOpenGLContext(GL api, OpenGLContextBase context, NativeWindowBase window) { + _api = api; _context = context; _window = window; } @@ -39,11 +41,11 @@ namespace Ryujinx.Ava.UI.Renderer context.Initialize(window); context.MakeCurrent(window); - GL.LoadBindings(new OpenTKBindingsContext(context.GetProcAddress)); + GL api = GL.GetApi(context.GetProcAddress); context.MakeCurrent(null); - return new SPBOpenGLContext(context, window); + return new SPBOpenGLContext(api, context, window); } } } From e72bf35c039ab3b91d9190a2a07bd92d28e23a3f Mon Sep 17 00:00:00 2001 From: IsaacMarovitz Date: Thu, 9 May 2024 22:15:55 -0400 Subject: [PATCH 22/35] Fix some stack overflows --- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 9 +---- .../Image/TextureView.cs | 40 +++++++++---------- 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index d09bee156e..1571199b51 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -103,14 +103,7 @@ namespace Ryujinx.Graphics.OpenGL public static void SetData(GL api, BufferHandle buffer, int offset, ReadOnlySpan data) { api.BindBuffer(BufferTargetARB.CopyWriteBuffer, buffer.ToUInt32()); - - unsafe - { - fixed (byte* ptr = data) - { - api.BufferSubData(BufferTargetARB.CopyWriteBuffer, offset, (uint)data.Length, (IntPtr)ptr); - } - } + api.BufferSubData(BufferTargetARB.CopyWriteBuffer, offset, (uint)data.Length, data); } public static void Delete(GL api, BufferHandle buffer) diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index 73b759aaf3..714207aecf 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -554,7 +554,7 @@ namespace Ryujinx.Graphics.OpenGL.Image return data; } - private void ReadFrom2D(IntPtr data, int layer, int level, int x, int y, int width, int height, int mipSize) + private unsafe void ReadFrom2D(IntPtr data, int layer, int level, int x, int y, int width, int height, int mipSize) { TextureTarget target = Target.Convert(); @@ -574,7 +574,7 @@ namespace Ryujinx.Graphics.OpenGL.Image (uint)width, (InternalFormat)format.PixelFormat, (uint)mipSize, - data); + (void*)data); } else { @@ -585,7 +585,7 @@ namespace Ryujinx.Graphics.OpenGL.Image (uint)width, format.PixelFormat, format.PixelType, - data); + (void*)data); } break; @@ -601,7 +601,7 @@ namespace Ryujinx.Graphics.OpenGL.Image 1, (InternalFormat)format.PixelFormat, (uint)mipSize, - data); + (void*)data); } else { @@ -614,7 +614,7 @@ namespace Ryujinx.Graphics.OpenGL.Image 1, format.PixelFormat, format.PixelType, - data); + (void*)data); } break; @@ -630,7 +630,7 @@ namespace Ryujinx.Graphics.OpenGL.Image (uint)height, (InternalFormat)format.PixelFormat, (uint)mipSize, - data); + (void*)data); } else { @@ -643,7 +643,7 @@ namespace Ryujinx.Graphics.OpenGL.Image (uint)height, format.PixelFormat, format.PixelType, - data); + (void*)data); } break; @@ -663,7 +663,7 @@ namespace Ryujinx.Graphics.OpenGL.Image 1, (InternalFormat)format.PixelFormat, (uint)mipSize, - data); + (void*)data); } else { @@ -678,7 +678,7 @@ namespace Ryujinx.Graphics.OpenGL.Image 1, format.PixelFormat, format.PixelType, - data); + (void*)data); } break; @@ -694,7 +694,7 @@ namespace Ryujinx.Graphics.OpenGL.Image (uint)height, (InternalFormat)format.PixelFormat, (uint)mipSize, - data); + (void*)data); } else { @@ -707,13 +707,13 @@ namespace Ryujinx.Graphics.OpenGL.Image (uint)height, format.PixelFormat, format.PixelType, - data); + (void*)data); } break; } } - private void ReadFrom(IntPtr data, int size) + private unsafe void ReadFrom(IntPtr data, int size) { TextureTarget target = Target.Convert(); uint baseLevel = 0; @@ -762,7 +762,7 @@ namespace Ryujinx.Graphics.OpenGL.Image width, (InternalFormat)format.PixelFormat, (uint)mipSize, - data); + (void*)data); } else { @@ -773,7 +773,7 @@ namespace Ryujinx.Graphics.OpenGL.Image width, format.PixelFormat, format.PixelType, - data); + (void*)data); } break; @@ -790,7 +790,7 @@ namespace Ryujinx.Graphics.OpenGL.Image height, (InternalFormat)format.PixelFormat, (uint)mipSize, - data); + (void*)data); } else { @@ -803,7 +803,7 @@ namespace Ryujinx.Graphics.OpenGL.Image height, format.PixelFormat, format.PixelType, - data); + (void*)data); } break; @@ -823,7 +823,7 @@ namespace Ryujinx.Graphics.OpenGL.Image depth, (InternalFormat)format.PixelFormat, (uint)mipSize, - data); + (void*)data); } else { @@ -838,7 +838,7 @@ namespace Ryujinx.Graphics.OpenGL.Image depth, format.PixelFormat, format.PixelType, - data); + (void*)data); } break; @@ -858,7 +858,7 @@ namespace Ryujinx.Graphics.OpenGL.Image height, (InternalFormat)format.PixelFormat, (uint)mipSize / 6, - data + faceOffset); + (void*)(data + faceOffset)); } else { @@ -871,7 +871,7 @@ namespace Ryujinx.Graphics.OpenGL.Image height, format.PixelFormat, format.PixelType, - data + faceOffset); + (void*)(data + faceOffset)); } } break; From 3e422f020cff31044a0e50feaa440cefbe5da12e Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 22:59:08 -0400 Subject: [PATCH 23/35] Hook up SDL2 and GTK --- src/Ryujinx.Gtk3/UI/MainWindow.cs | 2 +- src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs | 13 ++++++++--- .../UI/OpenToolkitBindingsContext.cs | 20 ---------------- src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs | 10 ++++---- .../OpenGL/OpenGLWindow.cs | 23 ++++++++----------- src/Ryujinx.Headless.SDL2/Program.cs | 4 ++-- 6 files changed, 28 insertions(+), 44 deletions(-) delete mode 100644 src/Ryujinx.Gtk3/UI/OpenToolkitBindingsContext.cs diff --git a/src/Ryujinx.Gtk3/UI/MainWindow.cs b/src/Ryujinx.Gtk3/UI/MainWindow.cs index d1ca6ce6ab..eec90ad2c6 100644 --- a/src/Ryujinx.Gtk3/UI/MainWindow.cs +++ b/src/Ryujinx.Gtk3/UI/MainWindow.cs @@ -504,7 +504,7 @@ namespace Ryujinx.UI } else { - renderer = new Graphics.OpenGL.OpenGLRenderer(); + renderer = new Graphics.OpenGL.OpenGLRenderer(((OpenGLRenderer)RendererWidget).GetApi()); } BackendThreading threadingMode = ConfigurationState.Instance.Graphics.BackendThreading; diff --git a/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs b/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs index 02a9e0388e..0ff3700c0f 100644 --- a/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs +++ b/src/Ryujinx.Gtk3/UI/OpenGLRenderer.cs @@ -1,7 +1,7 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Input.HLE; +using Silk.NET.OpenGL.Legacy; using SPB.Graphics; using SPB.Graphics.Exceptions; using SPB.Graphics.OpenGL; @@ -96,11 +96,18 @@ namespace Ryujinx.UI _openGLContext.MakeCurrent(_nativeWindow); - GL.ClearColor(0, 0, 0, 1.0f); - GL.Clear(ClearBufferMask.ColorBufferBit); + var api = GetApi(); + + api.ClearColor(0, 0, 0, 1.0f); + api.Clear(ClearBufferMask.ColorBufferBit); SwapBuffers(); } + public GL GetApi() + { + return GL.GetApi(_openGLContext.GetProcAddress); + } + public override void SwapBuffers() { _nativeWindow.SwapBuffers(); diff --git a/src/Ryujinx.Gtk3/UI/OpenToolkitBindingsContext.cs b/src/Ryujinx.Gtk3/UI/OpenToolkitBindingsContext.cs deleted file mode 100644 index 1224ccfe09..0000000000 --- a/src/Ryujinx.Gtk3/UI/OpenToolkitBindingsContext.cs +++ /dev/null @@ -1,20 +0,0 @@ -using SPB.Graphics; -using System; - -namespace Ryujinx.UI -{ - public class OpenToolkitBindingsContext : OpenTK.IBindingsContext - { - private readonly IBindingsContext _bindingContext; - - public OpenToolkitBindingsContext(IBindingsContext bindingsContext) - { - _bindingContext = bindingsContext; - } - - public IntPtr GetProcAddress(string procName) - { - return _bindingContext.GetProcAddress(procName); - } - } -} diff --git a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs index 5833411d32..1ecc64c67d 100644 --- a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs +++ b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.OpenGL; +using Silk.NET.OpenGL.Legacy; using SPB.Graphics; using SPB.Graphics.OpenGL; using SPB.Platform; @@ -9,11 +9,13 @@ namespace Ryujinx.UI { class SPBOpenGLContext : IOpenGLContext { + public readonly GL Api; private readonly OpenGLContextBase _context; private readonly NativeWindowBase _window; - private SPBOpenGLContext(OpenGLContextBase context, NativeWindowBase window) + private SPBOpenGLContext(GL api, OpenGLContextBase context, NativeWindowBase window) { + Api = api; _context = context; _window = window; } @@ -39,11 +41,11 @@ namespace Ryujinx.UI context.Initialize(window); context.MakeCurrent(window); - GL.LoadBindings(new OpenToolkitBindingsContext(context)); + GL api = GL.GetApi(context.GetProcAddress); context.MakeCurrent(null); - return new SPBOpenGLContext(context, window); + return new SPBOpenGLContext(api, context, window); } } } diff --git a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs index bef71e5a68..c8456df2c4 100644 --- a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs +++ b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs @@ -38,22 +38,16 @@ namespace Ryujinx.Headless.SDL2.OpenGL CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_STEREO, 0)); } - private class OpenToolkitBindingsContext : IBindingsContext - { - public IntPtr GetProcAddress(string procName) - { - return SDL_GL_GetProcAddress(procName); - } - } - private class SDL2OpenGLContext : IOpenGLContext { + public readonly GL Api; private readonly IntPtr _context; private readonly IntPtr _window; private readonly bool _shouldDisposeWindow; - public SDL2OpenGLContext(IntPtr context, IntPtr window, bool shouldDisposeWindow = true) + public SDL2OpenGLContext(GL api, IntPtr context, IntPtr window, bool shouldDisposeWindow = true) { + Api = api; _context = context; _window = window; _shouldDisposeWindow = shouldDisposeWindow; @@ -68,13 +62,13 @@ namespace Ryujinx.Headless.SDL2.OpenGL IntPtr windowHandle = SDL_CreateWindow("Ryujinx background context window", 0, 0, 1, 1, SDL_WindowFlags.SDL_WINDOW_OPENGL | SDL_WindowFlags.SDL_WINDOW_HIDDEN); IntPtr context = SDL_GL_CreateContext(windowHandle); - GL.LoadBindings(new OpenToolkitBindingsContext()); + GL api = GL.GetApi((_ => context)); CheckResult(SDL_GL_SetAttribute(SDL_GLattr.SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 0)); CheckResult(SDL_GL_MakeCurrent(windowHandle, IntPtr.Zero)); - return new SDL2OpenGLContext(context, windowHandle); + return new SDL2OpenGLContext(api, context, windowHandle); } public void MakeCurrent() @@ -111,6 +105,7 @@ namespace Ryujinx.Headless.SDL2.OpenGL private readonly GraphicsDebugLevel _glLogLevel; private SDL2OpenGLContext _openGLContext; + public GL Api => _openGLContext.Api; public OpenGLWindow( InputManager inputManager, @@ -142,15 +137,15 @@ namespace Ryujinx.Headless.SDL2.OpenGL } // NOTE: The window handle needs to be disposed by the thread that created it and is handled separately. - _openGLContext = new SDL2OpenGLContext(context, WindowHandle, false); + _openGLContext = new SDL2OpenGLContext(GL.GetApi((_ => context)), context, WindowHandle, false); // First take exclusivity on the OpenGL context. ((OpenGLRenderer)Renderer).InitializeBackgroundContext(SDL2OpenGLContext.CreateBackgroundContext(_openGLContext)); _openGLContext.MakeCurrent(); - GL.ClearColor(0, 0, 0, 1.0f); - GL.Clear(ClearBufferMask.ColorBufferBit); + _openGLContext.Api.ClearColor(0, 0, 0, 1.0f); + _openGLContext.Api.Clear(ClearBufferMask.ColorBufferBit); SwapBuffers(); if (IsExclusiveFullscreen) diff --git a/src/Ryujinx.Headless.SDL2/Program.cs b/src/Ryujinx.Headless.SDL2/Program.cs index 38faa6b8dd..1e63715132 100644 --- a/src/Ryujinx.Headless.SDL2/Program.cs +++ b/src/Ryujinx.Headless.SDL2/Program.cs @@ -532,8 +532,8 @@ namespace Ryujinx.Headless.SDL2 preferredGpuId); } - var openGlWindow = (OpenGLWindow)window; - return new OpenGLRenderer(window.); + var openGlWindow = window as OpenGLWindow; + return new OpenGLRenderer(openGlWindow.Api); } private static Switch InitializeEmulationContext(WindowBase window, IRenderer renderer, Options options) From 2b07d783c819a80449b0891e1c0c704960e2827d Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 22:59:34 -0400 Subject: [PATCH 24/35] Formatting --- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Debugger.cs | 2 +- src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs | 2 +- .../Effects/FxaaPostProcessingEffect.cs | 2 +- .../Effects/SmaaPostProcessingEffect.cs | 4 ++-- src/Ryujinx.Graphics.OpenGL/EnumConversion.cs | 6 +++--- src/Ryujinx.Graphics.OpenGL/FormatTable.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Framebuffer.cs | 2 +- src/Ryujinx.Graphics.OpenGL/IOpenGLContext.cs | 1 - src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs | 2 +- src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 6 +++--- src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Program.cs | 4 ++-- src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs | 4 ++-- src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Sync.cs | 2 +- src/Ryujinx.Graphics.OpenGL/VertexArray.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Window.cs | 2 +- src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs | 2 +- src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs | 2 +- src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs | 2 +- 31 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index 1571199b51..630cc80730 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; using System; namespace Ryujinx.Graphics.OpenGL diff --git a/src/Ryujinx.Graphics.OpenGL/Debugger.cs b/src/Ryujinx.Graphics.OpenGL/Debugger.cs index 1428429227..dc1aecf24a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Debugger.cs +++ b/src/Ryujinx.Graphics.OpenGL/Debugger.cs @@ -1,6 +1,6 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; +using Silk.NET.OpenGL.Legacy; using System; using System.Runtime.InteropServices; using System.Threading; diff --git a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs index a58d3668db..3920aa8943 100644 --- a/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs +++ b/src/Ryujinx.Graphics.OpenGL/DrawTextureEmulation.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.OpenGL.Image; +using Silk.NET.OpenGL.Legacy; using System; using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs index d9821a2417..aff20db2f1 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs @@ -1,7 +1,7 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; +using Silk.NET.OpenGL.Legacy; using System; using static Ryujinx.Graphics.OpenGL.Effects.ShaderHelper; diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs index ed772b8743..1f54ad2aaf 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs @@ -1,6 +1,6 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.OpenGL.Image; +using Silk.NET.OpenGL.Legacy; namespace Ryujinx.Graphics.OpenGL.Effects { diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs index dfb7073fec..94fbe16734 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs @@ -1,7 +1,7 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; +using Silk.NET.OpenGL.Legacy; using System; namespace Ryujinx.Graphics.OpenGL.Effects.Smaa @@ -219,7 +219,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa _gd.Api.DispatchCompute(dispatchX, dispatchY, 1); _gd.Api.MemoryBarrier(MemoryBarrierMask.ShaderImageAccessBarrierBit); - _gd.Api.BindImageTexture(0, blendOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite,InternalFormat.Rgba8); + _gd.Api.BindImageTexture(0, blendOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); _gd.Api.UseProgram(_blendShaderPrograms[Quality]); edgeOutput.Bind(0); areaTexture.Bind(1); diff --git a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs index 9a5015544d..81dbb7b5b0 100644 --- a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -1,9 +1,9 @@ -using Silk.NET.OpenGL.Legacy; -using Silk.NET.OpenGL.Legacy.Extensions.NV; -using Silk.NET.OpenGL.Legacy.Extensions.EXT; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; +using Silk.NET.OpenGL.Legacy; +using Silk.NET.OpenGL.Legacy.Extensions.EXT; +using Silk.NET.OpenGL.Legacy.Extensions.NV; namespace Ryujinx.Graphics.OpenGL { diff --git a/src/Ryujinx.Graphics.OpenGL/FormatTable.cs b/src/Ryujinx.Graphics.OpenGL/FormatTable.cs index e4f37b96c8..6492aa7f40 100644 --- a/src/Ryujinx.Graphics.OpenGL/FormatTable.cs +++ b/src/Ryujinx.Graphics.OpenGL/FormatTable.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; using System; namespace Ryujinx.Graphics.OpenGL diff --git a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs index 37b9a14cf6..d458fcafc2 100644 --- a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -1,6 +1,6 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; +using Silk.NET.OpenGL.Legacy; using Silk.NET.OpenGL.Legacy.Extensions.NV; using System; using System.Runtime.CompilerServices; diff --git a/src/Ryujinx.Graphics.OpenGL/IOpenGLContext.cs b/src/Ryujinx.Graphics.OpenGL/IOpenGLContext.cs index 525418d74f..5443465eae 100644 --- a/src/Ryujinx.Graphics.OpenGL/IOpenGLContext.cs +++ b/src/Ryujinx.Graphics.OpenGL/IOpenGLContext.cs @@ -1,4 +1,3 @@ -using Ryujinx.Graphics.OpenGL.Helper; using System; namespace Ryujinx.Graphics.OpenGL diff --git a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs index 527b9393df..89d669767c 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/ImageArray.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; namespace Ryujinx.Graphics.OpenGL.Image { diff --git a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs index 74e1543b2a..e595a5cf9d 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/Sampler.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; namespace Ryujinx.Graphics.OpenGL.Image { diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs index 53ea85eb56..9a31782b78 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBase.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; namespace Ryujinx.Graphics.OpenGL.Image { diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs index 074cbe4a88..3b5a5e9180 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureBuffer.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; using System; using System.Buffers; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index 5a07323375..1e70ab3bad 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -1,6 +1,6 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; using System; namespace Ryujinx.Graphics.OpenGL.Image diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs index 2025d5f1fe..b44d7c2bd1 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyMS.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; using System; using System.Numerics; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs index 09e68702d3..99446e0622 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureStorage.cs @@ -1,6 +1,6 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; namespace Ryujinx.Graphics.OpenGL.Image { diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index 714207aecf..5c40cc1776 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -1,6 +1,6 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; using System; using System.Buffers; using System.Diagnostics; diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index ae11daa259..deea560ac6 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -1,11 +1,11 @@ -using Silk.NET.OpenGL.Legacy; -using Silk.NET.OpenGL.Legacy.Extensions.ARB; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; using Ryujinx.Graphics.OpenGL.Queries; using Ryujinx.Graphics.Shader.Translation; +using Silk.NET.OpenGL.Legacy; +using Silk.NET.OpenGL.Legacy.Extensions.ARB; using System; using System.Runtime.InteropServices; using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; @@ -149,7 +149,7 @@ namespace Ryujinx.Graphics.OpenGL public Capabilities GetCapabilities() { bool intelWindows = Capabilities.GpuVendor == OpenGL.GpuVendor.IntelWindows; - bool intelUnix = Capabilities.GpuVendor == OpenGL.GpuVendor.IntelUnix; + bool intelUnix = Capabilities.GpuVendor == OpenGL.GpuVendor.IntelUnix; bool amdWindows = Capabilities.GpuVendor == OpenGL.GpuVendor.AmdWindows; return new Capabilities( diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index 050a54370e..33ef1b7d89 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -1,7 +1,7 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; +using Silk.NET.OpenGL.Legacy; using System; using System.Collections.Generic; using System.Runtime.CompilerServices; diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 4b3316fa51..d8aae8dd22 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -1,9 +1,9 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Image; using Ryujinx.Graphics.OpenGL.Queries; using Ryujinx.Graphics.Shader; +using Silk.NET.OpenGL.Legacy; using Silk.NET.OpenGL.Legacy.Extensions.NV; using System; using Sampler = Ryujinx.Graphics.OpenGL.Image.Sampler; diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index ba231e65dc..9c59f402b8 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -1,9 +1,9 @@ -using Silk.NET.OpenGL.Legacy; -using Silk.NET.OpenGL.Legacy.Extensions.ARB; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.Shader; using Ryujinx.Graphics.Shader.Translation; +using Silk.NET.OpenGL.Legacy; +using Silk.NET.OpenGL.Legacy.Extensions.ARB; using System; using System.Buffers.Binary; diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs index ad74b28686..a033ad0bad 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; +using Silk.NET.OpenGL.Legacy; using System; using System.Runtime.InteropServices; using System.Threading; @@ -60,7 +60,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries _api.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); Marshal.WriteInt64(_bufferMap, -1L); - _api.GetQueryObject(Query,QueryObjectParameterName.Result, (long*)0); + _api.GetQueryObject(Query, QueryObjectParameterName.Result, (long*)0); _api.MemoryBarrier(MemoryBarrierMask.QueryBufferBarrierBit | MemoryBarrierMask.ClientMappedBufferBarrierBit); } else diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs index 676723d8cc..c5c3caf6f6 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueue.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; using System; using System.Collections.Generic; using System.Threading; diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs index 578328665f..449d006248 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; using System; using System.Threading; diff --git a/src/Ryujinx.Graphics.OpenGL/Sync.cs b/src/Ryujinx.Graphics.OpenGL/Sync.cs index fb2acbe482..e806be8741 100644 --- a/src/Ryujinx.Graphics.OpenGL/Sync.cs +++ b/src/Ryujinx.Graphics.OpenGL/Sync.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Logging; +using Silk.NET.OpenGL.Legacy; using System; using System.Collections.Generic; using System.Linq; diff --git a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs index 155f69b158..4961f8a2d5 100644 --- a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; +using Silk.NET.OpenGL.Legacy; using System; using System.Numerics; using System.Runtime.CompilerServices; diff --git a/src/Ryujinx.Graphics.OpenGL/Window.cs b/src/Ryujinx.Graphics.OpenGL/Window.cs index 3741a9a9c4..0d04114f8f 100644 --- a/src/Ryujinx.Graphics.OpenGL/Window.cs +++ b/src/Ryujinx.Graphics.OpenGL/Window.cs @@ -1,8 +1,8 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL.Effects; using Ryujinx.Graphics.OpenGL.Effects.Smaa; using Ryujinx.Graphics.OpenGL.Image; +using Silk.NET.OpenGL.Legacy; using System; namespace Ryujinx.Graphics.OpenGL diff --git a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs index c8456df2c4..9e3c0dc00e 100644 --- a/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs +++ b/src/Ryujinx.Headless.SDL2/OpenGL/OpenGLWindow.cs @@ -1,9 +1,9 @@ // using OpenTK; -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.OpenGL; using Ryujinx.Input.HLE; +using Silk.NET.OpenGL.Legacy; using System; using static SDL2.SDL; diff --git a/src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs b/src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs index 92fe2c22e2..5d2817fbbf 100644 --- a/src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs +++ b/src/Ryujinx/UI/Renderer/EmbeddedWindowOpenGL.cs @@ -1,9 +1,9 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Common.Configuration; using Ryujinx.Common.Logging; using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.OpenGL; using Ryujinx.UI.Common.Configuration; +using Silk.NET.OpenGL.Legacy; using SPB.Graphics; using SPB.Graphics.Exceptions; using SPB.Graphics.OpenGL; diff --git a/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs b/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs index 9f94337b35..2f7c54849d 100644 --- a/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs +++ b/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs @@ -1,5 +1,5 @@ -using Silk.NET.OpenGL.Legacy; using Ryujinx.Graphics.OpenGL; +using Silk.NET.OpenGL.Legacy; using SPB.Graphics; using SPB.Graphics.OpenGL; using SPB.Platform; From bab7457b99ab80eb660840827c897baf8d269182 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 23:10:13 -0400 Subject: [PATCH 25/35] Fix some warnings --- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 8 ++--- src/Ryujinx.Graphics.OpenGL/Debugger.cs | 4 +-- src/Ryujinx.Graphics.OpenGL/EnumConversion.cs | 6 ++++ .../HardwareCapabilities.cs | 2 ++ .../Image/TextureCopy.cs | 2 +- .../PersistentBuffers.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 32 ++++++++++++------- src/Ryujinx.Graphics.OpenGL/Program.cs | 2 +- .../Queries/BufferedQuery.cs | 7 +--- 9 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index 630cc80730..e5c2e07237 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -23,7 +23,7 @@ namespace Ryujinx.Graphics.OpenGL size, PixelFormat.RgbaInteger, PixelType.UnsignedByte, - (IntPtr)valueArr); + valueArr); } } @@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.OpenGL uint handle = api.GenBuffer(); api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); - api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, UIntPtr.Zero, BufferUsageARB.DynamicDraw); + api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, in UIntPtr.Zero, BufferUsageARB.DynamicDraw); return Handle.FromUInt32(handle); } @@ -47,7 +47,7 @@ namespace Ryujinx.Graphics.OpenGL uint handle = api.GenBuffer(); api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); - api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)size, UIntPtr.Zero, + api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)size, in UIntPtr.Zero, BufferStorageMask.MapPersistentBit | BufferStorageMask.MapCoherentBit | BufferStorageMask.ClientStorageBit | @@ -97,7 +97,7 @@ namespace Ryujinx.Graphics.OpenGL public static void Resize(GL api, BufferHandle handle, int size) { api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); - api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, UIntPtr.Zero, BufferUsageARB.StreamCopy); + api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, in UIntPtr.Zero, BufferUsageARB.StreamCopy); } public static void SetData(GL api, BufferHandle buffer, int offset, ReadOnlySpan data) diff --git a/src/Ryujinx.Graphics.OpenGL/Debugger.cs b/src/Ryujinx.Graphics.OpenGL/Debugger.cs index dc1aecf24a..963bb0b5d7 100644 --- a/src/Ryujinx.Graphics.OpenGL/Debugger.cs +++ b/src/Ryujinx.Graphics.OpenGL/Debugger.cs @@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.OpenGL if (logLevel == GraphicsDebugLevel.None) { gl.Disable(EnableCap.DebugOutputSynchronous); - gl.DebugMessageCallback(null, IntPtr.Zero); + gl.DebugMessageCallback(null, in IntPtr.Zero); return; } @@ -45,7 +45,7 @@ namespace Ryujinx.Graphics.OpenGL _counter = 0; _debugCallback = GLDebugHandler; - gl.DebugMessageCallback(_debugCallback, IntPtr.Zero); + gl.DebugMessageCallback(_debugCallback, in IntPtr.Zero); Logger.Warning?.Print(LogClass.Gpu, "OpenGL Debugging is enabled. Performance will be negatively impacted."); } diff --git a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs index 81dbb7b5b0..75528e67b1 100644 --- a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -14,7 +14,9 @@ namespace Ryujinx.Graphics.OpenGL switch (mode) { case AddressMode.Clamp: +#pragma warning disable CS0618 // Type or member is obsolete return TextureWrapMode.Clamp; +#pragma warning restore CS0618 // Type or member is obsolete case AddressMode.Repeat: return TextureWrapMode.Repeat; case AddressMode.MirrorClamp: @@ -33,7 +35,9 @@ namespace Ryujinx.Graphics.OpenGL Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(AddressMode)} enum value: {mode}."); +#pragma warning disable CS0618 // Type or member is obsolete return TextureWrapMode.Clamp; +#pragma warning restore CS0618 // Type or member is obsolete } public static NV Convert(this AdvancedBlendOp op) @@ -451,7 +455,9 @@ namespace Ryujinx.Graphics.OpenGL case PrimitiveTopology.Quads: return PrimitiveType.Quads; case PrimitiveTopology.QuadStrip: +#pragma warning disable CS0618 // Type or member is obsolete return PrimitiveType.QuadStrip; +#pragma warning restore CS0618 // Type or member is obsolete case PrimitiveTopology.Polygon: return PrimitiveType.TriangleFan; case PrimitiveTopology.LinesAdjacency: diff --git a/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs b/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs index 704cbcd027..5e0ece3bf9 100644 --- a/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs +++ b/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs @@ -152,8 +152,10 @@ namespace Ryujinx.Graphics.OpenGL public static bool SupportsQuadsCheck(GL api) { api.GetError(); // Clear any existing error. +#pragma warning disable CS0618 // Type or member is obsolete api.Begin(PrimitiveType.Quads); api.End(); +#pragma warning restore CS0618 // Type or member is obsolete return api.GetError() == GLEnum.NoError; } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index 1e70ab3bad..a3a65b9b2b 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -464,7 +464,7 @@ namespace Ryujinx.Graphics.OpenGL.Image _copyPboSize = requiredSize; _gd.Api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); - _gd.Api.BufferData(BufferTargetARB.PixelPackBuffer, (uint)requiredSize, IntPtr.Zero, BufferUsageARB.DynamicCopy); + _gd.Api.BufferData(BufferTargetARB.PixelPackBuffer, (uint)requiredSize, in IntPtr.Zero, BufferUsageARB.DynamicCopy); } } diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index 33ef1b7d89..e80099499c 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -87,7 +87,7 @@ namespace Ryujinx.Graphics.OpenGL _copyBufferSize = requiredSize; _api.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); - _api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)requiredSize, IntPtr.Zero, BufferStorageMask.MapReadBit | BufferStorageMask.MapPersistentBit); + _api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)requiredSize, in IntPtr.Zero, BufferStorageMask.MapReadBit | BufferStorageMask.MapPersistentBit); _bufferMap = (IntPtr)_api.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, (uint)requiredSize, MapBufferAccessMask.ReadBit | MapBufferAccessMask.PersistentBit); } diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index d8aae8dd22..5f97fc25a0 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -238,7 +238,9 @@ namespace Ryujinx.Graphics.OpenGL { DrawQuadsImpl(vertexCount, instanceCount, firstVertex, firstInstance); } +#pragma warning disable CS0618 // Type or member is obsolete else if (_primitiveType == PrimitiveType.QuadStrip && !_gd.Capabilities.SupportsQuads) +#pragma warning restore CS0618 // Type or member is obsolete { DrawQuadStripImpl(vertexCount, instanceCount, firstVertex, firstInstance); } @@ -376,7 +378,9 @@ namespace Ryujinx.Graphics.OpenGL firstVertex, firstInstance); } +#pragma warning disable CS0618 // Type or member is obsolete else if (_primitiveType == PrimitiveType.QuadStrip && !_gd.Capabilities.SupportsQuads) +#pragma warning restore CS0618 // Type or member is obsolete { DrawQuadStripIndexedImpl( indexCount, @@ -476,7 +480,7 @@ namespace Ryujinx.Graphics.OpenGL PrimitiveType.TriangleFan, countsPtr, _elementsType, - indicesPtr, + in indicesPtr, (uint)quadsCount, baseVerticesPtr); } @@ -523,7 +527,7 @@ namespace Ryujinx.Graphics.OpenGL PrimitiveType.TriangleFan, countsPtr, _elementsType, - indicesPtr, + in indicesPtr, (uint)quadsCount, baseVerticesPtr); } @@ -538,7 +542,7 @@ namespace Ryujinx.Graphics.OpenGL { if (firstInstance == 0 && firstVertex == 0 && instanceCount == 1) { - _gd.Api.DrawElements(_primitiveType, (uint)indexCount, _elementsType, indexBaseOffset); + _gd.Api.DrawElements(_primitiveType, (uint)indexCount, _elementsType, in indexBaseOffset); } else if (firstInstance == 0 && instanceCount == 1) { @@ -546,7 +550,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - indexBaseOffset, + in indexBaseOffset, firstVertex); } else if (firstInstance == 0 && firstVertex == 0) @@ -555,7 +559,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - indexBaseOffset, + in indexBaseOffset, (uint)instanceCount); } else if (firstInstance == 0) @@ -564,7 +568,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - indexBaseOffset, + in indexBaseOffset, (uint)instanceCount, firstVertex); } @@ -574,7 +578,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - indexBaseOffset, + in indexBaseOffset, (uint)instanceCount, (uint)firstInstance); } @@ -584,7 +588,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - indexBaseOffset, + in indexBaseOffset, (uint)instanceCount, firstVertex, (uint)firstInstance); @@ -605,7 +609,7 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - _gd.Api.DrawElementsIndirect(_primitiveType, _elementsType, (IntPtr)indirectBuffer.Offset); + _gd.Api.DrawElementsIndirect(_primitiveType, _elementsType, indirectBuffer.Offset); _vertexArray.RestoreIndexBuffer(); @@ -630,7 +634,7 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.MultiDrawElementsIndirectCount( _primitiveType, _elementsType, - (IntPtr)indirectBuffer.Offset, + indirectBuffer.Offset, parameterBuffer.Offset, (uint)maxDrawCount, (uint)stride); @@ -652,7 +656,7 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - _gd.Api.DrawArraysIndirect(_primitiveType, (IntPtr)indirectBuffer.Offset); + _gd.Api.DrawArraysIndirect(_primitiveType, indirectBuffer.Offset); PostDraw(); } @@ -672,7 +676,7 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.MultiDrawArraysIndirectCount( _primitiveType, - (IntPtr)indirectBuffer.Offset, + indirectBuffer.Offset, parameterBuffer.Offset, (uint)maxDrawCount, (uint)stride); @@ -778,6 +782,7 @@ namespace Ryujinx.Graphics.OpenGL _tfEnabled = false; } +#pragma warning disable CS0618 // Type or member is obsolete public void SetAlphaTest(bool enable, float reference, CompareOp op) { if (!enable) @@ -789,6 +794,7 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.AlphaFunc((AlphaFunction)op.Convert(), reference); _gd.Api.Enable(EnableCap.AlphaTest); } +#pragma warning restore CS0618 // Type or member is obsolete public void SetBlendState(AdvancedBlendDescriptor blend) { @@ -1068,6 +1074,7 @@ namespace Ryujinx.Graphics.OpenGL } } +#pragma warning disable CS0618 // Type or member is obsolete public void SetPointParameters(float size, bool isProgramPointSize, bool enablePointSprite, Origin origin) { // GL_POINT_SPRITE was deprecated in core profile 3.2+ and causes GL_INVALID_ENUM when set. @@ -1098,6 +1105,7 @@ namespace Ryujinx.Graphics.OpenGL // From the spec, GL_INVALID_VALUE is generated if size is less than or equal to 0. _gd.Api.PointSize(Math.Max(float.Epsilon, size)); } +#pragma warning restore CS0618 // Type or member is obsolete public void SetPolygonMode(GAL.PolygonMode frontMode, GAL.PolygonMode backMode) { diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index 9c59f402b8..11a064fa12 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -93,7 +93,7 @@ namespace Ryujinx.Graphics.OpenGL { fixed (byte* ptr = code) { - _gd.Api.ProgramBinary(Handle, (GLEnum)binaryFormat, (IntPtr)ptr, (uint)code.Length - 4); + _gd.Api.ProgramBinary(Handle, (GLEnum)binaryFormat, ptr, (uint)code.Length - 4); } } } diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs index a033ad0bad..8c9ce1d284 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs @@ -27,12 +27,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries _type = type; _api.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); - - unsafe - { - long defaultValue = DefaultValue; - _api.BufferStorage(BufferStorageTarget.QueryBuffer, sizeof(long), (IntPtr)(&defaultValue), BufferStorageMask.MapReadBit | BufferStorageMask.MapWriteBit | BufferStorageMask.MapPersistentBit); - } + _api.BufferStorage(BufferStorageTarget.QueryBuffer, sizeof(long), DefaultValue, BufferStorageMask.MapReadBit | BufferStorageMask.MapWriteBit | BufferStorageMask.MapPersistentBit); unsafe { From 4ec9793602e0e4500498c136cb2a0693f5b34f24 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 9 May 2024 23:11:24 -0400 Subject: [PATCH 26/35] Style --- src/Ryujinx.Graphics.OpenGL/Framebuffer.cs | 2 +- src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs | 6 ++---- src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs | 6 ++---- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs index d458fcafc2..1a0ecf66b2 100644 --- a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -20,7 +20,7 @@ namespace Ryujinx.Graphics.OpenGL private int _colorsCount; private bool _dualSourceBlend; - private GL _api; + private readonly GL _api; public Framebuffer(GL api) { diff --git a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs index 1ecc64c67d..11c5f5be9e 100644 --- a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs +++ b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs @@ -9,13 +9,11 @@ namespace Ryujinx.UI { class SPBOpenGLContext : IOpenGLContext { - public readonly GL Api; private readonly OpenGLContextBase _context; private readonly NativeWindowBase _window; - private SPBOpenGLContext(GL api, OpenGLContextBase context, NativeWindowBase window) + private SPBOpenGLContext(OpenGLContextBase context, NativeWindowBase window) { - Api = api; _context = context; _window = window; } @@ -45,7 +43,7 @@ namespace Ryujinx.UI context.MakeCurrent(null); - return new SPBOpenGLContext(api, context, window); + return new SPBOpenGLContext(context, window); } } } diff --git a/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs b/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs index 2f7c54849d..0dc354ec65 100644 --- a/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs +++ b/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs @@ -9,13 +9,11 @@ namespace Ryujinx.Ava.UI.Renderer { class SPBOpenGLContext : IOpenGLContext { - private readonly GL _api; private readonly OpenGLContextBase _context; private readonly NativeWindowBase _window; - private SPBOpenGLContext(GL api, OpenGLContextBase context, NativeWindowBase window) + private SPBOpenGLContext(OpenGLContextBase context, NativeWindowBase window) { - _api = api; _context = context; _window = window; } @@ -45,7 +43,7 @@ namespace Ryujinx.Ava.UI.Renderer context.MakeCurrent(null); - return new SPBOpenGLContext(api, context, window); + return new SPBOpenGLContext(context, window); } } } From ccb3b083330eb10ad97b6196b587d4cf71fb63ed Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 10 May 2024 11:54:52 -0400 Subject: [PATCH 27/35] General cleanup --- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 14 +++++------- src/Ryujinx.Graphics.OpenGL/Debugger.cs | 22 +++++++++---------- src/Ryujinx.Graphics.OpenGL/Framebuffer.cs | 9 ++++---- .../Image/TextureCopyIncompatible.cs | 2 +- .../Image/TextureView.cs | 8 +++---- src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 14 +++++------- src/Ryujinx.Graphics.OpenGL/VertexArray.cs | 4 ++-- src/Ryujinx.Graphics.OpenGL/Window.cs | 2 +- src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs | 4 ---- src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs | 4 ---- 10 files changed, 34 insertions(+), 49 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index e5c2e07237..e7dcfbc3fe 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -78,20 +78,18 @@ namespace Ryujinx.Graphics.OpenGL { return new PinnedSpan(IntPtr.Add(ptr, offset).ToPointer(), size); } - else if (gd.Capabilities.UsePersistentBufferForFlush) + + if (gd.Capabilities.UsePersistentBufferForFlush) { return PinnedSpan.UnsafeFromSpan(gd.PersistentBuffers.Default.GetBufferData(buffer, offset, size)); } - else - { - IntPtr target = gd.PersistentBuffers.Default.GetHostArray(size); - gd.Api.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToUInt32()); + IntPtr target = gd.PersistentBuffers.Default.GetHostArray(size); - gd.Api.GetBufferSubData(BufferTargetARB.CopyReadBuffer, offset, (uint)size, (void*)target); + gd.Api.BindBuffer(BufferTargetARB.CopyReadBuffer, buffer.ToUInt32()); + gd.Api.GetBufferSubData(BufferTargetARB.CopyReadBuffer, offset, (uint)size, (void*)target); - return new PinnedSpan(target.ToPointer(), size); - } + return new PinnedSpan(target.ToPointer(), size); } public static void Resize(GL api, BufferHandle handle, int size) diff --git a/src/Ryujinx.Graphics.OpenGL/Debugger.cs b/src/Ryujinx.Graphics.OpenGL/Debugger.cs index 963bb0b5d7..1a3107ef39 100644 --- a/src/Ryujinx.Graphics.OpenGL/Debugger.cs +++ b/src/Ryujinx.Graphics.OpenGL/Debugger.cs @@ -28,18 +28,18 @@ namespace Ryujinx.Graphics.OpenGL gl.Enable(EnableCap.DebugOutputSynchronous); - if (logLevel == GraphicsDebugLevel.Error) + switch (logLevel) { - gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (uint[])null, true); - } - else if (logLevel == GraphicsDebugLevel.Slowdowns) - { - gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (uint[])null, true); - gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypePerformance, DebugSeverity.DontCare, 0, (uint[])null, true); - } - else - { - gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (uint[])null, true); + case GraphicsDebugLevel.Error: + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (uint[])null, true); + break; + case GraphicsDebugLevel.Slowdowns: + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypeError, DebugSeverity.DontCare, 0, (uint[])null, true); + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DebugTypePerformance, DebugSeverity.DontCare, 0, (uint[])null, true); + break; + default: + gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (uint[])null, true); + break; } _counter = 0; diff --git a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs index 1a0ecf66b2..91947b0ca2 100644 --- a/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Framebuffer.cs @@ -127,14 +127,13 @@ namespace Ryujinx.Graphics.OpenGL { return FramebufferAttachment.DepthStencilAttachment; } - else if (FormatTable.IsDepthOnly(format)) + + if (FormatTable.IsDepthOnly(format)) { return FramebufferAttachment.DepthAttachment; } - else - { - return FramebufferAttachment.StencilAttachment; - } + + return FramebufferAttachment.StencilAttachment; } public int GetColorLayerCount(int index) diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs index 26d14f5fb7..5ce8e3a0c7 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopyIncompatible.cs @@ -190,7 +190,7 @@ void main() { uint csHandle = _gd.Api.CreateShader(ShaderType.ComputeShader); - string[] formatTable = new[] { "r8ui", "r16ui", "r32ui", "rg8ui", "rg16ui", "rg32ui", "rgba8ui", "rgba16ui", "rgba32ui" }; + string[] formatTable = ["r8ui", "r16ui", "r32ui", "rg8ui", "rg16ui", "rg32ui", "rgba8ui", "rgba16ui", "rgba32ui"]; string srcFormat = formatTable[srcIndex]; string dstFormat = formatTable[dstIndex]; diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs index 5c40cc1776..e3a859ebeb 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureView.cs @@ -64,13 +64,13 @@ namespace Ryujinx.Graphics.OpenGL.Image _gd.Api.BindTexture(target, Handle); - int[] swizzleRgba = new int[] - { + int[] swizzleRgba = + [ (int)Info.SwizzleR.Convert(), (int)Info.SwizzleG.Convert(), (int)Info.SwizzleB.Convert(), - (int)Info.SwizzleA.Convert(), - }; + (int)Info.SwizzleA.Convert() + ]; if (Info.Format == Format.A1B5G5R5Unorm) { diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index deea560ac6..53b0715d69 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -76,13 +76,11 @@ namespace Ryujinx.Graphics.OpenGL return handle; } - else - { - return Buffer.Create(Api, size); - } + + return Buffer.Create(Api, size); } - public BufferHandle CreateBuffer(int size, GAL.BufferAccess access, BufferHandle storageHint) + public BufferHandle CreateBuffer(int size, BufferAccess access, BufferHandle storageHint) { return CreateBuffer(size, access); } @@ -118,10 +116,8 @@ namespace Ryujinx.Graphics.OpenGL { return new TextureBuffer(this, info); } - else - { - return ResourcePool.GetTextureOrNull(info) ?? new TextureStorage(this, info).CreateDefaultView(); - } + + return ResourcePool.GetTextureOrNull(info) ?? new TextureStorage(this, info).CreateDefaultView(); } public ITextureArray CreateTextureArray(int size, bool isBuffer) diff --git a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs index 4961f8a2d5..b5eca3bdf9 100644 --- a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -190,7 +190,7 @@ namespace Ryujinx.Graphics.OpenGL Buffer.Copy(_api, vb.Buffer.Handle, tempVertexBuffer, vb.Buffer.Offset, currentTempVbOffset, vb.Buffer.Size); Buffer.Clear(_api, tempVertexBuffer, currentTempVbOffset + vb.Buffer.Size, (uint)(requiredSize - vb.Buffer.Size), 0); - _api.BindVertexBuffer((uint)vbIndex, tempVertexBuffer.ToUInt32(), (IntPtr)currentTempVbOffset, (uint)vb.Stride); + _api.BindVertexBuffer((uint)vbIndex, tempVertexBuffer.ToUInt32(), currentTempVbOffset, (uint)vb.Stride); currentTempVbOffset += requiredSize; _vertexBuffersLimited |= 1u << vbIndex; @@ -236,7 +236,7 @@ namespace Ryujinx.Graphics.OpenGL ref var vb = ref _vertexBuffers[vbIndex]; - _api.BindVertexBuffer((uint)vbIndex, vb.Buffer.Handle.ToUInt32(), (IntPtr)vb.Buffer.Offset, (uint)vb.Stride); + _api.BindVertexBuffer((uint)vbIndex, vb.Buffer.Handle.ToUInt32(), vb.Buffer.Offset, (uint)vb.Stride); buffersLimited &= ~(1u << vbIndex); } diff --git a/src/Ryujinx.Graphics.OpenGL/Window.cs b/src/Ryujinx.Graphics.OpenGL/Window.cs index 0d04114f8f..56481ead3a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Window.cs +++ b/src/Ryujinx.Graphics.OpenGL/Window.cs @@ -83,7 +83,7 @@ namespace Ryujinx.Graphics.OpenGL { var swappedView = _gd.TextureCopy.BgraSwap(viewConverted); - viewConverted?.Dispose(); + viewConverted.Dispose(); viewConverted = swappedView; } diff --git a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs index 11c5f5be9e..21673d83f8 100644 --- a/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs +++ b/src/Ryujinx.Gtk3/UI/SPBOpenGLContext.cs @@ -1,5 +1,4 @@ using Ryujinx.Graphics.OpenGL; -using Silk.NET.OpenGL.Legacy; using SPB.Graphics; using SPB.Graphics.OpenGL; using SPB.Platform; @@ -38,9 +37,6 @@ namespace Ryujinx.UI context.Initialize(window); context.MakeCurrent(window); - - GL api = GL.GetApi(context.GetProcAddress); - context.MakeCurrent(null); return new SPBOpenGLContext(context, window); diff --git a/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs b/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs index 0dc354ec65..0085589ee3 100644 --- a/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs +++ b/src/Ryujinx/UI/Renderer/SPBOpenGLContext.cs @@ -1,5 +1,4 @@ using Ryujinx.Graphics.OpenGL; -using Silk.NET.OpenGL.Legacy; using SPB.Graphics; using SPB.Graphics.OpenGL; using SPB.Platform; @@ -38,9 +37,6 @@ namespace Ryujinx.Ava.UI.Renderer context.Initialize(window); context.MakeCurrent(window); - - GL api = GL.GetApi(context.GetProcAddress); - context.MakeCurrent(null); return new SPBOpenGLContext(context, window); From eff2d891c57d19aefc6bc59c7809432afe270287 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Fri, 10 May 2024 12:03:38 -0400 Subject: [PATCH 28/35] Resolve warnings --- .../Effects/ShaderHelper.cs | 3 ++- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 24 +++++++++++++------ .../Queries/BufferedQuery.cs | 4 +++- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs b/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs index dc406e84ae..a12cdd467d 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/ShaderHelper.cs @@ -23,7 +23,8 @@ namespace Ryujinx.Graphics.OpenGL.Effects public static uint CompileProgram(GL api, string[] shaders, ShaderType shaderType) { var shader = api.CreateShader(shaderType); - api.ShaderSource(shader, (uint)shaders.Length, shaders, 0); + var length = 0; + api.ShaderSource(shader, (uint)shaders.Length, shaders, in length); api.CompileShader(shader); var program = api.CreateProgram(); diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 5f97fc25a0..1ead524a1a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -419,11 +419,13 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { + var indices = indexBaseOffset + quadIndex * 4 * indexElemSize; + _gd.Api.DrawElementsInstancedBaseVertexBaseInstance( PrimitiveType.TriangleFan, 4, _elementsType, - indexBaseOffset + quadIndex * 4 * indexElemSize, + in indices, (uint)instanceCount, firstVertex, (uint)firstInstance); @@ -433,11 +435,13 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { + var indices = indexBaseOffset + quadIndex * 4 * indexElemSize; + _gd.Api.DrawElementsInstancedBaseInstance( PrimitiveType.TriangleFan, 4, _elementsType, - indexBaseOffset + quadIndex * 4 * indexElemSize, + in indices, (uint)instanceCount, (uint)firstInstance); } @@ -446,11 +450,13 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { + var indices = indexBaseOffset + quadIndex * 4 * indexElemSize; + _gd.Api.DrawElementsInstanced( PrimitiveType.TriangleFan, 4, _elementsType, - indexBaseOffset + quadIndex * 4 * indexElemSize, + in indices, (uint)instanceCount); } } @@ -609,7 +615,8 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - _gd.Api.DrawElementsIndirect(_primitiveType, _elementsType, indirectBuffer.Offset); + var offset = indirectBuffer.Offset; + _gd.Api.DrawElementsIndirect(_primitiveType, _elementsType, in offset); _vertexArray.RestoreIndexBuffer(); @@ -631,10 +638,11 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); _gd.Api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); + var offset = indirectBuffer.Offset; _gd.Api.MultiDrawElementsIndirectCount( _primitiveType, _elementsType, - indirectBuffer.Offset, + in offset, parameterBuffer.Offset, (uint)maxDrawCount, (uint)stride); @@ -656,7 +664,8 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - _gd.Api.DrawArraysIndirect(_primitiveType, indirectBuffer.Offset); + var offset = indirectBuffer.Offset; + _gd.Api.DrawArraysIndirect(_primitiveType, in offset); PostDraw(); } @@ -674,9 +683,10 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); _gd.Api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); + var offset = indirectBuffer.Offset; _gd.Api.MultiDrawArraysIndirectCount( _primitiveType, - indirectBuffer.Offset, + in offset, parameterBuffer.Offset, (uint)maxDrawCount, (uint)stride); diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs index 8c9ce1d284..03762eb784 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/BufferedQuery.cs @@ -27,7 +27,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries _type = type; _api.BindBuffer(BufferTargetARB.QueryBuffer, _buffer); - _api.BufferStorage(BufferStorageTarget.QueryBuffer, sizeof(long), DefaultValue, BufferStorageMask.MapReadBit | BufferStorageMask.MapWriteBit | BufferStorageMask.MapPersistentBit); + + var defaultValue = DefaultValue; + _api.BufferStorage(BufferStorageTarget.QueryBuffer, sizeof(long), in defaultValue, BufferStorageMask.MapReadBit | BufferStorageMask.MapWriteBit | BufferStorageMask.MapPersistentBit); unsafe { From 4aa0ea11d2a1af80e5ca6439af3dd325216d6707 Mon Sep 17 00:00:00 2001 From: IsaacMarovitz Date: Fri, 10 May 2024 13:21:07 -0400 Subject: [PATCH 29/35] Fix segfaults --- src/Ryujinx.Graphics.OpenGL/Buffer.cs | 12 ++++++------ src/Ryujinx.Graphics.OpenGL/Debugger.cs | 6 +++--- src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs | 4 ++-- src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Buffer.cs b/src/Ryujinx.Graphics.OpenGL/Buffer.cs index e7dcfbc3fe..d71b3233d0 100644 --- a/src/Ryujinx.Graphics.OpenGL/Buffer.cs +++ b/src/Ryujinx.Graphics.OpenGL/Buffer.cs @@ -32,22 +32,22 @@ namespace Ryujinx.Graphics.OpenGL return Handle.FromUInt32(api.GenBuffer()); } - public static BufferHandle Create(GL api, int size) + public unsafe static BufferHandle Create(GL api, int size) { uint handle = api.GenBuffer(); api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); - api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, in UIntPtr.Zero, BufferUsageARB.DynamicDraw); + api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, null, BufferUsageARB.DynamicDraw); return Handle.FromUInt32(handle); } - public static BufferHandle CreatePersistent(GL api, int size) + public unsafe static BufferHandle CreatePersistent(GL api, int size) { uint handle = api.GenBuffer(); api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle); - api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)size, in UIntPtr.Zero, + api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)size, null, BufferStorageMask.MapPersistentBit | BufferStorageMask.MapCoherentBit | BufferStorageMask.ClientStorageBit | @@ -92,10 +92,10 @@ namespace Ryujinx.Graphics.OpenGL return new PinnedSpan(target.ToPointer(), size); } - public static void Resize(GL api, BufferHandle handle, int size) + public unsafe static void Resize(GL api, BufferHandle handle, int size) { api.BindBuffer(BufferTargetARB.CopyWriteBuffer, handle.ToUInt32()); - api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, in UIntPtr.Zero, BufferUsageARB.StreamCopy); + api.BufferData(BufferTargetARB.CopyWriteBuffer, (uint)size, null, BufferUsageARB.StreamCopy); } public static void SetData(GL api, BufferHandle buffer, int offset, ReadOnlySpan data) diff --git a/src/Ryujinx.Graphics.OpenGL/Debugger.cs b/src/Ryujinx.Graphics.OpenGL/Debugger.cs index 1a3107ef39..e98cfb10f5 100644 --- a/src/Ryujinx.Graphics.OpenGL/Debugger.cs +++ b/src/Ryujinx.Graphics.OpenGL/Debugger.cs @@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.OpenGL private static int _counter; - public static void Initialize(GL gl, GraphicsDebugLevel logLevel) + public unsafe static void Initialize(GL gl, GraphicsDebugLevel logLevel) { // Disable everything gl.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (uint[])null, false); @@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.OpenGL if (logLevel == GraphicsDebugLevel.None) { gl.Disable(EnableCap.DebugOutputSynchronous); - gl.DebugMessageCallback(null, in IntPtr.Zero); + gl.DebugMessageCallback(null, null); return; } @@ -45,7 +45,7 @@ namespace Ryujinx.Graphics.OpenGL _counter = 0; _debugCallback = GLDebugHandler; - gl.DebugMessageCallback(_debugCallback, in IntPtr.Zero); + gl.DebugMessageCallback(_debugCallback, null); Logger.Warning?.Print(LogClass.Gpu, "OpenGL Debugging is enabled. Performance will be negatively impacted."); } diff --git a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs index a3a65b9b2b..93f9e13b67 100644 --- a/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs +++ b/src/Ryujinx.Graphics.OpenGL/Image/TextureCopy.cs @@ -442,7 +442,7 @@ namespace Ryujinx.Graphics.OpenGL.Image _gd.Api.BindBuffer(BufferTargetARB.PixelUnpackBuffer, 0); } - private void EnsurePbo(TextureView view) + private unsafe void EnsurePbo(TextureView view) { int requiredSize = 0; @@ -464,7 +464,7 @@ namespace Ryujinx.Graphics.OpenGL.Image _copyPboSize = requiredSize; _gd.Api.BindBuffer(BufferTargetARB.PixelPackBuffer, _copyPboHandle); - _gd.Api.BufferData(BufferTargetARB.PixelPackBuffer, (uint)requiredSize, in IntPtr.Zero, BufferUsageARB.DynamicCopy); + _gd.Api.BufferData(BufferTargetARB.PixelPackBuffer, (uint)requiredSize, null, BufferUsageARB.DynamicCopy); } } diff --git a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs index e80099499c..b578946eb8 100644 --- a/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs +++ b/src/Ryujinx.Graphics.OpenGL/PersistentBuffers.cs @@ -87,7 +87,7 @@ namespace Ryujinx.Graphics.OpenGL _copyBufferSize = requiredSize; _api.BindBuffer(BufferTargetARB.CopyWriteBuffer, _copyBufferHandle); - _api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)requiredSize, in IntPtr.Zero, BufferStorageMask.MapReadBit | BufferStorageMask.MapPersistentBit); + _api.BufferStorage(BufferStorageTarget.CopyWriteBuffer, (uint)requiredSize, null, BufferStorageMask.MapReadBit | BufferStorageMask.MapPersistentBit); _bufferMap = (IntPtr)_api.MapBufferRange(BufferTargetARB.CopyWriteBuffer, IntPtr.Zero, (uint)requiredSize, MapBufferAccessMask.ReadBit | MapBufferAccessMask.PersistentBit); } From 62b838850bb2b8f52b06b7020feb5e985f34da85 Mon Sep 17 00:00:00 2001 From: IsaacMarovitz Date: Sat, 11 May 2024 12:40:54 -0400 Subject: [PATCH 30/35] Fix Vertex Offset Pointers --- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 51 +++++++++------------- src/Ryujinx.Graphics.OpenGL/VertexArray.cs | 2 +- 2 files changed, 22 insertions(+), 31 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 1ead524a1a..2c49511ab5 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -419,13 +419,11 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - var indices = indexBaseOffset + quadIndex * 4 * indexElemSize; - _gd.Api.DrawElementsInstancedBaseVertexBaseInstance( PrimitiveType.TriangleFan, 4, _elementsType, - in indices, + (void*)(indexBaseOffset + quadIndex * 4 * indexElemSize), (uint)instanceCount, firstVertex, (uint)firstInstance); @@ -435,13 +433,11 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - var indices = indexBaseOffset + quadIndex * 4 * indexElemSize; - _gd.Api.DrawElementsInstancedBaseInstance( PrimitiveType.TriangleFan, 4, _elementsType, - in indices, + (void*)(indexBaseOffset + quadIndex * 4 * indexElemSize), (uint)instanceCount, (uint)firstInstance); } @@ -450,13 +446,11 @@ namespace Ryujinx.Graphics.OpenGL { for (int quadIndex = 0; quadIndex < quadsCount; quadIndex++) { - var indices = indexBaseOffset + quadIndex * 4 * indexElemSize; - _gd.Api.DrawElementsInstanced( PrimitiveType.TriangleFan, 4, _elementsType, - in indices, + (void*)(indexBaseOffset + quadIndex * 4 * indexElemSize), (uint)instanceCount); } } @@ -479,14 +473,14 @@ namespace Ryujinx.Graphics.OpenGL } fixed (uint* countsPtr = counts) - fixed (void* indicesPtr = indices) + fixed (void** indicesPtr = indices) fixed (int* baseVerticesPtr = baseVertices) { _gd.Api.MultiDrawElementsBaseVertex( PrimitiveType.TriangleFan, countsPtr, _elementsType, - in indicesPtr, + indicesPtr, (uint)quadsCount, baseVerticesPtr); } @@ -526,20 +520,20 @@ namespace Ryujinx.Graphics.OpenGL } fixed (uint* countsPtr = counts) - fixed (void* indicesPtr = indices) + fixed (void** indicesPtr = indices) fixed (int* baseVerticesPtr = baseVertices) { _gd.Api.MultiDrawElementsBaseVertex( PrimitiveType.TriangleFan, countsPtr, _elementsType, - in indicesPtr, + indicesPtr, (uint)quadsCount, baseVerticesPtr); } } - private void DrawIndexedImpl( + private unsafe void DrawIndexedImpl( int indexCount, int instanceCount, IntPtr indexBaseOffset, @@ -548,7 +542,7 @@ namespace Ryujinx.Graphics.OpenGL { if (firstInstance == 0 && firstVertex == 0 && instanceCount == 1) { - _gd.Api.DrawElements(_primitiveType, (uint)indexCount, _elementsType, in indexBaseOffset); + _gd.Api.DrawElements(_primitiveType, (uint)indexCount, _elementsType, (void*)indexBaseOffset); } else if (firstInstance == 0 && instanceCount == 1) { @@ -556,7 +550,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - in indexBaseOffset, + (void*)indexBaseOffset, firstVertex); } else if (firstInstance == 0 && firstVertex == 0) @@ -565,7 +559,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - in indexBaseOffset, + (void*)indexBaseOffset, (uint)instanceCount); } else if (firstInstance == 0) @@ -574,7 +568,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - in indexBaseOffset, + (void*)indexBaseOffset, (uint)instanceCount, firstVertex); } @@ -584,7 +578,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - in indexBaseOffset, + (void*)indexBaseOffset, (uint)instanceCount, (uint)firstInstance); } @@ -594,7 +588,7 @@ namespace Ryujinx.Graphics.OpenGL _primitiveType, (uint)indexCount, _elementsType, - in indexBaseOffset, + (void*)indexBaseOffset, (uint)instanceCount, firstVertex, (uint)firstInstance); @@ -623,7 +617,7 @@ namespace Ryujinx.Graphics.OpenGL PostDraw(); } - public void DrawIndexedIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride) + public unsafe void DrawIndexedIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride) { if (!_program.IsLinked) { @@ -638,11 +632,10 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); _gd.Api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); - var offset = indirectBuffer.Offset; _gd.Api.MultiDrawElementsIndirectCount( _primitiveType, _elementsType, - in offset, + (void*)indirectBuffer.Offset, parameterBuffer.Offset, (uint)maxDrawCount, (uint)stride); @@ -652,7 +645,7 @@ namespace Ryujinx.Graphics.OpenGL PostDraw(); } - public void DrawIndirect(BufferRange indirectBuffer) + public unsafe void DrawIndirect(BufferRange indirectBuffer) { if (!_program.IsLinked) { @@ -664,13 +657,12 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); - var offset = indirectBuffer.Offset; - _gd.Api.DrawArraysIndirect(_primitiveType, in offset); + _gd.Api.DrawArraysIndirect(_primitiveType, (void*)indirectBuffer.Offset); PostDraw(); } - public void DrawIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride) + public unsafe void DrawIndirectCount(BufferRange indirectBuffer, BufferRange parameterBuffer, int maxDrawCount, int stride) { if (!_program.IsLinked) { @@ -683,10 +675,9 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.BindBuffer(BufferTargetARB.DrawIndirectBuffer, indirectBuffer.Handle.ToUInt32()); _gd.Api.BindBuffer(BufferTargetARB.ParameterBuffer, parameterBuffer.Handle.ToUInt32()); - var offset = indirectBuffer.Offset; _gd.Api.MultiDrawArraysIndirectCount( _primitiveType, - in offset, + (void*)indirectBuffer.Offset, parameterBuffer.Offset, (uint)maxDrawCount, (uint)stride); @@ -1483,7 +1474,7 @@ namespace Ryujinx.Graphics.OpenGL if (buffer.Handle == BufferHandle.Null) { - _gd.Api.BindBufferRange(target, (uint)assignment.Binding, 0, IntPtr.Zero, 0); + _gd.Api.BindBufferRange(target, (uint)assignment.Binding, 0, 0, 0); continue; } diff --git a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs index b5eca3bdf9..854bdf976b 100644 --- a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -66,7 +66,7 @@ namespace Ryujinx.Graphics.OpenGL { if ((_vertexBuffersInUse & (1u << bindingIndex)) != 0) { - _api.BindVertexBuffer((uint)bindingIndex, 0, IntPtr.Zero, 0); + _api.BindVertexBuffer((uint)bindingIndex, 0, 0, 0); _vertexBuffersInUse &= ~(1u << bindingIndex); } } From b55ef55ab02571b0013d23351a2781b8d8863fcf Mon Sep 17 00:00:00 2001 From: IsaacMarovitz Date: Sat, 11 May 2024 13:32:35 -0400 Subject: [PATCH 31/35] Downgrade Silk.NET --- Directory.Packages.props | 10 ++--- .../Effects/FsrScalingFilter.cs | 6 +-- .../Effects/FxaaPostProcessingEffect.cs | 6 +-- .../Effects/SmaaPostProcessingEffect.cs | 12 ++--- src/Ryujinx.Graphics.OpenGL/EnumConversion.cs | 12 ++--- src/Ryujinx.Graphics.OpenGL/FormatTable.cs | 19 ++++---- .../HardwareCapabilities.cs | 2 +- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 44 ++++++++++--------- src/Ryujinx.Graphics.OpenGL/VertexArray.cs | 3 +- 9 files changed, 59 insertions(+), 55 deletions(-) diff --git a/Directory.Packages.props b/Directory.Packages.props index 86fb6c6888..ff91da5baf 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -38,10 +38,10 @@ - - - - + + + + @@ -52,4 +52,4 @@ - \ No newline at end of file + diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs index aff20db2f1..ba98a6574a 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FsrScalingFilter.cs @@ -120,10 +120,10 @@ namespace Ryujinx.Graphics.OpenGL.Effects var textureView = _intermediaryTexture.CreateView(_intermediaryTexture.Info, 0, 0) as TextureView; - uint previousProgram = (uint)_gd.Api.GetInteger(GetPName.CurrentProgram); - int previousUnit = _gd.Api.GetInteger(GetPName.ActiveTexture); + uint previousProgram = (uint)_gd.Api.GetInteger(GLEnum.CurrentProgram); + int previousUnit = _gd.Api.GetInteger(GLEnum.ActiveTexture); _gd.Api.ActiveTexture(TextureUnit.Texture0); - uint previousTextureBinding = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding = (uint)_gd.Api.GetInteger(GLEnum.TextureBinding2D); _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs index 1f54ad2aaf..511897a006 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/FxaaPostProcessingEffect.cs @@ -49,10 +49,10 @@ namespace Ryujinx.Graphics.OpenGL.Effects var textureView = _textureStorage.CreateView(view.Info, 0, 0) as TextureView; - uint previousProgram = (uint)_gd.Api.GetInteger(GetPName.CurrentProgram); - int previousUnit = _gd.Api.GetInteger(GetPName.ActiveTexture); + uint previousProgram = (uint)_gd.Api.GetInteger(GLEnum.CurrentProgram); + int previousUnit = _gd.Api.GetInteger(GLEnum.ActiveTexture); _gd.Api.ActiveTexture(TextureUnit.Texture0); - uint previousTextureBinding = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding = (uint)_gd.Api.GetInteger(GLEnum.TextureBinding2D); _gd.Api.BindImageTexture(0, textureView.Handle, 0, false, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); _gd.Api.UseProgram(_shaderProgram); diff --git a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs index 94fbe16734..37951d1689 100644 --- a/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs +++ b/src/Ryujinx.Graphics.OpenGL/Effects/SmaaPostProcessingEffect.cs @@ -184,14 +184,14 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa var areaTexture = _areaTexture.DefaultView as TextureView; var searchTexture = _searchTexture.DefaultView as TextureView; - uint previousFramebuffer = (uint)_gd.Api.GetInteger(GetPName.DrawFramebufferBinding); - int previousUnit = _gd.Api.GetInteger(GetPName.ActiveTexture); + uint previousFramebuffer = (uint)_gd.Api.GetInteger(GLEnum.DrawFramebufferBinding); + int previousUnit = _gd.Api.GetInteger(GLEnum.ActiveTexture); _gd.Api.ActiveTexture(TextureUnit.Texture0); - uint previousTextureBinding0 = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding0 = (uint)_gd.Api.GetInteger(GLEnum.TextureBinding2D); _gd.Api.ActiveTexture(TextureUnit.Texture1); - uint previousTextureBinding1 = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding1 = (uint)_gd.Api.GetInteger(GLEnum.TextureBinding2D); _gd.Api.ActiveTexture(TextureUnit.Texture2); - uint previousTextureBinding2 = (uint)_gd.Api.GetInteger(GetPName.TextureBinding2D); + uint previousTextureBinding2 = (uint)_gd.Api.GetInteger(GLEnum.TextureBinding2D); var framebuffer = new Framebuffer(_gd.Api); framebuffer.Bind(); @@ -209,7 +209,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa uint dispatchX = (uint)BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize); uint dispatchY = (uint)BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize); - uint previousProgram = (uint)_gd.Api.GetInteger(GetPName.CurrentProgram); + uint previousProgram = (uint)_gd.Api.GetInteger(GLEnum.CurrentProgram); _gd.Api.BindImageTexture(0, edgeOutput.Handle, 0, false, 0, BufferAccessARB.ReadWrite, InternalFormat.Rgba8); _gd.Api.UseProgram(_edgeShaderPrograms[Quality]); view.Bind(0); diff --git a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs index 75528e67b1..2f360c78d4 100644 --- a/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs +++ b/src/Ryujinx.Graphics.OpenGL/EnumConversion.cs @@ -14,9 +14,9 @@ namespace Ryujinx.Graphics.OpenGL switch (mode) { case AddressMode.Clamp: -#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable CS0612 // Type or member is obsolete return TextureWrapMode.Clamp; -#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore CS0612 // Type or member is obsolete case AddressMode.Repeat: return TextureWrapMode.Repeat; case AddressMode.MirrorClamp: @@ -35,9 +35,9 @@ namespace Ryujinx.Graphics.OpenGL Logger.Debug?.Print(LogClass.Gpu, $"Invalid {nameof(AddressMode)} enum value: {mode}."); -#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable CS0612 // Type or member is obsolete return TextureWrapMode.Clamp; -#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore CS0612 // Type or member is obsolete } public static NV Convert(this AdvancedBlendOp op) @@ -455,9 +455,9 @@ namespace Ryujinx.Graphics.OpenGL case PrimitiveTopology.Quads: return PrimitiveType.Quads; case PrimitiveTopology.QuadStrip: -#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable CS0612 // Type or member is obsolete return PrimitiveType.QuadStrip; -#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore CS0612 // Type or member is obsolete case PrimitiveTopology.Polygon: return PrimitiveType.TriangleFan; case PrimitiveTopology.LinesAdjacency: diff --git a/src/Ryujinx.Graphics.OpenGL/FormatTable.cs b/src/Ryujinx.Graphics.OpenGL/FormatTable.cs index 6492aa7f40..5a26a51cd7 100644 --- a/src/Ryujinx.Graphics.OpenGL/FormatTable.cs +++ b/src/Ryujinx.Graphics.OpenGL/FormatTable.cs @@ -1,5 +1,6 @@ using Ryujinx.Graphics.GAL; using Silk.NET.OpenGL.Legacy; +using Silk.NET.OpenGL.Legacy.Extensions.NV; using System; namespace Ryujinx.Graphics.OpenGL @@ -21,7 +22,7 @@ namespace Ryujinx.Graphics.OpenGL Add(Format.R8Snorm, new FormatInfo(1, true, false, InternalFormat.R8SNorm, PixelFormat.Red, PixelType.Byte)); Add(Format.R8Uint, new FormatInfo(1, false, false, InternalFormat.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte)); Add(Format.R8Sint, new FormatInfo(1, false, false, InternalFormat.R8i, PixelFormat.RedInteger, PixelType.Byte)); - Add(Format.R16Float, new FormatInfo(1, false, false, InternalFormat.R16f, PixelFormat.Red, PixelType.HalfFloat)); + Add(Format.R16Float, new FormatInfo(1, false, false, InternalFormat.R16f, PixelFormat.Red, (PixelType)NV.HalfFloatNV)); Add(Format.R16Unorm, new FormatInfo(1, true, false, InternalFormat.R16, PixelFormat.Red, PixelType.UnsignedShort)); Add(Format.R16Snorm, new FormatInfo(1, true, false, InternalFormat.R16SNorm, PixelFormat.Red, PixelType.Short)); Add(Format.R16Uint, new FormatInfo(1, false, false, InternalFormat.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort)); @@ -33,7 +34,7 @@ namespace Ryujinx.Graphics.OpenGL Add(Format.R8G8Snorm, new FormatInfo(2, true, false, InternalFormat.RG8SNorm, PixelFormat.RG, PixelType.Byte)); Add(Format.R8G8Uint, new FormatInfo(2, false, false, InternalFormat.RG8ui, PixelFormat.RGInteger, PixelType.UnsignedByte)); Add(Format.R8G8Sint, new FormatInfo(2, false, false, InternalFormat.RG8i, PixelFormat.RGInteger, PixelType.Byte)); - Add(Format.R16G16Float, new FormatInfo(2, false, false, InternalFormat.RG16f, PixelFormat.RG, PixelType.HalfFloat)); + Add(Format.R16G16Float, new FormatInfo(2, false, false, InternalFormat.RG16f, PixelFormat.RG, (PixelType)NV.HalfFloatNV)); Add(Format.R16G16Unorm, new FormatInfo(2, true, false, InternalFormat.RG16, PixelFormat.RG, PixelType.UnsignedShort)); Add(Format.R16G16Snorm, new FormatInfo(2, true, false, InternalFormat.RG16SNorm, PixelFormat.RG, PixelType.Short)); Add(Format.R16G16Uint, new FormatInfo(2, false, false, InternalFormat.RG16ui, PixelFormat.RGInteger, PixelType.UnsignedShort)); @@ -45,7 +46,7 @@ namespace Ryujinx.Graphics.OpenGL Add(Format.R8G8B8Snorm, new FormatInfo(3, true, false, InternalFormat.Rgb8SNorm, PixelFormat.Rgb, PixelType.Byte)); Add(Format.R8G8B8Uint, new FormatInfo(3, false, false, InternalFormat.Rgb8ui, PixelFormat.RgbInteger, PixelType.UnsignedByte)); Add(Format.R8G8B8Sint, new FormatInfo(3, false, false, InternalFormat.Rgb8i, PixelFormat.RgbInteger, PixelType.Byte)); - Add(Format.R16G16B16Float, new FormatInfo(3, false, false, InternalFormat.Rgb16f, PixelFormat.Rgb, PixelType.HalfFloat)); + Add(Format.R16G16B16Float, new FormatInfo(3, false, false, InternalFormat.Rgb16f, PixelFormat.Rgb, (PixelType)NV.HalfFloatNV)); Add(Format.R16G16B16Unorm, new FormatInfo(3, true, false, InternalFormat.Rgb16, PixelFormat.Rgb, PixelType.UnsignedShort)); Add(Format.R16G16B16Snorm, new FormatInfo(3, true, false, InternalFormat.Rgb16SNorm, PixelFormat.Rgb, PixelType.Short)); Add(Format.R16G16B16Uint, new FormatInfo(3, false, false, InternalFormat.Rgb16ui, PixelFormat.RgbInteger, PixelType.UnsignedShort)); @@ -57,7 +58,7 @@ namespace Ryujinx.Graphics.OpenGL Add(Format.R8G8B8A8Snorm, new FormatInfo(4, true, false, InternalFormat.Rgba8SNorm, PixelFormat.Rgba, PixelType.Byte)); Add(Format.R8G8B8A8Uint, new FormatInfo(4, false, false, InternalFormat.Rgba8ui, PixelFormat.RgbaInteger, PixelType.UnsignedByte)); Add(Format.R8G8B8A8Sint, new FormatInfo(4, false, false, InternalFormat.Rgba8i, PixelFormat.RgbaInteger, PixelType.Byte)); - Add(Format.R16G16B16A16Float, new FormatInfo(4, false, false, InternalFormat.Rgba16f, PixelFormat.Rgba, PixelType.HalfFloat)); + Add(Format.R16G16B16A16Float, new FormatInfo(4, false, false, InternalFormat.Rgba16f, PixelFormat.Rgba, (PixelType)NV.HalfFloatNV)); Add(Format.R16G16B16A16Unorm, new FormatInfo(4, true, false, InternalFormat.Rgba16, PixelFormat.Rgba, PixelType.UnsignedShort)); Add(Format.R16G16B16A16Snorm, new FormatInfo(4, true, false, InternalFormat.Rgba16SNorm, PixelFormat.Rgba, PixelType.Short)); Add(Format.R16G16B16A16Uint, new FormatInfo(4, false, false, InternalFormat.Rgba16ui, PixelFormat.RgbaInteger, PixelType.UnsignedShort)); @@ -67,11 +68,11 @@ namespace Ryujinx.Graphics.OpenGL Add(Format.R32G32B32A32Sint, new FormatInfo(4, false, false, InternalFormat.Rgba32i, PixelFormat.RgbaInteger, PixelType.Int)); Add(Format.S8Uint, new FormatInfo(1, false, false, InternalFormat.StencilIndex8, PixelFormat.StencilIndex, PixelType.UnsignedByte)); Add(Format.D16Unorm, new FormatInfo(1, false, false, InternalFormat.DepthComponent16, PixelFormat.DepthComponent, PixelType.UnsignedShort)); - Add(Format.S8UintD24Unorm, new FormatInfo(1, false, false, InternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248)); + Add(Format.S8UintD24Unorm, new FormatInfo(1, false, false, InternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, (PixelType)NV.UnsignedInt248NV)); Add(Format.X8UintD24Unorm, new FormatInfo(1, false, false, InternalFormat.DepthComponent24, PixelFormat.DepthComponent, PixelType.UnsignedInt)); Add(Format.D32Float, new FormatInfo(1, false, false, InternalFormat.DepthComponent32f, PixelFormat.DepthComponent, PixelType.Float)); - Add(Format.D24UnormS8Uint, new FormatInfo(1, false, false, InternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, PixelType.UnsignedInt248)); - Add(Format.D32FloatS8Uint, new FormatInfo(1, false, false, InternalFormat.Depth32fStencil8, PixelFormat.DepthStencil, PixelType.Float32UnsignedInt248Rev)); + Add(Format.D24UnormS8Uint, new FormatInfo(1, false, false, InternalFormat.Depth24Stencil8, PixelFormat.DepthStencil, (PixelType)NV.UnsignedInt248NV)); + Add(Format.D32FloatS8Uint, new FormatInfo(1, false, false, InternalFormat.Depth32fStencil8, PixelFormat.DepthStencil, (PixelType)NV.Float32UnsignedInt248RevNV)); Add(Format.R8G8B8A8Srgb, new FormatInfo(4, false, false, InternalFormat.Srgb8Alpha8, PixelFormat.Rgba, PixelType.UnsignedByte)); Add(Format.R4G4B4A4Unorm, new FormatInfo(4, true, false, InternalFormat.Rgba4, PixelFormat.Rgba, PixelType.UnsignedShort4444Rev)); Add(Format.R5G5B5X1Unorm, new FormatInfo(4, true, false, InternalFormat.Rgb5, PixelFormat.Rgb, PixelType.UnsignedShort1555Rev)); @@ -79,8 +80,8 @@ namespace Ryujinx.Graphics.OpenGL Add(Format.R5G6B5Unorm, new FormatInfo(3, true, false, InternalFormat.Rgb565, PixelFormat.Rgb, PixelType.UnsignedShort565Rev)); Add(Format.R10G10B10A2Unorm, new FormatInfo(4, true, false, InternalFormat.Rgb10A2, PixelFormat.Rgba, PixelType.UnsignedInt2101010Rev)); Add(Format.R10G10B10A2Uint, new FormatInfo(4, false, false, InternalFormat.Rgb10A2ui, PixelFormat.RgbaInteger, PixelType.UnsignedInt2101010Rev)); - Add(Format.R11G11B10Float, new FormatInfo(3, false, false, InternalFormat.R11fG11fB10f, PixelFormat.Rgb, PixelType.UnsignedInt10f11f11fRev)); - Add(Format.R9G9B9E5Float, new FormatInfo(3, false, false, InternalFormat.Rgb9E5, PixelFormat.Rgb, PixelType.UnsignedInt5999Rev)); + Add(Format.R11G11B10Float, new FormatInfo(3, false, false, InternalFormat.R11fG11fB10f, PixelFormat.Rgb, (PixelType)0x8C3B)); // GL_UNSIGNED_INT_10F_11F_11F_REV Defined in Updated Silk.NET + Add(Format.R9G9B9E5Float, new FormatInfo(3, false, false, InternalFormat.Rgb9E5, PixelFormat.Rgb, (PixelType)0x8C3E)); // GL_UNSIGNED_INT_5_9_9_9_REV Defined in Updated Silk.NET Add(Format.Bc1RgbaUnorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaS3TCDxt1Ext)); Add(Format.Bc2Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaS3TCDxt3Ext)); Add(Format.Bc3Unorm, new FormatInfo(4, true, false, InternalFormat.CompressedRgbaS3TCDxt5Ext)); diff --git a/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs b/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs index 5e0ece3bf9..f0d1fc5467 100644 --- a/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs +++ b/src/Ryujinx.Graphics.OpenGL/HardwareCapabilities.cs @@ -111,7 +111,7 @@ namespace Ryujinx.Graphics.OpenGL public static unsafe bool HasExtension(GL api, string name) { - int numExtensions = api.GetInteger(GetPName.NumExtensions); + int numExtensions = api.GetInteger(GLEnum.NumExtensions); for (uint extension = 0; extension < numExtensions; extension++) { diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 2c49511ab5..9e160565b4 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -150,7 +150,7 @@ namespace Ryujinx.Graphics.OpenGL if (stencilMaskChanged) { - _gd.Api.StencilMaskSeparate(TriangleFace.Front, (uint)stencilMask); + _gd.Api.StencilMaskSeparate(StencilFaceDirection.Front, (uint)stencilMask); } if (depthMaskChanged) @@ -176,7 +176,7 @@ namespace Ryujinx.Graphics.OpenGL if (stencilMaskChanged) { - _gd.Api.StencilMaskSeparate(TriangleFace.Front, (uint)_stencilFrontMask); + _gd.Api.StencilMaskSeparate(StencilFaceDirection.Front, (uint)_stencilFrontMask); } if (depthMaskChanged) @@ -193,11 +193,11 @@ namespace Ryujinx.Graphics.OpenGL } else if (depthMask) { - _gd.Api.ClearBuffer(BufferKind.Depth, 0, ref depthValue); + _gd.Api.ClearBuffer(BufferKind.Depth, 0, in depthValue); } else if (stencilMask != 0) { - _gd.Api.ClearBuffer(BufferKind.Stencil, 0, ref stencilValue); + _gd.Api.ClearBuffer(BufferKind.Stencil, 0, in stencilValue); } } @@ -238,9 +238,9 @@ namespace Ryujinx.Graphics.OpenGL { DrawQuadsImpl(vertexCount, instanceCount, firstVertex, firstInstance); } -#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable CS0612 // Type or member is obsolete else if (_primitiveType == PrimitiveType.QuadStrip && !_gd.Capabilities.SupportsQuads) -#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore CS0612 // Type or member is obsolete { DrawQuadStripImpl(vertexCount, instanceCount, firstVertex, firstInstance); } @@ -378,9 +378,9 @@ namespace Ryujinx.Graphics.OpenGL firstVertex, firstInstance); } -#pragma warning disable CS0618 // Type or member is obsolete +#pragma warning disable CS0612 // Type or member is obsolete else if (_primitiveType == PrimitiveType.QuadStrip && !_gd.Capabilities.SupportsQuads) -#pragma warning restore CS0618 // Type or member is obsolete +#pragma warning restore CS0612 // Type or member is obsolete { DrawQuadStripIndexedImpl( indexCount, @@ -436,7 +436,7 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.DrawElementsInstancedBaseInstance( PrimitiveType.TriangleFan, 4, - _elementsType, + (GLEnum)_elementsType, (void*)(indexBaseOffset + quadIndex * 4 * indexElemSize), (uint)instanceCount, (uint)firstInstance); @@ -577,7 +577,7 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.DrawElementsInstancedBaseInstance( _primitiveType, (uint)indexCount, - _elementsType, + (GLEnum)_elementsType, (void*)indexBaseOffset, (uint)instanceCount, (uint)firstInstance); @@ -783,6 +783,7 @@ namespace Ryujinx.Graphics.OpenGL _tfEnabled = false; } +#pragma warning disable CS0612 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete public void SetAlphaTest(bool enable, float reference, CompareOp op) { @@ -795,8 +796,9 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.AlphaFunc((AlphaFunction)op.Convert(), reference); _gd.Api.Enable(EnableCap.AlphaTest); } +#pragma warning restore CS0612 // Type or member is obsolete #pragma warning restore CS0618 // Type or member is obsolete - + public void SetBlendState(AdvancedBlendDescriptor blend) { if (_gd.Capabilities.SupportsBlendEquationAdvanced) @@ -1112,12 +1114,12 @@ namespace Ryujinx.Graphics.OpenGL { if (frontMode == backMode) { - _gd.Api.PolygonMode(TriangleFace.FrontAndBack, frontMode.Convert()); + _gd.Api.PolygonMode(MaterialFace.FrontAndBack, frontMode.Convert()); } else { - _gd.Api.PolygonMode(TriangleFace.Front, frontMode.Convert()); - _gd.Api.PolygonMode(TriangleFace.Back, backMode.Convert()); + _gd.Api.PolygonMode(MaterialFace.Front, frontMode.Convert()); + _gd.Api.PolygonMode(MaterialFace.Back, backMode.Convert()); } } @@ -1260,7 +1262,7 @@ namespace Ryujinx.Graphics.OpenGL } } - _gd.Api.ScissorArray(0, (uint)count, ref v[0]); + _gd.Api.ScissorArray(0, (uint)count, in v[0]); } public void SetStencilTest(StencilTestDescriptor stencilTest) @@ -1274,32 +1276,32 @@ namespace Ryujinx.Graphics.OpenGL } _gd.Api.StencilOpSeparate( - TriangleFace.Front, + StencilFaceDirection.Front, stencilTest.FrontSFail.Convert(), stencilTest.FrontDpFail.Convert(), stencilTest.FrontDpPass.Convert()); _gd.Api.StencilFuncSeparate( - TriangleFace.Front, + StencilFaceDirection.Front, (StencilFunction)stencilTest.FrontFunc.Convert(), stencilTest.FrontFuncRef, (uint)stencilTest.FrontFuncMask); - _gd.Api.StencilMaskSeparate(TriangleFace.Front, (uint)stencilTest.FrontMask); + _gd.Api.StencilMaskSeparate(StencilFaceDirection.Front, (uint)stencilTest.FrontMask); _gd.Api.StencilOpSeparate( - TriangleFace.Back, + StencilFaceDirection.Back, stencilTest.BackSFail.Convert(), stencilTest.BackDpFail.Convert(), stencilTest.BackDpPass.Convert()); _gd.Api.StencilFuncSeparate( - TriangleFace.Back, + StencilFaceDirection.Back, (StencilFunction)stencilTest.BackFunc.Convert(), stencilTest.BackFuncRef, (uint)stencilTest.BackFuncMask); - _gd.Api.StencilMaskSeparate(TriangleFace.Back, (uint)stencilTest.BackMask); + _gd.Api.StencilMaskSeparate(StencilFaceDirection.Back, (uint)stencilTest.BackMask); _gd.Api.Enable(EnableCap.StencilTest); diff --git a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs index 854bdf976b..398a2bb7cc 100644 --- a/src/Ryujinx.Graphics.OpenGL/VertexArray.cs +++ b/src/Ryujinx.Graphics.OpenGL/VertexArray.cs @@ -1,5 +1,6 @@ using Ryujinx.Graphics.GAL; using Silk.NET.OpenGL.Legacy; +using Silk.NET.OpenGL.Legacy.Extensions.NV; using System; using System.Numerics; using System.Runtime.CompilerServices; @@ -107,7 +108,7 @@ namespace Ryujinx.Graphics.OpenGL int size = fmtInfo.Components; bool isFloat = fmtInfo.PixelType == PixelType.Float || - fmtInfo.PixelType == PixelType.HalfFloat; + fmtInfo.PixelType == (PixelType)NV.HalfFloatNV; if (isFloat || fmtInfo.Normalized || fmtInfo.Scaled) { From 5495281775c73eb21898baf6486b21054a465f89 Mon Sep 17 00:00:00 2001 From: IsaacMarovitz Date: Sat, 11 May 2024 14:29:07 -0400 Subject: [PATCH 32/35] Formatting --- src/Ryujinx.Graphics.OpenGL/Pipeline.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs index 9e160565b4..c055a9f1a2 100644 --- a/src/Ryujinx.Graphics.OpenGL/Pipeline.cs +++ b/src/Ryujinx.Graphics.OpenGL/Pipeline.cs @@ -798,7 +798,7 @@ namespace Ryujinx.Graphics.OpenGL } #pragma warning restore CS0612 // Type or member is obsolete #pragma warning restore CS0618 // Type or member is obsolete - + public void SetBlendState(AdvancedBlendDescriptor blend) { if (_gd.Capabilities.SupportsBlendEquationAdvanced) From 121307abe2a67c1404fb1c60518dec4245f1840e Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Sun, 12 May 2024 11:31:51 -0400 Subject: [PATCH 33/35] Fix CounterQueue Query Target --- src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs index 449d006248..0a79c17a18 100644 --- a/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs +++ b/src/Ryujinx.Graphics.OpenGL/Queries/CounterQueueEvent.cs @@ -62,7 +62,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries return true; } - if (ClearCounter || Type == QueryTarget.TimeElapsed) + if (ClearCounter || Type == (QueryTarget)GLEnum.Timestamp) { result = 0; } From ead0265dba42f867235a4dabe40762eb40754f63 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 14 May 2024 12:28:35 -0400 Subject: [PATCH 34/35] Updated Capabilities --- src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs index 53b0715d69..ba775d3dd5 100644 --- a/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs +++ b/src/Ryujinx.Graphics.OpenGL/OpenGLRenderer.cs @@ -164,6 +164,7 @@ namespace Ryujinx.Graphics.OpenGL supportsBgraFormat: false, supportsR4G4Format: false, supportsR4G4B4A4Format: true, + supportsScaledVertexFormats: true, supportsSnormBufferTextureFormat: false, supports5BitComponentFormat: true, supportsSparseBuffer: false, @@ -178,7 +179,7 @@ namespace Ryujinx.Graphics.OpenGL supportsMismatchingViewFormat: Capabilities.SupportsMismatchingViewFormat, supportsCubemapView: true, supportsNonConstantTextureOffset: Capabilities.SupportsNonConstantTextureOffset, - supportsScaledVertexFormats: true, + supportsQuads: Capabilities.SupportsQuads, supportsSeparateSampler: false, supportsShaderBallot: Capabilities.SupportsShaderBallot, supportsShaderBarrierDivergence: !(intelWindows || intelUnix), From 91f63270cce92e741e1c6d31c5059cf7a789cc7c Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Tue, 14 May 2024 12:30:34 -0400 Subject: [PATCH 35/35] Sunshine Fixes --- src/Ryujinx.Graphics.OpenGL/Program.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Ryujinx.Graphics.OpenGL/Program.cs b/src/Ryujinx.Graphics.OpenGL/Program.cs index 11a064fa12..b96f009586 100644 --- a/src/Ryujinx.Graphics.OpenGL/Program.cs +++ b/src/Ryujinx.Graphics.OpenGL/Program.cs @@ -62,7 +62,7 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.CompileShader(shaderHandle); break; case TargetLanguage.Spirv: - fixed (byte* ptr = shader.BinaryCode.AsSpan()) + fixed (byte* ptr = shader.BinaryCode) { _gd.Api.ShaderBinary(1, in shaderHandle, ShaderBinaryFormat.ShaderBinaryFormatSpirV, ptr, (uint)shader.BinaryCode.Length); } @@ -146,7 +146,7 @@ namespace Ryujinx.Graphics.OpenGL { _gd.Api.GetProgram(Handle, ProgramPropertyARB.ProgramBinaryLength, out int size); - byte[] data = new byte[size]; + byte[] data = new byte[size + 4]; GLEnum binFormat; fixed (byte* ptr = data) @@ -154,7 +154,7 @@ namespace Ryujinx.Graphics.OpenGL _gd.Api.GetProgramBinary(Handle, (uint)size, out _, out binFormat, ptr); } - BinaryPrimitives.WriteInt32LittleEndian(data, (int)binFormat); + BinaryPrimitives.WriteInt32LittleEndian(data.AsSpan(size, 4), (int)binFormat); return data; }