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
D3DMetal shim for Game Porting Toolkit 4.0 beta 3, and the shim's copy of D3DMetal's d3d12.dll follows it by content. Beta 3 adds the Agility SDK entry point D3D12GetInterface (with a d3d12core.dll beside d3d12.dll) and renumbers the two Serialize exports to 110 and 111. The shim now exports D3D12GetInterface at 109 and forwards it, answering E_NOINTERFACE when the D3DMetal behind it lacks the call, and a device factory it hands out gets its CreateDevice wrapped so devices made that way get the same patches (timestamps, the depth resolve, the opt-in atomics answer). Built as d3dmetal-tsshim-20261015 for beta 3 engines only; engines with older D3DMetal keep 20261014, whose ordinals match theirs.
Gauthier Piarrette6332bc7a70f2
diff --git a/Sources/HighballKit/EngineStore.swift b/Sources/HighballKit/EngineStore.swiftindex 96971aa..593d5e6 100644--- a/Sources/HighballKit/EngineStore.swift+++ b/Sources/HighballKit/EngineStore.swift@@ -645,7 +645,10 @@ public struct InstalledEngine: Sendable {/// in nine bytes: its internal export name, because Wine 10 tells builtin modules apart by file/// name but CrossOver's Wine 11 by that internal name, and with it untouched the copy came back/// as the shim itself (no DirectX 12 device at all, 2026-09-08). Idempotent, and redone when the- /// D3DMetal files change (an engine update replaces them).+ /// D3DMetal files change. The copy is compared by content: D3DMetal 4.0 beta 2 and beta 3 ship+ /// d3d12.dll at the same size, and a file unpacked from an archive keeps its build date, older+ /// than a copy made earlier, so a size and date check kept beta 2's copy in front of beta 3 in an+ /// engine whose D3DMetal was replaced in place (2026-10-15).public func timestampShimDir(d3dmetal: URL) -> URL? {guard let shim = rendererDir("d3dmetal-tsshim") else { return nil }let fm = FileManager.default@@ -654,15 +657,10 @@ public struct InstalledEngine: Sendable {let pe = shim.appending(path: "wine/\(manifest.pe64LibDir)/\(Self.shimRealName).dll")let so = shim.appending(path: "wine/\(manifest.unixLibDir)/\(Self.shimRealName).so")do {- let realAttrs = try fm.attributesOfItem(atPath: realPE.path)- let current = (try? fm.attributesOfItem(atPath: pe.path))- let fresh = current != nil- && current?[.size] as? UInt64 == realAttrs[.size] as? UInt64- && ((current?[.modificationDate] as? Date) ?? .distantPast) >= ((realAttrs[.modificationDate] as? Date) ?? .distantPast)- && (try? PEExportName.read(Data(contentsOf: pe))) == "\(Self.shimRealName).dll"- if !fresh {+ let wanted = try PEExportName.patched(Data(contentsOf: realPE), to: "\(Self.shimRealName).dll")+ if (try? Data(contentsOf: pe)) != wanted {try? fm.removeItem(at: pe)- try PEExportName.patched(Data(contentsOf: realPE), to: "\(Self.shimRealName).dll").write(to: pe)+ try wanted.write(to: pe)}try fm.createDirectory(at: so.deletingLastPathComponent(), withIntermediateDirectories: true)if (try? fm.destinationOfSymbolicLink(atPath: so.path)) != realSO.path {diff --git a/Tests/HighballKitTests/PEExportNameTests.swift b/Tests/HighballKitTests/PEExportNameTests.swiftindex 1db5aa3..2bf7584 100644--- a/Tests/HighballKitTests/PEExportNameTests.swift+++ b/Tests/HighballKitTests/PEExportNameTests.swift@@ -75,3 +75,41 @@ final class PEExportNameTests: XCTestCase {XCTAssertEqual(PEExportName.read(try PEExportName.patched(d, to: "apd12.dll")), "apd12.dll")}}++/// The copy of D3DMetal's d3d12.dll laid out behind the timestamp shim follows the D3DMetal files by+/// content. D3DMetal 4.0 beta 2 and beta 3 ship d3d12.dll at the same size, and an unpacked file keeps+/// its build date, so the earlier size and date check kept beta 2's copy in front of beta 3 when the+/// D3DMetal files were replaced inside an engine (2026-10-15).+final class TimestampShimLayoutTests: XCTestCase {+ func testTheCopyFollowsD3DMetalWhenItChangesAtTheSameSize() throws {+ let fm = FileManager.default+ let root = fm.temporaryDirectory.appending(path: "hb-shim-\(UUID().uuidString)")+ defer { try? fm.removeItem(at: root) }+ let d3dmetal = root.appending(path: "renderers/d3dmetal")+ let realPE = d3dmetal.appending(path: "wine/x86_64-windows/d3d12.dll")+ try fm.createDirectory(at: realPE.deletingLastPathComponent(), withIntermediateDirectories: true)+ try fm.createDirectory(at: d3dmetal.appending(path: "wine/x86_64-unix"), withIntermediateDirectories: true)+ try Data().write(to: d3dmetal.appending(path: "wine/x86_64-unix/d3d12.so"))+ let shimPE = root.appending(path: "renderers/d3dmetal-tsshim/wine/x86_64-windows/d3d12.dll")+ try fm.createDirectory(at: shimPE.deletingLastPathComponent(), withIntermediateDirectories: true)+ try Data("shim".utf8).write(to: shimPE)+ var m = EngineManifest(id: "x64-test-r1", displayName: "test", arch: "x86_64", minMacOS: "14.0", components: [:])+ m.acceptedLicenses = [EngineManifest.gatedRenderers["d3dmetal"]!]+ let engine = InstalledEngine(manifest: m, root: root)++ var beta2 = SyntheticPE.make(exportName: "d3d12.dll"); beta2[0x500] = 2+ var beta3 = SyntheticPE.make(exportName: "d3d12.dll"); beta3[0x500] = 3+ XCTAssertEqual(beta2.count, beta3.count)+ try beta2.write(to: realPE)+ let shim = try XCTUnwrap(engine.timestampShimDir(d3dmetal: d3dmetal))+ let copy = shim.appending(path: "wine/x86_64-windows/\(InstalledEngine.shimRealName).dll")+ XCTAssertEqual(try Data(contentsOf: copy), try PEExportName.patched(beta2, to: "apd12.dll"))++ try beta3.write(to: realPE)+ try fm.setAttributes([.modificationDate: Date(timeIntervalSinceNow: -86400 * 30)], ofItemAtPath: realPE.path)+ _ = try XCTUnwrap(engine.timestampShimDir(d3dmetal: d3dmetal))+ XCTAssertEqual(try Data(contentsOf: copy), try PEExportName.patched(beta3, to: "apd12.dll"),+ "same size and an older date, still replaced")+ XCTAssertEqual(PEExportName.read(try Data(contentsOf: copy)), "apd12.dll")+ }+}diff --git a/spike/tsshim/d3d12.c b/spike/tsshim/d3d12.cindex e24c7f2..36372aa 100644--- a/spike/tsshim/d3d12.c+++ b/spike/tsshim/d3d12.c@@ -479,6 +479,50 @@ HRESULT WINAPI D3D12CreateDevice(IUnknown *adapter, D3D_FEATURE_LEVEL level, REFreturn hr;}+// D3D12GetInterface, the Agility SDK entry point D3DMetal exports from 4.0 beta 3 (with a d3d12core.dll+// beside it). A game can create its device through the ID3D12DeviceFactory it hands out instead of+// D3D12CreateDevice, so a factory's CreateDevice is wrapped to patch those devices the same way. A+// D3DMetal without the export (3.0, 4.0 beta 2) gets E_NOINTERFACE, which is what a game would see+// from a Windows d3d12.dll that predates the Agility SDK.+static HRESULT (STDMETHODCALLTYPE *real_FactoryCreateDevice)(ID3D12DeviceFactory *, IUnknown *, D3D_FEATURE_LEVEL, REFIID, void **);+static HRESULT STDMETHODCALLTYPE hook_FactoryCreateDevice(ID3D12DeviceFactory *f, IUnknown *adapter, D3D_FEATURE_LEVEL level, REFIID riid, void **out)+{+ HRESULT hr = real_FactoryCreateDevice(f, adapter, level, riid, out);+ if (SUCCEEDED(hr) && out && *out) {+ ID3D12Device *dev = NULL; IUnknown *u = (IUnknown *)*out;+ if (SUCCEEDED(u->lpVtbl->QueryInterface(u, &IID_ID3D12Device, (void **)&dev)) && dev) { patch_device(dev); dev->lpVtbl->Release(dev); }+ }+ return hr;+}+static void patch_factory_vtbl(void *iface)+{+ ID3D12DeviceFactoryVtbl *vt = *(ID3D12DeviceFactoryVtbl **)iface;+ patch_slot((void **)&vt->CreateDevice, (void *)hook_FactoryCreateDevice, (void **)&real_FactoryCreateDevice);+}++HRESULT WINAPI D3D12GetInterface(REFCLSID clsid, REFIID riid, void **out)+{+ typedef HRESULT (WINAPI *PFN)(REFCLSID, REFIID, void **);+ PFN fn = real_dll ? (PFN)GetProcAddress(real_dll, "D3D12GetInterface") : NULL;+ HRESULT hr;+ if (!fn) {+ LOG("D3D12GetInterface asked of a D3DMetal without it");+ if (out) *out = NULL;+ return E_NOINTERFACE;+ }+ hr = fn(clsid, riid, out);+ if (SUCCEEDED(hr) && out && *out && !idle) {+ ID3D12DeviceFactory *factory = NULL; IUnknown *u = (IUnknown *)*out;+ if (SUCCEEDED(u->lpVtbl->QueryInterface(u, &IID_ID3D12DeviceFactory, (void **)&factory)) && factory) {+ patch_factory_vtbl(factory);+ LOG("device factory %p patched", (void *)factory);+ factory->lpVtbl->Release(factory);+ }+ }+ if (dbg) LOG("D3D12GetInterface hr=0x%08lx", (unsigned long)hr);+ return hr;+}+BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved){if (reason == DLL_PROCESS_ATTACH) {diff --git a/spike/tsshim/d3d12.def b/spike/tsshim/d3d12.defindex 4ed3af5..b1d6af5 100644--- a/spike/tsshim/d3d12.def+++ b/spike/tsshim/d3d12.def@@ -9,5 +9,6 @@ EXPORTSD3D12CreateRootSignatureDeserializer @106D3D12CreateVersionedRootSignatureDeserializer @107D3D12EnableExperimentalFeatures @108- D3D12SerializeRootSignature @109- D3D12SerializeVersionedRootSignature @110+ D3D12GetInterface @109+ D3D12SerializeRootSignature @110+ D3D12SerializeVersionedRootSignature @111