Play Windows games on Apple Silicon Macs. Free, open-source app that installs the official Battle.net, Steam, Epic and GOG launchers and lists your games in one library.
HTML apple-siliconbattle-netcrossover-alternatived3dmetaldiablo-ii-resurrecteddxmtea-appepic-gamesgame-porting-toolkitgogmac-gamingmacosmacos-gamingrockstar-gamessteamubisoft-connectwhisky-alternativewindows-gameswinewine-wrapper
Games that offer NVIDIA DLSS can use it, done by Apple's MetalFX (#191)
Mikek4439a93ab7ee
diff --git a/scripts/gptk-dlss.sh b/scripts/gptk-dlss.shnew file mode 100644index 00000000000..0273713ebf8--- /dev/null+++ b/scripts/gptk-dlss.sh@@ -0,0 +1,45 @@+#!/usr/bin/env bash+# gptk-dlss.sh <engine> <prefix>: make NVIDIA DLSS work in games through+# Apple's MetalFX (D3DMetal's NGX bridge). Run before every launch; it only+# writes when something is missing, and does nothing on an engine without+# Apple's nvngx-on-metalfx shim (no GPTK, or a toolkit older than 3.0).+# Exit status 0 when the bridge is ready (the caller then sets+# D3DM_ENABLE_METALFX=1), 1 otherwise.+#+# Verified 2026-11-24 on an M4 Pro, macOS 26.5, GPTK 3.0: Hogwarts Legacy+# (Epic) lists "NVIDIA DLSS" and the Metal HUD shows MetalFX temporal scaling+# 2295x961 -> 3440x1440. With the engine parts alone, or with them and the+# registry key but Wine's placeholder still in system32, the game offers no DLSS.+# 1. Games and the NGX loader ask for nvngx.dll; Apple ships the shim as+# nvngx-on-metalfx.dll (CrossOver ships the same file as nvngx.dll), so the+# engine gets a copy under that name, and the bottle's system32 gets it in+# place of Wine's placeholder, which the NGX loader does not accept.+# 2. Its unixlib, nvngx.so, must be a symlink to libd3dshared.dylib like the+# other shims' (get-gptk.sh): a copied file looks for D3DMetal.framework+# next to itself (@loader_path), fails ("Failed to dlopen D3DMetal") and+# aborts every process that loads it, the Epic launcher included.+# 3. The NGX loader inside games finds nvngx.dll through+# HKLM\SOFTWARE\NVIDIA Corporation\Global\NGXCore FullPath, which only+# NVIDIA's driver writes on Windows.+set -u+ENGINE="${1:?engine}"; PREFIX="${2:?prefix}"+W="$ENGINE/lib/wine/x86_64-windows"; U="$ENGINE/lib/wine/x86_64-unix"+[ -f "$W/nvngx-on-metalfx.dll" ] && [ -f "$ENGINE/lib/external/libd3dshared.dylib" ] || exit 1++if ! cmp -s "$W/nvngx-on-metalfx.dll" "$W/nvngx.dll" 2>/dev/null; then+ cp -f "$W/nvngx-on-metalfx.dll" "$W/nvngx.dll.new" && mv -f "$W/nvngx.dll.new" "$W/nvngx.dll" || exit 1+fi+if [ "$(readlink "$U/nvngx.so" 2>/dev/null)" != ../../external/libd3dshared.dylib ]; then+ rm -f "$U/nvngx.so"; ln -s ../../external/libd3dshared.dylib "$U/nvngx.so" || exit 1+fi++[ -f "$PREFIX/system.reg" ] || exit 1+S="$PREFIX/drive_c/windows/system32"+if [ -d "$S" ] && ! cmp -s "$W/nvngx.dll" "$S/nvngx.dll" 2>/dev/null; then+ cp -f "$W/nvngx.dll" "$S/nvngx.dll.new" && mv -f "$S/nvngx.dll.new" "$S/nvngx.dll" || exit 1+fi+if ! grep -qi '^\[Software\\\\NVIDIA Corporation\\\\Global\\\\NGXCore\]' "$PREFIX/system.reg"; then+ WINEPREFIX="$PREFIX" WINEDEBUG=-all "$ENGINE/bin/wine" reg add 'HKLM\SOFTWARE\NVIDIA Corporation\Global\NGXCore' \+ /v FullPath /t REG_SZ /d 'C:\Windows\System32' /f >/dev/null 2>&1 || exit 1+fi+exit 0diff --git a/scripts/play.sh b/scripts/play.shindex 30012a3d3bb..bd48c69d6af 100755--- a/scripts/play.sh+++ b/scripts/play.sh@@ -68,6 +68,16 @@ case "$MODE" inENGINE=$(SOJU_CX_ENGINE="$ENGINE" bash "$(dirname "${BASH_SOURCE[0]}")/launcher-engine.sh") || exit 1 ;;esac+# NVIDIA DLSS in D3DMetal games, done by Apple's MetalFX (scripts/gptk-dlss.sh): games that offer DLSS list it+# in their settings. SOJU_DLSS=0 leaves it off. A launcher already running keeps its old environment.+# Called once the Wine environment below is exported: the script may start the bottle's wineserver (wine reg),+# and a server started without WINEMSYNC=1 turns away the launcher that comes after it (msync_init fails).+dlss_on() {+ [ "${SOJU_DLSS:-1}" = 1 ] || return 0+ bash "$(dirname "${BASH_SOURCE[0]}")/gptk-dlss.sh" "$ENGINE" "$WINEPREFIX" && export D3DM_ENABLE_METALFX=1+ return 0+}+export WINEDEBUG="${WINEDEBUG:-fixme-all}"# SOJU_KEYLOG=1: record every key event the Mac driver sees and every focus# change, to ~/.battlenet-macos/logs/keys-<mode>-<time>.log. For "a key stays@@ -98,6 +108,7 @@ export CX_ACTIVE_GRAPHICS_BACKEND=d3dmetalexport CX_GRAPHICS_BACKEND=d3dmetalexport CX_APPLEGPTK_LIBD3DSHARED_PATH="$ENGINE/lib/external/libd3dshared.dylib"export DYLD_FALLBACK_LIBRARY_PATH="$ENGINE/lib:/usr/lib"+case "$MODE" in battlenet|d2r|epic|gog|ea|rockstar|ubisoft) dlss_on ;; esac# Agent signature-check fix: sync the signed exe into each versioned subfolderBN="$WINEPREFIX/drive_c/Program Files (x86)/Battle.net"@@ -371,6 +382,7 @@ case "$MODE" in# (scripts/steam-gptk-engine.sh). Same wrapper and flags as below; games# get D3DMetal like Battle.net games, and no Wine 11 steps apply.ENGINE=$(bash "$(dirname "${BASH_SOURCE[0]}")/steam-gptk-engine.sh") || exit 1+ dlss_onexport CX_APPLEGPTK_LIBD3DSHARED_PATH="$ENGINE/lib/external/libd3dshared.dylib"export DYLD_FALLBACK_LIBRARY_PATH="$ENGINE/lib:/usr/lib"ST="$WINEPREFIX/drive_c/Program Files (x86)/Steam/steam.exe"diff --git a/scripts/xbox-wine.sh b/scripts/xbox-wine.shindex f174efb5ebb..5e0fa0531c9 100755--- a/scripts/xbox-wine.sh+++ b/scripts/xbox-wine.sh@@ -22,6 +22,10 @@ export DYLD_FALLBACK_LIBRARY_PATH="$ENGINE/lib:/usr/lib"if [ "${1:-}" = "--soju-stop-prefix" ]; thenexec "$ENGINE/bin/wineserver" -kfi+# NVIDIA DLSS through MetalFX, as in play.sh (scripts/gptk-dlss.sh); after WINEMSYNC is set, since it may start the wineserver.+if [ "${SOJU_DLSS:-1}" = 1 ] && bash "$(dirname "$0")/gptk-dlss.sh" "$ENGINE" "$WINEPREFIX"; then+ export D3DM_ENABLE_METALFX=1+fi# xodus-cli stops a game by signalling this script. A shell waiting on a# foreground child ignores SIGINT, so wine runs in the background and the# signal is forwarded: the game gets a TERM, and anything still running indiff --git a/tests/test_gptk_dlss.py b/tests/test_gptk_dlss.pynew file mode 100644index 00000000000..4374dde2ed6--- /dev/null+++ b/tests/test_gptk_dlss.py@@ -0,0 +1,84 @@+import os+import subprocess+import tempfile+import unittest+from pathlib import Path++ROOT = Path(__file__).resolve().parent.parent+SCRIPT = ROOT / "scripts/gptk-dlss.sh"+++def fake_engine(base, shim=True):+ eng = Path(base) / "engine"+ (eng / "lib/wine/x86_64-windows").mkdir(parents=True)+ (eng / "lib/wine/x86_64-unix").mkdir(parents=True)+ (eng / "lib/external").mkdir(parents=True)+ (eng / "lib/external/libd3dshared.dylib").write_bytes(b"dylib")+ if shim:+ (eng / "lib/wine/x86_64-windows/nvngx-on-metalfx.dll").write_bytes(b"apple shim")+ (eng / "bin").mkdir()+ wine = eng / "bin/wine" # records its arguments instead of running Windows code+ wine.write_text('#!/bin/sh\necho "$@" >> "$WINEPREFIX/wine-calls"\n'+ 'printf \'\\n[Software\\\\\\\\Nvidia Corporation\\\\\\\\Global\\\\\\\\NGXCore] 1\\n\' >> "$WINEPREFIX/system.reg"\n')+ wine.chmod(0o755)+ return eng+++def run(eng, prefix):+ return subprocess.run(["bash", str(SCRIPT), str(eng), str(prefix)]).returncode+++class GptkDlssTests(unittest.TestCase):+ def test_engine_gets_nvngx_and_symlinked_unixlib_and_prefix_gets_ngxcore_once(self):+ with tempfile.TemporaryDirectory() as d:+ eng = fake_engine(d)+ prefix = Path(d) / "bottle"; prefix.mkdir()+ (prefix / "system.reg").write_text("WINE REGISTRY Version 2\n")+ sys32 = prefix / "drive_c/windows/system32"; sys32.mkdir(parents=True)+ (sys32 / "nvngx.dll").write_bytes(b"wine placeholder")+ for _ in range(2): # the second run changes nothing+ self.assertEqual(run(eng, prefix), 0)+ self.assertEqual((eng / "lib/wine/x86_64-windows/nvngx.dll").read_bytes(), b"apple shim")+ self.assertEqual((sys32 / "nvngx.dll").read_bytes(), b"apple shim")+ so = eng / "lib/wine/x86_64-unix/nvngx.so"+ # A copied unixlib looks for D3DMetal next to itself and aborts the process.+ self.assertTrue(so.is_symlink())+ self.assertEqual(os.readlink(so), "../../external/libd3dshared.dylib")+ calls = (prefix / "wine-calls").read_text().splitlines()+ self.assertEqual(len(calls), 1)+ self.assertIn("NGXCore", calls[0])+ self.assertIn("FullPath", calls[0])++ def test_a_copied_unixlib_is_replaced_by_the_symlink(self):+ with tempfile.TemporaryDirectory() as d:+ eng = fake_engine(d)+ prefix = Path(d) / "bottle"; prefix.mkdir()+ (prefix / "system.reg").write_text("x\n")+ (eng / "lib/wine/x86_64-unix/nvngx.so").write_bytes(b"copy")+ self.assertEqual(run(eng, prefix), 0)+ self.assertTrue((eng / "lib/wine/x86_64-unix/nvngx.so").is_symlink())++ def test_without_apples_shim_nothing_is_touched(self):+ with tempfile.TemporaryDirectory() as d:+ eng = fake_engine(d, shim=False)+ prefix = Path(d) / "bottle"; prefix.mkdir()+ (prefix / "system.reg").write_text("x\n")+ self.assertEqual(run(eng, prefix), 1)+ self.assertFalse((eng / "lib/wine/x86_64-windows/nvngx.dll").exists())+ self.assertFalse((eng / "lib/wine/x86_64-unix/nvngx.so").exists())+ self.assertFalse((prefix / "wine-calls").exists())++ def test_play_sh_turns_metalfx_on_only_when_the_bridge_is_ready(self):+ text = (ROOT / "scripts/play.sh").read_text()+ self.assertIn('gptk-dlss.sh" "$ENGINE" "$WINEPREFIX" && export D3DM_ENABLE_METALFX=1', text)+ self.assertIn("SOJU_DLSS", text)+ # It may start the bottle's wineserver; one started before WINEMSYNC=1 turns the launcher away.+ call = text.index("dlss_on ;; esac")+ self.assertLess(text.index("export WINEMSYNC=1"), call)+ xbox = (ROOT / "scripts/xbox-wine.sh").read_text()+ self.assertLess(xbox.index("WINEMSYNC"), xbox.index("gptk-dlss.sh"))+ self.assertIn("D3DM_ENABLE_METALFX=1", xbox)+++if __name__ == "__main__":+ unittest.main()