tests: wait for the queues before settling retired resources #3509

Merged
Leyukaka merged 2 commits from upstream-pr/3509 into main 2026-12-02 19:48:41 +00:00
Leyukaka commented 2026-11-29 19:04:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T19:04:28Z.


Refs #3507 (item c).

tests/startup_resource_retire_title.cpp checked retirement right after a release at several stages without waiting for the release-time fences. settle() only resubmits the drain list and never waits on the GPU, so a "freed" check could run before the fence passed. This is the failure seen in CI run 46260430363 on the hardware_debug1 variant, case 6: retained=131072/2, expected=65536/1, i.e. the newer wrapper was still retained.

The change adds a wait on both registered guest queues (direct, gated) after the release and before the check. It is the same pattern as 80ab69e8 (#3457) in the sibling test tests/startup_resource_retire.cpp. One file, +9/-2, no change under src/.

Sites

8 wait sites, 9 stages:

Case Stage Wait
2 T_addr2 kept while slot70 SRV live, then T_addr2 retired after heap released both queues, added
3 T_rgba_after_bc7 retired both queues, added
4 Tv1 held by heap1 and heap2, then Tv1 retired after descriptor overwrite both queues, added
4 Tv2 held by overwritten heap2[0], then Tv2 retired after heap2 released both queues, added
6 newer wrapper retired with older SRV live both queues, added
6 older generation retired covered by the same wait: dropping the last SRV reference adds no release fence
7 slot 133 texture held by the closed draw list, then slot 133 draw hold dropped gated added before the existing direct waits
9 class texture with a refused RTV in a tracked slot gated added next to direct
9 class texture with a refused RTV in an untracked slot gated added next to direct

No assertion is removed or relaxed.

  • Cases 3, 6 and 9-tracked: the "freed" checks no longer race the release fence. The texture must still be freed.
  • Cases 2, 4, 7 and 9-untracked: the "kept" checks get stronger. Once the fences have passed, only a descriptor hold or a list hold can keep the texture, so an unfinished fence can no longer make them pass.

The gated queue waits on a gate fence in three cases, each signalled inside the same case: case 1 (tests/startup_resource_retire_title.cpp:633, signalled at :638), case 2 (:659, signalled at :687) and case 11 (:1110, signalled at :1147). Cases 1 and 2 signal before the first added wait (:724). Case 11 runs only in inline mode, where main() returns right after it (:1467-:1474) and no case with an added wait runs. So the added waits cannot block. In off mode nothing retires and the waits are inert.

Tests

At 994a36e5 on d3e306a7, dev preset, each variant 20 times in a row (ctest --parallel 1 --repeat until-fail:20), on WARP and on one desktop GPU:

  • 20/20: warp_debug0, hardware_debug0, off_warp, off_hardware, inline_warp_debug0, inline_hardware_debug0.
  • Skipped (77): warp_debug1, hardware_debug1, inline_warp_debug1, inline_hardware_debug1. The D3D12 debug layer is not installed on this machine.

Not covered

  • hardware_debug1, the variant that failed in CI, was not run locally. The fix is not proven locally against that failure.
  • Mutation: with the case-6 wait removed, warp_debug0 and hardware_debug0 each passed 120 runs out of 120. Without the debug layer the release fences pass within the drain loop, so this machine does not show that the wait is needed. That rests on the CI failure above and on the code argument.
  • The base d3e306a7 was not run separately.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5554063026 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3509). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T19:04:28Z. --- Refs #3507 (item c). `tests/startup_resource_retire_title.cpp` checked retirement right after a release at several stages without waiting for the release-time fences. `settle()` only resubmits the drain list and never waits on the GPU, so a "freed" check could run before the fence passed. This is the failure seen in CI run 46260430363 on the `hardware_debug1` variant, case 6: `retained=131072/2`, `expected=65536/1`, i.e. the newer wrapper was still retained. The change adds a wait on both registered guest queues (`direct`, `gated`) after the release and before the check. It is the same pattern as 80ab69e8 (#3457) in the sibling test `tests/startup_resource_retire.cpp`. One file, +9/-2, no change under `src/`. ## Sites 8 wait sites, 9 stages: | Case | Stage | Wait | |---|---|---| | 2 | `T_addr2 kept while slot70 SRV live`, then `T_addr2 retired after heap released` | both queues, added | | 3 | `T_rgba_after_bc7 retired` | both queues, added | | 4 | `Tv1 held by heap1 and heap2`, then `Tv1 retired after descriptor overwrite` | both queues, added | | 4 | `Tv2 held by overwritten heap2[0]`, then `Tv2 retired after heap2 released` | both queues, added | | 6 | `newer wrapper retired with older SRV live` | both queues, added | | 6 | `older generation retired` | covered by the same wait: dropping the last SRV reference adds no release fence | | 7 | `slot 133 texture held by the closed draw list`, then `slot 133 draw hold dropped` | `gated` added before the existing `direct` waits | | 9 | `class texture with a refused RTV in a tracked slot` | `gated` added next to `direct` | | 9 | `class texture with a refused RTV in an untracked slot` | `gated` added next to `direct` | No assertion is removed or relaxed. - Cases 3, 6 and 9-tracked: the "freed" checks no longer race the release fence. The texture must still be freed. - Cases 2, 4, 7 and 9-untracked: the "kept" checks get stronger. Once the fences have passed, only a descriptor hold or a list hold can keep the texture, so an unfinished fence can no longer make them pass. The gated queue waits on a gate fence in three cases, each signalled inside the same case: case 1 (`tests/startup_resource_retire_title.cpp:633`, signalled at `:638`), case 2 (`:659`, signalled at `:687`) and case 11 (`:1110`, signalled at `:1147`). Cases 1 and 2 signal before the first added wait (`:724`). Case 11 runs only in inline mode, where `main()` returns right after it (`:1467`-`:1474`) and no case with an added wait runs. So the added waits cannot block. In off mode nothing retires and the waits are inert. ## Tests At 994a36e5 on d3e306a7, dev preset, each variant 20 times in a row (`ctest --parallel 1 --repeat until-fail:20`), on WARP and on one desktop GPU: - 20/20: `warp_debug0`, `hardware_debug0`, `off_warp`, `off_hardware`, `inline_warp_debug0`, `inline_hardware_debug0`. - Skipped (77): `warp_debug1`, `hardware_debug1`, `inline_warp_debug1`, `inline_hardware_debug1`. The D3D12 debug layer is not installed on this machine. ## Not covered - `hardware_debug1`, the variant that failed in CI, was not run locally. The fix is not proven locally against that failure. - Mutation: with the case-6 wait removed, `warp_debug0` and `hardware_debug0` each passed 120 runs out of 120. Without the debug layer the release fences pass within the drain loop, so this machine does not show that the wait is needed. That rests on the CI failure above and on the code argument. - The base d3e306a7 was not run separately.
Not-Saii commented 2026-11-29 20:58:36 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-29T20:58:36Z.

Review: COMMENTED


I checked this against #3457, which fixed the same race in the sibling tests/startup_resource_retire.cpp. It's the same pattern, and the added waits sit in the right places. settle() only resubmits the drain list, so without a queue wait a "freed" check can run before the release fence passes. I also agree that the "kept" checks get stronger, not weaker, and no assertion changes.

On the claim that the added waits can't block: they can't, but the gated queue also waits on a gate in case 11 (case11_inline_stale_descriptor_draw, inline mode), not only in cases 1 and 2. That gate is signalled inside case 11 before it returns, and the cases run in a fixed order from main(), so no added wait can run while a gate is pending. Also, Context::sync times out and fails rather than hanging. The conclusion holds, and only the "cases 1 and 2" wording in the PR body is incomplete.

Same caveat as #3457: without the debug layer, the mutation can't fail locally, so the proof against hardware_debug1 is the CI failure plus the code argument. A full workflow run on the fork would exercise the _debug1 variants on the runner, if you want that before merge.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6104774311 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3509#pullrequestreview-6104774311). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-29T20:58:36Z. **Review:** COMMENTED --- I checked this against #3457, which fixed the same race in the sibling `tests/startup_resource_retire.cpp`. It's the same pattern, and the added waits sit in the right places. `settle()` only resubmits the drain list, so without a queue wait a "freed" check can run before the release fence passes. I also agree that the "kept" checks get stronger, not weaker, and no assertion changes. On the claim that the added waits can't block: they can't, but the gated queue also waits on a gate in case 11 (`case11_inline_stale_descriptor_draw`, inline mode), not only in cases 1 and 2. That gate is signalled inside case 11 before it returns, and the cases run in a fixed order from `main()`, so no added wait can run while a gate is pending. Also, `Context::sync` times out and fails rather than hanging. The conclusion holds, and only the "cases 1 and 2" wording in the PR body is incomplete. Same caveat as #3457: without the debug layer, the mutation can't fail locally, so the proof against `hardware_debug1` is the CI failure plus the code argument. A full workflow run on the fork would exercise the `_debug1` variants on the runner, if you want that before merge. AI-assisted.
Leyukaka commented 2026-11-29 21:05:59 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T21:05:59Z.


Confirmed: case 11 also queues a gate wait on the gated queue (tests/startup_resource_retire_title.cpp:1110, signalled at :1147). The PR body now names cases 1, 2 and 11 with their lines; case 11 runs only in inline mode, where no added wait runs.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7262602583 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3509#issuecomment-7262602583). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-29T21:05:59Z. --- Confirmed: case 11 also queues a gate wait on the gated queue (`tests/startup_resource_retire_title.cpp:1110`, signalled at `:1147`). The PR body now names cases 1, 2 and 11 with their lines; case 11 runs only in inline mode, where no added wait runs.
lukaslw-lab commented 2026-11-30 08:08:23 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by lukaslw-lab on 2026-11-30T08:08:23Z.

Review: APPROVED


Reviewed 994a36e5 by reading the diff; not built or run.

Verdict: approve. The waits close the race in every retire check of this file. No MUST.

  • Checked every settle()/stays() that follows a c.release() in the file, not only the eight changed sites. Each one now runs after both guest queues are synced. Case 1 (:621, :638), case 2 T1 (:687) and case 11 (:1147) already synced gated after their gate signal, and direct through an earlier stays(). Case 7's final settle() (:1018) follows the loop at :995-:998, which now syncs both. No gap is left in this file.
  • Case 6: the one wait at :888 also covers Told, released at :869. heap.Reset() at :895 only drops the view reference, so the second settle() needs no extra wait. This agrees with the PR body.
  • The cited failure matches: run 46260430363 (push of #3439) fails startup_resource_retire_title_hardware_debug1 at stage newer wrapper retired with older SRV live, retained=131072/2 expected=65536/1, which is case 6.

Tests: the PR changes only the test file. Its CI ran only startup_resource_retire_title_inline_warp_debug0, and inline mode returns right after case 11 (:1467-:1474), so no changed line ran on CI. The /O2 job, the one that runs the _debug1 variants and caught the failure, was skipped on the PR. So the first real check is main's /O2 run after merge. The local 20x runs in the PR body cover the debug0 and off variants only.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6108668799 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3509#pullrequestreview-6108668799). Originally posted by [lukaslw-lab](https://github.com/lukaslw-lab) on 2026-11-30T08:08:23Z. **Review:** APPROVED --- Reviewed `994a36e5` by reading the diff; not built or run. **Verdict: approve.** The waits close the race in every retire check of this file. No MUST. - Checked every `settle()`/`stays()` that follows a `c.release()` in the file, not only the eight changed sites. Each one now runs after both guest queues are synced. Case 1 (`:621`, `:638`), case 2 T1 (`:687`) and case 11 (`:1147`) already synced `gated` after their gate signal, and `direct` through an earlier `stays()`. Case 7's final `settle()` (`:1018`) follows the loop at `:995`-`:998`, which now syncs both. No gap is left in this file. - Case 6: the one wait at `:888` also covers `Told`, released at `:869`. `heap.Reset()` at `:895` only drops the view reference, so the second `settle()` needs no extra wait. This agrees with the PR body. - The cited failure matches: run 46260430363 (push of #3439) fails `startup_resource_retire_title_hardware_debug1` at stage `newer wrapper retired with older SRV live`, `retained=131072/2 expected=65536/1`, which is case 6. Tests: the PR changes only the test file. Its CI ran only `startup_resource_retire_title_inline_warp_debug0`, and inline mode returns right after case 11 (`:1467`-`:1474`), so no changed line ran on CI. The `/O2` job, the one that runs the `_debug1` variants and caught the failure, was skipped on the PR. So the first real check is main's `/O2` run after merge. The local 20x runs in the PR body cover the debug0 and off variants only.
R0Y00 commented 2026-11-30 19:31:16 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-30T19:31:16Z.

Review: COMMENTED


The current head conflicts with main in tests/startup_resource_retire_title.cpp. #3542 already landed the direct and gated queue waits for the reported case 6 failure in 2e30cc59. Please rebase the remaining wait sites onto current main and keep the existing assertions. A fresh run of the affected retirement variants on that head would make the remaining test-only scope clear.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6119110444 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3509#pullrequestreview-6119110444). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-30T19:31:16Z. **Review:** COMMENTED --- The current head conflicts with `main` in `tests/startup_resource_retire_title.cpp`. #3542 already landed the direct and gated queue waits for the reported case 6 failure in `2e30cc59`. Please rebase the remaining wait sites onto current `main` and keep the existing assertions. A fresh run of the affected retirement variants on that head would make the remaining test-only scope clear.
R0Y00 commented 2026-12-02 05:46:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T05:46:25Z.

Review: COMMENTED


I merged main into the contributor branch. The only conflict was the comment above the case 6 wait that main already has. Kept the main explanation and all remaining waits from the PR. ctest --preset dev --no-tests=error -j 1 --repeat until-fail:3 -R '^startup_resource_retire_title_' --output-on-failure passed all 10 tests three times on Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, including the debug-layer on/off variants and inline paths. Please re-review the updated head.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6145413238 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3509#pullrequestreview-6145413238). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T05:46:25Z. **Review:** COMMENTED --- I merged main into the contributor branch. The only conflict was the comment above the case 6 wait that main already has. Kept the main explanation and all remaining waits from the PR. `ctest --preset dev --no-tests=error -j 1 --repeat until-fail:3 -R '^startup_resource_retire_title_' --output-on-failure` passed all 10 tests three times on Windows 11 26300.9974, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, including the debug-layer on/off variants and inline paths. Please re-review the updated head.
R0Y00 commented 2026-12-02 19:48:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-12-02T19:48:29Z.

Review: APPROVED


Reviewed 2667da0d against current main. The earlier independent review covers the remaining waits, and I verified the branch update resolved only the comment at the case 6 wait already on main. The remaining changes wait on the registered queues before the existing retained/freed assertions. Windows 11 build 26300 / MSVC Debug ctest --preset dev --no-tests=error -j 1 --repeat until-fail:2 --output-on-failure -R '^startup_resource_retire_title_' passed all ten tests twice, on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, including inline and debug-layer on/off cases.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6157765178 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3509#pullrequestreview-6157765178). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-12-02T19:48:29Z. **Review:** APPROVED --- Reviewed 2667da0d against current main. The earlier independent review covers the remaining waits, and I verified the branch update resolved only the comment at the case 6 wait already on main. The remaining changes wait on the registered queues before the existing retained/freed assertions. Windows 11 build 26300 / MSVC Debug `ctest --preset dev --no-tests=error -j 1 --repeat until-fail:2 --output-on-failure -R '^startup_resource_retire_title_'` passed all ten tests twice, on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656, including inline and debug-layer on/off cases.
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
R0Y00/Xbox2Windows!3509
No description provided.