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 recipe's value can depend on the Mac it runs on. ${memoryMB} is this Mac's memory in MB and ${memoryMB*0.375} a share of it, rounded down, expanded in every launch's environment and in the generated dxvk.conf, so a recipe keeps the formula and each Mac gets its own number. First use: DXVK's dxgi.maxVideoMemoryBudget for Microsoft Flight Simulator 2024 on the arm64 line, which sizes its streaming from the video memory DXGI reports. On a 32 GB M4 the game took 27 to 33 GB at the Ultra preset it picked, and 12 to 14 GB with the budget at 12288 MB and the Low-End preset, two changes measured together, so the budget's own share is not known. Anything else between ${ and } stays as written. 532 tests pass on the M4.
Gauthier Piarrettefc429535cd44
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swiftindex 9838478..5557684 100644--- a/Sources/HighballKit/Bottle.swift+++ b/Sources/HighballKit/Bottle.swift@@ -875,7 +875,8 @@ 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: ":")}- return env+ // A recipe's value can depend on this Mac (a video memory budget from its memory).+ return env.mapValues { MacVariables.expand($0) }}/// The renderer-specific bridge files that make the DLSS switch actionable in this engine.@@ -1018,7 +1019,8 @@ public struct Bottle: Sendable {try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)// DXVK only writes its per-process log if the directory exists.try FileManager.default.createDirectory(at: dxvkLogURL, withIntermediateDirectories: true)- let content = Self.dxvkConfig(async: settings.dxvkAsync, appConfig: settings.dxvkAppConfig)+ let appConfig = settings.dxvkAppConfig.mapValues { $0.mapValues { MacVariables.expand($0) } }+ let content = Self.dxvkConfig(async: settings.dxvkAsync, appConfig: appConfig)if (try? String(contentsOf: dxvkConfigURL, encoding: .utf8)) != content {try content.write(to: dxvkConfigURL, atomically: true, encoding: .utf8)}diff --git a/Sources/HighballKit/MacVariables.swift b/Sources/HighballKit/MacVariables.swiftnew file mode 100644index 0000000..a381707--- /dev/null+++ b/Sources/HighballKit/MacVariables.swift@@ -0,0 +1,20 @@+import Foundation++/// Values a recipe writes that depend on the Mac a launch runs on, filled in at each launch.+/// `${memoryMB}` is this Mac's memory in MB and `${memoryMB*0.375}` a share of it, rounded down.+/// A game that sizes its streaming from the video memory DXGI reports fills what it is told it+/// has, and on Apple silicon that memory is the Mac's own: Microsoft Flight Simulator 2024 through+/// vkd3d-proton took 27 to 33 GB of a 32 GB M4 at the Ultra preset it picked, and 12 to 14 GB with+/// DXVK's dxgi.maxVideoMemoryBudget at 12288 MB and the Low-End preset (measured together on+/// 2026-10-12, so the budget's own share is not known).+/// Variables and dxvk.conf values are expanded when a launch builds them, so a recipe keeps the+/// formula and each Mac gets its own number. Anything else between ${ and } stays as written.+public enum MacVariables {+ public static func expand(_ value: String, memoryMB: Int = Machine.memoryMB) -> String {+ guard value.contains("${") else { return value }+ return value.replacing(#/\$\{memoryMB(?:\*([0-9]+(?:\.[0-9]+)?))?\}/#) { match in+ let factor = match.1.flatMap { Double($0) } ?? 1+ return String(Int((Double(memoryMB) * factor).rounded(.down)))+ }+ }+}diff --git a/Sources/HighballKit/PlayReport.swift b/Sources/HighballKit/PlayReport.swiftindex edf30a8..36fef38 100644--- a/Sources/HighballKit/PlayReport.swift+++ b/Sources/HighballKit/PlayReport.swift@@ -10,6 +10,8 @@ public enum Machine {(try? Shell.capture("/usr/bin/sw_vers", ["-productVersion"]))?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "?"}+ /// This Mac's memory in MB, which Apple silicon shares between the CPU and the GPU.+ public static var memoryMB: Int { Int(ProcessInfo.processInfo.physicalMemory / 1_048_576) }}/// A compatibility report for highball-db, prefilled from a finished session so "how did it go"diff --git a/Tests/HighballKitTests/MacVariablesTests.swift b/Tests/HighballKitTests/MacVariablesTests.swiftnew file mode 100644index 0000000..762b140--- /dev/null+++ b/Tests/HighballKitTests/MacVariablesTests.swift@@ -0,0 +1,65 @@+import XCTest+@testable import HighballKit++/// A recipe's value that depends on the Mac (a video memory budget from its memory) keeps its+/// formula in the settings and gets this Mac's number at each launch.+final class MacVariablesTests: XCTestCase {+ func testMemoryAndAShareOfIt() {+ XCTAssertEqual(MacVariables.expand("${memoryMB}", memoryMB: 32768), "32768")+ XCTAssertEqual(MacVariables.expand("dxgi.maxVideoMemoryBudget=${memoryMB*0.375}", memoryMB: 32768), "dxgi.maxVideoMemoryBudget=12288",+ "the budget measured on the 32 GB M4")+ XCTAssertEqual(MacVariables.expand("${memoryMB*0.375}", memoryMB: 16384), "6144")+ XCTAssertEqual(MacVariables.expand("${memoryMB*0.3}", memoryMB: 24576), "7372", "rounded down")+ XCTAssertEqual(MacVariables.expand("a=${memoryMB*2};b=${memoryMB}", memoryMB: 8192), "a=16384;b=8192")+ }++ func testAnythingElseStaysAsWritten() {+ XCTAssertEqual(MacVariables.expand("plain", memoryMB: 1), "plain")+ XCTAssertEqual(MacVariables.expand("${HOME}/x", memoryMB: 1), "${HOME}/x")+ XCTAssertEqual(MacVariables.expand("${memoryMB*}", memoryMB: 1), "${memoryMB*}")+ XCTAssertEqual(MacVariables.expand("${memoryMB*-1}", memoryMB: 1), "${memoryMB*-1}")+ }++ func testMachineMemoryIsReal() {+ XCTAssertGreaterThanOrEqual(Machine.memoryMB, 4096)+ XCTAssertEqual(MacVariables.expand("${memoryMB}"), String(Machine.memoryMB))+ }++ private var root: URL!++ override func setUpWithError() throws {+ root = FileManager.default.temporaryDirectory.appending(path: "hb-macvars-\(UUID().uuidString)")+ try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)+ }++ override func tearDownWithError() throws {+ try? FileManager.default.removeItem(at: root)+ }++ private func engine() throws -> InstalledEngine {+ let url = URL(fileURLWithPath: #filePath)+ .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()+ .appending(path: "spike/engine-manifest.json")+ let engineRoot = root.appending(path: "engine")+ for name in ["dxmt", "dxvk", "d9vk"] {+ try FileManager.default.createDirectory(at: engineRoot.appending(path: "frameworks/renderer/\(name)/wine"), withIntermediateDirectories: true)+ }+ return InstalledEngine(manifest: try EngineManifest.load(from: url), root: engineRoot)+ }++ func testALaunchGetsThisMacsNumberAndTheSettingKeepsTheFormula() throws {+ var b = Bottle(url: root.appending(path: "bottle"), settings: BottleSettings(name: "t", engineID: "e"))+ b.settings.renderer = .dxvk+ b.settings.environment["DXVK_CONFIG"] = "dxgi.maxVideoMemoryBudget=${memoryMB*0.375}"+ let env = try b.environment(engine: try engine(), extra: ["GAME_ONLY": "${memoryMB}"])+ XCTAssertEqual(env["DXVK_CONFIG"], "dxgi.maxVideoMemoryBudget=\(Machine.memoryMB * 3 / 8)")+ XCTAssertEqual(env["GAME_ONLY"], String(Machine.memoryMB), "a game's own variables too")+ XCTAssertEqual(b.settings.environment["DXVK_CONFIG"], "dxgi.maxVideoMemoryBudget=${memoryMB*0.375}")++ b.settings.dxvkAppConfig["FlightSimulator2024.exe"] = ["dxgi.maxVideoMemoryBudget": "${memoryMB*0.375}"]+ try b.writeDxvkConfig()+ let conf = try String(contentsOf: b.dxvkConfigURL, encoding: .utf8)+ XCTAssertTrue(conf.contains("dxgi.maxVideoMemoryBudget = \(Machine.memoryMB * 3 / 8)"), conf)+ XCTAssertFalse(conf.contains("${"))+ }+}