Skip to content

D3D12.X: allocator #9 takes the title's command-memory callback - #1109

Open
wilu222 wants to merge 1 commit into
xcl-dev:mainfrom
wilu222:d3d12x-allocator-memory-callback
Open

wilu222 wants to merge 1 commit into
xcl-dev:mainfrom
wilu222:d3d12x-allocator-memory-callback

Conversation

@wilu222

@wilu222 wilu222 commented Nov 24, 2026 •

Copy link
Copy Markdown

ID3D12CommandAllocator #9 registers the title's command-memory callback. XCL answers it with S_OK and does not call the callback, instead of the generic "not on PC" stub. This is the one-slot PR with evidence asked for when #228 was closed. Part of #1067, which lists #9 (~14 000 calls) among its unimplemented functions.

Evidence (retail 1.0.2.1, game_scarlett_master.exe at 0x140000000)

  • Call site title+0x1884fe: after taking an allocator from its pool (a lock cmpxchg loop), the title calls [vtbl+0x48] with rdx = title+0x555df10 and r8 = a pointer into one of its objects. It does not read the return value (rax is overwritten next).
  • title+0x555df10 is code, not a GUID: callback(…, a4, a5, a6, a7). It allocates a4 bytes with alignment a5 (a byte count if ≥ 16, otherwise log2) from the title's own allocator for the context a7. It stores the block as the context's current one, releases the previous one, and returns it. a1–a3 and a6 are unused. So the console runtime asks the title for command memory through this callback.
  • A traced run (temporary logging at slot 9, not in this PR; 90 s, RTX 5070) saw over 1024 calls on 68 allocators. Every call had the same callback (title+0x555df10) and the same context. The third and fourth argument registers held leftovers, so the method takes two arguments.
  • A PC allocator gets its memory from the driver, so nothing on XCL's side would ever ask the title for memory: the callback is not stored or called. The registration is still visible in the log, once, with the callback and context.

What is in it

  • D3D12.X: allocator #9 takes the title's command-memory callback: alloc_memory_callback_x at console slot 9 of command allocators (crates/xcl/src/hle/d3d12x/real.rs) and on the null device (crates/xcl/src/hle/d3d12x/null.rs), with a unit test in each. Both tests fail without the slot entries.

Tested

  • NVIDIA GeForce RTX 5070 (driver 32.0.16.1742), AMD Ryzen 7 5700X, 32 GB, Windows 10 Home 19045, Rust 1.100.0; tests in debug, smoke runs in release
  • Rebased onto main 6567c5f (conflict only in null.rs's test module, where main added a test next to ours; both kept).
  • cargo test --workspace --no-fail-fast -- --test-threads=4 on head 590d470: 995 passed, 4 failed, 45 ignored. The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0–_3: CreateComputePipelineState returns E_OUTOFMEMORY (0x8007000E) for seeds 70, 545, 1019 and 1507 on this adapter. They fail the same way, at the same seeds, on main 6567c5f (cargo test -p xcl --lib fuzz_validate_and_gpu: 0 passed, 4 failed), and they do not reach the code this PR changes.
  • An earlier full run on the same head had 10 failures: the 4 above, and then a device removal (0x887A0005) took 6 more GPU tests with it (list_x, title_textures, vram::d32s8_targets…). The rerun above had none of those 6.
  • SKIPPED lines: 19 "no wave64"; 3 f16/f32 per-lane forms refused ("gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ"); heap_window_out_of_memory_falls_back_to_the_switch_form ("no heap windows"); pso_measurement_compiles_an_exact_synthetic_record ("cannot disable the driver cache (Windows Developer Mode is required)").
  • cargo test -p xcl --lib allocator_9: 2 passed; with the two slot entries removed, both fail.
  • Retail 1.0.2.1: the PR's smoke run below logs D3D12.X: allocator #9 – the title registers a command-memory callback (0x14555df10, …) once, and no ID3D12CommandAllocator::#9 stub.

Regression run

main:

xcl-smoke v1
commit: 6567c5ffa38fbc7039b2d6bf520154689cc1f482
gpu: NVIDIA GeForce RTX 5070
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 2631 (PresentX 2631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15986 MB

PR:

xcl-smoke v1
commit: 590d470c7ae2f0f680b4bf05251ec9732ecb3a09
gpu: NVIDIA GeForce RTX 5070
title: 9cc6a39e
seconds: 120
exit: 0x0
frames shown: 2728 (PresentX 2728)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15361 MB

Not tested

  • AMD and Intel GPUs; Linux / Wine.
  • World loading and gameplay: the runs had no input and stayed at the intro and menus, so they do not show whether the rest of #1067 (the world-load crash) changes. This PR does not claim to fix it.
  • The field the callback writes (context+0x12798) is used only by the callback at that offset. The same memory is also reachable at offset 0x18 of a larger title object, and I did not check every access there. With the callback never called (as before this PR), the title ran normally in the runs above.
  • Other titles' use of allocator Olympus: harden DXIL cache identity and validation #9.

HANDOFF.md (near line 1754) lists allocator #9 among the stubs. After this PR it is answered, so that line is out of date.

AI use

  • Claude Code with Claude Opus 5.5: disassembled the call site and the callback, added and then removed the temporary trace, wrote the code, the tests, the commit message and this description, and ran the tests and smoke runs listed above.

@thehollowedone

Copy link
Copy Markdown

Independent live allocator check on 47efa2e and 5c88525. Windows 11 build 26300, RTX 3080 Ti / 621.35, Ryzen 7 9800X3D, Rust 1.99.1 MSVC, release.

The bundled synthetic title called slot 9 on the actual allocator's vtable twice before recording its stock triangle, then once after GPU fence completion and an allocator reset. All calls returned S_OK and the sentinel callback count stayed zero on both builds. Main logged the generic allocator slot 9 stub. The PR logged the named callback registration and no slot 9 stub. Both passed the stock triangle pixel and occlusion readbacks and exited with zero title failures.

I built with cargo build --offline --locked --release --workspace and ran xcl run <test-title> -- --hello with XCL_D3D12_DEBUG=1. The full test title logged the same debug-layer errors on both builds (93 ×3, 1046 ×1, 538 ×1). Synthetic title only. Retail and gameplay were outside the check.

AI-assisted. Codex (GPT-6, exact variant unavailable) wrote and ran the scratch check and drafted this report.

@celian-hamon

Copy link
Copy Markdown

lgtm

@futurepro62

futurepro62 commented Nov 24, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 5c88525 (on its base 47efa2e).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4: 743 passed, 0 failed, 41 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: allocator_9_is_the_memory_callback_slot, allocator_9_accepts_the_callback_without_calling_it.
  • Same head on the AMD Radeon iGPU of the 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 743 passed, 0 failed, 41 ignored, no skips.
  • My first Radeon run of this head had 3 list_x failures (E_OUTOFMEMORY, then a suspended device) while other GPU jobs ran on the machine; the rerun above is clean, and those 3 tests pass 3 of 3 runs on their own on both this head and main 930e8b4.

Not tested

  • A release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@Royalflamejlh

Copy link
Copy Markdown
Contributor

Linux (Wine + vkd3d-proton) + NVIDIA test of 5c88525 on main 930e8b4 + #684, 2 runs of 140 s each way of a retail title: the 2,328 and 2,323 stub calls to ID3D12CommandAllocator::#9 were gone with it, the registration was logged once, and the runs were otherwise the same.

Setup: Fedora 44 (kernel 7.2.9), Wine 11.21 Staging (Wayland driver), vkd3d-proton v3.1-90-g30b0eb9b with the relaxed-vtable patch from #175 and a local dxil-spirv patch, VKD3D_CONFIG=ignore_shared_fence. RTX 4070 12 GB (driver 615.71.09, 32-lane waves), Ryzen 9 9950X3D, 64 GB RAM. Release, cross-compiled to x86_64-pc-windows-gnu (rustc 1.98.0), DXC 1.9.2609.5, XCL_NETWORK=0, XCL_PSO_PRELOAD=0. Retail title 1.0.2.1, the first-run screens completed once and no story progress, one A press at 44.8 s through XCL_PRESS_AT. 5c88525 merged onto main 930e8b4 + #684 (e56dbc3) without conflicts; #684 is there because main alone faults in copy_from before this point.

Tested

  • cargo test --release -p xcl --lib allocator_9 under Wine, on the merge: 2 passed, 0 failed.
930e8b4 + #684, run 1 / 2 the same + 5c88525, run 1 / 2
stub calls to ID3D12CommandAllocator::#9 2328 / 2323 0 / 0
stub calls to the other seven d3d12_xs.dll slots 7214 / 7179 6933 / 7120
frames presented 2163 / 2152 2075 / 2136
last 2 s with a present 102.6 s / 102.2 s 100.2 s / 101.0 s
the title's null write at game+0x23cf683 132.6 s / 131.6 s 128.5 s / 129.5 s

Both runs with it logged this once, at 3.5 s:

D3D12.X: allocator #9 – the title registers a command-memory callback (0xe4adf10, context 0xb041e47c0)

The image is loaded at 0x8f50000 here, so that callback is game+0x555df10, the function the description names.

The presents stop and the watchdog fires 2 to 3 s earlier in the runs with it. Runs of the same tree differ by that much here (a run of 930e8b4 + #684 + #1288 stopped presenting at 100.4 s), so I read it as run-to-run difference, not as an effect of this change.

Read

  • real.rs:1040 (alloc_memory_callback_x) does what the description says: it logs the first call, keeps nothing and answers S_OK. real.rs:955 puts it on slot 9 and null.rs:155 gives the null device the same handler.
  • d3d12x: implement console command allocator, queue, and command list slots #1274 takes the same slot (alloc_set_allocation_callback_x) and keeps each allocator's callback in a map that nothing reads. The two merge together without a textual conflict, but only one handler is needed; this is the smaller one.

Not tested: past 140 s; the preload of #690 on; the rest of the test suite; AMD and Intel.

AI use: Claude Code (Claude Fable 5.2) read the diff, built the trees, ran the tests and the four runs with XCL_PRESS_AT, compared the logs and wrote this report.

The retail title calls ID3D12CommandAllocator xcl-dev#9 each time it takes an
allocator from its pool (title+0x188501), with two arguments: a callback
in its own code (title+0x555df10) and a context pointer. The return value
is not read. The callback takes a size (4th argument), an alignment (5th)
and the context (7th), and returns a block of the title's memory: the
console runtime asks the title for command memory through it.

A traced run (90 s, RTX 5070) saw over 1024 calls on 68 allocators, all
with the same callback and context. A PC allocator gets its memory from
the driver, so XCL never calls the callback: xcl-dev#9 answers S_OK and logs the
first registration, on real and null devices, instead of the generic
"not on PC" stub.

Assisted-by: Claude Code (Claude Opus 5.5)
@wilu222
wilu222 force-pushed the d3d12x-allocator-memory-callback branch from 5c88525 to 590d470 Compare November 25, 2026 00:44
@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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.

6 participants