Merge branch 'master' into features/crash-verification-ex

This commit is contained in:
kekkon 2023-06-25 21:03:36 +02:00 committed by GitHub
commit 2df17641e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
81 changed files with 417 additions and 382 deletions

View file

@ -39,10 +39,15 @@
<key>CSResourcesFileMapped</key>
<true/>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018 - 2022 Ryujinx Team and Contributors.</string>
<string>Copyright © 2018 - 2023 Ryujinx Team and Contributors.</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.games</string>
<key>LSMinimumSystemVersion</key>
<string>11.0</string>
<key>LSEnvironment</key>
<dict>
<key>COMPlus_DefaultStackSize</key>
<string>200000</string>
</dict>
</dict>
</plist>

View file

@ -228,7 +228,6 @@ namespace ARMeilleure.Instructions
switch (context.Fpcr.GetRoundingMode())
{
default:
case FPRoundingMode.ToNearest:
roundUp = (error > 0.5d || (error == 0.5d && (intMant & 1u) == 1u));
overflowToInf = true;
@ -248,6 +247,9 @@ namespace ARMeilleure.Instructions
roundUp = false;
overflowToInf = false;
break;
default:
throw new ArgumentException($"Invalid rounding mode \"{context.Fpcr.GetRoundingMode()}\".");
}
if (roundUp)
@ -412,7 +414,6 @@ namespace ARMeilleure.Instructions
switch (context.Fpcr.GetRoundingMode())
{
default:
case FPRoundingMode.ToNearest:
roundUp = (error > 0.5d || (error == 0.5d && (intMant & 1u) == 1u));
overflowToInf = true;
@ -432,6 +433,9 @@ namespace ARMeilleure.Instructions
roundUp = false;
overflowToInf = false;
break;
default:
throw new ArgumentException($"Invalid rounding mode \"{context.Fpcr.GetRoundingMode()}\".");
}
if (roundUp)
@ -585,7 +589,6 @@ namespace ARMeilleure.Instructions
switch (context.Fpcr.GetRoundingMode())
{
default:
case FPRoundingMode.ToNearest:
roundUp = (error > 0.5d || (error == 0.5d && (intMant & 1u) == 1u));
overflowToInf = true;
@ -605,6 +608,9 @@ namespace ARMeilleure.Instructions
roundUp = false;
overflowToInf = false;
break;
default:
throw new ArgumentException($"Invalid rounding mode \"{context.Fpcr.GetRoundingMode()}\".");
}
if (roundUp)
@ -1433,11 +1439,24 @@ namespace ARMeilleure.Instructions
switch (fpcr.GetRoundingMode())
{
case FPRoundingMode.ToNearest:
overflowToInf = true;
break;
case FPRoundingMode.TowardsPlusInfinity:
overflowToInf = !sign;
break;
case FPRoundingMode.TowardsMinusInfinity:
overflowToInf = sign;
break;
case FPRoundingMode.TowardsZero:
overflowToInf = false;
break;
default:
case FPRoundingMode.ToNearest: overflowToInf = true; break;
case FPRoundingMode.TowardsPlusInfinity: overflowToInf = !sign; break;
case FPRoundingMode.TowardsMinusInfinity: overflowToInf = sign; break;
case FPRoundingMode.TowardsZero: overflowToInf = false; break;
throw new ArgumentException($"Invalid rounding mode \"{fpcr.GetRoundingMode()}\".");
}
result = overflowToInf ? FPInfinity(sign) : FPMaxNormal(sign);
@ -2845,11 +2864,24 @@ namespace ARMeilleure.Instructions
switch (fpcr.GetRoundingMode())
{
case FPRoundingMode.ToNearest:
overflowToInf = true;
break;
case FPRoundingMode.TowardsPlusInfinity:
overflowToInf = !sign;
break;
case FPRoundingMode.TowardsMinusInfinity:
overflowToInf = sign;
break;
case FPRoundingMode.TowardsZero:
overflowToInf = false;
break;
default:
case FPRoundingMode.ToNearest: overflowToInf = true; break;
case FPRoundingMode.TowardsPlusInfinity: overflowToInf = !sign; break;
case FPRoundingMode.TowardsMinusInfinity: overflowToInf = sign; break;
case FPRoundingMode.TowardsZero: overflowToInf = false; break;
throw new ArgumentException($"Invalid rounding mode \"{fpcr.GetRoundingMode()}\".");
}
result = overflowToInf ? FPInfinity(sign) : FPMaxNormal(sign);

View file

@ -6,7 +6,7 @@ namespace ARMeilleure.Memory
{
IntPtr Pointer { get; }
bool Commit(ulong offset, ulong size);
void Commit(ulong offset, ulong size);
void MapAsRx(ulong offset, ulong size);
void MapAsRwx(ulong offset, ulong size);

View file

@ -13,8 +13,8 @@ namespace ARMeilleure.State
// _e0 & _e1 could be marked as readonly, however they are not readonly because we modify them through the Unsafe
// APIs. This also means that one should be careful when changing the layout of this struct.
private ulong _e0;
private ulong _e1;
private readonly ulong _e0;
private readonly ulong _e1;
/// <summary>
/// Gets a new <see cref="V128"/> with all bits set to zero.

View file

@ -18,7 +18,7 @@ namespace Ryujinx.Audio.Backends.OpenAL
private readonly ManualResetEvent _pauseEvent;
private readonly ConcurrentDictionary<OpenALHardwareDeviceSession, byte> _sessions;
private bool _stillRunning;
private Thread _updaterThread;
private readonly Thread _updaterThread;
public OpenALHardwareDeviceDriver()
{
@ -73,7 +73,7 @@ namespace Ryujinx.Audio.Backends.OpenAL
throw new ArgumentException($"{channelCount}");
}
OpenALHardwareDeviceSession session = new OpenALHardwareDeviceSession(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
OpenALHardwareDeviceSession session = new(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
_sessions.TryAdd(session, 0);
@ -123,6 +123,7 @@ namespace Ryujinx.Audio.Backends.OpenAL
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}

View file

@ -10,11 +10,11 @@ namespace Ryujinx.Audio.Backends.OpenAL
{
class OpenALHardwareDeviceSession : HardwareDeviceSessionOutputBase
{
private OpenALHardwareDeviceDriver _driver;
private int _sourceId;
private ALFormat _targetFormat;
private readonly OpenALHardwareDeviceDriver _driver;
private readonly int _sourceId;
private readonly ALFormat _targetFormat;
private bool _isActive;
private Queue<OpenALAudioBuffer> _queuedBuffers;
private readonly Queue<OpenALAudioBuffer> _queuedBuffers;
private ulong _playedSampleCount;
private readonly object _lock = new();
@ -32,23 +32,17 @@ namespace Ryujinx.Audio.Backends.OpenAL
private ALFormat GetALFormat()
{
switch (RequestedSampleFormat)
return RequestedSampleFormat switch
{
case SampleFormat.PcmInt16:
switch (RequestedChannelCount)
{
case 1:
return ALFormat.Mono16;
case 2:
return ALFormat.Stereo16;
case 6:
return ALFormat.Multi51Chn16Ext;
default:
throw new NotImplementedException($"Unsupported channel config {RequestedChannelCount}");
}
default:
throw new NotImplementedException($"Unsupported sample format {RequestedSampleFormat}");
}
SampleFormat.PcmInt16 => RequestedChannelCount switch
{
1 => ALFormat.Mono16,
2 => ALFormat.Stereo16,
6 => ALFormat.Multi51Chn16Ext,
_ => throw new NotImplementedException($"Unsupported channel config {RequestedChannelCount}"),
},
_ => throw new NotImplementedException($"Unsupported sample format {RequestedSampleFormat}"),
};
}
public override void PrepareToClose() { }
@ -69,7 +63,7 @@ namespace Ryujinx.Audio.Backends.OpenAL
{
lock (_lock)
{
OpenALAudioBuffer driverBuffer = new OpenALAudioBuffer
OpenALAudioBuffer driverBuffer = new()
{
DriverIdentifier = buffer.DataPointer,
BufferId = AL.GenBuffer(),

View file

@ -10,19 +10,19 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native
private const string LibraryName = "libsoundio";
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void OnDeviceChangeNativeDelegate(IntPtr ctx);
public delegate void OnDeviceChangeNativeDelegate(IntPtr ctx);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void OnBackendDisconnectedDelegate(IntPtr ctx, SoundIoError err);
public delegate void OnBackendDisconnectedDelegate(IntPtr ctx, SoundIoError err);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void OnEventsSignalDelegate(IntPtr ctx);
public delegate void OnEventsSignalDelegate(IntPtr ctx);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void EmitRtPrioWarningDelegate();
public delegate void EmitRtPrioWarningDelegate();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public unsafe delegate void JackCallbackDelegate(IntPtr msg);
public delegate void JackCallbackDelegate(IntPtr msg);
[StructLayout(LayoutKind.Sequential)]
public struct SoundIoStruct
@ -110,69 +110,69 @@ namespace Ryujinx.Audio.Backends.SoundIo.Native
}
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_create();
internal static partial IntPtr soundio_create();
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_connect(IntPtr ctx);
internal static partial SoundIoError soundio_connect(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial void soundio_disconnect(IntPtr ctx);
internal static partial void soundio_disconnect(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial void soundio_flush_events(IntPtr ctx);
internal static partial void soundio_flush_events(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial int soundio_output_device_count(IntPtr ctx);
internal static partial int soundio_output_device_count(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial int soundio_default_output_device_index(IntPtr ctx);
internal static partial int soundio_default_output_device_index(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_get_output_device(IntPtr ctx, int index);
internal static partial IntPtr soundio_get_output_device(IntPtr ctx, int index);
[LibraryImport(LibraryName)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool soundio_device_supports_format(IntPtr devCtx, SoundIoFormat format);
internal static partial bool soundio_device_supports_format(IntPtr devCtx, SoundIoFormat format);
[LibraryImport(LibraryName)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool soundio_device_supports_layout(IntPtr devCtx, IntPtr layout);
internal static partial bool soundio_device_supports_layout(IntPtr devCtx, IntPtr layout);
[LibraryImport(LibraryName)]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool soundio_device_supports_sample_rate(IntPtr devCtx, int sampleRate);
internal static partial bool soundio_device_supports_sample_rate(IntPtr devCtx, int sampleRate);
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_outstream_create(IntPtr devCtx);
internal static partial IntPtr soundio_outstream_create(IntPtr devCtx);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_open(IntPtr outStreamCtx);
internal static partial SoundIoError soundio_outstream_open(IntPtr outStreamCtx);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_start(IntPtr outStreamCtx);
internal static partial SoundIoError soundio_outstream_start(IntPtr outStreamCtx);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_begin_write(IntPtr outStreamCtx, IntPtr areas, IntPtr frameCount);
internal static partial SoundIoError soundio_outstream_begin_write(IntPtr outStreamCtx, IntPtr areas, IntPtr frameCount);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_end_write(IntPtr outStreamCtx);
internal static partial SoundIoError soundio_outstream_end_write(IntPtr outStreamCtx);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_pause(IntPtr devCtx, [MarshalAs(UnmanagedType.Bool)] bool pause);
internal static partial SoundIoError soundio_outstream_pause(IntPtr devCtx, [MarshalAs(UnmanagedType.Bool)] bool pause);
[LibraryImport(LibraryName)]
public static partial SoundIoError soundio_outstream_set_volume(IntPtr devCtx, double volume);
internal static partial SoundIoError soundio_outstream_set_volume(IntPtr devCtx, double volume);
[LibraryImport(LibraryName)]
public static partial void soundio_outstream_destroy(IntPtr streamCtx);
internal static partial void soundio_outstream_destroy(IntPtr streamCtx);
[LibraryImport(LibraryName)]
public static partial void soundio_destroy(IntPtr ctx);
internal static partial void soundio_destroy(IntPtr ctx);
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_channel_layout_get_default(int channelCount);
internal static partial IntPtr soundio_channel_layout_get_default(int channelCount);
[LibraryImport(LibraryName)]
public static partial IntPtr soundio_strerror(SoundIoError err);
internal static partial IntPtr soundio_strerror(SoundIoError err);
}
}

View file

@ -1,5 +1,4 @@
using System;
using System.Reflection.Metadata;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;

View file

@ -141,7 +141,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
throw new NotImplementedException("Input direction is currently not implemented on SoundIO backend!");
}
SoundIoHardwareDeviceSession session = new SoundIoHardwareDeviceSession(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
SoundIoHardwareDeviceSession session = new(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
_sessions.TryAdd(session, 0);
@ -162,7 +162,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
SampleFormat.PcmInt24 => SoundIoFormat.S24LE,
SampleFormat.PcmInt32 => SoundIoFormat.S32LE,
SampleFormat.PcmFloat => SoundIoFormat.Float32LE,
_ => throw new ArgumentException ($"Unsupported sample format {format}"),
_ => throw new ArgumentException($"Unsupported sample format {format}"),
};
}
@ -202,6 +202,8 @@ namespace Ryujinx.Audio.Backends.SoundIo
public void Dispose()
{
GC.SuppressFinalize(this);
if (Interlocked.CompareExchange(ref _disposeState, 1, 0) == 0)
{
Dispose(true);

View file

@ -12,12 +12,12 @@ namespace Ryujinx.Audio.Backends.SoundIo
{
class SoundIoHardwareDeviceSession : HardwareDeviceSessionOutputBase
{
private SoundIoHardwareDeviceDriver _driver;
private ConcurrentQueue<SoundIoAudioBuffer> _queuedBuffers;
private readonly SoundIoHardwareDeviceDriver _driver;
private readonly ConcurrentQueue<SoundIoAudioBuffer> _queuedBuffers;
private SoundIoOutStreamContext _outputStream;
private DynamicRingBuffer _ringBuffer;
private readonly DynamicRingBuffer _ringBuffer;
private ulong _playedSampleCount;
private ManualResetEvent _updateRequiredEvent;
private readonly ManualResetEvent _updateRequiredEvent;
private int _disposeState;
public SoundIoHardwareDeviceSession(SoundIoHardwareDeviceDriver driver, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount, float requestedVolume) : base(memoryManager, requestedSampleFormat, requestedSampleRate, requestedChannelCount)
@ -54,7 +54,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
public override void QueueBuffer(AudioBuffer buffer)
{
SoundIoAudioBuffer driverBuffer = new SoundIoAudioBuffer(buffer.DataPointer, GetSampleCount(buffer));
SoundIoAudioBuffer driverBuffer = new(buffer.DataPointer, GetSampleCount(buffer));
_ringBuffer.Write(buffer.Data, 0, buffer.Data.Length);
@ -81,7 +81,7 @@ namespace Ryujinx.Audio.Backends.SoundIo
_driver.FlushContextEvents();
}
public override void UnregisterBuffer(AudioBuffer buffer) {}
public override void UnregisterBuffer(AudioBuffer buffer) { }
public override bool WasBufferFullyConsumed(AudioBuffer buffer)
{

View file

@ -164,7 +164,7 @@ namespace Ryujinx.Audio
/// <summary>
/// The default coefficients used for standard 5.1 surround to stereo downmixing.
/// </summary>
public static float[] DefaultSurroundToStereoCoefficients = new float[4]
public static readonly float[] DefaultSurroundToStereoCoefficients = new float[4]
{
1.0f,
0.707f,

View file

@ -135,7 +135,7 @@ namespace Ryujinx.Ava
_inputManager = inputManager;
_accountManager = accountManager;
_userChannelPersistence = userChannelPersistence;
_renderingThread = new Thread(RenderLoop, 1 * 1024 * 1024) { Name = "GUI.RenderThread" };
_renderingThread = new Thread(RenderLoop) { Name = "GUI.RenderThread" };
_lastCursorMoveTime = Stopwatch.GetTimestamp();
_glLogLevel = ConfigurationState.Instance.Logger.GraphicsDebugLevel;
_topLevel = topLevel;

View file

@ -264,7 +264,7 @@ namespace Ryujinx.Ava.UI.ViewModels
private void SelectLastScannedAmiibo()
{
AmiiboApi scanned = _amiiboList.FirstOrDefault(amiibo => amiibo.GetId() == LastScannedAmiiboId);
AmiiboApi scanned = _amiiboList.Find(amiibo => amiibo.GetId() == LastScannedAmiiboId);
SeriesSelectedIndex = AmiiboSeries.IndexOf(scanned.AmiiboSeries);
AmiiboSelectedIndex = AmiiboList.IndexOf(scanned);
@ -325,7 +325,7 @@ namespace Ryujinx.Ava.UI.ViewModels
AmiiboApi selected = _amiibos[_amiiboSelectedIndex];
string imageUrl = _amiiboList.FirstOrDefault(amiibo => amiibo.Equals(selected)).Image;
string imageUrl = _amiiboList.Find(amiibo => amiibo.Equals(selected)).Image;
string usageString = "";

View file

@ -15,7 +15,7 @@ namespace Ryujinx.Cpu.Jit
_impl = new MemoryBlock(size, flags);
}
public bool Commit(ulong offset, ulong size) => _impl.Commit(offset, size);
public void Commit(ulong offset, ulong size) => _impl.Commit(offset, size);
public void MapAsRx(ulong offset, ulong size) => _impl.Reprotect(offset, size, MemoryPermission.ReadAndExecute);
public void MapAsRwx(ulong offset, ulong size) => _impl.Reprotect(offset, size, MemoryPermission.ReadWriteExecute);

View file

@ -512,7 +512,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <returns>True if at least one of the handles is dirty</returns>
private bool CheckDirty()
{
return Handles.Any(handle => handle.Dirty);
return Array.Exists(Handles, handle => handle.Dirty);
}
/// <summary>

View file

@ -22,7 +22,7 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
private const ushort FileFormatVersionMajor = 1;
private const ushort FileFormatVersionMinor = 2;
private const uint FileFormatVersionPacked = ((uint)FileFormatVersionMajor << 16) | FileFormatVersionMinor;
private const uint CodeGenVersion = 5241;
private const uint CodeGenVersion = 5311;
private const string SharedTocFileName = "shared.toc";
private const string SharedDataFileName = "shared.data";

View file

@ -12,8 +12,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
private readonly AVCodec_decode _decodeFrame;
private static readonly FFmpegApi.av_log_set_callback_callback _logFunc;
private readonly AVCodec* _codec;
private AVPacket* _packet;
private AVCodecContext* _context;
private readonly AVPacket* _packet;
private readonly AVCodecContext* _context;
public FFmpegContext(AVCodecID codecId)
{
@ -164,7 +164,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
FFmpegApi.av_packet_free(ppPacket);
}
FFmpegApi.avcodec_close(_context);
_ = FFmpegApi.avcodec_close(_context);
fixed (AVCodecContext** ppContext = &_context)
{

View file

@ -12,7 +12,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
private readonly byte[] _workBuffer = new byte[WorkBufferSize];
private FFmpegContext _context = new FFmpegContext(AVCodecID.AV_CODEC_ID_H264);
private FFmpegContext _context = new(AVCodecID.AV_CODEC_ID_H264);
private int _oldOutputWidth;
private int _oldOutputHeight;
@ -46,7 +46,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
byte[] output = new byte[data.Length + prep.Length];
prep.CopyTo(output);
data.CopyTo(new Span<byte>(output).Slice(prep.Length));
data.CopyTo(new Span<byte>(output)[prep.Length..]);
return output;
}

View file

@ -84,9 +84,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
Flush();
}
public Span<byte> AsSpan()
public readonly Span<byte> AsSpan()
{
return new Span<byte>(_workBuffer).Slice(0, _offset);
return new Span<byte>(_workBuffer)[.._offset];
}
public void WriteU(uint value, int valueSize) => WriteBits((int)value, valueSize);

View file

@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
{
public static Span<byte> Reconstruct(ref H264PictureInfo pictureInfo, byte[] workBuffer)
{
H264BitStreamWriter writer = new H264BitStreamWriter(workBuffer);
H264BitStreamWriter writer = new(workBuffer);
// Sequence Parameter Set.
writer.WriteU(1, 24);

View file

@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
struct AVCodec
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public unsafe byte* Name;
public unsafe byte* LongName;
public int Type;

View file

@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
struct AVCodec501
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public unsafe byte* Name;
public unsafe byte* LongName;
public int Type;

View file

@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
struct AVCodecContext
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public unsafe IntPtr AvClass;
public int LogLevelOffset;
public int CodecType;

View file

@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
struct AVFrame
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public Array8<IntPtr> Data;
public Array8<int> LineSize;
public IntPtr ExtendedData;

View file

@ -1,25 +1,23 @@
using System;
using AVBufferRef = System.IntPtr;
using AVBufferRef = System.IntPtr;
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
struct AVPacket
{
#pragma warning disable CS0649
public unsafe AVBufferRef *Buf;
#pragma warning disable CS0649 // Field is never assigned to
public unsafe AVBufferRef* Buf;
public long Pts;
public long Dts;
public unsafe byte* Data;
public int Size;
public int StreamIndex;
public int Flags;
public IntPtr SizeData;
public AVBufferRef SizeData;
public int SizeDataElems;
public long Duration;
public long Position;
public IntPtr Opaque;
public unsafe AVBufferRef *OpaqueRef;
public AVBufferRef Opaque;
public unsafe AVBufferRef* OpaqueRef;
public AVRational TimeBase;
#pragma warning restore CS0649
}

View file

@ -2,9 +2,9 @@
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
struct FFCodec<T> where T: struct
struct FFCodec<T> where T : struct
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public T Base;
public int CapsInternalOrCbType;
public int PrivDataSize;

View file

@ -2,9 +2,9 @@
namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
struct FFCodecLegacy<T> where T: struct
struct FFCodecLegacy<T> where T : struct
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public T Base;
public uint CapsInternalOrCbType;
public int PrivDataSize;

View file

@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
public const string AvCodecLibraryName = "avcodec";
public const string AvUtilLibraryName = "avutil";
private static readonly Dictionary<string, (int, int)> _librariesWhitelist = new Dictionary<string, (int, int)>
private static readonly Dictionary<string, (int, int)> _librariesWhitelist = new()
{
{ AvCodecLibraryName, (58, 59) },
{ AvUtilLibraryName, (56, 57) }
@ -61,9 +61,8 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
{
NativeLibrary.SetDllImportResolver(typeof(FFmpegApi).Assembly, (name, assembly, path) =>
{
IntPtr handle;
if (name == AvUtilLibraryName && TryLoadWhitelistedLibrary(AvUtilLibraryName, assembly, path, out handle))
if (name == AvUtilLibraryName && TryLoadWhitelistedLibrary(AvUtilLibraryName, assembly, path, out nint handle))
{
return handle;
}
@ -106,7 +105,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native
internal static unsafe partial AVCodecContext* avcodec_alloc_context3(AVCodec* codec);
[LibraryImport(AvCodecLibraryName)]
internal static unsafe partial int avcodec_open2(AVCodecContext* avctx, AVCodec* codec, void **options);
internal static unsafe partial int avcodec_open2(AVCodecContext* avctx, AVCodec* codec, void** options);
[LibraryImport(AvCodecLibraryName)]
internal static unsafe partial int avcodec_close(AVCodecContext* avctx);

View file

@ -11,9 +11,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg
public int RequestedWidth { get; }
public int RequestedHeight { get; }
public Plane YPlane => new Plane((IntPtr)Frame->Data[0], Stride * Height);
public Plane UPlane => new Plane((IntPtr)Frame->Data[1], UvStride * UvHeight);
public Plane VPlane => new Plane((IntPtr)Frame->Data[2], UvStride * UvHeight);
public Plane YPlane => new((IntPtr)Frame->Data[0], Stride * Height);
public Plane UPlane => new((IntPtr)Frame->Data[1], UvStride * UvHeight);
public Plane VPlane => new((IntPtr)Frame->Data[2], UvStride * UvHeight);
public FrameField Field => Frame->InterlacedFrame != 0 ? FrameField.Interlaced : FrameField.Progressive;

View file

@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Vp8
{
public bool IsHardwareAccelerated => false;
private readonly FFmpegContext _context = new FFmpegContext(AVCodecID.AV_CODEC_ID_VP8);
private readonly FFmpegContext _context = new(AVCodecID.AV_CODEC_ID_VP8);
public ISurface CreateSurface(int width, int height)
{
@ -43,7 +43,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Vp8
frame[9] = (byte)((pictureInfo.FrameHeight >> 8) & 0x3F);
}
bitstream.CopyTo(new Span<byte>(frame).Slice(uncompHeaderSize));
bitstream.CopyTo(new Span<byte>(frame)[uncompHeaderSize..]);
return _context.DecodeFrame(outSurf, frame) == 0;
}

View file

@ -166,7 +166,7 @@ namespace Ryujinx.Graphics.Shader.Instructions
{
// gl_FrontFacing sometimes has incorrect (flipped) values depending how it is accessed on Intel GPUs.
// This weird trick makes it behave.
res = context.ICompareLess(context.INegate(context.IConvertS32ToFP32(res)), Const(0));
res = context.ICompareLess(context.INegate(context.FP32ConvertToS32(context.ConditionalSelect(res, ConstF(1f), ConstF(0f)))), Const(0));
}
}

View file

@ -140,7 +140,7 @@ namespace Ryujinx.Graphics.Shader.Translation
FunctionMatch.RunPass(program);
foreach (DecodedFunction function in program.OrderBy(x => x.Address).Where(x => !x.IsCompilerGenerated))
foreach (DecodedFunction function in program.Where(x => !x.IsCompilerGenerated).OrderBy(x => x.Address))
{
program.AddFunctionAndSetId(function);
}

View file

@ -34,7 +34,7 @@ namespace Ryujinx.Graphics.Vic.Image
{
int index = RentMinimum(length, out T[] bufferArray);
buffer = new Span<T>(bufferArray).Slice(0, length);
buffer = new Span<T>(bufferArray)[..length];
return index;
}

View file

@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Vic.Image
{
ref struct RentedBuffer
{
public static RentedBuffer Empty => new RentedBuffer(Span<byte>.Empty, -1);
public static RentedBuffer Empty => new(Span<byte>.Empty, -1);
public Span<byte> Data;
public int Index;
@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Vic.Image
Index = index;
}
public void Return(BufferPool<byte> pool)
public readonly void Return(BufferPool<byte> pool)
{
if (Index != -1)
{
@ -65,7 +65,7 @@ namespace Ryujinx.Graphics.Vic.Image
Buffer2Index = buffer.Index;
}
public void Return(BufferPool<byte> pool)
public readonly void Return(BufferPool<byte> pool)
{
if (Buffer0Index != -1)
{

View file

@ -21,7 +21,8 @@ namespace Ryujinx.Graphics.Vic.Image
{
switch (surfaceConfig.SlotPixelFormat)
{
case PixelFormat.Y8___V8U8_N420: return ReadNv12(rm, ref config, ref surfaceConfig, ref offsets);
case PixelFormat.Y8___V8U8_N420:
return ReadNv12(rm, ref config, ref surfaceConfig, ref offsets);
}
Logger.Error?.Print(LogClass.Vic, $"Unsupported pixel format \"{surfaceConfig.SlotPixelFormat}\".");
@ -46,7 +47,7 @@ namespace Ryujinx.Graphics.Vic.Image
int yStride = GetPitch(width, 1);
int uvStride = GetPitch(input.UvWidth, 2);
Surface output = new Surface(rm.SurfacePool, width, height);
Surface output = new(rm.SurfacePool, width, height);
if (Sse41.IsSupported)
{
@ -276,7 +277,7 @@ namespace Ryujinx.Graphics.Vic.Image
int bytesPerPixel,
int planes)
{
InputSurface surface = new InputSurface();
InputSurface surface = new();
surface.Initialize();
@ -458,7 +459,7 @@ namespace Ryujinx.Graphics.Vic.Image
int outSize = dstStride * height;
int bufferIndex = rm.BufferPool.RentMinimum(outSize, out byte[] buffer);
Span<byte> dst = buffer;
dst = dst.Slice(0, outSize);
dst = dst[..outSize];
for (int y = 0; y < height; y++)
{
@ -485,9 +486,9 @@ namespace Ryujinx.Graphics.Vic.Image
int outSize = dstStride * height;
int bufferIndex = rm.BufferPool.RentMinimum(outSize, out byte[] buffer);
Span<byte> dst = buffer;
dst = dst.Slice(0, outSize);
dst = dst[..outSize];
LayoutConverter.ConvertBlockLinearToLinear(dst.Slice(dstStart), width, height, dstStride, bytesPerPixel, gobBlocksInY, src);
LayoutConverter.ConvertBlockLinearToLinear(dst[dstStart..], width, height, dstStride, bytesPerPixel, gobBlocksInY, src);
return new RentedBuffer(dst, bufferIndex);
}

View file

@ -2,10 +2,10 @@
namespace Ryujinx.Graphics.Vic.Types
{
struct BlendingSlotStruct
readonly struct BlendingSlotStruct
{
private long _word0;
private long _word1;
private readonly long _word0;
private readonly long _word1;
public int AlphaK1 => (int)_word0.Extract(0, 10);
public int AlphaK2 => (int)_word0.Extract(16, 10);

View file

@ -2,11 +2,11 @@
namespace Ryujinx.Graphics.Vic.Types
{
struct ClearRectStruct
readonly struct ClearRectStruct
{
#pragma warning disable CS0649
private long _word0;
private long _word1;
#pragma warning disable CS0649 // Field is never assigned to
private readonly long _word0;
private readonly long _word1;
#pragma warning restore CS0649
public int ClearRect0Left => (int)_word0.Extract(0, 14);

View file

@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Vic.Types
{
struct ConfigStruct
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public PipeConfig PipeConfig;
public OutputConfig OutputConfig;
public OutputSurfaceConfig OutputSurfaceConfig;

View file

@ -2,10 +2,10 @@
namespace Ryujinx.Graphics.Vic.Types
{
struct LumaKeyStruct
readonly struct LumaKeyStruct
{
private long _word0;
private long _word1;
private readonly long _word0;
private readonly long _word1;
public int LumaCoeff0 => (int)_word0.Extract(0, 20);
public int LumaCoeff1 => (int)_word0.Extract(20, 20);

View file

@ -2,12 +2,12 @@
namespace Ryujinx.Graphics.Vic.Types
{
struct MatrixStruct
readonly struct MatrixStruct
{
private long _word0;
private long _word1;
private long _word2;
private long _word3;
private readonly long _word0;
private readonly long _word1;
private readonly long _word2;
private readonly long _word3;
public int MatrixCoeff00 => (int)_word0.ExtractSx(0, 20);
public int MatrixCoeff10 => (int)_word0.ExtractSx(20, 20);

View file

@ -2,11 +2,11 @@
namespace Ryujinx.Graphics.Vic.Types
{
struct OutputConfig
readonly struct OutputConfig
{
#pragma warning disable CS0649
private long _word0;
private long _word1;
#pragma warning disable CS0649 // Field is never assigned to
private readonly long _word0;
private readonly long _word1;
#pragma warning restore CS0649
public int AlphaFillMode => (int)_word0.Extract(0, 3);

View file

@ -2,11 +2,11 @@
namespace Ryujinx.Graphics.Vic.Types
{
struct OutputSurfaceConfig
readonly struct OutputSurfaceConfig
{
#pragma warning disable CS0649
private long _word0;
private long _word1;
#pragma warning disable CS0649 // Field is never assigned to
private readonly long _word0;
private readonly long _word1;
#pragma warning restore CS0649
public PixelFormat OutPixelFormat => (PixelFormat)_word0.Extract(0, 7);

View file

@ -2,12 +2,12 @@
namespace Ryujinx.Graphics.Vic.Types
{
struct PipeConfig
readonly struct PipeConfig
{
#pragma warning disable CS0169, CS0649
private long _word0;
private long _word1;
#pragma warning restore CS0169, CS0649
#pragma warning disable CS0169, CS0649, IDE0051 // Remove unused private member
private readonly long _word0;
private readonly long _word1;
#pragma warning restore CS0169, CS0649, IDE0051
public int DownsampleHoriz => (int)_word0.Extract(0, 11);
public int DownsampleVert => (int)_word0.Extract(16, 11);

View file

@ -2,16 +2,18 @@
namespace Ryujinx.Graphics.Vic.Types
{
struct SlotConfig
readonly struct SlotConfig
{
private long _word0;
private long _word1;
private long _word2;
private long _word3;
private long _word4;
private long _word5;
private long _word6;
private long _word7;
private readonly long _word0;
private readonly long _word1;
private readonly long _word2;
private readonly long _word3;
private readonly long _word4;
private readonly long _word5;
private readonly long _word6;
#pragma warning disable IDE0051 // Remove unused private member
private readonly long _word7;
#pragma warning restore IDE0051
public bool SlotEnable => _word0.Extract(0);
public bool DeNoise => _word0.Extract(1);

View file

@ -2,10 +2,10 @@
namespace Ryujinx.Graphics.Vic.Types
{
struct SlotSurfaceConfig
readonly struct SlotSurfaceConfig
{
private long _word0;
private long _word1;
private readonly long _word0;
private readonly long _word1;
public PixelFormat SlotPixelFormat => (PixelFormat)_word0.Extract(0, 7);
public int SlotChromaLocHoriz => (int)_word0.Extract(7, 2);

View file

@ -30,7 +30,7 @@ namespace Ryujinx.Graphics.Vic
{
ConfigStruct config = ReadIndirect<ConfigStruct>(_state.State.SetConfigStructOffset);
using Surface output = new Surface(
using Surface output = new(
_rm.SurfacePool,
config.OutputSurfaceConfig.OutSurfaceWidth + 1,
config.OutputSurfaceConfig.OutSurfaceHeight + 1);
@ -58,7 +58,7 @@ namespace Ryujinx.Graphics.Vic
int targetW = Math.Min(output.Width - targetX, Math.Abs(x2 - x1));
int targetH = Math.Min(output.Height - targetY, Math.Abs(y2 - y1));
Rectangle targetRect = new Rectangle(targetX, targetY, targetW, targetH);
Rectangle targetRect = new(targetX, targetY, targetW, targetH);
Blender.BlendOne(output, src, ref slot, targetRect);
}

View file

@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Vic
{
struct PlaneOffsets
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public uint LumaOffset;
public uint ChromaUOffset;
public uint ChromaVOffset;
@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.Vic
struct VicRegisters
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public Array64<uint> Reserved0;
public uint Nop;
public Array15<uint> Reserved104;

View file

@ -256,7 +256,7 @@ namespace Ryujinx.Graphics.Vulkan
{
await Task.WhenAll(_shaders.Select(shader => shader.CompileTask));
if (_shaders.Any(shader => shader.CompileStatus == ProgramLinkStatus.Failure))
if (Array.Exists(_shaders, shader => shader.CompileStatus == ProgramLinkStatus.Failure))
{
LinkStatus = ProgramLinkStatus.Failure;

View file

@ -15,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast
writer.Write(Params);
if (Params.EndsWith(">"))
if (Params.EndsWith('>'))
{
writer.Write(" ");
}

View file

@ -206,7 +206,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Threading
WakeThreads(_condVarThreads, count, TryAcquireMutex, x => x.CondVarAddress == address);
if (!_condVarThreads.Any(x => x.CondVarAddress == address))
if (!_condVarThreads.Exists(x => x.CondVarAddress == address))
{
KernelTransfer.KernelToUser(address, 0);
}

View file

@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types
[StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x10)]
struct CreateId : IEquatable<CreateId>
{
public UInt128 Raw;
public readonly UInt128 Raw;
public bool IsNull => Raw == UInt128.Zero;
public bool IsValid => !IsNull && ((Raw >> 64) & 0xC0) == 0x80;

View file

@ -95,7 +95,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{
VirtualAmiiboFile virtualAmiiboFile = LoadAmiiboFile(amiiboId);
if (virtualAmiiboFile.ApplicationAreas.Any(item => item.ApplicationAreaId == applicationAreaId))
if (virtualAmiiboFile.ApplicationAreas.Exists(item => item.ApplicationAreaId == applicationAreaId))
{
_openedApplicationAreaId = applicationAreaId;
@ -124,7 +124,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{
VirtualAmiiboFile virtualAmiiboFile = LoadAmiiboFile(amiiboId);
if (virtualAmiiboFile.ApplicationAreas.Any(item => item.ApplicationAreaId == applicationAreaId))
if (virtualAmiiboFile.ApplicationAreas.Exists(item => item.ApplicationAreaId == applicationAreaId))
{
return false;
}
@ -144,7 +144,7 @@ namespace Ryujinx.HLE.HOS.Services.Nfc.Nfp
{
VirtualAmiiboFile virtualAmiiboFile = LoadAmiiboFile(amiiboId);
if (virtualAmiiboFile.ApplicationAreas.Any(item => item.ApplicationAreaId == _openedApplicationAreaId))
if (virtualAmiiboFile.ApplicationAreas.Exists(item => item.ApplicationAreaId == _openedApplicationAreaId))
{
for (int i = 0; i < virtualAmiiboFile.ApplicationAreas.Count; i++)
{

View file

@ -39,7 +39,7 @@ namespace Ryujinx.HLE.HOS.Services.Sockets.Sfdnsres.Proxy
}
// Ignore comments and empty lines
if (line.StartsWith("#") || line.Trim().Length == 0)
if (line.StartsWith('#') || line.Trim().Length == 0)
{
continue;
}

View file

@ -8,6 +8,7 @@ using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.Loaders.Executables;
using Ryujinx.Memory;
using System;
using System.Linq;
using static Ryujinx.HLE.HOS.ModLoader;
@ -99,7 +100,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
if (string.IsNullOrWhiteSpace(programName))
{
programName = nacpData.Value.Title.ItemsRo.ToArray().FirstOrDefault(x => x.Name[0] != 0).NameString.ToString();
programName = Array.Find(nacpData.Value.Title.ItemsRo.ToArray(), x => x.Name[0] != 0).NameString.ToString();
}
}

View file

@ -9,6 +9,7 @@ using LibHac.Tools.FsSystem.NcaUtils;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.Loaders.Executables;
using Ryujinx.HLE.Loaders.Processes.Extensions;
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Linq;
@ -184,7 +185,7 @@ namespace Ryujinx.HLE.Loaders.Processes
if (string.IsNullOrWhiteSpace(programName))
{
programName = nacpData.Value.Title.ItemsRo.ToArray().FirstOrDefault(x => x.Name[0] != 0).NameString.ToString();
programName = Array.Find(nacpData.Value.Title.ItemsRo.ToArray(), x => x.Name[0] != 0).NameString.ToString();
}
if (nacpData.Value.PresenceGroupId != 0)

View file

@ -61,7 +61,7 @@ namespace Ryujinx.HLE.Loaders.Processes
if (string.IsNullOrWhiteSpace(Name))
{
Name = ApplicationControlProperties.Title.ItemsRo.ToArray().FirstOrDefault(x => x.Name[0] != 0).NameString.ToString();
Name = Array.Find(ApplicationControlProperties.Title.ItemsRo.ToArray(), x => x.Name[0] != 0).NameString.ToString();
}
DisplayVersion = ApplicationControlProperties.DisplayVersionString.ToString();

View file

@ -4,36 +4,36 @@
{
private const int ModuleId = 1;
public static Result SessionCountExceeded => new Result(ModuleId, 7);
public static Result InvalidCapability => new Result(ModuleId, 14);
public static Result ThreadNotStarted => new Result(ModuleId, 57);
public static Result ThreadTerminating => new Result(ModuleId, 59);
public static Result InvalidSize => new Result(ModuleId, 101);
public static Result InvalidAddress => new Result(ModuleId, 102);
public static Result OutOfResource => new Result(ModuleId, 103);
public static Result OutOfMemory => new Result(ModuleId, 104);
public static Result HandleTableFull => new Result(ModuleId, 105);
public static Result InvalidMemState => new Result(ModuleId, 106);
public static Result InvalidPermission => new Result(ModuleId, 108);
public static Result InvalidMemRange => new Result(ModuleId, 110);
public static Result InvalidPriority => new Result(ModuleId, 112);
public static Result InvalidCpuCore => new Result(ModuleId, 113);
public static Result InvalidHandle => new Result(ModuleId, 114);
public static Result UserCopyFailed => new Result(ModuleId, 115);
public static Result InvalidCombination => new Result(ModuleId, 116);
public static Result TimedOut => new Result(ModuleId, 117);
public static Result Cancelled => new Result(ModuleId, 118);
public static Result MaximumExceeded => new Result(ModuleId, 119);
public static Result InvalidEnumValue => new Result(ModuleId, 120);
public static Result NotFound => new Result(ModuleId, 121);
public static Result InvalidThread => new Result(ModuleId, 122);
public static Result PortRemoteClosed => new Result(ModuleId, 123);
public static Result InvalidState => new Result(ModuleId, 125);
public static Result ReservedValue => new Result(ModuleId, 126);
public static Result PortClosed => new Result(ModuleId, 131);
public static Result ResLimitExceeded => new Result(ModuleId, 132);
public static Result ReceiveListBroken => new Result(ModuleId, 258);
public static Result OutOfVaSpace => new Result(ModuleId, 259);
public static Result CmdBufferTooSmall => new Result(ModuleId, 260);
public static Result SessionCountExceeded => new(ModuleId, 7);
public static Result InvalidCapability => new(ModuleId, 14);
public static Result ThreadNotStarted => new(ModuleId, 57);
public static Result ThreadTerminating => new(ModuleId, 59);
public static Result InvalidSize => new(ModuleId, 101);
public static Result InvalidAddress => new(ModuleId, 102);
public static Result OutOfResource => new(ModuleId, 103);
public static Result OutOfMemory => new(ModuleId, 104);
public static Result HandleTableFull => new(ModuleId, 105);
public static Result InvalidMemState => new(ModuleId, 106);
public static Result InvalidPermission => new(ModuleId, 108);
public static Result InvalidMemRange => new(ModuleId, 110);
public static Result InvalidPriority => new(ModuleId, 112);
public static Result InvalidCpuCore => new(ModuleId, 113);
public static Result InvalidHandle => new(ModuleId, 114);
public static Result UserCopyFailed => new(ModuleId, 115);
public static Result InvalidCombination => new(ModuleId, 116);
public static Result TimedOut => new(ModuleId, 117);
public static Result Cancelled => new(ModuleId, 118);
public static Result MaximumExceeded => new(ModuleId, 119);
public static Result InvalidEnumValue => new(ModuleId, 120);
public static Result NotFound => new(ModuleId, 121);
public static Result InvalidThread => new(ModuleId, 122);
public static Result PortRemoteClosed => new(ModuleId, 123);
public static Result InvalidState => new(ModuleId, 125);
public static Result ReservedValue => new(ModuleId, 126);
public static Result PortClosed => new(ModuleId, 131);
public static Result ResLimitExceeded => new(ModuleId, 132);
public static Result ReceiveListBroken => new(ModuleId, 258);
public static Result OutOfVaSpace => new(ModuleId, 259);
public static Result CmdBufferTooSmall => new(ModuleId, 260);
}
}

View file

@ -2,7 +2,7 @@
namespace Ryujinx.Horizon.Common
{
public struct OnScopeExit : IDisposable
public readonly struct OnScopeExit : IDisposable
{
private readonly Action _action;

View file

@ -13,13 +13,13 @@ namespace Ryujinx.Horizon.Common
public int ErrorCode { get; }
public bool IsSuccess => ErrorCode == 0;
public bool IsFailure => ErrorCode != 0;
public readonly bool IsSuccess => ErrorCode == 0;
public readonly bool IsFailure => ErrorCode != 0;
public int Module => ErrorCode & (ModuleMax - 1);
public int Description => (ErrorCode >> ModuleBits) & (DescriptionMax - 1);
public readonly int Module => ErrorCode & (ModuleMax - 1);
public readonly int Description => (ErrorCode >> ModuleBits) & (DescriptionMax - 1);
public string PrintableResult => $"{2000 + Module:D4}-{Description:D4}";
public readonly string PrintableResult => $"{2000 + Module:D4}-{Description:D4}";
public Result(int module, int description)
{
@ -36,17 +36,17 @@ namespace Ryujinx.Horizon.Common
ErrorCode = module | (description << ModuleBits);
}
public override bool Equals(object obj)
public readonly override bool Equals(object obj)
{
return obj is Result result && result.Equals(this);
}
public bool Equals(Result other)
public readonly bool Equals(Result other)
{
return other.ErrorCode == ErrorCode;
}
public override int GetHashCode()
public readonly override int GetHashCode()
{
return ErrorCode;
}
@ -61,7 +61,7 @@ namespace Ryujinx.Horizon.Common
return !lhs.Equals(rhs);
}
public bool InRange(int minInclusive, int maxInclusive)
public readonly bool InRange(int minInclusive, int maxInclusive)
{
return (uint)(Description - minInclusive) <= (uint)(maxInclusive - minInclusive);
}
@ -105,7 +105,7 @@ namespace Ryujinx.Horizon.Common
throw new InvalidResultException(this);
}
public override string ToString()
public readonly override string ToString()
{
if (ResultNames.TryGet(ErrorCode, out string name))
{

View file

@ -1,6 +1,5 @@
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
namespace Ryujinx.Memory
@ -101,12 +100,12 @@ namespace Ryujinx.Memory
/// </summary>
/// <param name="offset">Starting offset of the range to be committed</param>
/// <param name="size">Size of the range to be committed</param>
/// <returns>True if the operation was successful, false otherwise</returns>
/// <exception cref="SystemException">Throw when the operation was not successful</exception>
/// <exception cref="ObjectDisposedException">Throw when the memory block has already been disposed</exception>
/// <exception cref="InvalidMemoryRegionException">Throw when either <paramref name="offset"/> or <paramref name="size"/> are out of range</exception>
public bool Commit(ulong offset, ulong size)
public void Commit(ulong offset, ulong size)
{
return MemoryManagement.Commit(GetPointerInternal(offset, size), size, _forJit);
MemoryManagement.Commit(GetPointerInternal(offset, size), size, _forJit);
}
/// <summary>
@ -115,12 +114,12 @@ namespace Ryujinx.Memory
/// </summary>
/// <param name="offset">Starting offset of the range to be decommitted</param>
/// <param name="size">Size of the range to be decommitted</param>
/// <returns>True if the operation was successful, false otherwise</returns>
/// <exception cref="SystemException">Throw when the operation was not successful</exception>
/// <exception cref="ObjectDisposedException">Throw when the memory block has already been disposed</exception>
/// <exception cref="InvalidMemoryRegionException">Throw when either <paramref name="offset"/> or <paramref name="size"/> are out of range</exception>
public bool Decommit(ulong offset, ulong size)
public void Decommit(ulong offset, ulong size)
{
return MemoryManagement.Decommit(GetPointerInternal(offset, size), size);
MemoryManagement.Decommit(GetPointerInternal(offset, size), size);
}
/// <summary>

View file

@ -36,15 +36,15 @@ namespace Ryujinx.Memory
}
}
public static bool Commit(IntPtr address, ulong size, bool forJit)
public static void Commit(IntPtr address, ulong size, bool forJit)
{
if (OperatingSystem.IsWindows())
{
return MemoryManagementWindows.Commit(address, (IntPtr)size);
MemoryManagementWindows.Commit(address, (IntPtr)size);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
{
return MemoryManagementUnix.Commit(address, size, forJit);
MemoryManagementUnix.Commit(address, size, forJit);
}
else
{
@ -52,15 +52,15 @@ namespace Ryujinx.Memory
}
}
public static bool Decommit(IntPtr address, ulong size)
public static void Decommit(IntPtr address, ulong size)
{
if (OperatingSystem.IsWindows())
{
return MemoryManagementWindows.Decommit(address, (IntPtr)size);
MemoryManagementWindows.Decommit(address, (IntPtr)size);
}
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
{
return MemoryManagementUnix.Decommit(address, size);
MemoryManagementUnix.Decommit(address, size);
}
else
{

View file

@ -2,8 +2,6 @@
using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using static Ryujinx.Memory.MemoryManagerUnixHelper;
namespace Ryujinx.Memory
@ -12,7 +10,7 @@ namespace Ryujinx.Memory
[SupportedOSPlatform("macos")]
static class MemoryManagementUnix
{
private static readonly ConcurrentDictionary<IntPtr, ulong> _allocations = new ConcurrentDictionary<IntPtr, ulong>();
private static readonly ConcurrentDictionary<IntPtr, ulong> _allocations = new();
public static IntPtr Allocate(ulong size, bool forJit)
{
@ -68,7 +66,7 @@ namespace Ryujinx.Memory
return ptr;
}
public static bool Commit(IntPtr address, ulong size, bool forJit)
public static void Commit(IntPtr address, ulong size, bool forJit)
{
MmapProts prot = MmapProts.PROT_READ | MmapProts.PROT_WRITE;
@ -81,11 +79,9 @@ namespace Ryujinx.Memory
{
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
return true;
}
public static bool Decommit(IntPtr address, ulong size)
public static void Decommit(IntPtr address, ulong size)
{
// Must be writable for madvise to work properly.
if (mprotect(address, size, MmapProts.PROT_READ | MmapProts.PROT_WRITE) != 0)
@ -102,8 +98,6 @@ namespace Ryujinx.Memory
{
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
return true;
}
public static bool Reprotect(IntPtr address, ulong size, MemoryPermission permission)
@ -146,7 +140,7 @@ namespace Ryujinx.Memory
if (OperatingSystem.IsMacOS())
{
byte[] memName = Encoding.ASCII.GetBytes("Ryujinx-XXXXXX");
byte[] memName = "Ryujinx-XXXXXX"u8.ToArray();
fixed (byte* pMemName = memName)
{
@ -164,7 +158,7 @@ namespace Ryujinx.Memory
}
else
{
byte[] fileName = Encoding.ASCII.GetBytes("/dev/shm/Ryujinx-XXXXXX");
byte[] fileName = "/dev/shm/Ryujinx-XXXXXX"u8.ToArray();
fixed (byte* pFileName = fileName)
{

View file

@ -10,7 +10,7 @@ namespace Ryujinx.Memory
{
public const int PageSize = 0x1000;
private static readonly PlaceholderManager _placeholders = new PlaceholderManager();
private static readonly PlaceholderManager _placeholders = new();
public static IntPtr Allocate(IntPtr size)
{
@ -55,14 +55,20 @@ namespace Ryujinx.Memory
return ptr;
}
public static bool Commit(IntPtr location, IntPtr size)
public static void Commit(IntPtr location, IntPtr size)
{
return WindowsApi.VirtualAlloc(location, size, AllocationType.Commit, MemoryProtection.ReadWrite) != IntPtr.Zero;
if (WindowsApi.VirtualAlloc(location, size, AllocationType.Commit, MemoryProtection.ReadWrite) == IntPtr.Zero)
{
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
}
public static bool Decommit(IntPtr location, IntPtr size)
public static void Decommit(IntPtr location, IntPtr size)
{
return WindowsApi.VirtualFree(location, size, AllocationType.Decommit);
if (!WindowsApi.VirtualFree(location, size, AllocationType.Decommit))
{
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
}
public static void MapView(IntPtr sharedMemory, ulong srcOffset, IntPtr location, IntPtr size, MemoryBlock owner)

View file

@ -9,8 +9,6 @@ namespace Ryujinx.Tests.Memory
{
public class MultiRegionTrackingTests
{
private const int RndCnt = 3;
private const ulong MemorySize = 0x8000;
private const int PageSize = 4096;
@ -39,7 +37,7 @@ namespace Ryujinx.Tests.Memory
(IMultiRegionHandle)_tracking.BeginGranularTracking(address, size, null, granularity, 0);
}
private void RandomOrder(Random random, List<int> indices, Action<int> action)
private static void RandomOrder(Random random, List<int> indices, Action<int> action)
{
List<int> choices = indices.ToList();
@ -51,7 +49,7 @@ namespace Ryujinx.Tests.Memory
}
}
private int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func<ulong, bool> addressPredicate)
private static int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func<ulong, bool> addressPredicate)
{
int regionCount = 0;
ulong lastAddress = startAddress;
@ -67,7 +65,7 @@ namespace Ryujinx.Tests.Memory
return regionCount;
}
private int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func<ulong, bool> addressPredicate, int sequenceNumber)
private static int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func<ulong, bool> addressPredicate, int sequenceNumber)
{
int regionCount = 0;
ulong lastAddress = startAddress;
@ -83,9 +81,9 @@ namespace Ryujinx.Tests.Memory
return regionCount;
}
private void PreparePages(IMultiRegionHandle handle, int pageCount, ulong address = 0)
private static void PreparePages(IMultiRegionHandle handle, int pageCount, ulong address = 0)
{
Random random = new Random();
Random random = new();
// Make sure the list has minimum granularity (smart region changes granularity based on requested ranges)
RandomOrder(random, Enumerable.Range(0, pageCount).ToList(), (i) =>
@ -105,7 +103,7 @@ namespace Ryujinx.Tests.Memory
const int pageCount = 32;
IMultiRegionHandle handle = GetGranular(smart, 0, PageSize * pageCount, PageSize);
Random random = new Random();
Random random = new();
PreparePages(handle, pageCount);
@ -149,7 +147,7 @@ namespace Ryujinx.Tests.Memory
PreparePages(handle, pageCount);
Random random = new Random();
Random random = new();
IEnumerable<int> halfRange = Enumerable.Range(0, pageCount / 2);
List<int> odd = halfRange.Select(x => x * 2 + 1).ToList();
@ -240,7 +238,8 @@ namespace Ryujinx.Tests.Memory
ulong expectedAddress = 0;
// Expect each region to trigger in its entirety, in address ascending order.
handle.QueryModified((address, size) => {
handle.QueryModified((address, size) =>
{
int region = regionSizes[regionInd++];
Assert.AreEqual(address, expectedAddress);

View file

@ -7,14 +7,14 @@ namespace Ryujinx.Tests.Memory
{
public class Tests
{
private static readonly ulong MemorySize = MemoryBlock.GetPageSize() * 8;
private static readonly ulong _memorySize = MemoryBlock.GetPageSize() * 8;
private MemoryBlock _memoryBlock;
[SetUp]
public void Setup()
{
_memoryBlock = new MemoryBlock(MemorySize);
_memoryBlock = new MemoryBlock(_memorySize);
}
[TearDown]
@ -47,8 +47,8 @@ namespace Ryujinx.Tests.Memory
ulong pageSize = MemoryBlock.GetPageSize();
ulong blockSize = MemoryBlock.GetPageSize() * 16;
using MemoryBlock backing = new MemoryBlock(blockSize, MemoryAllocationFlags.Mirrorable);
using MemoryBlock toAlias = new MemoryBlock(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
using MemoryBlock backing = new(blockSize, MemoryAllocationFlags.Mirrorable);
using MemoryBlock toAlias = new(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
toAlias.MapView(backing, pageSize, 0, pageSize * 4);
toAlias.UnmapView(backing, pageSize * 3, pageSize);
@ -66,10 +66,10 @@ namespace Ryujinx.Tests.Memory
int pageBits = (int)ulong.Log2(pageSize);
ulong blockSize = MemoryBlock.GetPageSize() * 128;
using MemoryBlock backing = new MemoryBlock(blockSize, MemoryAllocationFlags.Mirrorable);
using MemoryBlock toAlias = new MemoryBlock(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
using MemoryBlock backing = new(blockSize, MemoryAllocationFlags.Mirrorable);
using MemoryBlock toAlias = new(blockSize, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
Random rng = new Random(123);
Random rng = new(123);
for (int i = 0; i < 20000; i++)
{
@ -101,8 +101,8 @@ namespace Ryujinx.Tests.Memory
ulong pageSize = MemoryBlock.GetPageSize();
ulong size = 100000 * pageSize; // The mappings limit on Linux is usually around 65K, so let's make sure we are above that.
using MemoryBlock backing = new MemoryBlock(pageSize, MemoryAllocationFlags.Mirrorable);
using MemoryBlock toAlias = new MemoryBlock(size, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
using MemoryBlock backing = new(pageSize, MemoryAllocationFlags.Mirrorable);
using MemoryBlock toAlias = new(size, MemoryAllocationFlags.Reserve | MemoryAllocationFlags.ViewCompatible);
for (ulong offset = 0; offset < size; offset += pageSize)
{

View file

@ -102,15 +102,17 @@ namespace Ryujinx.Tests.Memory
allHandle.Reprotect();
(ulong address, ulong size)? readTrackingTriggeredAll = null;
Action registerReadAction = () =>
void RegisterReadAction()
{
readTrackingTriggeredAll = null;
allHandle.RegisterAction((address, size) =>
{
readTrackingTriggeredAll = (address, size);
});
};
registerReadAction();
}
RegisterReadAction();
// Create 16 page sized handles contained within the allHandle.
RegionHandle[] containedHandles = new RegionHandle[16];
@ -149,7 +151,7 @@ namespace Ryujinx.Tests.Memory
}
// Clear flags and reset read action.
registerReadAction();
RegisterReadAction();
allHandle.Reprotect();
containedHandles[i].Reprotect();
}
@ -157,8 +159,8 @@ namespace Ryujinx.Tests.Memory
[Test]
public void PageAlignment(
[Values(1ul, 512ul, 2048ul, 4096ul, 65536ul)] [Random(1ul, 65536ul, RndCnt)] ulong address,
[Values(1ul, 4ul, 1024ul, 4096ul, 65536ul)] [Random(1ul, 65536ul, RndCnt)] ulong size)
[Values(1ul, 512ul, 2048ul, 4096ul, 65536ul)][Random(1ul, 65536ul, RndCnt)] ulong address,
[Values(1ul, 4ul, 1024ul, 4096ul, 65536ul)][Random(1ul, 65536ul, RndCnt)] ulong size)
{
ulong alignedStart = (address / PageSize) * PageSize;
ulong alignedEnd = ((address + size + PageSize - 1) / PageSize) * PageSize;
@ -204,7 +206,7 @@ namespace Ryujinx.Tests.Memory
long finishedTime = 0;
RegionHandle[] handles = new RegionHandle[threadCount * handlesPerThread];
Random globalRand = new Random();
Random globalRand = new();
for (int i = 0; i < handles.Length; i++)
{
@ -212,7 +214,7 @@ namespace Ryujinx.Tests.Memory
handles[i].Reprotect();
}
List<Thread> testThreads = new List<Thread>();
List<Thread> testThreads = new();
// Dirty flag consumer threads
int dirtyFlagReprotects = 0;
@ -224,7 +226,7 @@ namespace Ryujinx.Tests.Memory
int handleBase = randSeed * handlesPerThread;
while (Stopwatch.GetTimestamp() < finishedTime)
{
Random random = new Random(randSeed);
Random random = new(randSeed);
RegionHandle handle = handles[handleBase + random.Next(handlesPerThread)];
if (handle.Dirty)
@ -243,7 +245,7 @@ namespace Ryujinx.Tests.Memory
int randSeed = i;
testThreads.Add(new Thread(() =>
{
Random random = new Random(randSeed);
Random random = new(randSeed);
ulong handleBase = (ulong)(randSeed * handlesPerThread * PageSize);
while (Stopwatch.GetTimestamp() < finishedTime)
{
@ -261,7 +263,7 @@ namespace Ryujinx.Tests.Memory
testThreads.Add(new Thread(() =>
{
int maxAddress = threadCount * handlesPerThread * PageSize;
Random random = new Random(randSeed + 512);
Random random = new(randSeed + 512);
while (Stopwatch.GetTimestamp() < finishedTime)
{
RegionHandle handle = _tracking.BeginTracking((ulong)random.Next(maxAddress), (ulong)random.Next(65536), 0);
@ -303,7 +305,7 @@ namespace Ryujinx.Tests.Memory
int signalThreadsDone = 0;
bool isRegistered = false;
Action registerReadAction = () =>
void RegisterReadAction()
{
registeredCount++;
handle.RegisterAction((address, size) =>
@ -311,7 +313,7 @@ namespace Ryujinx.Tests.Memory
isRegistered = false;
Interlocked.Increment(ref triggeredCount);
});
};
}
const int threadCount = 16;
const int iterationCount = 10000;
@ -322,7 +324,7 @@ namespace Ryujinx.Tests.Memory
int randSeed = i;
signalThreads[i] = new Thread(() =>
{
Random random = new Random(randSeed);
Random random = new(randSeed);
for (int j = 0; j < iterationCount; j++)
{
_tracking.VirtualMemoryEvent((ulong)random.Next(PageSize), 4, false);
@ -346,7 +348,7 @@ namespace Ryujinx.Tests.Memory
if (!isRegistered)
{
isRegistered = true;
registerReadAction();
RegisterReadAction();
}
}

View file

@ -4,12 +4,12 @@ namespace Ryujinx.Tests.Unicorn
{
public class IndexedProperty<TIndex, TValue>
{
private Func<TIndex, TValue> _getFunc;
private Action<TIndex, TValue> _setAction;
private readonly Func<TIndex, TValue> _getFunc;
private readonly Action<TIndex, TValue> _setAction;
public IndexedProperty(Func<TIndex, TValue> getFunc, Action<TIndex, TValue> setAction)
{
_getFunc = getFunc;
_getFunc = getFunc;
_setAction = setAction;
}

View file

@ -2,10 +2,10 @@ using System;
namespace Ryujinx.Tests.Unicorn
{
public struct SimdValue : IEquatable<SimdValue>
public readonly struct SimdValue : IEquatable<SimdValue>
{
private ulong _e0;
private ulong _e1;
private readonly ulong _e0;
private readonly ulong _e1;
public SimdValue(ulong e0, ulong e1)
{
@ -39,31 +39,29 @@ namespace Ryujinx.Tests.Unicorn
return BitConverter.Int64BitsToDouble(GetInt64(index));
}
public int GetInt32(int index) => (int)GetUInt32(index);
public int GetInt32(int index) => (int)GetUInt32(index);
public long GetInt64(int index) => (long)GetUInt64(index);
public uint GetUInt32(int index)
{
switch (index)
return index switch
{
case 0: return (uint)(_e0 >> 0);
case 1: return (uint)(_e0 >> 32);
case 2: return (uint)(_e1 >> 0);
case 3: return (uint)(_e1 >> 32);
}
throw new ArgumentOutOfRangeException(nameof(index));
0 => (uint)(_e0 >> 0),
1 => (uint)(_e0 >> 32),
2 => (uint)(_e1 >> 0),
3 => (uint)(_e1 >> 32),
_ => throw new ArgumentOutOfRangeException(nameof(index)),
};
}
public ulong GetUInt64(int index)
{
switch (index)
return index switch
{
case 0: return _e0;
case 1: return _e1;
}
throw new ArgumentOutOfRangeException(nameof(index));
0 => _e0,
1 => _e1,
_ => throw new ArgumentOutOfRangeException(nameof(index)),
};
}
public byte[] ToArray()

View file

@ -5,7 +5,7 @@ namespace Ryujinx.Tests.Unicorn
{
public class UnicornAArch32 : IDisposable
{
internal readonly UnicornEngine.Unicorn uc;
internal readonly UnicornEngine.Unicorn Uc;
private bool _isDisposed;
public IndexedProperty<int, uint> R => new(GetX, SetX);
@ -84,7 +84,7 @@ namespace Ryujinx.Tests.Unicorn
public UnicornAArch32()
{
uc = new UnicornEngine.Unicorn(Common.UC_ARCH_ARM, Common.UC_MODE_LITTLE_ENDIAN);
Uc = new UnicornEngine.Unicorn(Common.UC_ARCH_ARM, Common.UC_MODE_LITTLE_ENDIAN);
SetRegister(Arm.UC_ARM_REG_C1_C0_2, GetRegister(Arm.UC_ARM_REG_C1_C0_2) | 0xf00000);
SetRegister(Arm.UC_ARM_REG_FPEXC, 0x40000000);
@ -105,7 +105,7 @@ namespace Ryujinx.Tests.Unicorn
{
if (!_isDisposed)
{
uc.Close();
Uc.Close();
_isDisposed = true;
}
}
@ -113,7 +113,7 @@ namespace Ryujinx.Tests.Unicorn
public void RunForCount(ulong count)
{
// FIXME: untilAddr should be 0xFFFFFFFFFFFFFFFFu
uc.EmuStart(this.PC, -1, 0, (long)count);
Uc.EmuStart(this.PC, -1, 0, (long)count);
}
public void Step()
@ -121,7 +121,7 @@ namespace Ryujinx.Tests.Unicorn
RunForCount(1);
}
private static int[] XRegisters =
private static readonly int[] _xRegisters =
{
Arm.UC_ARM_REG_R0,
Arm.UC_ARM_REG_R1,
@ -141,7 +141,8 @@ namespace Ryujinx.Tests.Unicorn
Arm.UC_ARM_REG_R15,
};
private static int[] QRegisters =
#pragma warning disable IDE0051, IDE0052 // Remove unused private member
private static readonly int[] _qRegisters =
{
Arm.UC_ARM_REG_Q0,
Arm.UC_ARM_REG_Q1,
@ -160,6 +161,7 @@ namespace Ryujinx.Tests.Unicorn
Arm.UC_ARM_REG_Q14,
Arm.UC_ARM_REG_Q15
};
#pragma warning restore IDE0051, IDE0052
public uint GetX(int index)
{
@ -168,7 +170,7 @@ namespace Ryujinx.Tests.Unicorn
throw new ArgumentOutOfRangeException(nameof(index));
}
return GetRegister(XRegisters[index]);
return GetRegister(_xRegisters[index]);
}
public void SetX(int index, uint value)
@ -178,7 +180,7 @@ namespace Ryujinx.Tests.Unicorn
throw new ArgumentOutOfRangeException(nameof(index));
}
SetRegister(XRegisters[index], value);
SetRegister(_xRegisters[index], value);
}
public SimdValue GetQ(int index)
@ -206,7 +208,7 @@ namespace Ryujinx.Tests.Unicorn
{
byte[] data = new byte[4];
uc.RegRead(register, data);
Uc.RegRead(register, data);
return BitConverter.ToUInt32(data, 0);
}
@ -215,16 +217,16 @@ namespace Ryujinx.Tests.Unicorn
{
byte[] data = BitConverter.GetBytes(value);
uc.RegWrite(register, data);
Uc.RegWrite(register, data);
}
public SimdValue GetVector(int register)
{
byte[] data = new byte[8];
uc.RegRead(register, data);
Uc.RegRead(register, data);
ulong lo = BitConverter.ToUInt64(data, 0);
uc.RegRead(register + 1, data);
Uc.RegRead(register + 1, data);
ulong hi = BitConverter.ToUInt64(data, 0);
return new SimdValue(lo, hi);
@ -233,16 +235,16 @@ namespace Ryujinx.Tests.Unicorn
private void SetVector(int register, SimdValue value)
{
byte[] data = BitConverter.GetBytes(value.GetUInt64(0));
uc.RegWrite(register, data);
Uc.RegWrite(register, data);
data = BitConverter.GetBytes(value.GetUInt64(1));
uc.RegWrite(register + 1, data);
Uc.RegWrite(register + 1, data);
}
public byte[] MemoryRead(ulong address, ulong size)
{
byte[] value = new byte[size];
uc.MemRead((long)address, value);
Uc.MemRead((long)address, value);
return value;
}
@ -254,7 +256,7 @@ namespace Ryujinx.Tests.Unicorn
public void MemoryWrite(ulong address, byte[] value)
{
uc.MemWrite((long)address, value);
Uc.MemWrite((long)address, value);
}
public void MemoryWrite8(ulong address, byte value) => MemoryWrite(address, new[] { value });
@ -267,17 +269,17 @@ namespace Ryujinx.Tests.Unicorn
public void MemoryMap(ulong address, ulong size, MemoryPermission permissions)
{
uc.MemMap((long)address, (long)size, (int)permissions);
Uc.MemMap((long)address, (long)size, (int)permissions);
}
public void MemoryUnmap(ulong address, ulong size)
{
uc.MemUnmap((long)address, (long)size);
Uc.MemUnmap((long)address, (long)size);
}
public void MemoryProtect(ulong address, ulong size, MemoryPermission permissions)
{
uc.MemProtect((long)address, (long)size, (int)permissions);
Uc.MemProtect((long)address, (long)size, (int)permissions);
}
}
}

View file

@ -5,7 +5,7 @@ namespace Ryujinx.Tests.Unicorn
{
public class UnicornAArch64 : IDisposable
{
internal readonly UnicornEngine.Unicorn uc;
internal readonly UnicornEngine.Unicorn Uc;
private bool _isDisposed;
public IndexedProperty<int, ulong> X => new(GetX, SetX);
@ -33,48 +33,48 @@ namespace Ryujinx.Tests.Unicorn
public uint Pstate
{
get => (uint)GetRegister(Arm64.UC_ARM64_REG_PSTATE);
set => SetRegister(Arm64.UC_ARM64_REG_PSTATE, value);
set => SetRegister(Arm64.UC_ARM64_REG_PSTATE, value);
}
public int Fpcr
{
get => (int)GetRegister(Arm64.UC_ARM64_REG_FPCR);
set => SetRegister(Arm64.UC_ARM64_REG_FPCR, (uint)value);
set => SetRegister(Arm64.UC_ARM64_REG_FPCR, (uint)value);
}
public int Fpsr
{
get => (int)GetRegister(Arm64.UC_ARM64_REG_FPSR);
set => SetRegister(Arm64.UC_ARM64_REG_FPSR, (uint)value);
set => SetRegister(Arm64.UC_ARM64_REG_FPSR, (uint)value);
}
public bool OverflowFlag
{
get => (Pstate & 0x10000000u) != 0;
get => (Pstate & 0x10000000u) != 0;
set => Pstate = (Pstate & ~0x10000000u) | (value ? 0x10000000u : 0u);
}
public bool CarryFlag
{
get => (Pstate & 0x20000000u) != 0;
get => (Pstate & 0x20000000u) != 0;
set => Pstate = (Pstate & ~0x20000000u) | (value ? 0x20000000u : 0u);
}
public bool ZeroFlag
{
get => (Pstate & 0x40000000u) != 0;
get => (Pstate & 0x40000000u) != 0;
set => Pstate = (Pstate & ~0x40000000u) | (value ? 0x40000000u : 0u);
}
public bool NegativeFlag
{
get => (Pstate & 0x80000000u) != 0;
get => (Pstate & 0x80000000u) != 0;
set => Pstate = (Pstate & ~0x80000000u) | (value ? 0x80000000u : 0u);
}
public UnicornAArch64()
{
uc = new UnicornEngine.Unicorn(Common.UC_ARCH_ARM64, Common.UC_MODE_LITTLE_ENDIAN);
Uc = new UnicornEngine.Unicorn(Common.UC_ARCH_ARM64, Common.UC_MODE_LITTLE_ENDIAN);
SetRegister(Arm64.UC_ARM64_REG_CPACR_EL1, 0x00300000);
}
@ -94,7 +94,7 @@ namespace Ryujinx.Tests.Unicorn
{
if (!_isDisposed)
{
uc.Close();
Uc.Close();
_isDisposed = true;
}
}
@ -102,7 +102,7 @@ namespace Ryujinx.Tests.Unicorn
public void RunForCount(ulong count)
{
// FIXME: untilAddr should be 0xFFFFFFFFFFFFFFFFul
uc.EmuStart((long)this.PC, -1, 0, (long)count);
Uc.EmuStart((long)this.PC, -1, 0, (long)count);
}
public void Step()
@ -110,7 +110,7 @@ namespace Ryujinx.Tests.Unicorn
RunForCount(1);
}
private static int[] XRegisters =
private static readonly int[] _xRegisters =
{
Arm64.UC_ARM64_REG_X0,
Arm64.UC_ARM64_REG_X1,
@ -145,7 +145,7 @@ namespace Ryujinx.Tests.Unicorn
Arm64.UC_ARM64_REG_X30,
};
private static int[] QRegisters =
private static readonly int[] _qRegisters =
{
Arm64.UC_ARM64_REG_Q0,
Arm64.UC_ARM64_REG_Q1,
@ -188,7 +188,7 @@ namespace Ryujinx.Tests.Unicorn
throw new ArgumentOutOfRangeException(nameof(index));
}
return GetRegister(XRegisters[index]);
return GetRegister(_xRegisters[index]);
}
public void SetX(int index, ulong value)
@ -198,7 +198,7 @@ namespace Ryujinx.Tests.Unicorn
throw new ArgumentOutOfRangeException(nameof(index));
}
SetRegister(XRegisters[index], value);
SetRegister(_xRegisters[index], value);
}
public SimdValue GetQ(int index)
@ -208,7 +208,7 @@ namespace Ryujinx.Tests.Unicorn
throw new ArgumentOutOfRangeException(nameof(index));
}
return GetVector(QRegisters[index]);
return GetVector(_qRegisters[index]);
}
public void SetQ(int index, SimdValue value)
@ -218,14 +218,14 @@ namespace Ryujinx.Tests.Unicorn
throw new ArgumentOutOfRangeException(nameof(index));
}
SetVector(QRegisters[index], value);
SetVector(_qRegisters[index], value);
}
private ulong GetRegister(int register)
{
byte[] data = new byte[8];
uc.RegRead(register, data);
Uc.RegRead(register, data);
return BitConverter.ToUInt64(data, 0);
}
@ -234,14 +234,14 @@ namespace Ryujinx.Tests.Unicorn
{
byte[] data = BitConverter.GetBytes(value);
uc.RegWrite(register, data);
Uc.RegWrite(register, data);
}
private SimdValue GetVector(int register)
{
byte[] data = new byte[16];
uc.RegRead(register, data);
Uc.RegRead(register, data);
return new SimdValue(data);
}
@ -250,49 +250,49 @@ namespace Ryujinx.Tests.Unicorn
{
byte[] data = value.ToArray();
uc.RegWrite(register, data);
Uc.RegWrite(register, data);
}
public byte[] MemoryRead(ulong address, ulong size)
{
byte[] value = new byte[size];
uc.MemRead((long)address, value);
Uc.MemRead((long)address, value);
return value;
}
public byte MemoryRead8 (ulong address) => MemoryRead(address, 1)[0];
public byte MemoryRead8(ulong address) => MemoryRead(address, 1)[0];
public ushort MemoryRead16(ulong address) => BitConverter.ToUInt16(MemoryRead(address, 2), 0);
public uint MemoryRead32(ulong address) => BitConverter.ToUInt32(MemoryRead(address, 4), 0);
public ulong MemoryRead64(ulong address) => BitConverter.ToUInt64(MemoryRead(address, 8), 0);
public uint MemoryRead32(ulong address) => BitConverter.ToUInt32(MemoryRead(address, 4), 0);
public ulong MemoryRead64(ulong address) => BitConverter.ToUInt64(MemoryRead(address, 8), 0);
public void MemoryWrite(ulong address, byte[] value)
{
uc.MemWrite((long)address, value);
Uc.MemWrite((long)address, value);
}
public void MemoryWrite8 (ulong address, byte value) => MemoryWrite(address, new[]{ value });
public void MemoryWrite16(ulong address, short value) => MemoryWrite(address, BitConverter.GetBytes(value));
public void MemoryWrite8(ulong address, byte value) => MemoryWrite(address, new[] { value });
public void MemoryWrite16(ulong address, short value) => MemoryWrite(address, BitConverter.GetBytes(value));
public void MemoryWrite16(ulong address, ushort value) => MemoryWrite(address, BitConverter.GetBytes(value));
public void MemoryWrite32(ulong address, int value) => MemoryWrite(address, BitConverter.GetBytes(value));
public void MemoryWrite32(ulong address, int value) => MemoryWrite(address, BitConverter.GetBytes(value));
public void MemoryWrite32(ulong address, uint value) => MemoryWrite(address, BitConverter.GetBytes(value));
public void MemoryWrite64(ulong address, long value) => MemoryWrite(address, BitConverter.GetBytes(value));
public void MemoryWrite64(ulong address, long value) => MemoryWrite(address, BitConverter.GetBytes(value));
public void MemoryWrite64(ulong address, ulong value) => MemoryWrite(address, BitConverter.GetBytes(value));
public void MemoryMap(ulong address, ulong size, MemoryPermission permissions)
{
uc.MemMap((long)address, (long)size, (int)permissions);
Uc.MemMap((long)address, (long)size, (int)permissions);
}
public void MemoryUnmap(ulong address, ulong size)
{
uc.MemUnmap((long)address, (long)size);
Uc.MemUnmap((long)address, (long)size);
}
public void MemoryProtect(ulong address, ulong size, MemoryPermission permissions)
{
uc.MemProtect((long)address, (long)size, (int)permissions);
Uc.MemProtect((long)address, (long)size, (int)permissions);
}
}
}

View file

@ -163,7 +163,7 @@ namespace Ryujinx.Ui.Windows
private void SelectLastScannedAmiibo()
{
bool isSet = _amiiboSeriesComboBox.SetActiveId(_amiiboList.FirstOrDefault(amiibo => amiibo.Head + amiibo.Tail == LastScannedAmiiboId).AmiiboSeries);
bool isSet = _amiiboSeriesComboBox.SetActiveId(_amiiboList.Find(amiibo => amiibo.Head + amiibo.Tail == LastScannedAmiiboId).AmiiboSeries);
isSet = _amiiboCharsComboBox.SetActiveId(LastScannedAmiiboId);
if (isSet == false)
@ -305,7 +305,7 @@ namespace Ryujinx.Ui.Windows
_amiiboImage.Pixbuf = new Gdk.Pixbuf(_amiiboLogoBytes);
string imageUrl = _amiiboList.FirstOrDefault(amiibo => amiibo.Head + amiibo.Tail == _amiiboCharsComboBox.ActiveId).Image;
string imageUrl = _amiiboList.Find(amiibo => amiibo.Head + amiibo.Tail == _amiiboCharsComboBox.ActiveId).Image;
var usageStringBuilder = new StringBuilder();

View file

@ -5,7 +5,7 @@ namespace Spv.Generator
{
internal struct ConstantKey : IEquatable<ConstantKey>
{
private Instruction _constant;
private readonly Instruction _constant;
public ConstantKey(Instruction constant)
{

View file

@ -5,7 +5,7 @@ namespace Spv.Generator
{
internal class DeterministicStringKey : IEquatable<DeterministicStringKey>
{
private string _value;
private readonly string _value;
public DeterministicStringKey(string value)
{

View file

@ -8,7 +8,7 @@ namespace Spv.Generator
{
public OperandType Type => OperandType.String;
private string _value;
private readonly string _value;
public LiteralString(string value)
{

View file

@ -5,7 +5,7 @@ namespace Spv.Generator
{
internal struct TypeDeclarationKey : IEquatable<TypeDeclarationKey>
{
private Instruction _typeDeclaration;
private readonly Instruction _typeDeclaration;
public TypeDeclarationKey(Instruction typeDeclaration)
{