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

Open
ySKELLETONX wants to merge 1 commit from upstream-pr/258 into main
ySKELLETONX commented 2026-11-26 13:41:10 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ySKELLETONX on 2026-11-26T13:41:10Z.


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.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:6627916770 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/258). Originally posted by [ySKELLETONX](https://github.com/ySKELLETONX) on 2026-11-26T13:41:10Z. --- `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.
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/258:upstream-pr/258'
git switch 'upstream-pr/258'

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