Compare commits

..

11 Commits

Author SHA1 Message Date
TSRBerry
b29ded1d60 [Ryujinx.SDL2.Common] Address dotnet-format issues (#5387)
* dotnet format style --severity info

Some changes were manually reverted.

* Address dotnet format CA1816 warnings

* Address or silence dotnet format CA1806 and a few CA1854 warnings

* Address most dotnet format whitespace warnings

* dotnet format whitespace after rebase
2023-06-26 01:51:16 +00:00
Mary
9860bfb2cd misc: memory: Migrate from OutOfMemoryException to SystemException entirely (#5399)
Fix a regression with address space allocation while providing more
information about the context of the exception.
2023-06-26 01:37:12 +00:00
TSRBerry
f6ada8d169 [Ryujinx.Graphics.Device] Address dotnet-format issues (#5363)
* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Address most dotnet format whitespace warnings

* dotnet format whitespace after rebase
2023-06-25 23:58:44 +02:00
TSRBerry
42d31f646d [Ryujinx.Audio.Backends.SDL2] Address dotnet-format issues (#5364)
* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format analyzers --serverity info

Some changes have been minimally adapted.

* Address dotnet format CA1816 warnings

* Address most dotnet format whitespace warnings

* Run dotnet format style after rebase

* Run dotnet format analyzers after rebase

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

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

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* Update src/Ryujinx.Audio.Backends.SDL2/SDL2HardwareDeviceDriver.cs

Co-authored-by: Ac_K <Acoustik666@gmail.com>

---------

Co-authored-by: Ac_K <Acoustik666@gmail.com>
2023-06-25 22:50:59 +02:00
TSRBerry
07fc3ded68 [Ryujinx.Graphics.Nvdec] Address dotnet-format issues (#5369)
* dotnet format style --severity info

Some changes were manually reverted.

* Restore a few unused methods and variables

* 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

* Add previously silenced warnings back

I have no clue how these disappeared

* Add comments to disabled warnings

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

* Address IDE0251 warnings

* 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
2023-06-25 21:44:42 +02:00
TSRBerry
fd01259d2b [Ryujinx.ShaderTools] Address dotnet-format issues (#5388)
* dotnet format style --severity info

Some changes were manually reverted.

* dotnet format whitespace after rebase
2023-06-25 21:37:33 +02:00
TSRBerry
7ffe7f8442 [Ryujinx.Graphics.Nvdec.FFmpeg] Address dotnet-format issues (#5370)
* dotnet format style --severity info

Some changes were manually reverted.

* Address or silence dotnet format CA1806 and a few CA1854 warnings

* 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

* Add comments to disabled warnings

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

* Address IDE0251 warnings

* 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
2023-06-25 19:03:48 +02:00
TSRBerry
2b2ce68f07 [Ryujinx.Tests.Memory] Address dotnet-format issues (#5390)
* 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 dotnet format CA1822 warnings

* 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

* Add comments to disabled warnings

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

* 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

* Final dotnet format pass and fix naming rule violations

* Apply suggestions from code review

Co-authored-by: Ac_K <Acoustik666@gmail.com>

* Remove unused constant

---------

Co-authored-by: Ac_K <Acoustik666@gmail.com>
2023-06-25 18:37:53 +02:00
TSRBerry
bc53d00463 [Ryujinx.Graphics.Vic] Address dotnet-format issues (#5374)
* dotnet format style --severity info

Some changes were manually reverted.

* Restore a few unused methods and variables

* Address review comments

* Address most dotnet format whitespace warnings

* Add comments to disabled warnings

* Address IDE0251 warnings

* dotnet format whitespace after rebase

* Remove SuppressMessage attribute for removed rule
2023-06-25 18:37:09 +02:00
TSRBerry
bddb2a1483 [Ryujinx.Tests.Unicorn] Address dotnet-format issues (#5391)
* dotnet format style --severity info

Some changes were manually reverted.

* Restore a few unused methods and variables

* 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

* Add comments to disabled warnings

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

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

This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e.

* dotnet format whitespace after rebase

* Final dotnet format pass and fix naming rule violations
2023-06-25 18:03:08 +02:00
Shihta Kuan
e3bacfa774 Set COMPlus_DefaultStackSize to 2M in macOS (#5349)
* Set COMPlus_DefaultStackSize to 2M in macOS

* Remove the custom thread stack size on Ryujinx.Ava
2023-06-25 14:49:53 +02:00
70 changed files with 311 additions and 297 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

@@ -19,12 +19,14 @@ namespace Ryujinx.Audio.Backends.SDL2
private readonly ManualResetEvent _pauseEvent;
private readonly ConcurrentDictionary<SDL2HardwareDeviceSession, byte> _sessions;
private bool _supportSurroundConfiguration;
private readonly bool _supportSurroundConfiguration;
// TODO: Add this to SDL2-CS
// NOTE: We use a DllImport here because of marshaling issue for spec.
#pragma warning disable SYSLIB1054
[DllImport("SDL2")]
private static extern int SDL_GetDefaultAudioInfo(IntPtr name, out SDL_AudioSpec spec, int isCapture);
#pragma warning restore SYSLIB1054
public SDL2HardwareDeviceDriver()
{
@@ -90,7 +92,7 @@ namespace Ryujinx.Audio.Backends.SDL2
throw new NotImplementedException("Input direction is currently not implemented on SDL2 backend!");
}
SDL2HardwareDeviceSession session = new SDL2HardwareDeviceSession(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
SDL2HardwareDeviceSession session = new(this, memoryManager, sampleFormat, sampleRate, channelCount, volume);
_sessions.TryAdd(session, 0);
@@ -135,8 +137,7 @@ namespace Ryujinx.Audio.Backends.SDL2
if (device == 0)
{
Logger.Error?.Print(LogClass.Application,
$"SDL2 open audio device initialization failed with error \"{SDL_GetError()}\"");
Logger.Error?.Print(LogClass.Application, $"SDL2 open audio device initialization failed with error \"{SDL_GetError()}\"");
return 0;
}
@@ -156,6 +157,7 @@ namespace Ryujinx.Audio.Backends.SDL2
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}

View File

@@ -12,19 +12,19 @@ namespace Ryujinx.Audio.Backends.SDL2
{
class SDL2HardwareDeviceSession : HardwareDeviceSessionOutputBase
{
private SDL2HardwareDeviceDriver _driver;
private ConcurrentQueue<SDL2AudioBuffer> _queuedBuffers;
private DynamicRingBuffer _ringBuffer;
private readonly SDL2HardwareDeviceDriver _driver;
private readonly ConcurrentQueue<SDL2AudioBuffer> _queuedBuffers;
private readonly DynamicRingBuffer _ringBuffer;
private ulong _playedSampleCount;
private ManualResetEvent _updateRequiredEvent;
private readonly ManualResetEvent _updateRequiredEvent;
private uint _outputStream;
private bool _hasSetupError;
private SDL_AudioCallback _callbackDelegate;
private int _bytesPerFrame;
private readonly SDL_AudioCallback _callbackDelegate;
private readonly int _bytesPerFrame;
private uint _sampleCount;
private bool _started;
private float _volume;
private ushort _nativeSampleFormat;
private readonly ushort _nativeSampleFormat;
public SDL2HardwareDeviceSession(SDL2HardwareDeviceDriver driver, IVirtualMemoryManager memoryManager, SampleFormat requestedSampleFormat, uint requestedSampleRate, uint requestedChannelCount, float requestedVolume) : base(memoryManager, requestedSampleFormat, requestedSampleRate, requestedChannelCount)
{
@@ -72,7 +72,7 @@ namespace Ryujinx.Audio.Backends.SDL2
private unsafe void Update(IntPtr userdata, IntPtr stream, int streamLength)
{
Span<byte> streamSpan = new Span<byte>((void*)stream, streamLength);
Span<byte> streamSpan = new((void*)stream, streamLength);
int maxFrameCount = (int)GetSampleCount(streamLength);
int bufferedFrames = _ringBuffer.Length / _bytesPerFrame;
@@ -82,7 +82,7 @@ namespace Ryujinx.Audio.Backends.SDL2
if (frameCount == 0)
{
// SDL2 left the responsibility to the user to clear the buffer.
streamSpan.Fill(0);
streamSpan.Clear();
return;
}
@@ -96,7 +96,7 @@ namespace Ryujinx.Audio.Backends.SDL2
IntPtr pStreamSrc = (IntPtr)p;
// Zero the dest buffer
streamSpan.Fill(0);
streamSpan.Clear();
// Apply volume to written data
SDL_MixAudioFormat(stream, pStreamSrc, _nativeSampleFormat, (uint)samples.Length, (int)(_volume * SDL_MIX_MAXVOLUME));
@@ -151,7 +151,7 @@ namespace Ryujinx.Audio.Backends.SDL2
if (_outputStream != 0)
{
SDL2AudioBuffer driverBuffer = new SDL2AudioBuffer(buffer.DataPointer, GetSampleCount(buffer));
SDL2AudioBuffer driverBuffer = new(buffer.DataPointer, GetSampleCount(buffer));
_ringBuffer.Write(buffer.Data, 0, buffer.Data.Length);

View File

@@ -134,7 +134,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

@@ -199,7 +199,7 @@ namespace Ryujinx.Cpu
break;
}
catch (OutOfMemoryException)
catch (SystemException)
{
baseMemory?.Dispose();
mirrorMemory?.Dispose();

View File

@@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.Device
public TState State;
private uint Size => (uint)(Unsafe.SizeOf<TState>() + RegisterSize - 1) / RegisterSize;
private static uint Size => (uint)(Unsafe.SizeOf<TState>() + RegisterSize - 1) / RegisterSize;
private readonly Func<int>[] _readCallbacks;
private readonly Action<int>[] _writeCallbacks;

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);
@@ -118,4 +118,4 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
WriteBits((int)value, size - 1);
}
}
}
}

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,26 +1,24 @@
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,11 +43,11 @@ 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;
}
public void Dispose() => _context.Dispose();
}
}
}

View File

@@ -17,12 +17,12 @@ namespace Ryujinx.Graphics.Nvdec
ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.BitstreamSize);
int width = (int)pictureInfo.PicWidthInMbs * MbSizeInPixels;
int width = (int)pictureInfo.PicWidthInMbs * MbSizeInPixels;
int height = (int)pictureInfo.PicHeightInMbs * MbSizeInPixels;
int surfaceIndex = (int)pictureInfo.OutputSurfaceIndex;
uint lumaOffset = state.SetPictureLumaOffset[surfaceIndex];
uint lumaOffset = state.SetPictureLumaOffset[surfaceIndex];
uint chromaOffset = state.SetPictureChromaOffset[surfaceIndex];
Decoder decoder = context.GetH264Decoder();
@@ -36,7 +36,7 @@ namespace Ryujinx.Graphics.Nvdec
SurfaceWriter.Write(
rm.Gmm,
outputSurface,
lumaOffset + pictureInfo.LumaFrameOffset,
lumaOffset + pictureInfo.LumaFrameOffset,
chromaOffset + pictureInfo.ChromaFrameOffset);
}
else
@@ -44,9 +44,9 @@ namespace Ryujinx.Graphics.Nvdec
SurfaceWriter.WriteInterlaced(
rm.Gmm,
outputSurface,
lumaOffset + pictureInfo.LumaTopFieldOffset,
lumaOffset + pictureInfo.LumaTopFieldOffset,
chromaOffset + pictureInfo.ChromaTopFieldOffset,
lumaOffset + pictureInfo.LumaBottomFieldOffset,
lumaOffset + pictureInfo.LumaBottomFieldOffset,
chromaOffset + pictureInfo.ChromaBottomFieldOffset);
}
}

View File

@@ -43,7 +43,7 @@ namespace Ryujinx.Graphics.Nvdec.Image
int width,
int height)
{
OffsetCalculator calc = new OffsetCalculator(width, height, 0, false, 2, 2);
OffsetCalculator calc = new(width, height, 0, false, 2, 2);
if (Sse2.IsSupported)
{

View File

@@ -60,7 +60,7 @@ namespace Ryujinx.Graphics.Nvdec.Image
WriteLuma(
lumaBottom.Memory.Span,
surface.YPlane.AsSpan().Slice(surface.Stride),
surface.YPlane.AsSpan()[surface.Stride..],
surface.Stride * 2,
surface.Width,
surface.Height / 2);
@@ -80,8 +80,8 @@ namespace Ryujinx.Graphics.Nvdec.Image
WriteChroma(
chromaBottom.Memory.Span,
surface.UPlane.AsSpan().Slice(surface.UvStride),
surface.VPlane.AsSpan().Slice(surface.UvStride),
surface.UPlane.AsSpan()[surface.UvStride..],
surface.VPlane.AsSpan()[surface.UvStride..],
surface.UvStride * 2,
surface.UvWidth,
surface.UvHeight / 2);
@@ -100,7 +100,7 @@ namespace Ryujinx.Graphics.Nvdec.Image
int width,
int height)
{
OffsetCalculator calc = new OffsetCalculator(width, height, 0, false, 2, 2);
OffsetCalculator calc = new(width, height, 0, false, 2, 2);
if (Sse2.IsSupported)
{

View File

@@ -26,4 +26,4 @@ namespace Ryujinx.Graphics.Nvdec
_vp8Decoder = null;
}
}
}
}

View File

@@ -14,7 +14,7 @@ namespace Ryujinx.Graphics.Nvdec
private readonly DeviceState<NvdecRegisters> _state;
private long _currentId;
private ConcurrentDictionary<long, NvdecDecoderContext> _contexts;
private readonly ConcurrentDictionary<long, NvdecDecoderContext> _contexts;
private NvdecDecoderContext _currentContext;
public NvdecDevice(MemoryManager gmm)

View File

@@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec
{
struct NvdecRegisters
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public Array64<uint> Reserved0;
public uint Nop;
public Array63<uint> Reserved104;

View File

@@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec
{
struct NvdecStatus
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public uint MbsCorrectlyDecoded;
public uint MbsInError;
public uint Reserved;
@@ -13,4 +13,4 @@ namespace Ryujinx.Graphics.Nvdec
public uint SliceHeaderErrorCode;
#pragma warning restore CS0649
}
}
}

View File

@@ -5,8 +5,9 @@ namespace Ryujinx.Graphics.Nvdec.Types.H264
{
struct PictureInfo
{
#pragma warning disable CS0169, CS0649
#pragma warning disable IDE0051, CS0169, CS0649 // Remove unused private member
Array18<uint> Unknown0;
#pragma warning restore IDE0051
public uint BitstreamSize;
public uint NumSlices;
public uint Unknown50;
@@ -50,24 +51,24 @@ namespace Ryujinx.Graphics.Nvdec.Types.H264
public Array10<uint> Unknown2D4;
#pragma warning restore CS0169, CS0649
public bool MbAdaptiveFrameFieldFlag => (Flags & (1 << 0)) != 0;
public bool Direct8x8InferenceFlag => (Flags & (1 << 1)) != 0;
public bool WeightedPredFlag => (Flags & (1 << 2)) != 0;
public bool ConstrainedIntraPredFlag => (Flags & (1 << 3)) != 0;
public bool IsReference => (Flags & (1 << 4)) != 0;
public bool FieldPicFlag => (Flags & (1 << 5)) != 0;
public bool BottomFieldFlag => (Flags & (1 << 6)) != 0;
public uint Log2MaxFrameNumMinus4 => (uint)(Flags >> 8) & 0xf;
public ushort ChromaFormatIdc => (ushort)((Flags >> 12) & 3);
public uint PicOrderCntType => (uint)(Flags >> 14) & 3;
public int PicInitQpMinus26 => ExtractSx(Flags, 16, 6);
public int ChromaQpIndexOffset => ExtractSx(Flags, 22, 5);
public int SecondChromaQpIndexOffset => ExtractSx(Flags, 27, 5);
public uint WeightedBipredIdc => (uint)(Flags >> 32) & 3;
public uint OutputSurfaceIndex => (uint)(Flags >> 34) & 0x7f;
public uint ColIndex => (uint)(Flags >> 41) & 0x1f;
public ushort FrameNum => (ushort)(Flags >> 46);
public bool QpprimeYZeroTransformBypassFlag => (Flags2 & (1 << 1)) != 0;
public readonly bool MbAdaptiveFrameFieldFlag => (Flags & (1 << 0)) != 0;
public readonly bool Direct8x8InferenceFlag => (Flags & (1 << 1)) != 0;
public readonly bool WeightedPredFlag => (Flags & (1 << 2)) != 0;
public readonly bool ConstrainedIntraPredFlag => (Flags & (1 << 3)) != 0;
public readonly bool IsReference => (Flags & (1 << 4)) != 0;
public readonly bool FieldPicFlag => (Flags & (1 << 5)) != 0;
public readonly bool BottomFieldFlag => (Flags & (1 << 6)) != 0;
public readonly uint Log2MaxFrameNumMinus4 => (uint)(Flags >> 8) & 0xf;
public readonly ushort ChromaFormatIdc => (ushort)((Flags >> 12) & 3);
public readonly uint PicOrderCntType => (uint)(Flags >> 14) & 3;
public readonly int PicInitQpMinus26 => ExtractSx(Flags, 16, 6);
public readonly int ChromaQpIndexOffset => ExtractSx(Flags, 22, 5);
public readonly int SecondChromaQpIndexOffset => ExtractSx(Flags, 27, 5);
public readonly uint WeightedBipredIdc => (uint)(Flags >> 32) & 3;
public readonly uint OutputSurfaceIndex => (uint)(Flags >> 34) & 0x7f;
public readonly uint ColIndex => (uint)(Flags >> 41) & 0x1f;
public readonly ushort FrameNum => (ushort)(Flags >> 46);
public readonly bool QpprimeYZeroTransformBypassFlag => (Flags2 & (1 << 1)) != 0;
private static int ExtractSx(ulong packed, int lsb, int length)
{

View File

@@ -4,12 +4,12 @@ namespace Ryujinx.Graphics.Nvdec.Types.H264
{
struct ReferenceFrame
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public uint Flags;
public Array2<uint> FieldOrderCnt;
public uint FrameNum;
#pragma warning restore CS0649
public uint OutputSurfaceIndex => (uint)Flags & 0x7f;
public readonly uint OutputSurfaceIndex => (uint)Flags & 0x7f;
}
}

View File

@@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.Types.Vp8
{
struct PictureInfo
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public Array13<uint> Unknown0;
public uint GpTimerTimeoutValue;
public ushort FrameWidth;

View File

@@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.Types.Vp9
{
struct EntropyProbs
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public Array10<Array10<Array8<byte>>> KfYModeProbE0ToE7;
public Array10<Array10<byte>> KfYModeProbE8;
public Array3<byte> Padding384;

View File

@@ -2,7 +2,7 @@
{
struct FrameSize
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public ushort Width;
public ushort Height;
public ushort LumaPitch;

View File

@@ -2,7 +2,7 @@
{
struct FrameStats
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public uint Unknown0;
public uint Unknown4;
public uint Pass2CycleCount;

View File

@@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.Types.Vp9
{
struct LoopFilter
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public byte ModeRefDeltaEnabled;
public Array4<sbyte> RefDeltas;
public Array2<sbyte> ModeDeltas;

View File

@@ -5,7 +5,7 @@ namespace Ryujinx.Graphics.Nvdec.Types.Vp9
{
struct PictureInfo
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public Array12<uint> Unknown0;
public uint BitstreamSize;
public uint IsEncrypted;
@@ -44,7 +44,7 @@ namespace Ryujinx.Graphics.Nvdec.Types.Vp9
public uint UnknownFC;
#pragma warning restore CS0649
public uint BitDepth => (SurfaceParams >> 1) & 0xf;
public readonly uint BitDepth => (SurfaceParams >> 1) & 0xf;
public Vp9PictureInfo Convert()
{

View File

@@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Nvdec.Types.Vp9
{
struct Segmentation
{
#pragma warning disable CS0649
#pragma warning disable CS0649 // Field is never assigned to
public byte Enabled;
public byte UpdateMap;
public byte TemporalUpdate;

View File

@@ -30,4 +30,4 @@ namespace Ryujinx.Graphics.Nvdec
rm.Cache.Put(outputSurface);
}
}
}
}

View File

@@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.Nvdec
{
static class Vp9Decoder
{
private static Decoder _decoder = new Decoder();
private static readonly Decoder _decoder = new();
public unsafe static void Decode(ResourceManager rm, ref NvdecRegisters state)
{
@@ -25,9 +25,9 @@ namespace Ryujinx.Graphics.Nvdec
return rm.Cache.Get(_decoder, lumaOffset, chromaOffset, size.Width, size.Height);
}
ISurface lastSurface = Rent(state.SetPictureLumaOffset[0], state.SetPictureChromaOffset[0], pictureInfo.LastFrameSize);
ISurface goldenSurface = Rent(state.SetPictureLumaOffset[1], state.SetPictureChromaOffset[1], pictureInfo.GoldenFrameSize);
ISurface altSurface = Rent(state.SetPictureLumaOffset[2], state.SetPictureChromaOffset[2], pictureInfo.AltFrameSize);
ISurface lastSurface = Rent(state.SetPictureLumaOffset[0], state.SetPictureChromaOffset[0], pictureInfo.LastFrameSize);
ISurface goldenSurface = Rent(state.SetPictureLumaOffset[1], state.SetPictureChromaOffset[1], pictureInfo.GoldenFrameSize);
ISurface altSurface = Rent(state.SetPictureLumaOffset[2], state.SetPictureChromaOffset[2], pictureInfo.AltFrameSize);
ISurface currentSurface = Rent(state.SetPictureLumaOffset[3], state.SetPictureChromaOffset[3], pictureInfo.CurrentFrameSize);
Vp9PictureInfo info = pictureInfo.Convert();
@@ -54,7 +54,7 @@ namespace Ryujinx.Graphics.Nvdec
Span<Vp9MvRef> mvsOut = MemoryMarshal.Cast<byte, Vp9MvRef>(mvsRegion.Memory.Span);
uint lumaOffset = state.SetPictureLumaOffset[3];
uint lumaOffset = state.SetPictureLumaOffset[3];
uint chromaOffset = state.SetPictureChromaOffset[3];
if (_decoder.Decode(ref info, currentSurface, bitstream, mvsIn, mvsOut))

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

@@ -15,4 +15,4 @@ namespace Ryujinx.Graphics.Vic
Height = height;
}
}
}
}

View File

@@ -121,4 +121,4 @@ namespace Ryujinx.Graphics.Vic
}
}
}
}
}

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

@@ -9,4 +9,4 @@ namespace Ryujinx.Graphics.Vic.Types
Disi1,
WeaveLumaBobFieldChroma
}
}
}

View File

@@ -76,4 +76,4 @@ namespace Ryujinx.Graphics.Vic.Types
return false;
}
}
}
}

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

@@ -31,7 +31,7 @@ namespace Ryujinx.Memory
/// </summary>
/// <param name="size">Size of the memory block in bytes</param>
/// <param name="flags">Flags that controls memory block memory allocation</param>
/// <exception cref="OutOfMemoryException">Throw when there's no enough memory to allocate the requested size</exception>
/// <exception cref="SystemException">Throw when there's an error while allocating the requested size</exception>
/// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
public MemoryBlock(ulong size, MemoryAllocationFlags flags = MemoryAllocationFlags.None)
{
@@ -66,7 +66,7 @@ namespace Ryujinx.Memory
/// </summary>
/// <param name="size">Size of the memory block in bytes</param>
/// <param name="sharedMemory">Shared memory to use as backing storage for this block</param>
/// <exception cref="OutOfMemoryException">Throw when there's no enough address space left to map the shared memory</exception>
/// <exception cref="SystemException">Throw when there's an error while mapping the shared memory</exception>
/// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
private MemoryBlock(ulong size, IntPtr sharedMemory)
{
@@ -82,7 +82,7 @@ namespace Ryujinx.Memory
/// </summary>
/// <returns>A new memory block that shares storage with this one</returns>
/// <exception cref="NotSupportedException">Throw when the current memory block does not support mirroring</exception>
/// <exception cref="OutOfMemoryException">Throw when there's no enough address space left to map the shared memory</exception>
/// <exception cref="SystemException">Throw when there's an error while mapping the shared memory</exception>
/// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
public MemoryBlock CreateMirror()
{

View File

@@ -147,12 +147,12 @@ namespace Ryujinx.Memory
fd = shm_open((IntPtr)pMemName, 0x2 | 0x200 | 0x800 | 0x400, 384); // O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0600
if (fd == -1)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
if (shm_unlink((IntPtr)pMemName) != 0)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
}
}
@@ -165,22 +165,22 @@ namespace Ryujinx.Memory
fd = mkstemp((IntPtr)pFileName);
if (fd == -1)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
if (unlink((IntPtr)pFileName) != 0)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
}
}
if (ftruncate(fd, (IntPtr)size) != 0)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
return (IntPtr)fd;
return fd;
}
public static void DestroySharedMemory(IntPtr handle)

View File

@@ -114,7 +114,7 @@ namespace Ryujinx.Memory
if (handle == IntPtr.Zero)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
return handle;
@@ -134,7 +134,7 @@ namespace Ryujinx.Memory
if (ptr == IntPtr.Zero)
{
throw new OutOfMemoryException();
throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
}
return ptr;

View File

@@ -19,10 +19,7 @@ namespace Ryujinx.SDL2.Common
{
get
{
if (_instance == null)
{
_instance = new SDL2Driver();
}
_instance ??= new SDL2Driver();
return _instance;
}
@@ -43,7 +40,7 @@ namespace Ryujinx.SDL2.Common
private readonly object _lock = new();
private SDL2Driver() {}
private SDL2Driver() { }
private const string SDL_HINT_JOYSTICK_HIDAPI_COMBINE_JOY_CONS = "SDL_JOYSTICK_HIDAPI_COMBINE_JOY_CONS";
@@ -80,8 +77,15 @@ namespace Ryujinx.SDL2.Common
}
// First ensure that we only enable joystick events (for connected/disconnected).
SDL_GameControllerEventState(SDL_DISABLE);
SDL_JoystickEventState(SDL_ENABLE);
if (SDL_GameControllerEventState(SDL_IGNORE) != SDL_IGNORE)
{
Logger.Error?.PrintMsg(LogClass.Application, "Couldn't change the state of game controller events.");
}
if (SDL_JoystickEventState(SDL_ENABLE) < 0)
{
Logger.Error?.PrintMsg(LogClass.Application, $"Failed to enable joystick event polling: {SDL_GetError()}");
}
// Disable all joysticks information, we don't need them no need to flood the event queue for that.
SDL_EventState(SDL_EventType.SDL_JOYAXISMOTION, SDL_DISABLE);
@@ -153,7 +157,7 @@ namespace Ryujinx.SDL2.Common
{
const int WaitTimeMs = 10;
using ManualResetEventSlim waitHandle = new ManualResetEventSlim(false);
using ManualResetEventSlim waitHandle = new(false);
while (_isRunning)
{
@@ -199,6 +203,7 @@ namespace Ryujinx.SDL2.Common
public void Dispose()
{
GC.SuppressFinalize(this);
Dispose(true);
}
}

View File

@@ -20,7 +20,7 @@ namespace Ryujinx.ShaderTools
public ReadOnlySpan<ulong> GetCode(ulong address, int minimumSize)
{
return MemoryMarshal.Cast<byte, ulong>(new ReadOnlySpan<byte>(_data).Slice((int)address));
return MemoryMarshal.Cast<byte, ulong>(new ReadOnlySpan<byte>(_data)[(int)address..]);
}
}
@@ -53,7 +53,7 @@ namespace Ryujinx.ShaderTools
byte[] data = File.ReadAllBytes(options.InputPath);
TranslationOptions translationOptions = new TranslationOptions(options.TargetLanguage, options.TargetApi, flags);
TranslationOptions translationOptions = new(options.TargetLanguage, options.TargetApi, flags);
ShaderProgram program = Translator.CreateContext(0, new GpuAccessor(data), translationOptions).Translate();
@@ -90,4 +90,4 @@ namespace Ryujinx.ShaderTools
.WithNotParsed(errors => errors.Output());
}
}
}
}

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);
@@ -437,4 +436,4 @@ namespace Ryujinx.Tests.Memory
Assert.AreEqual(pagesModified, new bool[] { true, false, false });
}
}
}
}

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)
{
@@ -115,4 +115,4 @@ namespace Ryujinx.Tests.Memory
}
}
}
}
}

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

@@ -11,4 +11,4 @@ namespace Ryujinx.Tests.Unicorn
Exec = 4,
All = 7,
}
}
}

View File

@@ -2,7 +2,7 @@ using System;
namespace Ryujinx.Tests.Unicorn
{
public struct SimdValue : IEquatable<SimdValue>
public readonly struct SimdValue : IEquatable<SimdValue>
{
private readonly ulong _e0;
private readonly 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()
@@ -109,4 +107,4 @@ namespace Ryujinx.Tests.Unicorn
return $"0x{_e1:X16}{_e0:X16}";
}
}
}
}

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);
}
}
}
}