Compare commits

...

14 Commits

Author SHA1 Message Date
Isaac Marovitz
f33fea3287 Remove Custom Theming (#6175) 2024-01-26 00:20:50 +01:00
dependabot[bot]
5d3eea40be nuget: bump DynamicData from 7.14.2 to 8.3.27 (#6028)
Bumps [DynamicData](https://github.com/reactiveui/DynamicData) from 7.14.2 to 8.3.27.
- [Release notes](https://github.com/reactiveui/DynamicData/releases)
- [Changelog](https://github.com/reactivemarbles/DynamicData/blob/main/ReleaseNotes.md)
- [Commits](https://github.com/reactiveui/DynamicData/compare/7.14.2...8.3.27)

---
updated-dependencies:
- dependency-name: DynamicData
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ac_K <Acoustik666@gmail.com>
2024-01-26 00:17:02 +01:00
Ac_K
cd37c75b82 Horizon: Implement arp:r and arp:w services (#5802)
* Horizon: Implement arp:r and arp:w services

* Fix formatting

* Remove HLE arp services

* Revert "Remove HLE arp services"

This reverts commit c576fcccadb963db56b96bacabd1c1ac7abfb1ab.

* Keep LibHac impl since it's used in bcat

* Addresses gdkchan's feedback

* ArpApi in PrepoIpcServer and remove LmApi

* Fix 2

* Fixes ArpApi init

* Fix encoding

* Update PrepoService.cs

* Fix prepo
2024-01-25 23:06:53 +01:00
TSRBerry
43705c2320 ssl: Work around missing remote hostname for authentication (#5988)
* ssl: Retrieve remote hostnames if the provided hostname is empty

 This avoids crashing with an AuthenticationException.

* ssl: Remove unused variable from RetrieveHostName
2024-01-25 20:10:51 +01:00
dependabot[bot]
371e6fa24c nuget: bump Microsoft.IO.RecyclableMemoryStream from 2.3.2 to 3.0.0 (#6120)
Bumps [Microsoft.IO.RecyclableMemoryStream](https://github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream) from 2.3.2 to 3.0.0.
- [Release notes](https://github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream/releases)
- [Changelog](https://github.com/microsoft/Microsoft.IO.RecyclableMemoryStream/blob/master/CHANGES.md)
- [Commits](https://github.com/Microsoft/Microsoft.IO.RecyclableMemoryStream/compare/2.3.2...3.0.0)

---
updated-dependencies:
- dependency-name: Microsoft.IO.RecyclableMemoryStream
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-25 19:41:24 +01:00
dependabot[bot]
1d9b63cc6a nuget: bump Microsoft.CodeAnalysis.CSharp from 4.7.0 to 4.8.0 (#6118)
Bumps [Microsoft.CodeAnalysis.CSharp](https://github.com/dotnet/roslyn) from 4.7.0 to 4.8.0.
- [Release notes](https://github.com/dotnet/roslyn/releases)
- [Changelog](https://github.com/dotnet/roslyn/blob/main/docs/Breaking%20API%20Changes.md)
- [Commits](https://github.com/dotnet/roslyn/commits)

---
updated-dependencies:
- dependency-name: Microsoft.CodeAnalysis.CSharp
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-01-25 19:35:10 +01:00
riperiperi
795539bc82 Vulkan: Use staging buffer for temporary constants (#6168)
* Vulkan: Use staging buffer for temporary constants

Helper shaders and post processing effects typically need some parameters to tell them what to do, which we pass via constant buffers that are created and destroyed each time.

This can vary in cost between different Vulkan drivers. It shows up on profiles on mesa and MoltenVK, so it's worth avoiding. Some games only do it once (BlitColor for present), others multiple times. It's also done for post processing filters and FSR upscaling, which creates two buffers.

For mirrors, I added the ability to reserve a range on the staging buffer for use as any type of binding. This PR allows these constant buffers to be instead temporarily allocated on the staging buffer, skipping allocation and buffer management costs entirely.

Two temporary allocations do remain:
- DrawTexture, because it doesn't have access to the command buffer scope
- Index buffer indirect conversion, because one of them is a storage buffer and thus is a little more complicated.

There's a small cost in that the uniform buffer takes up more space due to alignment requirements. At worst that's 256 bytes (on a GTX 1070) but more modern GPUs should have a better time.

Worth testing across different games and post effects to make sure they still work.

* Use temporary buffer for ConvertIndexBufferIndirect

* Simplify alignment passing for now

* Fix shader params length for CopyIncompatibleFormats

* Set data for helpershaders without overlap checks

The data is in the staging buffer, so its usage range is guarded using that.
2024-01-25 19:29:53 +01:00
Isaac Marovitz
dd2e851e95 OpenTK (#6143) 2024-01-25 19:25:47 +01:00
gdkchan
2ca70eb9a0 Implement SQSHL (immediate) CPU instruction (#6155)
* Implement SQSHL (immediate) CPU instruction

* Fix test
2024-01-24 23:50:43 +01:00
riperiperi
6575952432 Vulkan: Enumerate Query Pool properly (#6167)
Turns out that ElementAt for Queue<T> runs the default implementation as it doesn't implement IList, which enumerates elements of the queue up to the given index. This code was creating `count` enumerators and iterating way more queue items than it needed to at higher counts. The solution is just to use one enumerator and break out of the loop when we get the count that we need.

3.5% of backend time was being spent _just_ enumerating at the usual spot in SMO.
2024-01-24 19:33:52 -03:00
gdkchan
9a28ba72b1 Use unix timestamps on GetFileTimeStampRaw (#6169) 2024-01-24 19:26:59 -03:00
Alex0007
34a9922b57 Fix architecture preference for MacOS game shortcuts (#6145)
* Fix architecture preference for MacOS game shortcuts

* Detect arch and then pass it to script

Co-authored-by: jcm <john.moody@coloradocollege.edu>

* Remove old script write call in `CreateShortcutMacos`

* Turn launch script into EmbeddedResource

* Added final newline

---------

Co-authored-by: jcm <john.moody@coloradocollege.edu>
2024-01-22 23:10:25 +01:00
gdkchan
4df22eb867 Fix missing data for new copy dependency textures with mismatching size (#6161) 2024-01-22 17:42:26 -03:00
gdkchan
f241f88558 Add a separate device memory manager (#6153)
* Add a separate device memory manager

* Still need this

* Device writes are always tracked

* Device writes are always tracked (2)

* Rename more instances of gmm to mm
2024-01-22 17:14:46 -03:00
97 changed files with 2447 additions and 422 deletions

View File

@@ -13,25 +13,25 @@
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
<PackageVersion Include="Concentus" Version="1.1.7" />
<PackageVersion Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageVersion Include="DynamicData" Version="7.14.2" />
<PackageVersion Include="DynamicData" Version="8.3.27" />
<PackageVersion Include="FluentAvaloniaUI" Version="2.0.5" />
<PackageVersion Include="GtkSharp.Dependencies" Version="1.1.1" />
<PackageVersion Include="GtkSharp.Dependencies.osx" Version="0.0.5" />
<PackageVersion Include="jp2masa.Avalonia.Flexbox" Version="0.3.0-beta.4" />
<PackageVersion Include="LibHac" Version="0.19.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.8.0" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
<PackageVersion Include="MsgPack.Cli" Version="1.0.1" />
<PackageVersion Include="NetCoreServer" Version="7.0.0" />
<PackageVersion Include="NUnit" Version="3.13.3" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.1.0" />
<PackageVersion Include="OpenTK.Core" Version="4.8.1" />
<PackageVersion Include="OpenTK.Graphics" Version="4.8.1" />
<PackageVersion Include="OpenTK.Audio.OpenAL" Version="4.8.1" />
<PackageVersion Include="OpenTK.Windowing.GraphicsLibraryFramework" Version="4.8.1" />
<PackageVersion Include="OpenTK.Core" Version="4.8.2" />
<PackageVersion Include="OpenTK.Graphics" Version="4.8.2" />
<PackageVersion Include="OpenTK.Audio.OpenAL" Version="4.8.2" />
<PackageVersion Include="OpenTK.Windowing.GraphicsLibraryFramework" Version="4.8.2" />
<PackageVersion Include="Ryujinx.Audio.OpenAL.Dependencies" Version="1.21.0.1" />
<PackageVersion Include="Ryujinx.Graphics.Nvdec.Dependencies" Version="5.0.1-build13" />
<PackageVersion Include="Ryujinx.Graphics.Vulkan.Dependencies.MoltenVK" Version="1.2.0" />

View File

@@ -0,0 +1,8 @@
#!/bin/sh
launch_arch="$(uname -m)"
if [ "$(sysctl -in sysctl.proc_translated)" = "1" ]
then
launch_arch="arm64"
fi
arch -$launch_arch {0} {1}

View File

@@ -517,7 +517,10 @@ namespace ARMeilleure.Decoders
SetA64("0x00111100>>>xxx100111xxxxxxxxxx", InstName.Sqrshrn_V, InstEmit.Sqrshrn_V, OpCodeSimdShImm.Create);
SetA64("0111111100>>>xxx100011xxxxxxxxxx", InstName.Sqrshrun_S, InstEmit.Sqrshrun_S, OpCodeSimdShImm.Create);
SetA64("0x10111100>>>xxx100011xxxxxxxxxx", InstName.Sqrshrun_V, InstEmit.Sqrshrun_V, OpCodeSimdShImm.Create);
SetA64("010111110>>>>xxx011101xxxxxxxxxx", InstName.Sqshl_Si, InstEmit.Sqshl_Si, OpCodeSimdShImm.Create);
SetA64("0>001110<<1xxxxx010011xxxxxxxxxx", InstName.Sqshl_V, InstEmit.Sqshl_V, OpCodeSimdReg.Create);
SetA64("0000111100>>>xxx011101xxxxxxxxxx", InstName.Sqshl_Vi, InstEmit.Sqshl_Vi, OpCodeSimdShImm.Create);
SetA64("010011110>>>>xxx011101xxxxxxxxxx", InstName.Sqshl_Vi, InstEmit.Sqshl_Vi, OpCodeSimdShImm.Create);
SetA64("0101111100>>>xxx100101xxxxxxxxxx", InstName.Sqshrn_S, InstEmit.Sqshrn_S, OpCodeSimdShImm.Create);
SetA64("0x00111100>>>xxx100101xxxxxxxxxx", InstName.Sqshrn_V, InstEmit.Sqshrn_V, OpCodeSimdShImm.Create);
SetA64("0111111100>>>xxx100001xxxxxxxxxx", InstName.Sqshrun_S, InstEmit.Sqshrun_S, OpCodeSimdShImm.Create);

View File

@@ -116,7 +116,7 @@ namespace ARMeilleure.Instructions
}
else if (shift >= eSize)
{
if ((op.RegisterSize == RegisterSize.Simd64))
if (op.RegisterSize == RegisterSize.Simd64)
{
Operand res = context.VectorZeroUpper64(GetVec(op.Rd));
@@ -359,6 +359,16 @@ namespace ARMeilleure.Instructions
}
}
public static void Sqshl_Si(ArmEmitterContext context)
{
EmitShlImmOp(context, signedDst: true, ShlRegFlags.Signed | ShlRegFlags.Scalar | ShlRegFlags.Saturating);
}
public static void Sqshl_Vi(ArmEmitterContext context)
{
EmitShlImmOp(context, signedDst: true, ShlRegFlags.Signed | ShlRegFlags.Saturating);
}
public static void Sqshrn_S(ArmEmitterContext context)
{
if (Optimizations.UseAdvSimd)
@@ -1593,6 +1603,99 @@ namespace ARMeilleure.Instructions
Saturating = 1 << 3,
}
private static void EmitShlImmOp(ArmEmitterContext context, bool signedDst, ShlRegFlags flags = ShlRegFlags.None)
{
bool scalar = flags.HasFlag(ShlRegFlags.Scalar);
bool signed = flags.HasFlag(ShlRegFlags.Signed);
bool saturating = flags.HasFlag(ShlRegFlags.Saturating);
OpCodeSimdShImm op = (OpCodeSimdShImm)context.CurrOp;
Operand res = context.VectorZero();
int elems = !scalar ? op.GetBytesCount() >> op.Size : 1;
for (int index = 0; index < elems; index++)
{
Operand ne = EmitVectorExtract(context, op.Rn, index, op.Size, signed);
Operand e = !saturating
? EmitShlImm(context, ne, GetImmShl(op), op.Size)
: EmitShlImmSatQ(context, ne, GetImmShl(op), op.Size, signed, signedDst);
res = EmitVectorInsert(context, res, e, index, op.Size);
}
context.Copy(GetVec(op.Rd), res);
}
private static Operand EmitShlImm(ArmEmitterContext context, Operand op, int shiftLsB, int size)
{
int eSize = 8 << size;
Debug.Assert(op.Type == OperandType.I64);
Debug.Assert(eSize == 8 || eSize == 16 || eSize == 32 || eSize == 64);
Operand res = context.AllocateLocal(OperandType.I64);
if (shiftLsB >= eSize)
{
Operand shl = context.ShiftLeft(op, Const(shiftLsB));
context.Copy(res, shl);
}
else
{
Operand zeroL = Const(0L);
context.Copy(res, zeroL);
}
return res;
}
private static Operand EmitShlImmSatQ(ArmEmitterContext context, Operand op, int shiftLsB, int size, bool signedSrc, bool signedDst)
{
int eSize = 8 << size;
Debug.Assert(op.Type == OperandType.I64);
Debug.Assert(eSize == 8 || eSize == 16 || eSize == 32 || eSize == 64);
Operand lblEnd = Label();
Operand res = context.Copy(context.AllocateLocal(OperandType.I64), op);
if (shiftLsB >= eSize)
{
context.Copy(res, signedSrc
? EmitSignedSignSatQ(context, op, size)
: EmitUnsignedSignSatQ(context, op, size));
}
else
{
Operand shl = context.ShiftLeft(op, Const(shiftLsB));
if (eSize == 64)
{
Operand sarOrShr = signedSrc
? context.ShiftRightSI(shl, Const(shiftLsB))
: context.ShiftRightUI(shl, Const(shiftLsB));
context.Copy(res, shl);
context.BranchIf(lblEnd, sarOrShr, op, Comparison.Equal);
context.Copy(res, signedSrc
? EmitSignedSignSatQ(context, op, size)
: EmitUnsignedSignSatQ(context, op, size));
}
else
{
context.Copy(res, signedSrc
? EmitSignedSrcSatQ(context, shl, size, signedDst)
: EmitUnsignedSrcSatQ(context, shl, size, signedDst));
}
}
context.MarkLabel(lblEnd);
return res;
}
private static void EmitShlRegOp(ArmEmitterContext context, ShlRegFlags flags = ShlRegFlags.None)
{
bool scalar = flags.HasFlag(ShlRegFlags.Scalar);

View File

@@ -384,7 +384,9 @@ namespace ARMeilleure.Instructions
Sqrshrn_V,
Sqrshrun_S,
Sqrshrun_V,
Sqshl_Si,
Sqshl_V,
Sqshl_Vi,
Sqshrn_S,
Sqshrn_V,
Sqshrun_S,

View File

@@ -12,7 +12,6 @@ using Ryujinx.Ui.Common.Configuration;
using Ryujinx.Ui.Common.Helper;
using System;
using System.Diagnostics;
using System.IO;
namespace Ryujinx.Ava
{
@@ -90,8 +89,6 @@ namespace Ryujinx.Ava
try
{
string baseStyle = ConfigurationState.Instance.Ui.BaseStyle;
string themePath = ConfigurationState.Instance.Ui.CustomThemePath;
bool enableCustomTheme = ConfigurationState.Instance.Ui.EnableCustomTheme;
if (string.IsNullOrWhiteSpace(baseStyle))
{
@@ -106,24 +103,6 @@ namespace Ryujinx.Ava
"Dark" => ThemeVariant.Dark,
_ => ThemeVariant.Default,
};
if (enableCustomTheme)
{
if (!string.IsNullOrWhiteSpace(themePath))
{
try
{
var themeContent = File.ReadAllText(themePath);
var customStyle = AvaloniaRuntimeXamlLoader.Parse<IStyle>(themeContent);
Styles.Add(customStyle);
}
catch (Exception ex)
{
Logger.Error?.Print(LogClass.Application, $"Failed to Apply Custom Theme. Error: {ex.Message}");
}
}
}
}
catch (Exception)
{

View File

@@ -294,13 +294,9 @@
"GameListContextMenuRunApplication": "Run Application",
"GameListContextMenuToggleFavorite": "Toggle Favorite",
"GameListContextMenuToggleFavoriteToolTip": "Toggle Favorite status of Game",
"SettingsTabGeneralTheme": "Theme",
"SettingsTabGeneralThemeCustomTheme": "Custom Theme Path",
"SettingsTabGeneralThemeBaseStyle": "Base Style",
"SettingsTabGeneralThemeBaseStyleDark": "Dark",
"SettingsTabGeneralThemeBaseStyleLight": "Light",
"SettingsTabGeneralThemeEnableCustomTheme": "Enable Custom Theme",
"ButtonBrowse": "Browse",
"SettingsTabGeneralTheme": "Theme:",
"SettingsTabGeneralThemeDark": "Dark",
"SettingsTabGeneralThemeLight": "Light",
"ControllerSettingsConfigureGeneral": "Configure",
"ControllerSettingsRumble": "Rumble",
"ControllerSettingsRumbleStrongMultiplier": "Strong Rumble Multiplier",

View File

@@ -48,7 +48,6 @@ namespace Ryujinx.Ava.UI.ViewModels
private readonly List<string> _gpuIds = new();
private KeyboardHotkeys _keyboardHotkeys;
private int _graphicsBackendIndex;
private string _customThemePath;
private int _scalingFilter;
private int _scalingFilterLevel;
@@ -160,7 +159,6 @@ namespace Ryujinx.Ava.UI.ViewModels
public bool IsOpenAlEnabled { get; set; }
public bool IsSoundIoEnabled { get; set; }
public bool IsSDL2Enabled { get; set; }
public bool EnableCustomTheme { get; set; }
public bool IsCustomResolutionScaleActive => _resolutionScale == 4;
public bool IsScalingFilterActive => _scalingFilter == (int)Ryujinx.Common.Configuration.ScalingFilter.Fsr;
@@ -170,20 +168,6 @@ namespace Ryujinx.Ava.UI.ViewModels
public string TimeZone { get; set; }
public string ShaderDumpPath { get; set; }
public string CustomThemePath
{
get
{
return _customThemePath;
}
set
{
_customThemePath = value;
OnPropertyChanged();
}
}
public int Language { get; set; }
public int Region { get; set; }
public int FsGlobalAccessLogMode { get; set; }
@@ -426,8 +410,6 @@ namespace Ryujinx.Ava.UI.ViewModels
GameDirectories.Clear();
GameDirectories.AddRange(config.Ui.GameDirs.Value);
EnableCustomTheme = config.Ui.EnableCustomTheme;
CustomThemePath = config.Ui.CustomThemePath;
BaseStyleIndex = config.Ui.BaseStyle == "Light" ? 0 : 1;
// Input
@@ -515,8 +497,6 @@ namespace Ryujinx.Ava.UI.ViewModels
config.Ui.GameDirs.Value = gameDirs;
}
config.Ui.EnableCustomTheme.Value = EnableCustomTheme;
config.Ui.CustomThemePath.Value = CustomThemePath;
config.Ui.BaseStyle.Value = BaseStyleIndex == 0 ? "Light" : "Dark";
// Input

View File

@@ -36,7 +36,7 @@
<CheckBox IsChecked="{Binding ShowConfirmExit}">
<TextBlock Text="{locale:Locale SettingsTabGeneralShowConfirmExitDialog}" />
</CheckBox>
<StackPanel Margin="0, 15, 0, 10" Orientation="Horizontal">
<StackPanel Margin="0, 15, 0, 0" Orientation="Horizontal">
<TextBlock VerticalAlignment="Center"
Text="{locale:Locale SettingsTabGeneralHideCursor}"
Width="150" />
@@ -54,6 +54,22 @@
</ComboBoxItem>
</ComboBox>
</StackPanel>
<StackPanel Margin="0, 15, 0, 10" Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
Text="{locale:Locale SettingsTabGeneralTheme}"
Width="150" />
<ComboBox SelectedIndex="{Binding BaseStyleIndex}"
HorizontalContentAlignment="Left"
MinWidth="100">
<ComboBoxItem>
<TextBlock Text="{locale:Locale SettingsTabGeneralThemeLight}" />
</ComboBoxItem>
<ComboBoxItem>
<TextBlock Text="{locale:Locale SettingsTabGeneralThemeDark}" />
</ComboBoxItem>
</ComboBox>
</StackPanel>
</StackPanel>
<Separator Height="1" />
<TextBlock Classes="h1" Text="{locale:Locale SettingsTabGeneralGameDirectories}" />
@@ -106,64 +122,6 @@
</Button>
</Grid>
</StackPanel>
<Separator Height="1" />
<TextBlock Classes="h1" Text="{locale:Locale SettingsTabGeneralTheme}" />
<Grid Margin="10,0,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<CheckBox
IsChecked="{Binding EnableCustomTheme}"
ToolTip.Tip="{locale:Locale CustomThemeCheckTooltip}">
<TextBlock Text="{locale:Locale SettingsTabGeneralThemeEnableCustomTheme}" />
</CheckBox>
<TextBlock
Grid.Column="0"
Grid.Row="1"
VerticalAlignment="Center"
Margin="0,10,0,0"
Text="{locale:Locale SettingsTabGeneralThemeCustomTheme}"
ToolTip.Tip="{locale:Locale CustomThemePathTooltip}" />
<TextBox
Grid.Row="1"
Grid.Column="1"
Margin="0,10,0,0"
Text="{Binding CustomThemePath}" />
<Button
Grid.Row="1"
Grid.Column="2"
Margin="10,10,0,0"
Click="BrowseTheme"
ToolTip.Tip="{locale:Locale CustomThemeBrowseTooltip}"
Content="{locale:Locale ButtonBrowse}" />
<TextBlock
Grid.Column="0"
Grid.Row="2"
VerticalAlignment="Center"
Margin="0,10,0,0"
Text="{locale:Locale SettingsTabGeneralThemeBaseStyle}" />
<ComboBox
Grid.Column="1"
Grid.Row="2"
VerticalAlignment="Center"
Margin="0,10,0,0"
MinWidth="100"
SelectedIndex="{Binding BaseStyleIndex}">
<ComboBoxItem>
<TextBlock Text="{locale:Locale SettingsTabGeneralThemeBaseStyleLight}" />
</ComboBoxItem>
<ComboBoxItem>
<TextBlock Text="{locale:Locale SettingsTabGeneralThemeBaseStyleDark}" />
</ComboBoxItem>
</ComboBox>
</Grid>
</StackPanel>
</Border>
</ScrollViewer>

View File

@@ -61,29 +61,5 @@ namespace Ryujinx.Ava.UI.Views.Settings
GameList.SelectedIndex = oldIndex < GameList.ItemCount ? oldIndex : 0;
}
}
public async void BrowseTheme(object sender, RoutedEventArgs e)
{
var window = this.GetVisualRoot() as Window;
var result = await window.StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
{
Title = LocaleManager.Instance[LocaleKeys.SettingsSelectThemeFileDialogTitle],
AllowMultiple = false,
FileTypeFilter = new List<FilePickerFileType>
{
new("xml")
{
Patterns = new[] { "*.xaml" },
AppleUniformTypeIdentifiers = new[] { "com.ryujinx.xaml" },
MimeTypes = new[] { "application/xaml+xml" },
},
},
});
if (result.Count > 0)
{
ViewModel.CustomThemePath = result[0].Path.LocalPath;
}
}
}
}

View File

@@ -744,6 +744,17 @@ namespace Ryujinx.Common.Memory
public Span<T> AsSpan() => MemoryMarshal.CreateSpan(ref _e0, Length);
}
public struct Array65<T> : IArray<T> where T : unmanaged
{
T _e0;
Array64<T> _other;
public readonly int Length => 65;
public ref T this[int index] => ref AsSpan()[index];
[Pure]
public Span<T> AsSpan() => MemoryMarshal.CreateSpan(ref _e0, Length);
}
public struct Array73<T> : IArray<T> where T : unmanaged
{
T _e0;

View File

@@ -63,6 +63,18 @@ namespace Ryujinx.Common.Memory
public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
}
[StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
public struct ByteArray3000 : IArray<byte>
{
private const int Size = 3000;
byte _element;
public readonly int Length => Size;
public ref byte this[int index] => ref AsSpan()[index];
public Span<byte> AsSpan() => MemoryMarshal.CreateSpan(ref _element, Size);
}
[StructLayout(LayoutKind.Sequential, Size = Size, Pack = 1)]
public struct ByteArray4096 : IArray<byte>
{

View File

@@ -0,0 +1,395 @@
using Ryujinx.Memory;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Ryujinx.Graphics.Device
{
/// <summary>
/// Device memory manager.
/// </summary>
public class DeviceMemoryManager : IWritableBlock
{
private const int PtLvl0Bits = 10;
private const int PtLvl1Bits = 10;
public const int PtPageBits = 12;
private const ulong PtLvl0Size = 1UL << PtLvl0Bits;
private const ulong PtLvl1Size = 1UL << PtLvl1Bits;
public const ulong PageSize = 1UL << PtPageBits;
private const ulong PtLvl0Mask = PtLvl0Size - 1;
private const ulong PtLvl1Mask = PtLvl1Size - 1;
public const ulong PageMask = PageSize - 1;
private const int PtLvl0Bit = PtPageBits + PtLvl1Bits;
private const int PtLvl1Bit = PtPageBits;
private const int AddressSpaceBits = PtPageBits + PtLvl1Bits + PtLvl0Bits;
public const ulong PteUnmapped = ulong.MaxValue;
private readonly ulong[][] _pageTable;
private readonly IVirtualMemoryManager _physical;
/// <summary>
/// Creates a new instance of the GPU memory manager.
/// </summary>
/// <param name="physicalMemory">Physical memory that this memory manager will map into</param>
public DeviceMemoryManager(IVirtualMemoryManager physicalMemory)
{
_physical = physicalMemory;
_pageTable = new ulong[PtLvl0Size][];
}
/// <summary>
/// Reads data from GPU mapped memory.
/// </summary>
/// <typeparam name="T">Type of the data</typeparam>
/// <param name="va">GPU virtual address where the data is located</param>
/// <returns>The data at the specified memory location</returns>
public T Read<T>(ulong va) where T : unmanaged
{
int size = Unsafe.SizeOf<T>();
if (IsContiguous(va, size))
{
return _physical.Read<T>(Translate(va));
}
else
{
Span<byte> data = new byte[size];
ReadImpl(va, data);
return MemoryMarshal.Cast<byte, T>(data)[0];
}
}
/// <summary>
/// Gets a read-only span of data from GPU mapped memory.
/// </summary>
/// <param name="va">GPU virtual address where the data is located</param>
/// <param name="size">Size of the data</param>
/// <returns>The span of the data at the specified memory location</returns>
public ReadOnlySpan<byte> GetSpan(ulong va, int size)
{
if (IsContiguous(va, size))
{
return _physical.GetSpan(Translate(va), size);
}
else
{
Span<byte> data = new byte[size];
ReadImpl(va, data);
return data;
}
}
/// <summary>
/// Reads data from a possibly non-contiguous region of GPU mapped memory.
/// </summary>
/// <param name="va">GPU virtual address of the data</param>
/// <param name="data">Span to write the read data into</param>
private void ReadImpl(ulong va, Span<byte> data)
{
if (data.Length == 0)
{
return;
}
int offset = 0, size;
if ((va & PageMask) != 0)
{
ulong pa = Translate(va);
size = Math.Min(data.Length, (int)PageSize - (int)(va & PageMask));
if (pa != PteUnmapped && _physical.IsMapped(pa))
{
_physical.GetSpan(pa, size).CopyTo(data[..size]);
}
offset += size;
}
for (; offset < data.Length; offset += size)
{
ulong pa = Translate(va + (ulong)offset);
size = Math.Min(data.Length - offset, (int)PageSize);
if (pa != PteUnmapped && _physical.IsMapped(pa))
{
_physical.GetSpan(pa, size).CopyTo(data.Slice(offset, size));
}
}
}
/// <summary>
/// Gets a writable region from GPU mapped memory.
/// </summary>
/// <param name="va">Start address of the range</param>
/// <param name="size">Size in bytes to be range</param>
/// <returns>A writable region with the data at the specified memory location</returns>
public WritableRegion GetWritableRegion(ulong va, int size)
{
if (IsContiguous(va, size))
{
return _physical.GetWritableRegion(Translate(va), size, tracked: true);
}
else
{
Memory<byte> memory = new byte[size];
GetSpan(va, size).CopyTo(memory.Span);
return new WritableRegion(this, va, memory, tracked: true);
}
}
/// <summary>
/// Writes data to GPU mapped memory.
/// </summary>
/// <typeparam name="T">Type of the data</typeparam>
/// <param name="va">GPU virtual address to write the value into</param>
/// <param name="value">The value to be written</param>
public void Write<T>(ulong va, T value) where T : unmanaged
{
Write(va, MemoryMarshal.Cast<T, byte>(MemoryMarshal.CreateSpan(ref value, 1)));
}
/// <summary>
/// Writes data to GPU mapped memory.
/// </summary>
/// <param name="va">GPU virtual address to write the data into</param>
/// <param name="data">The data to be written</param>
public void Write(ulong va, ReadOnlySpan<byte> data)
{
if (IsContiguous(va, data.Length))
{
_physical.Write(Translate(va), data);
}
else
{
int offset = 0, size;
if ((va & PageMask) != 0)
{
ulong pa = Translate(va);
size = Math.Min(data.Length, (int)PageSize - (int)(va & PageMask));
if (pa != PteUnmapped && _physical.IsMapped(pa))
{
_physical.Write(pa, data[..size]);
}
offset += size;
}
for (; offset < data.Length; offset += size)
{
ulong pa = Translate(va + (ulong)offset);
size = Math.Min(data.Length - offset, (int)PageSize);
if (pa != PteUnmapped && _physical.IsMapped(pa))
{
_physical.Write(pa, data.Slice(offset, size));
}
}
}
}
/// <summary>
/// Writes data to GPU mapped memory without write tracking.
/// </summary>
/// <param name="va">GPU virtual address to write the data into</param>
/// <param name="data">The data to be written</param>
public void WriteUntracked(ulong va, ReadOnlySpan<byte> data)
{
throw new NotSupportedException();
}
/// <summary>
/// Maps a given range of pages to the specified CPU virtual address.
/// </summary>
/// <remarks>
/// All addresses and sizes must be page aligned.
/// </remarks>
/// <param name="pa">CPU virtual address to map into</param>
/// <param name="va">GPU virtual address to be mapped</param>
/// <param name="kind">Kind of the resource located at the mapping</param>
public void Map(ulong pa, ulong va, ulong size)
{
lock (_pageTable)
{
for (ulong offset = 0; offset < size; offset += PageSize)
{
SetPte(va + offset, PackPte(pa + offset));
}
}
}
/// <summary>
/// Unmaps a given range of pages at the specified GPU virtual memory region.
/// </summary>
/// <param name="va">GPU virtual address to unmap</param>
/// <param name="size">Size in bytes of the region being unmapped</param>
public void Unmap(ulong va, ulong size)
{
lock (_pageTable)
{
for (ulong offset = 0; offset < size; offset += PageSize)
{
SetPte(va + offset, PteUnmapped);
}
}
}
/// <summary>
/// Checks if a region of GPU mapped memory is contiguous.
/// </summary>
/// <param name="va">GPU virtual address of the region</param>
/// <param name="size">Size of the region</param>
/// <returns>True if the region is contiguous, false otherwise</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private bool IsContiguous(ulong va, int size)
{
if (!ValidateAddress(va) || GetPte(va) == PteUnmapped)
{
return false;
}
ulong endVa = (va + (ulong)size + PageMask) & ~PageMask;
va &= ~PageMask;
int pages = (int)((endVa - va) / PageSize);
for (int page = 0; page < pages - 1; page++)
{
if (!ValidateAddress(va + PageSize) || GetPte(va + PageSize) == PteUnmapped)
{
return false;
}
if (Translate(va) + PageSize != Translate(va + PageSize))
{
return false;
}
va += PageSize;
}
return true;
}
/// <summary>
/// Validates a GPU virtual address.
/// </summary>
/// <param name="va">Address to validate</param>
/// <returns>True if the address is valid, false otherwise</returns>
private static bool ValidateAddress(ulong va)
{
return va < (1UL << AddressSpaceBits);
}
/// <summary>
/// Checks if a given page is mapped.
/// </summary>
/// <param name="va">GPU virtual address of the page to check</param>
/// <returns>True if the page is mapped, false otherwise</returns>
public bool IsMapped(ulong va)
{
return Translate(va) != PteUnmapped;
}
/// <summary>
/// Translates a GPU virtual address to a CPU virtual address.
/// </summary>
/// <param name="va">GPU virtual address to be translated</param>
/// <returns>CPU virtual address, or <see cref="PteUnmapped"/> if unmapped</returns>
public ulong Translate(ulong va)
{
if (!ValidateAddress(va))
{
return PteUnmapped;
}
ulong pte = GetPte(va);
if (pte == PteUnmapped)
{
return PteUnmapped;
}
return UnpackPaFromPte(pte) + (va & PageMask);
}
/// <summary>
/// Gets the Page Table entry for a given GPU virtual address.
/// </summary>
/// <param name="va">GPU virtual address</param>
/// <returns>Page table entry (CPU virtual address)</returns>
private ulong GetPte(ulong va)
{
ulong l0 = (va >> PtLvl0Bit) & PtLvl0Mask;
ulong l1 = (va >> PtLvl1Bit) & PtLvl1Mask;
if (_pageTable[l0] == null)
{
return PteUnmapped;
}
return _pageTable[l0][l1];
}
/// <summary>
/// Sets a Page Table entry at a given GPU virtual address.
/// </summary>
/// <param name="va">GPU virtual address</param>
/// <param name="pte">Page table entry (CPU virtual address)</param>
private void SetPte(ulong va, ulong pte)
{
ulong l0 = (va >> PtLvl0Bit) & PtLvl0Mask;
ulong l1 = (va >> PtLvl1Bit) & PtLvl1Mask;
if (_pageTable[l0] == null)
{
_pageTable[l0] = new ulong[PtLvl1Size];
for (ulong index = 0; index < PtLvl1Size; index++)
{
_pageTable[l0][index] = PteUnmapped;
}
}
_pageTable[l0][l1] = pte;
}
/// <summary>
/// Creates a page table entry from a physical address and kind.
/// </summary>
/// <param name="pa">Physical address</param>
/// <returns>Page table entry</returns>
private static ulong PackPte(ulong pa)
{
return pa;
}
/// <summary>
/// Unpacks physical address from a page table entry.
/// </summary>
/// <param name="pte">Page table entry</param>
/// <returns>Physical address</returns>
private static ulong UnpackPaFromPte(ulong pte)
{
return pte;
}
}
}

View File

@@ -0,0 +1,39 @@
using Ryujinx.Common.Logging;
using System;
using System.Threading;
namespace Ryujinx.Graphics.Device
{
/// <summary>
/// Synchronization manager interface.
/// </summary>
public interface ISynchronizationManager
{
/// <summary>
/// Increment the value of a syncpoint with a given id.
/// </summary>
/// <param name="id">The id of the syncpoint</param>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown when id >= MaxHardwareSyncpoints</exception>
/// <returns>The incremented value of the syncpoint</returns>
uint IncrementSyncpoint(uint id);
/// <summary>
/// Get the value of a syncpoint with a given id.
/// </summary>
/// <param name="id">The id of the syncpoint</param>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown when id >= MaxHardwareSyncpoints</exception>
/// <returns>The value of the syncpoint</returns>
uint GetSyncpointValue(uint id);
/// <summary>
/// Wait on a syncpoint with a given id at a target threshold.
/// The callback will be called once the threshold is reached and will automatically be unregistered.
/// </summary>
/// <param name="id">The id of the syncpoint</param>
/// <param name="threshold">The target threshold</param>
/// <param name="timeout">The timeout</param>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown when id >= MaxHardwareSyncpoints</exception>
/// <returns>True if timed out</returns>
bool WaitOnSyncpoint(uint id, uint threshold, TimeSpan timeout);
}
}

View File

@@ -4,4 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Ryujinx.Memory\Ryujinx.Memory.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,4 +1,5 @@
using Ryujinx.Common;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.GPFifo;
using Ryujinx.Graphics.Gpu.Memory;
@@ -163,6 +164,22 @@ namespace Ryujinx.Graphics.Gpu
return new MemoryManager(physicalMemory);
}
/// <summary>
/// Creates a new device memory manager.
/// </summary>
/// <param name="pid">ID of the process that owns the memory manager</param>
/// <returns>The memory manager</returns>
/// <exception cref="ArgumentException">Thrown when <paramref name="pid"/> is invalid</exception>
public DeviceMemoryManager CreateDeviceMemoryManager(ulong pid)
{
if (!PhysicalMemoryRegistry.TryGetValue(pid, out var physicalMemory))
{
throw new ArgumentException("The PID is invalid or the process was not registered", nameof(pid));
}
return physicalMemory.CreateDeviceMemoryManager();
}
/// <summary>
/// Registers virtual memory used by a process for GPU memory access, caching and read/write tracking.
/// </summary>

View File

@@ -790,8 +790,12 @@ namespace Ryujinx.Graphics.Gpu.Image
texture = new Texture(_context, _physicalMemory, info, sizeInfo, range.Value, scaleMode);
// If the new texture is larger than the existing one, we need to fill the remaining space with CPU data,
// otherwise we only need the data that is copied from the existing texture, without loading the CPU data.
bool updateNewTexture = texture.Width > overlap.Width || texture.Height > overlap.Height;
texture.InitializeGroup(true, true, new List<TextureIncompatibleOverlap>());
texture.InitializeData(false, false);
texture.InitializeData(false, updateNewTexture);
overlap.SynchronizeMemory();
overlap.CreateCopyDependency(texture, oInfo.FirstLayer, oInfo.FirstLevel, true);

View File

@@ -329,49 +329,6 @@ namespace Ryujinx.Graphics.Gpu.Memory
}
}
/// <summary>
/// Writes data to GPU mapped memory, stopping at the first unmapped page at the memory region, if any.
/// </summary>
/// <param name="va">GPU virtual address to write the data into</param>
/// <param name="data">The data to be written</param>
public void WriteMapped(ulong va, ReadOnlySpan<byte> data)
{
if (IsContiguous(va, data.Length))
{
Physical.Write(Translate(va), data);
}
else
{
int offset = 0, size;
if ((va & PageMask) != 0)
{
ulong pa = Translate(va);
size = Math.Min(data.Length, (int)PageSize - (int)(va & PageMask));
if (pa != PteUnmapped && Physical.IsMapped(pa))
{
Physical.Write(pa, data[..size]);
}
offset += size;
}
for (; offset < data.Length; offset += size)
{
ulong pa = Translate(va + (ulong)offset);
size = Math.Min(data.Length - offset, (int)PageSize);
if (pa != PteUnmapped && Physical.IsMapped(pa))
{
Physical.Write(pa, data.Slice(offset, size));
}
}
}
}
/// <summary>
/// Runs remap actions that are added to an unmap event.
/// These must run after the mapping completes.

View File

@@ -1,4 +1,5 @@
using Ryujinx.Cpu;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.Shader;
using Ryujinx.Memory;
@@ -82,6 +83,15 @@ namespace Ryujinx.Graphics.Gpu.Memory
}
}
/// <summary>
/// Creates a new device memory manager.
/// </summary>
/// <returns>The memory manager</returns>
public DeviceMemoryManager CreateDeviceMemoryManager()
{
return new DeviceMemoryManager(_cpuMemory);
}
/// <summary>
/// Gets a host pointer for a given range of application memory.
/// If the memory region is not a single contiguous block, this method returns 0.

View File

@@ -1,4 +1,5 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Device;
using System;
using System.Threading;
@@ -7,7 +8,7 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
/// <summary>
/// GPU synchronization manager.
/// </summary>
public class SynchronizationManager
public class SynchronizationManager : ISynchronizationManager
{
/// <summary>
/// The maximum number of syncpoints supported by the GM20B.
@@ -29,12 +30,7 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
}
}
/// <summary>
/// Increment the value of a syncpoint with a given id.
/// </summary>
/// <param name="id">The id of the syncpoint</param>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown when id >= MaxHardwareSyncpoints</exception>
/// <returns>The incremented value of the syncpoint</returns>
/// <inheritdoc/>
public uint IncrementSyncpoint(uint id)
{
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(id, (uint)MaxHardwareSyncpoints);
@@ -42,12 +38,7 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
return _syncpoints[id].Increment();
}
/// <summary>
/// Get the value of a syncpoint with a given id.
/// </summary>
/// <param name="id">The id of the syncpoint</param>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown when id >= MaxHardwareSyncpoints</exception>
/// <returns>The value of the syncpoint</returns>
/// <inheritdoc/>
public uint GetSyncpointValue(uint id)
{
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(id, (uint)MaxHardwareSyncpoints);
@@ -84,15 +75,7 @@ namespace Ryujinx.Graphics.Gpu.Synchronization
_syncpoints[id].UnregisterCallback(waiterInformation);
}
/// <summary>
/// Wait on a syncpoint with a given id at a target threshold.
/// The callback will be called once the threshold is reached and will automatically be unregistered.
/// </summary>
/// <param name="id">The id of the syncpoint</param>
/// <param name="threshold">The target threshold</param>
/// <param name="timeout">The timeout</param>
/// <exception cref="System.ArgumentOutOfRangeException">Thrown when id >= MaxHardwareSyncpoints</exception>
/// <returns>True if timed out</returns>
/// <inheritdoc/>
public bool WaitOnSyncpoint(uint id, uint threshold, TimeSpan timeout)
{
ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual(id, (uint)MaxHardwareSyncpoints);

View File

@@ -1,5 +1,4 @@
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Synchronization;
using System.Collections.Generic;
using System.Threading;
@@ -7,10 +6,10 @@ namespace Ryujinx.Graphics.Host1x
{
public class Host1xClass : IDeviceState
{
private readonly SynchronizationManager _syncMgr;
private readonly ISynchronizationManager _syncMgr;
private readonly DeviceState<Host1xClassRegisters> _state;
public Host1xClass(SynchronizationManager syncMgr)
public Host1xClass(ISynchronizationManager syncMgr)
{
_syncMgr = syncMgr;
_state = new DeviceState<Host1xClassRegisters>(new Dictionary<string, RwCallback>

View File

@@ -1,7 +1,6 @@
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Synchronization;
using System;
using System.Numerics;
@@ -35,7 +34,7 @@ namespace Ryujinx.Graphics.Host1x
private int _mask;
private bool _incrementing;
public Host1xDevice(SynchronizationManager syncMgr)
public Host1xDevice(ISynchronizationManager syncMgr)
{
_syncptIncrMgr = new SyncptIncrManager(syncMgr);
_commandQueue = new AsyncWorkQueue<Command>(Process, "Ryujinx.Host1xProcessor");

View File

@@ -6,7 +6,6 @@
<ItemGroup>
<ProjectReference Include="..\Ryujinx.Graphics.Device\Ryujinx.Graphics.Device.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Gpu\Ryujinx.Graphics.Gpu.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,11 +1,11 @@
using Ryujinx.Graphics.Gpu.Synchronization;
using Ryujinx.Graphics.Device;
using System.Collections.Generic;
namespace Ryujinx.Graphics.Host1x
{
class SyncptIncrManager
{
private readonly SynchronizationManager _syncMgr;
private readonly ISynchronizationManager _syncMgr;
private readonly struct SyncptIncr
{
@@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.Host1x
private uint _currentId;
public SyncptIncrManager(SynchronizationManager syncMgr)
public SyncptIncrManager(ISynchronizationManager syncMgr)
{
_syncMgr = syncMgr;
}

View File

@@ -12,10 +12,10 @@ namespace Ryujinx.Graphics.Nvdec
public static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state)
{
PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetDrvPicSetupOffset);
PictureInfo pictureInfo = rm.MemoryManager.DeviceRead<PictureInfo>(state.SetDrvPicSetupOffset);
H264PictureInfo info = pictureInfo.Convert();
ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.BitstreamSize);
ReadOnlySpan<byte> bitstream = rm.MemoryManager.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.BitstreamSize);
int width = (int)pictureInfo.PicWidthInMbs * MbSizeInPixels;
int height = (int)pictureInfo.PicHeightInMbs * MbSizeInPixels;
@@ -34,7 +34,7 @@ namespace Ryujinx.Graphics.Nvdec
if (outputSurface.Field == FrameField.Progressive)
{
SurfaceWriter.Write(
rm.Gmm,
rm.MemoryManager,
outputSurface,
lumaOffset + pictureInfo.LumaFrameOffset,
chromaOffset + pictureInfo.ChromaFrameOffset);
@@ -42,7 +42,7 @@ namespace Ryujinx.Graphics.Nvdec
else
{
SurfaceWriter.WriteInterlaced(
rm.Gmm,
rm.MemoryManager,
outputSurface,
lumaOffset + pictureInfo.LumaTopFieldOffset,
chromaOffset + pictureInfo.ChromaTopFieldOffset,

View File

@@ -1,4 +1,4 @@
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Video;
using System;
using System.Diagnostics;
@@ -27,11 +27,11 @@ namespace Ryujinx.Graphics.Nvdec.Image
private readonly CacheItem[] _pool = new CacheItem[MaxItems];
private readonly MemoryManager _gmm;
private readonly DeviceMemoryManager _mm;
public SurfaceCache(MemoryManager gmm)
public SurfaceCache(DeviceMemoryManager mm)
{
_gmm = gmm;
_mm = mm;
}
public ISurface Get(IDecoder decoder, uint lumaOffset, uint chromaOffset, int width, int height)
@@ -77,7 +77,7 @@ namespace Ryujinx.Graphics.Nvdec.Image
if ((lumaOffset | chromaOffset) != 0)
{
SurfaceReader.Read(_gmm, surface, lumaOffset, chromaOffset);
SurfaceReader.Read(_mm, surface, lumaOffset, chromaOffset);
}
MoveToFront(i);
@@ -100,7 +100,7 @@ namespace Ryujinx.Graphics.Nvdec.Image
if ((lumaOffset | chromaOffset) != 0)
{
SurfaceReader.Read(_gmm, surface, lumaOffset, chromaOffset);
SurfaceReader.Read(_mm, surface, lumaOffset, chromaOffset);
}
MoveToFront(MaxItems - 1);

View File

@@ -1,5 +1,5 @@
using Ryujinx.Common;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Texture;
using Ryujinx.Graphics.Video;
using System;
@@ -11,13 +11,13 @@ namespace Ryujinx.Graphics.Nvdec.Image
{
static class SurfaceReader
{
public static void Read(MemoryManager gmm, ISurface surface, uint lumaOffset, uint chromaOffset)
public static void Read(DeviceMemoryManager mm, ISurface surface, uint lumaOffset, uint chromaOffset)
{
int width = surface.Width;
int height = surface.Height;
int stride = surface.Stride;
ReadOnlySpan<byte> luma = gmm.DeviceGetSpan(lumaOffset, GetBlockLinearSize(width, height, 1));
ReadOnlySpan<byte> luma = mm.DeviceGetSpan(lumaOffset, GetBlockLinearSize(width, height, 1));
ReadLuma(surface.YPlane.AsSpan(), luma, stride, width, height);
@@ -25,7 +25,7 @@ namespace Ryujinx.Graphics.Nvdec.Image
int uvHeight = surface.UvHeight;
int uvStride = surface.UvStride;
ReadOnlySpan<byte> chroma = gmm.DeviceGetSpan(chromaOffset, GetBlockLinearSize(uvWidth, uvHeight, 2));
ReadOnlySpan<byte> chroma = mm.DeviceGetSpan(chromaOffset, GetBlockLinearSize(uvWidth, uvHeight, 2));
ReadChroma(surface.UPlane.AsSpan(), surface.VPlane.AsSpan(), chroma, uvStride, uvWidth, uvHeight);
}

View File

@@ -1,5 +1,5 @@
using Ryujinx.Common;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Texture;
using Ryujinx.Graphics.Video;
using System;
@@ -12,11 +12,11 @@ namespace Ryujinx.Graphics.Nvdec.Image
{
static class SurfaceWriter
{
public static void Write(MemoryManager gmm, ISurface surface, uint lumaOffset, uint chromaOffset)
public static void Write(DeviceMemoryManager mm, ISurface surface, uint lumaOffset, uint chromaOffset)
{
int lumaSize = GetBlockLinearSize(surface.Width, surface.Height, 1);
using var luma = gmm.GetWritableRegion(ExtendOffset(lumaOffset), lumaSize);
using var luma = mm.GetWritableRegion(ExtendOffset(lumaOffset), lumaSize);
WriteLuma(
luma.Memory.Span,
@@ -27,7 +27,7 @@ namespace Ryujinx.Graphics.Nvdec.Image
int chromaSize = GetBlockLinearSize(surface.UvWidth, surface.UvHeight, 2);
using var chroma = gmm.GetWritableRegion(ExtendOffset(chromaOffset), chromaSize);
using var chroma = mm.GetWritableRegion(ExtendOffset(chromaOffset), chromaSize);
WriteChroma(
chroma.Memory.Span,
@@ -39,7 +39,7 @@ namespace Ryujinx.Graphics.Nvdec.Image
}
public static void WriteInterlaced(
MemoryManager gmm,
DeviceMemoryManager mm,
ISurface surface,
uint lumaTopOffset,
uint chromaTopOffset,
@@ -48,8 +48,8 @@ namespace Ryujinx.Graphics.Nvdec.Image
{
int lumaSize = GetBlockLinearSize(surface.Width, surface.Height / 2, 1);
using var lumaTop = gmm.GetWritableRegion(ExtendOffset(lumaTopOffset), lumaSize);
using var lumaBottom = gmm.GetWritableRegion(ExtendOffset(lumaBottomOffset), lumaSize);
using var lumaTop = mm.GetWritableRegion(ExtendOffset(lumaTopOffset), lumaSize);
using var lumaBottom = mm.GetWritableRegion(ExtendOffset(lumaBottomOffset), lumaSize);
WriteLuma(
lumaTop.Memory.Span,
@@ -67,8 +67,8 @@ namespace Ryujinx.Graphics.Nvdec.Image
int chromaSize = GetBlockLinearSize(surface.UvWidth, surface.UvHeight / 2, 2);
using var chromaTop = gmm.GetWritableRegion(ExtendOffset(chromaTopOffset), chromaSize);
using var chromaBottom = gmm.GetWritableRegion(ExtendOffset(chromaBottomOffset), chromaSize);
using var chromaTop = mm.GetWritableRegion(ExtendOffset(chromaTopOffset), chromaSize);
using var chromaBottom = mm.GetWritableRegion(ExtendOffset(chromaBottomOffset), chromaSize);
WriteChroma(
chromaTop.Memory.Span,

View File

@@ -1,23 +1,23 @@
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Device;
using System;
namespace Ryujinx.Graphics.Nvdec
{
static class MemoryExtensions
{
public static T DeviceRead<T>(this MemoryManager gmm, uint offset) where T : unmanaged
public static T DeviceRead<T>(this DeviceMemoryManager gmm, uint offset) where T : unmanaged
{
return gmm.Read<T>((ulong)offset << 8);
return gmm.Read<T>(ExtendOffset(offset));
}
public static ReadOnlySpan<byte> DeviceGetSpan(this MemoryManager gmm, uint offset, int size)
public static ReadOnlySpan<byte> DeviceGetSpan(this DeviceMemoryManager gmm, uint offset, int size)
{
return gmm.GetSpan((ulong)offset << 8, size);
return gmm.GetSpan(ExtendOffset(offset), size);
}
public static void DeviceWrite(this MemoryManager gmm, uint offset, ReadOnlySpan<byte> data)
public static void DeviceWrite(this DeviceMemoryManager gmm, uint offset, ReadOnlySpan<byte> data)
{
gmm.Write((ulong)offset << 8, data);
gmm.Write(ExtendOffset(offset), data);
}
public static ulong ExtendOffset(uint offset)

View File

@@ -1,6 +1,5 @@
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Nvdec.Image;
using System.Collections.Concurrent;
using System.Collections.Generic;
@@ -17,9 +16,9 @@ namespace Ryujinx.Graphics.Nvdec
private readonly ConcurrentDictionary<long, NvdecDecoderContext> _contexts;
private NvdecDecoderContext _currentContext;
public NvdecDevice(MemoryManager gmm)
public NvdecDevice(DeviceMemoryManager mm)
{
_rm = new ResourceManager(gmm, new SurfaceCache(gmm));
_rm = new ResourceManager(mm, new SurfaceCache(mm));
_state = new DeviceState<NvdecRegisters>(new Dictionary<string, RwCallback>
{
{ nameof(NvdecRegisters.Execute), new RwCallback(Execute, null) },

View File

@@ -1,16 +1,16 @@
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Nvdec.Image;
namespace Ryujinx.Graphics.Nvdec
{
readonly struct ResourceManager
{
public MemoryManager Gmm { get; }
public DeviceMemoryManager MemoryManager { get; }
public SurfaceCache Cache { get; }
public ResourceManager(MemoryManager gmm, SurfaceCache cache)
public ResourceManager(DeviceMemoryManager mm, SurfaceCache cache)
{
Gmm = gmm;
MemoryManager = mm;
Cache = cache;
}
}

View File

@@ -8,7 +8,6 @@
<ItemGroup>
<ProjectReference Include="..\Ryujinx.Common\Ryujinx.Common.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Device\Ryujinx.Graphics.Device.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Gpu\Ryujinx.Graphics.Gpu.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Nvdec.FFmpeg\Ryujinx.Graphics.Nvdec.FFmpeg.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Nvdec.Vp9\Ryujinx.Graphics.Nvdec.Vp9.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Texture\Ryujinx.Graphics.Texture.csproj" />

View File

@@ -10,8 +10,8 @@ namespace Ryujinx.Graphics.Nvdec
{
public static void Decode(NvdecDecoderContext context, ResourceManager rm, ref NvdecRegisters state)
{
PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetDrvPicSetupOffset);
ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.VLDBufferSize);
PictureInfo pictureInfo = rm.MemoryManager.DeviceRead<PictureInfo>(state.SetDrvPicSetupOffset);
ReadOnlySpan<byte> bitstream = rm.MemoryManager.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.VLDBufferSize);
Decoder decoder = context.GetVp8Decoder();
@@ -24,7 +24,7 @@ namespace Ryujinx.Graphics.Nvdec
if (decoder.Decode(ref info, outputSurface, bitstream))
{
SurfaceWriter.Write(rm.Gmm, outputSurface, lumaOffset, chromaOffset);
SurfaceWriter.Write(rm.MemoryManager, outputSurface, lumaOffset, chromaOffset);
}
rm.Cache.Put(outputSurface);

View File

@@ -1,5 +1,5 @@
using Ryujinx.Common;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Nvdec.Image;
using Ryujinx.Graphics.Nvdec.Types.Vp9;
using Ryujinx.Graphics.Nvdec.Vp9;
@@ -17,8 +17,8 @@ namespace Ryujinx.Graphics.Nvdec
public unsafe static void Decode(ResourceManager rm, ref NvdecRegisters state)
{
PictureInfo pictureInfo = rm.Gmm.DeviceRead<PictureInfo>(state.SetDrvPicSetupOffset);
EntropyProbs entropy = rm.Gmm.DeviceRead<EntropyProbs>(state.Vp9SetProbTabBufOffset);
PictureInfo pictureInfo = rm.MemoryManager.DeviceRead<PictureInfo>(state.SetDrvPicSetupOffset);
EntropyProbs entropy = rm.MemoryManager.DeviceRead<EntropyProbs>(state.Vp9SetProbTabBufOffset);
ISurface Rent(uint lumaOffset, uint chromaOffset, FrameSize size)
{
@@ -38,19 +38,19 @@ namespace Ryujinx.Graphics.Nvdec
entropy.Convert(ref info.Entropy);
ReadOnlySpan<byte> bitstream = rm.Gmm.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.BitstreamSize);
ReadOnlySpan<byte> bitstream = rm.MemoryManager.DeviceGetSpan(state.SetInBufBaseOffset, (int)pictureInfo.BitstreamSize);
ReadOnlySpan<Vp9MvRef> mvsIn = ReadOnlySpan<Vp9MvRef>.Empty;
if (info.UsePrevInFindMvRefs)
{
mvsIn = GetMvsInput(rm.Gmm, pictureInfo.CurrentFrameSize, state.Vp9SetColMvReadBufOffset);
mvsIn = GetMvsInput(rm.MemoryManager, pictureInfo.CurrentFrameSize, state.Vp9SetColMvReadBufOffset);
}
int miCols = BitUtils.DivRoundUp(pictureInfo.CurrentFrameSize.Width, 8);
int miRows = BitUtils.DivRoundUp(pictureInfo.CurrentFrameSize.Height, 8);
using var mvsRegion = rm.Gmm.GetWritableRegion(ExtendOffset(state.Vp9SetColMvWriteBufOffset), miRows * miCols * 16);
using var mvsRegion = rm.MemoryManager.GetWritableRegion(ExtendOffset(state.Vp9SetColMvWriteBufOffset), miRows * miCols * 16);
Span<Vp9MvRef> mvsOut = MemoryMarshal.Cast<byte, Vp9MvRef>(mvsRegion.Memory.Span);
@@ -59,10 +59,10 @@ namespace Ryujinx.Graphics.Nvdec
if (_decoder.Decode(ref info, currentSurface, bitstream, mvsIn, mvsOut))
{
SurfaceWriter.Write(rm.Gmm, currentSurface, lumaOffset, chromaOffset);
SurfaceWriter.Write(rm.MemoryManager, currentSurface, lumaOffset, chromaOffset);
}
WriteBackwardUpdates(rm.Gmm, state.Vp9SetCtxCounterBufOffset, ref info.BackwardUpdateCounts);
WriteBackwardUpdates(rm.MemoryManager, state.Vp9SetCtxCounterBufOffset, ref info.BackwardUpdateCounts);
rm.Cache.Put(lastSurface);
rm.Cache.Put(goldenSurface);
@@ -70,17 +70,17 @@ namespace Ryujinx.Graphics.Nvdec
rm.Cache.Put(currentSurface);
}
private static ReadOnlySpan<Vp9MvRef> GetMvsInput(MemoryManager gmm, FrameSize size, uint offset)
private static ReadOnlySpan<Vp9MvRef> GetMvsInput(DeviceMemoryManager mm, FrameSize size, uint offset)
{
int miCols = BitUtils.DivRoundUp(size.Width, 8);
int miRows = BitUtils.DivRoundUp(size.Height, 8);
return MemoryMarshal.Cast<byte, Vp9MvRef>(gmm.DeviceGetSpan(offset, miRows * miCols * 16));
return MemoryMarshal.Cast<byte, Vp9MvRef>(mm.DeviceGetSpan(offset, miRows * miCols * 16));
}
private static void WriteBackwardUpdates(MemoryManager gmm, uint offset, ref Vp9BackwardUpdates counts)
private static void WriteBackwardUpdates(DeviceMemoryManager mm, uint offset, ref Vp9BackwardUpdates counts)
{
using var backwardUpdatesRegion = gmm.GetWritableRegion(ExtendOffset(offset), Unsafe.SizeOf<BackwardUpdates>());
using var backwardUpdatesRegion = mm.GetWritableRegion(ExtendOffset(offset), Unsafe.SizeOf<BackwardUpdates>());
ref var backwardUpdates = ref MemoryMarshal.Cast<byte, BackwardUpdates>(backwardUpdatesRegion.Memory.Span)[0];

View File

@@ -454,7 +454,7 @@ namespace Ryujinx.Graphics.Vic.Image
int srcStride = GetPitch(width, bytesPerPixel);
int inSize = srcStride * height;
ReadOnlySpan<byte> src = rm.Gmm.GetSpan(ExtendOffset(offset), inSize);
ReadOnlySpan<byte> src = rm.MemoryManager.GetSpan(ExtendOffset(offset), inSize);
int outSize = dstStride * height;
int bufferIndex = rm.BufferPool.RentMinimum(outSize, out byte[] buffer);
@@ -481,7 +481,7 @@ namespace Ryujinx.Graphics.Vic.Image
{
int inSize = GetBlockLinearSize(width, height, bytesPerPixel, gobBlocksInY);
ReadOnlySpan<byte> src = rm.Gmm.GetSpan(ExtendOffset(offset), inSize);
ReadOnlySpan<byte> src = rm.MemoryManager.GetSpan(ExtendOffset(offset), inSize);
int outSize = dstStride * height;
int bufferIndex = rm.BufferPool.RentMinimum(outSize, out byte[] buffer);

View File

@@ -636,7 +636,7 @@ namespace Ryujinx.Graphics.Vic.Image
{
if (linear)
{
rm.Gmm.WriteMapped(ExtendOffset(offset), src);
rm.MemoryManager.Write(ExtendOffset(offset), src);
return;
}
@@ -659,7 +659,7 @@ namespace Ryujinx.Graphics.Vic.Image
LayoutConverter.ConvertLinearToBlockLinear(dst, width, height, dstStride, bytesPerPixel, gobBlocksInY, src);
rm.Gmm.WriteMapped(ExtendOffset(offset), dst);
rm.MemoryManager.Write(ExtendOffset(offset), dst);
rm.BufferPool.Return(dstIndex);
}

View File

@@ -1,17 +1,17 @@
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Vic.Image;
namespace Ryujinx.Graphics.Vic
{
readonly struct ResourceManager
{
public MemoryManager Gmm { get; }
public DeviceMemoryManager MemoryManager { get; }
public BufferPool<Pixel> SurfacePool { get; }
public BufferPool<byte> BufferPool { get; }
public ResourceManager(MemoryManager gmm, BufferPool<Pixel> surfacePool, BufferPool<byte> bufferPool)
public ResourceManager(DeviceMemoryManager mm, BufferPool<Pixel> surfacePool, BufferPool<byte> bufferPool)
{
Gmm = gmm;
MemoryManager = mm;
SurfacePool = surfacePool;
BufferPool = bufferPool;
}

View File

@@ -8,7 +8,6 @@
<ItemGroup>
<ProjectReference Include="..\Ryujinx.Common\Ryujinx.Common.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Device\Ryujinx.Graphics.Device.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Gpu\Ryujinx.Graphics.Gpu.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Host1x\Ryujinx.Graphics.Host1x.csproj" />
<ProjectReference Include="..\Ryujinx.Graphics.Texture\Ryujinx.Graphics.Texture.csproj" />
</ItemGroup>

View File

@@ -1,5 +1,4 @@
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Vic.Image;
using Ryujinx.Graphics.Vic.Types;
using System;
@@ -9,14 +8,14 @@ namespace Ryujinx.Graphics.Vic
{
public class VicDevice : IDeviceState
{
private readonly MemoryManager _gmm;
private readonly DeviceMemoryManager _mm;
private readonly ResourceManager _rm;
private readonly DeviceState<VicRegisters> _state;
public VicDevice(MemoryManager gmm)
public VicDevice(DeviceMemoryManager mm)
{
_gmm = gmm;
_rm = new ResourceManager(gmm, new BufferPool<Pixel>(), new BufferPool<byte>());
_mm = mm;
_rm = new ResourceManager(mm, new BufferPool<Pixel>(), new BufferPool<byte>());
_state = new DeviceState<VicRegisters>(new Dictionary<string, RwCallback>
{
{ nameof(VicRegisters.Execute), new RwCallback(Execute, null) },
@@ -68,7 +67,7 @@ namespace Ryujinx.Graphics.Vic
private T ReadIndirect<T>(uint offset) where T : unmanaged
{
return _gmm.Read<T>((ulong)offset << 8);
return _mm.Read<T>((ulong)offset << 8);
}
}
}

View File

@@ -4,6 +4,7 @@ using Silk.NET.Vulkan;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using VkBuffer = Silk.NET.Vulkan.Buffer;
using VkFormat = Silk.NET.Vulkan.Format;
@@ -384,7 +385,7 @@ namespace Ryujinx.Graphics.Vulkan
var baseData = new Span<byte>((void*)(_map + offset), size);
var modData = _pendingData.AsSpan(offset, size);
StagingBufferReserved? newMirror = _gd.BufferManager.StagingBuffer.TryReserveData(cbs, size, (int)_gd.Capabilities.MinResourceAlignment);
StagingBufferReserved? newMirror = _gd.BufferManager.StagingBuffer.TryReserveData(cbs, size);
if (newMirror != null)
{
@@ -838,6 +839,11 @@ namespace Ryujinx.Graphics.Vulkan
}
}
public unsafe void SetDataUnchecked<T>(int offset, ReadOnlySpan<T> data) where T : unmanaged
{
SetDataUnchecked(offset, MemoryMarshal.AsBytes(data));
}
public void SetDataInline(CommandBufferScoped cbs, Action endRenderPass, int dstOffset, ReadOnlySpan<byte> data)
{
if (!TryPushData(cbs, endRenderPass, dstOffset, data))

View File

@@ -9,6 +9,36 @@ using VkFormat = Silk.NET.Vulkan.Format;
namespace Ryujinx.Graphics.Vulkan
{
readonly struct ScopedTemporaryBuffer : IDisposable
{
private readonly BufferManager _bufferManager;
private readonly bool _isReserved;
public readonly BufferRange Range;
public readonly BufferHolder Holder;
public BufferHandle Handle => Range.Handle;
public int Offset => Range.Offset;
public ScopedTemporaryBuffer(BufferManager bufferManager, BufferHolder holder, BufferHandle handle, int offset, int size, bool isReserved)
{
_bufferManager = bufferManager;
Range = new BufferRange(handle, offset, size);
Holder = holder;
_isReserved = isReserved;
}
public void Dispose()
{
if (!_isReserved)
{
_bufferManager.Delete(Range.Handle);
}
}
}
class BufferManager : IDisposable
{
public const MemoryPropertyFlags DefaultBufferMemoryFlags =
@@ -238,6 +268,23 @@ namespace Ryujinx.Graphics.Vulkan
return Unsafe.As<ulong, BufferHandle>(ref handle64);
}
public ScopedTemporaryBuffer ReserveOrCreate(VulkanRenderer gd, CommandBufferScoped cbs, int size)
{
StagingBufferReserved? result = StagingBuffer.TryReserveData(cbs, size);
if (result.HasValue)
{
return new ScopedTemporaryBuffer(this, result.Value.Buffer, StagingBuffer.Handle, result.Value.Offset, result.Value.Size, true);
}
else
{
// Create a temporary buffer.
BufferHandle handle = CreateWithHandle(gd, size, out BufferHolder holder);
return new ScopedTemporaryBuffer(this, holder, handle, 0, size, false);
}
}
public unsafe MemoryRequirements GetHostImportedUsageRequirements(VulkanRenderer gd)
{
var usage = HostImportedBufferUsageFlags;
@@ -635,13 +682,14 @@ namespace Ryujinx.Graphics.Vulkan
{
if (disposing)
{
StagingBuffer.Dispose();
foreach (BufferHolder buffer in _buffers)
{
buffer.Dispose();
}
_buffers.Clear();
StagingBuffer.Dispose();
}
}

View File

@@ -142,19 +142,18 @@ namespace Ryujinx.Graphics.Vulkan.Effects
};
int rangeSize = dimensionsBuffer.Length * sizeof(float);
var bufferHandle = _renderer.BufferManager.CreateWithHandle(_renderer, rangeSize);
_renderer.BufferManager.SetData(bufferHandle, 0, dimensionsBuffer);
using var buffer = _renderer.BufferManager.ReserveOrCreate(_renderer, cbs, rangeSize);
buffer.Holder.SetDataUnchecked(buffer.Offset, dimensionsBuffer);
ReadOnlySpan<float> sharpeningBuffer = stackalloc float[] { 1.5f - (Level * 0.01f * 1.5f) };
var sharpeningBufferHandle = _renderer.BufferManager.CreateWithHandle(_renderer, sizeof(float));
_renderer.BufferManager.SetData(sharpeningBufferHandle, 0, sharpeningBuffer);
ReadOnlySpan<float> sharpeningBufferData = stackalloc float[] { 1.5f - (Level * 0.01f * 1.5f) };
using var sharpeningBuffer = _renderer.BufferManager.ReserveOrCreate(_renderer, cbs, sizeof(float));
sharpeningBuffer.Holder.SetDataUnchecked(sharpeningBuffer.Offset, sharpeningBufferData);
int threadGroupWorkRegionDim = 16;
int dispatchX = (width + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
int dispatchY = (height + (threadGroupWorkRegionDim - 1)) / threadGroupWorkRegionDim;
var bufferRanges = new BufferRange(bufferHandle, 0, rangeSize);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, bufferRanges) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, buffer.Range) });
_pipeline.SetImage(0, _intermediaryTexture, FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format));
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
_pipeline.ComputeBarrier();
@@ -162,16 +161,12 @@ namespace Ryujinx.Graphics.Vulkan.Effects
// Sharpening pass
_pipeline.SetProgram(_sharpeningProgram);
_pipeline.SetTextureAndSampler(ShaderStage.Compute, 1, _intermediaryTexture, _sampler);
var sharpeningRange = new BufferRange(sharpeningBufferHandle, 0, sizeof(float));
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(4, sharpeningRange) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(4, sharpeningBuffer.Range) });
_pipeline.SetImage(0, destinationTexture);
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
_pipeline.ComputeBarrier();
_pipeline.Finish();
_renderer.BufferManager.Delete(bufferHandle);
_renderer.BufferManager.Delete(sharpeningBufferHandle);
}
}
}

View File

@@ -66,12 +66,11 @@ namespace Ryujinx.Graphics.Vulkan.Effects
ReadOnlySpan<float> resolutionBuffer = stackalloc float[] { view.Width, view.Height };
int rangeSize = resolutionBuffer.Length * sizeof(float);
var bufferHandle = _renderer.BufferManager.CreateWithHandle(_renderer, rangeSize);
using var buffer = _renderer.BufferManager.ReserveOrCreate(_renderer, cbs, rangeSize);
_renderer.BufferManager.SetData(bufferHandle, 0, resolutionBuffer);
buffer.Holder.SetDataUnchecked(buffer.Offset, resolutionBuffer);
var bufferRanges = new BufferRange(bufferHandle, 0, rangeSize);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, bufferRanges) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, buffer.Range) });
var dispatchX = BitUtils.DivRoundUp(view.Width, IPostProcessingEffect.LocalGroupSize);
var dispatchY = BitUtils.DivRoundUp(view.Height, IPostProcessingEffect.LocalGroupSize);
@@ -79,7 +78,6 @@ namespace Ryujinx.Graphics.Vulkan.Effects
_pipeline.SetImage(0, _texture, FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format));
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
_renderer.BufferManager.Delete(bufferHandle);
_pipeline.ComputeBarrier();
_pipeline.Finish();

View File

@@ -215,11 +215,10 @@ namespace Ryujinx.Graphics.Vulkan.Effects
ReadOnlySpan<float> resolutionBuffer = stackalloc float[] { view.Width, view.Height };
int rangeSize = resolutionBuffer.Length * sizeof(float);
var bufferHandle = _renderer.BufferManager.CreateWithHandle(_renderer, rangeSize);
using var buffer = _renderer.BufferManager.ReserveOrCreate(_renderer, cbs, rangeSize);
_renderer.BufferManager.SetData(bufferHandle, 0, resolutionBuffer);
var bufferRanges = new BufferRange(bufferHandle, 0, rangeSize);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, bufferRanges) });
buffer.Holder.SetDataUnchecked(buffer.Offset, resolutionBuffer);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(2, buffer.Range) });
_pipeline.SetImage(0, _edgeOutputTexture, FormatTable.ConvertRgba8SrgbToUnorm(view.Info.Format));
_pipeline.DispatchCompute(dispatchX, dispatchY, 1);
_pipeline.ComputeBarrier();
@@ -245,8 +244,6 @@ namespace Ryujinx.Graphics.Vulkan.Effects
_pipeline.Finish();
_renderer.BufferManager.Delete(bufferHandle);
return _outputTexture;
}

View File

@@ -430,11 +430,11 @@ namespace Ryujinx.Graphics.Vulkan
(region[2], region[3]) = (region[3], region[2]);
}
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, RegionBufferSize);
using var buffer = gd.BufferManager.ReserveOrCreate(gd, cbs, RegionBufferSize);
gd.BufferManager.SetData<float>(bufferHandle, 0, region);
buffer.Holder.SetDataUnchecked<float>(buffer.Offset, region);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, new BufferRange(bufferHandle, 0, RegionBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, buffer.Range) });
Span<Viewport> viewports = stackalloc Viewport[1];
@@ -490,8 +490,6 @@ namespace Ryujinx.Graphics.Vulkan
}
_pipeline.Finish(gd, cbs);
gd.BufferManager.Delete(bufferHandle);
}
private void BlitDepthStencil(
@@ -527,11 +525,11 @@ namespace Ryujinx.Graphics.Vulkan
(region[2], region[3]) = (region[3], region[2]);
}
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, RegionBufferSize);
using var buffer = gd.BufferManager.ReserveOrCreate(gd, cbs, RegionBufferSize);
gd.BufferManager.SetData<float>(bufferHandle, 0, region);
buffer.Holder.SetDataUnchecked<float>(buffer.Offset, region);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, new BufferRange(bufferHandle, 0, RegionBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, buffer.Range) });
Span<Viewport> viewports = stackalloc Viewport[1];
@@ -582,8 +580,6 @@ namespace Ryujinx.Graphics.Vulkan
}
_pipeline.Finish(gd, cbs);
gd.BufferManager.Delete(bufferHandle);
}
private static TextureView CreateDepthOrStencilView(TextureView depthStencilTexture, DepthStencilMode depthStencilMode)
@@ -681,11 +677,11 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetCommandBuffer(cbs);
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, ClearColorBufferSize);
using var buffer = gd.BufferManager.ReserveOrCreate(gd, cbs, ClearColorBufferSize);
gd.BufferManager.SetData(bufferHandle, 0, clearColor);
buffer.Holder.SetDataUnchecked(buffer.Offset, clearColor);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, new BufferRange(bufferHandle, 0, ClearColorBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, buffer.Range) });
Span<Viewport> viewports = stackalloc Viewport[1];
@@ -721,8 +717,6 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
_pipeline.Draw(4, 1, 0, 0);
_pipeline.Finish();
gd.BufferManager.Delete(bufferHandle);
}
public void Clear(
@@ -745,11 +739,11 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetCommandBuffer(cbs);
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, ClearColorBufferSize);
using var buffer = gd.BufferManager.ReserveOrCreate(gd, cbs, ClearColorBufferSize);
gd.BufferManager.SetData<float>(bufferHandle, 0, stackalloc float[] { depthValue });
buffer.Holder.SetDataUnchecked<float>(buffer.Offset, stackalloc float[] { depthValue });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, new BufferRange(bufferHandle, 0, ClearColorBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(1, buffer.Range) });
Span<Viewport> viewports = stackalloc Viewport[1];
@@ -771,8 +765,6 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetStencilTest(CreateStencilTestDescriptor(stencilMask != 0, stencilValue, 0xff, stencilMask));
_pipeline.Draw(4, 1, 0, 0);
_pipeline.Finish();
gd.BufferManager.Delete(bufferHandle);
}
public void DrawTexture(
@@ -878,13 +870,13 @@ namespace Ryujinx.Graphics.Vulkan
shaderParams[2] = size;
shaderParams[3] = srcOffset;
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, ParamsBufferSize);
using var buffer = gd.BufferManager.ReserveOrCreate(gd, cbs, ParamsBufferSize);
gd.BufferManager.SetData<int>(bufferHandle, 0, shaderParams);
buffer.Holder.SetDataUnchecked<int>(buffer.Offset, shaderParams);
_pipeline.SetCommandBuffer(cbs);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, new BufferRange(bufferHandle, 0, ParamsBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, buffer.Range) });
Span<Auto<DisposableBuffer>> sbRanges = new Auto<DisposableBuffer>[2];
@@ -896,8 +888,6 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetProgram(_programStrideChange);
_pipeline.DispatchCompute(1 + elems / ConvertElementsPerWorkgroup, 1, 1);
gd.BufferManager.Delete(bufferHandle);
_pipeline.Finish(gd, cbs);
}
else
@@ -1025,7 +1015,7 @@ namespace Ryujinx.Graphics.Vulkan
{
const int ParamsBufferSize = 4;
Span<int> shaderParams = stackalloc int[sizeof(int)];
Span<int> shaderParams = stackalloc int[ParamsBufferSize / sizeof(int)];
int srcBpp = src.Info.BytesPerPixel;
int dstBpp = dst.Info.BytesPerPixel;
@@ -1034,9 +1024,9 @@ namespace Ryujinx.Graphics.Vulkan
shaderParams[0] = BitOperations.Log2((uint)ratio);
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, ParamsBufferSize);
using var buffer = gd.BufferManager.ReserveOrCreate(gd, cbs, ParamsBufferSize);
gd.BufferManager.SetData<int>(bufferHandle, 0, shaderParams);
buffer.Holder.SetDataUnchecked<int>(buffer.Offset, shaderParams);
TextureView.InsertImageBarrier(
gd.Api,
@@ -1064,7 +1054,7 @@ namespace Ryujinx.Graphics.Vulkan
var srcFormat = GetFormat(componentSize, srcBpp / componentSize);
var dstFormat = GetFormat(componentSize, dstBpp / componentSize);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, new BufferRange(bufferHandle, 0, ParamsBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, buffer.Range) });
for (int l = 0; l < levels; l++)
{
@@ -1093,8 +1083,6 @@ namespace Ryujinx.Graphics.Vulkan
}
}
gd.BufferManager.Delete(bufferHandle);
_pipeline.Finish(gd, cbs);
TextureView.InsertImageBarrier(
@@ -1128,9 +1116,9 @@ namespace Ryujinx.Graphics.Vulkan
(shaderParams[0], shaderParams[1]) = GetSampleCountXYLog2(samples);
(shaderParams[2], shaderParams[3]) = GetSampleCountXYLog2((int)TextureStorage.ConvertToSampleCountFlags(gd.Capabilities.SupportedSampleCounts, (uint)samples));
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, ParamsBufferSize);
using var buffer = gd.BufferManager.ReserveOrCreate(gd, cbs, ParamsBufferSize);
gd.BufferManager.SetData<int>(bufferHandle, 0, shaderParams);
buffer.Holder.SetDataUnchecked<int>(buffer.Offset, shaderParams);
TextureView.InsertImageBarrier(
gd.Api,
@@ -1147,7 +1135,7 @@ namespace Ryujinx.Graphics.Vulkan
1);
_pipeline.SetCommandBuffer(cbs);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, new BufferRange(bufferHandle, 0, ParamsBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, buffer.Range) });
if (isDepthOrStencil)
{
@@ -1226,8 +1214,6 @@ namespace Ryujinx.Graphics.Vulkan
}
}
gd.BufferManager.Delete(bufferHandle);
_pipeline.Finish(gd, cbs);
TextureView.InsertImageBarrier(
@@ -1261,9 +1247,9 @@ namespace Ryujinx.Graphics.Vulkan
(shaderParams[0], shaderParams[1]) = GetSampleCountXYLog2(samples);
(shaderParams[2], shaderParams[3]) = GetSampleCountXYLog2((int)TextureStorage.ConvertToSampleCountFlags(gd.Capabilities.SupportedSampleCounts, (uint)samples));
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, ParamsBufferSize);
using var buffer = gd.BufferManager.ReserveOrCreate(gd, cbs, ParamsBufferSize);
gd.BufferManager.SetData<int>(bufferHandle, 0, shaderParams);
buffer.Holder.SetDataUnchecked<int>(buffer.Offset, shaderParams);
TextureView.InsertImageBarrier(
gd.Api,
@@ -1299,7 +1285,7 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetViewports(viewports);
_pipeline.SetPrimitiveTopology(PrimitiveTopology.TriangleStrip);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, new BufferRange(bufferHandle, 0, ParamsBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, buffer.Range) });
if (isDepthOrStencil)
{
@@ -1364,8 +1350,6 @@ namespace Ryujinx.Graphics.Vulkan
}
}
gd.BufferManager.Delete(bufferHandle);
_pipeline.Finish(gd, cbs);
TextureView.InsertImageBarrier(
@@ -1616,10 +1600,11 @@ namespace Ryujinx.Graphics.Vulkan
pattern.OffsetIndex.CopyTo(shaderParams[..pattern.OffsetIndex.Length]);
var patternBufferHandle = gd.BufferManager.CreateWithHandle(gd, ParamsBufferSize, out var patternBuffer);
using var patternScoped = gd.BufferManager.ReserveOrCreate(gd, cbs, ParamsBufferSize);
var patternBuffer = patternScoped.Holder;
var patternBufferAuto = patternBuffer.GetBuffer();
gd.BufferManager.SetData<int>(patternBufferHandle, 0, shaderParams);
patternBuffer.SetDataUnchecked<int>(patternScoped.Offset, shaderParams);
_pipeline.SetCommandBuffer(cbs);
@@ -1635,7 +1620,8 @@ namespace Ryujinx.Graphics.Vulkan
indirectDataSize);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, drawCountBufferAligned) });
_pipeline.SetStorageBuffers(1, new[] { srcIndirectBuffer.GetBuffer(), dstIndirectBuffer.GetBuffer(), patternBuffer.GetBuffer() });
_pipeline.SetStorageBuffers(1, new[] { srcIndirectBuffer.GetBuffer(), dstIndirectBuffer.GetBuffer() });
_pipeline.SetStorageBuffers(stackalloc[] { new BufferAssignment(3, patternScoped.Range) });
_pipeline.SetProgram(_programConvertIndirectData);
_pipeline.DispatchCompute(1, 1, 1);
@@ -1643,12 +1629,12 @@ namespace Ryujinx.Graphics.Vulkan
BufferHolder.InsertBufferBarrier(
gd,
cbs.CommandBuffer,
patternBufferAuto.Get(cbs, ParamsIndirectDispatchOffset, ParamsIndirectDispatchSize).Value,
patternBufferAuto.Get(cbs, patternScoped.Offset + ParamsIndirectDispatchOffset, ParamsIndirectDispatchSize).Value,
AccessFlags.ShaderWriteBit,
AccessFlags.IndirectCommandReadBit,
PipelineStageFlags.ComputeShaderBit,
PipelineStageFlags.DrawIndirectBit,
ParamsIndirectDispatchOffset,
patternScoped.Offset + ParamsIndirectDispatchOffset,
ParamsIndirectDispatchSize);
BufferHolder.InsertBufferBarrier(
@@ -1662,11 +1648,11 @@ namespace Ryujinx.Graphics.Vulkan
0,
convertedCount * outputIndexSize);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, new BufferRange(patternBufferHandle, 0, ParamsBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, new BufferRange(patternScoped.Handle, patternScoped.Offset, ParamsBufferSize)) });
_pipeline.SetStorageBuffers(1, new[] { srcIndexBuffer.GetBuffer(), dstIndexBuffer.GetBuffer() });
_pipeline.SetProgram(_programConvertIndexBuffer);
_pipeline.DispatchComputeIndirect(patternBufferAuto, ParamsIndirectDispatchOffset);
_pipeline.DispatchComputeIndirect(patternBufferAuto, patternScoped.Offset + ParamsIndirectDispatchOffset);
BufferHolder.InsertBufferBarrier(
gd,
@@ -1679,8 +1665,6 @@ namespace Ryujinx.Graphics.Vulkan
0,
convertedCount * outputIndexSize);
gd.BufferManager.Delete(patternBufferHandle);
_pipeline.Finish(gd, cbs);
}
@@ -1726,13 +1710,13 @@ namespace Ryujinx.Graphics.Vulkan
shaderParams[0] = pixelCount;
shaderParams[1] = dstOffset;
var bufferHandle = gd.BufferManager.CreateWithHandle(gd, ParamsBufferSize);
using var buffer = gd.BufferManager.ReserveOrCreate(gd, cbs, ParamsBufferSize);
gd.BufferManager.SetData<int>(bufferHandle, 0, shaderParams);
buffer.Holder.SetDataUnchecked<int>(buffer.Offset, shaderParams);
_pipeline.SetCommandBuffer(cbs);
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, new BufferRange(bufferHandle, 0, ParamsBufferSize)) });
_pipeline.SetUniformBuffers(stackalloc[] { new BufferAssignment(0, buffer.Range) });
Span<Auto<DisposableBuffer>> sbRanges = new Auto<DisposableBuffer>[2];
@@ -1744,8 +1728,6 @@ namespace Ryujinx.Graphics.Vulkan
_pipeline.SetProgram(_programConvertD32S8ToD24S8);
_pipeline.DispatchCompute(1 + inSize / ConvertElementsPerWorkgroup, 1, 1);
gd.BufferManager.Delete(bufferHandle);
_pipeline.Finish(gd, cbs);
BufferHolder.InsertBufferBarrier(

View File

@@ -67,9 +67,18 @@ namespace Ryujinx.Graphics.Vulkan.Queries
lock (_queryPool)
{
count = Math.Min(count, _queryPool.Count);
for (int i = 0; i < count; i++)
if (count > 0)
{
_queryPool.ElementAt(i).PoolReset(cmd, ResetSequence);
foreach (BufferedQuery query in _queryPool)
{
query.PoolReset(cmd, ResetSequence);
if (--count == 0)
{
break;
}
}
}
}
}

View File

@@ -1,5 +1,6 @@
using Ryujinx.Common;
using Ryujinx.Common.Logging;
using Ryujinx.Graphics.GAL;
using System;
using System.Collections.Generic;
using System.Diagnostics;
@@ -29,6 +30,9 @@ namespace Ryujinx.Graphics.Vulkan
private readonly VulkanRenderer _gd;
private readonly BufferHolder _buffer;
private readonly int _resourceAlignment;
public readonly BufferHandle Handle;
private readonly struct PendingCopy
{
@@ -48,9 +52,10 @@ namespace Ryujinx.Graphics.Vulkan
public StagingBuffer(VulkanRenderer gd, BufferManager bufferManager)
{
_gd = gd;
_buffer = bufferManager.Create(gd, BufferSize);
Handle = bufferManager.CreateWithHandle(gd, BufferSize, out _buffer);
_pendingCopies = new Queue<PendingCopy>();
_freeSize = BufferSize;
_resourceAlignment = (int)gd.Capabilities.MinResourceAlignment;
}
public void PushData(CommandBufferPool cbp, CommandBufferScoped? cbs, Action endRenderPass, BufferHolder dst, int dstOffset, ReadOnlySpan<byte> data)
@@ -197,7 +202,7 @@ namespace Ryujinx.Graphics.Vulkan
/// Reserve a range on the staging buffer for the current command buffer and upload data to it.
/// </summary>
/// <param name="cbs">Command buffer to reserve the data on</param>
/// <param name="data">The data to upload</param>
/// <param name="size">The minimum size the reserved data requires</param>
/// <param name="alignment">The required alignment for the buffer offset</param>
/// <returns>The reserved range of the staging buffer</returns>
public unsafe StagingBufferReserved? TryReserveData(CommandBufferScoped cbs, int size, int alignment)
@@ -223,6 +228,18 @@ namespace Ryujinx.Graphics.Vulkan
return ReserveDataImpl(cbs, size, alignment);
}
/// <summary>
/// Reserve a range on the staging buffer for the current command buffer and upload data to it.
/// Uses the most permissive byte alignment.
/// </summary>
/// <param name="cbs">Command buffer to reserve the data on</param>
/// <param name="size">The minimum size the reserved data requires</param>
/// <returns>The reserved range of the staging buffer</returns>
public unsafe StagingBufferReserved? TryReserveData(CommandBufferScoped cbs, int size)
{
return TryReserveData(cbs, size, _resourceAlignment);
}
private bool WaitFreeCompleted(CommandBufferPool cbp)
{
if (_pendingCopies.TryPeek(out var pc))
@@ -263,7 +280,7 @@ namespace Ryujinx.Graphics.Vulkan
{
if (disposing)
{
_buffer.Dispose();
_gd.BufferManager.Delete(Handle);
while (_pendingCopies.TryDequeue(out var pc))
{

View File

@@ -186,7 +186,12 @@ namespace Ryujinx.HLE.FileSystem
public void InitializeFsServer(LibHac.Horizon horizon, out HorizonClient fsServerClient)
{
LocalFileSystem serverBaseFs = new(AppDataManager.BaseDirPath);
LocalFileSystem serverBaseFs = new(useUnixTimeStamps: true);
Result result = serverBaseFs.Initialize(AppDataManager.BaseDirPath, LocalFileSystem.PathMode.DefaultCaseSensitivity, ensurePathExists: true);
if (result.IsFailure())
{
throw new HorizonResultException(result, "Error creating LocalFileSystem.");
}
fsServerClient = horizon.CreatePrivilegedHorizonClient();
var fsServer = new FileSystemServer(fsServerClient);

View File

@@ -1,8 +0,0 @@
namespace Ryujinx.HLE.HOS.Services.Arp
{
[Service("arp:r")]
class IReader : IpcService
{
public IReader(ServiceCtx context) { }
}
}

View File

@@ -1,8 +0,0 @@
namespace Ryujinx.HLE.HOS.Services.Arp
{
[Service("arp:w")]
class IWriter : IpcService
{
public IWriter(ServiceCtx context) { }
}
}

View File

@@ -1,4 +1,4 @@
using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Host1x;
using Ryujinx.Graphics.Nvdec;
using Ryujinx.Graphics.Vic;
@@ -9,7 +9,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
{
class Host1xContext : IDisposable
{
public MemoryManager Smmu { get; }
public DeviceMemoryManager Smmu { get; }
public NvMemoryAllocator MemoryAllocator { get; }
public Host1xDevice Host1x { get; }
@@ -17,7 +17,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv
{
MemoryAllocator = new NvMemoryAllocator();
Host1x = new Host1xDevice(gpu.Synchronization);
Smmu = gpu.CreateMemoryManager(pid);
Smmu = gpu.CreateDeviceMemoryManager(pid);
var nvdec = new NvdecDevice(Smmu);
var vic = new VicDevice(Smmu);
Host1x.RegisterDevice(ClassId.Nvdec, nvdec);

View File

@@ -266,7 +266,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostAsGpu
if (size == 0)
{
size = (uint)map.Size;
size = map.Size;
}
NvInternalResult result = NvInternalResult.Success;

View File

@@ -250,12 +250,12 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvHostChannel
{
if (map.DmaMapAddress == 0)
{
ulong va = _host1xContext.MemoryAllocator.GetFreeAddress((ulong)map.Size, out ulong freeAddressStartPosition, 1, MemoryManager.PageSize);
ulong va = _host1xContext.MemoryAllocator.GetFreeAddress(map.Size, out ulong freeAddressStartPosition, 1, MemoryManager.PageSize);
if (va != NvMemoryAllocator.PteUnmapped && va <= uint.MaxValue && (va + (uint)map.Size) <= uint.MaxValue)
if (va != NvMemoryAllocator.PteUnmapped && va <= uint.MaxValue && (va + map.Size) <= uint.MaxValue)
{
_host1xContext.MemoryAllocator.AllocateRange(va, (uint)map.Size, freeAddressStartPosition);
_host1xContext.Smmu.Map(map.Address, va, (uint)map.Size, PteKind.Pitch); // FIXME: This should not use the GMMU.
_host1xContext.MemoryAllocator.AllocateRange(va, map.Size, freeAddressStartPosition);
_host1xContext.Smmu.Map(map.Address, va, map.Size);
map.DmaMapAddress = va;
}
else

View File

@@ -69,7 +69,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
return NvInternalResult.InvalidInput;
}
int size = BitUtils.AlignUp(arguments.Size, (int)MemoryManager.PageSize);
uint size = BitUtils.AlignUp(arguments.Size, (uint)MemoryManager.PageSize);
arguments.Handle = CreateHandleFromMap(new NvMapHandle(size));
@@ -128,7 +128,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
map.Align = arguments.Align;
map.Kind = (byte)arguments.Kind;
int size = BitUtils.AlignUp(map.Size, (int)MemoryManager.PageSize);
uint size = BitUtils.AlignUp(map.Size, (uint)MemoryManager.PageSize);
ulong address = arguments.Address;
@@ -191,7 +191,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
switch (arguments.Param)
{
case NvMapHandleParam.Size:
arguments.Result = map.Size;
arguments.Result = (int)map.Size;
break;
case NvMapHandleParam.Align:
arguments.Result = map.Align;

View File

@@ -5,7 +5,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
[StructLayout(LayoutKind.Sequential)]
struct NvMapCreate
{
public int Size;
public uint Size;
public int Handle;
}
}

View File

@@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
public int Handle;
public int Padding;
public ulong Address;
public int Size;
public uint Size;
public int Flags;
}
}

View File

@@ -8,7 +8,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
public int Handle;
public int Id;
#pragma warning restore CS0649
public int Size;
public uint Size;
public int Align;
public int Kind;
public ulong Address;
@@ -22,7 +22,7 @@ namespace Ryujinx.HLE.HOS.Services.Nv.NvDrvServices.NvMap
_dupes = 1;
}
public NvMapHandle(int size) : this()
public NvMapHandle(uint size) : this()
{
Size = size;
}

View File

@@ -159,9 +159,7 @@ namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
}
else
{
#pragma warning disable CS0162 // Unreachable code
return ResultCode.StereoVisionRestrictionConfigurableDisabled;
#pragma warning restore CS0162
}
}

View File

@@ -3,6 +3,7 @@ using Ryujinx.HLE.HOS.Services.Sockets.Bsd.Impl;
using Ryujinx.HLE.HOS.Services.Ssl.Types;
using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
@@ -83,10 +84,40 @@ namespace Ryujinx.HLE.HOS.Services.Ssl.SslService
}
#pragma warning restore SYSLIB0039
/// <summary>
/// Retrieve the hostname of the current remote in case the provided hostname is null or empty.
/// </summary>
/// <param name="hostName">The current hostname</param>
/// <returns>Either the resolved or provided hostname</returns>
/// <remarks>
/// This is done to avoid getting an <see cref="System.Security.Authentication.AuthenticationException"/>
/// as the remote certificate will be rejected with <c>RemoteCertificateNameMismatch</c> due to an empty hostname.
/// This is not what the switch does!
/// It might just skip remote hostname verification if the hostname wasn't set with <see cref="ISslConnection.SetHostName"/> before.
/// TODO: Remove this as soon as we know how the switch deals with empty hostnames
/// </remarks>
private string RetrieveHostName(string hostName)
{
if (!string.IsNullOrEmpty(hostName))
{
return hostName;
}
try
{
return Dns.GetHostEntry(Socket.RemoteEndPoint.Address).HostName;
}
catch (SocketException)
{
return hostName;
}
}
public ResultCode Handshake(string hostName)
{
StartSslOperation();
_stream = new SslStream(new NetworkStream(((ManagedSocket)Socket).Socket, false), false, null, null);
hostName = RetrieveHostName(hostName);
_stream.AuthenticateAsClient(hostName, null, TranslateSslVersion(_sslVersion), false);
EndSslOperation();

View File

@@ -34,7 +34,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
return metaLoader;
}
public static ProcessResult Load(this IFileSystem exeFs, Switch device, BlitStruct<ApplicationControlProperty> nacpData, MetaLoader metaLoader, bool isHomebrew = false)
public static ProcessResult Load(this IFileSystem exeFs, Switch device, BlitStruct<ApplicationControlProperty> nacpData, MetaLoader metaLoader, byte programIndex, bool isHomebrew = false)
{
ulong programId = metaLoader.GetProgramId();
@@ -119,6 +119,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
true,
programName,
metaLoader.GetProgramId(),
programIndex,
null,
nsoExecutables);

View File

@@ -26,7 +26,7 @@ namespace Ryujinx.HLE.Loaders.Processes
ProcessLoaderHelper.EnsureSaveData(device, new ApplicationId(programId), nacpData);
}
ProcessResult processResult = exeFs.Load(device, nacpData, metaLoader);
ProcessResult processResult = exeFs.Load(device, nacpData, metaLoader, 0);
// Load RomFS.
if (!string.IsNullOrEmpty(romFsPath))

View File

@@ -61,7 +61,7 @@ namespace Ryujinx.HLE.Loaders.Processes.Extensions
*/
ProcessResult processResult = exeFs.Load(device, nacpData, metaLoader);
ProcessResult processResult = exeFs.Load(device, nacpData, metaLoader, (byte)nca.GetProgramIndex());
// Load RomFS.
if (romFs == null)

View File

@@ -77,7 +77,7 @@ namespace Ryujinx.HLE.Loaders.Processes
if (processResult.ProcessId == 0)
{
// This is not a normal NSP, it's actually a ExeFS as a NSP
processResult = partitionFileSystem.Load(_device, new BlitStruct<ApplicationControlProperty>(1), partitionFileSystem.GetNpdm(), true);
processResult = partitionFileSystem.Load(_device, new BlitStruct<ApplicationControlProperty>(1), partitionFileSystem.GetNpdm(), 0, true);
}
if (processResult.ProcessId != 0 && _processesByPid.TryAdd(processResult.ProcessId, processResult))
@@ -198,7 +198,7 @@ namespace Ryujinx.HLE.Loaders.Processes
}
else
{
programName = System.IO.Path.GetFileNameWithoutExtension(path);
programName = Path.GetFileNameWithoutExtension(path);
executable = new NsoExecutable(new LocalStorage(path, FileAccess.Read), programName);
}
@@ -215,6 +215,7 @@ namespace Ryujinx.HLE.Loaders.Processes
allowCodeMemoryForJit: true,
programName,
programId,
0,
null,
executable);

View File

@@ -19,6 +19,7 @@ using Ryujinx.HLE.HOS.Kernel.Process;
using Ryujinx.HLE.Loaders.Executables;
using Ryujinx.HLE.Loaders.Processes.Extensions;
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Arp;
using System;
using System.Linq;
using System.Runtime.InteropServices;
@@ -229,6 +230,7 @@ namespace Ryujinx.HLE.Loaders.Processes
bool allowCodeMemoryForJit,
string name,
ulong programId,
byte programIndex,
byte[] arguments = null,
params IExecutable[] executables)
{
@@ -421,7 +423,7 @@ namespace Ryujinx.HLE.Loaders.Processes
// Once everything is loaded, we can load cheats.
device.Configuration.VirtualFileSystem.ModLoader.LoadCheats(programId, tamperInfo, device.TamperMachine);
return new ProcessResult(
ProcessResult processResult = new(
metaLoader,
applicationControlProperties,
diskCacheEnabled,
@@ -431,6 +433,25 @@ namespace Ryujinx.HLE.Loaders.Processes
meta.MainThreadPriority,
meta.MainThreadStackSize,
device.System.State.DesiredTitleLanguage);
// Register everything in arp service.
device.System.ServiceTable.ArpWriter.AcquireRegistrar(out IRegistrar registrar);
registrar.SetApplicationControlProperty(MemoryMarshal.Cast<byte, Horizon.Sdk.Ns.ApplicationControlProperty>(applicationControlProperties.ByteSpan)[0]);
// TODO: Handle Version and StorageId when it will be needed.
registrar.SetApplicationLaunchProperty(new ApplicationLaunchProperty()
{
ApplicationId = new Horizon.Sdk.Ncm.ApplicationId(programId),
Version = 0x00,
Storage = Horizon.Sdk.Ncm.StorageId.BuiltInUser,
PatchStorage = Horizon.Sdk.Ncm.StorageId.None,
ApplicationKind = ApplicationKind.Application,
});
device.System.ServiceTable.ArpReader.GetApplicationInstanceId(out ulong applicationInstanceId, process.Pid);
device.System.ServiceTable.ArpWriter.AcquireApplicationProcessPropertyUpdater(out IUpdater updater, applicationInstanceId);
updater.SetApplicationProcessProperty(process.Pid, new ApplicationProcessProperty() { ProgramIndex = programIndex });
return processResult;
}
public static Result LoadIntoMemory(KProcess process, IExecutable image, ulong baseAddress)

View File

@@ -0,0 +1,61 @@
using Ryujinx.Horizon.Arp.Ipc;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Arp.Detail;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using Ryujinx.Horizon.Sdk.Sm;
namespace Ryujinx.Horizon.Arp
{
class ArpIpcServer
{
private const int ArpRMaxSessionsCount = 16;
private const int ArpWMaxSessionsCount = 8;
private const int MaxSessionsCount = ArpRMaxSessionsCount + ArpWMaxSessionsCount;
private const int PointerBufferSize = 0x1000;
private const int MaxDomains = 24;
private const int MaxDomainObjects = 32;
private const int MaxPortsCount = 2;
private static readonly ManagerOptions _managerOptions = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false);
private SmApi _sm;
private ServerManager _serverManager;
private ApplicationInstanceManager _applicationInstanceManager;
public IReader Reader { get; private set; }
public IWriter Writer { get; private set; }
public void Initialize()
{
HeapAllocator allocator = new();
_sm = new SmApi();
_sm.Initialize().AbortOnFailure();
_serverManager = new ServerManager(allocator, _sm, MaxPortsCount, _managerOptions, MaxSessionsCount);
_applicationInstanceManager = new ApplicationInstanceManager();
Reader reader = new(_applicationInstanceManager);
Reader = reader;
Writer writer = new(_applicationInstanceManager);
Writer = writer;
_serverManager.RegisterObjectForServer(reader, ServiceName.Encode("arp:r"), ArpRMaxSessionsCount);
_serverManager.RegisterObjectForServer(writer, ServiceName.Encode("arp:w"), ArpWMaxSessionsCount);
}
public void ServiceRequests()
{
_serverManager.ServiceRequests();
}
public void Shutdown()
{
_applicationInstanceManager.Dispose();
_serverManager.Dispose();
}
}
}

View File

@@ -0,0 +1,20 @@
namespace Ryujinx.Horizon.Arp
{
class ArpMain : IService
{
public static void Main(ServiceTable serviceTable)
{
ArpIpcServer arpIpcServer = new();
arpIpcServer.Initialize();
serviceTable.ArpReader = arpIpcServer.Reader;
serviceTable.ArpWriter = arpIpcServer.Writer;
serviceTable.SignalServiceReady();
arpIpcServer.ServiceRequests();
arpIpcServer.Shutdown();
}
}
}

View File

@@ -0,0 +1,135 @@
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Arp.Detail;
using Ryujinx.Horizon.Sdk.Ns;
using Ryujinx.Horizon.Sdk.Sf;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using System;
namespace Ryujinx.Horizon.Arp.Ipc
{
partial class Reader : IReader, IServiceObject
{
private readonly ApplicationInstanceManager _applicationInstanceManager;
public Reader(ApplicationInstanceManager applicationInstanceManager)
{
_applicationInstanceManager = applicationInstanceManager;
}
[CmifCommand(0)]
public Result GetApplicationLaunchProperty(out ApplicationLaunchProperty applicationLaunchProperty, ulong applicationInstanceId)
{
if (_applicationInstanceManager.Entries[applicationInstanceId] == null || !_applicationInstanceManager.Entries[applicationInstanceId].LaunchProperty.HasValue)
{
applicationLaunchProperty = default;
return ArpResult.InvalidInstanceId;
}
applicationLaunchProperty = _applicationInstanceManager.Entries[applicationInstanceId].LaunchProperty.Value;
return Result.Success;
}
[CmifCommand(1)]
public Result GetApplicationControlProperty([Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias, 0x4000)] out ApplicationControlProperty applicationControlProperty, ulong applicationInstanceId)
{
if (_applicationInstanceManager.Entries[applicationInstanceId] == null || !_applicationInstanceManager.Entries[applicationInstanceId].ControlProperty.HasValue)
{
applicationControlProperty = default;
return ArpResult.InvalidInstanceId;
}
applicationControlProperty = _applicationInstanceManager.Entries[applicationInstanceId].ControlProperty.Value;
return Result.Success;
}
[CmifCommand(2)]
public Result GetApplicationProcessProperty(out ApplicationProcessProperty applicationProcessProperty, ulong applicationInstanceId)
{
if (_applicationInstanceManager.Entries[applicationInstanceId] == null || !_applicationInstanceManager.Entries[applicationInstanceId].ProcessProperty.HasValue)
{
applicationProcessProperty = default;
return ArpResult.InvalidInstanceId;
}
applicationProcessProperty = _applicationInstanceManager.Entries[applicationInstanceId].ProcessProperty.Value;
return Result.Success;
}
[CmifCommand(3)]
public Result GetApplicationInstanceId(out ulong applicationInstanceId, ulong pid)
{
applicationInstanceId = 0;
if (pid == 0)
{
return ArpResult.InvalidPid;
}
for (int i = 0; i < _applicationInstanceManager.Entries.Length; i++)
{
if (_applicationInstanceManager.Entries[i] != null && _applicationInstanceManager.Entries[i].Pid == pid)
{
applicationInstanceId = (ulong)i;
return Result.Success;
}
}
return ArpResult.InvalidPid;
}
[CmifCommand(4)]
public Result GetApplicationInstanceUnregistrationNotifier(out IUnregistrationNotifier unregistrationNotifier)
{
unregistrationNotifier = new UnregistrationNotifier(_applicationInstanceManager);
return Result.Success;
}
[CmifCommand(5)]
public Result ListApplicationInstanceId(out int count, [Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias)] Span<ulong> applicationInstanceIdList)
{
count = 0;
if (_applicationInstanceManager.Entries[0] != null)
{
applicationInstanceIdList[count++] = 0;
}
if (_applicationInstanceManager.Entries[1] != null)
{
applicationInstanceIdList[count++] = 1;
}
return Result.Success;
}
[CmifCommand(6)]
public Result GetMicroApplicationInstanceId(out ulong microApplicationInstanceId, [ClientProcessId] ulong pid)
{
return GetApplicationInstanceId(out microApplicationInstanceId, pid);
}
[CmifCommand(7)]
public Result GetApplicationCertificate([Buffer(HipcBufferFlags.Out | HipcBufferFlags.MapAlias | HipcBufferFlags.FixedSize, 0x528)] out ApplicationCertificate applicationCertificate, ulong applicationInstanceId)
{
if (_applicationInstanceManager.Entries[applicationInstanceId] == null)
{
applicationCertificate = default;
return ArpResult.InvalidInstanceId;
}
applicationCertificate = _applicationInstanceManager.Entries[applicationInstanceId].Certificate.Value;
return Result.Success;
}
}
}

View File

@@ -0,0 +1,52 @@
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Arp.Detail;
using Ryujinx.Horizon.Sdk.Ns;
using Ryujinx.Horizon.Sdk.Sf;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using System;
namespace Ryujinx.Horizon.Arp.Ipc
{
partial class Registrar : IRegistrar, IServiceObject
{
private readonly ApplicationInstance _applicationInstance;
public Registrar(ApplicationInstance applicationInstance)
{
_applicationInstance = applicationInstance;
}
[CmifCommand(0)]
public Result Issue(out ulong applicationInstanceId)
{
throw new NotImplementedException();
}
[CmifCommand(1)]
public Result SetApplicationLaunchProperty(ApplicationLaunchProperty applicationLaunchProperty)
{
if (_applicationInstance.LaunchProperty != null)
{
return ArpResult.DataAlreadyBound;
}
_applicationInstance.LaunchProperty = applicationLaunchProperty;
return Result.Success;
}
[CmifCommand(2)]
public Result SetApplicationControlProperty([Buffer(HipcBufferFlags.In | HipcBufferFlags.MapAlias | HipcBufferFlags.FixedSize, 0x4000)] in ApplicationControlProperty applicationControlProperty)
{
if (_applicationInstance.ControlProperty != null)
{
return ArpResult.DataAlreadyBound;
}
_applicationInstance.ControlProperty = applicationControlProperty;
return Result.Success;
}
}
}

View File

@@ -0,0 +1,25 @@
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Arp.Detail;
using Ryujinx.Horizon.Sdk.Sf;
namespace Ryujinx.Horizon.Arp.Ipc
{
partial class UnregistrationNotifier : IUnregistrationNotifier, IServiceObject
{
private readonly ApplicationInstanceManager _applicationInstanceManager;
public UnregistrationNotifier(ApplicationInstanceManager applicationInstanceManager)
{
_applicationInstanceManager = applicationInstanceManager;
}
[CmifCommand(0)]
public Result GetReadableHandle([CopyHandle] out int readableHandle)
{
readableHandle = _applicationInstanceManager.EventHandle;
return Result.Success;
}
}
}

View File

@@ -0,0 +1,74 @@
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Arp.Detail;
using Ryujinx.Horizon.Sdk.Sf;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using System;
namespace Ryujinx.Horizon.Arp.Ipc
{
partial class Updater : IUpdater, IServiceObject
{
private readonly ApplicationInstanceManager _applicationInstanceManager;
private readonly ulong _applicationInstanceId;
private readonly bool _forCertificate;
public Updater(ApplicationInstanceManager applicationInstanceManager, ulong applicationInstanceId, bool forCertificate)
{
_applicationInstanceManager = applicationInstanceManager;
_applicationInstanceId = applicationInstanceId;
_forCertificate = forCertificate;
}
[CmifCommand(0)]
public Result Issue()
{
throw new NotImplementedException();
}
[CmifCommand(1)]
public Result SetApplicationProcessProperty(ulong pid, ApplicationProcessProperty applicationProcessProperty)
{
if (_forCertificate)
{
return ArpResult.DataAlreadyBound;
}
if (pid == 0)
{
return ArpResult.InvalidPid;
}
_applicationInstanceManager.Entries[_applicationInstanceId].Pid = pid;
_applicationInstanceManager.Entries[_applicationInstanceId].ProcessProperty = applicationProcessProperty;
return Result.Success;
}
[CmifCommand(2)]
public Result DeleteApplicationProcessProperty()
{
if (_forCertificate)
{
return ArpResult.DataAlreadyBound;
}
_applicationInstanceManager.Entries[_applicationInstanceId].ProcessProperty = new ApplicationProcessProperty();
return Result.Success;
}
[CmifCommand(3)]
public Result SetApplicationCertificate([Buffer(HipcBufferFlags.In | HipcBufferFlags.AutoSelect)] ApplicationCertificate applicationCertificate)
{
if (!_forCertificate)
{
return ArpResult.DataAlreadyBound;
}
_applicationInstanceManager.Entries[_applicationInstanceId].Certificate = applicationCertificate;
return Result.Success;
}
}
}

View File

@@ -0,0 +1,75 @@
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Arp.Detail;
using Ryujinx.Horizon.Sdk.OsTypes;
using Ryujinx.Horizon.Sdk.Sf;
namespace Ryujinx.Horizon.Arp.Ipc
{
partial class Writer : IWriter, IServiceObject
{
private readonly ApplicationInstanceManager _applicationInstanceManager;
public Writer(ApplicationInstanceManager applicationInstanceManager)
{
_applicationInstanceManager = applicationInstanceManager;
}
[CmifCommand(0)]
public Result AcquireRegistrar(out IRegistrar registrar)
{
if (_applicationInstanceManager.Entries[0] != null)
{
if (_applicationInstanceManager.Entries[1] != null)
{
registrar = null;
return ArpResult.NoFreeInstance;
}
else
{
_applicationInstanceManager.Entries[1] = new ApplicationInstance();
registrar = new Registrar(_applicationInstanceManager.Entries[1]);
}
}
else
{
_applicationInstanceManager.Entries[0] = new ApplicationInstance();
registrar = new Registrar(_applicationInstanceManager.Entries[0]);
}
return Result.Success;
}
[CmifCommand(1)]
public Result UnregisterApplicationInstance(ulong applicationInstanceId)
{
if (_applicationInstanceManager.Entries[applicationInstanceId] != null)
{
_applicationInstanceManager.Entries[applicationInstanceId] = null;
}
Os.SignalSystemEvent(ref _applicationInstanceManager.SystemEvent);
return Result.Success;
}
[CmifCommand(2)]
public Result AcquireApplicationProcessPropertyUpdater(out IUpdater updater, ulong applicationInstanceId)
{
updater = new Updater(_applicationInstanceManager, applicationInstanceId, false);
return Result.Success;
}
[CmifCommand(3)]
public Result AcquireApplicationCertificateUpdater(out IUpdater updater, ulong applicationInstanceId)
{
updater = new Updater(_applicationInstanceManager, applicationInstanceId, true);
return Result.Success;
}
}
}

View File

@@ -5,6 +5,7 @@ using Ryujinx.Common.Utilities;
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Prepo.Types;
using Ryujinx.Horizon.Sdk.Account;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Prepo;
using Ryujinx.Horizon.Sdk.Sf;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
@@ -22,14 +23,16 @@ namespace Ryujinx.Horizon.Prepo.Ipc
System,
}
private readonly ArpApi _arp;
private readonly PrepoServicePermissionLevel _permissionLevel;
private ulong _systemSessionId;
private bool _immediateTransmissionEnabled;
private bool _userAgreementCheckEnabled = true;
public PrepoService(PrepoServicePermissionLevel permissionLevel)
public PrepoService(ArpApi arp, PrepoServicePermissionLevel permissionLevel)
{
_arp = arp;
_permissionLevel = permissionLevel;
}
@@ -165,7 +168,7 @@ namespace Ryujinx.Horizon.Prepo.Ipc
return PrepoResult.PermissionDenied;
}
private static Result ProcessPlayReport(PlayReportKind playReportKind, ReadOnlySpan<byte> gameRoomBuffer, ReadOnlySpan<byte> reportBuffer, ulong pid, Uid userId, bool withUserId = false, ApplicationId applicationId = default)
private Result ProcessPlayReport(PlayReportKind playReportKind, ReadOnlySpan<byte> gameRoomBuffer, ReadOnlySpan<byte> reportBuffer, ulong pid, Uid userId, bool withUserId = false, ApplicationId applicationId = default)
{
if (withUserId)
{
@@ -199,8 +202,8 @@ namespace Ryujinx.Horizon.Prepo.Ipc
builder.AppendLine("PlayReport log:");
builder.AppendLine($" Kind: {playReportKind}");
// NOTE: The service calls arp:r using the pid to get the application id, if it fails PrepoResult.InvalidPid is returned.
// Reports are stored internally and an event is signaled to transmit them.
// NOTE: Reports are stored internally and an event is signaled to transmit them.
if (pid != 0)
{
builder.AppendLine($" Pid: {pid}");
@@ -210,6 +213,16 @@ namespace Ryujinx.Horizon.Prepo.Ipc
builder.AppendLine($" ApplicationId: {applicationId}");
}
Result result = _arp.GetApplicationInstanceId(out ulong applicationInstanceId, pid);
if (result.IsFailure)
{
return PrepoResult.InvalidPid;
}
_arp.GetApplicationLaunchProperty(out ApplicationLaunchProperty applicationLaunchProperty, applicationInstanceId).AbortOnFailure();
builder.AppendLine($" ApplicationVersion: {applicationLaunchProperty.Version}");
if (!userId.IsNull)
{
builder.AppendLine($" UserId: {userId}");

View File

@@ -1,4 +1,5 @@
using Ryujinx.Horizon.Prepo.Types;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using Ryujinx.Horizon.Sdk.Sm;
@@ -17,16 +18,19 @@ namespace Ryujinx.Horizon.Prepo
private static readonly ManagerOptions _managerOptions = new(PointerBufferSize, MaxDomains, MaxDomainObjects, false);
private SmApi _sm;
private ArpApi _arp;
private PrepoServerManager _serverManager;
public void Initialize()
{
HeapAllocator allocator = new();
_arp = new ArpApi(allocator);
_sm = new SmApi();
_sm.Initialize().AbortOnFailure();
_serverManager = new PrepoServerManager(allocator, _sm, MaxPortsCount, _managerOptions, TotalMaxSessionsCount);
_serverManager = new PrepoServerManager(allocator, _sm, _arp, MaxPortsCount, _managerOptions, TotalMaxSessionsCount);
#pragma warning disable IDE0055 // Disable formatting
_serverManager.RegisterServer((int)PrepoPortIndex.Admin, ServiceName.Encode("prepo:a"), MaxSessionsCount); // 1.0.0-5.1.0
@@ -45,6 +49,7 @@ namespace Ryujinx.Horizon.Prepo
public void Shutdown()
{
_arp.Dispose();
_serverManager.Dispose();
}
}

View File

@@ -1,6 +1,7 @@
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Prepo.Ipc;
using Ryujinx.Horizon.Prepo.Types;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using Ryujinx.Horizon.Sdk.Sm;
using System;
@@ -9,8 +10,11 @@ namespace Ryujinx.Horizon.Prepo
{
class PrepoServerManager : ServerManager
{
public PrepoServerManager(HeapAllocator allocator, SmApi sm, int maxPorts, ManagerOptions options, int maxSessions) : base(allocator, sm, maxPorts, options, maxSessions)
private readonly ArpApi _arp;
public PrepoServerManager(HeapAllocator allocator, SmApi sm, ArpApi arp, int maxPorts, ManagerOptions options, int maxSessions) : base(allocator, sm, maxPorts, options, maxSessions)
{
_arp = arp;
}
protected override Result OnNeedsToAccept(int portIndex, Server server)
@@ -18,12 +22,12 @@ namespace Ryujinx.Horizon.Prepo
return (PrepoPortIndex)portIndex switch
{
#pragma warning disable IDE0055 // Disable formatting
PrepoPortIndex.Admin => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)),
PrepoPortIndex.Admin2 => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Admin)),
PrepoPortIndex.Manager => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Manager)),
PrepoPortIndex.User => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.User)),
PrepoPortIndex.System => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.System)),
PrepoPortIndex.Debug => AcceptImpl(server, new PrepoService(PrepoServicePermissionLevel.Debug)),
PrepoPortIndex.Admin => AcceptImpl(server, new PrepoService(_arp, PrepoServicePermissionLevel.Admin)),
PrepoPortIndex.Admin2 => AcceptImpl(server, new PrepoService(_arp, PrepoServicePermissionLevel.Admin)),
PrepoPortIndex.Manager => AcceptImpl(server, new PrepoService(_arp, PrepoServicePermissionLevel.Manager)),
PrepoPortIndex.User => AcceptImpl(server, new PrepoService(_arp, PrepoServicePermissionLevel.User)),
PrepoPortIndex.System => AcceptImpl(server, new PrepoService(_arp, PrepoServicePermissionLevel.System)),
PrepoPortIndex.Debug => AcceptImpl(server, new PrepoService(_arp, PrepoServicePermissionLevel.Debug)),
_ => throw new ArgumentOutOfRangeException(nameof(portIndex)),
#pragma warning restore IDE0055
};

View File

@@ -0,0 +1,9 @@
using System.Runtime.InteropServices;
namespace Ryujinx.Horizon.Sdk.Arp
{
[StructLayout(LayoutKind.Sequential, Size = 0x528)]
public struct ApplicationCertificate
{
}
}

View File

@@ -0,0 +1,8 @@
namespace Ryujinx.Horizon.Sdk.Arp
{
public enum ApplicationKind : byte
{
Application,
MicroApplication,
}
}

View File

@@ -0,0 +1,14 @@
using Ryujinx.Horizon.Sdk.Ncm;
namespace Ryujinx.Horizon.Sdk.Arp
{
public struct ApplicationLaunchProperty
{
public ApplicationId ApplicationId;
public uint Version;
public StorageId Storage;
public StorageId PatchStorage;
public ApplicationKind ApplicationKind;
public byte Padding;
}
}

View File

@@ -0,0 +1,10 @@
using Ryujinx.Common.Memory;
namespace Ryujinx.Horizon.Sdk.Arp
{
public struct ApplicationProcessProperty
{
public byte ProgramIndex;
public Array15<byte> Unknown;
}
}

View File

@@ -0,0 +1,130 @@
using Ryujinx.Common.Memory;
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Ns;
using Ryujinx.Horizon.Sdk.Sf.Cmif;
using Ryujinx.Horizon.Sdk.Sf.Hipc;
using Ryujinx.Horizon.Sdk.Sm;
using System;
using System.Runtime.CompilerServices;
namespace Ryujinx.Horizon.Sdk.Arp
{
class ArpApi : IDisposable
{
private const string ArpRName = "arp:r";
private readonly HeapAllocator _allocator;
private int _sessionHandle;
public ArpApi(HeapAllocator allocator)
{
_allocator = allocator;
}
private void InitializeArpRService()
{
if (_sessionHandle == 0)
{
using var smApi = new SmApi();
smApi.Initialize();
smApi.GetServiceHandle(out _sessionHandle, ServiceName.Encode(ArpRName)).AbortOnFailure();
}
}
public Result GetApplicationInstanceId(out ulong applicationInstanceId, ulong applicationPid)
{
Span<byte> data = stackalloc byte[8];
SpanWriter writer = new(data);
writer.Write(applicationPid);
InitializeArpRService();
Result result = ServiceUtil.SendRequest(out CmifResponse response, _sessionHandle, 3, sendPid: false, data);
if (result.IsFailure)
{
applicationInstanceId = 0;
return result;
}
SpanReader reader = new(response.Data);
applicationInstanceId = reader.Read<ulong>();
return Result.Success;
}
public Result GetApplicationLaunchProperty(out ApplicationLaunchProperty applicationLaunchProperty, ulong applicationInstanceId)
{
applicationLaunchProperty = default;
Span<byte> data = stackalloc byte[8];
SpanWriter writer = new(data);
writer.Write(applicationInstanceId);
InitializeArpRService();
Result result = ServiceUtil.SendRequest(out CmifResponse response, _sessionHandle, 0, sendPid: false, data);
if (result.IsFailure)
{
return result;
}
SpanReader reader = new(response.Data);
applicationLaunchProperty = reader.Read<ApplicationLaunchProperty>();
return Result.Success;
}
public Result GetApplicationControlProperty(out ApplicationControlProperty applicationControlProperty, ulong applicationInstanceId)
{
applicationControlProperty = default;
Span<byte> data = stackalloc byte[8];
SpanWriter writer = new(data);
writer.Write(applicationInstanceId);
ulong bufferSize = (ulong)Unsafe.SizeOf<ApplicationControlProperty>();
ulong bufferAddress = _allocator.Allocate(bufferSize);
InitializeArpRService();
Result result = ServiceUtil.SendRequest(
out CmifResponse response,
_sessionHandle,
1,
sendPid: false,
data,
stackalloc[] { HipcBufferFlags.Out | HipcBufferFlags.MapAlias | HipcBufferFlags.FixedSize },
stackalloc[] { new PointerAndSize(bufferAddress, bufferSize) });
if (result.IsFailure)
{
return result;
}
applicationControlProperty = HorizonStatic.AddressSpace.Read<ApplicationControlProperty>(bufferAddress);
_allocator.Free(bufferAddress, bufferSize);
return Result.Success;
}
public void Dispose()
{
if (_sessionHandle != 0)
{
HorizonStatic.Syscall.CloseHandle(_sessionHandle);
_sessionHandle = 0;
}
GC.SuppressFinalize(this);
}
}
}

View File

@@ -0,0 +1,17 @@
using Ryujinx.Horizon.Common;
namespace Ryujinx.Horizon.Sdk.Arp
{
static class ArpResult
{
private const int ModuleId = 157;
public static Result InvalidArgument => new(ModuleId, 30);
public static Result InvalidPid => new(ModuleId, 31);
public static Result InvalidPointer => new(ModuleId, 32);
public static Result DataAlreadyBound => new(ModuleId, 42);
public static Result AllocationFailed => new(ModuleId, 63);
public static Result NoFreeInstance => new(ModuleId, 101);
public static Result InvalidInstanceId => new(ModuleId, 102);
}
}

View File

@@ -0,0 +1,13 @@
using Ryujinx.Horizon.Sdk.Ns;
namespace Ryujinx.Horizon.Sdk.Arp.Detail
{
class ApplicationInstance
{
public ulong Pid { get; set; }
public ApplicationLaunchProperty? LaunchProperty { get; set; }
public ApplicationProcessProperty? ProcessProperty { get; set; }
public ApplicationControlProperty? ControlProperty { get; set; }
public ApplicationCertificate? Certificate { get; set; }
}
}

View File

@@ -0,0 +1,31 @@
using Ryujinx.Horizon.Sdk.OsTypes;
using System;
using System.Threading;
namespace Ryujinx.Horizon.Sdk.Arp.Detail
{
class ApplicationInstanceManager : IDisposable
{
private int _disposalState;
public SystemEventType SystemEvent;
public int EventHandle;
public readonly ApplicationInstance[] Entries = new ApplicationInstance[2];
public ApplicationInstanceManager()
{
Os.CreateSystemEvent(out SystemEvent, EventClearMode.ManualClear, true).AbortOnFailure();
EventHandle = Os.GetReadableHandleOfSystemEvent(ref SystemEvent);
}
public void Dispose()
{
if (EventHandle != 0 && Interlocked.Exchange(ref _disposalState, 1) == 0)
{
Os.DestroySystemEvent(ref SystemEvent);
}
}
}
}

View File

@@ -0,0 +1,18 @@
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Ns;
using System;
namespace Ryujinx.Horizon.Sdk.Arp
{
public interface IReader
{
public Result GetApplicationLaunchProperty(out ApplicationLaunchProperty applicationLaunchProperty, ulong applicationInstanceId);
public Result GetApplicationControlProperty(out ApplicationControlProperty applicationControlProperty, ulong applicationInstanceId);
public Result GetApplicationProcessProperty(out ApplicationProcessProperty applicationControlProperty, ulong applicationInstanceId);
public Result GetApplicationInstanceId(out ulong applicationInstanceId, ulong pid);
public Result GetApplicationInstanceUnregistrationNotifier(out IUnregistrationNotifier unregistrationNotifier);
public Result ListApplicationInstanceId(out int count, Span<ulong> applicationInstanceIdList);
public Result GetMicroApplicationInstanceId(out ulong MicroApplicationInstanceId, ulong pid);
public Result GetApplicationCertificate(out ApplicationCertificate applicationCertificate, ulong applicationInstanceId);
}
}

View File

@@ -0,0 +1,12 @@
using Ryujinx.Horizon.Common;
using Ryujinx.Horizon.Sdk.Ns;
namespace Ryujinx.Horizon.Sdk.Arp
{
public interface IRegistrar
{
public Result Issue(out ulong applicationInstanceId);
public Result SetApplicationLaunchProperty(ApplicationLaunchProperty applicationLaunchProperty);
public Result SetApplicationControlProperty(in ApplicationControlProperty applicationControlProperty);
}
}

View File

@@ -0,0 +1,9 @@
using Ryujinx.Horizon.Common;
namespace Ryujinx.Horizon.Sdk.Arp
{
public interface IUnregistrationNotifier
{
public Result GetReadableHandle(out int readableHandle);
}
}

View File

@@ -0,0 +1,12 @@
using Ryujinx.Horizon.Common;
namespace Ryujinx.Horizon.Sdk.Arp
{
public interface IUpdater
{
public Result Issue();
public Result SetApplicationProcessProperty(ulong pid, ApplicationProcessProperty applicationProcessProperty);
public Result DeleteApplicationProcessProperty();
public Result SetApplicationCertificate(ApplicationCertificate applicationCertificate);
}
}

View File

@@ -0,0 +1,12 @@
using Ryujinx.Horizon.Common;
namespace Ryujinx.Horizon.Sdk.Arp
{
public interface IWriter
{
public Result AcquireRegistrar(out IRegistrar registrar);
public Result UnregisterApplicationInstance(ulong applicationInstanceId);
public Result AcquireApplicationProcessPropertyUpdater(out IUpdater updater, ulong applicationInstanceId);
public Result AcquireApplicationCertificateUpdater(out IUpdater updater, ulong applicationInstanceId);
}
}

View File

@@ -1,6 +1,6 @@
namespace Ryujinx.Horizon.Sdk.Ncm
{
readonly struct ApplicationId
public readonly struct ApplicationId
{
public readonly ulong Id;

View File

@@ -0,0 +1,13 @@
namespace Ryujinx.Horizon.Sdk.Ncm
{
public enum StorageId : byte
{
None,
Host,
GameCard,
BuiltInSystem,
BuiltInUser,
SdCard,
Any,
}
}

View File

@@ -0,0 +1,309 @@
using Ryujinx.Common.Memory;
using Ryujinx.Horizon.Sdk.Arp.Detail;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
namespace Ryujinx.Horizon.Sdk.Ns
{
public struct ApplicationControlProperty
{
public Array16<ApplicationTitle> Title;
public Array37<byte> Isbn;
public StartupUserAccountValue StartupUserAccount;
public UserAccountSwitchLockValue UserAccountSwitchLock;
public AddOnContentRegistrationTypeValue AddOnContentRegistrationType;
public AttributeFlagValue AttributeFlag;
public uint SupportedLanguageFlag;
public ParentalControlFlagValue ParentalControlFlag;
public ScreenshotValue Screenshot;
public VideoCaptureValue VideoCapture;
public DataLossConfirmationValue DataLossConfirmation;
public PlayLogPolicyValue PlayLogPolicy;
public ulong PresenceGroupId;
public Array32<sbyte> RatingAge;
public Array16<byte> DisplayVersion;
public ulong AddOnContentBaseId;
public ulong SaveDataOwnerId;
public long UserAccountSaveDataSize;
public long UserAccountSaveDataJournalSize;
public long DeviceSaveDataSize;
public long DeviceSaveDataJournalSize;
public long BcatDeliveryCacheStorageSize;
public Array8<byte> ApplicationErrorCodeCategory;
public Array8<ulong> LocalCommunicationId;
public LogoTypeValue LogoType;
public LogoHandlingValue LogoHandling;
public RuntimeAddOnContentInstallValue RuntimeAddOnContentInstall;
public RuntimeParameterDeliveryValue RuntimeParameterDelivery;
public Array2<byte> Reserved30F4;
public CrashReportValue CrashReport;
public HdcpValue Hdcp;
public ulong SeedForPseudoDeviceId;
public Array65<byte> BcatPassphrase;
public StartupUserAccountOptionFlagValue StartupUserAccountOption;
public Array6<byte> ReservedForUserAccountSaveDataOperation;
public long UserAccountSaveDataSizeMax;
public long UserAccountSaveDataJournalSizeMax;
public long DeviceSaveDataSizeMax;
public long DeviceSaveDataJournalSizeMax;
public long TemporaryStorageSize;
public long CacheStorageSize;
public long CacheStorageJournalSize;
public long CacheStorageDataAndJournalSizeMax;
public ushort CacheStorageIndexMax;
public byte Reserved318A;
public byte RuntimeUpgrade;
public uint SupportingLimitedLicenses;
public Array16<ulong> PlayLogQueryableApplicationId;
public PlayLogQueryCapabilityValue PlayLogQueryCapability;
public RepairFlagValue RepairFlag;
public byte ProgramIndex;
public RequiredNetworkServiceLicenseOnLaunchValue RequiredNetworkServiceLicenseOnLaunchFlag;
public Array4<byte> Reserved3214;
public ApplicationNeighborDetectionClientConfiguration NeighborDetectionClientConfiguration;
public ApplicationJitConfiguration JitConfiguration;
public RequiredAddOnContentsSetBinaryDescriptor RequiredAddOnContentsSetBinaryDescriptors;
public PlayReportPermissionValue PlayReportPermission;
public CrashScreenshotForProdValue CrashScreenshotForProd;
public CrashScreenshotForDevValue CrashScreenshotForDev;
public byte ContentsAvailabilityTransitionPolicy;
public Array4<byte> Reserved3404;
public AccessibleLaunchRequiredVersionValue AccessibleLaunchRequiredVersion;
public ByteArray3000 Reserved3448;
public readonly string IsbnString => Encoding.UTF8.GetString(Isbn.AsSpan()).TrimEnd('\0');
public readonly string DisplayVersionString => Encoding.UTF8.GetString(DisplayVersion.AsSpan()).TrimEnd('\0');
public readonly string ApplicationErrorCodeCategoryString => Encoding.UTF8.GetString(ApplicationErrorCodeCategory.AsSpan()).TrimEnd('\0');
public readonly string BcatPassphraseString => Encoding.UTF8.GetString(BcatPassphrase.AsSpan()).TrimEnd('\0');
public struct ApplicationTitle
{
public ByteArray512 Name;
public Array256<byte> Publisher;
public readonly string NameString => Encoding.UTF8.GetString(Name.AsSpan()).TrimEnd('\0');
public readonly string PublisherString => Encoding.UTF8.GetString(Publisher.AsSpan()).TrimEnd('\0');
}
public struct ApplicationNeighborDetectionClientConfiguration
{
public ApplicationNeighborDetectionGroupConfiguration SendGroupConfiguration;
public Array16<ApplicationNeighborDetectionGroupConfiguration> ReceivableGroupConfigurations;
}
public struct ApplicationNeighborDetectionGroupConfiguration
{
public ulong GroupId;
public Array16<byte> Key;
}
public struct ApplicationJitConfiguration
{
public JitConfigurationFlag Flags;
public long MemorySize;
}
public struct RequiredAddOnContentsSetBinaryDescriptor
{
public Array32<ushort> Descriptors;
}
public struct AccessibleLaunchRequiredVersionValue
{
public Array8<ulong> ApplicationId;
}
public enum Language
{
AmericanEnglish = 0,
BritishEnglish = 1,
Japanese = 2,
French = 3,
German = 4,
LatinAmericanSpanish = 5,
Spanish = 6,
Italian = 7,
Dutch = 8,
CanadianFrench = 9,
Portuguese = 10,
Russian = 11,
Korean = 12,
TraditionalChinese = 13,
SimplifiedChinese = 14,
BrazilianPortuguese = 15,
}
public enum Organization
{
CERO = 0,
GRACGCRB = 1,
GSRMR = 2,
ESRB = 3,
ClassInd = 4,
USK = 5,
PEGI = 6,
PEGIPortugal = 7,
PEGIBBFC = 8,
Russian = 9,
ACB = 10,
OFLC = 11,
IARCGeneric = 12,
}
public enum StartupUserAccountValue : byte
{
None = 0,
Required = 1,
RequiredWithNetworkServiceAccountAvailable = 2,
}
public enum UserAccountSwitchLockValue : byte
{
Disable = 0,
Enable = 1,
}
public enum AddOnContentRegistrationTypeValue : byte
{
AllOnLaunch = 0,
OnDemand = 1,
}
[Flags]
public enum AttributeFlagValue
{
None = 0,
Demo = 1 << 0,
RetailInteractiveDisplay = 1 << 1,
}
public enum ParentalControlFlagValue
{
None = 0,
FreeCommunication = 1,
}
public enum ScreenshotValue : byte
{
Allow = 0,
Deny = 1,
}
public enum VideoCaptureValue : byte
{
Disable = 0,
Manual = 1,
Enable = 2,
}
public enum DataLossConfirmationValue : byte
{
None = 0,
Required = 1,
}
public enum PlayLogPolicyValue : byte
{
Open = 0,
LogOnly = 1,
None = 2,
Closed = 3,
All = Open,
}
public enum LogoTypeValue : byte
{
LicensedByNintendo = 0,
DistributedByNintendo = 1,
Nintendo = 2,
}
public enum LogoHandlingValue : byte
{
Auto = 0,
Manual = 1,
}
public enum RuntimeAddOnContentInstallValue : byte
{
Deny = 0,
AllowAppend = 1,
AllowAppendButDontDownloadWhenUsingNetwork = 2,
}
public enum RuntimeParameterDeliveryValue : byte
{
Always = 0,
AlwaysIfUserStateMatched = 1,
OnRestart = 2,
}
public enum CrashReportValue : byte
{
Deny = 0,
Allow = 1,
}
public enum HdcpValue : byte
{
None = 0,
Required = 1,
}
[Flags]
public enum StartupUserAccountOptionFlagValue : byte
{
None = 0,
IsOptional = 1 << 0,
}
public enum PlayLogQueryCapabilityValue : byte
{
None = 0,
WhiteList = 1,
All = 2,
}
[Flags]
public enum RepairFlagValue : byte
{
None = 0,
SuppressGameCardAccess = 1 << 0,
}
[Flags]
public enum RequiredNetworkServiceLicenseOnLaunchValue : byte
{
None = 0,
Common = 1 << 0,
}
[Flags]
public enum JitConfigurationFlag : ulong
{
None = 0,
Enabled = 1 << 0,
}
[Flags]
public enum PlayReportPermissionValue : byte
{
None = 0,
TargetMarketing = 1 << 0,
}
public enum CrashScreenshotForProdValue : byte
{
Deny = 0,
Allow = 1,
}
public enum CrashScreenshotForDevValue : byte
{
Deny = 0,
Allow = 1,
}
}
}

View File

@@ -35,5 +35,254 @@ namespace Ryujinx.Horizon.Sdk
return CmifMessage.ParseResponse(out response, HorizonStatic.AddressSpace.GetWritableRegion(tlsAddress, tlsSize).Memory.Span, false, 0);
}
public static Result SendRequest(
out CmifResponse response,
int sessionHandle,
uint requestId,
bool sendPid,
scoped ReadOnlySpan<byte> data,
ReadOnlySpan<HipcBufferFlags> bufferFlags,
ReadOnlySpan<PointerAndSize> buffers)
{
ulong tlsAddress = HorizonStatic.ThreadContext.TlsAddress;
int tlsSize = Api.TlsMessageBufferSize;
using (var tlsRegion = HorizonStatic.AddressSpace.GetWritableRegion(tlsAddress, tlsSize))
{
CmifRequestFormat format = new()
{
DataSize = data.Length,
RequestId = requestId,
SendPid = sendPid,
};
for (int index = 0; index < bufferFlags.Length; index++)
{
FormatProcessBuffer(ref format, bufferFlags[index]);
}
CmifRequest request = CmifMessage.CreateRequest(tlsRegion.Memory.Span, format);
for (int index = 0; index < buffers.Length; index++)
{
RequestProcessBuffer(ref request, buffers[index], bufferFlags[index]);
}
data.CopyTo(request.Data);
}
Result result = HorizonStatic.Syscall.SendSyncRequest(sessionHandle);
if (result.IsFailure)
{
response = default;
return result;
}
return CmifMessage.ParseResponse(out response, HorizonStatic.AddressSpace.GetWritableRegion(tlsAddress, tlsSize).Memory.Span, false, 0);
}
private static void FormatProcessBuffer(ref CmifRequestFormat format, HipcBufferFlags flags)
{
if (flags == 0)
{
return;
}
bool isIn = flags.HasFlag(HipcBufferFlags.In);
bool isOut = flags.HasFlag(HipcBufferFlags.Out);
if (flags.HasFlag(HipcBufferFlags.AutoSelect))
{
if (isIn)
{
format.InAutoBuffersCount++;
}
if (isOut)
{
format.OutAutoBuffersCount++;
}
}
else if (flags.HasFlag(HipcBufferFlags.Pointer))
{
if (isIn)
{
format.InPointersCount++;
}
if (isOut)
{
if (flags.HasFlag(HipcBufferFlags.FixedSize))
{
format.OutFixedPointersCount++;
}
else
{
format.OutPointersCount++;
}
}
}
else if (flags.HasFlag(HipcBufferFlags.MapAlias))
{
if (isIn && isOut)
{
format.InOutBuffersCount++;
}
else if (isIn)
{
format.InBuffersCount++;
}
else
{
format.OutBuffersCount++;
}
}
}
private static void RequestProcessBuffer(ref CmifRequest request, PointerAndSize buffer, HipcBufferFlags flags)
{
if (flags == 0)
{
return;
}
bool isIn = flags.HasFlag(HipcBufferFlags.In);
bool isOut = flags.HasFlag(HipcBufferFlags.Out);
if (flags.HasFlag(HipcBufferFlags.AutoSelect))
{
HipcBufferMode mode = HipcBufferMode.Normal;
if (flags.HasFlag(HipcBufferFlags.MapTransferAllowsNonSecure))
{
mode = HipcBufferMode.NonSecure;
}
if (flags.HasFlag(HipcBufferFlags.MapTransferAllowsNonDevice))
{
mode = HipcBufferMode.NonDevice;
}
if (isIn)
{
RequestInAutoBuffer(ref request, buffer.Address, buffer.Size, mode);
}
if (isOut)
{
RequestOutAutoBuffer(ref request, buffer.Address, buffer.Size, mode);
}
}
else if (flags.HasFlag(HipcBufferFlags.Pointer))
{
if (isIn)
{
RequestInPointer(ref request, buffer.Address, buffer.Size);
}
if (isOut)
{
if (flags.HasFlag(HipcBufferFlags.FixedSize))
{
RequestOutFixedPointer(ref request, buffer.Address, buffer.Size);
}
else
{
RequestOutPointer(ref request, buffer.Address, buffer.Size);
}
}
}
else if (flags.HasFlag(HipcBufferFlags.MapAlias))
{
HipcBufferMode mode = HipcBufferMode.Normal;
if (flags.HasFlag(HipcBufferFlags.MapTransferAllowsNonSecure))
{
mode = HipcBufferMode.NonSecure;
}
if (flags.HasFlag(HipcBufferFlags.MapTransferAllowsNonDevice))
{
mode = HipcBufferMode.NonDevice;
}
if (isIn && isOut)
{
RequestInOutBuffer(ref request, buffer.Address, buffer.Size, mode);
}
else if (isIn)
{
RequestInBuffer(ref request, buffer.Address, buffer.Size, mode);
}
else
{
RequestOutBuffer(ref request, buffer.Address, buffer.Size, mode);
}
}
}
private static void RequestInAutoBuffer(ref CmifRequest request, ulong bufferAddress, ulong bufferSize, HipcBufferMode mode)
{
if (request.ServerPointerSize != 0 && bufferSize <= (ulong)request.ServerPointerSize)
{
RequestInPointer(ref request, bufferAddress, bufferSize);
RequestInBuffer(ref request, 0UL, 0UL, mode);
}
else
{
RequestInPointer(ref request, 0UL, 0UL);
RequestInBuffer(ref request, bufferAddress, bufferSize, mode);
}
}
private static void RequestOutAutoBuffer(ref CmifRequest request, ulong bufferAddress, ulong bufferSize, HipcBufferMode mode)
{
if (request.ServerPointerSize != 0 && bufferSize <= (ulong)request.ServerPointerSize)
{
RequestOutPointer(ref request, bufferAddress, bufferSize);
RequestOutBuffer(ref request, 0UL, 0UL, mode);
}
else
{
RequestOutPointer(ref request, 0UL, 0UL);
RequestOutBuffer(ref request, bufferAddress, bufferSize, mode);
}
}
private static void RequestInBuffer(ref CmifRequest request, ulong bufferAddress, ulong bufferSize, HipcBufferMode mode)
{
request.Hipc.SendBuffers[request.SendBufferIndex++] = new HipcBufferDescriptor(bufferAddress, bufferSize, mode);
}
private static void RequestOutBuffer(ref CmifRequest request, ulong bufferAddress, ulong bufferSize, HipcBufferMode mode)
{
request.Hipc.ReceiveBuffers[request.RecvBufferIndex++] = new HipcBufferDescriptor(bufferAddress, bufferSize, mode);
}
private static void RequestInOutBuffer(ref CmifRequest request, ulong bufferAddress, ulong bufferSize, HipcBufferMode mode)
{
request.Hipc.ExchangeBuffers[request.ExchBufferIndex++] = new HipcBufferDescriptor(bufferAddress, bufferSize, mode);
}
private static void RequestInPointer(ref CmifRequest request, ulong bufferAddress, ulong bufferSize)
{
request.Hipc.SendStatics[request.SendStaticIndex++] = new HipcStaticDescriptor(bufferAddress, (ushort)bufferSize, request.CurrentInPointerId++);
request.ServerPointerSize -= (int)bufferSize;
}
private static void RequestOutFixedPointer(ref CmifRequest request, ulong bufferAddress, ulong bufferSize)
{
request.Hipc.ReceiveList[request.RecvListIndex++] = new HipcReceiveListEntry(bufferAddress, (ushort)bufferSize);
request.ServerPointerSize -= (int)bufferSize;
}
private static void RequestOutPointer(ref CmifRequest request, ulong bufferAddress, ulong bufferSize)
{
RequestOutFixedPointer(ref request, bufferAddress, bufferSize);
request.OutPointerSizes[request.OutPointerSizeIndex++] = (ushort)bufferSize;
}
}
}

View File

@@ -10,5 +10,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Cmif
public Span<ushort> OutPointerSizes;
public Span<uint> Objects;
public int ServerPointerSize;
public int CurrentInPointerId;
public int SendBufferIndex;
public int RecvBufferIndex;
public int ExchBufferIndex;
public int SendStaticIndex;
public int RecvListIndex;
public int OutPointerSizeIndex;
}
}

View File

@@ -11,5 +11,12 @@ namespace Ryujinx.Horizon.Sdk.Sf.Hipc
public ulong Address => _addressLow | (((ulong)_word2 << 4) & 0xf00000000UL) | (((ulong)_word2 << 34) & 0x7000000000UL);
public ulong Size => _sizeLow | ((ulong)_word2 << 8) & 0xf00000000UL;
public HipcBufferMode Mode => (HipcBufferMode)(_word2 & 3);
public HipcBufferDescriptor(ulong address, ulong size, HipcBufferMode mode)
{
_sizeLow = (uint)size;
_addressLow = (uint)address;
_word2 = (uint)mode | ((uint)(address >> 34) & 0x1c) | ((uint)(size >> 32) << 24) | ((uint)(address >> 4) & 0xf0000000);
}
}
}

View File

@@ -1,3 +1,4 @@
using Ryujinx.Horizon.Arp;
using Ryujinx.Horizon.Bcat;
using Ryujinx.Horizon.Hshl;
using Ryujinx.Horizon.Ins;
@@ -8,6 +9,7 @@ using Ryujinx.Horizon.Ngc;
using Ryujinx.Horizon.Ovln;
using Ryujinx.Horizon.Prepo;
using Ryujinx.Horizon.Psc;
using Ryujinx.Horizon.Sdk.Arp;
using Ryujinx.Horizon.Srepo;
using Ryujinx.Horizon.Usb;
using Ryujinx.Horizon.Wlan;
@@ -23,6 +25,9 @@ namespace Ryujinx.Horizon
private readonly ManualResetEvent _servicesReadyEvent = new(false);
public IReader ArpReader { get; internal set; }
public IWriter ArpWriter { get; internal set; }
public IEnumerable<ServiceEntry> GetServices(HorizonOptions options)
{
List<ServiceEntry> entries = new();
@@ -32,6 +37,7 @@ namespace Ryujinx.Horizon
entries.Add(new ServiceEntry(T.Main, this, options));
}
RegisterService<ArpMain>();
RegisterService<BcatMain>();
RegisterService<HshlMain>();
RegisterService<InsMain>();

View File

@@ -311,6 +311,46 @@ namespace Ryujinx.Tests.Cpu
};
}
private static uint[] _ShlImm_S_D_()
{
return new[]
{
0x5F407400u, // SQSHL D0, D0, #0
};
}
private static uint[] _ShlImm_V_8B_16B_()
{
return new[]
{
0x0F087400u, // SQSHL V0.8B, V0.8B, #0
};
}
private static uint[] _ShlImm_V_4H_8H_()
{
return new[]
{
0x0F107400u, // SQSHL V0.4H, V0.4H, #0
};
}
private static uint[] _ShlImm_V_2S_4S_()
{
return new[]
{
0x0F207400u, // SQSHL V0.2S, V0.2S, #0
};
}
private static uint[] _ShlImm_V_2D_()
{
return new[]
{
0x4F407400u, // SQSHL V0.2D, V0.2D, #0
};
}
private static uint[] _ShrImm_Sri_S_D_()
{
return new[]
@@ -813,6 +853,117 @@ namespace Ryujinx.Tests.Cpu
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void ShlImm_S_D([ValueSource(nameof(_ShlImm_S_D_))] uint opcodes,
[Values(0u)] uint rd,
[Values(1u, 0u)] uint rn,
[ValueSource(nameof(_1D_))] ulong z,
[ValueSource(nameof(_1D_))] ulong a,
[Values(1u, 64u)] uint shift)
{
uint immHb = (64 + shift) & 0x7F;
opcodes |= ((rn & 31) << 5) | ((rd & 31) << 0);
opcodes |= (immHb << 16);
V128 v0 = MakeVectorE0E1(z, z);
V128 v1 = MakeVectorE0(a);
SingleOpcode(opcodes, v0: v0, v1: v1);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void ShlImm_V_8B_16B([ValueSource(nameof(_ShlImm_V_8B_16B_))] uint opcodes,
[Values(0u)] uint rd,
[Values(1u, 0u)] uint rn,
[ValueSource(nameof(_8B_))] ulong z,
[ValueSource(nameof(_8B_))] ulong a,
[Values(1u, 8u)] uint shift,
[Values(0b0u, 0b1u)] uint q) // <8B, 16B>
{
uint immHb = (8 + shift) & 0x7F;
opcodes |= ((rn & 31) << 5) | ((rd & 31) << 0);
opcodes |= (immHb << 16);
opcodes |= ((q & 1) << 30);
V128 v0 = MakeVectorE0E1(z, z);
V128 v1 = MakeVectorE0E1(a, a * q);
SingleOpcode(opcodes, v0: v0, v1: v1);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void ShlImm_V_4H_8H([ValueSource(nameof(_ShlImm_V_4H_8H_))] uint opcodes,
[Values(0u)] uint rd,
[Values(1u, 0u)] uint rn,
[ValueSource(nameof(_4H_))] ulong z,
[ValueSource(nameof(_4H_))] ulong a,
[Values(1u, 16u)] uint shift,
[Values(0b0u, 0b1u)] uint q) // <4H, 8H>
{
uint immHb = (16 + shift) & 0x7F;
opcodes |= ((rn & 31) << 5) | ((rd & 31) << 0);
opcodes |= (immHb << 16);
opcodes |= ((q & 1) << 30);
V128 v0 = MakeVectorE0E1(z, z);
V128 v1 = MakeVectorE0E1(a, a * q);
SingleOpcode(opcodes, v0: v0, v1: v1);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void ShlImm_V_2S_4S([ValueSource(nameof(_ShlImm_V_2S_4S_))] uint opcodes,
[Values(0u)] uint rd,
[Values(1u, 0u)] uint rn,
[ValueSource(nameof(_2S_))] ulong z,
[ValueSource(nameof(_2S_))] ulong a,
[Values(1u, 32u)] uint shift,
[Values(0b0u, 0b1u)] uint q) // <2S, 4S>
{
uint immHb = (32 + shift) & 0x7F;
opcodes |= ((rn & 31) << 5) | ((rd & 31) << 0);
opcodes |= (immHb << 16);
opcodes |= (((q | (immHb >> 6)) & 1) << 30);
V128 v0 = MakeVectorE0E1(z, z);
V128 v1 = MakeVectorE0E1(a, a * q);
SingleOpcode(opcodes, v0: v0, v1: v1);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void ShlImm_V_2D([ValueSource(nameof(_ShlImm_V_2D_))] uint opcodes,
[Values(0u)] uint rd,
[Values(1u, 0u)] uint rn,
[ValueSource(nameof(_1D_))] ulong z,
[ValueSource(nameof(_1D_))] ulong a,
[Values(1u, 64u)] uint shift)
{
uint immHb = (64 + shift) & 0x7F;
opcodes |= ((rn & 31) << 5) | ((rd & 31) << 0);
opcodes |= (immHb << 16);
V128 v0 = MakeVectorE0E1(z, z);
V128 v1 = MakeVectorE0E1(a, a);
SingleOpcode(opcodes, v0: v0, v1: v1);
CompareAgainstUnicorn();
}
[Test, Pairwise]
public void ShrImm_Sri_S_D([ValueSource(nameof(_ShrImm_Sri_S_D_))] uint opcodes,
[Values(0u)] uint rd,

View File

@@ -54,6 +54,7 @@ namespace Ryujinx.Ui.Common.Helper
{
string basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Ryujinx");
var plistFile = EmbeddedResources.ReadAllText("Ryujinx.Ui.Common/shortcut-template.plist");
var shortcutScript = EmbeddedResources.ReadAllText("Ryujinx.Ui.Common/shortcut-launch-script.sh");
// Macos .App folder
string contentFolderPath = Path.Combine("/Applications", cleanedAppName + ".app", "Contents");
string scriptFolderPath = Path.Combine(contentFolderPath, "MacOS");
@@ -68,8 +69,7 @@ namespace Ryujinx.Ui.Common.Helper
string scriptPath = Path.Combine(scriptFolderPath, ScriptName);
using StreamWriter scriptFile = new(scriptPath);
scriptFile.WriteLine("#!/bin/sh");
scriptFile.WriteLine($"{basePath} {GetArgsString(appFilePath)}");
scriptFile.Write(shortcutScript, basePath, GetArgsString(appFilePath));
// Set execute permission
FileInfo fileInfo = new(scriptPath);

View File

@@ -51,6 +51,7 @@
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'osx-x64' OR '$(RuntimeIdentifier)' == 'osx-arm64' OR '$(RuntimeIdentifier)' == ''">
<EmbeddedResource Include="..\..\distribution\macos\shortcut-template.plist" />
<EmbeddedResource Include="..\..\distribution\macos\shortcut-launch-script.sh" />
</ItemGroup>
<ItemGroup>