Skip to content

GPU tests: each test's prepare hook runs on its own thread - #2585

Open
fyernald wants to merge 1 commit into
Marvisak:mainfrom
fyernald:fix/prepare-hook-per-thread
Open

fyernald wants to merge 1 commit into
Marvisak:mainfrom
fyernald:fix/prepare-hook-per-thread

Conversation

@fyernald

Copy link
Copy Markdown

Two victory-gpu tests added in 42ea09f fail intermittently when the suite runs in parallel (the default for cargo test):

  • descriptor::host::tests::a_slot_rewritten_while_its_view_is_prepared_views_the_new_record: "the slot views the record written last"
  • descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait: "both made"

Each passes when run alone.

Cause

Both tests install work in WHILE_PREPARING, which prepare runs once. It was one global for the whole test process. Every test that binds a view calls prepare, so with tests running in parallel:

  • another test's prepare can take the hook first, so the work runs inside that test instead, or
  • the other of these two tests can replace the hook before this test's own prepare runs, so this test runs the other one's work.

Either way, the concurrent write (or bind) the test checks for never happens, and its assertion fails.

Change

WHILE_PREPARING is now thread-local. prepare runs on the thread that binds the view (HostHeap::mirror), so each test's hook runs in its own prepare and nowhere else. The two tests set and check it via set / with_borrow. This is test code only; nothing outside #[cfg(test)] changes. WHILE_MAKING is left alone, because it already only runs for its own slot.

Testing

Windows 10 Pro 22H2 (19045), RTX 3080 (driver 617.42), Rust 1.98.1 MSVC, base 67e8ae1. The full victory-gpu lib test binary was run 200 times in a row with default parallelism:

Build Runs with either test failing
main 67e8ae1 22 / 200 (a_slot_rewritten_… 13, views_bound_… 11)
this PR 0 / 200

The other failures on this machine are unchanged in both builds and unrelated. They happen in every run: dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views (NVIDIA's view heap cap, FIND-9), plus a_texture_written_in_one_format_reads_in_another_through_a_placed_view (Windows 10 has no ID3D12Device10, #1999).

  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: clean, also with --all-features
  • cargo xtask policy: 184 files ok

Claim: #1633 (comment)

What was wrong: `descriptor::host::tests::WHILE_PREPARING`, the hook that
runs work while a view's texture is prepared, was one global for the
test process. Every test that binds a view prepares one, and the suite
runs tests in parallel, so the hook ran in whichever test prepared
first, or another test replaced it before its own test's prepare ran.
`a_slot_rewritten_while_its_view_is_prepared_views_the_new_record` then
failed with "the slot views the record written last" (the rewrite never
happened) and `views_bound_while_another_slot_gets_its_texture_do_not_wait`
with "both made" (the other slot was never bound).

What changed: the hook is thread-local. `prepare` runs on the thread
that binds the view (`HostHeap::mirror`), so a test's hook runs in its
own prepare and in no other test's. Test code only.

Evidence: the full `cargo test -p victory-gpu --lib` binary, 200 runs
each on Windows 10 (19045) and an RTX 3080: main 67e8ae1 had a failure
of one of the two in 22 runs (13 and 11); with this change, none.
@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

oni-swr verification — head 19016aaf6f13fdc7d338ad15fb825453e8717739, origin/main 67e8ae1401df112248aed36d0024483181b718b7

Environment: Windows 11 Pro (26200), rustc 1.98.1, WARP only (VICTORY_D3D12_WARP=1 with --features diagnostics, which is what makes the host device the software adapter; Windows SDK 10.0.26100.0 dxil.dll on PATH). No hardware GPU use in the reported runs, no game files, no retail data. Merge check: git merge-tree --write-tree origin/main <head> is clean.

Commands / results

  • cargo test --locked -p victory-gpu --features diagnostics --lib -- descriptor::host::tests: 13 passed, 0 failed, 0 ignored
  • cargo test --locked -p victory-gpu --features diagnostics: 198 passed, 0 failed, 1 ignored (lib; 0 doctests)
  • Flake reproduction, built lib binary run 150 times each with descriptor:: --test-threads=16: origin/main 7/150 runs fail (views_bound_while_another_slot_gets_its_texture_do_not_wait 4, a_slot_rewritten_while_its_view_is_prepared_views_the_new_record 4); this PR 0/150.
  • Separately, full-lib runs (60 each, default threads) show an unrelated flake in memory::tests::a_submission_that_missed_leaves_the_copies_at_once on WARP: main 9/60, PR 14/60 (also seen once failing on bindless::tests::heap_views_are_current on main). It is not touched by this diff, passes alone and with --test-threads=1; noting it so it is not blamed on this PR.

Review: test-only change. WHILE_PREPARING becomes a thread_local! RefCell; prepare runs on the thread calling HostHeap::mirror, so the hook set by a test is consumed on that same thread, and the helper threads the tests spawn only perform the concurrent write/bind (they never need the hook). WHILE_MAKING correctly left alone. I found no defects.

Overlap: no open PR changes the same hunks. #2547, #2558, #2543, #2542, #2541, #2483 also touch descriptor/host.rs and all merge with this branch cleanly (merge-tree); #2475 conflicts with it in descriptor/host.rs/draw.rs (an ordering matter for whichever lands second, not this PR's fault).

AI disclosure: this review and verification were done by Claude Code (Claude Sonnet 5.5), not a human reviewer. Comment-only; no code changed.

@fyernald

Copy link
Copy Markdown
Author

Thanks, @oni-swr. Your 7/150 → 0/150 on WARP matches what I saw on hardware.

On memory::tests::a_submission_that_missed_leaves_the_copies_at_once: it never failed in any of my full-suite runs on an RTX 3080 (Windows 10, default parallelism). That's 0 of 550: 200 on main 67e8ae1, 200 with this PR and 150 more on other builds. So it looks specific to WARP (or to its timing), which fits your reading that it's unrelated here.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. This is a test-only fix for two flaky descriptor::host tests. WHILE_PREPARING was one process-wide hook, and prepare runs it for every view any parallel test binds, so another test could take or replace it first. It is now a thread_local! RefCell. prepare (descriptor/host.rs) calls tests::while_preparing() on the thread that calls HostHeap::mirror, which is the test's own thread, so each hook runs in its own test. The helper threads the tests spawn never need it. Nothing outside #[cfg(test)] changes.

CI: check passing. Merges cleanly into current main. A recommendation to look at it, not an approval.


Generated by Claude Code

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants