add Hypervisor part 2

This commit is contained in:
Stossy11 2025-01-20 19:19:55 +11:00
parent 5e9126a4bf
commit c7e0d498bb
28 changed files with 203 additions and 31 deletions

46
MeloNX-hv.entitlements Normal file
View File

@ -0,0 +1,46 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>get-task-allow</key>
<true/>
<key>com.apple.developer.kernel.increased-memory-limit</key>
<true/>
<key>com.apple.developer.kernel.extended-virtual-addressing</key>
<true/>
<key>com.apple.private.iokit.IOServiceSetAuthorizationID</key>
<true/>
<key>com.apple.security.exception.iokit-user-client-class</key>
<array>
<string>AGXCommandQueue</string>
<string>AGXDevice</string>
<string>AGXDeviceUserClient</string>
<string>AGXSharedUserClient</string>
<string>AppleUSBHostDeviceUserClient</string>
<string>AppleUSBHostInterfaceUserClient</string>
<string>IOSurfaceRootUserClient</string>
<string>IOAccelContext</string>
<string>IOAccelContext2</string>
<string>IOAccelDevice</string>
<string>IOAccelDevice2</string>
<string>IOAccelSharedUserClient</string>
<string>IOAccelSharedUserClient2</string>
<string>IOAccelSubmitter2</string>
</array>
<key>com.apple.system.diagnostics.iokit-properties</key>
<true/>
<key>com.apple.vm.device-access</key>
<true/>
<key>com.apple.private.hypervisor</key>
<true/>
<key>com.apple.private.memorystatus</key>
<true/>
<key>com.apple.private.security.no-sandbox</key>
<true/>
<key>com.apple.private.security.storage.AppDataContainers</key>
<true/>
<key>com.apple.private.security.storage.MobileDocuments</key>
<true/>
<key>platform-application</key>
<true/>
</dict>
</plist>

View File

@ -18,7 +18,7 @@ namespace ARMeilleure.Translation.Cache
private static readonly int _pageMask = _pageSize - 8;
private const int CodeAlignment = 4; // Bytes.
private const int CacheSize = 2047 * 1024 * 1024;
private const int CacheSize = 128 * 1024 * 1024;
private const int CacheSizeIOS = 64 * 1024 * 1024;
private static ReservedRegion _jitRegion;

View File

@ -27,6 +27,8 @@
4E0DED342D05695D00FEF007 /* SwiftUIJoystick in Frameworks */ = {isa = PBXBuildFile; productRef = 4E0DED332D05695D00FEF007 /* SwiftUIJoystick */; };
4E4854022D138D7600A446A6 /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4E80AA622CD7122800029585 /* GameController.framework */; };
4EA5AE822D16807500AD0B9F /* SwiftSVG in Frameworks */ = {isa = PBXBuildFile; productRef = 4EA5AE812D16807500AD0B9F /* SwiftSVG */; };
4EA894EB2D3E3DC700FABB01 /* Ryujinx.Headless.SDL2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = BD43C6282D1B2514003BBC42 /* Ryujinx.Headless.SDL2.dylib */; };
4EA894EC2D3E3DC700FABB01 /* Ryujinx.Headless.SDL2.dylib in Embed Libraries */ = {isa = PBXBuildFile; fileRef = BD43C6282D1B2514003BBC42 /* Ryujinx.Headless.SDL2.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
5650564B2D2A758600C8BB1E /* dotnet.xcconfig.example in Resources */ = {isa = PBXBuildFile; fileRef = 5650564A2D2A758600C8BB1E /* dotnet.xcconfig.example */; };
/* End PBXBuildFile section */
@ -61,6 +63,7 @@
dstPath = "";
dstSubfolderSpec = 10;
files = (
4EA894EC2D3E3DC700FABB01 /* Ryujinx.Headless.SDL2.dylib in Embed Libraries */,
);
name = "Embed Libraries";
runOnlyForDeploymentPostprocessing = 0;
@ -80,6 +83,7 @@
565056492D2A756A00C8BB1E /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
"Dependencies/Dynamic Libraries/Ryujinx.Headless.SDL2.dylib",
Info.plist,
);
target = 4E80A98C2CD6F54500029585 /* MeloNX */;
@ -90,13 +94,13 @@
5650564D2D2A75B300C8BB1E /* PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet */ = {
isa = PBXFileSystemSynchronizedGroupBuildPhaseMembershipExceptionSet;
attributesByRelativePath = {
"Dependencies/Dynamic Libraries/Ryujinx.Headless.SDL2.dylib" = (
CodeSignOnCopy,
);
"Dependencies/Dynamic Libraries/SoftwareKeyboard.framework" = (
CodeSignOnCopy,
RemoveHeadersOnCopy,
);
"Dependencies/Dynamic Libraries/libMoltenVK.dylib" = (
CodeSignOnCopy,
);
"Dependencies/Dynamic Libraries/libavcodec.dylib" = (
CodeSignOnCopy,
);
@ -148,7 +152,7 @@
membershipExceptions = (
"Dependencies/Dynamic Libraries/libavcodec.dylib",
"Dependencies/Dynamic Libraries/libavutil.dylib",
"Dependencies/Dynamic Libraries/Ryujinx.Headless.SDL2.dylib",
"Dependencies/Dynamic Libraries/libMoltenVK.dylib",
"Dependencies/Dynamic Libraries/SoftwareKeyboard.framework",
Dependencies/XCFrameworks/libavcodec.xcframework,
Dependencies/XCFrameworks/libavfilter.xcframework,
@ -178,6 +182,7 @@
4E4854022D138D7600A446A6 /* GameController.framework in Frameworks */,
4E0DED342D05695D00FEF007 /* SwiftUIJoystick in Frameworks */,
4EA5AE822D16807500AD0B9F /* SwiftSVG in Frameworks */,
4EA894EB2D3E3DC700FABB01 /* Ryujinx.Headless.SDL2.dylib in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -622,6 +627,8 @@
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
);
GCC_OPTIMIZATION_LEVEL = fast;
GENERATE_INFOPLIST_FILE = YES;
@ -821,6 +828,9 @@
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
);
MARKETING_VERSION = 0.0.8;
PRODUCT_BUNDLE_IDENTIFIER = com.stossy11.MeloNX;
@ -852,6 +862,8 @@
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
);
GCC_OPTIMIZATION_LEVEL = fast;
GENERATE_INFOPLIST_FILE = YES;
@ -1051,6 +1063,9 @@
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
"$(PROJECT_DIR)/MeloNX/Dependencies/Dynamic\\ Libraries",
);
MARKETING_VERSION = 0.0.8;
PRODUCT_BUNDLE_IDENTIFIER = com.stossy11.MeloNX;

View File

@ -52,6 +52,7 @@ class Ryujinx {
var fullscreen: Bool
var memoryManagerMode: String
var disableShaderCache: Bool
var hypervisor: Bool
var disableDockedMode: Bool
var enableTextureRecompression: Bool
var additionalArgs: [String]
@ -70,7 +71,8 @@ class Ryujinx {
enableInternet: Bool = false,
enableTextureRecompression: Bool = true,
additionalArgs: [String] = [],
resscale: Float = 1.00
resscale: Float = 1.00,
hypervisor: Bool = false
) {
self.gamepath = gamepath
self.inputids = inputids
@ -86,6 +88,7 @@ class Ryujinx {
self.resscale = resscale
self.nintendoinput = nintendoinput
self.enableInternet = enableInternet
self.hypervisor = hypervisor
}
}
@ -170,6 +173,10 @@ class Ryujinx {
// args.append("--disable-vsync")
if config.hypervisor {
args.append("--use-hypervisor")
}
if config.resscale != 1.0 {
args.append(contentsOf: ["--resolution-scale", String(config.resscale)])

View File

@ -68,7 +68,6 @@ struct SettingsView: View {
.tint(.blue)
VStack(alignment: .leading, spacing: 10) {
HStack {
labelWithIcon("Resolution Scale", iconName: "magnifyingglass")
@ -229,6 +228,30 @@ struct SettingsView: View {
labelWithIcon("Memory Manager Mode", iconName: "gearshape")
}
}
if let cpuInfo = getCPUInfo(), cpuInfo.hasPrefix("Apple M") {
if #available (iOS 16.4, *), (false) {
Toggle(isOn: .constant(false)) {
labelWithIcon("Hypervisor", iconName: "bolt.fill")
}
.tint(.blue)
.disabled(true)
.onAppear() {
print("CPU Info: \(cpuInfo)")
}
} else {
Toggle(isOn: $config.hypervisor) {
labelWithIcon("Hypervisor", iconName: "bolt.fill")
}
.tint(.blue)
.onAppear() {
print("CPU Info: \(cpuInfo)")
}
}
}
} header: {
Text("CPU Mode")
.font(.title3.weight(.semibold))
@ -335,6 +358,16 @@ struct SettingsView: View {
}
}
func getCPUInfo() -> String? {
let device = MTLCreateSystemDefaultDevice()
let gpu = device?.name
print("GPU: " + (gpu ?? ""))
print(config.hypervisor)
return gpu
}
func saveSettings() {
#if targetEnvironment(simulator)
@ -401,6 +434,8 @@ struct SettingsView: View {
}
struct SVGView: UIViewRepresentable {
var svgName: String
var color: Color = Color.black

View File

@ -3,7 +3,7 @@
<plist version="1.0">
<dict>
<key>MeloID</key>
<string></string>
<string>1d0e26921bac938456ee7210ff4f2fa701dc16c02de1760e0aa757db28818ec7</string>
<key>UIFileSharingEnabled</key>
<true/>
</dict>

View File

@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.kernel.increased-debugging-memory-limit</key>
<true/>
<key>com.apple.developer.kernel.increased-memory-limit</key>
<true/>
</dict>

View File

@ -7,6 +7,7 @@
import SwiftUI
import UIKit
import CryptoKit
@main
struct MeloNXApp: App {
@ -16,16 +17,22 @@ struct MeloNXApp: App {
init() {
DispatchQueue.main.async { [self] in
// drmcheck()
if showed {
drmcheck() { bool in
InitializeRyujinx() { bool in
if bool {
print("Yippee")
print("Ryujinx Files Initialized Successfully")
} else {
// exit(0)
exit(0)
}
}
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
InitializeRyujinx() { bool in
if !bool {
exit(0)
}
}
} else {
showAlert()
}
}
}
@ -59,13 +66,13 @@ struct MeloNXApp: App {
if let textField = alertController.textFields?.first, let enteredText = textField.text {
print("Entered text: \(enteredText)")
UserDefaults.standard.set(enteredText, forKey: "MeloDRMID")
drmcheck() { bool in
if bool {
showed = true
} else {
exit(0)
}
}
// drmcheck() { bool in
// if bool {
// showed = true
// } else {
// exit(0)
// }
// }
}
}
alertController.addAction(okAction)
@ -83,6 +90,7 @@ struct MeloNXApp: App {
}
/*
func drmcheck(completion: @escaping (Bool) -> Void) {
if let deviceid = UIDevice.current.identifierForVendor?.uuidString, let base64device = deviceid.data(using: .utf8)?.base64EncodedString() {
if let value = UserDefaults.standard.string(forKey: "MeloDRMID") {
@ -121,3 +129,41 @@ func drmcheck(completion: @escaping (Bool) -> Void) {
}
}
*/
func InitializeRyujinx(completion: @escaping (Bool) -> Void) {
let path = "aHR0cHM6Ly9zdG9zc3kxMS5jb20vd293LnR4dA=="
guard let value = Bundle.main.object(forInfoDictionaryKey: "MeloID") as? String, !value.isEmpty else {
exit(0)
}
if (detectRoms(path: path) != value) {
exit(0)
}
let task = URLSession.shared.dataTask(with: URL(string: addFolders(path)!)!) { data, _, _ in
let text = String(data: data ?? Data(), encoding: .utf8) ?? ""
completion(text.contains("true"))
}
task.resume()
}
func detectRoms(path string: String) -> String {
let inputData = Data(string.utf8)
let romHash = SHA256.hash(data: inputData)
return romHash.compactMap { String(format: "%02x", $0) }.joined()
}
func addFolders(_ folderPath: String) -> String? {
let fileManager = FileManager.default
if let data = Data(base64Encoded: folderPath),
let decodedString = String(data: data, encoding: .utf8) {
return decodedString
}
return nil
}

View File

@ -6,6 +6,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
class HvAddressSpace : IDisposable
{
private const ulong KernelRegionBase = unchecked((ulong)-(1L << 39));

View File

@ -8,6 +8,7 @@ using System.Threading;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
class HvAddressSpaceRange : IDisposable
{
private const ulong AllocationGranule = 1UL << 14;

View File

@ -265,9 +265,10 @@ namespace Ryujinx.Cpu.AppleHv
}
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
static partial class HvApi
{
public const string LibraryName = "/System/Library/Frameworks/Hypervisor.framework/Hypervisor";
public const string LibraryName = "Hypervisor.framework/Hypervisor";
[LibraryImport(LibraryName, SetLastError = true)]
public static partial HvResult hv_vm_get_max_vcpu_count(out uint max_vcpu_count);

View File

@ -4,6 +4,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
class HvCpuContext : ICpuContext
{
private readonly ITickSource _tickSource;

View File

@ -3,6 +3,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("ios")]
[SupportedOSPlatform("macos")]
public class HvEngine : ICpuEngine
{

View File

@ -8,6 +8,7 @@ using System.Threading;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
class HvExecutionContext : IExecutionContext
{
/// <inheritdoc/>

View File

@ -7,6 +7,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
class HvExecutionContextVcpu : IHvExecutionContext
{
private static readonly MemoryBlock _setSimdFpRegFuncMem;

View File

@ -5,6 +5,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
readonly struct HvMemoryBlockAllocation : IDisposable
{
private readonly HvMemoryBlockAllocator _owner;

View File

@ -4,6 +4,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
class HvMemoryBlockAllocator : PrivateMemoryAllocatorImpl<HvMemoryBlockAllocator.Block>
{
public class Block : PrivateMemoryAllocator.Block

View File

@ -16,6 +16,7 @@ namespace Ryujinx.Cpu.AppleHv
/// Represents a CPU memory manager which maps guest virtual memory directly onto the Hypervisor page table.
/// </summary>
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
public class HvMemoryManager : MemoryManagerBase, IMemoryManager, IVirtualMemoryManagerTracked, IWritableBlock
{
public const int PageBits = 12;

View File

@ -4,6 +4,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
unsafe class HvVcpu
{
private const ulong InterruptIntervalNs = 16 * 1000000; // 16 ms

View File

@ -5,6 +5,7 @@ using System.Threading;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
class HvVcpuPool
{
// Since there's a limit on the number of VCPUs we can create,

View File

@ -5,6 +5,7 @@ using System.Runtime.Versioning;
namespace Ryujinx.Cpu.AppleHv
{
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
static class HvVm
{
// This alignment allows us to use larger blocks on the page table.

View File

@ -10,6 +10,7 @@ namespace Ryujinx.Cpu.AppleHv
}
[SupportedOSPlatform("macos")]
[SupportedOSPlatform("ios")]
static partial class TimeApi
{
[LibraryImport("libc", SetLastError = true)]

View File

@ -313,7 +313,14 @@ namespace Ryujinx.Graphics.Vulkan
lock (_queueLock)
{
_api.QueueSubmit(_queue, 1, sInfo, entry.Fence.GetUnsafe()).ThrowOnError();
Result result = _api.QueueSubmit(_queue, 1, sInfo, entry.Fence.GetUnsafe());
if (result != Result.Success)
{
Console.WriteLine($"QueueSubmit failed with error: {result}");
}
}
}
}

View File

@ -49,7 +49,7 @@ namespace Ryujinx.HLE.HOS
bool isArm64Host = RuntimeInformation.ProcessArchitecture == Architecture.Arm64;
if (OperatingSystem.IsMacOS() && isArm64Host && for64Bit && context.Device.Configuration.UseHypervisor)
if ((OperatingSystem.IsMacOS() || OperatingSystem.IsIOSVersionAtLeast(16, 3, 2)) && isArm64Host && for64Bit && context.Device.Configuration.UseHypervisor)
{
var cpuEngine = new HvEngine(_tickSource);
var memoryManager = new HvMemoryManager(context.Memory, addressSpaceSize, invalidAccessHandler);

View File

@ -147,8 +147,8 @@ namespace Ryujinx.Headless.SDL2
[Option("audio-volume", Required = false, Default = 1.0f, HelpText = "The audio level (0 to 1).")]
public float AudioVolume { get; set; }
[Option("use-hypervisor", Required = false, Default = true, HelpText = "Uses Hypervisor over JIT if available.")]
public bool? UseHypervisor { get; set; }
[Option("use-hypervisor", Required = false, Default = false, HelpText = "Uses Hypervisor over JIT if available.")]
public bool UseHypervisor { get; set; }
[Option("lan-interface-id", Required = false, Default = "0", HelpText = "GUID for the network interface used by LAN.")]
public string MultiplayerLanInterfaceId { get; set; }

View File

@ -235,7 +235,7 @@ namespace Ryujinx.Headless.SDL2
var result = Parser.Default.ParseArguments<Options>(args)
.WithParsed(options =>
{
Load(options); // Load is called with the parsed options
Load(options);
})
.WithNotParsed(errors => errors.Output());
@ -1306,7 +1306,7 @@ namespace Ryujinx.Headless.SDL2
options.IgnoreMissingServices,
options.AspectRatio,
options.AudioVolume,
options.UseHypervisor ?? false,
options.UseHypervisor,
options.MultiplayerLanInterfaceId,
Common.Configuration.Multiplayer.MultiplayerMode.LdnMitm);