GPU tests: the work run while a view is prepared is per thread #2944

Closed
desplmfao wants to merge 1 commit from upstream-pr/2946 into main
desplmfao commented 2026-11-26 01:14:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-26T01:14:39Z.


views_bound_while_another_slot_gets_its_texture_do_not_wait fails at random in CI with both made. In the last 25 failed runs it did on three unrelated PRs: #2310 (run), gpu/loose-window-reuse (run) and gpu/parallel-refresh (run).

Cause: that test and a_slot_rewritten_while_its_view_is_prepared_views_the_new_record set a global hook (WHILE_PREPARING) that runs while a view's texture is prepared, and any test that prepares a view takes it. With tests in parallel, one test can take or replace the other's hook. The work then never runs where it was meant to, and the second slot is never made.

Change: the hook is thread-local. It's set and taken on the test's own thread; the threads the work spawns don't see it. Test code only.

How it was found: the failing CI run on #2310 (which doesn't touch descriptor/), then a search of the recent failed runs for the test name. Locally (Wine, vkd3d-proton 3.2.0, RTX 5080) it didn't reproduce in 25 parallel runs of descriptor::host, before or after; the race needs CI's timing. Clippy is clean.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6617245044 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2946). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-26T01:14:39Z. --- `views_bound_while_another_slot_gets_its_texture_do_not_wait` fails at random in CI with `both made`. In the last 25 failed runs it did on three unrelated PRs: #2310 ([run](https://github.com/Marvisak/VIctory/actions/runs/45731594851)), `gpu/loose-window-reuse` ([run](https://github.com/Marvisak/VIctory/actions/runs/45713430315)) and `gpu/parallel-refresh` ([run](https://github.com/Marvisak/VIctory/actions/runs/45712699066)). **Cause:** that test and `a_slot_rewritten_while_its_view_is_prepared_views_the_new_record` set a global hook (`WHILE_PREPARING`) that runs while a view's texture is prepared, and any test that prepares a view takes it. With tests in parallel, one test can take or replace the other's hook. The work then never runs where it was meant to, and the second slot is never made. **Change:** the hook is thread-local. It's set and taken on the test's own thread; the threads the work spawns don't see it. Test code only. **How it was found:** the failing CI run on #2310 (which doesn't touch `descriptor/`), then a search of the recent failed runs for the test name. Locally (Wine, vkd3d-proton 3.2.0, RTX 5080) it didn't reproduce in 25 parallel runs of `descriptor::host`, before or after; the race needs CI's timing. Clippy is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Dukestar69 commented 2026-11-26 02:06:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T02:05:10Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):

  • cargo test -p victory-gpu --lib descriptor::host::tests -- --skip dynamic_slots_are_held_until_released: 14 passed, 0 failed (parallel run; dynamic_slots_are_held_until_released skipped due to pre-existing NVIDIA 1M view-heap cap #1744).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Moving WHILE_PREPARING from a global Mutex to a thread_local! RefCell cleanly eliminates cross-test stealing of the prepare hook during parallel test runs.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6067589458 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2946#pullrequestreview-6067589458). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T02:05:10Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090): - `cargo test -p victory-gpu --lib descriptor::host::tests -- --skip dynamic_slots_are_held_until_released`: **14 passed, 0 failed** (parallel run; `dynamic_slots_are_held_until_released` skipped due to pre-existing NVIDIA 1M view-heap cap `#1744`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Moving `WHILE_PREPARING` from a global `Mutex` to a `thread_local!` `RefCell` cleanly eliminates cross-test stealing of the prepare hook during parallel test runs. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-26 02:07:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T01:31:58Z.


Code review and parallel stress verification at head f337e710f98d on main (63bcca43c6a0):

  • Code review (crates/victory-gpu/src/descriptor/host.rs:1917-1941):
    • Moves WHILE_PREPARING from a global Mutex<Option<Work>> to thread_local! RefCell<Option<Work>> behind private on_prepare/prepare_pending helpers (verified no other references exist across victory-gpu/src). Spawned worker threads inside prepare callbacks observe None in their own TLS and cannot steal callbacks from concurrent tests.
  • Verified (Windows 11, NVIDIA RTX 5090, VICTORY_D3D12_DEBUG=1, Rust 1.98.1):
    • cargo xtask policy: 191 files ok; cargo clippy --locked -p victory-gpu --tests -- -D warnings: 0 warnings
    • Ran descriptor::host::tests in parallel across 6 consecutive runs: all 14 non-1M-heap-cap tests (including all 3 WHILE_PREPARING concurrency tests) passed 6/6 runs cleanly (only the pre-existing NVIDIA 1M view-heap baseline dynamic_slots_are_held_until_released failed consistently).

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7179865845 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2946#issuecomment-7179865845). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T01:31:58Z. --- Code review and parallel stress verification at head `f337e710f98d` on `main` (`63bcca43c6a0`): - **Code review (`crates/victory-gpu/src/descriptor/host.rs:1917-1941`)**: - Moves `WHILE_PREPARING` from a global `Mutex<Option<Work>>` to `thread_local! RefCell<Option<Work>>` behind private `on_prepare`/`prepare_pending` helpers (verified no other references exist across `victory-gpu/src`). Spawned worker threads inside prepare callbacks observe `None` in their own TLS and cannot steal callbacks from concurrent tests. - **Verified (Windows 11, NVIDIA RTX 5090, `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1)**: - `cargo xtask policy`: `191 files ok`; `cargo clippy --locked -p victory-gpu --tests -- -D warnings`: 0 warnings - Ran `descriptor::host::tests` in parallel across **6 consecutive runs**: all 14 non-1M-heap-cap tests (including all 3 `WHILE_PREPARING` concurrency tests) passed 6/6 runs cleanly (only the pre-existing NVIDIA 1M view-heap baseline `dynamic_slots_are_held_until_released` failed consistently). LGTM.
kotekompotek commented 2026-11-26 03:04:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-26T02:22:49Z.

Review: COMMENTED


Verified: this fixes a real flake class — parallel tests could take each other's queued prepare-work, leaving the intended test unexercised and failing at random. thread_local keeps the once-only semantics per test thread, and on_prepare/prepare_pending helpers keep call sites tidy. Consistent with the earlier thread_local conversion of the other WHILE_PREPARING.

<!-- greyfinch-sync:Marvisak/VIctory:review:6067721970 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2946#pullrequestreview-6067721970). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-26T02:22:49Z. **Review:** COMMENTED --- Verified: this fixes a real flake class — parallel tests could take each other's queued prepare-work, leaving the intended test unexercised and failing at random. thread_local keeps the once-only semantics per test thread, and on_prepare/prepare_pending helpers keep call sites tidy. Consistent with the earlier thread_local conversion of the other WHILE_PREPARING.
fyernald commented 2026-11-26 03:05:09 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fyernald on 2026-11-26T02:22:11Z.


This is the same change as #2585, opened 2026-11-25 16:16 UTC and triaged as a merge candidate at 19016aa: WHILE_PREPARING becomes thread-local, test code only.

That PR has parallel-run numbers for both tests: 22/200 → 0/200 runs failing on an RTX 3080, and 7/150 → 0/150 on WARP from @oni-swr. Linking the two so only one needs to land.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7180739231 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2946#issuecomment-7180739231). Originally posted by [fyernald](https://github.com/fyernald) on 2026-11-26T02:22:11Z. --- This is the same change as #2585, opened 2026-11-25 16:16 UTC and triaged as a merge candidate at `19016aa`: `WHILE_PREPARING` becomes thread-local, test code only. That PR has parallel-run numbers for both tests: 22/200 → 0/200 runs failing on an RTX 3080, and 7/150 → 0/150 on WARP from @oni-swr. Linking the two so only one needs to land.
upstream-sync closed this pull request 2026-11-26 04:05:49 +00:00
desplmfao commented 2026-11-26 04:06:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by desplmfao on 2026-11-26T03:23:52Z.


@fyernald thanks, you're right. #2585 is the same change, it came first, and it has the parallel-run numbers. I searched for the test's name rather than for WHILE_PREPARING and missed it. Closing this in favour of #2585.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7181682923 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2946#issuecomment-7181682923). Originally posted by [desplmfao](https://github.com/desplmfao) on 2026-11-26T03:23:52Z. --- @fyernald thanks, you're right. #2585 is the same change, it came first, and it has the parallel-run numbers. I searched for the test's name rather than for `WHILE_PREPARING` and missed it. Closing this in favour of #2585.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!2944
No description provided.