From 58907e2c290473326e5ab74bdfe1429b8a518ba4 Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Thu, 22 Jun 2023 13:36:07 -0300 Subject: [PATCH 01/17] GetHashCode should not reference mutable fields (#5331) --- src/ARMeilleure/State/V128.cs | 4 ++-- src/Ryujinx.HLE/HOS/Services/Mii/Types/CreateId.cs | 2 +- src/Ryujinx.Tests.Unicorn/SimdValue.cs | 4 ++-- src/Spv.Generator/ConstantKey.cs | 2 +- src/Spv.Generator/DeterministicStringKey.cs | 2 +- src/Spv.Generator/LiteralString.cs | 2 +- src/Spv.Generator/TypeDeclarationKey.cs | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ARMeilleure/State/V128.cs b/src/ARMeilleure/State/V128.cs index 3fa9f9a99..441bbfa6d 100644 --- a/src/ARMeilleure/State/V128.cs +++ b/src/ARMeilleure/State/V128.cs @@ -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; /// /// Gets a new with all bits set to zero. diff --git a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CreateId.cs b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CreateId.cs index c1a97f526..283d82fc8 100644 --- a/src/Ryujinx.HLE/HOS/Services/Mii/Types/CreateId.cs +++ b/src/Ryujinx.HLE/HOS/Services/Mii/Types/CreateId.cs @@ -6,7 +6,7 @@ namespace Ryujinx.HLE.HOS.Services.Mii.Types [StructLayout(LayoutKind.Sequential, Pack = 1, Size = 0x10)] struct CreateId : IEquatable { - public UInt128 Raw; + public readonly UInt128 Raw; public bool IsNull => Raw == UInt128.Zero; public bool IsValid => !IsNull && ((Raw >> 64) & 0xC0) == 0x80; diff --git a/src/Ryujinx.Tests.Unicorn/SimdValue.cs b/src/Ryujinx.Tests.Unicorn/SimdValue.cs index 2b5284305..ce9e178cc 100644 --- a/src/Ryujinx.Tests.Unicorn/SimdValue.cs +++ b/src/Ryujinx.Tests.Unicorn/SimdValue.cs @@ -4,8 +4,8 @@ namespace Ryujinx.Tests.Unicorn { public struct SimdValue : IEquatable { - private ulong _e0; - private ulong _e1; + private readonly ulong _e0; + private readonly ulong _e1; public SimdValue(ulong e0, ulong e1) { diff --git a/src/Spv.Generator/ConstantKey.cs b/src/Spv.Generator/ConstantKey.cs index d3c1b905a..e7758b408 100644 --- a/src/Spv.Generator/ConstantKey.cs +++ b/src/Spv.Generator/ConstantKey.cs @@ -5,7 +5,7 @@ namespace Spv.Generator { internal struct ConstantKey : IEquatable { - private Instruction _constant; + private readonly Instruction _constant; public ConstantKey(Instruction constant) { diff --git a/src/Spv.Generator/DeterministicStringKey.cs b/src/Spv.Generator/DeterministicStringKey.cs index 491bb745a..cab4dbcc2 100644 --- a/src/Spv.Generator/DeterministicStringKey.cs +++ b/src/Spv.Generator/DeterministicStringKey.cs @@ -5,7 +5,7 @@ namespace Spv.Generator { internal class DeterministicStringKey : IEquatable { - private string _value; + private readonly string _value; public DeterministicStringKey(string value) { diff --git a/src/Spv.Generator/LiteralString.cs b/src/Spv.Generator/LiteralString.cs index 629ff7bf6..741d922bb 100644 --- a/src/Spv.Generator/LiteralString.cs +++ b/src/Spv.Generator/LiteralString.cs @@ -8,7 +8,7 @@ namespace Spv.Generator { public OperandType Type => OperandType.String; - private string _value; + private readonly string _value; public LiteralString(string value) { diff --git a/src/Spv.Generator/TypeDeclarationKey.cs b/src/Spv.Generator/TypeDeclarationKey.cs index a4aa95634..e4fd5fd57 100644 --- a/src/Spv.Generator/TypeDeclarationKey.cs +++ b/src/Spv.Generator/TypeDeclarationKey.cs @@ -5,7 +5,7 @@ namespace Spv.Generator { internal struct TypeDeclarationKey : IEquatable { - private Instruction _typeDeclaration; + private readonly Instruction _typeDeclaration; public TypeDeclarationKey(Instruction typeDeclaration) { From d604e982276105db043ca495a16f1b047bb2d0f6 Mon Sep 17 00:00:00 2001 From: Kurochi51 Date: Thu, 22 Jun 2023 22:35:06 +0300 Subject: [PATCH 02/17] Fix regression introduced by 1.1.1733 on Intel GPUs (#5311) * Fix regression introduced by 1.1733 on Intel iGPUs * Should have actually figured the variable, oops. * maybe something goes wrong here? honestly lost * Shader cache bump --- .../Shader/DiskCache/DiskCacheHostStorage.cs | 2 +- src/Ryujinx.Graphics.Shader/Instructions/InstEmitAttribute.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs b/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs index 5cfbfd386..267112865 100644 --- a/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs +++ b/src/Ryujinx.Graphics.Gpu/Shader/DiskCache/DiskCacheHostStorage.cs @@ -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"; diff --git a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitAttribute.cs b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitAttribute.cs index bb60d2746..76b2e0783 100644 --- a/src/Ryujinx.Graphics.Shader/Instructions/InstEmitAttribute.cs +++ b/src/Ryujinx.Graphics.Shader/Instructions/InstEmitAttribute.cs @@ -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)); } } From 7608cb37ab798db49f33f3870f2f84fbe0809266 Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Thu, 22 Jun 2023 20:37:25 -0300 Subject: [PATCH 03/17] "Exists" method should be used instead of the "Any" extension (#5345) --- src/Ryujinx.Graphics.Gpu/Image/TextureGroupHandle.cs | 2 +- src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs | 2 +- src/Ryujinx.HLE/HOS/Kernel/Threading/KAddressArbiter.cs | 2 +- src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Ryujinx.Graphics.Gpu/Image/TextureGroupHandle.cs b/src/Ryujinx.Graphics.Gpu/Image/TextureGroupHandle.cs index fd66269dd..da8dd849d 100644 --- a/src/Ryujinx.Graphics.Gpu/Image/TextureGroupHandle.cs +++ b/src/Ryujinx.Graphics.Gpu/Image/TextureGroupHandle.cs @@ -512,7 +512,7 @@ namespace Ryujinx.Graphics.Gpu.Image /// True if at least one of the handles is dirty private bool CheckDirty() { - return Handles.Any(handle => handle.Dirty); + return Array.Exists(Handles, handle => handle.Dirty); } /// diff --git a/src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs b/src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs index 222cdf2a7..2a3f86579 100644 --- a/src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs +++ b/src/Ryujinx.Graphics.Vulkan/ShaderCollection.cs @@ -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; diff --git a/src/Ryujinx.HLE/HOS/Kernel/Threading/KAddressArbiter.cs b/src/Ryujinx.HLE/HOS/Kernel/Threading/KAddressArbiter.cs index 74867b44e..57fbabd51 100644 --- a/src/Ryujinx.HLE/HOS/Kernel/Threading/KAddressArbiter.cs +++ b/src/Ryujinx.HLE/HOS/Kernel/Threading/KAddressArbiter.cs @@ -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); } diff --git a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs index 9166e87fa..9e1db7fcd 100644 --- a/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs +++ b/src/Ryujinx.HLE/HOS/Services/Nfc/Nfp/VirtualAmiibo.cs @@ -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++) { From efbd29463d2eb38cd177818a170f245556852f17 Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Thu, 22 Jun 2023 20:42:23 -0300 Subject: [PATCH 04/17] "Find" method should be used instead of the "FirstOrDefault" extension (#5344) --- src/Ryujinx.Ava/UI/ViewModels/AmiiboWindowViewModel.cs | 4 ++-- .../Loaders/Processes/Extensions/FileSystemExtensions.cs | 3 ++- src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs | 3 ++- src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs | 3 ++- src/Ryujinx/Ui/Windows/AmiiboWindow.cs | 4 ++-- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Ryujinx.Ava/UI/ViewModels/AmiiboWindowViewModel.cs b/src/Ryujinx.Ava/UI/ViewModels/AmiiboWindowViewModel.cs index ead1a1442..ecd425ef2 100644 --- a/src/Ryujinx.Ava/UI/ViewModels/AmiiboWindowViewModel.cs +++ b/src/Ryujinx.Ava/UI/ViewModels/AmiiboWindowViewModel.cs @@ -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 = ""; diff --git a/src/Ryujinx.HLE/Loaders/Processes/Extensions/FileSystemExtensions.cs b/src/Ryujinx.HLE/Loaders/Processes/Extensions/FileSystemExtensions.cs index 782ccef31..b619a7134 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/Extensions/FileSystemExtensions.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/Extensions/FileSystemExtensions.cs @@ -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(); } } diff --git a/src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs b/src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs index 0eedc2131..f391f9656 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/ProcessLoader.cs @@ -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; @@ -176,7 +177,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) diff --git a/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs b/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs index 81e75e270..40b516cc8 100644 --- a/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs +++ b/src/Ryujinx.HLE/Loaders/Processes/ProcessResult.cs @@ -6,6 +6,7 @@ using Ryujinx.Cpu; using Ryujinx.HLE.HOS.SystemState; using Ryujinx.HLE.Loaders.Processes.Extensions; using Ryujinx.Horizon.Common; +using System; using System.Linq; namespace Ryujinx.HLE.Loaders.Processes @@ -59,7 +60,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(); diff --git a/src/Ryujinx/Ui/Windows/AmiiboWindow.cs b/src/Ryujinx/Ui/Windows/AmiiboWindow.cs index 9cfb29427..5bf69d5af 100644 --- a/src/Ryujinx/Ui/Windows/AmiiboWindow.cs +++ b/src/Ryujinx/Ui/Windows/AmiiboWindow.cs @@ -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(); From 91e4caaa69954f5aac06f01650542e5072ead3de Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Thu, 22 Jun 2023 21:15:14 -0300 Subject: [PATCH 05/17] "StartsWith" and "EndsWith" overloads that take a "char" should be used instead of the ones that take a "string" (#5347) --- .../HOS/Diagnostics/Demangler/Ast/TemplateArguments.cs | 2 +- .../HOS/Services/Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/TemplateArguments.cs b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/TemplateArguments.cs index aefd668de..cc14d9645 100644 --- a/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/TemplateArguments.cs +++ b/src/Ryujinx.HLE/HOS/Diagnostics/Demangler/Ast/TemplateArguments.cs @@ -15,7 +15,7 @@ namespace Ryujinx.HLE.HOS.Diagnostics.Demangler.Ast writer.Write(Params); - if (Params.EndsWith(">")) + if (Params.EndsWith('>')) { writer.Write(" "); } diff --git a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs index 8eece5ea0..0e18c5705 100644 --- a/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs +++ b/src/Ryujinx.HLE/HOS/Services/Sockets/Sfdnsres/Proxy/DnsMitmResolver.cs @@ -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; } From bf96bc84a82f2c4ab771b2ab0c610f86d00b1adf Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Thu, 22 Jun 2023 21:51:44 -0300 Subject: [PATCH 06/17] "Where" should be used before "OrderBy" (#5346) --- src/Ryujinx.Graphics.Shader/Translation/Translator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Graphics.Shader/Translation/Translator.cs b/src/Ryujinx.Graphics.Shader/Translation/Translator.cs index b44d6daaa..255030a4b 100644 --- a/src/Ryujinx.Graphics.Shader/Translation/Translator.cs +++ b/src/Ryujinx.Graphics.Shader/Translation/Translator.cs @@ -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); } From 7d160e98fde05e0b9b542dc04ea72dc34994bc5b Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sat, 24 Jun 2023 02:46:04 +0200 Subject: [PATCH 07/17] MemoryManagement: Change return types for Commit/Decommit to void (#5325) * Replace return type with void for Commit/Decommit * Small cleanup --- src/ARMeilleure/Memory/IJitMemoryBlock.cs | 4 ++-- src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs | 4 ++-- src/Ryujinx.Memory/MemoryBlock.cs | 13 ++++++------- src/Ryujinx.Memory/MemoryManagement.cs | 12 ++++++------ src/Ryujinx.Memory/MemoryManagementUnix.cs | 16 +++++----------- src/Ryujinx.Memory/MemoryManagementWindows.cs | 16 +++++++++++----- 6 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/ARMeilleure/Memory/IJitMemoryBlock.cs b/src/ARMeilleure/Memory/IJitMemoryBlock.cs index 670f2862d..9b11e07ff 100644 --- a/src/ARMeilleure/Memory/IJitMemoryBlock.cs +++ b/src/ARMeilleure/Memory/IJitMemoryBlock.cs @@ -6,9 +6,9 @@ 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); } -} +} \ No newline at end of file diff --git a/src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs b/src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs index 327fb303e..61e27eaf5 100644 --- a/src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs +++ b/src/Ryujinx.Cpu/Jit/JitMemoryBlock.cs @@ -15,10 +15,10 @@ 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); public void Dispose() => _impl.Dispose(); } -} +} \ No newline at end of file diff --git a/src/Ryujinx.Memory/MemoryBlock.cs b/src/Ryujinx.Memory/MemoryBlock.cs index 885ef4569..2cf04628a 100644 --- a/src/Ryujinx.Memory/MemoryBlock.cs +++ b/src/Ryujinx.Memory/MemoryBlock.cs @@ -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 /// /// Starting offset of the range to be committed /// Size of the range to be committed - /// True if the operation was successful, false otherwise + /// Throw when the operation was not successful /// Throw when the memory block has already been disposed /// Throw when either or are out of range - 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); } /// @@ -115,12 +114,12 @@ namespace Ryujinx.Memory /// /// Starting offset of the range to be decommitted /// Size of the range to be decommitted - /// True if the operation was successful, false otherwise + /// Throw when the operation was not successful /// Throw when the memory block has already been disposed /// Throw when either or are out of range - 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); } /// diff --git a/src/Ryujinx.Memory/MemoryManagement.cs b/src/Ryujinx.Memory/MemoryManagement.cs index c4b5ac4c9..7acf8345f 100644 --- a/src/Ryujinx.Memory/MemoryManagement.cs +++ b/src/Ryujinx.Memory/MemoryManagement.cs @@ -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 { diff --git a/src/Ryujinx.Memory/MemoryManagementUnix.cs b/src/Ryujinx.Memory/MemoryManagementUnix.cs index 30baf0353..d665b2294 100644 --- a/src/Ryujinx.Memory/MemoryManagementUnix.cs +++ b/src/Ryujinx.Memory/MemoryManagementUnix.cs @@ -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 _allocations = new ConcurrentDictionary(); + private static readonly ConcurrentDictionary _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) { diff --git a/src/Ryujinx.Memory/MemoryManagementWindows.cs b/src/Ryujinx.Memory/MemoryManagementWindows.cs index cbf3ecbac..d7d78bd86 100644 --- a/src/Ryujinx.Memory/MemoryManagementWindows.cs +++ b/src/Ryujinx.Memory/MemoryManagementWindows.cs @@ -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) From fffc3ed19308ba5a5139add55af8cb4918bc5378 Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Sat, 24 Jun 2023 09:01:59 -0300 Subject: [PATCH 08/17] Mutable fields should not be "public static" (#5352) --- src/Ryujinx.Audio/Constants.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ryujinx.Audio/Constants.cs b/src/Ryujinx.Audio/Constants.cs index 7d2ffa57b..cde87744f 100644 --- a/src/Ryujinx.Audio/Constants.cs +++ b/src/Ryujinx.Audio/Constants.cs @@ -164,7 +164,7 @@ namespace Ryujinx.Audio /// /// The default coefficients used for standard 5.1 surround to stereo downmixing. /// - public static float[] DefaultSurroundToStereoCoefficients = new float[4] + public static readonly float[] DefaultSurroundToStereoCoefficients = new float[4] { 1.0f, 0.707f, From bc392e55dfd0eed72ce30a550e91fa480eba1ef9 Mon Sep 17 00:00:00 2001 From: Marco Carvalho Date: Sat, 24 Jun 2023 09:06:58 -0300 Subject: [PATCH 09/17] Empty "case" clauses that fall through to the "default" should be omitted (#5353) * Empty "case" clauses that fall through to the "default" should be omitted * default throw exception * format --- src/ARMeilleure/Instructions/SoftFloat.cs | 54 ++++++++++++++++++----- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/src/ARMeilleure/Instructions/SoftFloat.cs b/src/ARMeilleure/Instructions/SoftFloat.cs index 9e3db68d9..4af73c6df 100644 --- a/src/ARMeilleure/Instructions/SoftFloat.cs +++ b/src/ARMeilleure/Instructions/SoftFloat.cs @@ -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); From df5be5812f9ebfd6533ef3eefdcdb24d30f29954 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 25 Jun 2023 01:29:40 +0200 Subject: [PATCH 10/17] [Ryujinx.Audio.Backends.OpenAL] Address dotnet-format issues (#5359) * dotnet format style --severity info Some changes were manually reverted. * Restore a few unused methods and variables * Address dotnet format CA1816 warnings * Address most dotnet format whitespace 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 --- .../OpenALHardwareDeviceDriver.cs | 5 +-- .../OpenALHardwareDeviceSession.cs | 36 ++++++++----------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs index 0c793f248..92946900f 100644 --- a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceDriver.cs @@ -18,7 +18,7 @@ namespace Ryujinx.Audio.Backends.OpenAL private readonly ManualResetEvent _pauseEvent; private readonly ConcurrentDictionary _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); } diff --git a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs index 8d7d0d6a2..4a2d521fe 100644 --- a/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.OpenAL/OpenALHardwareDeviceSession.cs @@ -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 _queuedBuffers; + private readonly Queue _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(), From ede5b3c3240f0d4cf06f38174bf50b9f2f3593e8 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 25 Jun 2023 02:15:56 +0200 Subject: [PATCH 11/17] [Ryujinx.Audio.Backends.SoundIo] Address dotnet-format issues (#5360) * dotnet format style --severity info Some changes were manually reverted. * Address dotnet format CA1816 warnings * Address dotnet format CA1401 warnings * Address most dotnet format whitespace warnings * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * 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 * Address review feedback --- .../Native/SoundIo.cs | 52 +++++++++---------- .../Native/SoundIoContext.cs | 1 - .../SoundIoHardwareDeviceDriver.cs | 6 ++- .../SoundIoHardwareDeviceSession.cs | 12 ++--- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIo.cs b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIo.cs index 9c3e686df..31af3e9d3 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIo.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIo.cs @@ -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); } } diff --git a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoContext.cs b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoContext.cs index 3744c2e64..afa86befa 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoContext.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/Native/SoundIoContext.cs @@ -1,5 +1,4 @@ using System; -using System.Reflection.Metadata; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Threading; diff --git a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceDriver.cs b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceDriver.cs index 02da27769..9dac0992c 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceDriver.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceDriver.cs @@ -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); diff --git a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs index 96d9ce970..0aa13e7ed 100644 --- a/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs +++ b/src/Ryujinx.Audio.Backends.SoundIo/SoundIoHardwareDeviceSession.cs @@ -12,12 +12,12 @@ namespace Ryujinx.Audio.Backends.SoundIo { class SoundIoHardwareDeviceSession : HardwareDeviceSessionOutputBase { - private SoundIoHardwareDeviceDriver _driver; - private ConcurrentQueue _queuedBuffers; + private readonly SoundIoHardwareDeviceDriver _driver; + private readonly ConcurrentQueue _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) { From 7c2f07d12458ce6d2ee9c98f78d56ec8b20762bb Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 25 Jun 2023 13:40:37 +0200 Subject: [PATCH 12/17] [Ryujinx.Horizon.Common] Address dotnet-format issues (#5382) * dotnet format style --severity info Some changes were manually reverted. * Address most dotnet format whitespace warnings * Address IDE0251 warnings * dotnet format whitespace after rebase --- src/Ryujinx.Horizon.Common/KernelResult.cs | 62 +++++++++++----------- src/Ryujinx.Horizon.Common/OnScopeExit.cs | 2 +- src/Ryujinx.Horizon.Common/Result.cs | 22 ++++---- src/Ryujinx.Horizon.Common/ResultNames.cs | 2 +- 4 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/Ryujinx.Horizon.Common/KernelResult.cs b/src/Ryujinx.Horizon.Common/KernelResult.cs index 51fec2057..ff367ac46 100644 --- a/src/Ryujinx.Horizon.Common/KernelResult.cs +++ b/src/Ryujinx.Horizon.Common/KernelResult.cs @@ -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); } } diff --git a/src/Ryujinx.Horizon.Common/OnScopeExit.cs b/src/Ryujinx.Horizon.Common/OnScopeExit.cs index 2b81e492f..deba7bbad 100644 --- a/src/Ryujinx.Horizon.Common/OnScopeExit.cs +++ b/src/Ryujinx.Horizon.Common/OnScopeExit.cs @@ -2,7 +2,7 @@ namespace Ryujinx.Horizon.Common { - public struct OnScopeExit : IDisposable + public readonly struct OnScopeExit : IDisposable { private readonly Action _action; diff --git a/src/Ryujinx.Horizon.Common/Result.cs b/src/Ryujinx.Horizon.Common/Result.cs index 28056310f..8e458475d 100644 --- a/src/Ryujinx.Horizon.Common/Result.cs +++ b/src/Ryujinx.Horizon.Common/Result.cs @@ -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)) { @@ -115,4 +115,4 @@ namespace Ryujinx.Horizon.Common return PrintableResult; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Horizon.Common/ResultNames.cs b/src/Ryujinx.Horizon.Common/ResultNames.cs index 8f8173ed5..84058cf2c 100644 --- a/src/Ryujinx.Horizon.Common/ResultNames.cs +++ b/src/Ryujinx.Horizon.Common/ResultNames.cs @@ -1698,4 +1698,4 @@ namespace Ryujinx.Horizon.Common return _names.TryGetValue(errorCode, out name); } } -} \ No newline at end of file +} From e3bacfa77481738aabee5f8b8be3f8ff91132c43 Mon Sep 17 00:00:00 2001 From: Shihta Kuan Date: Sun, 25 Jun 2023 20:49:53 +0800 Subject: [PATCH 13/17] Set COMPlus_DefaultStackSize to 2M in macOS (#5349) * Set COMPlus_DefaultStackSize to 2M in macOS * Remove the custom thread stack size on Ryujinx.Ava --- distribution/macos/Info.plist | 7 ++++++- src/Ryujinx.Ava/AppHost.cs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/distribution/macos/Info.plist b/distribution/macos/Info.plist index 6c3f7717c..968814f94 100644 --- a/distribution/macos/Info.plist +++ b/distribution/macos/Info.plist @@ -39,10 +39,15 @@ CSResourcesFileMapped NSHumanReadableCopyright - Copyright © 2018 - 2022 Ryujinx Team and Contributors. + Copyright © 2018 - 2023 Ryujinx Team and Contributors. LSApplicationCategoryType public.app-category.games LSMinimumSystemVersion 11.0 + LSEnvironment + + COMPlus_DefaultStackSize + 200000 + diff --git a/src/Ryujinx.Ava/AppHost.cs b/src/Ryujinx.Ava/AppHost.cs index d3e0ea392..a25713796 100644 --- a/src/Ryujinx.Ava/AppHost.cs +++ b/src/Ryujinx.Ava/AppHost.cs @@ -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; From bddb2a148355ef2ce326d47e8e5217bd8af36a98 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 25 Jun 2023 18:03:08 +0200 Subject: [PATCH 14/17] [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 --- src/Ryujinx.Tests.Unicorn/IndexedProperty.cs | 6 +- src/Ryujinx.Tests.Unicorn/MemoryPermission.cs | 2 +- src/Ryujinx.Tests.Unicorn/SimdValue.cs | 32 ++++----- src/Ryujinx.Tests.Unicorn/UnicornAArch32.cs | 42 ++++++------ src/Ryujinx.Tests.Unicorn/UnicornAArch64.cs | 68 +++++++++---------- 5 files changed, 75 insertions(+), 75 deletions(-) diff --git a/src/Ryujinx.Tests.Unicorn/IndexedProperty.cs b/src/Ryujinx.Tests.Unicorn/IndexedProperty.cs index 65d445fc0..347b91a08 100644 --- a/src/Ryujinx.Tests.Unicorn/IndexedProperty.cs +++ b/src/Ryujinx.Tests.Unicorn/IndexedProperty.cs @@ -4,12 +4,12 @@ namespace Ryujinx.Tests.Unicorn { public class IndexedProperty { - private Func _getFunc; - private Action _setAction; + private readonly Func _getFunc; + private readonly Action _setAction; public IndexedProperty(Func getFunc, Action setAction) { - _getFunc = getFunc; + _getFunc = getFunc; _setAction = setAction; } diff --git a/src/Ryujinx.Tests.Unicorn/MemoryPermission.cs b/src/Ryujinx.Tests.Unicorn/MemoryPermission.cs index 044b3176b..6d3e7370d 100644 --- a/src/Ryujinx.Tests.Unicorn/MemoryPermission.cs +++ b/src/Ryujinx.Tests.Unicorn/MemoryPermission.cs @@ -11,4 +11,4 @@ namespace Ryujinx.Tests.Unicorn Exec = 4, All = 7, } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Tests.Unicorn/SimdValue.cs b/src/Ryujinx.Tests.Unicorn/SimdValue.cs index ce9e178cc..0401c693f 100644 --- a/src/Ryujinx.Tests.Unicorn/SimdValue.cs +++ b/src/Ryujinx.Tests.Unicorn/SimdValue.cs @@ -2,7 +2,7 @@ using System; namespace Ryujinx.Tests.Unicorn { - public struct SimdValue : IEquatable + public readonly struct SimdValue : IEquatable { 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}"; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Tests.Unicorn/UnicornAArch32.cs b/src/Ryujinx.Tests.Unicorn/UnicornAArch32.cs index a095e6641..6532beab8 100644 --- a/src/Ryujinx.Tests.Unicorn/UnicornAArch32.cs +++ b/src/Ryujinx.Tests.Unicorn/UnicornAArch32.cs @@ -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 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); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Tests.Unicorn/UnicornAArch64.cs b/src/Ryujinx.Tests.Unicorn/UnicornAArch64.cs index 16dfd93bd..bdb535581 100644 --- a/src/Ryujinx.Tests.Unicorn/UnicornAArch64.cs +++ b/src/Ryujinx.Tests.Unicorn/UnicornAArch64.cs @@ -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 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); } } -} \ No newline at end of file +} From bc53d0046310293a90a4312fa9317bb698dded5c Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 25 Jun 2023 18:37:09 +0200 Subject: [PATCH 15/17] [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 --- src/Ryujinx.Graphics.Vic/Image/BufferPool.cs | 2 +- .../Image/InputSurface.cs | 6 +++--- .../Image/SurfaceReader.cs | 13 ++++++------ src/Ryujinx.Graphics.Vic/Rectangle.cs | 2 +- src/Ryujinx.Graphics.Vic/Scaler.cs | 2 +- .../Types/BlendingSlotStruct.cs | 6 +++--- .../Types/ClearRectStruct.cs | 8 ++++---- .../Types/ConfigStruct.cs | 2 +- .../Types/DeinterlaceMode.cs | 2 +- src/Ryujinx.Graphics.Vic/Types/FrameFormat.cs | 2 +- .../Types/LumaKeyStruct.cs | 6 +++--- .../Types/MatrixStruct.cs | 10 +++++----- .../Types/OutputConfig.cs | 8 ++++---- .../Types/OutputSurfaceConfig.cs | 8 ++++---- src/Ryujinx.Graphics.Vic/Types/PipeConfig.cs | 10 +++++----- src/Ryujinx.Graphics.Vic/Types/SlotConfig.cs | 20 ++++++++++--------- .../Types/SlotSurfaceConfig.cs | 6 +++--- src/Ryujinx.Graphics.Vic/VicDevice.cs | 4 ++-- src/Ryujinx.Graphics.Vic/VicRegisters.cs | 4 ++-- 19 files changed, 62 insertions(+), 59 deletions(-) diff --git a/src/Ryujinx.Graphics.Vic/Image/BufferPool.cs b/src/Ryujinx.Graphics.Vic/Image/BufferPool.cs index cde7e6ebb..1f7dc08a1 100644 --- a/src/Ryujinx.Graphics.Vic/Image/BufferPool.cs +++ b/src/Ryujinx.Graphics.Vic/Image/BufferPool.cs @@ -34,7 +34,7 @@ namespace Ryujinx.Graphics.Vic.Image { int index = RentMinimum(length, out T[] bufferArray); - buffer = new Span(bufferArray).Slice(0, length); + buffer = new Span(bufferArray)[..length]; return index; } diff --git a/src/Ryujinx.Graphics.Vic/Image/InputSurface.cs b/src/Ryujinx.Graphics.Vic/Image/InputSurface.cs index 15ac04600..04994468c 100644 --- a/src/Ryujinx.Graphics.Vic/Image/InputSurface.cs +++ b/src/Ryujinx.Graphics.Vic/Image/InputSurface.cs @@ -4,7 +4,7 @@ namespace Ryujinx.Graphics.Vic.Image { ref struct RentedBuffer { - public static RentedBuffer Empty => new RentedBuffer(Span.Empty, -1); + public static RentedBuffer Empty => new(Span.Empty, -1); public Span Data; public int Index; @@ -15,7 +15,7 @@ namespace Ryujinx.Graphics.Vic.Image Index = index; } - public void Return(BufferPool pool) + public readonly void Return(BufferPool pool) { if (Index != -1) { @@ -65,7 +65,7 @@ namespace Ryujinx.Graphics.Vic.Image Buffer2Index = buffer.Index; } - public void Return(BufferPool pool) + public readonly void Return(BufferPool pool) { if (Buffer0Index != -1) { diff --git a/src/Ryujinx.Graphics.Vic/Image/SurfaceReader.cs b/src/Ryujinx.Graphics.Vic/Image/SurfaceReader.cs index 10fd9d8d3..079b4ef12 100644 --- a/src/Ryujinx.Graphics.Vic/Image/SurfaceReader.cs +++ b/src/Ryujinx.Graphics.Vic/Image/SurfaceReader.cs @@ -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 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 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); } diff --git a/src/Ryujinx.Graphics.Vic/Rectangle.cs b/src/Ryujinx.Graphics.Vic/Rectangle.cs index 8a8dd63a4..b12560bd2 100644 --- a/src/Ryujinx.Graphics.Vic/Rectangle.cs +++ b/src/Ryujinx.Graphics.Vic/Rectangle.cs @@ -15,4 +15,4 @@ namespace Ryujinx.Graphics.Vic Height = height; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Vic/Scaler.cs b/src/Ryujinx.Graphics.Vic/Scaler.cs index 18ae66c4a..7d539299a 100644 --- a/src/Ryujinx.Graphics.Vic/Scaler.cs +++ b/src/Ryujinx.Graphics.Vic/Scaler.cs @@ -121,4 +121,4 @@ namespace Ryujinx.Graphics.Vic } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Vic/Types/BlendingSlotStruct.cs b/src/Ryujinx.Graphics.Vic/Types/BlendingSlotStruct.cs index 86da41d29..2cc6b1e28 100644 --- a/src/Ryujinx.Graphics.Vic/Types/BlendingSlotStruct.cs +++ b/src/Ryujinx.Graphics.Vic/Types/BlendingSlotStruct.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vic/Types/ClearRectStruct.cs b/src/Ryujinx.Graphics.Vic/Types/ClearRectStruct.cs index ae582a920..da9888f78 100644 --- a/src/Ryujinx.Graphics.Vic/Types/ClearRectStruct.cs +++ b/src/Ryujinx.Graphics.Vic/Types/ClearRectStruct.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vic/Types/ConfigStruct.cs b/src/Ryujinx.Graphics.Vic/Types/ConfigStruct.cs index 5edc81839..bf94606c0 100644 --- a/src/Ryujinx.Graphics.Vic/Types/ConfigStruct.cs +++ b/src/Ryujinx.Graphics.Vic/Types/ConfigStruct.cs @@ -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; diff --git a/src/Ryujinx.Graphics.Vic/Types/DeinterlaceMode.cs b/src/Ryujinx.Graphics.Vic/Types/DeinterlaceMode.cs index aa0654f01..216995b39 100644 --- a/src/Ryujinx.Graphics.Vic/Types/DeinterlaceMode.cs +++ b/src/Ryujinx.Graphics.Vic/Types/DeinterlaceMode.cs @@ -9,4 +9,4 @@ namespace Ryujinx.Graphics.Vic.Types Disi1, WeaveLumaBobFieldChroma } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Vic/Types/FrameFormat.cs b/src/Ryujinx.Graphics.Vic/Types/FrameFormat.cs index 91f5751b4..f6007f924 100644 --- a/src/Ryujinx.Graphics.Vic/Types/FrameFormat.cs +++ b/src/Ryujinx.Graphics.Vic/Types/FrameFormat.cs @@ -76,4 +76,4 @@ namespace Ryujinx.Graphics.Vic.Types return false; } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Vic/Types/LumaKeyStruct.cs b/src/Ryujinx.Graphics.Vic/Types/LumaKeyStruct.cs index 5d83bd711..0cb5e6d9d 100644 --- a/src/Ryujinx.Graphics.Vic/Types/LumaKeyStruct.cs +++ b/src/Ryujinx.Graphics.Vic/Types/LumaKeyStruct.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vic/Types/MatrixStruct.cs b/src/Ryujinx.Graphics.Vic/Types/MatrixStruct.cs index c0a4c34ee..f89a142f8 100644 --- a/src/Ryujinx.Graphics.Vic/Types/MatrixStruct.cs +++ b/src/Ryujinx.Graphics.Vic/Types/MatrixStruct.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vic/Types/OutputConfig.cs b/src/Ryujinx.Graphics.Vic/Types/OutputConfig.cs index 7b8669942..10ceb240f 100644 --- a/src/Ryujinx.Graphics.Vic/Types/OutputConfig.cs +++ b/src/Ryujinx.Graphics.Vic/Types/OutputConfig.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vic/Types/OutputSurfaceConfig.cs b/src/Ryujinx.Graphics.Vic/Types/OutputSurfaceConfig.cs index 6a8b21e13..ad236882d 100644 --- a/src/Ryujinx.Graphics.Vic/Types/OutputSurfaceConfig.cs +++ b/src/Ryujinx.Graphics.Vic/Types/OutputSurfaceConfig.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vic/Types/PipeConfig.cs b/src/Ryujinx.Graphics.Vic/Types/PipeConfig.cs index 76720eb1c..408bd83ea 100644 --- a/src/Ryujinx.Graphics.Vic/Types/PipeConfig.cs +++ b/src/Ryujinx.Graphics.Vic/Types/PipeConfig.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vic/Types/SlotConfig.cs b/src/Ryujinx.Graphics.Vic/Types/SlotConfig.cs index aba61add3..4031bf995 100644 --- a/src/Ryujinx.Graphics.Vic/Types/SlotConfig.cs +++ b/src/Ryujinx.Graphics.Vic/Types/SlotConfig.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vic/Types/SlotSurfaceConfig.cs b/src/Ryujinx.Graphics.Vic/Types/SlotSurfaceConfig.cs index 4492c85f9..0be0d4f43 100644 --- a/src/Ryujinx.Graphics.Vic/Types/SlotSurfaceConfig.cs +++ b/src/Ryujinx.Graphics.Vic/Types/SlotSurfaceConfig.cs @@ -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); diff --git a/src/Ryujinx.Graphics.Vic/VicDevice.cs b/src/Ryujinx.Graphics.Vic/VicDevice.cs index 8b66727df..b2bc98d81 100644 --- a/src/Ryujinx.Graphics.Vic/VicDevice.cs +++ b/src/Ryujinx.Graphics.Vic/VicDevice.cs @@ -30,7 +30,7 @@ namespace Ryujinx.Graphics.Vic { ConfigStruct config = ReadIndirect(_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); } diff --git a/src/Ryujinx.Graphics.Vic/VicRegisters.cs b/src/Ryujinx.Graphics.Vic/VicRegisters.cs index 1c11b5549..1e002839c 100644 --- a/src/Ryujinx.Graphics.Vic/VicRegisters.cs +++ b/src/Ryujinx.Graphics.Vic/VicRegisters.cs @@ -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 Reserved0; public uint Nop; public Array15 Reserved104; From 2b2ce68f07041189977515aa5b6ff6f04477d386 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 25 Jun 2023 18:37:53 +0200 Subject: [PATCH 16/17] [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 * Remove unused constant --------- Co-authored-by: Ac_K --- .../MultiRegionTrackingTests.cs | 21 ++++++------ src/Ryujinx.Tests.Memory/Tests.cs | 20 ++++++------ src/Ryujinx.Tests.Memory/TrackingTests.cs | 32 ++++++++++--------- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/Ryujinx.Tests.Memory/MultiRegionTrackingTests.cs b/src/Ryujinx.Tests.Memory/MultiRegionTrackingTests.cs index 674d23565..dffbe74d8 100644 --- a/src/Ryujinx.Tests.Memory/MultiRegionTrackingTests.cs +++ b/src/Ryujinx.Tests.Memory/MultiRegionTrackingTests.cs @@ -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 indices, Action action) + private static void RandomOrder(Random random, List indices, Action action) { List choices = indices.ToList(); @@ -51,7 +49,7 @@ namespace Ryujinx.Tests.Memory } } - private int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func addressPredicate) + private static int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func 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 addressPredicate, int sequenceNumber) + private static int ExpectQueryInOrder(IMultiRegionHandle handle, ulong startAddress, ulong size, Func 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 halfRange = Enumerable.Range(0, pageCount / 2); List 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 }); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Tests.Memory/Tests.cs b/src/Ryujinx.Tests.Memory/Tests.cs index 5ab01d5a5..bfc6344b7 100644 --- a/src/Ryujinx.Tests.Memory/Tests.cs +++ b/src/Ryujinx.Tests.Memory/Tests.cs @@ -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 } } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Tests.Memory/TrackingTests.cs b/src/Ryujinx.Tests.Memory/TrackingTests.cs index faf295575..dce73cf4f 100644 --- a/src/Ryujinx.Tests.Memory/TrackingTests.cs +++ b/src/Ryujinx.Tests.Memory/TrackingTests.cs @@ -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 testThreads = new List(); + List 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(); } } From 7ffe7f8442eb70980da55832a293fab52ff58cf1 Mon Sep 17 00:00:00 2001 From: TSRBerry <20988865+TSRBerry@users.noreply.github.com> Date: Sun, 25 Jun 2023 19:03:48 +0200 Subject: [PATCH 17/17] [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 --- .../FFmpegContext.cs | 6 +++--- .../H264/Decoder.cs | 4 ++-- .../H264/H264BitStreamWriter.cs | 6 +++--- .../H264/SpsAndPpsReconstruction.cs | 2 +- .../Native/AVCodec.cs | 2 +- .../Native/AVCodec501.cs | 2 +- .../Native/AVCodecContext.cs | 2 +- .../Native/AVFrame.cs | 2 +- .../Native/AVPacket.cs | 16 +++++++--------- .../Native/FFCodec.cs | 4 ++-- .../Native/FFCodecLegacy.cs | 4 ++-- .../Native/FFmpegApi.cs | 7 +++---- src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs | 6 +++--- src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs | 6 +++--- 14 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs index 572ceaaab..284a35a24 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs @@ -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) { diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs index d8b213e55..7dd643ce3 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs @@ -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(output).Slice(prep.Length)); + data.CopyTo(new Span(output)[prep.Length..]); return output; } diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/H264BitStreamWriter.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/H264BitStreamWriter.cs index 3d3b32933..57ab9fb53 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/H264BitStreamWriter.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/H264BitStreamWriter.cs @@ -84,9 +84,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264 Flush(); } - public Span AsSpan() + public readonly Span AsSpan() { - return new Span(_workBuffer).Slice(0, _offset); + return new Span(_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); } } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/SpsAndPpsReconstruction.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/SpsAndPpsReconstruction.cs index 57fb65d50..d8bf6f746 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/SpsAndPpsReconstruction.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/SpsAndPpsReconstruction.cs @@ -8,7 +8,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264 { public static Span Reconstruct(ref H264PictureInfo pictureInfo, byte[] workBuffer) { - H264BitStreamWriter writer = new H264BitStreamWriter(workBuffer); + H264BitStreamWriter writer = new(workBuffer); // Sequence Parameter Set. writer.WriteU(1, 24); diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs index 46d3ad61c..434b9b29b 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec.cs @@ -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; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs index 47d4969ac..7b82b5ddf 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodec501.cs @@ -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; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs index 6c9fbc893..a9605c63f 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVCodecContext.cs @@ -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; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs index faaf5c7d8..cdc9ebfdc 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVFrame.cs @@ -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 Data; public Array8 LineSize; public IntPtr ExtendedData; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVPacket.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVPacket.cs index d5b021040..47b9bef98 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVPacket.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/AVPacket.cs @@ -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 } -} \ No newline at end of file +} diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs index 4df45af46..89a33697c 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodec.cs @@ -2,9 +2,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { - struct FFCodec where T: struct + struct FFCodec 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; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs index 910270a55..630e2c179 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFCodecLegacy.cs @@ -2,9 +2,9 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native { - struct FFCodecLegacy where T: struct + struct FFCodecLegacy 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; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs index d173a4129..262d26431 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Native/FFmpegApi.cs @@ -10,7 +10,7 @@ namespace Ryujinx.Graphics.Nvdec.FFmpeg.Native public const string AvCodecLibraryName = "avcodec"; public const string AvUtilLibraryName = "avutil"; - private static readonly Dictionary _librariesWhitelist = new Dictionary + private static readonly Dictionary _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); diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs index 1ca9d1d53..959791b6e 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Surface.cs @@ -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; diff --git a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs index 3570c3ecc..5e38c8c8e 100644 --- a/src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs +++ b/src/Ryujinx.Graphics.Nvdec.FFmpeg/Vp8/Decoder.cs @@ -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(frame).Slice(uncompHeaderSize)); + bitstream.CopyTo(new Span(frame)[uncompHeaderSize..]); return _context.DecodeFrame(outSurf, frame) == 0; } public void Dispose() => _context.Dispose(); } -} \ No newline at end of file +}