Skip to content

D3D12.X: preserve native host vtable prefixes and tails - #1904

Draft
mikebuckets171 wants to merge 1 commit into
xcl-dev:mainfrom
mikebuckets171:pr/d3dmetal-native-vtable-prefix
Draft

mikebuckets171 wants to merge 1 commit into
xcl-dev:mainfrom
mikebuckets171:pr/d3dmetal-native-vtable-prefix

Conversation

@mikebuckets171

Copy link
Copy Markdown

Part of #258. This upstreams Ahmet Dedeler's focused D3DMetal host-vtable fix from ddf3be7, preserving its author and existing Claude Mythos 5.2 co-author trailer. D3DMetal is native code under Wine rather than a PE module: the existing extended vtable layout puts XCL metadata where D3DMetal expects its C++ ABI prefix and does not preserve enough host tail slots. The change mirrors the host prefix and tail only when the original methods are outside PE modules; PE-backed Windows host tables keep their existing layout.

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: preserve the native host vtable prefix/tail and map extended tables back to their original table; add a focused regression test for native and PE-backed table layouts.

Tested

  • MacBook Pro M5 Pro (20-core GPU), 48 GB; macOS 27.2.1 (26B131); CrossOver 26.3.0.39832, D3DMetal 3.0, Rosetta 2; Rust/Cargo 1.100.0; LLVM-MinGW 20261117 / clang 23.1.6.
  • cargo build --workspace --locked --release --target x86_64-pc-windows-gnullvm — passed on this head.
  • cargo test -p xcl --lib --release --target x86_64-pc-windows-gnullvm hle::d3d12x::real::native_host_table_tests::a_native_hosts_table_keeps_its_prefix_and_other_tables_keep_theirs -- --exact --nocapture — 1 passed, 0 failed, 951 filtered out, under CrossOver.
  • Same retail title, same Mac host and 60-second limit, offline CrossOver bottle, separate fresh data roots:
    • main 689f2db477c3c062cf162649781640ef8a977c18:
xcl-smoke v1
commit: 689f2db477c3c062cf162649781640ef8a977c18
gpu: AMD Compatibility Mode
title: retail (Xbox Series X|S package, private drive)
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB
  • PR 50768d87beca1773980745db1fbc68cf69446b92:
xcl-smoke v1
commit: 50768d87beca1773980745db1fbc68cf69446b92
gpu: AMD Compatibility Mode
title: retail (Xbox Series X|S package, private drive)
seconds: 60
exit: 0x0
frames shown: 0 (PresentX 0)
presents per 2 s (last 3): 0 0 0
device removals: 0
crashes: 0
peak commit: 0 MB
  • The two title runs are 0-frame against 0-frame on plain upstream main; this is a bounded no-regression check only, not evidence the title reaches the changed vtable path. Wine reports peak commit as 0 MB, so memory is unmeasured.

Not tested

AI use

  • OpenChamber with GPT-6 Luna rebased Ahmet's existing commit, ran the named Mac checks and prepared this description. The source commit retains Ahmet Dedeler as author and its existing Claude Mythos 5.2 co-author disclosure.

XCL gives every D3D12 object a vtable of its own: the original table's address, then the
host's methods with XCL's in between. That assumes a host whose methods are in a PE module
and which uses a table only through its public slots.

Apple's D3DMetal (the D3D12 of CrossOver and the Game Porting Toolkit on macOS) is native
code in no PE module. It reads the words in front of the table of an object it is handed
(type information, offset-to-top and the virtual-base offsets of the C++ ABI) and calls
virtual methods of its own well past the public ones. In XCL's table the word in front of
slot 0 is the original table's address, not type information, and the table ends 64 slots
after the last word the scan took for a method.

For a table whose first method is in no PE module (`module_of` is 0), `class_for` now
- puts 16 words of the host's table in front of the extended one (`table_header`), where
  the original's address is on other hosts; the original is then found through
  `NATIVE_EXTS` (`orig_table`), a list read without a lock;
- takes every slot up to `total` as the host's and guards it, since the scan for the end
  of the table cannot work there (it stops at the first word that is in a module);
- copies the host's words after `total` behind XCL's slots (up to 512 from the last public
  method), so a call of the host's own does not run off the end.

A table from a PE module is laid out as before, word for word: `table_header` returns the
original's address alone, and `orig_table` reads the word in front of the table when no
native table was made.

Test: a_native_hosts_table_keeps_its_prefix_and_other_tables_keep_theirs.

Part of xcl-dev#258.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
(cherry picked from commit ddf3be7)
anoyarou pushed a commit to anoyarou/xcl that referenced this pull request Nov 24, 2026
…cl-dev#1904)

XCL gives every D3D12 object a vtable of its own: the original table's address, then the
host's methods with XCL's in between. That assumes a host whose methods are in a PE module
and which uses a table only through its public slots.

Apple's D3DMetal (the D3D12 of CrossOver and the Game Porting Toolkit on macOS) is native
code in no PE module. It reads the words in front of the table of an object it is handed
(type information, offset-to-top and the virtual-base offsets of the C++ ABI) and calls
virtual methods of its own well past the public ones. In XCL's table the word in front of
slot 0 is the original table's address, not type information, and the table ends 64 slots
after the last word the scan took for a method.

For a table whose first method is in no PE module (`module_of` is 0), `class_for` now
- puts 16 words of the host's table in front of the extended one (`table_header`), where
  the original's address is on other hosts; the original is then found through
  `NATIVE_EXTS` (`orig_table`), a list read without a lock;
- takes every slot up to `total` as the host's and guards it, since the scan for the end
  of the table cannot work there (it stops at the first word that is in a module);
- copies the host's words after `total` behind XCL's slots (up to 512 from the last public
  method), so a call of the host's own does not run off the end.

A table from a PE module is laid out as before, word for word: `table_header` returns the
original's address alone, and `orig_table` reads the word in front of the table when no
native table was made.

Test: a_native_hosts_table_keeps_its_prefix_and_other_tables_keep_theirs.

Part of xcl-dev#258.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
(cherry picked from commit ddf3be7)
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@bmjask bmjask left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No confirmed source defect, but this D3DMetal ABI prerequisite is not merge-ready. Synthetic layout tests do not validate real native-host adoption/dynamic_cast or tail calls; the Mac smoke reaches zero frames and does not exercise rendering/adoption. Prefix/tail constants need target-path evidence, and IsBadReadPtr establishes mapped readability rather than actual vtable extent. Add a real D3DMetal host tail-call/adoption integration test, a non-zero-frame target run, and required Windows/current CI evidence.

@github-actions

Copy link
Copy Markdown

Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

@github-actions github-actions Bot added the stale No activity for 3 days; closed 4 days later unless something happens label Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 50768d8

No open or merged PR makes the same change. #3099 touches class_for as part of a large amd-dev rebase, but it does not keep the native host's prefix or tail.
One point in real.rs:class_for: on a native host scanned becomes total, and slots 0..total are read with *ot.add(i) without the IsBadReadPtr probe that the prefix (table_header) and the tail get. That read can run past the host table's mapping. Main's list_x.rs test (*(raw as *mut usize) = *ext.sub(1)) still reads the word before the table directly, but only in a test. The branch conflicts with main.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale No activity for 3 days; closed 4 days later unless something happens

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants