On a submit-bound PC the title spins on its frame fence: measurements, a reversed throttle, and switches that do nothing here #2940

Open
leonida/mandy
opened 2026-12-01 20:06:12 +00:00 by Yizzii · 1 comment
Yizzii commented 2026-12-01 20:06:12 +00:00

PC: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D (8C/16T), 32 GB, Windows 11. Builds: 7fbcd45, ed867d7 and dcda41f (each section says which), diag profile, the launcher's settings, frame generation off. All runs stand at one save restored before every run, with background apps closed by the test script (a music player left open in the later runs). Frame times are split by draws a frame: light < 6,500, heavy > 8,000. A/B runs use LEONIDA_AB with 4 s phases for 15 minutes; plain runs are 6 minutes.

On dcda41f this PC does 23.0-23.2 ms light and 29.6-30.4 ms heavy (two runs). The runtime's "card's clock" line (medians over both runs) puts the card at about 70 % busy and idle 7.0-7.9 ms a frame, 6.9-7.2 ms of that "while the submitting thread was working (the card idle behind us)". So here the submitting thread is the limit, not the card. Several of the findings.md results these switches rest on were taken where the card was the wall (d280: about 95 % busy), and some come out differently here.

1. The title allows two frames under way, and its main thread spins on that fence (reversed from the executable)

Windows Performance Recorder (CPU profile, 20 s, ed867d7): the busiest title thread was on a processor 55 % of the time, and 81 % of those samples were in one wait: 61 % in the Sleep it calls and 20 % in its own monitorx/mwaitx loop. That is at least ~10 ms of every ~24 ms frame, before counting its time asleep. The timeline shows most of it as the title running ("outside our spans"); only the longer sleeps appear as waits.

The wait, by RVA in the 1.0.2.1 image:

  • +0x2474740 runs at the end of each frame with that frame's fence token. It keeps the tokens in a ring of two, a function-local static at +0x75ddb60, with read and write counts at +0x75ddb74 / +0x75ddb78 (+0x75ddb70 is the static's init guard). With two under way it waits for the older one.
  • The wait is +0x4fb0a50 -> +0x4fb0ad0: monitorx/mwaitx on the fence's value, then Sleep through +0x4fb0e90 (the call returns to +0x4fb0c27), until the value passes.

So at the end of frame N the title waits until frame N-1 has been submitted, run and landed. In the same run the submitting thread worked 20.4 of 24.2 ms a frame light and 24.9 of 30.7 heavy.

I tried letting the title have three frames under way: the ring moved to four slots in the padding at the end of .data (+0xabce400), waiting at three instead of two. Both runs broke within a minute in the world: device removed ("relay: fence ... did not reach") in one, a title write fault at +0x50ebb82 in the other, and badly wrong lighting and stretched models on screen. The title's per-frame data most likely relies on that limit, so it has to stay. Writing it down so nobody else spends a run on it.

2. GetWriteWatch calls of one process don't overlap, and the title's faults wait with them

Local experiment (ed867d7): ask_ahead's runs asked on the wide helpers (wide_each), not one after another on the submitting thread, with the answers merged back in order. A/B, 57 rounds of four phases, 33,286 frames:

  • frame +0.125 +-0.079 ms (worse)
  • kernel asking time summed over threads 2.49 -> 8.40 ms a frame
  • the submitting thread's asking 2.82 -> 3.28 ms
  • the title's faults (faults_page_first_ms) 7.56 -> 9.29 ms

So spreading kernel calls over threads only makes them queue, and the title's own threads queue behind them. The other way round, every kernel call left out should help twice: the submitting thread and the title's faults.

3. The title's descriptor ring runs dry under a slow frame (one-byte fix, no fps)

The title fills root-table descriptors into a ring shared by all its contexts:

  • 32 chunks (+0x5c5ff4a: mov r14d, 0x20) of 256 KiB (+0x5c5ff50), set up at +0x5c5ff00. Values at +0xa943914 (count) and +0xa943910 (size) override them when set. Init at +0x247ac20.
  • A context whose chunk is full takes the next at +0x49b0. A chunk comes back once its fence passes (+0x4dad000 -> GetCompletedValue). With none to take, the thread does Sleep(1) and tries again (+0x4afc).

In a timeline (7fbcd45, ~30 fps with the timeline on) the job threads slept there ~13 times a frame (257 in 20 frames), about 1.5 ms each (p90 2-2.5 ms). With the count patched to 128 (one byte, 24 MiB more) the sleeps went to 0 and the timeline frame from 33.2 to 29.8 ms (one run each). In normal runs there was no change: light 23.8 / 24.1 ms without against 23.7 / 23.9 with, heavy 30.7 / 31.3 against 31.1 / 30.8. It only bites when the frame is slowed, so maybe on slower PCs.

4. Switches that do nothing on this PC (or cost)

All in ms of frame time, on minus off. A/B rows on dcda41f and ed867d7 are matched by draw count (see the end) unless noted.

Switch Build How Result
LEONIDA_PRESENT_SMOOTH 7fbcd45 A/B, 112 rounds, phase medians keep on: light -0.14 +-0.07, heavy +0.01 +-0.16; present jitter 0.3-0.5 ms lower (a fifth to a quarter)
LEONIDA_RELAY_EACH dcda41f A/B, 56 rounds, 33,599 frames +0.23 +-0.16
LEONIDA_SUBMIT_FRAMES 3 vs 1 dcda41f same A/B; and 6-min runs A/B +0.44 +-0.11; runs within run-to-run spread, heavy p90 36.0 vs 32.8 ms
LEONIDA_ASK_GAP_KB 8192 vs 256 ed867d7 A/B, 113 rounds, 33,665 frames +0.125 +-0.080 for 8 MiB (n.s.); kernel 2.43 vs 2.20 ms, askings 275 vs 419
LEONIDA_COPY_BESIDE ed867d7 A/B, 113 rounds, 33,217 frames -0.14 +-0.14
LEONIDA_WRITE_SITES ed867d7 3+3 alternated runs, 16-20 places light 23.60 / 23.57 / 23.26 vs 23.43 / 23.22 / 23.52
LEONIDA_WIDE_HALF (8 vs 4 helpers, 16 threads) ed867d7 A/B, 57 rounds, 33,286 frames +0.197 +-0.082 (worse)
cargo profile play (thin LTO) ed867d7 3+3 alternated runs +0.12 (pairs +0.54, -0.34, +0.15)

RELAY_EACH and SUBMIT_FRAMES were written for a title polling its fence, and that is this PC (section 1). They still do nothing here: telling the title sooner or queueing deeper doesn't shorten the wait. What sets it is the time to finish frame N-1 (submitting thread, then card, then landing).

On the list threads: their recording is ~0.35 ms of a frame's chain in the timeline. Local changes to them on 7fbcd45 (a lock skipped, hash sets kept across resets, a cheaper pointer hash) gave light -0.07 +-0.10 and heavy -0.15 +-0.14; the list-thread CPU saved shows up as idle, not as frame time. LIST_LOCK_FAST (#2764) was the change there that showed up: light -0.34 +-0.13, p90 -1.06 +-0.41, measured before it was merged.

5. Where the submitting thread's time goes (dcda41f, its own line)

Per frame:

Work ms
asking the write watch 2.8-3.2
title bytes under flights' writes 2.2
the lists' steps 9.0
copies in the card's memory 2.9
sending the lists 1.2-1.3
the heaps' records 0.5-0.8

The lists' steps break down as refreshes 4.5 ms in 26 flushes of ~5,500 refreshes (~85 % known to copy nothing), and copies and fills 1.8 ms. Per frame there are also 274 kernel askings over ~1.5 GB, 3.0-3.8 ms of protection changes, and ~1,400 title faults costing ~7.7 ms of the title's threads.

The in-process sampler on this thread (ed867d7, inclusive shares, they overlap) agrees: shadow::wide 27 % (8 % of it waiting on the helpers), refresh_front 21 %, kernel_written (GetWriteWatch) 9 %, ask_ahead 8 %. RTSSHooks64 (RivaTuner) shows up in 7 % of its samples but only 0.15 % on its own (the driver's ExecuteCommandLists runs through its hook), so it isn't a cost.

How these were measured

Besides LEONIDA_AB's phase lines, every run wrote a line per frame: frame time, draws, the A/B bits, card idle, submitting thread worked, process CPU time. Each frame is compared only with frames of a like draw count (250-draw bins), and on minus off is taken per round of phases. On the same data that gave an error of +-0.08 ms, against +-0.21 for the same rounds without the matching.

PC: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D (8C/16T), 32 GB, Windows 11. Builds: 7fbcd45, ed867d7 and dcda41f (each section says which), diag profile, the launcher's settings, frame generation off. All runs stand at one save restored before every run, with background apps closed by the test script (a music player left open in the later runs). Frame times are split by draws a frame: light < 6,500, heavy > 8,000. A/B runs use LEONIDA_AB with 4 s phases for 15 minutes; plain runs are 6 minutes. On dcda41f this PC does 23.0-23.2 ms light and 29.6-30.4 ms heavy (two runs). The runtime's "card's clock" line (medians over both runs) puts the card at about 70 % busy and idle 7.0-7.9 ms a frame, 6.9-7.2 ms of that "while the submitting thread was working (the card idle behind us)". So here the submitting thread is the limit, not the card. Several of the findings.md results these switches rest on were taken where the card was the wall (d280: about 95 % busy), and some come out differently here. ## 1. The title allows two frames under way, and its main thread spins on that fence (reversed from the executable) Windows Performance Recorder (CPU profile, 20 s, ed867d7): the busiest title thread was on a processor 55 % of the time, and 81 % of those samples were in one wait: 61 % in the Sleep it calls and 20 % in its own monitorx/mwaitx loop. That is at least ~10 ms of every ~24 ms frame, before counting its time asleep. The timeline shows most of it as the title running ("outside our spans"); only the longer sleeps appear as waits. The wait, by RVA in the 1.0.2.1 image: - +0x2474740 runs at the end of each frame with that frame's fence token. It keeps the tokens in a ring of two, a function-local static at +0x75ddb60, with read and write counts at +0x75ddb74 / +0x75ddb78 (+0x75ddb70 is the static's init guard). With two under way it waits for the older one. - The wait is +0x4fb0a50 -> +0x4fb0ad0: monitorx/mwaitx on the fence's value, then Sleep through +0x4fb0e90 (the call returns to +0x4fb0c27), until the value passes. So at the end of frame N the title waits until frame N-1 has been submitted, run and landed. In the same run the submitting thread worked 20.4 of 24.2 ms a frame light and 24.9 of 30.7 heavy. I tried letting the title have three frames under way: the ring moved to four slots in the padding at the end of .data (+0xabce400), waiting at three instead of two. Both runs broke within a minute in the world: device removed ("relay: fence ... did not reach") in one, a title write fault at +0x50ebb82 in the other, and badly wrong lighting and stretched models on screen. The title's per-frame data most likely relies on that limit, so it has to stay. Writing it down so nobody else spends a run on it. ## 2. GetWriteWatch calls of one process don't overlap, and the title's faults wait with them Local experiment (ed867d7): ask_ahead's runs asked on the wide helpers (wide_each), not one after another on the submitting thread, with the answers merged back in order. A/B, 57 rounds of four phases, 33,286 frames: - frame +0.125 +-0.079 ms (worse) - kernel asking time summed over threads 2.49 -> 8.40 ms a frame - the submitting thread's asking 2.82 -> 3.28 ms - the title's faults (faults_page_first_ms) 7.56 -> 9.29 ms So spreading kernel calls over threads only makes them queue, and the title's own threads queue behind them. The other way round, every kernel call left out should help twice: the submitting thread and the title's faults. ## 3. The title's descriptor ring runs dry under a slow frame (one-byte fix, no fps) The title fills root-table descriptors into a ring shared by all its contexts: - 32 chunks (+0x5c5ff4a: mov r14d, 0x20) of 256 KiB (+0x5c5ff50), set up at +0x5c5ff00. Values at +0xa943914 (count) and +0xa943910 (size) override them when set. Init at +0x247ac20. - A context whose chunk is full takes the next at +0x49b0. A chunk comes back once its fence passes (+0x4dad000 -> GetCompletedValue). With none to take, the thread does Sleep(1) and tries again (+0x4afc). In a timeline (7fbcd45, ~30 fps with the timeline on) the job threads slept there ~13 times a frame (257 in 20 frames), about 1.5 ms each (p90 2-2.5 ms). With the count patched to 128 (one byte, 24 MiB more) the sleeps went to 0 and the timeline frame from 33.2 to 29.8 ms (one run each). In normal runs there was no change: light 23.8 / 24.1 ms without against 23.7 / 23.9 with, heavy 30.7 / 31.3 against 31.1 / 30.8. It only bites when the frame is slowed, so maybe on slower PCs. ## 4. Switches that do nothing on this PC (or cost) All in ms of frame time, on minus off. A/B rows on dcda41f and ed867d7 are matched by draw count (see the end) unless noted. | Switch | Build | How | Result | |---|---|---|---| | LEONIDA_PRESENT_SMOOTH | 7fbcd45 | A/B, 112 rounds, phase medians | keep on: light -0.14 +-0.07, heavy +0.01 +-0.16; present jitter 0.3-0.5 ms lower (a fifth to a quarter) | | LEONIDA_RELAY_EACH | dcda41f | A/B, 56 rounds, 33,599 frames | +0.23 +-0.16 | | LEONIDA_SUBMIT_FRAMES 3 vs 1 | dcda41f | same A/B; and 6-min runs | A/B +0.44 +-0.11; runs within run-to-run spread, heavy p90 36.0 vs 32.8 ms | | LEONIDA_ASK_GAP_KB 8192 vs 256 | ed867d7 | A/B, 113 rounds, 33,665 frames | +0.125 +-0.080 for 8 MiB (n.s.); kernel 2.43 vs 2.20 ms, askings 275 vs 419 | | LEONIDA_COPY_BESIDE | ed867d7 | A/B, 113 rounds, 33,217 frames | -0.14 +-0.14 | | LEONIDA_WRITE_SITES | ed867d7 | 3+3 alternated runs, 16-20 places | light 23.60 / 23.57 / 23.26 vs 23.43 / 23.22 / 23.52 | | LEONIDA_WIDE_HALF (8 vs 4 helpers, 16 threads) | ed867d7 | A/B, 57 rounds, 33,286 frames | +0.197 +-0.082 (worse) | | cargo profile play (thin LTO) | ed867d7 | 3+3 alternated runs | +0.12 (pairs +0.54, -0.34, +0.15) | RELAY_EACH and SUBMIT_FRAMES were written for a title polling its fence, and that is this PC (section 1). They still do nothing here: telling the title sooner or queueing deeper doesn't shorten the wait. What sets it is the time to finish frame N-1 (submitting thread, then card, then landing). On the list threads: their recording is ~0.35 ms of a frame's chain in the timeline. Local changes to them on 7fbcd45 (a lock skipped, hash sets kept across resets, a cheaper pointer hash) gave light -0.07 +-0.10 and heavy -0.15 +-0.14; the list-thread CPU saved shows up as idle, not as frame time. LIST_LOCK_FAST (#2764) was the change there that showed up: light -0.34 +-0.13, p90 -1.06 +-0.41, measured before it was merged. ## 5. Where the submitting thread's time goes (dcda41f, its own line) Per frame: | Work | ms | |---|---| | asking the write watch | 2.8-3.2 | | title bytes under flights' writes | 2.2 | | the lists' steps | 9.0 | | copies in the card's memory | 2.9 | | sending the lists | 1.2-1.3 | | the heaps' records | 0.5-0.8 | The lists' steps break down as refreshes 4.5 ms in 26 flushes of ~5,500 refreshes (~85 % known to copy nothing), and copies and fills 1.8 ms. Per frame there are also 274 kernel askings over ~1.5 GB, 3.0-3.8 ms of protection changes, and ~1,400 title faults costing ~7.7 ms of the title's threads. The in-process sampler on this thread (ed867d7, inclusive shares, they overlap) agrees: shadow::wide 27 % (8 % of it waiting on the helpers), refresh_front 21 %, kernel_written (GetWriteWatch) 9 %, ask_ahead 8 %. RTSSHooks64 (RivaTuner) shows up in 7 % of its samples but only 0.15 % on its own (the driver's ExecuteCommandLists runs through its hook), so it isn't a cost. ## How these were measured Besides LEONIDA_AB's phase lines, every run wrote a line per frame: frame time, draws, the A/B bits, card idle, submitting thread worked, process CPU time. Each frame is compared only with frames of a like draw count (250-draw bins), and on minus off is taken per round of phases. On the same data that gave an error of +-0.08 ms, against +-0.21 for the same rounds without the matching.
MoonEyes commented 2026-12-03 15:28:08 +00:00

This was generated by AI during triage.

Triage Notes

What we've established so far:

  • Reported on Windows 11 with an RTX 5070 Ti, Ryzen 7 9800X3D and 32 GB RAM: 23.0-23.2 ms light frames and 29.6-30.4 ms heavy frames in the measured runs.
  • The report identifies the submitting thread as the limit (about 70% GPU busy), and includes measurements of the frame-fence wait, GetWriteWatch overlap, descriptor-ring pressure, and several switches.
  • The relevant switch behavior and prior measurements are documented in d3d12/docs/switches.md and d3d12/docs/findings.md. I could not independently reproduce the hardware/game run here.

What we still need from you (@Yizzii):

  • What concrete outcome should this issue request: add these findings to the docs, investigate a specific optimization, or something else? If the goal is optimization, what workload and frame-time target should count as success?
> *This was generated by AI during triage.* ## Triage Notes **What we've established so far:** - Reported on Windows 11 with an RTX 5070 Ti, Ryzen 7 9800X3D and 32 GB RAM: 23.0-23.2 ms light frames and 29.6-30.4 ms heavy frames in the measured runs. - The report identifies the submitting thread as the limit (about 70% GPU busy), and includes measurements of the frame-fence wait, GetWriteWatch overlap, descriptor-ring pressure, and several switches. - The relevant switch behavior and prior measurements are documented in `d3d12/docs/switches.md` and `d3d12/docs/findings.md`. I could not independently reproduce the hardware/game run here. **What we still need from you (@Yizzii):** - What concrete outcome should this issue request: add these findings to the docs, investigate a specific optimization, or something else? If the goal is optimization, what workload and frame-time target should count as success?
Sign in to join this conversation.
No assignees
No project
No milestone
Dependencies

No dependencies set

Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
leonida/mandy#2940
No description provided.