Skip to content

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

Open
Leyukaka wants to merge 2 commits into
R0Y00:mainfrom
Leyukaka:tests-resource-retire-sync
Open

Leyukaka wants to merge 2 commits into
R0Y00:mainfrom
Leyukaka:tests-resource-retire-sync

Conversation

@Leyukaka

@Leyukaka Leyukaka commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

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 80ab69e (#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 994a36e on d3e306a, 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 d3e306a was not run separately.

@Not-Saii Not-Saii left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator Author

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 lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
R0Y00 requested a review from lukaslw-lab December 2, 2026 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants