d3d12_xs tests: three --lib tests that fail or crash on a release build (dangling temporary, function address, stale map entry) #276

Closed
github-bot wants to merge 3 commits from gh-pr/276/head into gh-pr/276/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 10:53 UTC · original
QuentinDanblon:fix/d3d12xs-hw-lib-tests → main · +3 −3 · 3 files · 3 commits · closed without merging

Library / area: d3d12_xs, tests only (pso_xrec.rs test module, device_console_fix.rs test module, dbcount_tests.rs)

Exports changed (exports.txt rows): none

Source of the behaviour: none needed, no runtime behaviour changes. Three tests of the --lib suite fail or kill the test process on this PC (RTX 5090, Windows 11, release build). CI does not run them: rust.yml only runs cargo check for d3d12_xs.

Three commits, one per test. Each fix is in the test, 3 files, +3 -3.

1. pso_xrec::tests::unknown_root_signatures_ext_entries_and_cached_blobs_are_not_recorded (ff387bb)

The whole test process died with an access violation, 3 runs of 3 with --exact. Under cdb the fault is in pso_xrec::capture at pso_xrec.rs:294, reading the semantic name of an input-layout element.

The test built its descriptor with gfx_desc(&vs, &ps, &[elem(..)], ..) inside a let. The element array is a temporary dropped at the end of that statement, so the descriptor kept a dangling pointer. The first three captures return before they read the input layout; only the last one dereferenced it.

capture is right to read through the title's pointer: the D3D12 create call requires the arrays to be valid for the duration of the call. The array is now bound to a local that outlives every capture. 5 runs of 5 pass.

2. device_console_fix::tests::console_heap_properties_create_on_pc_through_every_wrapped_path (dd6d6f7)

Failed on every run at device_console_fix.rs:384: the test compared slot 26 of the wrapped vtable with get_custom_heap_properties_x as usize, and the two addresses differed.

In cdb, x *!*get_custom_heap_properties_x* lists two symbols of that name in the release test binary. The build holds two copies of that small function, and Rust does not guarantee one address per function. The wrapper does install our function; the test compared two copies of it.

The address check is removed. The test still calls slot 26 with a sentinel-filled struct and requires the console values for heap types 1, 2 and 3, then checks that the PC runtime rejects those values unwrapped and that every wrapped create path accepts them.

Checked that the remaining assertions catch a slot 26 that is not replaced: with slot 26 taken from the unwrapped device (local change, not committed) the test process dies with an access violation, because the console order of the arguments is not the PC one.

3. dbcount::tests::translated_pixel_shaders_with_uavs_keep_their_source (a7ab19e)

Failed in full runs with --test-threads=1: 2 runs of 2 on the two commits above. The test asserted that PS_SRC holds no entry at the address of a pixel shader without UAVs. PS_SRC is process-wide, keyed by the address of the bytecode, and never shrinks, so an earlier test can leave an entry at an address the allocator later gives to this test.

Measured with a probe in place of the assertion, 2 runs of 2: the entry at the address of the plain shader had length 3304, the plain shader 2512 bytes, the UAV shader of this test 3152 bytes. It belongs to neither.

The assertion now uses the rule strip_ps uses in production, which reads an entry only when its length and hash match the bytecode. I did not look for which earlier test notes that entry.

Tests

On a7ab19e (base de1e1da), RTX 5090 PC, Windows 11:

  • cargo test -p d3d12_xs --release --lib -- --test-threads=1: 3 runs, each 662 passed, 1 failed, 71 ignored.
  • The remaining failure is xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs. It needs a console d3d12_xs.dll, which I do not have. Not touched.
  • pr_gate.py --base origin/main: 0 problems.

Not covered, not claimed

  • Other tests compare a vtable slot with a function address in the same way and pass today: cl_console_fix.rs:413-420, console_slots.rs:591-593, cl2_state.rs:2398. The same duplication could break them in another build. I did not change them.

  • The second fix was checked on the RTX 5090 only.

  • Whether these tests behave the same on your machine or in a debug build is not known to me.

  • cargo test -p d3d12_xs passes for what is listed above

  • No game or console files and no binaries included

  • No fake success; nothing in the runtime changes

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-23 10:53 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/276) `QuentinDanblon:fix/d3d12xs-hw-lib-tests` → `main` · +3 −3 · 3 files · 3 commits · closed without merging **Library / area:** `d3d12_xs`, tests only (`pso_xrec.rs` test module, `device_console_fix.rs` test module, `dbcount_tests.rs`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** none needed, no runtime behaviour changes. Three tests of the `--lib` suite fail or kill the test process on this PC (RTX 5090, Windows 11, release build). CI does not run them: `rust.yml` only runs `cargo check` for `d3d12_xs`. Three commits, one per test. Each fix is in the test, 3 files, +3 -3. ### 1. `pso_xrec::tests::unknown_root_signatures_ext_entries_and_cached_blobs_are_not_recorded` (`ff387bb`) The whole test process died with an access violation, 3 runs of 3 with `--exact`. Under cdb the fault is in `pso_xrec::capture` at `pso_xrec.rs:294`, reading the semantic name of an input-layout element. The test built its descriptor with `gfx_desc(&vs, &ps, &[elem(..)], ..)` inside a `let`. The element array is a temporary dropped at the end of that statement, so the descriptor kept a dangling pointer. The first three captures return before they read the input layout; only the last one dereferenced it. `capture` is right to read through the title's pointer: the D3D12 create call requires the arrays to be valid for the duration of the call. The array is now bound to a local that outlives every capture. 5 runs of 5 pass. ### 2. `device_console_fix::tests::console_heap_properties_create_on_pc_through_every_wrapped_path` (`dd6d6f7`) Failed on every run at `device_console_fix.rs:384`: the test compared slot 26 of the wrapped vtable with `get_custom_heap_properties_x as usize`, and the two addresses differed. In cdb, `x *!*get_custom_heap_properties_x*` lists two symbols of that name in the release test binary. The build holds two copies of that small function, and Rust does not guarantee one address per function. The wrapper does install our function; the test compared two copies of it. The address check is removed. The test still calls slot 26 with a sentinel-filled struct and requires the console values for heap types 1, 2 and 3, then checks that the PC runtime rejects those values unwrapped and that every wrapped create path accepts them. Checked that the remaining assertions catch a slot 26 that is not replaced: with slot 26 taken from the unwrapped device (local change, not committed) the test process dies with an access violation, because the console order of the arguments is not the PC one. ### 3. `dbcount::tests::translated_pixel_shaders_with_uavs_keep_their_source` (`a7ab19e`) Failed in full runs with `--test-threads=1`: 2 runs of 2 on the two commits above. The test asserted that `PS_SRC` holds no entry at the address of a pixel shader without UAVs. `PS_SRC` is process-wide, keyed by the address of the bytecode, and never shrinks, so an earlier test can leave an entry at an address the allocator later gives to this test. Measured with a probe in place of the assertion, 2 runs of 2: the entry at the address of the plain shader had length 3304, the plain shader 2512 bytes, the UAV shader of this test 3152 bytes. It belongs to neither. The assertion now uses the rule `strip_ps` uses in production, which reads an entry only when its length and hash match the bytecode. I did not look for which earlier test notes that entry. ### Tests On `a7ab19e` (base `de1e1da`), RTX 5090 PC, Windows 11: - `cargo test -p d3d12_xs --release --lib -- --test-threads=1`: 3 runs, each 662 passed, 1 failed, 71 ignored. - The remaining failure is `xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs`. It needs a console `d3d12_xs.dll`, which I do not have. Not touched. - `pr_gate.py --base origin/main`: 0 problems. ### Not covered, not claimed - Other tests compare a vtable slot with a function address in the same way and pass today: `cl_console_fix.rs:413-420`, `console_slots.rs:591-593`, `cl2_state.rs:2398`. The same duplication could break them in another build. I did not change them. - The second fix was checked on the RTX 5090 only. - Whether these tests behave the same on your machine or in a debug build is not known to me. - [x] `cargo test -p d3d12_xs` passes for what is listed above - [x] No game or console files and no binaries included - [x] No fake success; nothing in the runtime changes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
pso_xrec::tests::unknown_root_signatures_ext_entries_and_cached_blobs_are_not_recorded
killed the whole test process with an access violation (exit 139 under
Git Bash, 3 of 3 runs with --exact and --test-threads=1). Under cdb the
fault is in pso_xrec::capture at pso_xrec.rs:294, reading the semantic
name of an input-layout element, called from the test's last capture.

The test built its descriptor with gfx_desc(&vs, &ps, &[elem(..)], ..)
inside a let statement. The element array is a temporary that is dropped
at the end of that statement, so the descriptor kept a dangling pointer
to it. The first three captures return before reading the input layout
(unknown root signature, ext entries, cached blob), so only the last one
dereferenced the stale stack slot. The test does not create a device;
the adapter plays no part.

capture is right to read the input layout through the title's pointer:
the D3D12 create call requires the descriptor's arrays to be valid for
the duration of the call. Only the test was wrong.

The element array is now bound to a local that outlives every capture.

Run: cargo test -p d3d12_xs --release --lib -- --exact <test>:
5 of 5 runs pass after the change.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
device_console_fix::tests::console_heap_properties_create_on_pc_through_every_wrapped_path
failed on every run in a release build at device_console_fix.rs:384:

    assertion `left == right` failed
      left: 140695242310080
     right: 140695240276176

The assertion compared slot 26 of the wrapped device vtable with
get_custom_heap_properties_x as usize. In cdb, `x *!*get_custom_heap_properties_x*`
lists two symbols of that name in the release test binary: the build
holds two copies of that small function, and Rust does not guarantee
that a function has a single address. The wrapper does install our
function; the test compared two copies of it.

The address check is removed. The test still calls slot 26 with a
sentinel-filled HeapProperties and requires the console values from
custom_heap_properties for heap types 1, 2 and 3, then checks that the
PC runtime rejects those values unwrapped and that every wrapped create
path accepts them.

Checked that the remaining assertions still catch a slot 26 that is not
replaced: with slot 26 taken from the unwrapped device (temporary local
change, not committed) the test process dies with an access violation
(exit 139), because the console order of the arguments (result pointer
first, object second) is not the PC one.

Run: cargo test -p d3d12_xs --release --lib -- --exact <test> on an
NVIDIA RTX 5090: passes.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
translated_pixel_shaders_with_uavs_keep_their_source asserted that
PS_SRC holds no entry at the address of a pixel shader without UAVs.
PS_SRC is process-wide and keyed by the address of the bytecode, and
its entries are never removed, so an earlier test can leave an entry at
an address the allocator later gives to this test.

Measured with a probe in place of the assertion, full lib run with
--test-threads=1 on the parent of this commit, 2 runs of 2:
the entry found at the address of the plain shader had length 3304,
the plain shader 2512 bytes and the UAV shader of this test 3152 bytes.
It belongs to neither. Which earlier test noted it was not looked for.

The assertion now uses the same rule as strip_ps, which reads an entry
only when its length and hash match the bytecode: the test fails only
if the entry at that address describes the plain shader.

No change outside the test.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:16:57 +00:00
github-bot closed this pull request 2026-11-26 06:16:57 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 13:45 UTC · original

Applied locally on main with your authorship kept (cherry-picked, c40dd17); tests pass in a sandbox. It ships in the next release; this PR will be closed when that is pushed. Thanks.

**@⁠omonkeyz** on GitHub · 2026-11-23 13:45 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/276#issuecomment-7102979565) Applied locally on main with your authorship kept (cherry-picked, c40dd17); tests pass in a sandbox. It ships in the next release; this PR will be closed when that is pushed. Thanks.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:09 UTC · original

Applied on main in c40dd17 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:09 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/276#issuecomment-7163362594) Applied on main in c40dd17 (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.