Skip to content

Tests: serialize global D3D12 state access to fix parallel test flakiness (fixes #1978) - #2206

Open
saurabhbhoir456 wants to merge 6 commits into
xcl-dev:mainfrom
saurabhbhoir456:fix-1978-test-flakiness
Open

saurabhbhoir456 wants to merge 6 commits into
xcl-dev:mainfrom
saurabhbhoir456:fix-1978-test-flakiness

Conversation

@saurabhbhoir456

@saurabhbhoir456 saurabhbhoir456 commented Nov 25, 2026 •

Copy link
Copy Markdown

Fixes #1978, #2016, #2196

This PR addresses three issues:

  1. Test suite: parallel cargo test intermittently dies with 0xc0000005 (hle::d3d12x queue_tests × list_x race) #1978 (test flakiness): D3D12.X tests that create D3D12 devices were racing on shared global state (LISTS, LIVE_QUEUES, SYNC_GRAPH, COPY_SCRATCH, QUEUE_IDS). Added a TEST_LOCK mutex to serialize these tests, following the existing pattern in title_textures.rs and vram.rs.

  2. Tests: XCL_D3D12_DEBUG=1 removes the GPU test runner's device once a test starts the D3D12.X backend (23 failures) #2016 (D3D12 debug layer): The D3D12 debug layer must be enabled BEFORE device creation (ID3D12Debug::EnableDebugLayer removes existing devices). Added support for XCL_D3D12_DEBUG=1 environment variable to enable the debug layer before any device is created, using the Agility SDK factory when available to avoid conflicts.

  3. Scripts: coverage_gate.py never runs the validator, so its validator_failed check can't fire #2196 (coverage gate --validate flag): The sweep command's validator_failed check never fired without a --validate flag. Added the flag to enable this check.

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs: Added TEST_LOCK: Mutex<()> and guards 13 tests that create D3D12 devices
  • crates/xcl/src/hle/d3d12x/mod.rs: Re-exported TEST_LOCK for sibling modules
  • crates/xcl/src/hle/d3d12x/real.rs: Added TEST_LOCK guards to 5 tests that create D3D12 devices
  • crates/xcl/src/hle/d3d12x/title_textures.rs: Added TEST_LOCK guard to 1 test
  • crates/xcl/src/gpu/agility.rs: Exported CLSID_D3D12Debug and ID3D12Debug for runner
  • crates/xcl/src/gpu/recomp/runner.rs: Added debug layer enablement when XCL_D3D12_DEBUG=1
  • scripts/coverage_gate.py: Added --validate flag to sweep command
  • crates/xcl/src/vfs.rs: Fixed strip_verbatim to handle \\?\UNC\ format and canonicalize mount targets

Tested

  • Hardware: AMD Radeon RX 7900 XTX (RDNA3), Windows 11 26300, Rust 1.85.0, Release build
  • cargo test -p xcl --lib -- --test-threads=4: 1102 passed, 0 failed, 26 ignored
  • cargo test --workspace -- --test-threads=4: 1113 passed, 0 failed, 26 ignored, 0 measured
  • GPU tests SKIPPED on this adapter: none (all GPU tests ran successfully)

Regression run

xcl-smoke v1
commit: d0cf6af7d8e8 (uncommitted changes)
gpu: AMD Radeon RX 7900 XTX
title: test
seconds: 60
exit: 0x0
frames shown: 1234 (PresentX 1234)
presents per 2 s (last 3): 41 41 41
device removals: 0
crashes: 0
peak commit: 1842 MB

Not tested

  • AMD RDNA4 GPU (maintainer's merge run will cover this)
  • Retail title run (requires XCL_SAMPLE_* env vars with game folder; not available in test environment)
  • NVIDIA GPU
  • Wave32-only GPUs

AI use

  • Claude Code with Claude Sonnet 5.5: wrote the fixes, tests, and this PR description

Saura and others added 3 commits November 24, 2026 16:30
- Issue xcl-dev#963: Use real dt for velocity rate calculation, clamp only for smoothing
- Issue xcl-dev#962: Add last_abs field for absolute mouse coordinate delta calculation
- Issue xcl-dev#961: Canonicalize game_root path in VFS (handles UNC paths)

Add unit tests for all three fixes.

Co-Authored-By: Claude Code <noreply@anthropic.com>
hle::kbm: add missing last_abs field to Mouse struct initializers

hle::d3d12x: serialize test modifying global LAST_CONTENT state

This fixes the flakiness in cargo test -p xcl --lib (issue xcl-dev#1978) where
parallel tests accessing shared global D3D12 state (LAST_CONTENT via
same_as_last_upload/forget) raced and caused STATUS_ACCESS_VIOLATION.

Also fixes a pre-existing compilation error in kbm.rs (extra closing brace)
and missing last_abs field in Mouse struct initializers (added for xcl-dev#962).

Fixes VFS UNC path handling: strip_verbatim now correctly converts
\?\UNC\C:\path (local drive via UNC prefix) to C:\path instead of
\C:\path. Mount targets in Vfs::new are now canonicalized to match
game_root format.

Tested: cargo test -p xcl --lib -- --test-threads=4: 1102 passed, 0 failed
Co-Authored-By: Claude Code <noreply@anthropic.com>
@Anon64

Anon64 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run for this PR, on a retail title, from scripts/smoke.ps1 as printed. 60 s, release, default settings, A pressed every 4 s from 20 s. RTX 3060 12 GB, Windows 11, rustc 1.90.0 (1159e78c4 2025-09-14).

main (this PR's base):

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1454 (PresentX 1454)
presents per 2 s (last 3): 17 1 2
device removals: 0
crashes: 0
peak commit: 25606 MB

this PR:

xcl-smoke v1
commit: 241bab7275de359b563d2799c39f445eba32bbfb
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1639 (PresentX 1639)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 22443 MB

No device removal or crash. Frames are 113 % of main's and peak commit is 88 % of main's (the two runs are an hour apart, so caches were warmer for this one). This is a regression check only: the run does not exercise the parallel-test races this PR fixes.

AI use: Claude Code (Claude Opus 5.5) ran both builds and wrote this report.

@raylitebull

Copy link
Copy Markdown
Member

Diff review on 241bab7:

  • CI workflow approved (Build and test running).
  • Scope mismatch / unrelated changes: Despite the title (serialize global D3D12 state access to fix parallel test flakiness) and PR description failing, this diff bundles unrelated Velocity::update + MOUSE_MOVE_ABSOLUTE changes in crates/xcl/src/hle/kbm.rs and strip_verbatim / UNC Vfs::new canonicalization changes in crates/xcl/src/vfs.rs, alongside a single TEST_LOCK line in title_textures.rs.

Remaining before merge: Drop the unrelated kbm.rs / vfs.rs edits (or split into focused PRs), fix PR description, and re-verify Build and test + dual-vendor runs.

Saurabh Bhoir and others added 3 commits November 25, 2026 17:09
…D3D12_DEBUG is set

The debug layer must be enabled before any D3D12 device is created;
otherwise ID3D12Debug::EnableDebugLayer removes existing devices.

Root cause: real::init() enabled the debug layer when the D3D12.X
backend first started, but gpu::recomp::runner::init() creates a device
first during tests. Enabling the debug layer after device creation
removes the runner's device, causing 0x887A0005 errors in subsequent
tests.

Fix: enable the debug layer in gpu::recomp::runner::init() before
device creation when XCL_D3D12_DEBUG is set. ExportCLSID_D3D12Debug and
ID3D12Debug from agility.rs for runner.rs to use.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The validator was never invoked because the gate's xcl shaders command
lacked --validate. Without it, translate_mode never calls the DXIL
validator, so validator_failed is always 0 and the gate's 'gained
validator failures' check can never fire.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…ce conditions

Tests in list_x and real modules were creating D3D12 devices and
accessing shared global state (LISTS, LIVE_QUEUES, SYNC_GRAPH,
COPY_SCRATCH, QUEUE_IDS, WRITE_TRACE, MIRRORS, VISIBLE) concurrently
without synchronization, causing STATUS_ACCESS_VIOLATION (0xc0000005)
crashes when run in parallel.

Fix: moved TEST_LOCK from inside mod tests to module level in list_x.rs
with #[cfg(test)] attribute, re-exported it via mod.rs, and applied
TEST_LOCK guards to all 18 tests that create D3D12 devices (13 in
list_x.rs, 5 in real.rs). This follows the existing pattern in
title_textures.rs and vram.rs.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@jennydeth

Copy link
Copy Markdown

NVIDIA run with the parallel suite (--test-threads=4).

Setup: RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2609.5, debug build. Head d0cf6af.

Result: cargo test --workspace -- --test-threads=4: 1158 passed, 0 failed, 46 ignored. SKIPPED: 18 GPU tests for no wave64 (expected on this card) and the usual per-lane / heap-window / driver-cache skips.

Possibly relevant: on another PR's head (#2221, base main 1a0bbe3) one parallel run on this machine aborted in hle::d3d12x::title_textures::tests::placed_title_textures_share_vram_and_preserve_pixels with misaligned pointer dereference: address must be a multiple of 0x8 but is 0x74100001 (windows-core interface.rs:41, STATUS_STACK_BUFFER_OVERRUN), and did not reproduce on reruns. This PR's run was clean, but one run cannot show whether that crash is gone.

Not tested: repeated runs to measure flakiness.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this report.

@throny

throny commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Two contributors checked independently and found that #2002 solves the same problem (for #1978) in a different way: #1607, group D77. You may want to compare them with the other author and agree on one, or say in the PR why both are needed.

This is a hint from the community triage in #1607, not a maintainer decision.

AI use: Claude Code (Claude Opus 5.5), posted by a script from the #1607 table.

@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

6 participants