timeline: wait for busy queues to finish before pump/submit returns (#116) #132

Open
adritoyalser wants to merge 1 commit from upstream-pr/132 into main
adritoyalser commented 2026-11-25 15:31:46 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adritoyalser on 2026-11-25T15:31:46Z.


Summary

Fixes #116 (implements Option 1 cleanly with a Condvar + RAII guard).

Root Cause

Timeline::submit (and fence::signal) call timeline::pump(), which steps every queue. When another thread (either the victory-queues watcher thread or another concurrent submitting thread) is already mid-step on a queue (s.busy == true), Timeline::step returned false immediately, letting submit() / pump() return while ready work on that queue — or cross-queue work just unblocked by a Signal — was still running on the other thread.

Changes

  • crates/victory-gpu/src/timeline.rs:
    • Added done: Condvar to Timeline and an RAII BusyGuard that tracks a thread-local STEPPING nesting depth, clears s.busy, and calls done.notify_all() on drop (including unwinds).
    • Changed Timeline::step to return Step::{Idle, Moved, Busy}.
    • Updated pump() (pump_inner(true)) to step all non-busy queues first, and if no queue moved while one is Busy (and STEPPING == 0), wait on queue.wait_not_busy() before re-pumping until every ready op across all queues has finished.
    • Kept the background victory-queues watcher non-blocking (pump_inner(false)).
    • Added regression tests submit_waits_for_busy_queue_on_another_thread and reentrant_submit_inside_work_does_not_deadlock.

Verification

  • Before fix (01aadd1): running the victory-gpu test binary on query:: queue:: failed 24 / 30 runs (page_mappings_run_after_a_queues_wait at queue.rs:935, present_runs_after_a_queues_wait at queue.rs:834).
  • After fix:
    • timeline:: tests: 4 passed, 0 failed.
    • query:: queue:: stress test: 0 failures in 50 / 50 runs.
    • cargo clippy -q -p victory-gpu --lib --tests --locked --no-deps: 0 warnings in timeline.rs.
<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6608026929 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/132). Originally posted by [adritoyalser](https://github.com/adritoyalser) on 2026-11-25T15:31:46Z. --- ## Summary Fixes #116 (implements Option 1 cleanly with a `Condvar` + RAII guard). ### Root Cause `Timeline::submit` (and `fence::signal`) call `timeline::pump()`, which steps every queue. When another thread (either the `victory-queues` watcher thread or another concurrent submitting thread) is already mid-step on a queue (`s.busy == true`), `Timeline::step` returned `false` immediately, letting `submit()` / `pump()` return while ready work on that queue — or cross-queue work just unblocked by a `Signal` — was still running on the other thread. ### Changes - **`crates/victory-gpu/src/timeline.rs`**: - Added `done: Condvar` to `Timeline` and an RAII `BusyGuard` that tracks a thread-local `STEPPING` nesting depth, clears `s.busy`, and calls `done.notify_all()` on drop (including unwinds). - Changed `Timeline::step` to return `Step::{Idle, Moved, Busy}`. - Updated `pump()` (`pump_inner(true)`) to step all non-busy queues first, and if no queue moved while one is `Busy` (and `STEPPING == 0`), wait on `queue.wait_not_busy()` before re-pumping until every ready op across all queues has finished. - Kept the background `victory-queues` watcher non-blocking (`pump_inner(false)`). - Added regression tests `submit_waits_for_busy_queue_on_another_thread` and `reentrant_submit_inside_work_does_not_deadlock`. ## Verification - **Before fix (`01aadd1`):** running the `victory-gpu` test binary on `query:: queue::` failed **24 / 30 runs** (`page_mappings_run_after_a_queues_wait` at `queue.rs:935`, `present_runs_after_a_queues_wait` at `queue.rs:834`). - **After fix:** - `timeline::` tests: **4 passed, 0 failed**. - `query:: queue::` stress test: **0 failures in 50 / 50 runs**. - `cargo clippy -q -p victory-gpu --lib --tests --locked --no-deps`: **0 warnings in `timeline.rs`**.
Adika713 commented 2026-11-25 15:49:17 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by Adika713 on 2026-11-25T15:49:17Z.


Verified on AMD Radeon RX 6950 XT, Ryzen 5 3600, 32 GB RAM, Windows 11,
Rust 1.98.1 / Cargo 1.98.1. No game data; the title was not run.

I used the focused filters from #116 because full-lib serial runs on this
machine mostly hit the separate #102 watch flake
(watch::tests::written_pages_are_reported_to_every_asker: 15/20 runs).
Each tree used an isolated CARGO_TARGET_DIR.

Before, at upstream/main 01aadd193d57e71fb4d57810eb2fdd1bc95c950b, from
F:\VIctory-Belobug-AMD with CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-gpu-main-verify:

cargo test -p victory-gpu --lib -- queue:: query::

50 runs: 26 runs exited nonzero, including 2 hard exits with code
-1073740791 and no test-result line. The 24 runs that reported a result
gave these failing test counts:

  • queue::tests::page_mappings_run_after_a_queues_wait: 10
  • queue::tests::present_runs_after_a_queues_wait: 10
  • queue::tests::queue_signals_complete_at_once: 7
  • queue::tests::work_after_a_wait_runs_once_the_other_queue_signals: 5

I did not see the query-named failures from #116 in this 50-run sample.

After, at PR head 62aad1f, from a detached worktree at
F:\VIctory-Belobug-AMD\_agent_tmp\pr-132 with
CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-pr132-verify:

cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-132\Cargo.toml -p victory-gpu --lib -- queue:: query::
cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-132\Cargo.toml -p victory-gpu timeline:: -- --test-threads=1
  • Same 50 runs: 0 nonzero exits, 0 crashes; every run gave
    test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 105 filtered out.
  • timeline::: test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 113 filtered out.

Overlap: PR #109 head 6febfef also touches timeline.rs, but with the same
focused command it still failed 19/30 runs (1 hard exit), with the same four
queue tests. I wrote no competing fix.

Not tested: the game, or the full workspace suite after this PR.

AI-assisted: OpenCode, model Big Pickle. No game data.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7167342427 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/132#issuecomment-7167342427). Originally posted by [Adika713](https://github.com/Adika713) on 2026-11-25T15:49:17Z. --- Verified on AMD Radeon RX 6950 XT, Ryzen 5 3600, 32 GB RAM, Windows 11, Rust 1.98.1 / Cargo 1.98.1. No game data; the title was not run. I used the focused filters from #116 because full-lib serial runs on this machine mostly hit the separate #102 watch flake (`watch::tests::written_pages_are_reported_to_every_asker`: 15/20 runs). Each tree used an isolated `CARGO_TARGET_DIR`. Before, at `upstream/main` `01aadd193d57e71fb4d57810eb2fdd1bc95c950b`, from `F:\VIctory-Belobug-AMD` with `CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-gpu-main-verify`: ```powershell cargo test -p victory-gpu --lib -- queue:: query:: ``` 50 runs: **26 runs exited nonzero**, including 2 hard exits with code `-1073740791` and no test-result line. The 24 runs that reported a result gave these failing test counts: - `queue::tests::page_mappings_run_after_a_queues_wait`: 10 - `queue::tests::present_runs_after_a_queues_wait`: 10 - `queue::tests::queue_signals_complete_at_once`: 7 - `queue::tests::work_after_a_wait_runs_once_the_other_queue_signals`: 5 I did not see the query-named failures from #116 in this 50-run sample. After, at PR head `62aad1f`, from a detached worktree at `F:\VIctory-Belobug-AMD\_agent_tmp\pr-132` with `CARGO_TARGET_DIR=F:\VIctory-Belobug-AMD\_agent_tmp\target-pr132-verify`: ```powershell cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-132\Cargo.toml -p victory-gpu --lib -- queue:: query:: cargo test --manifest-path F:\VIctory-Belobug-AMD\_agent_tmp\pr-132\Cargo.toml -p victory-gpu timeline:: -- --test-threads=1 ``` - Same 50 runs: **0 nonzero exits, 0 crashes**; every run gave `test result: ok. 12 passed; 0 failed; 0 ignored; 0 measured; 105 filtered out`. - `timeline::`: `test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 113 filtered out`. Overlap: PR #109 head `6febfef` also touches `timeline.rs`, but with the same focused command it still failed 19/30 runs (1 hard exit), with the same four queue tests. I wrote no competing fix. Not tested: the game, or the full workspace suite after this PR. AI-assisted: OpenCode, model Big Pickle. No game data.
adrianmjim commented 2026-11-25 18:57:09 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by adrianmjim on 2026-11-25T18:57:09Z.


RDNA3 data to go with the RX 6950 XT numbers above. RX 7900 XT, driver 32.0.32029.2010, Windows 11 build 26300, Rust 1.98.1. No game data, title not run. The lib test binary was run directly, interleaved with main 01aadd1 under the same load (another GPU job was running).

  • victory_gpu-*.exe queue:: query::, default threads, 60 runs each:
    • main: 45/60 runs failed. Per test: queue_signals_complete_at_once 21, page_mappings_run_after_a_queues_wait 16, present_runs_after_a_queues_wait 13, work_after_a_wait_runs_once_the_other_queue_signals 8, occlusion_queries_around_draws_not_run_stay_visible 2. Two of the main runs ended with no test-result line right after the occlusion query failure.
    • this PR (62aad1f): 0/60.
    • this PR together with #112 and #115: 0/40.
  • Full lib, default threads: queue/query failures are rare here even on main (2/80), and this PR had 0/40, so this alone says little. The two new timeline:: tests passed in every full-lib run on this tree (55) and on the combined tree (55).
  • No hangs. Mean full-lib time was 2.91 s on this PR vs 2.88 s on main.

No new failures. The other failures on this tree also happen on main: #102 (this PR does not touch it), frame::tests::waits_end_on_ticks_and_count_frames, and three guarded-view watch::tests. A few full-lib runs ended without a result line. They happened on trees without this PR too, so I can't tie them to it.

Not tested: the title.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7171623980 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/132#issuecomment-7171623980). Originally posted by [adrianmjim](https://github.com/adrianmjim) on 2026-11-25T18:57:09Z. --- RDNA3 data to go with the RX 6950 XT numbers above. RX 7900 XT, driver 32.0.32029.2010, Windows 11 build 26300, Rust 1.98.1. No game data, title not run. The lib test binary was run directly, interleaved with main `01aadd1` under the same load (another GPU job was running). - `victory_gpu-*.exe queue:: query::`, default threads, 60 runs each: - main: 45/60 runs failed. Per test: `queue_signals_complete_at_once` 21, `page_mappings_run_after_a_queues_wait` 16, `present_runs_after_a_queues_wait` 13, `work_after_a_wait_runs_once_the_other_queue_signals` 8, `occlusion_queries_around_draws_not_run_stay_visible` 2. Two of the main runs ended with no test-result line right after the occlusion query failure. - this PR (`62aad1f`): 0/60. - this PR together with #112 and #115: 0/40. - Full lib, default threads: queue/query failures are rare here even on main (2/80), and this PR had 0/40, so this alone says little. The two new `timeline::` tests passed in every full-lib run on this tree (55) and on the combined tree (55). - No hangs. Mean full-lib time was 2.91 s on this PR vs 2.88 s on main. No new failures. The other failures on this tree also happen on main: #102 (this PR does not touch it), `frame::tests::waits_end_on_ticks_and_count_frames`, and three guarded-view `watch::tests`. A few full-lib runs ended without a result line. They happened on trees without this PR too, so I can't tie them to it. Not tested: the title.
battledogegames-design commented 2026-11-25 21:35:01 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by battledogegames-design on 2026-11-25T21:35:01Z.


Deterministic regression test for busy-queue submit completion

Thanks for the queue-completion fix. I tested a small change to its regression coverage. If the second submitter is descheduled throughout the current 30 ms sleep, the first callback can finish before the second submission begins. Both assertions can then pass on an uncontended queue.

The replacement holds the first callback on a channel and observes the second submitter encountering that same queue busy. All 20 controlled runs recorded both completion bits in one load immediately after submit returned, joined the worker, and checked the saved snapshot. Cleanup cannot change that snapshot.

Tested revision Result
Original main at 01aadd1 10/10 returned with neither callback complete, triggering the expected assertion
PR head 62aad1f 10/10 returned with both callbacks complete
Existing reentrant submission test on the PR Passed separately

On the PR, a test-only hook releases the worker when the submitter commits to waiting under the queue mutex. A different waiting mechanism would need an equivalent observation point. Production queue behavior is unchanged. Validation covered these synthetic tests only. The full workspace suite, independent-queue latency, physical-GPU behavior, and game execution remain untested here.

The ZIP includes pr.patch, the baseline comparison, reproduction commands, and all 21 logs. Would you prefer to integrate the test into this PR or receive a separate test-only PR?

issue-116-maintainer-review.zip

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7175269393 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/132#issuecomment-7175269393). Originally posted by [battledogegames-design](https://github.com/battledogegames-design) on 2026-11-25T21:35:01Z. --- ### Deterministic regression test for busy-queue submit completion Thanks for the queue-completion fix. I tested a small change to its regression coverage. If the second submitter is descheduled throughout the current 30 ms sleep, the first callback can finish before the second submission begins. Both assertions can then pass on an uncontended queue. The replacement holds the first callback on a channel and observes the second submitter encountering that same queue busy. All 20 controlled runs recorded both completion bits in one load immediately after `submit` returned, joined the worker, and checked the saved snapshot. Cleanup cannot change that snapshot. | Tested revision | Result | | --- | --- | | Original main at `01aadd1` | 10/10 returned with neither callback complete, triggering the expected assertion | | PR head `62aad1f` | 10/10 returned with both callbacks complete | | Existing reentrant submission test on the PR | Passed separately | On the PR, a test-only hook releases the worker when the submitter commits to waiting under the queue mutex. A different waiting mechanism would need an equivalent observation point. Production queue behavior is unchanged. Validation covered these synthetic tests only. The full workspace suite, independent-queue latency, physical-GPU behavior, and game execution remain untested here. The ZIP includes `pr.patch`, the baseline comparison, reproduction commands, and all 21 logs. Would you prefer to integrate the test into this PR or receive a separate test-only PR? [issue-116-maintainer-review.zip](https://github.com/user-attachments/files/35434523/issue-116-maintainer-review.zip)
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/132:upstream-pr/132'
git switch 'upstream-pr/132'

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/132'
git switch 'upstream-pr/132'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/132'
git switch 'upstream-pr/132'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/132'
git switch 'main'
git merge --squash 'upstream-pr/132'
git switch 'main'
git merge --ff-only 'upstream-pr/132'
git switch 'main'
git merge 'upstream-pr/132'
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
Belobug/VIctory-Belobug-AMD!132
No description provided.