Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.
Swift apple-silicond3dmetaldxmtdxvkfexgame-porting-toolkitgamingmac-gamingmacosmetalmoltenvksteamswiftuivkd3d-protonwhisky-alternativewindows-gameswinewine-wrapper
A game's recipe can switch on athei's x87sidecar with HB_X87SIDECAR=1. Old 32-bit games do their maths on the x87 unit, which Rosetta runs slowly, and the sidecar compiles that code much faster (an x87 loop 884 to 40 ms on a base M4, Tale of Wuxia 4.4 to 45 fps, highball-db#352). The launch gets ROSETTA_X87_PATH only where the engine ships the sidecar and runs under Rosetta, never for every game, since the sidecar relies on how Rosetta lays out its translations and checks that at each start (#165). Steam restarts for a game whose sidecar setting differs from its own, since the game inherits it. Tests cover both.
Gauthier Piarrette4f58b29681e5
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swiftindex e85f606..42ad460 100644--- a/Sources/HighballKit/Bottle.swift+++ b/Sources/HighballKit/Bottle.swift@@ -923,6 +923,14 @@ public struct Bottle: Sendable {let inserted = (env["DYLD_INSERT_LIBRARIES"] ?? "").split(separator: ":").map(String.init)env["DYLD_INSERT_LIBRARIES"] = ([lib.path] + inserted.filter { $0 != lib.path }).joined(separator: ":")}+ // Old 32-bit games do their maths on the x87 unit, which Rosetta runs slowly. A game's recipe+ // asks for athei's x87sidecar with HB_X87SIDECAR=1, and it applies only where the engine+ // ships the sidecar and runs under Rosetta. Never on for everything: the sidecar relies on+ // how Rosetta lays out its translations, and checks that at each start (highball#165).+ env.removeValue(forKey: "ROSETTA_X87_PATH")+ if env["HB_X87SIDECAR"] == "1", engine.manifest.requiresRosetta, let sidecar = engine.x87Sidecar {+ env["ROSETTA_X87_PATH"] = sidecar.path+ }// A recipe's value can depend on this Mac (a video memory budget from its memory), and an engine's or a recipe's// on this environment (a driver's shader cache kept inside it, and gone with it).return env.mapValues { MacVariables.expand($0).replacingOccurrences(of: "${environment}", with: url.path) }diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swiftindex d34108c..9865e87 100644--- a/Sources/HighballKit/EngineStore.swift+++ b/Sources/HighballKit/EngineStore.swift@@ -638,6 +638,14 @@ public struct InstalledEngine: Sendable {let lib = frameworksDir.appending(path: "libhbaudiobuf.dylib")return FileManager.default.fileExists(atPath: lib.path) ? lib : nil}+ /// athei's x87sidecar (MIT), when the engine ships it as a component. Wine re-executes a+ /// 32-bit program through it when ROSETTA_X87_PATH names it (the Wine 11 engines' patch 0012,+ /// cooperative attach, no entitlements), and it compiles the program's x87 maths much faster+ /// than Rosetta does: Tale of Wuxia's maps went from 4.4 to 45 fps (highball-db#352).+ public var x87Sidecar: URL? {+ let tool = root.appending(path: "x87sidecar/x87sidecar")+ return FileManager.default.isExecutableFile(atPath: tool.path) ? tool : nil+ }public var renderersDir: URL { root.appending(path: "renderers", directoryHint: .isDirectory) }public var wineBinary: URL { engineDir.appending(path: "bin/wine") }public var wineserverBinary: URL { engineDir.appending(path: "bin/wineserver") }diff --git a/Sources/HighballKit/SteamRestart.swift b/Sources/HighballKit/SteamRestart.swiftindex 65ef1aa..6fb4f19 100644--- a/Sources/HighballKit/SteamRestart.swift+++ b/Sources/HighballKit/SteamRestart.swift@@ -103,6 +103,11 @@ public enum SteamRestart {for (key, what) in inherited where (live[key] == "1") != (wanted[key] == "1") {reasons.append("it runs with \(what) \(live[key] == "1" ? "on" : "off") and the game wants it \(wanted[key] == "1" ? "on" : "off")")}+ // Wine re-executes a 32-bit program through the x87 sidecar when it starts, and the game+ // inherits the variable from the client.+ if live["ROSETTA_X87_PATH"] != wanted["ROSETTA_X87_PATH"] {+ reasons.append("it runs with the x87 sidecar \(live["ROSETTA_X87_PATH"] == nil ? "off" : "on") and the game wants it \(wanted["ROSETTA_X87_PATH"] == nil ? "off" : "on")")+ }// Frame generation is a family of LSFGM_ variables the shim reads when the game starts,// so a toggle flipped while the client runs would otherwise leave the game where the// client was (highball#109 follow-up). Any difference in the family restarts the client.diff --git a/Tests/HighballKitTests/RendererAvailabilityTests.swift b/Tests/HighballKitTests/RendererAvailabilityTests.swiftindex 572ede7..9f3d9d4 100644--- a/Tests/HighballKitTests/RendererAvailabilityTests.swift+++ b/Tests/HighballKitTests/RendererAvailabilityTests.swift@@ -160,6 +160,23 @@ final class RendererAvailabilityTests: XCTestCase {XCTAssertNil(fine.note)}+ /// A game's recipe asks for athei's x87sidecar with HB_X87SIDECAR=1 (highball#165), and the+ /// launch gets ROSETTA_X87_PATH only where the engine ships the sidecar.+ func testTheX87SidecarIsSetOnlyForAGameThatAsksAndAnEngineThatShipsIt() throws {+ let e = try engine(accepted: false)+ var asks = bottle(renderer: .dxmt)+ asks.settings.environment = ["HB_X87SIDECAR": "1"]+ XCTAssertNil(try asks.environment(engine: e)["ROSETTA_X87_PATH"], "no sidecar in this engine")+ let tool = e.root.appending(path: "x87sidecar/x87sidecar")+ try FileManager.default.createDirectory(at: tool.deletingLastPathComponent(), withIntermediateDirectories: true)+ FileManager.default.createFile(atPath: tool.path, contents: Data(), attributes: [.posixPermissions: 0o755])+ XCTAssertEqual(try asks.environment(engine: e)["ROSETTA_X87_PATH"], tool.path)+ XCTAssertNil(try bottle(renderer: .dxmt).environment(engine: e)["ROSETTA_X87_PATH"], "a game that doesn't ask")+ var stale = bottle(renderer: .dxmt)+ stale.settings.environment = ["ROSETTA_X87_PATH": "/somewhere/else"]+ XCTAssertNil(try stale.environment(engine: e)["ROSETTA_X87_PATH"], "only the switch sets it")+ }+func testEnvironmentFollowsTheDegradedRendererInsteadOfThrowing() throws {let e = try engine(accepted: false)let env = try bottle(renderer: .d3dmetal).environment(engine: e)diff --git a/Tests/HighballKitTests/SteamRestartTests.swift b/Tests/HighballKitTests/SteamRestartTests.swiftindex 7228b4c..ad436ac 100644--- a/Tests/HighballKitTests/SteamRestartTests.swift+++ b/Tests/HighballKitTests/SteamRestartTests.swift@@ -128,6 +128,16 @@ final class SteamRestartTests: XCTestCase {XCTAssertEqual(SteamRestart.rendererName(ofLive: [:]), "wined3d")}+ /// The x87 sidecar is chosen when a 32-bit program starts, and the game inherits the variable+ /// from the client, so a client started without it is restarted for a game that asks for it.+ func testAClientWithoutTheX87SidecarIsRestartedForAGameThatWantsIt() {+ let base = ["WINEDLLPATH_PREPEND": "/e/dxmt", "WINEMSYNC": "1"]+ var wanted = base; wanted["ROSETTA_X87_PATH"] = "/e/x87sidecar/x87sidecar"+ XCTAssertNotNil(SteamRestart.reason(live: base, wanted: wanted, wantedRenderer: "dxmt"))+ XCTAssertNotNil(SteamRestart.reason(live: wanted, wanted: base, wantedRenderer: "dxmt"))+ XCTAssertNil(SteamRestart.reason(live: wanted, wanted: wanted, wantedRenderer: "dxmt"))+ }+/// The audio buffer library loads when a process starts and the game inherits it from the/// client, so a client running without it is restarted for a launch that wants it (highball#127).func testAClientWithoutTheAudioLibraryIsRestartedForALaunchThatWantsIt() {