Skip to content

Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.

A graphics mode the engine cannot run never kills a launch (#61)

Gauthier Piarrette99f3d2cdd425
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index af7d77e..d0c4ee8 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -164,11 +164,28 @@ final class AppState {
func play(_ item: LibraryItem, renderer: Renderer? = nil) {
guard let bottleName = item.bottleName,
let bottle = bottles.first(where: { $0.name == bottleName }) else { return }
- if renderer == nil, !bottle.settings.rendererExplicit,
- let appid = item.steamAppID, gameDB[appid]?.effectiveRenderer() == .d3dmetal,
- let engine = engine(for: bottle), engine.ships("d3dmetal"), engine.rendererDir("d3dmetal") == nil {
- pendingD3DMetal = (item, bottle, engine)
- return
+ // The mode this launch will run with, whoever chose it: the caller, the row (unless the
+ // environment's mode is an explicit choice), a pinned program's own, or the environment.
+ // An engine that cannot run it must not be found out by Wine (#61: a fix recipe had set
+ // D3DMetal on a bottle whose engine had no licence accepted, and every launch in it
+ // died with "missing renderer"). A licence is asked for here, once, in context; a mode
+ // the engine simply lacks degrades to one it has, and the log says so.
+ var renderer = renderer
+ if let engine = engine(for: bottle) {
+ let rowMode = bottle.settings.rendererExplicit ? nil : item.steamAppID.flatMap { gameDB[$0]?.effectiveRenderer() }
+ let pinMode = item.pinID.flatMap { id in bottle.settings.pins.first { $0.id == id }?.renderer }
+ let wanted = renderer ?? rowMode ?? pinMode ?? bottle.settings.renderer
+ switch wanted.availability(in: engine) {
+ case .available:
+ break
+ case .needsLicence:
+ pendingD3DMetal = (item, bottle, engine)
+ return
+ case .notShipped:
+ let instead = Renderer.fallback(for: wanted, in: engine)
+ appendLog("\(item.title): \(wanted.unavailableReason(in: engine) ?? "") Playing with \(GamePageCopy.plainName(instead)).")
+ renderer = instead
+ }
}
if let recipe = fixRecipe(for: item), !bottle.settings.recipes.contains(recipe.id),
let engine = engine(for: bottle) {
@@ -990,6 +1007,14 @@ final class AppState {
func launch(pin: Pin, in bottle: Bottle) {
guard let engine = engine(for: bottle) else { return }
+ // A pinned program's own mode behind an unaccepted licence gets the same ask as a game's
+ // (#61); the runner degrades any other mode the engine lacks, with a note.
+ if let wanted = pin.renderer ?? Optional(bottle.settings.renderer),
+ case .needsLicence = wanted.availability(in: engine),
+ let item = libraryItems.first(where: { $0.pinID == pin.id }) {
+ pendingD3DMetal = (item, bottle, engine)
+ return
+ }
guard !launchingPins.contains(pin.id) else {
fail(HighballError.failed("\(pin.name) is already starting or running. If its window never appeared, stop the environment's processes in Settings, then try again."))
return
diff --git a/Sources/HighballApp/BottleView.swift b/Sources/HighballApp/BottleView.swift
index 71423d8..35a719a 100644
--- a/Sources/HighballApp/BottleView.swift
+++ b/Sources/HighballApp/BottleView.swift
@@ -264,6 +264,7 @@ struct BottleSettingsSheet: View {
@State private var dpiDraft: Double? = nil
private var currentDpi: Int { (state.bottles.first { $0.name == bottle.name } ?? bottle).settings.dpiScale }
+ private var currentRenderer: Renderer { (state.bottles.first { $0.name == bottle.name } ?? bottle).settings.renderer }
private var engine: InstalledEngine? { state.engine(for: bottle) }
private var d3dmetalAvailable: Bool { engine?.rendererDir("d3dmetal") != nil }
private var d3dmetalPossible: Bool {
@@ -294,10 +295,17 @@ struct BottleSettingsSheet: View {
Task { @MainActor in state.update(copy) }
})) {
Text(L("DXMT — D3D10/11 → Metal (default)")).tag(Renderer.dxmt)
- if d3dmetalAvailable { Text(L("D3DMetal — D3D11/12, Apple")).tag(Renderer.d3dmetal) }
+ // Shown when selectable, and when it is the setting even though this
+ // engine cannot run it: a picker that hides the current value reads as
+ // empty, and the row below says what happens instead (#61).
+ if d3dmetalAvailable || currentRenderer == .d3dmetal { Text(L("D3DMetal — D3D11/12, Apple")).tag(Renderer.d3dmetal) }
Text(L("DXVK — D3D9/10/11 → Vulkan")).tag(Renderer.dxvk)
Text(L("WineD3D — slow fallback")).tag(Renderer.wined3d)
}
+ if !d3dmetalAvailable, currentRenderer == .d3dmetal, let engine, let why = Renderer.d3dmetal.unavailableReason(in: engine) {
+ Text(String(format: L("Programs here start with %@ until this is resolved: %@"), GamePageCopy.plainName(Renderer.fallback(for: .d3dmetal, in: engine)), why))
+ .font(.caption).foregroundStyle(.secondary)
+ }
if !d3dmetalAvailable && d3dmetalPossible {
HStack {
Text(L("D3DMetal (needed for DirectX 12) requires accepting Apple’s Game Porting Toolkit license."))
diff --git a/Sources/HighballApp/HighballApp.swift b/Sources/HighballApp/HighballApp.swift
index a36af6e..47f7efe 100644
--- a/Sources/HighballApp/HighballApp.swift
+++ b/Sources/HighballApp/HighballApp.swift
@@ -207,6 +207,10 @@ struct ContentView: View {
Button(L("Turn it on and play")) { state.enableD3DMetalAndPlay() }
if let other = GamePageCopy.otherWorkingRenderer(pending.item.steamAppID.flatMap { state.gameDB[$0] }) {
Button(String(format: L("Play with %@"), GamePageCopy.plainName(other))) { state.playPendingD3DMetal(with: other) }
+ } else if pending.item.steamAppID.flatMap({ state.gameDB[$0]?.effectiveRenderer() }) != .d3dmetal {
+ // The ask came from the environment's setting, not a row that needs D3DMetal:
+ // the default mode is a real way out (#61 had none short of a new bottle).
+ Button(String(format: L("Play with %@"), GamePageCopy.plainName(.dxmt))) { state.playPendingD3DMetal(with: .dxmt) }
}
Button(L("Read Apple's licence")) {
state.licenseEngine = pending.engine
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swift
index f9d7c40..3e69db8 100644
--- a/Sources/HighballKit/Bottle.swift
+++ b/Sources/HighballKit/Bottle.swift
@@ -18,10 +18,12 @@ public enum Renderer: String, Codable, CaseIterable, Sendable {
case .wined3d:
return env
case .dxmt:
- guard let dir = engine.rendererDir("dxmt") else { throw HighballError.missing("dxmt renderer in engine \(engine.id)") }
+ 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)
case .d3dmetal:
- guard let dir = engine.rendererDir("d3dmetal") else { throw HighballError.missing("d3dmetal renderer in engine \(engine.id) (optional component not installed?)") }
+ // The old text said "(optional component not installed?)" whether the files were absent or
+ // merely unlicensed; #61's engine had them, and the reporter went looking for a download.
+ guard let dir = engine.rendererDir("d3dmetal") else { throw HighballError.missing(unavailableReason(in: engine) ?? "d3dmetal renderer in engine \(engine.id)") }
let external = dir.appending(path: "external").path
env["WINEDLLPATH_PREPEND"] = Self.withD9VK(dir.appending(path: "wine").path, engine: engine)
env["CX_D3DMETALPATH"] = external
@@ -79,6 +81,55 @@ public enum Renderer: String, Codable, CaseIterable, Sendable {
if next == .d3dmetal && !d3dmetalAvailable { return current == .dxmt ? .dxvk : .dxmt }
return next
}
+
+ // MARK: Availability (issue #61)
+
+ /// Whether an engine can run this renderer, and if not, why: the files may be absent, or
+ /// present but behind a licence that has not been accepted for that engine. The two need
+ /// different actions, and the old single message ("optional component not installed?")
+ /// sent a user whose engine had the files to reinstalling.
+ public enum Availability: Equatable, Sendable {
+ case available
+ case needsLicence(String)
+ case notShipped
+ }
+
+ public func availability(in engine: InstalledEngine) -> Availability {
+ if self == .wined3d { return .available }
+ if engine.rendererDir(rawValue) != nil { return .available }
+ if let gate = EngineManifest.gatedRenderers[rawValue], engine.ships(rawValue) { return .needsLicence(gate) }
+ return .notShipped
+ }
+
+ /// One sentence for a person: what stops this renderer in `engine` and what to do. Nil when it runs.
+ public func unavailableReason(in engine: InstalledEngine) -> String? {
+ let name = Self.displayName(self)
+ switch availability(in: engine) {
+ case .available: return nil
+ case .needsLicence:
+ return "\(name) is in engine \(engine.id), but Apple's licence has not been accepted for that engine. Accept it in the environment's settings (Graphics → Review licence…), or choose another graphics mode."
+ case .notShipped:
+ return "engine \(engine.id) has no \(name). Switch the environment to an engine that has it (its settings → Advanced → Engine), or choose another graphics mode."
+ }
+ }
+
+ /// The order a bottle-level setting degrades in when its renderer cannot run: Highball's
+ /// default first, then Vulkan, then Wine's own D3D, which every engine has.
+ public static let fallbackOrder: [Renderer] = [.dxmt, .dxvk, .wined3d]
+
+ /// The best renderer `engine` can run in place of `wanted`. Never `wanted` itself.
+ public static func fallback(for wanted: Renderer, in engine: InstalledEngine) -> Renderer {
+ fallbackOrder.first { $0 != wanted && $0.availability(in: engine) == .available } ?? .wined3d
+ }
+
+ static func displayName(_ r: Renderer) -> String {
+ switch r {
+ case .wined3d: return "WineD3D"
+ case .dxmt: return "DXMT"
+ case .d3dmetal: return "D3DMetal"
+ case .dxvk: return "DXVK"
+ }
+ }
}
public enum WindowsVersion: String, Codable, CaseIterable, Sendable {
@@ -355,7 +406,25 @@ public struct Bottle: Sendable {
/// Environment for running something in this bottle: engine base + bottle settings + renderer + extras.
/// Keys ending in `+` are appended to an existing value with `:` (paths) or `;` (WINEDLLOVERRIDES).
+ /// The renderer a launch will actually use. `requested` (a per-launch or per-program choice)
+ /// is strict: when the engine cannot run it, the error says why and what to do. The bottle's
+ /// own setting (`requested == nil`) degrades instead, to the best mode the engine can run,
+ /// with a note for the log and the person: a setting is a preference, and a preference must
+ /// never leave an environment where nothing starts (#61: a recipe had set D3DMetal on a
+ /// bottle whose engine had no licence accepted for it, and every launch died before Wine).
+ public func effectiveRenderer(requested: Renderer?, engine: InstalledEngine) throws -> (renderer: Renderer, note: String?) {
+ if let requested {
+ if let why = requested.unavailableReason(in: engine) { throw HighballError.missing(why) }
+ return (requested, nil)
+ }
+ let wanted = settings.renderer
+ guard let why = wanted.unavailableReason(in: engine) else { return (wanted, nil) }
+ let instead = Renderer.fallback(for: wanted, in: engine)
+ return (instead, "running with \(Renderer.displayName(instead)) instead of \(Renderer.displayName(wanted)): \(why)")
+ }
+
public func environment(engine: InstalledEngine, renderer: Renderer? = nil, extra: [String: String] = [:]) throws -> [String: String] {
+ let effective = try effectiveRenderer(requested: renderer, engine: engine).renderer
var env = engine.baseEnvironment()
env["WINEPREFIX"] = url.path
env["WINEDEBUG"] = "fixme-all"
@@ -367,7 +436,7 @@ public struct Bottle: Sendable {
}
if settings.metalHUD { env["MTL_HUD_ENABLED"] = "1" }
if settings.advertiseAVX { env["ROSETTA_ADVERTISE_AVX"] = "1" }
- let r = renderer ?? settings.renderer
+ let r = effective
// The async toggle travels in the generated dxvk.conf, NOT the DXVK_ASYNC env var:
// the async fork reads `env == "1" || config.enableAsync`, so an env 1 can never be
// overridden for a single game, while the conf's [csgo.exe] section can (issue #21).
@@ -405,7 +474,7 @@ public struct Bottle: Sendable {
if !settings.dllOverrides.isEmpty { merge(&env, ["WINEDLLOVERRIDES+": settings.dllOverrides]) }
merge(&env, ["WINEDLLOVERRIDES+": "winemenubuilder.exe=d"])
merge(&env, settings.environment)
- merge(&env, try (renderer ?? settings.renderer).environment(engine: engine))
+ merge(&env, try effective.environment(engine: engine))
merge(&env, extra)
return env
}
diff --git a/Sources/HighballKit/GamePageCopy.swift b/Sources/HighballKit/GamePageCopy.swift
index f4cfc1d..c31a4f7 100644
--- a/Sources/HighballKit/GamePageCopy.swift
+++ b/Sources/HighballKit/GamePageCopy.swift
@@ -137,6 +137,11 @@ extension GamePageCopy {
/// The consequence sentence of the D3DMetal ask, from the row: "will not start" only when
/// no other renderer is recorded as working, "runs faster with it" when one is.
public static func d3dMetalAsk(title: String, entry: GameDBEntry?) -> String {
+ // Asked because the environment (or a pinned program) is set to D3DMetal, not because
+ // the row needs it (#61): say where the setting came from and that the default runs.
+ guard entry?.effectiveRenderer() == .d3dmetal else {
+ return "The environment \(title) runs in is set to D3DMetal, which needs Apple's licence accepted for its engine. Turning it on means accepting that licence, which allows non-commercial use; nothing downloads and nothing is sent to Apple. Playing with DXMT, Highball's default, works for most games."
+ }
let consequence = otherWorkingRenderer(entry).map {
"Without it, \(title) still runs on \(plainName($0)), which was recorded as working, but slower."
} ?? "The database records no other graphics mode as working for \(title), so without it Highball has nothing else to try."
diff --git a/Sources/HighballKit/Recipe.swift b/Sources/HighballKit/Recipe.swift
index cf697de..facf72d 100644
--- a/Sources/HighballKit/Recipe.swift
+++ b/Sources/HighballKit/Recipe.swift
@@ -249,9 +249,11 @@ public struct RecipeRunner: Sendable {
self.paths = paths; self.engine = engine; self.bottle = bottle; self.store = EngineStore(paths: paths)
}
- /// The renderer a recipe may set, or nil when the user's explicit choice must stand (#29).
- public static func rendererToApply(recipeRenderer: Renderer?, settings: BottleSettings) -> Renderer? {
- guard let r = recipeRenderer, !settings.rendererExplicit else { return nil }
+ /// The renderer a recipe may set, or nil when the user's explicit choice must stand (#29) or
+ /// the bottle's engine cannot run it (#61: a fix recipe set D3DMetal on a bottle whose engine
+ /// had no licence accepted for it, and every later launch in that bottle died before Wine).
+ public static func rendererToApply(recipeRenderer: Renderer?, settings: BottleSettings, available: Bool = true) -> Renderer? {
+ guard let r = recipeRenderer, !settings.rendererExplicit, available else { return nil }
return r
}
@@ -266,8 +268,11 @@ public struct RecipeRunner: Sendable {
// A recipe's renderer is a default, never an override: an explicit user choice wins
// (issue #29 — the Steam recipe silently reset a d3dmetal bottle to dxmt).
if let r = recipe.renderer {
- if let applied = Self.rendererToApply(recipeRenderer: r, settings: bottle.settings) {
+ let why = r.unavailableReason(in: engine)
+ if let applied = Self.rendererToApply(recipeRenderer: r, settings: bottle.settings, available: why == nil) {
bottle.settings.renderer = applied
+ } else if let why {
+ notes.append("Kept this bottle's renderer (\(bottle.settings.renderer.rawValue)); the recipe suggests \(r.rawValue): \(why)")
} else {
notes.append("Kept this bottle's renderer (\(bottle.settings.renderer.rawValue)); the recipe suggests \(r.rawValue).")
}
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index 7f40f2e..d208ae6 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -4,6 +4,9 @@ public struct LaunchResult: Sendable {
public let exitStatus: Int32
public let duration: TimeInterval
public let log: URL
+ /// Set when the launch ran with a different graphics mode than the bottle asked for (#61);
+ /// the same sentence is in the log header.
+ public var note: String? = nil
/// Heuristic: exited non-zero (or at all) within 10 s of launch. The app uses this to suggest another renderer.
public var crashedEarly: Bool { duration < 10 && exitStatus != 0 }
}
@@ -105,7 +108,10 @@ public struct WineRunner: Sendable {
// DXVK reads its options from the generated conf (async toggle + per-game profiles like
// [csgo.exe], issue #21) — refresh it before the spawn. Every renderer but wined3d gets
// DXVK's d3d9 attached, so every one of them needs the conf, not just .dxvk.
- if (renderer ?? bottle.settings.renderer) != .wined3d { try? bottle.writeDxvkConfig() }
+ // A bottle set to a renderer its engine cannot run degrades to one it can (#61); the
+ // note goes in the header and to the caller so the substitution is never silent.
+ let resolved = try bottle.effectiveRenderer(requested: renderer, engine: engine)
+ if resolved.renderer != .wined3d { try? bottle.writeDxvkConfig() }
var env = try bottle.environment(engine: engine, renderer: renderer, extra: extraEnvironment)
// 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
@@ -120,8 +126,12 @@ public struct WineRunner: Sendable {
let logURL = Self.uniqueLogURL(in: paths.logs, named: "\(stamp)-\(bottle.name)-\(label ?? args.first ?? "wine")")
FileManager.default.createFile(atPath: logURL.path, contents: nil)
let logHandle = try FileHandle(forWritingTo: logURL)
- let header = Self.launchHeader(engine: engine, bottle: bottle,
- renderer: renderer ?? bottle.settings.renderer, env: env, args: args)
+ var header = Self.launchHeader(engine: engine, bottle: bottle,
+ renderer: resolved.renderer, env: env, args: args)
+ if let note = resolved.note {
+ header += "# note: \(note)\n"
+ onOutput?("note: \(note)")
+ }
logHandle.write(Data(header.utf8))
let process = Process()
@@ -185,7 +195,7 @@ public struct WineRunner: Sendable {
try? tail.close()
}
onOutput?(footer.trimmingCharacters(in: .newlines))
- return LaunchResult(exitStatus: status, duration: duration, log: logURL)
+ return LaunchResult(exitStatus: status, duration: duration, log: logURL, note: resolved.note)
}
/// Runs the executable directly under `wine` (not `start /unix`) so the process stays attached and
@@ -212,8 +222,16 @@ public struct WineRunner: Sendable {
throw HighballError.invalid("\(pin.name) points at \(pin.path), which isn't there. If this was added by an older Highball, remove it and drag the program in again.")
}
let env = pin.environment.merging(extraEnvironment) { $1 }
+ // A pin's own mode is a preference recorded by a recipe or a person, not a demand: when
+ // this engine cannot run it, the environment's mode applies (and degrades in turn if it
+ // must), with a note, rather than a launch that dies before Wine (#61).
+ var renderer = pin.renderer
+ if let wanted = renderer, let why = wanted.unavailableReason(in: engine) {
+ onOutput?("note: \(pin.name) asks for \(Renderer.displayName(wanted)), but \(why) Using the environment's mode.")
+ renderer = nil
+ }
// cwd = the exe's folder, as a Windows shortcut would — games with relative asset paths need it.
- return try await start(exe, arguments: pin.arguments, renderer: pin.renderer, extraEnvironment: env,
+ return try await start(exe, arguments: pin.arguments, renderer: renderer, extraEnvironment: env,
workingDirectory: exe.deletingLastPathComponent(), onOutput: onOutput)
}
diff --git a/Sources/highball/main.swift b/Sources/highball/main.swift
index 96d346e..7529e1c 100644
--- a/Sources/highball/main.swift
+++ b/Sources/highball/main.swift
@@ -39,7 +39,13 @@ struct Engine: AsyncParsableCommand {
if engines.isEmpty { print("no engines installed — try: highball engine install spike/engine-manifest.json"); return }
for e in engines {
let v = (try? e.wineVersion()) ?? "?"
- let renderers = HighballKit.Renderer.allCases.filter { $0 == .wined3d || e.rendererDir($0.rawValue) != nil }.map(\.rawValue).joined(separator: ",")
+ let renderers = HighballKit.Renderer.allCases.compactMap { r -> String? in
+ switch r.availability(in: e) {
+ case .available: return r.rawValue
+ case .needsLicence: return "\(r.rawValue) (licence not accepted)"
+ case .notShipped: return nil
+ }
+ }.joined(separator: ",")
print("\(e.id)\t\(v)\trenderers: \(renderers)")
}
}
@@ -350,6 +356,7 @@ struct Run: AsyncParsableCommand {
}
result = try await runner.run([program] + arguments, renderer: renderer, label: program, onOutput: out)
}
+ if let note = result.note { print("note: \(note)") }
print("exit=\(result.exitStatus) after \(Int(result.duration))s — log: \(result.log.path)")
if result.crashedEarly {
// A sync-mode mismatch with the running wineserver kills the process before it does
diff --git a/Tests/HighballKitTests/RendererAvailabilityTests.swift b/Tests/HighballKitTests/RendererAvailabilityTests.swift
new file mode 100644
index 0000000..aca51f7
--- /dev/null
+++ b/Tests/HighballKitTests/RendererAvailabilityTests.swift
@@ -0,0 +1,124 @@
+import XCTest
+@testable import HighballKit
+
+/// Issue #61: a bottle set to D3DMetal on an engine that carries the files but has no licence
+/// accepted for them died at launch with "missing: d3dmetal renderer … (optional component not
+/// installed?)", the message was wrong, and nothing offered a way out short of a new bottle.
+/// A renderer the engine cannot run must be reported for what it is, a bottle-level setting
+/// must degrade to a mode that runs, and a recipe must not install such a setting.
+final class RendererAvailabilityTests: XCTestCase {
+ private var root: URL!
+
+ override func setUpWithError() throws {
+ root = FileManager.default.temporaryDirectory.appending(path: "hb-engine-\(UUID().uuidString)")
+ try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
+ }
+
+ override func tearDownWithError() throws {
+ try? FileManager.default.removeItem(at: root)
+ }
+
+ private func manifest() throws -> EngineManifest {
+ let url = URL(fileURLWithPath: #filePath)
+ .deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
+ .appending(path: "spike/engine-manifest.json")
+ return try EngineManifest.load(from: url)
+ }
+
+ /// An engine like the shipped one: the runtime template carries every renderer, D3DMetal
+ /// included; `accepted` decides whether the licence is on record.
+ private func engine(ships: [String] = ["dxmt", "dxvk", "d9vk", "d3dmetal"], accepted: Bool) throws -> InstalledEngine {
+ var m = try manifest()
+ m.acceptedLicenses = accepted ? [EngineManifest.gatedRenderers["d3dmetal"]!] : nil
+ // Each engine gets its own root: one test builds several, and files from a full engine
+ // must not leak into the one that is meant to lack a renderer.
+ let engineRoot = root.appending(path: UUID().uuidString)
+ for name in ships {
+ try FileManager.default.createDirectory(at: engineRoot.appending(path: "frameworks/renderer/\(name)/wine"), withIntermediateDirectories: true)
+ }
+ return InstalledEngine(manifest: m, root: engineRoot)
+ }
+
+ private func bottle(renderer: Renderer, explicit: Bool = false) -> Bottle {
+ var b = Bottle(url: URL(fileURLWithPath: "/tmp/hb-test-bottle-61"), settings: BottleSettings(name: "t", engineID: "e"))
+ b.settings.renderer = renderer
+ b.settings.rendererExplicit = explicit
+ return b
+ }
+
+ // MARK: Availability
+
+ func testAvailabilityTellsLicenceFromAbsence() throws {
+ let unaccepted = try engine(accepted: false)
+ XCTAssertEqual(Renderer.d3dmetal.availability(in: unaccepted), .needsLicence("apple-gptk-license-2023-08-17"))
+ XCTAssertEqual(Renderer.dxmt.availability(in: unaccepted), .available)
+ XCTAssertEqual(Renderer.wined3d.availability(in: unaccepted), .available, "Wine's own D3D is always there")
+ let accepted = try engine(accepted: true)
+ XCTAssertEqual(Renderer.d3dmetal.availability(in: accepted), .available)
+ let without = try engine(ships: ["dxmt", "dxvk", "d9vk"], accepted: true)
+ XCTAssertEqual(Renderer.d3dmetal.availability(in: without), .notShipped, "an accepted licence does not conjure files")
+ }
+
+ func testReasonsNameTheActionNotAMissingComponent() throws {
+ let why = Renderer.d3dmetal.unavailableReason(in: try engine(accepted: false))!
+ XCTAssertTrue(why.contains("licence"), why)
+ XCTAssertTrue(why.contains("Review licence") || why.contains("accept"), why)
+ XCTAssertFalse(why.contains("not installed"), "the files are there; saying otherwise sent #61 to reinstalling")
+ let none = Renderer.d3dmetal.unavailableReason(in: try engine(ships: ["dxmt"], accepted: true))!
+ XCTAssertTrue(none.contains("engine"), none)
+ XCTAssertNil(Renderer.dxmt.unavailableReason(in: try engine(accepted: false)))
+ }
+
+ func testFallbackPrefersTheDefaultThenVulkanThenWine() throws {
+ XCTAssertEqual(Renderer.fallback(for: .d3dmetal, in: try engine(accepted: false)), .dxmt)
+ XCTAssertEqual(Renderer.fallback(for: .d3dmetal, in: try engine(ships: ["dxvk", "d9vk"], accepted: false)), .dxvk)
+ XCTAssertEqual(Renderer.fallback(for: .d3dmetal, in: try engine(ships: [], accepted: false)), .wined3d)
+ XCTAssertEqual(Renderer.fallback(for: .dxmt, in: try engine(ships: ["dxvk", "d9vk"], accepted: false)), .dxvk, "never the mode that failed")
+ }
+
+ // MARK: A launch
+
+ func testBottleSettingDegradesWithANoteAndAnExplicitRequestRefuses() throws {
+ let e = try engine(accepted: false)
+ let b = bottle(renderer: .d3dmetal)
+ let (r, note) = try b.effectiveRenderer(requested: nil, engine: e)
+ XCTAssertEqual(r, .dxmt)
+ XCTAssertNotNil(note)
+ XCTAssertTrue(note!.contains("DXMT") || note!.contains("dxmt"), note!)
+ XCTAssertThrowsError(try b.effectiveRenderer(requested: .d3dmetal, engine: e)) { error in
+ let text = String(describing: error)
+ XCTAssertTrue(text.contains("licence"), text)
+ XCTAssertFalse(text.contains("not installed"), text)
+ }
+ let fine = try b.effectiveRenderer(requested: nil, engine: try engine(accepted: true))
+ XCTAssertEqual(fine.renderer, .d3dmetal)
+ XCTAssertNil(fine.note)
+ }
+
+ func testEnvironmentFollowsTheDegradedRendererInsteadOfThrowing() throws {
+ let e = try engine(accepted: false)
+ let env = try bottle(renderer: .d3dmetal).environment(engine: e)
+ XCTAssertNil(env["CX_D3DMETALPATH"], "no D3DMetal variables when it is not running")
+ XCTAssertTrue(env["WINEDLLPATH_PREPEND"]?.contains("/dxmt/") == true, "the fallback's overlay is on the path")
+ XCTAssertThrowsError(try bottle(renderer: .dxmt).environment(engine: e, renderer: .d3dmetal), "an explicit request stays strict")
+ }
+
+ // MARK: The ask
+
+ func testAskCopySaysWhereTheSettingCameFromWhenNoRowNeedsIt() {
+ let fromEnvironment = GamePageCopy.d3dMetalAsk(title: "Deliver At All Costs Demo", entry: nil)
+ XCTAssertTrue(fromEnvironment.contains("environment"), fromEnvironment)
+ XCTAssertTrue(fromEnvironment.contains("DXMT"), "the way out is named")
+ XCTAssertFalse(fromEnvironment.contains("nothing else to try"), "that sentence belongs to rows with no working alternative")
+ }
+
+ // MARK: A recipe
+
+ func testRecipeDoesNotSetAModeTheEngineCannotRun() {
+ let settings = BottleSettings(name: "t", engineID: "e")
+ XCTAssertEqual(RecipeRunner.rendererToApply(recipeRenderer: .d3dmetal, settings: settings, available: true), .d3dmetal)
+ XCTAssertNil(RecipeRunner.rendererToApply(recipeRenderer: .d3dmetal, settings: settings, available: false), "#61: the recipe's mode must not outlive what the engine can do")
+ var explicit = settings; explicit.renderer = .dxvk; explicit.rendererExplicit = true
+ XCTAssertNil(RecipeRunner.rendererToApply(recipeRenderer: .d3dmetal, settings: explicit, available: true), "#29 still holds")
+ }
+}