Queued presents: the title's present goes into its queue's line and returns; our thread shows the frame in order, at most N waiting (VICTORY_PRESENT_QUEUED=1|2, off by default) #1136

Open
github-bot wants to merge 2 commits from github-bot/gh-1136 into main AGit
Owner

@⁠exotiquee on GitHub · 2026-11-25 21:23 UTC · original
exotiquee:pr/present-queued → main · +1050 −102 · 2 files · 2 commits · open

Branch pr/present-queued on main c36971b, two commits:

  1. Queues' lines walked through a trait (no behaviour change). This is the minimal prerequisite. release_held_now's loop becomes walk(&Queues, all, joining) over a small Lines trait. The trait covers the lines, fences, memory values, the host's send / run / present, and signals. Queues is the code that was inline, unchanged, diagnostics included. Tests can now run the walk on lines of their own and record what left them, in which order.
  2. Queued presents (VICTORY_PRESENT_QUEUED=1|2).

Why this is not VICTORY_ASYNC_PRESENT

The README notes that putting presents behind the line changed nothing. VICTORY_ASYNC_PRESENT=1 lets only one present wait behind the line: the next present finds it still there and runs the lines on the title's thread the old way, so the title still stands at every second present, and the other queues are not ordered behind the frame. This change lets up to N presents wait (marks in every other line keep the frame order) and never runs the lines on the title's thread; the measured present wait below is the difference.

What it does

With VICTORY_ASYNC_SUBMIT=1 + VICTORY_JOIN_PARTS=1, a profile showed the title's render thread on a processor only 4 % of the time. It stood about 42 ms of each frame in present -> present_now -> release_held_now -> the one-releaser lock. The present ran the lines itself, so it waited until our thread had prepared and sent the whole frame. Our thread meanwhile sat idle about as long (39 ms a frame in queue::worker). The two threads took turns.

With VICTORY_PRESENT_QUEUED=N:

  • The present call. queue_present puts a mark (Held::Mark(frame)) into every other line that holds anything. It then puts Held::Present into the present's own line, wakes the worker and returns. If N presents are already in the lines, the call stands until the oldest has been shown (a SHOWN condvar, like a swap chain's frame latency).
  • The walk (with marks):
    • What is ahead of a present or mark runs first, free things first.
    • Once nothing else moves, waits ahead of a present or mark are passed. This is the old present's forced release (forces()).
    • The present runs once every other line has reached its mark of that frame.
    • A mark is passed once its frame has been shown. So what the title gave after the present runs after the frame, as when the present ran the lines itself.
    • Signals keep their lines' order and go behind the flights as before.
  • Unchanged paths. Saved or listed frames (diagnostics) run the old way. VICTORY_ASYNC_PRESENT=1 is left as it was.
  • Log line. Every 256 frames: presents queued / the old way, the title's present calls in ms a frame and how much of that waited at the bound, and frames in flight when a present was queued.

Switch

VICTORY_PRESENT_QUEUED=1 or 2 (the bound), off by default. It needs VICTORY_ASYNC_SUBMIT=1 and presents sent ahead (the relay, or VICTORY_LATE_WAIT=3). Without them it logs a warning and stays off. With the switch off, every path is as before.

How it was tested

cargo +1.98.1 test --locked -j 4 -p victory-gpu (WARP and RTX 5080 tests run automatically): 193 passed, 0 failed, 5 ignored. With --features diagnostics: 210 passed, 0 failed, 6 ignored (several runs).

New tests (queue::join_tests, the walk on lines of its own):

  • Joining, unchanged by the refactor:
    • a wait met by a part taken joins, and signals follow the parts they followed;
    • a wait not known to be met sends what was taken;
    • a signal another queue waits for comes after its part;
    • a fence reached and a value in memory let two queues' parts join;
    • at most VICTORY_JOIN_MOST parts go together;
    • forced lines run each part alone, in order;
    • 400 random line sets, joined and not, keep every line's order and waits.
  • a_queued_present_runs_and_shows_what_the_present_ran_and_showed. 10,000 things in 110 rounds, with 1-4 queues and over 1,000 presents: parts, signals, fence waits, value waits met by earlier parts, and waits nothing meets. Queued presents give exactly the runs, signals and present sequence of the present that ran the lines itself.
  • queued_presents_keep_the_frame_order_and_the_bound. The title runs ahead (lines run now and then, joined or not, bound 1 and 2, 200 rounds). Checked:
    • everything given before a present runs before its frame is shown;
    • the present's queue's later parts run after it;
    • frames are shown in order, each once;
    • each part runs once, in its line's order;
    • never more presents wait than the bound;
    • the title's wait at the bound always ends.

Known flaky upstream test, also on plain main: indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields, a WARP race between the budget's two groups. It failed in some runs here and passed on rerun, as it does on main.

One --features diagnostics run printed no result line (the test process seems to have ended early). It did not happen again in 7 reruns, and the cause is unknown.

What we measured (RTX 5080, Ryzen 7 9800X3D)

Measured in our own tree (fork base plus our other switches, including a send station that is not part of this PR), not on this exact branch:

  • The title's wait at Present: about 42 ms a frame before (profile). With the switch it was 0.6 ms in the first run and 0.5 ms in a control run.
  • Frame rate, first run: 17.6-19.2 fps (~18.3). That run turned out to be at a lighter stretch of the scene (2,640-2,900 draws, 46-52 MB copies a frame), where the player had moved to.
  • Same build, same switches, control run: ~14 fps.
  • Scene-matched comparison afterwards: ~14.4 fps median for this build vs ~15.3 for a later build of ours. Both had the switch on, and the later build carries further changes. There is no clean on/off A/B of this switch at the same spot.
  • For reference: the build just before it, without the switch, was 13.5-14.6 fps (~14.2) in a warm run at a different spot.
  • No crash.

So the measured effect is the title's present wait (42 → 0.5 ms). The frame rate effect is not established beyond scene variance.

Risks

  • The title can now be up to N frames ahead of what is shown, like a swap chain's frame latency. N is 1 or 2.
  • Correctness rests on the walk's order rules. The two randomized tests compare against the old order. The game runs had no crash. No picture A/B was made.
  • The prerequisite refactor touches the core of the queue walk. It is meant to be behaviour-neutral (same code moved behind a trait), and the old join tests check it.

🤖 Generated with Claude Code

**@⁠exotiquee** on GitHub · 2026-11-25 21:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/1136) `exotiquee:pr/present-queued` → `main` · +1050 −102 · 2 files · 2 commits · open Branch `pr/present-queued` on `main` c36971b, two commits: 1. **Queues' lines walked through a trait (no behaviour change).** This is the minimal prerequisite. `release_held_now`'s loop becomes `walk(&Queues, all, joining)` over a small `Lines` trait. The trait covers the lines, fences, memory values, the host's send / run / present, and signals. `Queues` is the code that was inline, unchanged, diagnostics included. Tests can now run the walk on lines of their own and record what left them, in which order. 2. **Queued presents** (`VICTORY_PRESENT_QUEUED=1|2`). ## Why this is not `VICTORY_ASYNC_PRESENT` The README notes that putting presents behind the line changed nothing. `VICTORY_ASYNC_PRESENT=1` lets only one present wait behind the line: the next present finds it still there and runs the lines on the title's thread the old way, so the title still stands at every second present, and the other queues are not ordered behind the frame. This change lets up to N presents wait (marks in every other line keep the frame order) and never runs the lines on the title's thread; the measured present wait below is the difference. ## What it does With `VICTORY_ASYNC_SUBMIT=1` + `VICTORY_JOIN_PARTS=1`, a profile showed the title's render thread on a processor only 4 % of the time. It stood about 42 ms of each frame in `present -> present_now -> release_held_now -> the one-releaser lock`. The present ran the lines itself, so it waited until our thread had prepared and sent the whole frame. Our thread meanwhile sat idle about as long (39 ms a frame in `queue::worker`). The two threads took turns. With `VICTORY_PRESENT_QUEUED=N`: - **The present call.** `queue_present` puts a mark (`Held::Mark(frame)`) into every other line that holds anything. It then puts `Held::Present` into the present's own line, wakes the worker and returns. If N presents are already in the lines, the call stands until the oldest has been shown (a `SHOWN` condvar, like a swap chain's frame latency). - **The walk** (with `marks`): - What is ahead of a present or mark runs first, free things first. - Once nothing else moves, waits ahead of a present or mark are passed. This is the old present's forced release (`forces()`). - The present runs once every other line has reached its mark of that frame. - A mark is passed once its frame has been shown. So what the title gave after the present runs after the frame, as when the present ran the lines itself. - Signals keep their lines' order and go behind the flights as before. - **Unchanged paths.** Saved or listed frames (diagnostics) run the old way. `VICTORY_ASYNC_PRESENT=1` is left as it was. - **Log line.** Every 256 frames: presents queued / the old way, the title's present calls in ms a frame and how much of that waited at the bound, and frames in flight when a present was queued. ## Switch `VICTORY_PRESENT_QUEUED=1` or `2` (the bound), **off by default**. It needs `VICTORY_ASYNC_SUBMIT=1` and presents sent ahead (the relay, or `VICTORY_LATE_WAIT=3`). Without them it logs a warning and stays off. With the switch off, every path is as before. ## How it was tested `cargo +1.98.1 test --locked -j 4 -p victory-gpu` (WARP and RTX 5080 tests run automatically): **193 passed, 0 failed, 5 ignored**. With `--features diagnostics`: **210 passed, 0 failed, 6 ignored** (several runs). New tests (`queue::join_tests`, the walk on lines of its own): - Joining, unchanged by the refactor: - a wait met by a part taken joins, and signals follow the parts they followed; - a wait not known to be met sends what was taken; - a signal another queue waits for comes after its part; - a fence reached and a value in memory let two queues' parts join; - at most `VICTORY_JOIN_MOST` parts go together; - forced lines run each part alone, in order; - 400 random line sets, joined and not, keep every line's order and waits. - `a_queued_present_runs_and_shows_what_the_present_ran_and_showed`. 10,000 things in 110 rounds, with 1-4 queues and over 1,000 presents: parts, signals, fence waits, value waits met by earlier parts, and waits nothing meets. Queued presents give exactly the runs, signals and present sequence of the present that ran the lines itself. - `queued_presents_keep_the_frame_order_and_the_bound`. The title runs ahead (lines run now and then, joined or not, bound 1 and 2, 200 rounds). Checked: - everything given before a present runs before its frame is shown; - the present's queue's later parts run after it; - frames are shown in order, each once; - each part runs once, in its line's order; - never more presents wait than the bound; - the title's wait at the bound always ends. Known flaky upstream test, also on plain `main`: `indirect::tests::warp_budget_saturates_without_wraparound_and_preserves_draw_fields`, a WARP race between the budget's two groups. It failed in some runs here and passed on rerun, as it does on `main`. One `--features diagnostics` run printed no result line (the test process seems to have ended early). It did not happen again in 7 reruns, and the cause is unknown. ## What we measured (RTX 5080, Ryzen 7 9800X3D) Measured in our own tree (fork base plus our other switches, including a send station that is not part of this PR), not on this exact branch: - **The title's wait at Present:** about 42 ms a frame before (profile). With the switch it was 0.6 ms in the first run and 0.5 ms in a control run. - **Frame rate, first run:** 17.6-19.2 fps (~18.3). That run turned out to be at a lighter stretch of the scene (2,640-2,900 draws, 46-52 MB copies a frame), where the player had moved to. - **Same build, same switches, control run:** ~14 fps. - **Scene-matched comparison afterwards:** ~14.4 fps median for this build vs ~15.3 for a later build of ours. Both had the switch on, and the later build carries further changes. **There is no clean on/off A/B of this switch at the same spot.** - **For reference:** the build just before it, without the switch, was 13.5-14.6 fps (~14.2) in a warm run at a different spot. - No crash. So the measured effect is the title's present wait (42 → 0.5 ms). The frame rate effect is not established beyond scene variance. ## Risks - The title can now be up to N frames ahead of what is shown, like a swap chain's frame latency. N is 1 or 2. - Correctness rests on the walk's order rules. The two randomized tests compare against the old order. The game runs had no crash. No picture A/B was made. - The prerequisite refactor touches the core of the queue walk. It is meant to be behaviour-neutral (same code moved behind a trait), and the old join tests check it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
release_held_now's loop is now walk(&Queues, all, joining) over a Lines
trait: the lines, fences, memory values, the host's send / run / present
and signals. Queues is the layer's (the code that was inline, unchanged,
diagnostics included); the tests have lines of their own that record what
left them in which order. send_joined takes the lines too.

Tests (queue join_tests): waits met by a part taken join and signals follow
the parts they followed; a wait not known to be met sends what was taken;
a signal another queue waits for comes after its part; a fence reached and
a value in memory let two queues' parts join; at most VICTORY_JOIN_MOST
parts go together; forced lines run each part alone in order; 400 random
line sets, joined and not, keep every line's order and waits.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
With VICTORY_ASYNC_SUBMIT=1 + VICTORY_JOIN_PARTS=1 the title's render
thread was on a processor 4 % of the time and stood 42-46 ms of a 96 ms
frame in present -> present_now -> release_held_now -> the one-releaser
lock: the present ran the lines itself, so it waited until our thread had
prepared and sent the whole frame, while our thread waited about as long
for work. The two threads took turns.

With VICTORY_PRESENT_QUEUED=N (needs VICTORY_ASYNC_SUBMIT=1 and presents
sent ahead, i.e. the relay or VICTORY_LATE_WAIT=3; otherwise it says so
and stays off):
- queue_present puts a mark (Held::Mark(frame)) into every other line that
  holds anything, then Held::Present into the present's own line, wakes the
  worker and returns. Above N presents in the lines the call stands until
  the oldest has been shown (SHOWN condvar; like a swap chain's frame
  latency).
- walk (with `marks`): what is ahead of a present or mark runs first, free
  things first; once nothing else moves, waits ahead of a present or mark
  are passed (the old present's forced release, `forces()`); the present
  runs once every other line has reached its mark of that frame; a mark is
  passed once its frame has been shown, so what the title gave after the
  present runs after the frame, as when the present ran the lines itself.
  Signals keep their lines' order and go behind the flights as before.
- Saved or listed frames (diagnostics) run the old way.
- Held::Present carries Option<ID3D12Resource> (none in the tests).
- VICTORY_ASYNC_PRESENT=1 is left as it was (one present behind the line
  at most; the next one ran the lines itself on the title's thread).
- Log line every 256 frames: presents queued / the old way, the title's
  present calls in ms a frame and how much of it waited at the bound,
  frames in flight when a present was queued.

Tests (queue join_tests, on the walk with lines of their own): 10,000
things in 110 rounds (parts, signals, fence waits, value waits met by
earlier parts, waits nothing meets, 1,000+ presents, 1-4 queues): queued
presents with the lines run after each give exactly the runs, signals and
present sequence of the present that ran the lines itself. With the title
ahead (lines run now and then, joined or not, bound 1 and 2, 200 rounds):
everything given before a present runs before its frame is shown, the
present's queue's later parts after it, frames shown in order and once,
each part once in its line's order, never more presents waiting than the
bound, and the title's wait at the bound always ends.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:11 +00:00
Author
Owner

@⁠UwUCammie on GitHub · 2026-11-25 21:55 UTC · original

I tried queue depth 1 on an RX 7900 XT (RADV 26.3.1, Wine 11.22). In the first room the host meter counted 639 presents in 73.27 seconds, or 8.72 FPS at 4,864 draws per frame. The same route with the preceding build and synchronous presents averaged 9.11 FPS at 4,832 draws per frame. One pass each.

The queue was active throughout. In the last 256-frame report all 256 went through the queue, with one frame in flight at most. The title spent 4.3 ms per frame in the present call, almost all of it waiting for the earlier frame. The shorter call didn’t translate into higher throughput in this run.

**@⁠UwUCammie** on GitHub · 2026-11-25 21:55 UTC · [original](https://github.com/fxceless/victory-fork/pull/1136#issuecomment-7175707975) I tried queue depth 1 on an RX 7900 XT (RADV 26.3.1, Wine 11.22). In the first room the host meter counted 639 presents in 73.27 seconds, or 8.72 FPS at 4,864 draws per frame. The same route with the preceding build and synchronous presents averaged 9.11 FPS at 4,832 draws per frame. One pass each. The queue was active throughout. In the last 256-frame report all 256 went through the queue, with one frame in flight at most. The title spent 4.3 ms per frame in the present call, almost all of it waiting for the earlier frame. The shorter call didn’t translate into higher throughput in this run.
Author
Owner

@⁠Filip722 on GitHub · 2026-11-26 18:07 UTC · original

I tested a local port of #1136 on Bazzite 44, RTX 5060 Laptop 8 GB, NVIDIA 615.78.08, GE-Proton11-14, and vkd3d-proton 3.2.0 (cae8353ed7959c4+). The two Series S runs used the same executable, initial caches, offline checkpoint, async submission and relay. The only launch difference was VICTORY_PRESENT_QUEUED=1. Both counts use the frame identifier of the completed DXGI Present.

Queue depth Unique Presents in 54 s FPS Median / p95 interval Min. free VRAM
Disabled 326 6.05 160 / 188 ms 1600 MiB
1 306 5.66 163 / 230 ms 931 MiB

These are single-run measurements from the same stationary view and elapsed window with median pending pipelines at zero. Startup differed before that window, so I would treat the early timing and VRAM difference as observations. The nine focused queue tests passed under Proton. Depth 2 remains untested on this laptop.

Assisted by Codex (GPT-6.2-Sol High).

**@⁠Filip722** on GitHub · 2026-11-26 18:07 UTC · [original](https://github.com/fxceless/victory-fork/pull/1136#issuecomment-7200079691) I tested a local port of #1136 on Bazzite 44, RTX 5060 Laptop 8 GB, NVIDIA 615.78.08, GE-Proton11-14, and vkd3d-proton 3.2.0 (cae8353ed7959c4+). The two Series S runs used the same executable, initial caches, offline checkpoint, async submission and relay. The only launch difference was VICTORY_PRESENT_QUEUED=1. Both counts use the frame identifier of the completed DXGI Present. | Queue depth | Unique Presents in 54 s | FPS | Median / p95 interval | Min. free VRAM | | --- | ---: | ---: | ---: | ---: | | Disabled | 326 | 6.05 | 160 / 188 ms | 1600 MiB | | 1 | 306 | 5.66 | 163 / 230 ms | 931 MiB | These are single-run measurements from the same stationary view and elapsed window with median pending pipelines at zero. Startup differed before that window, so I would treat the early timing and VRAM difference as observations. The nine focused queue tests passed under Proton. Depth 2 remains untested on this laptop. Assisted by Codex (GPT-6.2-Sol High).
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/1136/head:github-bot/gh-1136'
git switch 'github-bot/gh-1136'

Merge

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