WIP: perf(vk): with the render thread, a fence of one queue waits for that queue's work, not for other queues' stopped work #2648

Draft
Veix wants to merge 2 commits from Veix/Longshot:perf/render-thread-queue-fences into main
Member

Summary

With the render thread, a fence of one queue waits for that queue's work, as it does without the render thread since 8c28ed70, instead of for every queue's work up to it, which another queue's stopped submission held back. (The result line is to be written from the measurements of this head.)

NVN's fences are per queue (nvnQueueFenceSync covers the work submitted to that queue). Without the render thread the replay keeps that since 8c28ed70: fence_q gives the queue's last submission, and a wait for it waits for the recording that submission was finished in (wait_recorded). With the render thread, the default since #588, fence_q gave the newest submission of any queue, and the wait went to the shared timeline, which signals a value only once no older submission of any queue is stopped at an event wait. OoT's main thread waits every frame for a fence of one of its queues, while the presentation queues' submissions stop at an event wait until the main thread's CPU signal: its wait then included their stopped work.

What this changes (render thread only; without it nothing changes):

  • fence_q: the queue's own last submission, as enqueue numbers it (q_own, a leaf lock), or the last present's value if that is newer. A present carries no queue, and a fence taken after it covers it, as on main.
  • wait_inner: wait_own_recording waits for the recording the value was finished in (value_rec, woken by rec_map_cv), or until the shared timeline passes the value, within the wait's time. Neither within it: the shared timeline, as before.
  • RX_VK_PER_QUEUE_FENCES=0 (the existing switch) gives the old behaviour in both modes.

Prior work: #2212 (siantm, closed on 2026-11-24) made the same change behind RX_VK_ASYNC_FENCES, built on #2211's wait for a queue; it was closed with #2211, which was withdrawn. Its review (dazemc) found that a fence taken after a present must cover the present; this pull request does that. Its measurements showed no gain on the Test Farm and a worse tail in one CPU-paced sitting on an RTX 4060 (p99 17.7 -> 21.3 ms, cause not found). This one waits on the existing recording map instead of #2211's wait. Related: #2523 (neotoxic, WIP) changes the fence poll without the render thread; no overlap in behaviour, its hunk is next to this one.

Read first: fence_q and wait_own_recording in gpu/vk/vk_replay.cpp, then tests/test_render_thread_queue_fences.py.

Testing

Tested: Windows 11, Ryzen 9 9900X, RTX 4070 SUPER 12 GB, driver 621.24, on main @ 9eabf8bc. tests/test_render_thread_queue_fences.py (new) cuts fence_q, wait_own_recording and enqueue's notes out of gpu/vk/vk_replay.cpp and runs them against stand-ins for the queues and both timelines: it fails on main (a fence of the scene queue is the newest submission of any queue, and its wait waits for the shared timeline) and passes here, with clang++ and g++; undoing either the queue's own value or the own wait makes it fail. The checks that read the changed files (python -I -B tests/run_all.py --changed origin/main): the 2 that fail (test_dev_ab, test_input_movie) fail the same way on main @ 9eabf8bc on this PC. The renderer builds.

What this head is, against what was measured before it: the change was first measured as a proof of concept, together with other changes. This head differs from that proof of concept in more than one way, so a result that differs from it has more than one candidate:

  1. The wait: the proof of concept noted its own table of "recorded whole" values (the recording expected next) and waited up to 1 s for a value to appear in it; this head waits on the existing recording map (value_rec, filled when the recording is submitted) and polls the shared timeline each 1 ms, within the wait's time.
  2. The present: the proof of concept gave a fence only the queue's last submission; this head gives the last present's value if that is newer (the review point of #2212). In the proof of concept's runs (the walking route's second Castle Town stay, two runs, 3,600 fences) no fence was taken after a newer present, so for OoT there this rule is expected to change nothing.
  3. The fence's own value is kept under its own lock in enqueue in both; the proof of concept also kept it when RX_VK_PER_QUEUE_FENCES=0.

Still to test:

  • In the game at this head against main, alone (no other change): the recorded routes, frame pacing and the host's GPU-wait line, CPU-bound and GPU-bound (by hand)
  • A count of the waits that took the own-recording path, and of the fences the present rule raised (by hand)
  • The tail #2212 saw: frames of 50 ms or more and p99 against main (by hand)
  • AMD and Intel cards, a Steam Deck (no mirrors: the render thread is off there by default; with it forced on): the same picture as main, no hang (@Beanstalk or by hand)
  • Linux: the build and the check (by hand)

Measurements

(To be measured at this head against main @ 9eabf8bc.)

Risks

  • A fence wait that returns before its queue's work is done would let the game reuse memory the GPU still reads (a flicker, a wrong frame). The wait is for the recording its submission was finished in, on the recordings' timeline, as without the render thread; the shared timeline is still waited for when the recording is not found within the wait's time. RX_VK_PER_QUEUE_FENCES=0 gives main's behaviour.
  • Nothing changes in saves, longshot_options.ini or the caches.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A fix: a game-free test that fails on main and passes here.
  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

This pull request was written with the help of Claude (an AI assistant).

## Summary **With the render thread, a fence of one queue waits for that queue's work, as it does without the render thread since 8c28ed70, instead of for every queue's work up to it, which another queue's stopped submission held back.** (The result line is to be written from the measurements of this head.) NVN's fences are per queue (`nvnQueueFenceSync` covers the work submitted to that queue). Without the render thread the replay keeps that since 8c28ed70: `fence_q` gives the queue's last submission, and a wait for it waits for the recording that submission was finished in (`wait_recorded`). With the render thread, the default since #588, `fence_q` gave the newest submission of any queue, and the wait went to the shared timeline, which signals a value only once no older submission of any queue is stopped at an event wait. OoT's main thread waits every frame for a fence of one of its queues, while the presentation queues' submissions stop at an event wait until the main thread's CPU signal: its wait then included their stopped work. What this changes (render thread only; without it nothing changes): - `fence_q`: the queue's own last submission, as `enqueue` numbers it (`q_own`, a leaf lock), or the last present's value if that is newer. A present carries no queue, and a fence taken after it covers it, as on `main`. - `wait_inner`: `wait_own_recording` waits for the recording the value was finished in (`value_rec`, woken by `rec_map_cv`), or until the shared timeline passes the value, within the wait's time. Neither within it: the shared timeline, as before. - `RX_VK_PER_QUEUE_FENCES=0` (the existing switch) gives the old behaviour in both modes. **Prior work:** #2212 (siantm, closed on 2026-11-24) made the same change behind `RX_VK_ASYNC_FENCES`, built on #2211's wait for a queue; it was closed with #2211, which was withdrawn. Its review (dazemc) found that a fence taken after a present must cover the present; this pull request does that. Its measurements showed no gain on the Test Farm and a worse tail in one CPU-paced sitting on an RTX 4060 (p99 17.7 -> 21.3 ms, cause not found). This one waits on the existing recording map instead of #2211's wait. Related: #2523 (neotoxic, WIP) changes the fence poll without the render thread; no overlap in behaviour, its hunk is next to this one. Read first: `fence_q` and `wait_own_recording` in `gpu/vk/vk_replay.cpp`, then `tests/test_render_thread_queue_fences.py`. ## Testing **Tested:** Windows 11, Ryzen 9 9900X, RTX 4070 SUPER 12 GB, driver 621.24, on `main` @ 9eabf8bc. `tests/test_render_thread_queue_fences.py` (new) cuts `fence_q`, `wait_own_recording` and `enqueue`'s notes out of `gpu/vk/vk_replay.cpp` and runs them against stand-ins for the queues and both timelines: it fails on `main` (a fence of the scene queue is the newest submission of any queue, and its wait waits for the shared timeline) and passes here, with clang++ and g++; undoing either the queue's own value or the own wait makes it fail. The checks that read the changed files (`python -I -B tests/run_all.py --changed origin/main`): the 2 that fail (test_dev_ab, test_input_movie) fail the same way on `main` @ 9eabf8bc on this PC. The renderer builds. **What this head is, against what was measured before it:** the change was first measured as a proof of concept, together with other changes. This head differs from that proof of concept in more than one way, so a result that differs from it has more than one candidate: 1. The wait: the proof of concept noted its own table of "recorded whole" values (the recording expected next) and waited up to 1 s for a value to appear in it; this head waits on the existing recording map (`value_rec`, filled when the recording is submitted) and polls the shared timeline each 1 ms, within the wait's time. 2. The present: the proof of concept gave a fence only the queue's last submission; this head gives the last present's value if that is newer (the review point of #2212). In the proof of concept's runs (the walking route's second Castle Town stay, two runs, 3,600 fences) no fence was taken after a newer present, so for OoT there this rule is expected to change nothing. 3. The fence's own value is kept under its own lock in `enqueue` in both; the proof of concept also kept it when `RX_VK_PER_QUEUE_FENCES=0`. **Still to test:** - In the game at this head against `main`, alone (no other change): the recorded routes, frame pacing and the host's GPU-wait line, CPU-bound and GPU-bound (by hand) - A count of the waits that took the own-recording path, and of the fences the present rule raised (by hand) - The tail #2212 saw: frames of 50 ms or more and p99 against `main` (by hand) - AMD and Intel cards, a Steam Deck (no mirrors: the render thread is off there by default; with it forced on): the same picture as `main`, no hang (@Beanstalk or by hand) - Linux: the build and the check (by hand) ## Measurements (To be measured at this head against `main` @ 9eabf8bc.) ## Risks - A fence wait that returns before its queue's work is done would let the game reuse memory the GPU still reads (a flicker, a wrong frame). The wait is for the recording its submission was finished in, on the recordings' timeline, as without the render thread; the shared timeline is still waited for when the recording is not found within the wait's time. `RX_VK_PER_QUEUE_FENCES=0` gives `main`'s behaviour. - Nothing changes in saves, `longshot_options.ini` or the caches. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [ ] Tested on my own PC, in the game for a change the game runs, as Testing says. - [ ] `mise run test` passes (any failure that also fails on `main` is named). - [ ] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A fix: a game-free test that fails on `main` and passes here. - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. This pull request was written with the help of Claude (an AI assistant).
tests/test_render_thread_queue_fences.py cuts fence_q, the render thread's wait for a
queue's own recording and enqueue's note of a queue's value out of gpu/vk/vk_replay.cpp
and runs them against stand-ins for the queues and the two timelines. On main it fails:
with the render thread a fence of the scene queue is the newest submission of any queue,
and its wait has no step of its own, so it waits for the shared timeline, which another
queue's stopped submission holds back.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
perf(vk): with the render thread, a fence of one queue waits for that queue's work, not for other queues' stopped work
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 23s
22d3bee724
NVN's fences are per queue. Without the render thread the replay keeps that since
8c28ed70: a fence is its queue's last submission, and a wait for it waits for the
recording that submission was finished in. With the render thread (the default since
#588) a fence was the newest submission of any queue, and a wait for it waited for the
shared timeline, which signals a value only once no older submission of any queue is
stopped at an event wait.

- fence_q: with the render thread, the queue's own last value, as enqueue numbers its
  submits (q_own, a leaf lock), or the last present's if that is newer: a present carries
  no queue, and a fence taken after it covers it, as on main.
- wait_inner: with the render thread, wait_own_recording waits for the recording the
  value was finished in (value_rec, woken by rec_map_cv), or until the shared timeline
  passes the value, within the wait's time; neither within it: the shared timeline, as
  before.
- RX_VK_PER_QUEUE_FENCES=0 gives the old behaviour in both modes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 23s
This pull request has changes conflicting with the target branch.
  • gpu/vk/switches.def
Some workflows are waiting to be reviewed.
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'perf/render-thread-queue-fences:Veix-perf/render-thread-queue-fences'
git switch 'Veix-perf/render-thread-queue-fences'
Sign in to join this conversation.
No reviewers
No milestone
No project
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.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2648
No description provided.