Skip to content

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

steam launch: a client kept with another renderer is said out loud, in the activity log, the launch header and the session (highball-db#48)

Gauthier Piarrette6b6437664b78
diff --git a/Sources/HighballApp/AppState.swift b/Sources/HighballApp/AppState.swift
index af7045a..0ce3ba1 100644
--- a/Sources/HighballApp/AppState.swift
+++ b/Sources/HighballApp/AppState.swift
@@ -1511,18 +1511,32 @@ final class AppState {
let runner = WineRunner(paths: paths, engine: engine, bottle: bottle)
// A running client would serve the launch with its own environment; when that is
// not the game's, cold-start first: never under a running game, Steam's or not.
- if !sessionRuns(in: bottle), let why = try await runner.restartSteamIfMismatched(renderer: renderer) {
+ // A kept client is said out loud, in the activity log and in the launch log's header:
+ // the game runs on the client's stack, and a report must not claim otherwise.
+ var headerNote: String?
+ var served = renderer ?? bottle.settings.renderer
+ switch try await runner.restartSteamIfMismatched(renderer: renderer, mayRestart: !sessionRuns(in: bottle)) {
+ case .restarted(let why):
await MainActor.run { self.appendLog("Restarting Steam before \(game.name): \(why).") }
+ case .kept(let why, let live):
+ let liveName = Renderer(rawValue: live).map(Renderer.displayName) ?? live
+ let text = "Steam keeps running as it is because a game is still open in \(bottle.name): \(why). \(game.name) gets the client's \(liveName) stack, not \(Renderer.displayName(served)). Quit the open game or crash window, or press Stop all processes, then Play again."
+ headerNote = text
+ if let r = Renderer(rawValue: live) { served = r }
+ await MainActor.run { self.appendLog(text) }
+ case .noClient, .serves:
+ break
}
+ let note = headerNote, servedRenderer = served
let box = LaunchOutcome()
let log = logLine(box)
watchedLaunch(box) {
- try await runner.start(steam, arguments: ["-silent", "-applaunch", String(game.appid)] + extraArgs, renderer: renderer, onOutput: log)
+ try await runner.start(steam, arguments: ["-silent", "-applaunch", String(game.appid)] + extraArgs, renderer: renderer, headerNote: note, onOutput: log)
}
let handedOff = try await awaitHandoff(box, program: game.name, timeout: 360, exitEndsWait: false) {
SessionWatch.isAlive(markers: markers, ps: await Self.processList())
} crashed: { result in
- let current = renderer ?? bottle.settings.renderer
+ let current = servedRenderer
self.crashSuggestion = CrashSuggestion(program: game.name, bottleName: bottle.name,
renderer: Renderer.suggestion(after: current, d3dmetalAvailable: engine.rendererDir("d3dmetal") != nil, vkd3dAvailable: engine.rendererDir("vkd3d") != nil),
logPath: result.log.path, current: current, seconds: Int(result.duration),
@@ -1530,7 +1544,7 @@ final class AppState {
}
guard handedOff else { return }
beginSession(GameSession(title: game.name, bottleName: bottle.name, appid: game.appid, markers: markers,
- renderer: (renderer ?? bottle.settings.renderer).rawValue))
+ renderer: servedRenderer.rawValue))
}
}
diff --git a/Sources/HighballKit/Bottle.swift b/Sources/HighballKit/Bottle.swift
index 3df7d50..3ad3d57 100644
--- a/Sources/HighballKit/Bottle.swift
+++ b/Sources/HighballKit/Bottle.swift
@@ -154,7 +154,7 @@ public enum Renderer: String, Codable, CaseIterable, Sendable {
fallbackOrder.first { $0 != wanted && $0.availability(in: engine) == .available } ?? .wined3d
}
- static func displayName(_ r: Renderer) -> String {
+ public static func displayName(_ r: Renderer) -> String {
switch r {
case .wined3d: return "WineD3D"
case .dxmt: return "DXMT"
diff --git a/Sources/HighballKit/SteamRestart.swift b/Sources/HighballKit/SteamRestart.swift
index 3bf326b..2a9d642 100644
--- a/Sources/HighballKit/SteamRestart.swift
+++ b/Sources/HighballKit/SteamRestart.swift
@@ -14,6 +14,31 @@ public enum SteamRestart {
/// Per-process settings the game inherits from the client and cannot change afterwards.
static let inherited: [(String, String)] = [("ROSETTA_ADVERTISE_AVX", "AVX advertised"), ("MTL_HUD_ENABLED", "the Metal HUD")]
+ /// What became of the running client before a launch.
+ public enum Outcome: Equatable {
+ /// No client runs; the launch cold-starts one with its own environment.
+ case noClient
+ /// The running client serves the launch as asked.
+ case serves
+ /// The client was cold-restarted; why, for the log.
+ case restarted(String)
+ /// The client does not match but a game is still open in the environment, so it stays,
+ /// and the launch gets the client's stack. `live` names the client's renderer.
+ case kept(String, live: String)
+ }
+
+ /// The renderer a running client was started with, read off its overlay path: each entry is
+ /// `<...>/<renderer>/wine`, under `frameworks/renderer/` or `renderers/`. "wined3d" when it
+ /// has no overlay. The d9vk entry rides along with every renderer and names none.
+ public static func rendererName(ofLive env: [String: String]) -> String {
+ let dirs = (env["WINEDLLPATH_PREPEND"] ?? "").split(separator: ":").compactMap { entry -> String? in
+ let parts = entry.split(separator: "/")
+ return parts.count >= 2 && parts.last == "wine" ? String(parts[parts.count - 2]) : nil
+ }
+ for name in ["d3dmetal", "dxmt", "vkd3d", "dxvk"] where dirs.contains(name) { return name }
+ return "wined3d"
+ }
+
public static func reason(live: [String: String], wanted: [String: String], wantedRenderer: String) -> String? {
var reasons: [String] = []
if live["WINEDLLPATH_PREPEND"] != wanted["WINEDLLPATH_PREPEND"] {
@@ -64,20 +89,22 @@ extension WineRunner {
}
}
- /// Cold-starts the bottle when its running Steam client could not serve a launch with
- /// `renderer` (see `SteamRestart`), so the launch that follows starts a fresh client with
- /// the right environment. Never while a game runs in the bottle: a wrong environment
- /// beats killing someone's game. Returns the reason for the log, nil when nothing was done.
- public func restartSteamIfMismatched(renderer: Renderer?) async throws -> String? {
- guard let live = runningSteamEnvironment() else { return nil }
+ /// Whether the running Steam client can serve a launch with `renderer`, restarting it when
+ /// it cannot (see `SteamRestart`), so the launch that follows starts a fresh client with the
+ /// right environment. Never while a game runs in the bottle (`mayRestart` false, or a prefix
+ /// process working in a game folder): a wrong environment beats killing someone's game. That
+ /// case comes back as `.kept` so the caller can say so; silently launching under the client's
+ /// stack cost highball-db#48 six rounds, the game ran on DXMT while every log said D3DMetal.
+ public func restartSteamIfMismatched(renderer: Renderer?, mayRestart: Bool = true) async throws -> SteamRestart.Outcome {
+ guard let live = runningSteamEnvironment() else { return .noClient }
let wanted = try bottle.environment(engine: engine, renderer: renderer)
guard let why = SteamRestart.reason(live: live, wanted: wanted,
- wantedRenderer: (renderer ?? bottle.settings.renderer).rawValue),
- !steamGameIsRunning() else { return nil }
+ wantedRenderer: (renderer ?? bottle.settings.renderer).rawValue) else { return .serves }
+ if !mayRestart || steamGameIsRunning() { return .kept(why, live: SteamRestart.rendererName(ofLive: live)) }
try kill()
// `kill` waits for the server; give the client's own exit a moment too, so the launch
// that follows does not forward to a client on its way out.
for _ in 0..<50 where runningSteamEnvironment() != nil { try await Task.sleep(for: .milliseconds(100)) }
- return why
+ return .restarted(why)
}
}
diff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swift
index 70f9403..a1bd91e 100644
--- a/Sources/HighballKit/WineRunner.swift
+++ b/Sources/HighballKit/WineRunner.swift
@@ -98,6 +98,7 @@ public struct WineRunner: Sendable {
label: String? = nil,
workingDirectory: URL? = nil,
restoreMscoreeFirst: Bool = true,
+ headerNote: String? = nil,
onOutput: (@Sendable (String) -> Void)? = nil
) async throws -> LaunchResult {
try paths.ensure()
@@ -132,6 +133,9 @@ public struct WineRunner: Sendable {
header += "# note: \(note)\n"
onOutput?("note: \(note)")
}
+ // The caller's own caveat, e.g. a Steam client kept with another renderer: the header is
+ // what a report quotes, so the truth about the stack the game got must be in it.
+ if let headerNote { header += "# note: \(headerNote)\n" }
logHandle.write(Data(header.utf8))
let process = Process()
@@ -209,10 +213,10 @@ public struct WineRunner: Sendable {
/// Runs the executable directly under `wine` (not `start /unix`) so the process stays attached and
/// everything it and its children print lands in the log. The call returns when the program exits.
@discardableResult
- public func start(_ executable: URL, arguments: [String] = [], renderer: Renderer? = nil, extraEnvironment: [String: String] = [:], workingDirectory: URL? = nil, onOutput: (@Sendable (String) -> Void)? = nil) async throws -> LaunchResult {
+ public func start(_ executable: URL, arguments: [String] = [], renderer: Renderer? = nil, extraEnvironment: [String: String] = [:], workingDirectory: URL? = nil, headerNote: String? = nil, onOutput: (@Sendable (String) -> Void)? = nil) async throws -> LaunchResult {
await syncDllOverridesRegistry()
await syncKeyboardRegistry()
- return try await run([executable.path] + arguments, renderer: renderer, extraEnvironment: extraEnvironment, label: executable.lastPathComponent, workingDirectory: workingDirectory, onOutput: onOutput)
+ return try await run([executable.path] + arguments, renderer: renderer, extraEnvironment: extraEnvironment, label: executable.lastPathComponent, workingDirectory: workingDirectory, headerNote: headerNote, onOutput: onOutput)
}
/// Runs the pinned program, honouring its own renderer/env/args.
diff --git a/Tests/HighballKitTests/SteamRestartTests.swift b/Tests/HighballKitTests/SteamRestartTests.swift
index 0ced0bd..be73f15 100644
--- a/Tests/HighballKitTests/SteamRestartTests.swift
+++ b/Tests/HighballKitTests/SteamRestartTests.swift
@@ -51,4 +51,13 @@ final class SteamRestartTests: XCTestCase {
XCTAssertEqual(SteamRestart.reason(live: dxvk, wanted: wanted, wantedRenderer: "dxvk"),
"it runs with the Metal HUD off and the game wants it on")
}
+
+ func testRendererNameComesFromTheOverlayPath() {
+ let base = "/e/x64-crossover26.3-r8/frameworks/renderer"
+ XCTAssertEqual(SteamRestart.rendererName(ofLive: ["WINEDLLPATH_PREPEND": "/e/x/renderers/d3dmetal-tsshim/wine:\(base)/d3dmetal/wine:\(base)/d9vk/wine"]), "d3dmetal")
+ XCTAssertEqual(SteamRestart.rendererName(ofLive: ["WINEDLLPATH_PREPEND": "\(base)/d9vk/wine:\(base)/dxmt/wine"]), "dxmt")
+ XCTAssertEqual(SteamRestart.rendererName(ofLive: ["WINEDLLPATH_PREPEND": "\(base)/d9vk/wine:\(base)/dxvk/wine"]), "dxvk")
+ XCTAssertEqual(SteamRestart.rendererName(ofLive: ["WINEDLLPATH_PREPEND": "/e/x/renderers/dxmt/wine:\(base)/d9vk/wine"]), "dxmt")
+ XCTAssertEqual(SteamRestart.rendererName(ofLive: [:]), "wined3d")
+ }
}