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
The vkd3d mode keeps vkd3d-proton's pipeline cache in the prefix, one folder per engine build, under C:\highball\cache\vkd3d. The folder's name is the engine id plus eight hex digits over every component's checksum, so a rebuilt MoltenVK or renderer under the same version starts a new cache instead of reading pipelines another build compiled, which kept stale caches alive across MoltenVK rebuilds on the arm64 line (backlog B2). Without a path vkd3d-proton wrote the cache beside the game's executable. A launch makes its folder and removes the ones other builds left, and a path a recipe sets elsewhere is left alone. The launch log's header now names the vkd3d and DXVK settings (VKD3D_SHADER_CACHE_PATH, VKD3D_CONFIG, VKD3D_SHADER_MODEL, VKD3D_FEATURE_LEVEL, DXVK_CONFIG). 528 tests pass on the M4.
Gauthier Piarrettebe6a4cd61bac
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swiftindex ff53ca6..9838478 100644--- a/Sources/HighballKit/Bottle.swift+++ b/Sources/HighballKit/Bottle.swift@@ -36,6 +36,10 @@ public enum Renderer: String, Codable, CaseIterable, Sendable {env["DXVK_RELAX_FEATURES"] = "1"env["VKD3D_FEATURE_LEVEL"] = "12_0"env["VKD3D_SHADER_MODEL"] = "6_6"+ // The pipeline cache goes in the prefix, one folder per engine build (B2): without a+ // path vkd3d-proton writes it beside the game's executable, where it outlives the+ // MoltenVK and renderer builds that compiled it.+ env["VKD3D_SHADER_CACHE_PATH"] = Bottle.vkd3dCacheWindowsRoot + "\\" + engine.manifest.vkd3dCacheKeycase .dxmt:guard let dir = engine.rendererDir("dxmt") else { throw HighballError.missing(unavailableReason(in: engine) ?? "dxmt renderer in engine \(engine.id)") }env["WINEDLLPATH_PREPEND"] = Self.withD9VK(dir.appending(path: "wine").path, engine: engine)@@ -909,6 +913,25 @@ public struct Bottle: Sendable {public static let dxvkConfigWindowsPath = #"C:\highball\dxvk.conf"#/// Unix location of the same file.public var dxvkConfigURL: URL { driveC.appending(path: "highball/dxvk.conf") }++ /// Where the vkd3d mode keeps vkd3d-proton's pipeline caches, as Windows sees it and on disk.+ public static let vkd3dCacheWindowsRoot = "C:\\highball\\cache\\vkd3d"+ public var vkd3dCacheRoot: URL { driveC.appending(path: "highball/cache/vkd3d", directoryHint: .isDirectory) }++ /// Makes the cache folder a launch's environment names, when it is one of Highball's, and+ /// removes the folders other engine builds left beside it. A path a recipe set elsewhere is+ /// left alone.+ public func prepareVkd3dCache(environment env: [String: String]) {+ let prefix = Self.vkd3dCacheWindowsRoot + "\\"+ guard let path = env["VKD3D_SHADER_CACHE_PATH"], path.hasPrefix(prefix) else { return }+ let key = String(path.dropFirst(prefix.count))+ guard !key.isEmpty, !key.contains("\\"), !key.contains("/") else { return }+ let fm = FileManager.default+ try? fm.createDirectory(at: vkd3dCacheRoot.appending(path: key), withIntermediateDirectories: true)+ for old in (try? fm.contentsOfDirectory(atPath: vkd3dCacheRoot.path)) ?? [] where old != key {+ try? fm.removeItem(at: vkd3dCacheRoot.appending(path: old))+ }+ }/// Windows path DXVK writes its per-process logs to, and its Unix location.public static let dxvkLogWindowsPath = #"C:\highball\logs"#public var dxvkLogURL: URL { driveC.appending(path: "highball/logs") }diff --git a/Sources/HighballKit/Manifest.swift b/Sources/HighballKit/Manifest.swiftindex 04f7ed9..430fbf3 100644--- a/Sources/HighballKit/Manifest.swift+++ b/Sources/HighballKit/Manifest.swift@@ -1,3 +1,4 @@+import CryptoKitimport Foundation/// An engine manifest describes every binary Gin downloads to assemble one engine.@@ -120,6 +121,16 @@ public struct EngineManifest: Codable, Sendable, Identifiable {/// Renderer overlay names gated behind a license id.public static let gatedRenderers: [String: String] = ["d3dmetal": "apple-gptk-license-2023-08-17"]+ /// The folder name of vkd3d-proton's pipeline cache for this engine build: the id plus eight hex+ /// digits over every component's checksum. A rebuilt component (a patched MoltenVK under the same+ /// version, a new renderer build) gets a fresh cache instead of reusing pipelines another build+ /// compiled, which is how stale caches survived MoltenVK rebuilds (backlog B2).+ public var vkd3dCacheKey: String {+ let fingerprint = components.keys.sorted().map { "\($0)=\(components[$0]!.sha256)" }.joined(separator: "\n")+ let digest = SHA256.hash(data: Data(fingerprint.utf8)).map { String(format: "%02x", $0) }.joined()+ return "\(id)-\(digest.prefix(8))"+ }+public static func load(from url: URL) throws -> EngineManifest {let data = try Data(contentsOf: url)let decoder = JSONDecoder()diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swiftindex 05ab07e..0bfcf34 100644--- a/Sources/HighballKit/WineRunner.swift+++ b/Sources/HighballKit/WineRunner.swift@@ -106,7 +106,7 @@ public struct WineRunner: Sendable {}// The Mac's output rate: a sound report is unanswerable without it (highball#127).if let audio = AudioOutput.headerLine(sampleRate: AudioOutput.defaultOutputSampleRate()) { out += audio }- for key in ["WINEDLLPATH_PREPEND", "WINEDLLOVERRIDES", "ROSETTA_ADVERTISE_AVX", "MTL_HUD_ENABLED", "CX_FWD_COMPAT_GL_CTX", "DXVK_CONFIG_FILE", "DXVK_LOG_PATH", "LSFGM_MULTIPLIER", "LSFGM_PACING_MODE", "LSFGM_FLOW_SCALE", "LSFGM_DLL_PATH"] {+ for key in ["WINEDLLPATH_PREPEND", "WINEDLLOVERRIDES", "ROSETTA_ADVERTISE_AVX", "MTL_HUD_ENABLED", "CX_FWD_COMPAT_GL_CTX", "DXVK_CONFIG_FILE", "DXVK_LOG_PATH", "DXVK_CONFIG", "VKD3D_SHADER_MODEL", "VKD3D_FEATURE_LEVEL", "VKD3D_CONFIG", "VKD3D_SHADER_CACHE_PATH", "LSFGM_MULTIPLIER", "LSFGM_PACING_MODE", "LSFGM_FLOW_SCALE", "LSFGM_DLL_PATH"] {if let value = env[key] { out += "# \(key)=\(value)\n" }}// The generated dxvk.conf decides per-game behaviour, so quote it rather than making the@@ -144,6 +144,7 @@ public struct WineRunner: Sendable {try bottle.prepareDLSSBridge(engine: engine, renderer: resolved.renderer)if resolved.renderer != .wined3d { try? bottle.writeDxvkConfig() }var env = try bottle.environment(engine: engine, renderer: renderer, extra: extraEnvironment)+ bottle.prepareVkd3dCache(environment: env)// Wine fixes the sync mode when the prefix's wineserver starts; a process started with a// different one dies at msync_init before doing anything (issue #32: a registry write// "succeeding" in 0 s while a Steam window, cold-started with sync off, was open). So adiff --git a/Tests/HighballKitTests/RendererAvailabilityTests.swift b/Tests/HighballKitTests/RendererAvailabilityTests.swiftindex ec00b62..40e8b98 100644--- a/Tests/HighballKitTests/RendererAvailabilityTests.swift+++ b/Tests/HighballKitTests/RendererAvailabilityTests.swift@@ -225,6 +225,8 @@ final class RendererAvailabilityTests: XCTestCase {XCTAssertEqual(env["VKD3D_SHADER_MODEL"], "6_6")XCTAssertEqual(env["VKD3D_RELAX_DEVICE_CAPS"], "1")XCTAssertEqual(env["DXVK_RELAX_FEATURES"], "1")+ XCTAssertEqual(env["VKD3D_SHADER_CACHE_PATH"], "C:\\highball\\cache\\vkd3d\\" + e.manifest.vkd3dCacheKey,+ "B2: the pipeline cache lives in the prefix, one folder per engine build")let without = try engine(ships: ["dxmt", "dxvk", "d9vk"], accepted: false)XCTAssertEqual(Renderer.vkd3d.availability(in: without), .notShipped)XCTAssertThrowsError(try Renderer.vkd3d.environment(engine: without))@@ -232,6 +234,44 @@ final class RendererAvailabilityTests: XCTestCase {XCTAssertFalse(Renderer.fallbackOrder.contains(.vkd3d), "never a fallback for other modes")}+ /// B2: a pipeline cache compiled by one MoltenVK build and read by another gave wrong or hung+ /// pipelines on the arm64 line. The key follows every component's checksum, so a rebuilt+ /// component (same version, new patch) starts a new cache, and nothing else moves it.+ func testVkd3dCacheKeyFollowsTheComponentsBuild() throws {+ let m = try manifest()+ XCTAssertEqual(m.vkd3dCacheKey, try manifest().vkd3dCacheKey, "stable for one build")+ XCTAssertTrue(m.vkd3dCacheKey.hasPrefix(m.id + "-"))+ XCTAssertEqual(m.vkd3dCacheKey.count, m.id.count + 9)+ var rebuilt = m+ let name = m.components.keys.sorted().last!+ rebuilt.components[name]!.sha256 = String(repeating: "0", count: 64)+ XCTAssertNotEqual(rebuilt.vkd3dCacheKey, m.vkd3dCacheKey, "a rebuilt component starts a new cache")+ var renamed = m+ renamed.displayName = "Something else"+ renamed.notes = ["a note"]+ XCTAssertEqual(renamed.vkd3dCacheKey, m.vkd3dCacheKey, "only the binaries count")+ }++ func testALaunchMakesItsCacheFolderAndDropsOtherBuildsCaches() throws {+ let fm = FileManager.default+ let b = Bottle(url: root.appending(path: "bottle"), settings: BottleSettings(name: "t", engineID: "e"))+ let stale = b.vkd3dCacheRoot.appending(path: "old-engine-12345678")+ try fm.createDirectory(at: stale, withIntermediateDirectories: true)+ try Data("x".utf8).write(to: stale.appending(path: "vkd3d-proton.cache"))+ b.prepareVkd3dCache(environment: ["VKD3D_SHADER_CACHE_PATH": "C:\\highball\\cache\\vkd3d\\new-engine-abcdef01"])+ XCTAssertTrue(fm.fileExists(atPath: b.vkd3dCacheRoot.appending(path: "new-engine-abcdef01").path))+ XCTAssertFalse(fm.fileExists(atPath: stale.path), "another build's cache is removed")++ let kept = b.vkd3dCacheRoot.appending(path: "new-engine-abcdef01/vkd3d-proton.cache")+ try Data("y".utf8).write(to: kept)+ b.prepareVkd3dCache(environment: ["VKD3D_SHADER_CACHE_PATH": "C:\\highball\\cache\\vkd3d\\new-engine-abcdef01"])+ XCTAssertTrue(fm.fileExists(atPath: kept.path), "the current build's cache survives the next launch")++ b.prepareVkd3dCache(environment: ["VKD3D_SHADER_CACHE_PATH": "C:\\games\\cache"])+ b.prepareVkd3dCache(environment: [:])+ XCTAssertTrue(fm.fileExists(atPath: kept.path), "a path a recipe set elsewhere, or none, touches nothing")+ }+func testSuggestionOffersTheOtherDirectX12RouteAfterAppleFails() {XCTAssertEqual(Renderer.suggestion(after: .d3dmetal, vkd3dAvailable: true), .vkd3d)XCTAssertEqual(Renderer.suggestion(after: .d3dmetal, vkd3dAvailable: false), .dxvk)