Compare commits

..

4 Commits

Author SHA1 Message Date
MutantAura
eed17f963e Increase access permissions for Ava timezones (#4538) 2023-03-12 17:20:09 +01:00
TSRBerry
c09c0c002d [Flatpak] Beautify multiline strings again & Add full git commit hash (#4535)
* Don't destroy multiline strings

* Use full git commit hash
2023-03-12 10:42:33 +01:00
Mary
d56d335c0b misc: Some dependencies cleanup (#4507)
* Remove dependencies on libraries provided by .NET standard library

* Use System.IO.Hashing instead of Crc32.NET
2023-03-12 03:24:11 +01:00
jhorv
23c844b2aa Misc performance tweaks (#4509)
* use Array.Empty() where instead of allocating new zero-length arrays

* structure for loops in a way that the JIT will elide array/Span bounds checking

* avoiding function calls in for loop condition tests

* avoid LINQ in a hot path

* conform with code style

* fix mistake in GetNextWaitingObject()

* fix GetNextWaitingObject() possibility of returning null if all list items have TimePoint == long.MaxValue

* make GetNextWaitingObject() behave FIFO behavior for multiple items with the same TimePoint
2023-03-11 17:05:48 -03:00
22 changed files with 76 additions and 55 deletions

View File

@@ -35,7 +35,7 @@ jobs:
id: version_info id: version_info
working-directory: Ryujinx working-directory: Ryujinx
run: | run: |
echo "git_short_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT echo "git_hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
@@ -84,7 +84,7 @@ jobs:
- name: Update flatpak metadata - name: Update flatpak metadata
id: metadata id: metadata
env: env:
RYUJINX_GIT_HASH: ${{ steps.version_info.outputs.git_short_hash }} RYUJINX_GIT_HASH: ${{ steps.version_info.outputs.git_hash }}
shell: python shell: python
run: | run: |
import hashlib import hashlib
@@ -94,7 +94,17 @@ jobs:
import yaml import yaml
from datetime import datetime from datetime import datetime
from lxml import etree from lxml import etree
# Ensure we don't destroy multiline strings
def str_presenter(dumper, data):
if len(data.splitlines()) > 1:
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
return dumper.represent_scalar("tag:yaml.org,2002:str", data)
yaml.representer.SafeRepresenter.add_representer(str, str_presenter)
yaml_file = "flathub/org.ryujinx.Ryujinx.yml" yaml_file = "flathub/org.ryujinx.Ryujinx.yml"
xml_file = "flathub/org.ryujinx.Ryujinx.appdata.xml" xml_file = "flathub/org.ryujinx.Ryujinx.appdata.xml"

View File

@@ -265,7 +265,7 @@ namespace ARMeilleure.CodeGen.Arm64
} }
else else
{ {
relocInfo = new RelocInfo(new RelocEntry[0]); relocInfo = new RelocInfo(Array.Empty<RelocEntry>());
} }
return (code, relocInfo); return (code, relocInfo);

View File

@@ -433,16 +433,11 @@ namespace ARMeilleure.CodeGen.RegisterAllocators
private static int GetHighestValueIndex(Span<int> span) private static int GetHighestValueIndex(Span<int> span)
{ {
int highest = span[0]; int highest = int.MinValue;
if (highest == int.MaxValue)
{
return 0;
}
int selected = 0; int selected = 0;
for (int index = 1; index < span.Length; index++) for (int index = 0; index < span.Length; index++)
{ {
int current = span[index]; int current = span[index];

View File

@@ -17,7 +17,7 @@ namespace ARMeilleure.Decoders
{ {
uint[] tbl = new uint[256]; uint[] tbl = new uint[256];
for (int idx = 0; idx < 256; idx++) for (int idx = 0; idx < tbl.Length; idx++)
{ {
tbl[idx] = ExpandImm8ToFP32((uint)idx); tbl[idx] = ExpandImm8ToFP32((uint)idx);
} }
@@ -29,7 +29,7 @@ namespace ARMeilleure.Decoders
{ {
ulong[] tbl = new ulong[256]; ulong[] tbl = new ulong[256];
for (int idx = 0; idx < 256; idx++) for (int idx = 0; idx < tbl.Length; idx++)
{ {
tbl[idx] = ExpandImm8ToFP64((ulong)idx); tbl[idx] = ExpandImm8ToFP64((ulong)idx);
} }

View File

@@ -1301,7 +1301,7 @@ namespace ARMeilleure.Decoders
{ {
List<InstInfo>[] temp = new List<InstInfo>[FastLookupSize]; List<InstInfo>[] temp = new List<InstInfo>[FastLookupSize];
for (int index = 0; index < FastLookupSize; index++) for (int index = 0; index < temp.Length; index++)
{ {
temp[index] = new List<InstInfo>(); temp[index] = new List<InstInfo>();
} }
@@ -1311,7 +1311,7 @@ namespace ARMeilleure.Decoders
int mask = ToFastLookupIndex(inst.Mask); int mask = ToFastLookupIndex(inst.Mask);
int value = ToFastLookupIndex(inst.Value); int value = ToFastLookupIndex(inst.Value);
for (int index = 0; index < FastLookupSize; index++) for (int index = 0; index < temp.Length; index++)
{ {
if ((index & mask) == value) if ((index & mask) == value)
{ {
@@ -1320,7 +1320,7 @@ namespace ARMeilleure.Decoders
} }
} }
for (int index = 0; index < FastLookupSize; index++) for (int index = 0; index < temp.Length; index++)
{ {
table[index] = temp[index].ToArray(); table[index] = temp[index].ToArray();
} }

View File

@@ -12,7 +12,6 @@
<PackageVersion Include="Avalonia.Svg.Skia" Version="0.10.18" /> <PackageVersion Include="Avalonia.Svg.Skia" Version="0.10.18" />
<PackageVersion Include="CommandLineParser" Version="2.9.1" /> <PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="Concentus" Version="1.1.7" /> <PackageVersion Include="Concentus" Version="1.1.7" />
<PackageVersion Include="Crc32.NET" Version="1.2.0" />
<PackageVersion Include="DiscordRichPresence" Version="1.1.3.18" /> <PackageVersion Include="DiscordRichPresence" Version="1.1.3.18" />
<PackageVersion Include="DynamicData" Version="7.12.11" /> <PackageVersion Include="DynamicData" Version="7.12.11" />
<PackageVersion Include="FluentAvaloniaUI" Version="1.4.5" /> <PackageVersion Include="FluentAvaloniaUI" Version="1.4.5" />
@@ -45,10 +44,8 @@
<PackageVersion Include="SPB" Version="0.0.4-build28" /> <PackageVersion Include="SPB" Version="0.0.4-build28" />
<PackageVersion Include="System.Drawing.Common" Version="7.0.0" /> <PackageVersion Include="System.Drawing.Common" Version="7.0.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="6.27.0" /> <PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="6.27.0" />
<PackageVersion Include="System.IO.FileSystem.Primitives" Version="4.3.0" /> <PackageVersion Include="System.IO.Hashing" Version="7.0.0" />
<PackageVersion Include="System.Management" Version="7.0.0" /> <PackageVersion Include="System.Management" Version="7.0.0" />
<PackageVersion Include="System.Net.NameResolution" Version="4.3.0" />
<PackageVersion Include="System.Threading.ThreadPool" Version="4.3.0" />
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-f7c841d" /> <PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-f7c841d" />
<PackageVersion Include="XamlNameReferenceGenerator" Version="1.5.1" /> <PackageVersion Include="XamlNameReferenceGenerator" Version="1.5.1" />
</ItemGroup> </ItemGroup>

View File

@@ -400,7 +400,9 @@ namespace Ryujinx.Audio.Common
{ {
uint bufferIndex = (_releasedBufferIndex - _bufferReleasedCount) % Constants.AudioDeviceBufferCountMax; uint bufferIndex = (_releasedBufferIndex - _bufferReleasedCount) % Constants.AudioDeviceBufferCountMax;
for (int i = 0; i < GetTotalBufferCount(); i++) uint totalBufferCount = GetTotalBufferCount();
for (int i = 0; i < totalBufferCount; i++)
{ {
if (_buffers[bufferIndex].BufferTag == bufferTag) if (_buffers[bufferIndex].BufferTag == bufferTag)
{ {

View File

@@ -236,7 +236,7 @@ namespace Ryujinx.Ava.UI.ViewModels
public DateTimeOffset DateOffset { get; set; } public DateTimeOffset DateOffset { get; set; }
public TimeSpan TimeOffset { get; set; } public TimeSpan TimeOffset { get; set; }
private AvaloniaList<TimeZone> TimeZones { get; set; } internal AvaloniaList<TimeZone> TimeZones { get; set; }
public AvaloniaList<string> GameDirectories { get; set; } public AvaloniaList<string> GameDirectories { get; set; }
public ObservableCollection<ComboBoxItem> AvailableGpus { get; set; } public ObservableCollection<ComboBoxItem> AvailableGpus { get; set; }

View File

@@ -125,7 +125,7 @@ namespace Ryujinx.Ava.UI.Windows
public static Bgra32[] GetBuffer(Image<Bgra32> image) public static Bgra32[] GetBuffer(Image<Bgra32> image)
{ {
return image.TryGetSinglePixelSpan(out var data) ? data.ToArray() : new Bgra32[0]; return image.TryGetSinglePixelSpan(out var data) ? data.ToArray() : Array.Empty<Bgra32>();
} }
private static int GetColorScore(Dictionary<int, int> dominantColorBin, int maxHitCount, PaletteColor color) private static int GetColorScore(Dictionary<int, int> dominantColorBin, int maxHitCount, PaletteColor color)

View File

@@ -17,7 +17,7 @@ namespace Ryujinx.Graphics.Vulkan.Queries
_counterQueues = new CounterQueue[count]; _counterQueues = new CounterQueue[count];
for (int index = 0; index < count; index++) for (int index = 0; index < _counterQueues.Length; index++)
{ {
CounterType type = (CounterType)index; CounterType type = (CounterType)index;
_counterQueues[index] = new CounterQueue(gd, device, pipeline, type); _counterQueues[index] = new CounterQueue(gd, device, pipeline, type);

View File

@@ -29,9 +29,6 @@
<PackageReference Include="Silk.NET.Vulkan" /> <PackageReference Include="Silk.NET.Vulkan" />
<PackageReference Include="Silk.NET.Vulkan.Extensions.EXT" /> <PackageReference Include="Silk.NET.Vulkan.Extensions.EXT" />
<PackageReference Include="Silk.NET.Vulkan.Extensions.KHR" /> <PackageReference Include="Silk.NET.Vulkan.Extensions.KHR" />
<PackageReference Include="System.IO.FileSystem.Primitives" />
<PackageReference Include="System.Net.NameResolution" />
<PackageReference Include="System.Threading.ThreadPool" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -29,7 +29,7 @@ namespace Ryujinx.Graphics.Vulkan
uint structSize = 0; uint structSize = 0;
for (int i = 0; i < count; ++i) for (int i = 0; i < Map.Length; ++i)
{ {
var typeSize = SizeOf(description[i].Type); var typeSize = SizeOf(description[i].Type);
Map[i] = new SpecializationMapEntry(description[i].Id, structSize, typeSize); Map[i] = new SpecializationMapEntry(description[i].Id, structSize, typeSize);
@@ -46,11 +46,10 @@ namespace Ryujinx.Graphics.Vulkan
// For advanced mapping with overlapping or staggered fields // For advanced mapping with overlapping or staggered fields
public SpecDescription(SpecializationMapEntry[] map) public SpecDescription(SpecializationMapEntry[] map)
{ {
int count = map.Length;
Map = map; Map = map;
uint structSize = 0; uint structSize = 0;
for (int i = 0; i < count; ++i) for (int i = 0; i < map.Length; ++i)
{ {
structSize = Math.Max(structSize, map[i].Offset + (uint)map[i].Size); structSize = Math.Max(structSize, map[i].Offset + (uint)map[i].Size);
} }

View File

@@ -60,10 +60,9 @@ namespace Ryujinx.Graphics.Vulkan
private void RecreateSwapchain() private void RecreateSwapchain()
{ {
var oldSwapchain = _swapchain; var oldSwapchain = _swapchain;
int imageCount = _swapchainImageViews.Length;
_vsyncModeChanged = false; _vsyncModeChanged = false;
for (int i = 0; i < imageCount; i++) for (int i = 0; i < _swapchainImageViews.Length; i++)
{ {
_swapchainImageViews[i].Dispose(); _swapchainImageViews[i].Dispose();
} }
@@ -147,7 +146,7 @@ namespace Ryujinx.Graphics.Vulkan
_swapchainImageViews = new Auto<DisposableImageView>[imageCount]; _swapchainImageViews = new Auto<DisposableImageView>[imageCount];
for (int i = 0; i < imageCount; i++) for (int i = 0; i < _swapchainImageViews.Length; i++)
{ {
_swapchainImageViews[i] = CreateSwapchainImageView(_swapchainImages[i], surfaceFormat.Format); _swapchainImageViews[i] = CreateSwapchainImageView(_swapchainImages[i], surfaceFormat.Format);
} }

View File

@@ -49,12 +49,12 @@ namespace Ryujinx.HLE.HOS.Ipc
public static IpcHandleDesc MakeCopy(params int[] handles) public static IpcHandleDesc MakeCopy(params int[] handles)
{ {
return new IpcHandleDesc(handles, new int[0]); return new IpcHandleDesc(handles, Array.Empty<int>());
} }
public static IpcHandleDesc MakeMove(params int[] handles) public static IpcHandleDesc MakeMove(params int[] handles)
{ {
return new IpcHandleDesc(new int[0], handles); return new IpcHandleDesc(Array.Empty<int>(), handles);
} }
public byte[] GetBytes() public byte[] GetBytes()

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
@@ -132,7 +133,7 @@ namespace Ryujinx.HLE.HOS.Ipc
word0 |= (ReceiveBuff.Count & 0xf) << 24; word0 |= (ReceiveBuff.Count & 0xf) << 24;
word0 |= (ExchangeBuff.Count & 0xf) << 28; word0 |= (ExchangeBuff.Count & 0xf) << 28;
byte[] handleData = new byte[0]; byte[] handleData = Array.Empty<byte>();
if (HandleDesc != null) if (HandleDesc != null)
{ {
@@ -202,7 +203,7 @@ namespace Ryujinx.HLE.HOS.Ipc
word0 |= (ReceiveBuff.Count & 0xf) << 24; word0 |= (ReceiveBuff.Count & 0xf) << 24;
word0 |= (ExchangeBuff.Count & 0xf) << 28; word0 |= (ExchangeBuff.Count & 0xf) << 28;
byte[] handleData = new byte[0]; byte[] handleData = Array.Empty<byte>();
if (HandleDesc != null) if (HandleDesc != null)
{ {

View File

@@ -1,7 +1,6 @@
using Ryujinx.Common; using Ryujinx.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
namespace Ryujinx.HLE.HOS.Kernel.Common namespace Ryujinx.HLE.HOS.Kernel.Common
@@ -86,7 +85,7 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
{ {
Interlocked.Exchange(ref _enforceWakeupFromSpinWait, 0); Interlocked.Exchange(ref _enforceWakeupFromSpinWait, 0);
next = _waitingObjects.OrderBy(x => x.TimePoint).FirstOrDefault(); next = GetNextWaitingObject();
} }
if (next != null) if (next != null)
@@ -140,6 +139,26 @@ namespace Ryujinx.HLE.HOS.Kernel.Common
} }
} }
private WaitingObject GetNextWaitingObject()
{
WaitingObject selected = null;
long lowestTimePoint = long.MaxValue;
for (int index = _waitingObjects.Count - 1; index >= 0; index--)
{
WaitingObject current = _waitingObjects[index];
if (current.TimePoint <= lowestTimePoint)
{
selected = current;
lowestTimePoint = current.TimePoint;
}
}
return selected;
}
public static long ConvertNanosecondsToMilliseconds(long time) public static long ConvertNanosecondsToMilliseconds(long time)
{ {
time /= 1000000; time /= 1000000;

View File

@@ -233,7 +233,7 @@ namespace Ryujinx.HLE.HOS.Services.Time.TimeZone
// If the location name is too long, error out. // If the location name is too long, error out.
if (locationName.Length > 0x24) if (locationName.Length > 0x24)
{ {
outLocationNameArray = new string[0]; outLocationNameArray = Array.Empty<string>();
return ResultCode.LocationNameTooLong; return ResultCode.LocationNameTooLong;
} }

View File

@@ -27,7 +27,9 @@ namespace Ryujinx.Input.SDL2
SDL2Driver.Instance.OnJoystickDisconnected += HandleJoyStickDisconnected; SDL2Driver.Instance.OnJoystickDisconnected += HandleJoyStickDisconnected;
// Add already connected gamepads // Add already connected gamepads
for (int joystickIndex = 0; joystickIndex < SDL_NumJoysticks(); joystickIndex++) int numJoysticks = SDL_NumJoysticks();
for (int joystickIndex = 0; joystickIndex < numJoysticks; joystickIndex++)
{ {
HandleJoyStickConnected(joystickIndex, SDL_JoystickGetDeviceInstanceID(joystickIndex)); HandleJoyStickConnected(joystickIndex, SDL_JoystickGetDeviceInstanceID(joystickIndex));
} }

View File

@@ -1,5 +1,4 @@
using Force.Crc32; using Ryujinx.Common;
using Ryujinx.Common;
using Ryujinx.Common.Configuration.Hid; using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Common.Configuration.Hid.Controller; using Ryujinx.Common.Configuration.Hid.Controller;
using Ryujinx.Common.Configuration.Hid.Controller.Motion; using Ryujinx.Common.Configuration.Hid.Controller.Motion;
@@ -9,6 +8,7 @@ using Ryujinx.Input.Motion.CemuHook.Protocol;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Hashing;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Numerics; using System.Numerics;
@@ -401,10 +401,10 @@ namespace Ryujinx.Input.Motion.CemuHook
writer.Seek(6, SeekOrigin.Begin); writer.Seek(6, SeekOrigin.Begin);
writer.Write(header.Length); writer.Write(header.Length);
header.Crc32 = Crc32Algorithm.Compute(stream.ToArray()); Crc32.Hash(stream.ToArray(), header.Crc32.AsSpan());
writer.Seek(8, SeekOrigin.Begin); writer.Seek(8, SeekOrigin.Begin);
writer.Write(header.Crc32); writer.Write(header.Crc32.AsSpan());
byte[] data = stream.ToArray(); byte[] data = stream.ToArray();
@@ -440,10 +440,10 @@ namespace Ryujinx.Input.Motion.CemuHook
writer.Seek(6, SeekOrigin.Begin); writer.Seek(6, SeekOrigin.Begin);
writer.Write(header.Length); writer.Write(header.Length);
header.Crc32 = Crc32Algorithm.Compute(stream.ToArray()); Crc32.Hash(stream.ToArray(), header.Crc32.AsSpan());
writer.Seek(8, SeekOrigin.Begin); writer.Seek(8, SeekOrigin.Begin);
writer.Write(header.Crc32); writer.Write(header.Crc32.AsSpan());
byte[] data = stream.ToArray(); byte[] data = stream.ToArray();
@@ -458,8 +458,7 @@ namespace Ryujinx.Input.Motion.CemuHook
Id = (uint)clientId, Id = (uint)clientId,
MagicString = Magic, MagicString = Magic,
Version = Version, Version = Version,
Length = 0, Length = 0
Crc32 = 0
}; };
return header; return header;

View File

@@ -1,14 +1,15 @@
using System.Runtime.InteropServices; using Ryujinx.Common.Memory;
using System.Runtime.InteropServices;
namespace Ryujinx.Input.Motion.CemuHook.Protocol namespace Ryujinx.Input.Motion.CemuHook.Protocol
{ {
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct Header public struct Header
{ {
public uint MagicString; public uint MagicString;
public ushort Version; public ushort Version;
public ushort Length; public ushort Length;
public uint Crc32; public Array4<byte> Crc32;
public uint Id; public uint Id;
} }
} }

View File

@@ -6,7 +6,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Crc32.NET" /> <PackageReference Include="System.IO.Hashing" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -78,7 +78,7 @@ namespace Ryujinx.Memory.Tests
IEnumerable<MemoryRange> IVirtualMemoryManager.GetPhysicalRegions(ulong va, ulong size) IEnumerable<MemoryRange> IVirtualMemoryManager.GetPhysicalRegions(ulong va, ulong size)
{ {
return NoMappings ? new MemoryRange[0] : new MemoryRange[] { new MemoryRange(va, size) }; return NoMappings ? Array.Empty<MemoryRange>() : new MemoryRange[] { new MemoryRange(va, size) };
} }
public bool IsMapped(ulong va) public bool IsMapped(ulong va)