Skip to content

Commit

Permalink
misc: Code cleanups & improvements, again
Browse files Browse the repository at this point in the history
  • Loading branch information
GreemDev committed Oct 17, 2024
1 parent a13cf09 commit 235083a
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 156 deletions.
4 changes: 4 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<PackageVersion Include="Avalonia.Markup.Xaml.Loader" Version="11.0.10" />
<PackageVersion Include="Avalonia.Svg" Version="11.0.0.18" />
<PackageVersion Include="Avalonia.Svg.Skia" Version="11.0.0.18" />
<PackageVersion Include="Projektanker.Icons.Avalonia" Version="9.4.0" />
<PackageVersion Include="Projektanker.Icons.Avalonia.FontAwesome" Version="9.4.0"/>
<PackageVersion Include="Projektanker.Icons.Avalonia.MaterialDesign" Version="9.4.0"/>
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="Concentus" Version="2.2.0" />
<PackageVersion Include="DiscordRichPresence" Version="1.2.1.24" />
Expand All @@ -34,6 +37,7 @@
<PackageVersion Include="Ryujinx.Graphics.Nvdec.Dependencies" Version="5.0.3-build14" />
<PackageVersion Include="Ryujinx.Graphics.Vulkan.Dependencies.MoltenVK" Version="1.2.0" />
<PackageVersion Include="Ryujinx.SDL2-CS" Version="2.30.0-build32" />
<PackageVersion Include="Gommon" Version="2.6.5" />
<PackageVersion Include="securifybv.ShellLink" Version="0.1.0" />
<PackageVersion Include="shaderc.net" Version="0.1.0" />
<PackageVersion Include="SharpZipLib" Version="1.4.2" />
Expand Down
6 changes: 3 additions & 3 deletions src/ARMeilleure/Optimizations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ARMeilleure
public static class Optimizations
{
// low-core count PPTC
public static bool EcoFriendly { get; set; } = false;
public static bool LowPower { get; set; } = false;

public static bool FastFP { get; set; } = true;

Expand Down Expand Up @@ -54,8 +54,8 @@ public static bool ForceLegacySse
internal static bool UseSse41 => UseSse41IfAvailable && X86HardwareCapabilities.SupportsSse41;
internal static bool UseSse42 => UseSse42IfAvailable && X86HardwareCapabilities.SupportsSse42;
internal static bool UsePopCnt => UsePopCntIfAvailable && X86HardwareCapabilities.SupportsPopcnt;
internal static bool UseAvx => UseAvxIfAvailable && X86HardwareCapabilities.SupportsAvx && !ForceLegacySse;
internal static bool UseAvx512F => UseAvx512FIfAvailable && X86HardwareCapabilities.SupportsAvx512F && !ForceLegacySse;
internal static bool UseAvx => UseAvxIfAvailable && X86HardwareCapabilities.SupportsAvx && !ForceLegacySse;
internal static bool UseAvx512F => UseAvx512FIfAvailable && X86HardwareCapabilities.SupportsAvx512F && !ForceLegacySse;
internal static bool UseAvx512Vl => UseAvx512VlIfAvailable && X86HardwareCapabilities.SupportsAvx512Vl && !ForceLegacySse;
internal static bool UseAvx512Bw => UseAvx512BwIfAvailable && X86HardwareCapabilities.SupportsAvx512Bw && !ForceLegacySse;
internal static bool UseAvx512Dq => UseAvx512DqIfAvailable && X86HardwareCapabilities.SupportsAvx512Dq && !ForceLegacySse;
Expand Down
4 changes: 2 additions & 2 deletions src/ARMeilleure/Translation/PTC/Ptc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,11 @@ public void MakeAndSaveTranslations(Translator translator)

int degreeOfParallelism = Environment.ProcessorCount;

if (Optimizations.EcoFriendly)
if (Optimizations.LowPower)
degreeOfParallelism /= 3;

// If there are enough cores lying around, we leave one alone for other tasks.
if (degreeOfParallelism > 4 && !Optimizations.EcoFriendly)
if (degreeOfParallelism > 4 && !Optimizations.LowPower)
{
degreeOfParallelism--;
}
Expand Down
1 change: 1 addition & 0 deletions src/Ryujinx.Common/Ryujinx.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" />
<PackageReference Include="MsgPack.Cli" />
<PackageReference Include="System.Management" />
<PackageReference Include="Gommon" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Ryujinx.Graphics.Nvdec.FFmpeg/FFmpegContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public FFmpegContext(AVCodecID codecId)
int avCodecMajorVersion = avCodecRawVersion >> 16;
int avCodecMinorVersion = (avCodecRawVersion >> 8) & 0xFF;

// libavcodec 59.24 changed AvCodec to move its private API and also move the codec function to an union.
// libavcodec 59.24 changed AvCodec to move its private API and also move the codec function to a union.
if (avCodecMajorVersion > 59 || (avCodecMajorVersion == 59 && avCodecMinorVersion > 24))
{
_decodeFrame = Marshal.GetDelegateForFunctionPointer<AVCodec_decode>(((FFCodec<AVCodec>*)_codec)->CodecCallback);
Expand Down
5 changes: 2 additions & 3 deletions src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/Decoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public bool Decode(ref H264PictureInfo pictureInfo, ISurface output, ReadOnlySpa
{
Surface outSurf = (Surface)output;

if (outSurf.RequestedWidth != _oldOutputWidth ||
outSurf.RequestedHeight != _oldOutputHeight)
if (outSurf.RequestedWidth != _oldOutputWidth || outSurf.RequestedHeight != _oldOutputHeight)
{
_context.Dispose();
_context = new FFmpegContext(AVCodecID.AV_CODEC_ID_H264);
Expand All @@ -38,7 +37,7 @@ public bool Decode(ref H264PictureInfo pictureInfo, ISurface output, ReadOnlySpa

Span<byte> bs = Prepend(bitstream, SpsAndPpsReconstruction.Reconstruct(ref pictureInfo, _workBuffer));

return _context.DecodeFrame(outSurf, bs) == 0;
return _context.DecodeFrame(outSurf, bs) is 0;
}

private static byte[] Prepend(ReadOnlySpan<byte> data, ReadOnlySpan<byte> prep)
Expand Down
28 changes: 7 additions & 21 deletions src/Ryujinx.Graphics.Nvdec.FFmpeg/H264/H264BitStreamWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,13 @@

namespace Ryujinx.Graphics.Nvdec.FFmpeg.H264
{
struct H264BitStreamWriter
struct H264BitStreamWriter(byte[] workBuffer)
{
private const int BufferSize = 8;

private readonly byte[] _workBuffer;

private int _offset;
private int _buffer;
private int _bufferPos;

public H264BitStreamWriter(byte[] workBuffer)
{
_workBuffer = workBuffer;
_offset = 0;
_buffer = 0;
_bufferPos = 0;
}
private int _offset = 0;
private int _buffer = 0;
private int _bufferPos = 0;

public void WriteBit(bool value)
{
Expand Down Expand Up @@ -59,9 +49,7 @@ public void WriteBits(int value, int valueSize)
private int GetFreeBufferBits()
{
if (_bufferPos == BufferSize)
{
Flush();
}

return BufferSize - _bufferPos;
}
Expand All @@ -70,7 +58,7 @@ public void Flush()
{
if (_bufferPos != 0)
{
_workBuffer[_offset++] = (byte)_buffer;
workBuffer[_offset++] = (byte)_buffer;

_buffer = 0;
_bufferPos = 0;
Expand All @@ -84,10 +72,8 @@ public void End()
Flush();
}

public readonly Span<byte> AsSpan()
{
return new Span<byte>(_workBuffer)[.._offset];
}
public readonly Span<byte> AsSpan()
=> new Span<byte>(workBuffer)[.._offset];

public void WriteU(uint value, int valueSize) => WriteBits((int)value, valueSize);
public void WriteSe(int value) => WriteExpGolombCodedInt(value);
Expand Down
74 changes: 13 additions & 61 deletions src/Ryujinx.HLE/Switch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,77 +68,29 @@ public Switch(HLEConfiguration configuration)
#pragma warning restore IDE0055
}

public bool LoadCart(string exeFsDir, string romFsFile = null)
{
return Processes.LoadUnpackedNca(exeFsDir, romFsFile);
}

public bool LoadXci(string xciFile, ulong applicationId = 0)
{
return Processes.LoadXci(xciFile, applicationId);
}

public bool LoadNca(string ncaFile)
{
return Processes.LoadNca(ncaFile);
}

public bool LoadNsp(string nspFile, ulong applicationId = 0)
{
return Processes.LoadNsp(nspFile, applicationId);
}

public bool LoadProgram(string fileName)
{
return Processes.LoadNxo(fileName);
}

public bool WaitFifo()
{
return Gpu.GPFifo.WaitForCommands();
}

public void ProcessFrame()
{
Gpu.ProcessShaderCacheQueue();
Gpu.Renderer.PreFrame();
Gpu.GPFifo.DispatchCalls();
}

public bool ConsumeFrameAvailable()
{
return Gpu.Window.ConsumeFrameAvailable();
}
public bool LoadCart(string exeFsDir, string romFsFile = null) => Processes.LoadUnpackedNca(exeFsDir, romFsFile);
public bool LoadXci(string xciFile, ulong applicationId = 0) => Processes.LoadXci(xciFile, applicationId);
public bool LoadNca(string ncaFile) => Processes.LoadNca(ncaFile);
public bool LoadNsp(string nspFile, ulong applicationId = 0) => Processes.LoadNsp(nspFile, applicationId);
public bool LoadProgram(string fileName) => Processes.LoadNxo(fileName);

public void PresentFrame(Action swapBuffersCallback)
{
Gpu.Window.Present(swapBuffersCallback);
}
public void SetVolume(float volume) => AudioDeviceDriver.Volume = Math.Clamp(volume, 0f, 1f);
public float GetVolume() => AudioDeviceDriver.Volume;
public bool IsAudioMuted() => AudioDeviceDriver.Volume == 0;

public void SetVolume(float volume)
{
AudioDeviceDriver.Volume = Math.Clamp(volume, 0f, 1f);
}

public float GetVolume()
{
return AudioDeviceDriver.Volume;
}
public void EnableCheats() => ModLoader.EnableCheats(Processes.ActiveApplication.ProgramId, TamperMachine);

public void EnableCheats()
{
ModLoader.EnableCheats(Processes.ActiveApplication.ProgramId, TamperMachine);
}

public bool IsAudioMuted()
{
return AudioDeviceDriver.Volume == 0;
}

public void DisposeGpu()
{
Gpu.Dispose();
}
public bool WaitFifo() => Gpu.GPFifo.WaitForCommands();
public bool ConsumeFrameAvailable() => Gpu.Window.ConsumeFrameAvailable();
public void PresentFrame(Action swapBuffersCallback) => Gpu.Window.Present(swapBuffersCallback);
public void DisposeGpu() => Gpu.Dispose();

public void Dispose()
{
Expand Down
7 changes: 2 additions & 5 deletions src/Ryujinx/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ private void Renderer_ScreenCaptured(object sender, ScreenCaptureImageInfo e)
}
}

private void SaveBitmapAsPng(SKBitmap bitmap, string path)
private static void SaveBitmapAsPng(SKBitmap bitmap, string path)
{
using var data = bitmap.Encode(SKEncodedImageFormat.Png, 100);
using var stream = File.OpenWrite(path);
Expand All @@ -406,8 +406,6 @@ private void SaveBitmapAsPng(SKBitmap bitmap, string path)

public void Start()
{
ARMeilleure.Optimizations.EcoFriendly = ConfigurationState.Instance.System.EnableLowPowerPtc;

if (OperatingSystem.IsWindows())
{
_windowsMultimediaTimerResolution = new WindowsMultimediaTimerResolution(1);
Expand Down Expand Up @@ -540,9 +538,8 @@ public void DisposeContext()
private void Dispose()
{
if (Device.Processes != null)
{
MainWindowViewModel.UpdateGameMetadata(Device.Processes.ActiveApplication.ProgramIdText);
}


ConfigurationState.Instance.System.IgnoreMissingServices.Event -= UpdateIgnoreMissingServicesState;
ConfigurationState.Instance.Graphics.AspectRatio.Event -= UpdateAspectRatioState;
Expand Down
34 changes: 14 additions & 20 deletions src/Ryujinx/Common/Locale/LocaleExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,20 @@ namespace Ryujinx.Ava.Common.Locale
{
internal class LocaleExtension(LocaleKeys key) : MarkupExtension
{
public LocaleKeys Key { get; } = key;
private ClrPropertyInfo PropertyInfo
=> new(
"Item",
_ => LocaleManager.Instance[key],
null,
typeof(string)
);

public override object ProvideValue(IServiceProvider serviceProvider)
{
var builder = new CompiledBindingPathBuilder();

builder.Property(
new ClrPropertyInfo("Item",
_ => LocaleManager.Instance[Key],
null,
typeof(string)
),
PropertyInfoAccessorFactory.CreateInpcPropertyAccessor);

var binding = new CompiledBindingExtension(builder.Build())
{
Source = LocaleManager.Instance
};

return binding.ProvideValue(serviceProvider);
}
public override object ProvideValue(IServiceProvider serviceProvider) =>
new CompiledBindingExtension(
new CompiledBindingPathBuilder()
.Property(PropertyInfo, PropertyInfoAccessorFactory.CreateInpcPropertyAccessor)
.Build()
) { Source = LocaleManager.Instance }
.ProvideValue(serviceProvider);
}
}
15 changes: 5 additions & 10 deletions src/Ryujinx/UI/Controls/NavigationDialogHost.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Avalonia.Styling;
using Avalonia.Threading;
using FluentAvalonia.UI.Controls;
using Gommon;
using LibHac;
using LibHac.Common;
using LibHac.Fs;
Expand Down Expand Up @@ -84,10 +85,7 @@ public static async Task Show(AccountManager ownerAccountManager, ContentManager
Padding = new Thickness(0),
};

contentDialog.Closed += (sender, args) =>
{
content.ViewModel.Dispose();
};
contentDialog.Closed += (_, _) => content.ViewModel.Dispose();

Style footer = new(x => x.Name("DialogSpace").Child().OfType<Border>());
footer.Setters.Add(new Setter(IsVisibleProperty, false));
Expand All @@ -109,12 +107,9 @@ public void LoadProfiles()
ViewModel.Profiles.Clear();
ViewModel.LostProfiles.Clear();

var profiles = AccountManager.GetAllUsers().OrderBy(x => x.Name);

foreach (var profile in profiles)
{
ViewModel.Profiles.Add(new UserProfile(profile, this));
}
AccountManager.GetAllUsers()
.OrderBy(x => x.Name)
.ForEach(profile => ViewModel.Profiles.Add(new UserProfile(profile, this)));

var saveDataFilter = SaveDataFilter.Make(programId: default, saveType: SaveDataType.Account, default, saveDataId: default, index: default);

Expand Down
Loading

0 comments on commit 235083a

Please sign in to comment.