Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
feat(dlss): link GPTK nvngx-on-metalfx as nvngx and gate it with NVAPI
raymondchinsd0a2c7a5dc96
diff --git a/app/Sources/NotProtonApp/Model/FreeEngineWinecxD3DMetal.swift b/app/Sources/NotProtonApp/Model/FreeEngineWinecxD3DMetal.swiftindex e9324e9..5eb5c9b 100644--- a/app/Sources/NotProtonApp/Model/FreeEngineWinecxD3DMetal.swift+++ b/app/Sources/NotProtonApp/Model/FreeEngineWinecxD3DMetal.swift@@ -16,8 +16,10 @@// lib/wine/x86_64-{windows,unix}/nvapi64.* -> the user's, when the GPTK has them. Wine has// none of its own here. compat_run.sh disables it unless a game's conf says NVAPI=1,// since an nvapi that answers sends some games down NVIDIA-only paths.-// nvngx-on-metalfx is not linked: it only serves DLSS through that nvapi, and CrossOver-// renames it to nvngx.dll per prefix, which NotProton does not do.+// lib/wine/x86_64-{windows,unix}/nvngx.* -> the user's nvngx-on-metalfx.*, DLSS served+// by MetalFX. CrossOver copies it into each prefix as nvngx.dll; linking it under+// that name here lets the prefix's placeholder nvngx.dll resolve to it. compat_run.sh+// gates it together with nvapi64.// lib/external/{D3DMetal.framework,libd3dshared.dylib} -> the user's external/// winecx's own lib/external, and the CX_APPLEGPTK_LIBD3DSHARED_PATH winecx's ntdll// dlopens for non-native code regions.@@ -32,8 +34,10 @@ import Foundationenum WinecxD3DMetal {static let forwarders = ["d3d10.dll", "d3d11.dll", "d3d12.dll", "dxgi.dll"]- // Linked when the GPTK has it, never required. Wine's tree has no file of this name.- static let optionalForwarders = ["nvapi64.dll"]+ // Linked when the GPTK has it, never required. Wine's tree has no file of these names.+ static let optionalForwarders = ["nvapi64.dll", "nvngx.dll"]+ // The GPTK file an optional forwarder links to, when its name differs.+ static let optionalSources = ["nvngx.dll": "nvngx-on-metalfx.dll"]static let sharedLibrary = "libd3dshared.dylib"static let framework = "D3DMetal.framework"@@ -50,6 +54,10 @@ enum WinecxD3DMetal {(forwarder as NSString).deletingPathExtension + ".so"}+ static func sourceName(of forwarder: String) -> String {+ optionalSources[forwarder] ?? forwarder+ }+struct Payload: Sendable, Equatable {// The folder holding external/ and wine/.let libRoot: URL@@ -141,15 +149,15 @@ enum WinecxD3DMetal {(root.appending(path: "\(externalPath)/\(sharedLibrary)"), shared),]let optional = optionalForwarders.filter { name in- isBuiltin(source.appending(path: "wine/x86_64-windows/\(name)"))+ isBuiltin(source.appending(path: "wine/x86_64-windows/\(sourceName(of: name))"))&& !exists(root.appending(path: "\(builtinPath)/\(name)"))}for name in forwarders + optional {links.append((root.appending(path: "\(builtinPath)/\(name)"),- source.appending(path: "wine/x86_64-windows/\(name)").path(percentEncoded: false)))+ source.appending(path: "wine/x86_64-windows/\(sourceName(of: name))").path(percentEncoded: false)))// Apple's own unix half when the GPTK ships one, which is itself a link to// libd3dshared, otherwise libd3dshared directly.- let unix = source.appending(path: "wine/x86_64-unix/\(unixName(of: name))")+ let unix = source.appending(path: "wine/x86_64-unix/\(unixName(of: sourceName(of: name)))")links.append((root.appending(path: "\(unixPath)/\(unixName(of: name))"),fm.fileExists(atPath: unix.path(percentEncoded: false))? unix.path(percentEncoded: false) : shared))diff --git a/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift b/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swiftindex 76b134d..7fcf7da 100644--- a/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift+++ b/app/Tests/NotProtonAppTests/FreeEngineWinecxTests.swift@@ -373,12 +373,13 @@ struct FreeEngineWinecxTests {== source.appending(path: "external/libd3dshared.dylib").path(percentEncoded: false))#expect(try destination(of: root.appending(path: "lib/external/D3DMetal.framework"))== source.appending(path: "external/D3DMetal.framework").path(percentEncoded: false))- for name in WinecxD3DMetal.forwarders + ["nvapi64.dll"] {+ for name in WinecxD3DMetal.forwarders + ["nvapi64.dll", "nvngx.dll"] {+ let from = WinecxD3DMetal.sourceName(of: name)#expect(try destination(of: root.appending(path: "lib/wine/x86_64-windows/\(name)"))- == source.appending(path: "wine/x86_64-windows/\(name)").path(percentEncoded: false))+ == source.appending(path: "wine/x86_64-windows/\(from)").path(percentEncoded: false))let so = WinecxD3DMetal.unixName(of: name)#expect(try destination(of: root.appending(path: "lib/wine/x86_64-unix/\(so)"))- == source.appending(path: "wine/x86_64-unix/\(so)").path(percentEncoded: false))+ == source.appending(path: "wine/x86_64-unix/\(WinecxD3DMetal.unixName(of: from))").path(percentEncoded: false))// Through Apple's own relative link, onto the shared library.#expect(try Data(contentsOf: root.appending(path: "lib/wine/x86_64-unix/\(so)")) == Data("dylib".utf8))}@@ -386,7 +387,7 @@ struct FreeEngineWinecxTests {let saved = root.appending(path: "lib/notproton-backends/wine-stock/x86_64-windows/\(name)")#expect(Digest.sha256IfPresent(saved) == Self.stock[name])}- // nvngx-on-metalfx is left out.+ // nvngx-on-metalfx is linked as nvngx, never under its own name.#expect(!fm.fileExists(atPath: root.appending(path: "lib/wine/x86_64-windows/nvngx-on-metalfx.dll").path(percentEncoded: false)))#expect(!fm.fileExists(atPath: root.appending(path: "lib/notproton-backends/d3dmetal").path(percentEncoded: false)))#expect(fm.fileExists(atPath: root.appending(path: "lib/external/README").path(percentEncoded: false)))@@ -602,7 +603,7 @@ struct FreeEngineWinecxTests {#expect(WinecxD3DMetal.isLinked(root: root))#expect(WinecxD3DMetal.layoutProblems(root: root, stock: Self.stock).isEmpty)let shared = try Data(contentsOf: payload.libRoot.appending(path: "external/libd3dshared.dylib"))- for name in WinecxD3DMetal.forwarders + ["nvapi64.dll"] {+ for name in WinecxD3DMetal.forwarders + ["nvapi64.dll", "nvngx.dll"] {let pe = root.appending(path: "lib/wine/x86_64-windows/\(name)")#expect(WinecxD3DMetal.isBuiltin(pe), "\(name)")#expect(try Data(contentsOf: root.appending(path: "lib/wine/x86_64-unix/\(WinecxD3DMetal.unixName(of: name))"))diff --git a/docs/GAMEFIXES.md b/docs/GAMEFIXES.mdindex fe62031..90da649 100644--- a/docs/GAMEFIXES.md+++ b/docs/GAMEFIXES.md@@ -31,7 +31,7 @@ logged, when:| `FRAMEGEN_UI` | `0`, `1` | Same as `NOTPROTON_FRAMEGEN_UI`, Protect UI: keeps static HUD and menus sharp. On when unset || `FRAMEGEN_FALLBACK` | `0`, `1` | Same as `NOTPROTON_FRAMEGEN_FALLBACK`, Fast-motion fallback: skips generated frames that would smear. On when unset || `FRAMEGEN_ENGINE` | `own`, `metalfx` | Same as `NOTPROTON_FRAMEGEN_ENGINE`: the built-in optical flow (`own`, the default) or MetalFX frame interpolation |-| `NVAPI` | `0`, `1` | `1` turns on Apple's `nvapi64` on an engine with a linked Game Porting Toolkit, for `d3dmetal` only. Off by default, since an nvapi that answers sends some games down NVIDIA-only paths |+| `NVAPI` | `0`, `1` | `1` turns on Apple's `nvapi64` and `nvngx` (DLSS on MetalFX) on an engine with a linked Game Porting Toolkit, for `d3dmetal` only. Off by default, since an nvapi that answers sends some games down NVIDIA-only paths || `DXMT_*`, `DXVK_*`, `MVK_*`, `VKD3D_*`, `D3DM_*`, `STAGING_*` | any | Exported as is || `MTL_HUD_ENABLED`, `WINEDEBUG`, `WINE_LARGE_ADDRESS_AWARE`, `WINE_CPU_TOPOLOGY` | any | Exported as is |@@ -78,7 +78,7 @@ are set aside. So on that engine:and `d3d10`/`d3d12` stay builtin, which is Apple's- `d3dmetal` sets every D3D DLL (`d3d10`, `d3d10core`, `d3d11`, `d3d12`, `dxgi`) to `b`,exports `CX_GRAPHICS_BACKEND=d3dmetal` and `CX_APPLEGPTK_LIBD3DSHARED_PATH`-- Apple's `nvapi64` is set to `d` unless the conf says `NVAPI=1` and the backend is+- Apple's `nvapi64` and `nvngx` are set to `d` unless the conf says `NVAPI=1` and the backend is`d3dmetal`Without a linked Game Porting Toolkit the WineCX engine behaves like the WineHQ one.diff --git a/docs/WINECX.md b/docs/WINECX.mdindex 3ab74cd..ba86bb8 100644--- a/docs/WINECX.md+++ b/docs/WINECX.md@@ -252,9 +252,12 @@ What `compat_run.sh` does with it is in [GAMEFIXES.md](GAMEFIXES.md#winecx-with-`d3dmetal` becomes the default and the D3D12 choice, `wined3d` runs `d3dmetal`, and `dxmt`and `dxvk` still work per game as natives.-`nvngx-on-metalfx.dll` is not linked. It only serves DLSS through Apple's nvapi, and-CrossOver renames it to `nvngx.dll` per prefix, which NotProton does not do. Apple's-`nvapi64` is linked but disabled per game unless its conf says `NVAPI=1`.+`nvngx-on-metalfx.dll` is linked as `nvngx.dll` (and its unix half as `nvngx.so`), the+name CrossOver gives it when it copies it into each prefix. The prefix's placeholder+`nvngx.dll` then resolves to it, and the prefix gets `HKLM\Software\NVIDIA Corporation\Global\NGXCore`+`FullPath=C:\Windows\System32` so the game's NGX loader finds it. Apple's `nvapi64` and+`nvngx` are linked but disabled per game unless its conf says `NVAPI=1`. With both on and+`D3DM_ENABLE_METALFX=1`, games show DLSS and D3DMetal serves it with MetalFX.## Using D3DMetal with your own Game Porting Toolkitdiff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex f75d448..c082c45 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -683,15 +683,19 @@ activate_backend() {donebackend_overrides="${native:+$native=n,b}"[ -z "$builtin" ] || backend_overrides="${backend_overrides:+$backend_overrides;}$builtin=b"- # A linked Game Porting Toolkit can bring Apple's nvapi64 into lib/wine. An nvapi that- # answers sends some games down NVIDIA-only paths, so it stays disabled unless the game's- # conf says NVAPI=1, and then only on D3DMetal, the only backend it talks to.+ # A linked Game Porting Toolkit can bring Apple's nvapi64 and nvngx (DLSS on MetalFX) into+ # lib/wine. An nvapi that answers sends some games down NVIDIA-only paths, so both stay+ # disabled unless the game's conf says NVAPI=1, and then only on D3DMetal, the only+ # backend they talk to.if d3dmetal_engine && [ -e "$CX_ROOT/lib/wine/x86_64-windows/nvapi64.dll" ]; then+ nv_dlls=nvapi64+ [ ! -e "$CX_ROOT/lib/wine/x86_64-windows/nvngx.dll" ] || nv_dlls="nvapi64,nvngx"if [ "$gamefix_nvapi" = 1 ] && [ "$backend" = d3dmetal ]; then- backend_overrides="${backend_overrides:+$backend_overrides;}nvapi64=b"+ backend_overrides="${backend_overrides:+$backend_overrides;}$nv_dlls=b"+ graphics_log "NVAPI=1: $nv_dlls on"else[ "$gamefix_nvapi" != 1 ] || graphics_log "NVAPI=1 not applied, $backend is not d3dmetal"- backend_overrides="${backend_overrides:+$backend_overrides;}nvapi64=d"+ backend_overrides="${backend_overrides:+$backend_overrides;}$nv_dlls=d"fifiif [ "$backend" = d3dmetal ]; then@@ -1083,6 +1087,8 @@ import_prefix_settings() {'[HKEY_CURRENT_USER\Software\Wine\WineDbg]' '"ShowCrashDialog"=dword:00000000' '' \'[HKEY_CURRENT_USER\Software\Wine\Mac Driver]' "$retina_line" '' \'[HKEY_LOCAL_MACHINE\Software\Classes\steam]' '"URL Protocol"=""' '' \+ '[HKEY_LOCAL_MACHINE\Software\NVIDIA Corporation\Global\NGXCore]' \+ '"FullPath"="C:\\Windows\\System32"' '' \'[HKEY_LOCAL_MACHINE\Software\Classes\steam\shell\open\command]' \'@="\"C:\\Program Files (x86)\\Steam\\steam.exe\" \"%1\""' '' \&& hidraw_lines add "$controllers_add" && hidraw_lines remove "$controllers_remove"; } \diff --git a/dylib/tests/gamefixescheck.sh b/dylib/tests/gamefixescheck.shindex 70364c0..d0c9151 100644--- a/dylib/tests/gamefixescheck.sh+++ b/dylib/tests/gamefixescheck.sh@@ -66,7 +66,9 @@ engine() {ln -s "$case_dir/gptk/$dll.dll" "$case_dir/engine/lib/wine/x86_64-windows/$dll.dll"doneprintf 'apple nvapi64\n' > "$case_dir/gptk/nvapi64.dll"- ln -s "$case_dir/gptk/nvapi64.dll" "$case_dir/engine/lib/wine/x86_64-windows/nvapi64.dll" ;;+ ln -s "$case_dir/gptk/nvapi64.dll" "$case_dir/engine/lib/wine/x86_64-windows/nvapi64.dll"+ printf 'apple nvngx-on-metalfx\n' > "$case_dir/gptk/nvngx-on-metalfx.dll"+ ln -s "$case_dir/gptk/nvngx-on-metalfx.dll" "$case_dir/engine/lib/wine/x86_64-windows/nvngx.dll" ;;msync) : > "$case_dir/engine/.notproton-msync" ;;empty) mkdir -p "$case_dir/engine/lib/notproton-backends" ;;*) mkdir -p "$case_dir/engine/lib/notproton-backends/${file%/*}"@@ -345,7 +347,7 @@ engine d3dmetal-linkedlaunch waitforexitandrun 'steam://rungameid/4242'is "the default is d3dmetal" "d3dmetal" "$(got backend)"has "logged as default" "backend=d3dmetal (default)" "$case_dir/log"-is "every D3D DLL is builtin, Apple's nvapi64 disabled" "d3d10,d3d10core,d3d11,d3d12,dxgi=b;nvapi64=d;$trio" "$(got WINEDLLOVERRIDES)"+is "every D3D DLL is builtin, Apple's nvapi64 and nvngx disabled" "d3d10,d3d10core,d3d11,d3d12,dxgi=b;nvapi64,nvngx=d;$trio" "$(got WINEDLLOVERRIDES)"is "CX_GRAPHICS_BACKEND is exported" "d3dmetal" "$(got CX_GRAPHICS_BACKEND)"launch waitforexitandrun "$case_dir/game/game.exe"is "a D3D11 game auto-detects d3dmetal" "d3dmetal" "$(got backend)"@@ -363,12 +365,12 @@ is "so does a conf BACKEND=wined3d" "d3dmetal" "$(got backend)"user_conf 'BACKEND=dxmt'launch waitforexitandrun "$case_dir/game/game.exe"is "dxmt still works per game" "dxmt" "$(got backend)"-is "as natives, with Apple's d3d10 and d3d12 builtin" "d3d10core,d3d11,dxgi=n,b;d3d10,d3d12=b;nvapi64=d;$trio" "$(got WINEDLLOVERRIDES)"+is "as natives, with Apple's d3d10 and d3d12 builtin" "d3d10core,d3d11,dxgi=n,b;d3d10,d3d12=b;nvapi64,nvngx=d;$trio" "$(got WINEDLLOVERRIDES)"is "dxmt dxgi is in system32" "backend dxmt/x86_64-windows/dxgi.dll" "$(sys system32 dxgi)"is "and CX_GRAPHICS_BACKEND is left alone" "<unset>" "$(got CX_GRAPHICS_BACKEND)"user_conf 'BACKEND=dxvk'launch waitforexitandrun "$case_dir/game/game.exe"-is "dxvk still works per game" "d3d10core,d3d11=n,b;d3d10,d3d12,dxgi=b;nvapi64=d;$trio" "$(got WINEDLLOVERRIDES)"+is "dxvk still works per game" "d3d10core,d3d11=n,b;d3d10,d3d12,dxgi=b;nvapi64,nvngx=d;$trio" "$(got WINEDLLOVERRIDES)"is "the stale dxmt dxgi goes back to Wine's set-aside copy, never Apple's" "stock x86_64-windows dxgi" "$(sys system32 dxgi)"user_conf ''launch waitforexitandrun "$case_dir/game/game.exe"@@ -376,10 +378,10 @@ is "back on d3dmetal, dxvk's d3d11 goes back to Wine's copy" "stock x86_64-windois "and nothing of Apple's is copied into the prefix" "0" "$(grep -rl '^apple ' "$case_dir/data/pfx" | wc -l | tr -d ' ')"user_conf 'NVAPI=1'launch waitforexitandrun "$case_dir/game/game.exe"-is "a conf NVAPI=1 turns Apple's nvapi64 on" "d3d10,d3d10core,d3d11,d3d12,dxgi=b;nvapi64=b;$trio" "$(got WINEDLLOVERRIDES)"+is "a conf NVAPI=1 turns Apple's nvapi64 and nvngx (DLSS) on" "d3d10,d3d10core,d3d11,d3d12,dxgi=b;nvapi64,nvngx=b;$trio" "$(got WINEDLLOVERRIDES)"user_conf 'NVAPI=1' 'BACKEND=dxmt'launch waitforexitandrun "$case_dir/game/game.exe"-is "but not for dxmt" "d3d10core,d3d11,dxgi=n,b;d3d10,d3d12=b;nvapi64=d;$trio" "$(got WINEDLLOVERRIDES)"+is "but not for dxmt" "d3d10core,d3d11,dxgi=n,b;d3d10,d3d12=b;nvapi64,nvngx=d;$trio" "$(got WINEDLLOVERRIDES)"has "and says so" "NVAPI=1 not applied, dxmt is not d3dmetal" "$case_dir/log"user_conf 'NVAPI=yes'launch waitforexitandrun "$case_dir/game/game.exe"