sahib453 2cc44b8318 Stop d3dmetal-harness runner tests racing probe start-up
kills_a_probe_that_exceeds_the_timeout and
a_descendant_holding_the_pipes_cannot_outlast_the_deadline gave a
freshly written script 300 ms and 500 ms to start and print, and the
first failed intermittently with empty stdout (#479). Both now use a
2 s deadline. The kill test also checks that the probe ran until the
deadline and that its process is gone afterwards. Test-only change.

Signed-off-by: sahib453 <sahibsingh4533@gmail.com>
2026-11-27 02:00:21 +05:30
2026-11-22 09:23:19 +05:30

BetterXen

Modular Xbox Series (Scarlett) compatibility layer for Apple Silicon macOS — built on CrossOver, Rosetta 2, and D3DMetal 3.0.

Hybrid build and shim checks Repository hygiene Platform: Apple Silicon Graphics: D3DMetal 3.0 Stack: Rust + C++20 PE32+ Status: experimental License: GPL-3.0-or-later

Important

Experimental status. BetterXen is an active, open-source compatibility engineering project with Milestone M0 and Milestone M1 verified complete on synthetic PE32+ workloads under CrossOver 26.3 + Rosetta 2, and Milestone M2 (First Rendered Frame & Shader Format Gate) currently active. Commercial Xbox game execution is not yet supported. CrossOver, Rosetta 2, and D3DMetal are externally installed dependencies and are never bundled or redistributed.

BetterXen builds the missing Xbox Game OS layer around CrossOver 26.3+, Rosetta 2, and D3DMetal 3.0 on Apple Silicon:

  • Native ARM64 macOS tooling (launcher/, Rust) for host diagnostics, PE32+ static probing, CrossOver bottle orchestration, and structured trace aggregation.
  • Cross-compiled x86-64 Windows PE32+ shim DLLs (shims/, C++20 via mingw-w64) implementing Xbox runtime APIs (xmem, XCRDAPI, d3d12_xs, xg_xs, xgameruntime, GameInput, AcpHal/xapu/chad, Win32/PSM forwarders, and a clwb Vectored Exception Handler).
  • Shader pipeline (shader-transpiler/, Rust) for classifying DXBC containers (DXIL vs. ACCC/FSPX RDNA 2 machine code) and handling console shader translation where required.

Caution

Clean-room and anti-piracy policy. BetterXen strictly opposes piracy and does not distribute copyrighted game files, firmware, decryption keys, or DRM circumvention tooling. Zero proprietary binaries, assets, or leaked materials are permitted in this repository or its Git history. All in-repo tests use independently authored synthetic PE32+ workloads.


Progress Tracker

Tracks engineering milestones and synthetic conformance progress only — not commercial game compatibility percentages.

flowchart LR
    M0["M0: Foundation & Shims\n(Verified Complete)"]:::done
    M1["M1: Boot to D3D12\n(Verified Complete — 16/16)"]:::done
    M2["M2: First Frame &\nShader Gate\n(Active — Milestone #18)"]:::active
    M3["M3: Shaders &\nTexture Tiling"]:::planned
    M4["M4: 3D, DXR/BVH\n& Input"]:::planned
    M5["M5: Audio, Saves\n& Stability"]:::planned
    M6["M6: Cache & 16 GB\nOptimization"]:::planned

    M0 --> M1 --> M2 --> M3 --> M4 --> M5 --> M6

    classDef done fill:#dafbe1,stroke:#1a7f37,color:#0f5323,stroke-width:2px
    classDef active fill:#ddf4ff,stroke:#0969da,color:#0a3069,stroke-width:2px
    classDef planned fill:#f6f8fa,stroke:#8c959f,color:#57606a

Legend: 🟢 Done / Merged · 🔵 Active Milestone · ⚪ Planned

Active Milestone — M2: First Rendered Frame & Shader Format Gate

Track Focus Visual Status Live Issues
Track A system32 shim staging (#457 / PR #458 merged), AMD-only VEH emulation (#451), Track A/F runner integration (#407) 🟩🟨🟨 (#458 merged; #451, #407 active) View Track A
Track B XCRDAPI.dll DirectStorage GPU-buffer & batch transfers (#467) ⬜ (1 ready) View Track B
Track C d3d12_xs D3D12ConfigureVirtualMemoryX + placed resources (#464), PresentX swapchain bridge (#465), D3D workload fixes (#450) ⬜⬜⬜ (3 ready) View Track C
Track D dxbc-accc Windows guest bridge (#445), M2 Shader Format Gate ADR & PSO hook (#466) ⬜⬜ (2 ready) View Track D
Track E Public GDK COM QueryApiImpl dispatch (#456 / PR #462 merged), offline XGameSave + XPackage COM dispatch (#468) 🟩⬜ (#462 merged, 1 ready) View Track E
Track F D3DMetal GPU limits fixture (#453 / PR #455), M2 first-frame + shader-gate exit fixture (#469) 🟨⬜ (PR #455 approved, 1 ready) View Track F

🟩 Merged & verified · 🟨 PR open / in review · ⬜ Open & ready to claim

Milestone Roadmap (M0 → M6)

Milestone Scope Status
M0 — Repo, ABI & Cross-Build 6-track layout, frozen abi/, ARM64 bx-cli, 16 cross-compiled PE32+ shims, live CrossOver + Rosetta 2 smoke tests (test_veh_clwb, test_shim_exports) 🟢 Verified complete (#406)
M1 — Boot to D3D12XboxCreateDevice Full startup shim coverage (xmem physical/scatter pages, XCRDAPI async file reads, d3d12_xs auto-logging COM proxy, offline xgameruntime + dynamic loader exports, audio queue stubs, supervised bx-cli run, ADR 0007, test_integration_boot 19 pass / 2 pending / 0 fail) 🟢 Verified complete (Milestone #17)
M2 — First Frame & Shader Gate Reversible system32 staging, public GDK COM QueryApiImpl dispatch, PresentX → IDXGISwapChain3::Present via D3DMetal 3.0, dxbc-accc Windows bridge, D3DMetal GPU limits, and Shader Format Gate ADR 🔵 Active (Milestone #18)
M3 — Shaders, Streaming & Textures DirectStorage decompression, RDNA 2 xg_xs texture deswizzling, full shader pipeline ⚪ Planned
M4 — 3D Rendering, DXR/BVH & Input BVH4 rehydration → live D3DMetal 3.0 DXR rebuild, PC FidelityFX/MetalFX upscaling shim, full GameInput ⚪ Planned
M5 — Audio, Saves & Stability Software audio/DSP decoding (AcpHal/xapu/chad), PersistentLocalStorage, multi-hour soak stability ⚪ Planned
M6 — Cache, 16 GB Tuning & Polish Persistent PSO/shader disk cache, Lockhart 16 GB unified memory optimization, Metal System Trace tuning ⚪ Planned

See docs/architecture/parallel-tracks.md and docs/roadmap.md for full details.


Architecture

Rosetta 2 executes x86-64 CPU code (including AVX/AVX2/FMA/F16C/BMI1/BMI2/128-bit VAES when launched with ROSETTA_ADVERTISE_AVX=1), CrossOver/Wine provides Win32/NT/CRT/XAudio2/WinHTTP, and D3DMetal 3.0 translates Direct3D 12 + DXR onto Metal. BetterXen supplies the modular Xbox Game OS shims, clwb exception handling, shader bridge, and ARM64 orchestration around that stack.

flowchart TD
    Guest["Scarlett x86-64 PE32+ Executable"]

    subgraph Shims["BetterXen x86-64 Wine Shims (Cross-Compiled on macOS)"]
        VEH["bx_runtime_veh.dll (clwb VEH trap, JSONL trace, Lockhart cap)"]
        XMem["xmem.dll (Physical/Virtual/Scatter Allocator)"]
        DS["XCRDAPI.dll (DirectStorage Async I/O)"]
        D3DX["d3d12_xs.dll + xg_xs.dll (Xbox D3D12 COM Proxy & RDNA2 Tiling)"]
        XGR["xgameruntime.dll + GameInput.dll + Audio/DSP"]
        Bridge["PSM AppNotify & ntuser Win32 Forwarders"]
    end

    subgraph Shaders["Shader & DXR Bridge"]
        DXIL["DXIL Fast Path (SM 6.5/6.6)"]
        ACCC["ACCC / FSPX RDNA2 Transpiler"]
    end

    subgraph External["External Foundation (User-Installed)"]
        Wine["CrossOver 26.3 / Wine (Win32, CRT, XAudio2, WinHTTP)"]
        Rosetta["Rosetta 2 (ROSETTA_ADVERTISE_AVX=1)"]
        D3DM["D3DMetal 3.0 (D3D12 + DXR on Apple Silicon Metal)"]
    end

    CLI["bx-cli (Native ARM64 macOS Launcher, Probe & Telemetry)"]

    Guest --> Shims
    D3DX --> DXIL --> D3DM
    D3DX --> ACCC --> D3DM
    XMem --> Wine
    DS --> Wine
    XGR --> Wine
    Bridge --> Wine
    VEH --> Rosetta
    Wine --> Rosetta
    CLI -.->|"Launches, sets overrides, summarizes traces"| External

Repository Layout

The repository is organized into disjoint track directories around a single frozen abi/ contract so 5–8+ contributors (and coding agents) can work concurrently with minimal merge conflicts.

Directory Track Stack Contents
abi/ Shared (frozen) C headers + .def Versioned cross-DLL headers (bx_config.h, bx_log.h, bx_xmem_internal.h, bx_shader_bridge.h) and canonical export tables for all 16 shim DLLs
launcher/ Track A Rust (arm64) bx-cli (doctor, probe, shader, trace, run), bx-probe (PE32+ import classifier), bx-telemetry (JSONL trace aggregator)
shims/runtime_veh/ Track A C++20 (x86_64 PE) bx_runtime_veh.dll: clwb VEH trap, adcx/adox tripwire, Lockhart/Anaconda memory profile config, structured JSONL logging
shims/win32_bridge/ Track A C++20 (x86_64 PE) api-ms-win-core-psm-appnotify-l1-1-0/1.dll stubs and ext-ms-win-rtcore-ntuser-* → user32.dll forwarders; CrossOver answers these API-set names itself for static imports, so the files are not loaded that way (ADR 0007)
shims/xmem/, shims/xcrdapi/ Track B C++20 (x86_64 PE) xmem.dll (13 Xbox memory APIs + internal region stats) and XCRDAPI.dll (DStorageGetFactory async I/O)
shims/d3d12_xs/, shims/xg_xs/, shims/ffx_bvh_hooks/ Track C C++20 (x86_64 PE) Xbox D3D12 COM proxy over D3DMetal 3.0, RDNA 2 texture tiling (XG), and future FidelityFX/BVH4 hooks
shader-transpiler/ Track D Rust (arm64) dxbc-accc (DXBC/DXIL/ACCC/FSPX classifier), future RDNA 2 transpiler & d3dmetal-native isolation harness
shims/xgameruntime/, shims/gameinput/, shims/audio/ Track E C++20 (x86_64 PE) Offline GDK runtime (xgameruntime.dll), GameInput.dll (@1), and AcpHal.dll/xapu.dll/chad.dll
tests/conformance/ Track F C++20 (x86_64 PE) Auto-discovered clean-room synthetic PE32+ test binaries (test_*/CMakeLists.txt)

Quick Start

Requirements

  • Apple Silicon Mac running native ARM64 macOS with Rosetta 2 and CrossOver 26.3+ (external install).
  • Rust toolchain (aarch64-apple-darwin, Rust 1.85+ / 1.100.0).
  • mingw-w64 & cmake (brew install mingw-w64 cmake) for cross-compiling x86-64 Windows PE32+ shims on macOS.
  • Python 3.11+ for export verification and repository hygiene checks.

Build & Verify

git clone https://github.com/MacosPorters/betterxen.git
cd betterxen

# 1. Build & test the native ARM64 Rust workspace (launcher + shader-transpiler)
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
cargo build -p bx-cli

# 2. Check host Apple Silicon, Rosetta 2, CrossOver, D3DMetal, and mingw-w64 readiness
target/debug/bx-cli doctor

# 3. Cross-compile all 16 x86-64 PE32+ shim DLLs + conformance binaries
#    (automatically verifies every abi/defs/*.def export and zero MinGW runtime DLL deps)
scripts/build-shims.sh

# 4. Run live synthetic PE32+ conformance tests inside CrossOver + Rosetta 2
target/debug/bx-cli run --prefix /tmp/bx-test --shims build-shims/bin --log /tmp/bx-test.jsonl --exe build-shims/bin/test_veh_clwb.exe
target/debug/bx-cli run --prefix /tmp/bx-test --shims build-shims/bin --log /tmp/bx-test.jsonl --exe build-shims/bin/test_shim_exports.exe
target/debug/bx-cli trace /tmp/bx-test.jsonl

# 5. Check Markdown links & repository hygiene
python3 scripts/audit/docs_hygiene.py

bx-cli Commands

Command Purpose
bx-cli doctor Inspects Apple Silicon host, RAM (recommends lockhart on 16 GB Macs or anaconda on 32 GB+), Rosetta 2, CrossOver, D3DMetal, and mingw-w64
bx-cli probe <pe32+> Static PE32+ import scanner that classifies every imported DLL into Tracks A–E or Wine built-ins
bx-cli shader <blob> Classifies a DXBC shader container (DXIL vs. legacy SHDR/SHEX vs. ACCC/FSPX)
bx-cli run --exe <path> ... Launches a PE32+ binary under CrossOver/Wine with env_clear() host isolation (--inherit-env opt-in), ROSETTA_ADVERTISE_AVX=1, WINEDLLOVERRIDES, BX_PROFILE, and JSONL trace capture
bx-cli trace <log.jsonl> Aggregates bx_runtime_veh.dll logs (unimplemented API counts, COM vtable misses, clwb VEH traps, ADX tripwires)

Contributing with Humans & Coding Agents

BetterXen is built for parallel work across 5–8+ contributors and coding agents (AGENTS.md — symlinked as CLAUDE.md — holds the full ruleset):

  1. Pick a track & claim an issue from docs/issues/wave-1-backlog.md (or GitHub Issues using .github/ISSUE_TEMPLATE/track-handoff.yml). Reply Claiming — branch: track-<a..f>/<issue>-<slug> before coding.
  2. Isolate your branch or worktree: git worktree add ../wt-<issue> -b track-<a..f>/<issue>-<slug> origin/main.
  3. Stay inside your issue's exclusive file scope: Never edit another track's directory inside a feature PR. Need a new cross-DLL helper? Open a small [ABI] PR touching only abi/ first.
  4. Add a conflict-free conformance test: Drop tests/conformance/test_<name>/CMakeLists.txt + main.cpp — CMake auto-discovers test_* directories with zero edits to shared files.
  5. Run the verification commands above, update CHANGELOG.md under [Unreleased], sign off commits (DCO Signed-off-by), and open a PR with Closes #<issue>.

See AGENTS.md, CONTRIBUTING.md, docs/architecture/parallel-tracks.md, and docs/README.md.


Current Verified Scope & Limitations

  • Verified (local Apple M5, macOS 27.2.1, CrossOver 26.3, Rosetta 2):
    • Native ARM64 bx-cli, bx-probe, bx-telemetry, and dxbc-accc unit tests.
    • All 16 x86-64 PE32+ shim DLLs cross-compile with zero warnings, pass strict PE Export Directory verification (102 exact names, ordinals, forwarders, 0 extra exports), and carry zero dynamic MinGW runtime dependencies.
    • test_veh_clwb.exe executes AVX2+FMA, traps and skips clwb via bx_runtime_veh.dll, and exercises starter XMemAlloc/XMemTransferMemory under CrossOver/Wine.
    • test_shim_exports.exe loads all 16 shim DLLs and resolves 25 runtime exports via LoadLibraryA / GetProcAddress inside CrossOver/Wine.
  • Not yet implemented (M1–M6):
    • d3d12_xs.dll COM device/command-list/PSO proxy and PresentX swapchain presentation.
    • xmem.dll physical/scatter page mapping and XCRDAPI.dll async DirectStorage queues.
    • xg_xs.dll RDNA 2 texture tiling/deswizzling and DXR/BVH4 rehydration interception.
    • Console ACCC/FSPX RDNA 2 → DXIL/MSL shader transpilation (gated on M2).
    • Real software audio/DSP decoding behind AcpHal/xapu/chad and full GameInput polling.
    • Commercial Xbox game execution.

Historical Native-First Research

The earlier paused native-first implementation (independent x86-64 interpreter/ARM64 DBT, bounded gfx1030 RDNA 2 → MSL translator, native Metal backend, and Swift app) was retired from main per ADR 0006 and remains preserved permanently in Git history at tag native-first-final.


License

BetterXen is licensed under the GNU General Public License v3 or later. See THIRD_PARTY_NOTICES.md and docs/legal.md for attribution and legal scope.

BetterXen is an independent open-source project and is not affiliated with Microsoft, Xbox, Apple, CodeWeavers, or any game publisher.

Languages
C++ 57%
Rust 22.2%
C 16.6%
Shell 1.6%
Python 1.2%
Other 1.4%