d3d12_xs: route command-list slots 131/132 by the caller's GXDK edition #334
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!334
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/334/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@GDAgent on GitHub · 2026-11-23 20:24 UTC · original
GDAgent:fix/d3d12-cmdlist-slots-131-132-edition→main· +441 −1 · 3 files · 2 commits · closed without mergingWhat
Two things in one small change, both needed before a newer-GDK title can record its first command list:
cl_edition.rs: finds out which GXDK edition the calling module was built with. The module's.xbldsection carries_xbld_edition_sdktype=GXDK,<edition>fields; the parser reads them from the module's own header and image (bounded bySizeOfImage, at most 1 MiB), keeps the highest edition and caches the answer per module. The caller is the first stack return address outside the emulator that follows a call instruction (unwinder first, then a raw scan bounded byGetCurrentThreadStackLimits, so a frame without unwind data cannot send the scan past the stack top).FlushTextureCacheX, and skipped on copy lists, where a UAV barrier is illegal). For older editions the slots are routed to whatever handler was registered before this layer. When there is none (the case onmain), the command is ignored and the log says so: no success is faked and nothing is claimed.The shim table grows from 128 to 256 entries, because slots 131/132 are read past the end of it today. That is the same one-line change as #296 (
const N: usize = 128to256), so whichever lands first, the other merges without a conflict. This PR is based onmain, not stacked on #296, and does not touch #296's tests or its IID changes.Why / evidence
A very popular AAA title built with a 2504+ GDK calls list slots 131 and 132 right after list creation. With the old meaning of slot 131 (a batched acceleration-structure build, which only exists on the ray-tracing branch, not on
main) the call is routed to the wrong operation; with the table at 128 it is a call through a null pointer. In native Windows 11 runs (not run under Proton) of that title, routing by edition got it past command-list creation and the first calls to these slots; the slot-131 arguments are logged for the first 16 calls so the exact semantics can be refined from evidence. What the two slots really do on the console is not known from documentation; "synchronisation command" is inferred from the call pattern, and the global UAV barrier is the conservative host equivalent (it can only add ordering).Edition cut-off: titles with GXDK 250402 and 260405 (and 250405) use the new layout; the cut-off constant is
250400, so every edition from 2504 on takes the new meaning. No evidence for editions between 2021 and 2504; they keep the old layout.Tests
cargo test -p d3d12_xs --lib cl_edition(all generic, no console files or title data):GXDK,<6 digits>only,GRDK, wrong lengths and non-digits rejected, duplicates folded;.xbldsection lookup in a synthetic PE header, bounded by the image size, bad magic and truncated headers rejected;.xbldkeeps the old layout;9 passed.
TOMBOX_REMOVED_EXIT_MS=off cargo test -p d3d12_xs --lib -- --test-threads=1on the follow-up device-slot branch, which contains this commit: 677 passed, 4 failed, 71 ignored. The 4 failures also fail onmainon this RDNA2 GPU and are not touched here (alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement,placed_offset::tests::uneven_views_get_exact_helpers_and_msaa_shares_the_alias_heap,title_shadow::tests::buffer_then_texture_migrates_to_one_local_heap_and_keeps_bytes: see #322;xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs: needs a console DLL). Native Windows 11; not run under Proton.Not verified
main; onmainthe command is ignored and logged. It is routed correctly once that implementation is registered in the table before this layer.@GDAgent on GitHub · 2026-11-23 23:06 UTC · original
Thanks, confirmed and fixed in
bb26712.FF 14at the end of the window givessib == 1fork == 2, and the guard readcode[8]. I added your skip right aftersibis computed (continue, so the longer candidates are still examined) and both regressions toreturn_addresses_must_follow_a_call. Without the fix the new negative case panics withindex out of bounds: the len is 8 but the index is 8; with it all ninecl_editiontests pass (Windows 11, RDNA2 host,cargo test -p d3d12_xs --lib cl_edition).Agreed on the limit: this only removes the out-of-bounds read. The suffix check stays a filter for plausible call sites, not a proof that a stack word is a return address; the caller still has to land inside a module with an
.xbldsection before its edition is used.@omonkeyz on GitHub · 2026-11-25 13:50 UTC · original
Applied on main in
d68b34a(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.@RomainROCH on GitHub · 2026-11-23 20:54 UTC · original · reviewed
Found a concrete bounds bug in
cl_edition::after_callat this head. Fork == 2, a suffixFF 14(mod=0, /2, rm=4) givessib == 1; the match guard readscode[c-k+2], i.e.code[8]on an eight-byte array. That panics, potentially aborting when reached through the extern-system slot handlers. It can even occur at a genuine return address:90 90 FF 90 00 00 FF 14is a validcall [rax+disp32], but the shorter candidate is examined first.Minimal fix: immediately after calculating
sib, addif sib == 1 && k < 3 { continue; }. Do not return false there, because a longer candidate can still be valid. Suggested regressions inreturn_addresses_must_follow_a_call:assert!(!t(&[0xff, 0x14]));andassert!(t(&[0xff, 0x90, 0, 0, 0xff, 0x14]));.I verified the original failure and the guard using an isolated Python transcription of this function, including all 256 ModRM values following FF at the end of an 8-byte buffer and the existing positive/negative controls. No Rust build or game test here. This fixes the out-of-bounds case only; it does not establish that arbitrary stack words or suffixes are reliable call sites.
Pull request closed