[Ryujinx.Graphics.OpenGL] Address dotnet-format issues (#5372)

* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Restore a few unused methods and variables

* Silence dotnet format IDE0060 warnings

* Address or silence dotnet format IDE1006 warnings

* Fix IDE0090 after rebase

* Address most dotnet format whitespace warnings

* Apply dotnet format whitespace formatting

A few of them have been manually reverted and the corresponding warning was silenced

* Format if-blocks correctly

* Another rebase, another dotnet format run

* Run dotnet format after rebase and remove unused usings

- analyzers
- style
- whitespace

* Add comments to disabled warnings

* Simplify properties and array initialization, Use const when possible, Remove trailing commas

* Start working on disabled warnings

* Address a few disabled IDE0060 warnings

* Silence IDE0060 in .editorconfig

* Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas"

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* First dotnet format pass

* Address review feedback
This commit is contained in:
TSRBerry 2023-06-28 18:10:55 +02:00 committed by GitHub
parent 9288ffd26d
commit 40f2bd37e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 198 additions and 197 deletions

View File

@ -9,12 +9,12 @@ namespace Ryujinx.Graphics.OpenGL
{ {
[ThreadStatic] [ThreadStatic]
public static bool InBackground; public static bool InBackground;
private Thread _thread; private readonly Thread _thread;
private bool _running; private bool _running;
private AutoResetEvent _signal; private readonly AutoResetEvent _signal;
private Queue<Action> _work; private readonly Queue<Action> _work;
private ObjectPool<ManualResetEventSlim> _invokePool; private readonly ObjectPool<ManualResetEventSlim> _invokePool;
private readonly IOpenGLContext _backgroundContext; private readonly IOpenGLContext _backgroundContext;
public BackgroundContextWorker(IOpenGLContext backgroundContext) public BackgroundContextWorker(IOpenGLContext backgroundContext)

View File

@ -63,10 +63,18 @@ namespace Ryujinx.Graphics.OpenGL
switch (type) switch (type)
{ {
case DebugType.DebugTypeError : Logger.Error?.Print(LogClass.Gpu, $"{severity}: {msg}\nCallStack={Environment.StackTrace}", "GLERROR"); break; case DebugType.DebugTypeError:
case DebugType.DebugTypePerformance: Logger.Warning?.Print(LogClass.Gpu, $"{severity}: {msg}", "GLPERF"); break; Logger.Error?.Print(LogClass.Gpu, $"{severity}: {msg}\nCallStack={Environment.StackTrace}", "GLERROR");
case DebugType.DebugTypePushGroup : Logger.Info?.Print(LogClass.Gpu, $"{{ ({id}) {severity}: {msg}", "GLINFO"); break; break;
case DebugType.DebugTypePopGroup : Logger.Info?.Print(LogClass.Gpu, $"}} ({id}) {severity}: {msg}", "GLINFO"); break; case DebugType.DebugTypePerformance:
Logger.Warning?.Print(LogClass.Gpu, $"{severity}: {msg}", "GLPERF");
break;
case DebugType.DebugTypePushGroup:
Logger.Info?.Print(LogClass.Gpu, $"{{ ({id}) {severity}: {msg}", "GLINFO");
break;
case DebugType.DebugTypePopGroup:
Logger.Info?.Print(LogClass.Gpu, $"}} ({id}) {severity}: {msg}", "GLINFO");
break;
default: default:
if (source == DebugSource.DebugSourceApplication) if (source == DebugSource.DebugSourceApplication)
{ {

View File

@ -65,16 +65,12 @@ void main()
if (x0 > x1) if (x0 > x1)
{ {
float temp = s0; (s1, s0) = (s0, s1);
s0 = s1;
s1 = temp;
} }
if (y0 > y1) if (y0 > y1)
{ {
float temp = t0; (t1, t0) = (t0, t1);
t0 = t1;
t1 = temp;
} }
GL.Uniform1(_uniformSrcX0Location, s0); GL.Uniform1(_uniformSrcX0Location, s0);

View File

@ -37,7 +37,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects
} }
} }
public FsrScalingFilter(OpenGLRenderer renderer, IPostProcessingEffect filter) public FsrScalingFilter(OpenGLRenderer renderer)
{ {
Initialize(); Initialize();

View File

@ -1,5 +1,4 @@
using OpenTK.Graphics.OpenGL; using OpenTK.Graphics.OpenGL;
using System;
namespace Ryujinx.Graphics.OpenGL.Effects namespace Ryujinx.Graphics.OpenGL.Effects
{ {

View File

@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.OpenGL.Effects.Smaa
private int[] _neighbourShaderPrograms; private int[] _neighbourShaderPrograms;
private TextureStorage _edgeOutputTexture; private TextureStorage _edgeOutputTexture;
private TextureStorage _blendOutputTexture; private TextureStorage _blendOutputTexture;
private string[] _qualities; private readonly string[] _qualities;
private int _inputUniform; private int _inputUniform;
private int _outputUniform; private int _outputUniform;
private int _samplerAreaUniform; private int _samplerAreaUniform;

View File

@ -4,10 +4,10 @@ using System;
namespace Ryujinx.Graphics.OpenGL namespace Ryujinx.Graphics.OpenGL
{ {
struct FormatTable readonly struct FormatTable
{ {
private static FormatInfo[] _table; private static readonly FormatInfo[] _table;
private static SizedInternalFormat[] _tableImage; private static readonly SizedInternalFormat[] _tableImage;
static FormatTable() static FormatTable()
{ {
@ -16,6 +16,7 @@ namespace Ryujinx.Graphics.OpenGL
_table = new FormatInfo[tableSize]; _table = new FormatInfo[tableSize];
_tableImage = new SizedInternalFormat[tableSize]; _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.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.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.R8Uint, new FormatInfo(1, false, false, All.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte));
@ -200,6 +201,7 @@ namespace Ryujinx.Graphics.OpenGL
Add(Format.R10G10B10A2Unorm, (SizedInternalFormat)All.Rgb10A2); Add(Format.R10G10B10A2Unorm, (SizedInternalFormat)All.Rgb10A2);
Add(Format.R10G10B10A2Uint, (SizedInternalFormat)All.Rgb10A2ui); Add(Format.R10G10B10A2Uint, (SizedInternalFormat)All.Rgb10A2ui);
Add(Format.R11G11B10Float, (SizedInternalFormat)All.R11fG11fB10f); Add(Format.R11G11B10Float, (SizedInternalFormat)All.R11fG11fB10f);
#pragma warning restore IDE0055
} }
private static void Add(Format format, FormatInfo info) private static void Add(Format format, FormatInfo info)

View File

@ -105,7 +105,7 @@ namespace Ryujinx.Graphics.OpenGL
_colorsCount = colorsCount; _colorsCount = colorsCount;
} }
private void SetDrawBuffersImpl(int colorsCount) private static void SetDrawBuffersImpl(int colorsCount)
{ {
DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[colorsCount]; DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[colorsCount];

View File

@ -5,30 +5,30 @@ namespace Ryujinx.Graphics.OpenGL
{ {
static class HwCapabilities static class HwCapabilities
{ {
private static readonly Lazy<bool> _supportsAlphaToCoverageDitherControl = new Lazy<bool>(() => HasExtension("GL_NV_alpha_to_coverage_dither_control")); private static readonly Lazy<bool> _supportsAlphaToCoverageDitherControl = new(() => HasExtension("GL_NV_alpha_to_coverage_dither_control"));
private static readonly Lazy<bool> _supportsAstcCompression = new Lazy<bool>(() => HasExtension("GL_KHR_texture_compression_astc_ldr")); private static readonly Lazy<bool> _supportsAstcCompression = new(() => HasExtension("GL_KHR_texture_compression_astc_ldr"));
private static readonly Lazy<bool> _supportsBlendEquationAdvanced = new Lazy<bool>(() => HasExtension("GL_NV_blend_equation_advanced")); private static readonly Lazy<bool> _supportsBlendEquationAdvanced = new(() => HasExtension("GL_NV_blend_equation_advanced"));
private static readonly Lazy<bool> _supportsDrawTexture = new Lazy<bool>(() => HasExtension("GL_NV_draw_texture")); private static readonly Lazy<bool> _supportsDrawTexture = new(() => HasExtension("GL_NV_draw_texture"));
private static readonly Lazy<bool> _supportsFragmentShaderInterlock = new Lazy<bool>(() => HasExtension("GL_ARB_fragment_shader_interlock")); private static readonly Lazy<bool> _supportsFragmentShaderInterlock = new(() => HasExtension("GL_ARB_fragment_shader_interlock"));
private static readonly Lazy<bool> _supportsFragmentShaderOrdering = new Lazy<bool>(() => HasExtension("GL_INTEL_fragment_shader_ordering")); private static readonly Lazy<bool> _supportsFragmentShaderOrdering = new(() => HasExtension("GL_INTEL_fragment_shader_ordering"));
private static readonly Lazy<bool> _supportsGeometryShaderPassthrough = new Lazy<bool>(() => HasExtension("GL_NV_geometry_shader_passthrough")); private static readonly Lazy<bool> _supportsGeometryShaderPassthrough = new(() => HasExtension("GL_NV_geometry_shader_passthrough"));
private static readonly Lazy<bool> _supportsImageLoadFormatted = new Lazy<bool>(() => HasExtension("GL_EXT_shader_image_load_formatted")); private static readonly Lazy<bool> _supportsImageLoadFormatted = new(() => HasExtension("GL_EXT_shader_image_load_formatted"));
private static readonly Lazy<bool> _supportsIndirectParameters = new Lazy<bool>(() => HasExtension("GL_ARB_indirect_parameters")); private static readonly Lazy<bool> _supportsIndirectParameters = new(() => HasExtension("GL_ARB_indirect_parameters"));
private static readonly Lazy<bool> _supportsParallelShaderCompile = new Lazy<bool>(() => HasExtension("GL_ARB_parallel_shader_compile")); private static readonly Lazy<bool> _supportsParallelShaderCompile = new(() => HasExtension("GL_ARB_parallel_shader_compile"));
private static readonly Lazy<bool> _supportsPolygonOffsetClamp = new Lazy<bool>(() => HasExtension("GL_EXT_polygon_offset_clamp")); private static readonly Lazy<bool> _supportsPolygonOffsetClamp = new(() => HasExtension("GL_EXT_polygon_offset_clamp"));
private static readonly Lazy<bool> _supportsQuads = new Lazy<bool>(SupportsQuadsCheck); private static readonly Lazy<bool> _supportsQuads = new(SupportsQuadsCheck);
private static readonly Lazy<bool> _supportsSeamlessCubemapPerTexture = new Lazy<bool>(() => HasExtension("GL_ARB_seamless_cubemap_per_texture")); private static readonly Lazy<bool> _supportsSeamlessCubemapPerTexture = new(() => HasExtension("GL_ARB_seamless_cubemap_per_texture"));
private static readonly Lazy<bool> _supportsShaderBallot = new Lazy<bool>(() => HasExtension("GL_ARB_shader_ballot")); private static readonly Lazy<bool> _supportsShaderBallot = new(() => HasExtension("GL_ARB_shader_ballot"));
private static readonly Lazy<bool> _supportsShaderViewportLayerArray = new Lazy<bool>(() => HasExtension("GL_ARB_shader_viewport_layer_array")); private static readonly Lazy<bool> _supportsShaderViewportLayerArray = new(() => HasExtension("GL_ARB_shader_viewport_layer_array"));
private static readonly Lazy<bool> _supportsViewportArray2 = new Lazy<bool>(() => HasExtension("GL_NV_viewport_array2")); private static readonly Lazy<bool> _supportsViewportArray2 = new(() => HasExtension("GL_NV_viewport_array2"));
private static readonly Lazy<bool> _supportsTextureCompressionBptc = new Lazy<bool>(() => HasExtension("GL_EXT_texture_compression_bptc")); private static readonly Lazy<bool> _supportsTextureCompressionBptc = new(() => HasExtension("GL_EXT_texture_compression_bptc"));
private static readonly Lazy<bool> _supportsTextureCompressionRgtc = new Lazy<bool>(() => HasExtension("GL_EXT_texture_compression_rgtc")); private static readonly Lazy<bool> _supportsTextureCompressionRgtc = new(() => HasExtension("GL_EXT_texture_compression_rgtc"));
private static readonly Lazy<bool> _supportsTextureCompressionS3tc = new Lazy<bool>(() => HasExtension("GL_EXT_texture_compression_s3tc")); private static readonly Lazy<bool> _supportsTextureCompressionS3tc = new(() => HasExtension("GL_EXT_texture_compression_s3tc"));
private static readonly Lazy<bool> _supportsTextureShadowLod = new Lazy<bool>(() => HasExtension("GL_EXT_texture_shadow_lod")); private static readonly Lazy<bool> _supportsTextureShadowLod = new(() => HasExtension("GL_EXT_texture_shadow_lod"));
private static readonly Lazy<bool> _supportsViewportSwizzle = new Lazy<bool>(() => HasExtension("GL_NV_viewport_swizzle")); private static readonly Lazy<bool> _supportsViewportSwizzle = new(() => HasExtension("GL_NV_viewport_swizzle"));
private static readonly Lazy<int> _maximumComputeSharedMemorySize = new Lazy<int>(() => GetLimit(All.MaxComputeSharedMemorySize)); private static readonly Lazy<int> _maximumComputeSharedMemorySize = new(() => GetLimit(All.MaxComputeSharedMemorySize));
private static readonly Lazy<int> _storageBufferOffsetAlignment = new Lazy<int>(() => GetLimit(All.ShaderStorageBufferOffsetAlignment)); private static readonly Lazy<int> _storageBufferOffsetAlignment = new(() => GetLimit(All.ShaderStorageBufferOffsetAlignment));
public enum GpuVendor public enum GpuVendor
{ {
@ -40,14 +40,13 @@ namespace Ryujinx.Graphics.OpenGL
Nvidia Nvidia
} }
private static readonly Lazy<GpuVendor> _gpuVendor = new Lazy<GpuVendor>(GetGpuVendor); private static readonly Lazy<GpuVendor> _gpuVendor = new(GetGpuVendor);
private static bool _isAMD => _gpuVendor.Value == GpuVendor.AmdWindows || _gpuVendor.Value == GpuVendor.AmdUnix; private static bool IsIntel => _gpuVendor.Value == GpuVendor.IntelWindows || _gpuVendor.Value == GpuVendor.IntelUnix;
private static bool _isIntel => _gpuVendor.Value == GpuVendor.IntelWindows || _gpuVendor.Value == GpuVendor.IntelUnix;
public static GpuVendor Vendor => _gpuVendor.Value; public static GpuVendor Vendor => _gpuVendor.Value;
private static Lazy<float> _maxSupportedAnisotropy = new Lazy<float>(GL.GetFloat((GetPName)All.MaxTextureMaxAnisotropy)); private static readonly Lazy<float> _maxSupportedAnisotropy = new(GL.GetFloat((GetPName)All.MaxTextureMaxAnisotropy));
public static bool UsePersistentBufferForFlush => _gpuVendor.Value == GpuVendor.AmdWindows || _gpuVendor.Value == GpuVendor.Nvidia; public static bool UsePersistentBufferForFlush => _gpuVendor.Value == GpuVendor.AmdWindows || _gpuVendor.Value == GpuVendor.Nvidia;
@ -75,7 +74,7 @@ namespace Ryujinx.Graphics.OpenGL
public static bool SupportsMismatchingViewFormat => _gpuVendor.Value != GpuVendor.AmdWindows && _gpuVendor.Value != GpuVendor.IntelWindows; public static bool SupportsMismatchingViewFormat => _gpuVendor.Value != GpuVendor.AmdWindows && _gpuVendor.Value != GpuVendor.IntelWindows;
public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia; public static bool SupportsNonConstantTextureOffset => _gpuVendor.Value == GpuVendor.Nvidia;
public static bool RequiresSyncFlush => _gpuVendor.Value == GpuVendor.AmdWindows || _isIntel; public static bool RequiresSyncFlush => _gpuVendor.Value == GpuVendor.AmdWindows || IsIntel;
public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value; public static int MaximumComputeSharedMemorySize => _maximumComputeSharedMemorySize.Value;
public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value; public static int StorageBufferOffsetAlignment => _storageBufferOffsetAlignment.Value;

View File

@ -7,7 +7,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{ {
class TextureBuffer : TextureBase, ITexture class TextureBuffer : TextureBase, ITexture
{ {
private OpenGLRenderer _renderer; private readonly OpenGLRenderer _renderer;
private int _bufferOffset; private int _bufferOffset;
private int _bufferSize; private int _bufferSize;
private int _bufferCount; private int _bufferCount;
@ -58,7 +58,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{ {
var dataSpan = data.AsSpan(); var dataSpan = data.AsSpan();
Buffer.SetData(_buffer, _bufferOffset, dataSpan.Slice(0, Math.Min(dataSpan.Length, _bufferSize))); Buffer.SetData(_buffer, _bufferOffset, dataSpan[..Math.Min(dataSpan.Length, _bufferSize)]);
} }
public void SetData(SpanOrArray<byte> data, int layer, int level) public void SetData(SpanOrArray<byte> data, int layer, int level)

View File

@ -1,5 +1,4 @@
using OpenTK.Graphics.OpenGL; using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@ -81,9 +80,6 @@ void main()
public void CopyIncompatibleFormats(ITextureInfo src, ITextureInfo dst, int srcLayer, int dstLayer, int srcLevel, int dstLevel, int depth, int levels) public void CopyIncompatibleFormats(ITextureInfo src, ITextureInfo dst, int srcLayer, int dstLayer, int srcLevel, int dstLevel, int depth, int levels)
{ {
TextureCreateInfo srcInfo = src.Info;
TextureCreateInfo dstInfo = dst.Info;
int srcBpp = src.Info.BytesPerPixel; int srcBpp = src.Info.BytesPerPixel;
int dstBpp = dst.Info.BytesPerPixel; int dstBpp = dst.Info.BytesPerPixel;
@ -176,7 +172,7 @@ void main()
return GetShader(ComputeShaderWidening, _wideningProgramHandles, componentSize, srcComponentsCount, dstComponentsCount); return GetShader(ComputeShaderWidening, _wideningProgramHandles, componentSize, srcComponentsCount, dstComponentsCount);
} }
private int GetShader( private static int GetShader(
string code, string code,
Dictionary<int, int> programHandles, Dictionary<int, int> programHandles,
int componentSize, int componentSize,

View File

@ -94,8 +94,8 @@ void main()
}"; }";
private readonly OpenGLRenderer _renderer; private readonly OpenGLRenderer _renderer;
private int[] _msToNonMSProgramHandles; private readonly int[] _msToNonMSProgramHandles;
private int[] _nonMSToMSProgramHandles; private readonly int[] _nonMSToMSProgramHandles;
public TextureCopyMS(OpenGLRenderer renderer) public TextureCopyMS(OpenGLRenderer renderer)
{ {
@ -219,7 +219,7 @@ void main()
return GetShader(ComputeShaderNonMSToMS, _nonMSToMSProgramHandles, bytesPerPixel); return GetShader(ComputeShaderNonMSToMS, _nonMSToMSProgramHandles, bytesPerPixel);
} }
private int GetShader(string code, int[] programHandles, int bytesPerPixel) private static int GetShader(string code, int[] programHandles, int bytesPerPixel)
{ {
int index = BitOperations.Log2((uint)bytesPerPixel); int index = BitOperations.Log2((uint)bytesPerPixel);

View File

@ -88,9 +88,7 @@ namespace Ryujinx.Graphics.OpenGL.Image
{ {
// Swap B <-> R for BGRA formats, as OpenGL has no support for them // Swap B <-> R for BGRA formats, as OpenGL has no support for them
// and we need to manually swap the components on read/write on the GPU. // and we need to manually swap the components on read/write on the GPU.
int temp = swizzleRgba[0]; (swizzleRgba[2], swizzleRgba[0]) = (swizzleRgba[0], swizzleRgba[2]);
swizzleRgba[0] = swizzleRgba[2];
swizzleRgba[2] = temp;
} }
GL.TexParameter(target, TextureParameterName.TextureSwizzleRgba, swizzleRgba); GL.TexParameter(target, TextureParameterName.TextureSwizzleRgba, swizzleRgba);
@ -186,8 +184,8 @@ namespace Ryujinx.Graphics.OpenGL.Image
// This approach uses blit, which causes a resolution loss since some samples will be lost // This approach uses blit, which causes a resolution loss since some samples will be lost
// in the process. // in the process.
Extents2D srcRegion = new Extents2D(0, 0, Width, Height); Extents2D srcRegion = new(0, 0, Width, Height);
Extents2D dstRegion = new Extents2D(0, 0, destinationView.Width, destinationView.Height); Extents2D dstRegion = new(0, 0, destinationView.Width, destinationView.Height);
if (destinationView.Target.IsMultisample()) if (destinationView.Target.IsMultisample())
{ {

View File

@ -21,13 +21,13 @@ namespace Ryujinx.Graphics.OpenGL
public IWindow Window => _window; public IWindow Window => _window;
private TextureCopy _textureCopy; private readonly TextureCopy _textureCopy;
private TextureCopy _backgroundTextureCopy; private readonly TextureCopy _backgroundTextureCopy;
internal TextureCopy TextureCopy => BackgroundContextWorker.InBackground ? _backgroundTextureCopy : _textureCopy; internal TextureCopy TextureCopy => BackgroundContextWorker.InBackground ? _backgroundTextureCopy : _textureCopy;
internal TextureCopyIncompatible TextureCopyIncompatible { get; } internal TextureCopyIncompatible TextureCopyIncompatible { get; }
internal TextureCopyMS TextureCopyMS { get; } internal TextureCopyMS TextureCopyMS { get; }
private Sync _sync; private readonly Sync _sync;
public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured; public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;

View File

@ -11,10 +11,10 @@ namespace Ryujinx.Graphics.OpenGL
{ {
class PersistentBuffers : IDisposable class PersistentBuffers : IDisposable
{ {
private PersistentBuffer _main = new PersistentBuffer(); private readonly PersistentBuffer _main = new();
private PersistentBuffer _background = new PersistentBuffer(); private readonly PersistentBuffer _background = new();
private Dictionary<BufferHandle, IntPtr> _maps = new Dictionary<BufferHandle, IntPtr>(); private readonly Dictionary<BufferHandle, IntPtr> _maps = new();
public PersistentBuffer Default => BackgroundContextWorker.InBackground ? _background : _main; public PersistentBuffer Default => BackgroundContextWorker.InBackground ? _background : _main;
@ -91,7 +91,7 @@ namespace Ryujinx.Graphics.OpenGL
return _dataMap; return _dataMap;
} }
private void Sync() private static void Sync()
{ {
GL.MemoryBarrier(MemoryBarrierFlags.ClientMappedBufferBarrierBit); GL.MemoryBarrier(MemoryBarrierFlags.ClientMappedBufferBarrierBit);
@ -133,7 +133,7 @@ namespace Ryujinx.Graphics.OpenGL
Sync(); Sync();
return new ReadOnlySpan<byte>(_bufferMap.ToPointer(), size).Slice(offset); return new ReadOnlySpan<byte>(_bufferMap.ToPointer(), size)[offset..];
} }
public unsafe ReadOnlySpan<byte> GetBufferData(BufferHandle buffer, int offset, int size) public unsafe ReadOnlySpan<byte> GetBufferData(BufferHandle buffer, int offset, int size)

View File

@ -44,11 +44,11 @@ namespace Ryujinx.Graphics.OpenGL
private CounterQueueEvent _activeConditionalRender; private CounterQueueEvent _activeConditionalRender;
private Vector4<int>[] _fpIsBgra = new Vector4<int>[SupportBuffer.FragmentIsBgraCount]; private readonly Vector4<int>[] _fpIsBgra = new Vector4<int>[SupportBuffer.FragmentIsBgraCount];
private Vector4<float>[] _renderScale = new Vector4<float>[73]; private readonly Vector4<float>[] _renderScale = new Vector4<float>[73];
private int _fragmentScaleCount; private int _fragmentScaleCount;
private (TextureBase, Format)[] _images; private readonly (TextureBase, Format)[] _images;
private TextureBase _unit0Texture; private TextureBase _unit0Texture;
private Sampler _unit0Sampler; private Sampler _unit0Sampler;
@ -260,7 +260,7 @@ namespace Ryujinx.Graphics.OpenGL
PostDraw(); PostDraw();
} }
private void DrawQuadsImpl( private static void DrawQuadsImpl(
int vertexCount, int vertexCount,
int instanceCount, int instanceCount,
int firstVertex, int firstVertex,
@ -285,7 +285,7 @@ namespace Ryujinx.Graphics.OpenGL
quadsCount); quadsCount);
} }
private void DrawQuadStripImpl( private static void DrawQuadStripImpl(
int vertexCount, int vertexCount,
int instanceCount, int instanceCount,
int firstVertex, int firstVertex,
@ -366,8 +366,12 @@ namespace Ryujinx.Graphics.OpenGL
switch (_elementsType) switch (_elementsType)
{ {
case DrawElementsType.UnsignedShort: indexElemSize = 2; break; case DrawElementsType.UnsignedShort:
case DrawElementsType.UnsignedInt: indexElemSize = 4; break; indexElemSize = 2;
break;
case DrawElementsType.UnsignedInt:
indexElemSize = 4;
break;
} }
IntPtr indexBaseOffset = _indexBaseOffset + firstIndex * indexElemSize; IntPtr indexBaseOffset = _indexBaseOffset + firstIndex * indexElemSize;
@ -1471,7 +1475,7 @@ namespace Ryujinx.Graphics.OpenGL
GL.MemoryBarrier(MemoryBarrierFlags.TextureFetchBarrierBit); GL.MemoryBarrier(MemoryBarrierFlags.TextureFetchBarrierBit);
} }
private void SetBuffers(ReadOnlySpan<BufferAssignment> buffers, bool isStorage) private static void SetBuffers(ReadOnlySpan<BufferAssignment> buffers, bool isStorage)
{ {
BufferRangeTarget target = isStorage ? BufferRangeTarget.ShaderStorageBuffer : BufferRangeTarget.UniformBuffer; BufferRangeTarget target = isStorage ? BufferRangeTarget.ShaderStorageBuffer : BufferRangeTarget.UniformBuffer;
@ -1700,12 +1704,10 @@ namespace Ryujinx.Graphics.OpenGL
} }
public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual) public bool TryHostConditionalRendering(ICounterEvent value, ulong compare, bool isEqual)
{
if (value is CounterQueueEvent)
{ {
// Compare an event and a constant value. // Compare an event and a constant value.
CounterQueueEvent evt = (CounterQueueEvent)value; if (value is CounterQueueEvent evt)
{
// Easy host conditional rendering when the check matches what GL can do: // Easy host conditional rendering when the check matches what GL can do:
// - Event is of type samples passed. // - Event is of type samples passed.
// - Result is not a combination of multiple queries. // - Result is not a combination of multiple queries.

View File

@ -123,7 +123,7 @@ namespace Ryujinx.Graphics.OpenGL
if (log.Length > MaxShaderLogLength) if (log.Length > MaxShaderLogLength)
{ {
log = log.Substring(0, MaxShaderLogLength) + "..."; log = log[..MaxShaderLogLength] + "...";
} }
Logger.Warning?.Print(LogClass.Gpu, $"Shader linking failed: \n{log}"); Logger.Warning?.Print(LogClass.Gpu, $"Shader linking failed: \n{log}");

View File

@ -14,9 +14,9 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public int Query { get; } public int Query { get; }
private int _buffer; private readonly int _buffer;
private IntPtr _bufferMap; private readonly IntPtr _bufferMap;
private QueryTarget _type; private readonly QueryTarget _type;
public BufferedQuery(QueryTarget type) public BufferedQuery(QueryTarget type)
{ {
@ -64,7 +64,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
} }
} }
private bool WaitingForValue(long data) private static bool WaitingForValue(long data)
{ {
return data == DefaultValue || return data == DefaultValue ||
((ulong)data & HighMask) == (unchecked((ulong)DefaultValue) & HighMask); ((ulong)data & HighMask) == (unchecked((ulong)DefaultValue) & HighMask);

View File

@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
private readonly Pipeline _pipeline; private readonly Pipeline _pipeline;
private Queue<CounterQueueEvent> _events = new Queue<CounterQueueEvent>(); private readonly Queue<CounterQueueEvent> _events = new();
private CounterQueueEvent _current; private CounterQueueEvent _current;
private ulong _accumulatedCounter; private ulong _accumulatedCounter;
@ -23,12 +23,12 @@ namespace Ryujinx.Graphics.OpenGL.Queries
private readonly object _lock = new(); private readonly object _lock = new();
private Queue<BufferedQuery> _queryPool; private readonly Queue<BufferedQuery> _queryPool;
private AutoResetEvent _queuedEvent = new AutoResetEvent(false); private readonly AutoResetEvent _queuedEvent = new(false);
private AutoResetEvent _wakeSignal = new AutoResetEvent(false); private readonly AutoResetEvent _wakeSignal = new(false);
private AutoResetEvent _eventConsumed = new AutoResetEvent(false); private readonly AutoResetEvent _eventConsumed = new(false);
private Thread _consumerThread; private readonly Thread _consumerThread;
internal CounterQueue(Pipeline pipeline, CounterType type) internal CounterQueue(Pipeline pipeline, CounterType type)
{ {
@ -148,14 +148,13 @@ namespace Ryujinx.Graphics.OpenGL.Queries
private static QueryTarget GetTarget(CounterType type) private static QueryTarget GetTarget(CounterType type)
{ {
switch (type) return type switch
{ {
case CounterType.SamplesPassed: return QueryTarget.SamplesPassed; CounterType.SamplesPassed => QueryTarget.SamplesPassed,
case CounterType.PrimitivesGenerated: return QueryTarget.PrimitivesGenerated; CounterType.PrimitivesGenerated => QueryTarget.PrimitivesGenerated,
case CounterType.TransformFeedbackPrimitivesWritten: return QueryTarget.TransformFeedbackPrimitivesWritten; CounterType.TransformFeedbackPrimitivesWritten => QueryTarget.TransformFeedbackPrimitivesWritten,
} _ => QueryTarget.SamplesPassed,
};
return QueryTarget.SamplesPassed;
} }
public void Flush(bool blocking) public void Flush(bool blocking)

View File

@ -18,8 +18,8 @@ namespace Ryujinx.Graphics.OpenGL.Queries
public ulong DrawIndex { get; } public ulong DrawIndex { get; }
private CounterQueue _queue; private readonly CounterQueue _queue;
private BufferedQuery _counter; private readonly BufferedQuery _counter;
private bool _hostAccessReserved = false; private bool _hostAccessReserved = false;
private int _refCount = 1; // Starts with a reference from the counter queue. private int _refCount = 1; // Starts with a reference from the counter queue.

View File

@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.OpenGL.Queries
{ {
class Counters : IDisposable class Counters : IDisposable
{ {
private CounterQueue[] _counterQueues; private readonly CounterQueue[] _counterQueues;
public Counters() public Counters()
{ {

View File

@ -21,7 +21,7 @@ namespace Ryujinx.Graphics.OpenGL
private const int DisposedLiveFrames = 2; private const int DisposedLiveFrames = 2;
private readonly object _lock = new(); private readonly object _lock = new();
private readonly Dictionary<TextureCreateInfo, List<DisposedTexture>> _textures = new Dictionary<TextureCreateInfo, List<DisposedTexture>>(); private readonly Dictionary<TextureCreateInfo, List<DisposedTexture>> _textures = new();
/// <summary> /// <summary>
/// Add a texture that is not being used anymore to the resource pool to be used later. /// Add a texture that is not being used anymore to the resource pool to be used later.
@ -32,8 +32,7 @@ namespace Ryujinx.Graphics.OpenGL
{ {
lock (_lock) lock (_lock)
{ {
List<DisposedTexture> list; if (!_textures.TryGetValue(view.Info, out List<DisposedTexture> list))
if (!_textures.TryGetValue(view.Info, out list))
{ {
list = new List<DisposedTexture>(); list = new List<DisposedTexture>();
_textures.Add(view.Info, list); _textures.Add(view.Info, list);
@ -59,8 +58,7 @@ namespace Ryujinx.Graphics.OpenGL
{ {
lock (_lock) lock (_lock)
{ {
List<DisposedTexture> list; if (!_textures.TryGetValue(info, out List<DisposedTexture> list))
if (!_textures.TryGetValue(info, out list))
{ {
return null; return null;
} }

View File

@ -15,13 +15,13 @@ namespace Ryujinx.Graphics.OpenGL
} }
private ulong _firstHandle = 0; private ulong _firstHandle = 0;
private ClientWaitSyncFlags _syncFlags => HwCapabilities.RequiresSyncFlush ? ClientWaitSyncFlags.None : ClientWaitSyncFlags.SyncFlushCommandsBit; private static ClientWaitSyncFlags SyncFlags => HwCapabilities.RequiresSyncFlush ? ClientWaitSyncFlags.None : ClientWaitSyncFlags.SyncFlushCommandsBit;
private List<SyncHandle> _handles = new List<SyncHandle>(); private readonly List<SyncHandle> _handles = new();
public void Create(ulong id) public void Create(ulong id)
{ {
SyncHandle handle = new SyncHandle SyncHandle handle = new()
{ {
ID = id, ID = id,
Handle = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None) Handle = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None)
@ -57,7 +57,7 @@ namespace Ryujinx.Graphics.OpenGL
if (handle.ID > lastHandle) if (handle.ID > lastHandle)
{ {
WaitSyncStatus syncResult = GL.ClientWaitSync(handle.Handle, _syncFlags, 0); WaitSyncStatus syncResult = GL.ClientWaitSync(handle.Handle, SyncFlags, 0);
if (syncResult == WaitSyncStatus.AlreadySignaled) if (syncResult == WaitSyncStatus.AlreadySignaled)
{ {
@ -101,7 +101,7 @@ namespace Ryujinx.Graphics.OpenGL
return; return;
} }
WaitSyncStatus syncResult = GL.ClientWaitSync(result.Handle, _syncFlags, 1000000000); WaitSyncStatus syncResult = GL.ClientWaitSync(result.Handle, SyncFlags, 1000000000);
if (syncResult == WaitSyncStatus.TimeoutExpired) if (syncResult == WaitSyncStatus.TimeoutExpired)
{ {
@ -123,9 +123,12 @@ namespace Ryujinx.Graphics.OpenGL
first = _handles.FirstOrDefault(); first = _handles.FirstOrDefault();
} }
if (first == null) break; if (first == null)
{
break;
}
WaitSyncStatus syncResult = GL.ClientWaitSync(first.Handle, _syncFlags, 0); WaitSyncStatus syncResult = GL.ClientWaitSync(first.Handle, SyncFlags, 0);
if (syncResult == WaitSyncStatus.AlreadySignaled) if (syncResult == WaitSyncStatus.AlreadySignaled)
{ {
@ -140,7 +143,8 @@ namespace Ryujinx.Graphics.OpenGL
first.Handle = IntPtr.Zero; first.Handle = IntPtr.Zero;
} }
} }
} else }
else
{ {
// This sync handle and any following have not been reached yet. // This sync handle and any following have not been reached yet.
break; break;

View File

@ -20,7 +20,7 @@ namespace Ryujinx.Graphics.OpenGL
private uint _vertexBuffersLimited; private uint _vertexBuffersLimited;
private BufferRange _indexBuffer; private BufferRange _indexBuffer;
private BufferHandle _tempIndexBuffer; private readonly BufferHandle _tempIndexBuffer;
private BufferHandle _tempVertexBuffer; private BufferHandle _tempVertexBuffer;
private int _tempVertexBufferSize; private int _tempVertexBufferSize;

View File

@ -375,7 +375,7 @@ namespace Ryujinx.Graphics.OpenGL
if (_scalingFilter is not FsrScalingFilter) if (_scalingFilter is not FsrScalingFilter)
{ {
_scalingFilter?.Dispose(); _scalingFilter?.Dispose();
_scalingFilter = new FsrScalingFilter(_renderer, _antiAliasing); _scalingFilter = new FsrScalingFilter(_renderer);
} }
_isLinear = false; _isLinear = false;
_scalingFilter.Level = _scalingFilterLevel; _scalingFilter.Level = _scalingFilterLevel;