Skip to content

D3D12.X: a list vtable at a reused heap address gets its own methods - #2593

Open
SergeAx wants to merge 1 commit into
xcl-dev:mainfrom
SergeAx:d3d12x-heap-vtable-classes
Open

SergeAx wants to merge 1 commit into
xcl-dev:mainfrom
SergeAx:d3d12x-heap-vtable-classes

Conversation

@SergeAx

@SergeAx SergeAx commented Nov 26, 2026 •

Copy link
Copy Markdown

Fixes #2588.

With the Agility SDK 1.620, an open command list's vtable is in heap memory and goes with the list. real::class_for cached the extended vtable by the runtime vtable's address and copied the runtime's methods only once, so a direct list whose open vtable came where a released compute list's had been called the compute list's methods: its ClearDepthStencilView made Close fail with E_FAIL. That is the parallel-only failure of vram::tests::d32s8_targets_take_their_own_size_of_video_memory (#42).

What is in it

  • crates/xcl/src/hle/d3d12x/real.rs: a Class of a vtable outside any module keeps the methods it copied (copied), and class_for takes it only while they are still the ones at that address. Vtables in a module's image are looked up as before.
  • crates/xcl/src/hle/d3d12x/real.rs (class_tests): a_direct_list_at_a_released_compute_lists_vtable_records_with_its_own_methods.

Tested

  • NVIDIA GeForce RTX 5080, driver 621.14; AMD Ryzen 5 3500X; Windows 10 Pro 22H2 (19045.6466), D3D12 Agility SDK 1.620.2; Rust 1.100.0, debug
  • cargo test --workspace --no-fail-fast -- --test-threads=4 at 52c0802f: 1426 passed, 4 failed, 47 ignored. The 4 are DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905 (fuzz_validate_and_gpu_0.._3, seeds 70, 545, 1019 and 1507), as on main 6d12f58 (GPU test results: NVIDIA RTX 3080 (wave32) and AMD RDNA2 iGPU (no mesh shaders) #42).
  • SKIPPED (25): 21 × no wave64; 3 × wave32 per-lane form refused (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32); heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows
  • The new test fails in 5 runs out of 5 with the lookup ignoring copied, and passes in 5 out of 5 with this change.
  • The lib tests run as --test-threads=4 hle::d3d12x hle::xgameruntime: the D32S8 test failed in 2–5 runs out of 10 on 6d12f58, and in 0 out of 12 with this change.

Regression run

main:

xcl-smoke v1
commit: 08db8020d323bf478964fcc586152cce54959cfc
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1332 (PresentX 1332)
presents per 2 s (last 3): 30 50 20
device removals: 0
crashes: 0
peak commit: 18965 MB

this PR:

xcl-smoke v1
commit: 52c0802fb8f13c4efef3b82a14bc34fd338ae7a6
gpu: NVIDIA GeForce RTX 5080
title: 3c290c16
seconds: 60
exit: 0x0
frames shown: 1307 (PresentX 1307)
presents per 2 s (last 3): 44 41 10
device removals: 0
crashes: 0
peak commit: 19621 MB

Not tested

  • AMD and Intel GPUs, Windows 11, and the inbox D3D12 runtime without the Agility SDK (its vtables are in D3D12Core.dll, which this change looks up as before)
  • On AMD the new test does not reach the fix: on an RX 9070 XT (Windows 11) it was SKIPPED in 3 runs out of 3, as no direct list got a released compute list's vtable address in its 200 tries (report in the comments). On the RTX 5080 here it reaches it (above)
  • Whether it also covers the other parallel-only failures reported in GPU test results: NVIDIA RTX 3080 (wave32) and AMD RDNA2 iGPU (no mesh shaders) #42 (list_x::tests::a_reset_while_the_last_submit_runs_records_on_another_pc_list)

AI use

  • Claude Code (Claude Opus 5.5) found the cause, wrote the change and the test, ran the tests and measurements, and wrote this description.

Agility SDK 1.620 keeps an open command list's vtable in heap memory
that is freed with the list. class_for cached the extended vtable by
the runtime vtable's address and copied the runtime's methods only the
first time, so a direct list whose open vtable came where a released
compute list's had been called the compute list's methods: its
ClearDepthStencilView made Close fail with E_FAIL. That is how vram's
D32S8 test failed in parallel runs (2-5 in 10 with hle::d3d12x and one
more module on 4 threads, RTX 5080; 0 in 12 with this change).

A class of a vtable outside any module now keeps the methods it copied
and is taken only while they are still the ones there.

Fixes xcl-dev#2588
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.

Thanks!

— Devin

@DarkPanda69

Copy link
Copy Markdown

AMD run (listed as untested), on Windows 11 too: on an RX 9070 XT the new test skips. The reuse it waits for did not happen in 3 runs, so on this machine it passes without exercising the fix.

Head 52c0802 applied on main b49be18, debug, Windows 11 Pro 26200, RX 9070 XT (RDNA4, driver 32.0.32029.2010). The test takes the default adapter (create_device(None, ..)), which is the RX 9070 XT on this machine.

cargo test -p xcl --lib -- a_direct_list_at_a_released_compute_lists_vtable --nocapture, 3 times, each:

SKIPPED hle::d3d12x::real::class_tests::a_direct_list_at_a_released_compute_lists_vtable_records_with_its_own_methods: 
no direct list got a released compute list's vtable
test ... ok

So in the test's 200 tries, no direct list landed on a released compute list's vtable address here. Your report's SKIPPED list doesn't include this test, so it did run on the RTX 5080. Whether the address reuse is rarer here because of the GPU driver, Windows 11 or the heap was not looked into. This run also says nothing about whether the fix is right on AMD; it only shows the test does not reach it on this machine.

Not tested: the machine's RTX 3060 (the test always uses the default adapter), Intel, a title.
AI use: Claude Code (Claude Opus 5.5) ran the test on this machine and wrote this report.

@mokkamokacaffe

Copy link
Copy Markdown

I found an additional cache-boundary case in the current implementation.

same_methods walks the historical copied.len() before deriving the replacement vtable’s current interface and scanned length. A shorter replacement can therefore be read using the older length, while a longer table sharing the old prefix can reuse stale internal method handling.

I prepared a focused follow-up at ea5a19a. It derives the live table shape first, compares the complete snapshot and metadata, preserves the image-backed fast path, and adds CPU-only coverage for:

  • Shorter replacement tables
  • Longer replacement tables
  • Changes in internal slots
  • A → B → A historical-generation reuse

Tested

  • Windows no-GPU CI on the combined tree: 1430 passed, 0 failed, 47 ignored
  • heap_classes_match_only_the_same_shape_and_methods: passed
  • git diff --check: passed

Not tested

  • The Agility SDK 1.620 heap-reuse regression skipped because the CI runner did not expose a changed heap vtable.
  • Exact-head GPU workspace tests
  • AMD, NVIDIA, or Intel hardware
  • Paired retail-title xcl-smoke runs

Exact-head GPU and smoke runs remain required after this change is folded into #2593.

AI use

  • OpenAI Codex with GPT-5.6 Sol reviewed the change, implemented the follow-up, and ran the source and Windows CI checks.

@SlopTart

Copy link
Copy Markdown

Tested: current PR head merged onto current origin/main (clean), Linux (Arch, kernel 7.2.15), Mesa 26.2.5 RADV, Radeon RX 7900 XT (NAVI31), cargo target x86_64-pc-windows-gnu run under wine-11.0 (Proton), rustc 1.94.0, vkd3d-proton 3.1 with the XCL patch, official MS DXC (binaries 2026-09-29).

gpu_ suite (cold cache): 165 passed / 3 failed, no crashes. The three are the known baseline on this lane (seed-1003 fuzz, mad/mac contraction, promoted-UAV-clear driver gap, PR #2490); none caused by this PR.
Targeted run of a_direct_list_at_a_released_compute_lists_vtable_records_with_its_own_methods: passed.

Not tested: retail titles (no title data on this lane, counts only).

AI use: Hermes agent (local Qwen-class) ran both machines and drafted this; I checked it before posting.

@SergeAx

SergeAx commented Nov 26, 2026

Copy link
Copy Markdown
Author

@mokkamokacaffe thanks for looking. I read class_for at 52c0802 and ea5a19a, and I don't think the extra check is needed:

  • A shorter replacement. same_methods reads copied.len() words at orig: the old class's scanned, the same words its own scan read at that address. A class is reused only when all of those words equal its snapshot; a fresh scan would then find the same words in the same module and stop no earlier, so the table cannot come out shorter.
  • A longer replacement. A fresh scan comes out longer only if the word at scanned, where the old scan stopped, now points into the same module. With the first scanned words identical, it is the same runtime class, whose table length is fixed: a word after it is heap memory past the vtable, not a method. The runtime calls only its own methods, all among the compared words, and for the title such a slot answers the same either way: the guard of an internal slot answers a title call as the stub does (logged, 0), and console_slots / console_remap give it the same handler in both cases.
  • A → B → A. Every class stays in CLASSES and the lookup matches by methods, so A's class is found again when A's table comes back.

ea5a19a runs the QI probe and the scan on every adopt of an object with a heap vtable before matching (every command list on Agility 1.620), where this PR compares scanned words. Its new test covers the new matching_class helper; it does not show a case where this PR's lookup returns the wrong class. So I'm keeping #2593 as it is.

AI use: Claude Code (Claude Opus 5.5) read both commits and wrote this reply.

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

NVIDIA test report for 52c0802: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug.

  • a_direct_list_at_a_released_compute_lists_vtable_records_with_its_own_methods, --exact --test-threads=1 --nocapture, 5 runs: 5 passed; the reuse happened (no SKIPPED line) in 0 of 5, so it skipped as on the RX 9070 XT. The cause here is the D3D12 runtime, not the driver: with no Agility SDK found, create_device used the inbox D3D12Core.dll 10.0.26100.9549, whose command list vtables are in the DLL image (PC vtable D3D12Core.dll+0x30ed90 / +0x30e830). Compute and direct lists then have different static vtables, and copied is never set.
  • The same command with XCL_D3D12_DIR set to the Agility SDK 1.620.2 (NuGet Microsoft.Direct3D.D3D12 1.620.2), 5 runs: 5 passed; the list vtables were heap addresses, and the reuse happened (no SKIPPED line) in 4 of 5, so the fix is exercised on this driver. With the lookup changed to ignore copied (local edit, Agility 1.620.2), it failed 5 of 5: ClearDepthStencilView of a direct list at a compute list's vtable 0x... failed its Close.
  • hle::d3d12x::real:: at default threads, inbox runtime, 3 runs: 60 passed, 0 failed each time; the new test SKIPPED in all 3.
  • cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4 (the hle::xaudio2 tests hang on this machine, on main too), inbox runtime: 1296 passed, 0 failed, 27 ignored; 26 SKIPPED lines (21 × no wave64; 3 × wave32 per-lane form refused: V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32; pso_measurement_compiles_an_exact_synthetic_record: driver cache needs Developer Mode; and the new test).
    The RX 9070 XT report doesn't say which D3D12 runtime it loaded; if it was the inbox one, its skip has the same cause, and a run with XCL_D3D12_DIR would show whether AMD reuses the address.
    Lib tests only; no title run.
    AI-assisted (Claude Code, Claude Opus 5.5).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

D3D12.X: a direct list at a released compute list's heap vtable address gets the compute list's methods

6 participants