wait_fence waits for the card without holding the submission lock (#163) #258

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

@⁠ySKELLETONX on GitHub · 2026-11-26 13:41 UTC · original
ySKELLETONX:perf/wait-fence-unlocked → main · +98 −8 · 1 files · 1 commits · open

Host::wait_fence took submitted and then blocked in WaitForSingleObject until the card reached the value. Lists reset or dropped on the title's recording threads (HostList::reset, Drop) and the timeline's signals (wait_in_flight) come here, so while one of them waited, every other submission, and the prewarm that is meant to overlap the card, stood at execute_inner's lock for as long as the card ran. The profile in #163 put 12% of the submitting thread in Mutex::lock_contended on it.

What changes (crates/victory-gpu/src/host.rs only)

  • The card is waited for on an event of the waiting thread's own (thread-local, auto-reset, closed at thread exit), without submitted.
  • submitted is taken afterwards only for reap_completed, so what a caller sees when wait_fence returns is the same: the submissions up to the value are finished.
  • If another thread finished them meanwhile (FINISHED_FENCE >= target), the lock is not taken at all.
  • Without an event of its own (creation or SetEventOnCompletion fails), the wait falls back to the shared event under the lock, as before.
  • execute_inner and drain_in_flight_locked still wait under the lock on the shared event; nothing there changes.

Test host::tests::waiting_for_the_card_leaves_submitted_free (WARP, no game data): the card signals the value only after the processor opens a gate fence, and another thread must take submitted while the wait goes on. It fails on the old code ( `submitted` stayed held while a thread waited for the card) and passes 20/20 with this change.

  • cargo test -p victory-gpu --lib --locked, 20 full runs: 114 passed, apart from two flaky tests that don't touch this code: watch::written_pages_are_reported_to_every_asker (also fails on main, #102, fixed by #115) and once frame::waits_end_on_ticks_and_count_frames (asserts a wait ends within 50 ms; frame.rs doesn't use the host).
  • cargo xtask policy --staged: ok

Tested on Ryzen 7 5700X3D + RX 7600 XT, Windows 11. I can't measure it in the world; @⁠ThiagoTodeschini, if you get the chance, the same spot as in #163 with and without this would show how much of the 12% it gives back. Independent of #253.

**@⁠ySKELLETONX** on GitHub · 2026-11-26 13:41 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/258) `ySKELLETONX:perf/wait-fence-unlocked` → `main` · +98 −8 · 1 files · 1 commits · open `Host::wait_fence` took `submitted` and then blocked in `WaitForSingleObject` until the card reached the value. Lists reset or dropped on the title's recording threads (`HostList::reset`, `Drop`) and the timeline's signals (`wait_in_flight`) come here, so while one of them waited, every other submission, and the `prewarm` that is meant to overlap the card, stood at `execute_inner`'s lock for as long as the card ran. The profile in #163 put 12% of the submitting thread in `Mutex::lock_contended` on it. **What changes** (`crates/victory-gpu/src/host.rs` only) - The card is waited for on an event of the waiting thread's own (thread-local, auto-reset, closed at thread exit), without `submitted`. - `submitted` is taken afterwards only for `reap_completed`, so what a caller sees when `wait_fence` returns is the same: the submissions up to the value are finished. - If another thread finished them meanwhile (`FINISHED_FENCE >= target`), the lock is not taken at all. - Without an event of its own (creation or `SetEventOnCompletion` fails), the wait falls back to the shared event under the lock, as before. - `execute_inner` and `drain_in_flight_locked` still wait under the lock on the shared event; nothing there changes. **Test** `host::tests::waiting_for_the_card_leaves_submitted_free` (WARP, no game data): the card signals the value only after the processor opens a gate fence, and another thread must take `submitted` while the wait goes on. It fails on the old code (`` `submitted` stayed held while a thread waited for the card``) and passes 20/20 with this change. - `cargo test -p victory-gpu --lib --locked`, 20 full runs: 114 passed, apart from two flaky tests that don't touch this code: `watch::written_pages_are_reported_to_every_asker` (also fails on `main`, #102, fixed by #115) and once `frame::waits_end_on_ticks_and_count_frames` (asserts a wait ends within 50 ms; `frame.rs` doesn't use the host). - `cargo xtask policy --staged`: ok Tested on Ryzen 7 5700X3D + RX 7600 XT, Windows 11. I can't measure it in the world; @⁠ThiagoTodeschini, if you get the chance, the same spot as in #163 with and without this would show how much of the 12% it gives back. Independent of #253.
Host::wait_fence took `submitted` and then blocked in WaitForSingleObject
until the card reached the value. Lists reset or dropped on the title's
recording threads and the timeline's signals come here, so while one of
them waited, every other submission (and the prewarm that is meant to
overlap the card) stood at execute_inner's lock for as long as the card
ran. The profile in #163 put 12% of the submitting thread in
Mutex::lock_contended on it.

The card is now waited for on an event of the waiting thread's own
(thread-local, auto-reset, closed at thread exit), and `submitted` is
taken afterwards only for reap_completed. If another thread finished the
submissions up to the value meanwhile (FINISHED_FENCE), the lock is not
taken at all. Without an event of its own (creation or
SetEventOnCompletion fails) the wait falls back to the shared event under
the lock, as before. execute_inner and drain_in_flight_locked still wait
under the lock on the shared event; nothing there changes.

New test waiting_for_the_card_leaves_submitted_free (WARP): the card
signals the value only after the processor opens a gate fence; another
thread must take `submitted` while the wait goes on. It fails on the old
code ("`submitted` stayed held") and passes 20/20 with this change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 13:43:58 +00:00
This pull request can be merged automatically.
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/258/head:github-bot/gh-258'
git switch 'github-bot/gh-258'

Merge

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