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

Open
github-bot wants to merge 1 commit from github-bot/gh-132 into main AGit
Owner

@⁠adritoyalser on GitHub · 2026-11-25 15:31 UTC · original
adritoyalser:fix/timeline-submit-wait-busy → main · +130 −17 · 1 files · 1 commits · open

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.
**@⁠adritoyalser** on GitHub · 2026-11-25 15:31 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/132) `adritoyalser:fix/timeline-submit-wait-busy` → `main` · +130 −17 · 1 files · 1 commits · open ## 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`**.
`Timeline::submit` and `fence::signal` rely on `timeline::pump` running
all unblocked queue work before returning, but `Timeline::step` returned
immediately when another thread (the `victory-queues` watcher or another
submitting thread) held `busy == true` on a queue. As a result, a submit
or signal could return while its own work (or cross-queue work it just
unblocked) was still mid-flight on another thread.

- Add a `Condvar` (`done`) on `Timeline` and an RAII `BusyGuard` that
  always clears `busy`, notifies waiters, and maintains a thread-local
  `STEPPING` nesting depth (even on unwind).
- Have `Timeline::step` return `Step::{Idle, Moved, Busy}` so `pump`
  continues stepping any non-busy queues first, then waits on the first
  busy queue via `wait_not_busy()` and re-checks until all ready work
  has completed.
- Skip waiting when called re-entrantly from inside `Timeline::step`
  (`STEPPING > 0`, preventing self-deadlock) or from the background
  `victory-queues` watcher (`pump_inner(false)`).
- Add unit tests for concurrent submit-while-busy and re-entrant submit.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:36:22 +00:00
Author
Owner

@⁠Adika713 on GitHub · 2026-11-25 15:49 UTC · original

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.

**@⁠Adika713** on GitHub · 2026-11-25 15:49 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/132#issuecomment-7167342427) 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.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 18:57 UTC · original

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.

**@⁠adrianmjim** on GitHub · 2026-11-25 18:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/132#issuecomment-7171623980) 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.
Author
Owner

@⁠battledogegames-design on GitHub · 2026-11-25 21:35 UTC · original

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

**@⁠battledogegames-design** on GitHub · 2026-11-25 21:35 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/132#issuecomment-7175269393) ### 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 can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/132/head:github-bot/gh-132'
git switch 'github-bot/gh-132'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-132'
git switch 'github-bot/gh-132'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-132'
git switch 'github-bot/gh-132'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-132'
git switch 'main'
git merge --squash 'github-bot/gh-132'
git switch 'main'
git merge --ff-only 'github-bot/gh-132'
git switch 'main'
git merge 'github-bot/gh-132'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.