Compare commits

..

4 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
8 changed files with 43 additions and 36 deletions

View File

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

View File

@@ -12,19 +12,19 @@ namespace Ryujinx.Audio.Backends.SDL2
{ {
class SDL2HardwareDeviceSession : HardwareDeviceSessionOutputBase class SDL2HardwareDeviceSession : HardwareDeviceSessionOutputBase
{ {
private SDL2HardwareDeviceDriver _driver; private readonly SDL2HardwareDeviceDriver _driver;
private ConcurrentQueue<SDL2AudioBuffer> _queuedBuffers; private readonly ConcurrentQueue<SDL2AudioBuffer> _queuedBuffers;
private DynamicRingBuffer _ringBuffer; private readonly DynamicRingBuffer _ringBuffer;
private ulong _playedSampleCount; private ulong _playedSampleCount;
private ManualResetEvent _updateRequiredEvent; private readonly ManualResetEvent _updateRequiredEvent;
private uint _outputStream; private uint _outputStream;
private bool _hasSetupError; private bool _hasSetupError;
private SDL_AudioCallback _callbackDelegate; private readonly SDL_AudioCallback _callbackDelegate;
private int _bytesPerFrame; private readonly int _bytesPerFrame;
private uint _sampleCount; private uint _sampleCount;
private bool _started; private bool _started;
private float _volume; 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) 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) 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 maxFrameCount = (int)GetSampleCount(streamLength);
int bufferedFrames = _ringBuffer.Length / _bytesPerFrame; int bufferedFrames = _ringBuffer.Length / _bytesPerFrame;
@@ -82,7 +82,7 @@ namespace Ryujinx.Audio.Backends.SDL2
if (frameCount == 0) if (frameCount == 0)
{ {
// SDL2 left the responsibility to the user to clear the buffer. // SDL2 left the responsibility to the user to clear the buffer.
streamSpan.Fill(0); streamSpan.Clear();
return; return;
} }
@@ -96,7 +96,7 @@ namespace Ryujinx.Audio.Backends.SDL2
IntPtr pStreamSrc = (IntPtr)p; IntPtr pStreamSrc = (IntPtr)p;
// Zero the dest buffer // Zero the dest buffer
streamSpan.Fill(0); streamSpan.Clear();
// Apply volume to written data // Apply volume to written data
SDL_MixAudioFormat(stream, pStreamSrc, _nativeSampleFormat, (uint)samples.Length, (int)(_volume * SDL_MIX_MAXVOLUME)); 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) 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); _ringBuffer.Write(buffer.Data, 0, buffer.Data.Length);

View File

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

View File

@@ -13,7 +13,7 @@ namespace Ryujinx.Graphics.Device
public TState State; 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 Func<int>[] _readCallbacks;
private readonly Action<int>[] _writeCallbacks; private readonly Action<int>[] _writeCallbacks;

View File

@@ -31,7 +31,7 @@ namespace Ryujinx.Memory
/// </summary> /// </summary>
/// <param name="size">Size of the memory block in bytes</param> /// <param name="size">Size of the memory block in bytes</param>
/// <param name="flags">Flags that controls memory block memory allocation</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> /// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
public MemoryBlock(ulong size, MemoryAllocationFlags flags = MemoryAllocationFlags.None) public MemoryBlock(ulong size, MemoryAllocationFlags flags = MemoryAllocationFlags.None)
{ {
@@ -66,7 +66,7 @@ namespace Ryujinx.Memory
/// </summary> /// </summary>
/// <param name="size">Size of the memory block in bytes</param> /// <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> /// <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> /// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
private MemoryBlock(ulong size, IntPtr sharedMemory) private MemoryBlock(ulong size, IntPtr sharedMemory)
{ {
@@ -82,7 +82,7 @@ namespace Ryujinx.Memory
/// </summary> /// </summary>
/// <returns>A new memory block that shares storage with this one</returns> /// <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="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> /// <exception cref="PlatformNotSupportedException">Throw when the current platform is not supported</exception>
public MemoryBlock CreateMirror() 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 fd = shm_open((IntPtr)pMemName, 0x2 | 0x200 | 0x800 | 0x400, 384); // O_RDWR | O_CREAT | O_EXCL | O_TRUNC, 0600
if (fd == -1) if (fd == -1)
{ {
throw new OutOfMemoryException(); throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
} }
if (shm_unlink((IntPtr)pMemName) != 0) 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); fd = mkstemp((IntPtr)pFileName);
if (fd == -1) if (fd == -1)
{ {
throw new OutOfMemoryException(); throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
} }
if (unlink((IntPtr)pFileName) != 0) if (unlink((IntPtr)pFileName) != 0)
{ {
throw new OutOfMemoryException(); throw new SystemException(Marshal.GetLastPInvokeErrorMessage());
} }
} }
} }
if (ftruncate(fd, (IntPtr)size) != 0) 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) public static void DestroySharedMemory(IntPtr handle)

View File

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

View File

@@ -19,10 +19,7 @@ namespace Ryujinx.SDL2.Common
{ {
get get
{ {
if (_instance == null) _instance ??= new SDL2Driver();
{
_instance = new SDL2Driver();
}
return _instance; return _instance;
} }
@@ -43,7 +40,7 @@ namespace Ryujinx.SDL2.Common
private readonly object _lock = new(); 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"; 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). // First ensure that we only enable joystick events (for connected/disconnected).
SDL_GameControllerEventState(SDL_DISABLE); if (SDL_GameControllerEventState(SDL_IGNORE) != SDL_IGNORE)
SDL_JoystickEventState(SDL_ENABLE); {
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. // 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); SDL_EventState(SDL_EventType.SDL_JOYAXISMOTION, SDL_DISABLE);
@@ -153,7 +157,7 @@ namespace Ryujinx.SDL2.Common
{ {
const int WaitTimeMs = 10; const int WaitTimeMs = 10;
using ManualResetEventSlim waitHandle = new ManualResetEventSlim(false); using ManualResetEventSlim waitHandle = new(false);
while (_isRunning) while (_isRunning)
{ {
@@ -199,6 +203,7 @@ namespace Ryujinx.SDL2.Common
public void Dispose() public void Dispose()
{ {
GC.SuppressFinalize(this);
Dispose(true); Dispose(true);
} }
} }