GPU tests: a freed test pool keeps its addresses, and mark tests hold off submissions #3083

Open
0xkn0wh3r3 wants to merge 2 commits from upstream-pr/3085 into main
0xkn0wh3r3 commented 2026-11-26 07:02:51 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by 0xkn0wh3r3 on 2026-11-26T07:02:51Z.


Run in parallel (the default cargo test), victory-gpu's shadow and watch tests fail now and then, and each passes when run alone. There are two causes, and both are fixed in the tests only.

1. A freed test pool's addresses were handed out again while a tracker still guarded them.
watch::protect counts a page that is already in the guard set as guarded, and skips VirtualProtect for it. A test can leave a tracker of its pool behind (a host copy or a texture's staging that something global still holds) and then free the pool. I instrumented watch::tests::free, and in every run some tests freed memory that was still in GUARDS:

  • host::batch::a_copy_is_refreshed_once_per_submission_by_the_pages_written
  • host::withholding::only_programs_using_title_memory_are_withheld
  • texture::tests::a_texture_viewed_from_a_later_level_is_staged_from_it_only

If another test's VirtualAlloc lands on those addresses, its pages count as guarded already. Its writes then never fault, so nothing is seen as changed or saved. This produced the failures in watch::tests::armed_ranges_keep_their_pages_bytes_from_before_the_first_write, unmapped_pages_are_taken_apart and the partial-refresh tests.

watch::tests::free now decommits the pool and keeps its addresses reserved, so no later allocation lands there, whichever test leaked the tracker.

2. A submission of a test running alongside took the marks a mark test had just set.
shadow::copy_back_marks takes every mark in the bitmaps, and Host::execute calls it. The fix adds host::tests::no_submissions(), which holds the submission lock while it is alive, as the read-mark tests in host.rs already do. These tests now hold it:

  • marked_pages_go_back_by_the_bytes_the_gpu_changed
  • marks_of_shaders_using_title_memory_are_held_back
  • partial_refresh_under_marked_range_updates_saved_bytes

None of them submits work itself.

Measured. 20 runs of cargo test -p victory-gpu --lib on Windows with an NVIDIA GPU.

  • On main: before the fix, 1 shadow failure in 20 runs; after it, no shadow or watch failure in 20 runs.
  • On a branch with more open GPU PRs merged in, where these races show up more often: before, 8 of 20 runs had a shadow or watch failure; after, none in 20 runs.

Two tests fail on main in every run, with or without this change: memory::tests::lists_share_a_table_and_copies_keep_their_views and descriptor::host::tests::dynamic_slots_are_held_until_released. They are not related to this change.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6621364045 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3085). Originally posted by [0xkn0wh3r3](https://github.com/0xkn0wh3r3) on 2026-11-26T07:02:51Z. --- Run in parallel (the default `cargo test`), victory-gpu's shadow and watch tests fail now and then, and each passes when run alone. There are two causes, and both are fixed in the tests only. **1. A freed test pool's addresses were handed out again while a tracker still guarded them.** `watch::protect` counts a page that is already in the guard set as guarded, and skips `VirtualProtect` for it. A test can leave a tracker of its pool behind (a host copy or a texture's staging that something global still holds) and then free the pool. I instrumented `watch::tests::free`, and in every run some tests freed memory that was still in `GUARDS`: - `host::batch::a_copy_is_refreshed_once_per_submission_by_the_pages_written` - `host::withholding::only_programs_using_title_memory_are_withheld` - `texture::tests::a_texture_viewed_from_a_later_level_is_staged_from_it_only` If another test's `VirtualAlloc` lands on those addresses, its pages count as guarded already. Its writes then never fault, so nothing is seen as changed or saved. This produced the failures in `watch::tests::armed_ranges_keep_their_pages_bytes_from_before_the_first_write`, `unmapped_pages_are_taken_apart` and the partial-refresh tests. `watch::tests::free` now decommits the pool and keeps its addresses reserved, so no later allocation lands there, whichever test leaked the tracker. **2. A submission of a test running alongside took the marks a mark test had just set.** `shadow::copy_back_marks` takes every mark in the bitmaps, and `Host::execute` calls it. The fix adds `host::tests::no_submissions()`, which holds the submission lock while it is alive, as the read-mark tests in `host.rs` already do. These tests now hold it: - `marked_pages_go_back_by_the_bytes_the_gpu_changed` - `marks_of_shaders_using_title_memory_are_held_back` - `partial_refresh_under_marked_range_updates_saved_bytes` None of them submits work itself. **Measured.** 20 runs of `cargo test -p victory-gpu --lib` on Windows with an NVIDIA GPU. - **On main:** before the fix, 1 shadow failure in 20 runs; after it, no shadow or watch failure in 20 runs. - **On a branch with more open GPU PRs merged in**, where these races show up more often: before, 8 of 20 runs had a shadow or watch failure; after, none in 20 runs. Two tests fail on main in every run, with or without this change: `memory::tests::lists_share_a_table_and_copies_keep_their_views` and `descriptor::host::tests::dynamic_slots_are_held_until_released`. They are not related to this change.
Dukestar69 commented 2026-11-26 08:03:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T07:07:46Z.

Review: APPROVED


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

  • cargo test -p victory-gpu watch::tests -- --test-threads=1: 15 passed, 0 failed.
  • cargo test -p victory-gpu shadow::tests -- --test-threads=1: 9 passed, 0 failed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6069846269 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3085#pullrequestreview-6069846269). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T07:07:46Z. **Review:** APPROVED --- Tested locally merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090): - `cargo test -p victory-gpu watch::tests -- --test-threads=1`: 15 passed, 0 failed. - `cargo test -p victory-gpu shadow::tests -- --test-threads=1`: 9 passed, 0 failed. - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
oni-swr commented 2026-11-26 08:03:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-26T07:38:46Z.


Independent WARP-only verification of this PR at b57d5a0cc544c4dc5bb4764bded9f8eb1b271eb8 (claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7185343017). Existing tests only, no source edits, no PR. AI use: Claude Code (Claude Sonnet 5.5), coordinated by Codex (gpt-6.2-sol).

Result. I did not reproduce the shadow/watch/mark flake on the parent under WARP, so these runs neither confirm nor refute the PR's fix. The PR head had no failures in 180 runs.

Compared

  • base 63bcca43c6a00a758510398fa43096ce7e4f7df0 (the PR's base)
  • 46b8c8163580e6717c80cd0938811e16b716e7a0 (the head's immediate parent, the first PR commit)
  • head b57d5a0cc544c4dc5bb4764bded9f8eb1b271eb8

Environment

  • Windows 11 10.0.26200, rustc/cargo 1.98.1, d3d10warp.dll 10.0.26100.9818.
  • The machine has one physical GPU. It was not used (see the adapter check below).
  • VICTORY_D3D12_WARP=1, VICTORY_DXIL = Windows SDK 10.0.26100.0 x64\dxil.dll (1.8.2502.11).
  • Target dir D:\victory-3085-warp-target, with -j 4 on every cargo command. D: stayed above 188 GB free.

Adapter check

  • VICTORY_D3D12_WARP only takes effect in a --features diagnostics build (host.rs: cfg!(feature = "diagnostics") && switch::on(...)). A default-feature build ignores it and would use the physical GPU. All repeated runs therefore use --features diagnostics builds only.
  • Before the GPU tests I watched the loaded modules of the test process while it ran.
    • With the variable set: d3d10warp.dll, Microsoft.Internal.WarpPal.dll, d3d12.dll, D3D12Core.dll, dxilconv.dll, and no vendor driver module.
    • Without it (control): amdxc64.dll and amdihk64.dll loaded instead.
  • The existing host::tests::warp_adapter_accepts_only_software printed EnumWarpAdapter: vendor=0x1414, flags=0x2 (Microsoft, software).

Commands

cargo test -p victory-gpu --lib --locked -j 4 --no-run --features diagnostics   # once per commit
<test exe>                                      # whole lib: 246 passed, 1 ignored (247 tests)
<test exe> --test-threads=32
<test exe> shadow:: watch:: marked read_marks marks    # 33 tests: shadow, watch, marked_*, read-mark tests

Runs were interleaved across the three builds. The test executables were run directly, not through cargo test.

Counts (failed runs / runs)

run set base head's parent head
whole lib, default threads 0/40 1/40 0/40
whole lib, --test-threads=32 1/40 0/40 0/40
33-test shadow/watch/mark subset 0/100 0/100 0/100
total 1/180 1/180 0/180

Failures

  • Both failures were the same test, descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait (descriptor/host.rs:2011, "both made"). It is in a file this PR does not touch.
  • It appeared once on base and once on the head's parent, and never on the head in 180 runs. I have not tried to explain it. With 1 failure per build in 180 runs, this does not show the PR changes it.
  • No shadow::, watch:: or mark test failed in any run on any commit.
  • The two tests the PR text says fail on every run on main, memory::tests::lists_share_a_table_and_copies_keep_their_views and descriptor::host::tests::dynamic_slots_are_held_until_released, passed in all 540 runs here.

Limitations

  • WARP only, no physical GPU, so timing and contention differ from the PR author's NVIDIA runs (1 shadow failure in 20 runs on main).
  • 0 failures in 40 default-thread parent runs cannot rule out a flake rate of a few percent.
  • The default-feature build was not run repeatedly, because it would select the physical GPU.
  • Only victory-gpu --lib was run. No other crates, no game, no dumps.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7185679957 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3085#issuecomment-7185679957). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-26T07:38:46Z. --- Independent WARP-only verification of this PR at `b57d5a0cc544c4dc5bb4764bded9f8eb1b271eb8` (claim: https://github.com/Marvisak/VIctory/issues/1633#issuecomment-7185343017). Existing tests only, no source edits, no PR. AI use: Claude Code (Claude Sonnet 5.5), coordinated by Codex (gpt-6.2-sol). **Result.** I did not reproduce the shadow/watch/mark flake on the parent under WARP, so these runs neither confirm nor refute the PR's fix. The PR head had no failures in 180 runs. **Compared** - base `63bcca43c6a00a758510398fa43096ce7e4f7df0` (the PR's base) - `46b8c8163580e6717c80cd0938811e16b716e7a0` (the head's immediate parent, the first PR commit) - head `b57d5a0cc544c4dc5bb4764bded9f8eb1b271eb8` **Environment** - Windows 11 10.0.26200, rustc/cargo 1.98.1, `d3d10warp.dll` 10.0.26100.9818. - The machine has one physical GPU. It was not used (see the adapter check below). - `VICTORY_D3D12_WARP=1`, `VICTORY_DXIL` = Windows SDK 10.0.26100.0 `x64\dxil.dll` (1.8.2502.11). - Target dir `D:\victory-3085-warp-target`, with `-j 4` on every cargo command. D: stayed above 188 GB free. **Adapter check** - `VICTORY_D3D12_WARP` only takes effect in a `--features diagnostics` build (`host.rs`: `cfg!(feature = "diagnostics") && switch::on(...)`). A default-feature build ignores it and would use the physical GPU. All repeated runs therefore use `--features diagnostics` builds only. - Before the GPU tests I watched the loaded modules of the test process while it ran. - With the variable set: `d3d10warp.dll`, `Microsoft.Internal.WarpPal.dll`, `d3d12.dll`, `D3D12Core.dll`, `dxilconv.dll`, and no vendor driver module. - Without it (control): `amdxc64.dll` and `amdihk64.dll` loaded instead. - The existing `host::tests::warp_adapter_accepts_only_software` printed `EnumWarpAdapter: vendor=0x1414, flags=0x2` (Microsoft, software). **Commands** ``` cargo test -p victory-gpu --lib --locked -j 4 --no-run --features diagnostics # once per commit <test exe> # whole lib: 246 passed, 1 ignored (247 tests) <test exe> --test-threads=32 <test exe> shadow:: watch:: marked read_marks marks # 33 tests: shadow, watch, marked_*, read-mark tests ``` Runs were interleaved across the three builds. The test executables were run directly, not through `cargo test`. **Counts (failed runs / runs)** | run set | base | head's parent | head | |---|---|---|---| | whole lib, default threads | 0/40 | 1/40 | 0/40 | | whole lib, `--test-threads=32` | 1/40 | 0/40 | 0/40 | | 33-test shadow/watch/mark subset | 0/100 | 0/100 | 0/100 | | total | 1/180 | 1/180 | 0/180 | **Failures** - Both failures were the same test, `descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait` (`descriptor/host.rs:2011`, "both made"). It is in a file this PR does not touch. - It appeared once on base and once on the head's parent, and never on the head in 180 runs. I have not tried to explain it. With 1 failure per build in 180 runs, this does not show the PR changes it. - No `shadow::`, `watch::` or mark test failed in any run on any commit. - The two tests the PR text says fail on every run on main, `memory::tests::lists_share_a_table_and_copies_keep_their_views` and `descriptor::host::tests::dynamic_slots_are_held_until_released`, passed in all 540 runs here. **Limitations** - WARP only, no physical GPU, so timing and contention differ from the PR author's NVIDIA runs (1 shadow failure in 20 runs on main). - 0 failures in 40 default-thread parent runs cannot rule out a flake rate of a few percent. - The default-feature build was not run repeatedly, because it would select the physical GPU. - Only `victory-gpu --lib` was run. No other crates, no game, no dumps.
fuzeofficlal commented 2026-11-26 09:05:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:40:00Z.

Review: APPROVED


Clean, test-only fix for both parallel test races:

  • All changes are strictly under #[cfg(test)] (host.rs, shadow.rs, watch.rs), with no production code impact.
  • Checked all watch::tests::free call sites: every caller passes a base allocation from watch::tests::pool, so VirtualFree(p, 0, MEM_DECOMMIT) safely decommits the whole region while keeping its virtual address range reserved so leaked GUARDS entries from other tests cannot poison subsequent pools.
  • Checked all three shadow::tests holding host::tests::no_submissions(): none of them submit command lists or re-enter host.submitted, matching the existing pattern in host::tests.

Verified locally on Windows 11 with default parallel test execution (no --test-threads=1):

  • RTX 5090: cargo test -p victory-gpu --lib -- watch:: shadow:: — 10/10 parallel runs passed (25/25 each)
  • WARP (--features diagnostics, VICTORY_D3D12_WARP=1): watch:: shadow:: — 5/5 parallel runs passed (25/25 each)
  • cargo clippy -p victory-gpu --all-targets -- -D warnings (default and --all-features): clean
  • cargo xtask policy: 191 files ok

LGTM.

<!-- greyfinch-sync:Marvisak/VIctory:review:6070844717 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3085#pullrequestreview-6070844717). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:40:00Z. **Review:** APPROVED --- Clean, test-only fix for both parallel test races: - All changes are strictly under `#[cfg(test)]` (`host.rs`, `shadow.rs`, `watch.rs`), with no production code impact. - Checked all `watch::tests::free` call sites: every caller passes a base allocation from `watch::tests::pool`, so `VirtualFree(p, 0, MEM_DECOMMIT)` safely decommits the whole region while keeping its virtual address range reserved so leaked `GUARDS` entries from other tests cannot poison subsequent pools. - Checked all three `shadow::tests` holding `host::tests::no_submissions()`: none of them submit command lists or re-enter `host.submitted`, matching the existing pattern in `host::tests`. Verified locally on Windows 11 with default parallel test execution (no `--test-threads=1`): - RTX 5090: `cargo test -p victory-gpu --lib -- watch:: shadow::` — 10/10 parallel runs passed (25/25 each) - WARP (`--features diagnostics`, `VICTORY_D3D12_WARP=1`): `watch:: shadow::` — 5/5 parallel runs passed (25/25 each) - `cargo clippy -p victory-gpu --all-targets -- -D warnings` (default and `--all-features`): clean - `cargo xtask policy`: 191 files ok LGTM.
Marvisak commented 2026-11-26 09:06:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T08:21:04Z.


Automated triage for the maintainers.

Merge candidate. This changes tests only. watch::tests::free now uses MEM_DECOMMIT (size 0 at the allocation base decommits the whole region) instead of MEM_RELEASE. The address range stays reserved, so a later test's pool cannot land on pages that a leaked tracker still keeps in GUARDS. The new host::tests::no_submissions() holds Host::submitted, the same lock the existing read-mark tests in host.rs hold. The three shadow mark/refresh tests now take it. I checked that their bodies (register, find -> shared_buffer, copy_back_marks) never submit, so they cannot deadlock. Their lock order (submitted, then buffers) is the same as Host::execute's. One cost: test address space is no longer returned, which is fine at these pool sizes.

CI: passing (check).


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7186488015 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3085#issuecomment-7186488015). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T08:21:04Z. --- <!-- victory-triage v1 head=b57d5a0cc544c4dc5bb4764bded9f8eb1b271eb8 verdict=merge-candidate at=2026-11-26T08:17:59Z --> Automated triage for the maintainers. **Merge candidate.** This changes tests only. `watch::tests::free` now uses `MEM_DECOMMIT` (size 0 at the allocation base decommits the whole region) instead of `MEM_RELEASE`. The address range stays reserved, so a later test's pool cannot land on pages that a leaked tracker still keeps in `GUARDS`. The new `host::tests::no_submissions()` holds `Host::submitted`, the same lock the existing read-mark tests in `host.rs` hold. The three shadow mark/refresh tests now take it. I checked that their bodies (`register`, `find` -> `shared_buffer`, `copy_back_marks`) never submit, so they cannot deadlock. Their lock order (submitted, then buffers) is the same as `Host::execute`'s. One cost: test address space is no longer returned, which is fine at these pool sizes. CI: passing (check). --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3085:upstream-pr/3085'
git switch 'upstream-pr/3085'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3085'
git switch 'upstream-pr/3085'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3085'
git switch 'upstream-pr/3085'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3085'
git switch 'main'
git merge --squash 'upstream-pr/3085'
git switch 'main'
git merge --ff-only 'upstream-pr/3085'
git switch 'main'
git merge 'upstream-pr/3085'
git push origin 'main'
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!3083
No description provided.