startup: native draws serialise on the exclusive draw lock; readable-memory page probes dominate the hold in heavy scenes #3897

Open
opened 2026-12-02 23:22:16 +00:00 by SimSalabimse · 1 comment
SimSalabimse commented 2026-12-02 23:22:16 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-12-02T23:22:16Z.


Summary

Native-path draws serialise on the exclusive draw lock. In a heavy scene (hundreds of translated draws per present) about two thirds of the wall time is spent holding that lock, and most of the hold is readable-memory page probes that take about one page fault each.

What was measured

Two runs of the same scene on the Windows test PC (Simsalabim), about 410 s each, with per-draw phase timers and, in the second run, a frame copy compare change (neither is upstream yet). One run per build, so treat the figures as one sample each, not a benchmark.

Steady slow phase (second half of each run), per present:

run 1 run 2
wall 303 ms 271 ms
draw lock hold / wall 0.69 0.66
draw calls per present 681 671
last-third fps 3.27 3.62

In the second run, where the frame copy was split into probe, compare, snapshot alloc, memcpy and ring reserve:

  • Readable-memory probe: 149 ms of the 180 ms lock hold per present (83%).
  • Snapshot compare: about 11 ms. Snapshot allocation: about 0.1 ms. Ring reserve: about 0.2 ms.
  • Process page faults in the slow phase: about 1.3k to 1.65k per present against about 1.5k probes per present (about one fault per probe). In the fast phase (about 5 calls per present) the fault count is close to zero.
  • Probe cost works out to roughly 90 us per call on average (inferred from the counts; the log has no probe counter).

The system was also near its memory ceiling in the slow phase (low available RAM, commit close to the limit).

What is not known

The log cannot separate two readings of the faults: (1) memory pressure pages guest memory out and the probe pays the page-in, or (2) something faults once per range on every probe (a guard or protected page that is tripped and re-armed). The two runs also differ in build and scene timing, so the 10% fps gap is not a clean A/B.

Idea (not tested)

  • Add a probe count, probe time and pages-touched counter first, so the two readings above can be told apart.
  • Touch or prefetch the ranges a draw will read before taking the draw lock, so several draw threads take their faults in parallel instead of one after another.
  • #2976 (closed: table buffer compare under draw_lock)
  • #3516 and #3528 (prepare translations and create PSOs outside draw_lock)
  • #3477 (runtime diagnostics for long runs)
  • A draft PR series for the phase timers and the frame copy changes is planned and will be linked here.

AI-Assisted

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6756679129 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3897). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-12-02T23:22:16Z. --- ## Summary Native-path draws serialise on the exclusive draw lock. In a heavy scene (hundreds of translated draws per present) about two thirds of the wall time is spent holding that lock, and most of the hold is readable-memory page probes that take about one page fault each. ## What was measured Two runs of the same scene on the Windows test PC (Simsalabim), about 410 s each, with per-draw phase timers and, in the second run, a frame copy compare change (neither is upstream yet). One run per build, so treat the figures as one sample each, not a benchmark. Steady slow phase (second half of each run), per present: | | run 1 | run 2 | |---|---|---| | wall | 303 ms | 271 ms | | draw lock hold / wall | 0.69 | 0.66 | | draw calls per present | 681 | 671 | | last-third fps | 3.27 | 3.62 | In the second run, where the frame copy was split into probe, compare, snapshot alloc, memcpy and ring reserve: - Readable-memory probe: 149 ms of the 180 ms lock hold per present (83%). - Snapshot compare: about 11 ms. Snapshot allocation: about 0.1 ms. Ring reserve: about 0.2 ms. - Process page faults in the slow phase: about 1.3k to 1.65k per present against about 1.5k probes per present (about one fault per probe). In the fast phase (about 5 calls per present) the fault count is close to zero. - Probe cost works out to roughly 90 us per call on average (inferred from the counts; the log has no probe counter). The system was also near its memory ceiling in the slow phase (low available RAM, commit close to the limit). ## What is not known The log cannot separate two readings of the faults: (1) memory pressure pages guest memory out and the probe pays the page-in, or (2) something faults once per range on every probe (a guard or protected page that is tripped and re-armed). The two runs also differ in build and scene timing, so the 10% fps gap is not a clean A/B. ## Idea (not tested) - Add a probe count, probe time and pages-touched counter first, so the two readings above can be told apart. - Touch or prefetch the ranges a draw will read before taking the draw lock, so several draw threads take their faults in parallel instead of one after another. ## Related - #2976 (closed: table buffer compare under draw_lock) - #3516 and #3528 (prepare translations and create PSOs outside draw_lock) - #3477 (runtime diagnostics for long runs) - A draft PR series for the phase timers and the frame copy changes is planned and will be linked here. AI-Assisted
triggered02 commented 2026-12-03 13:43:40 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by triggered02 on 2026-12-03T13:43:40Z.


Claiming the counter half of this, not the phase timers.

Slice: add probe accounting around probe_readable (src/startup_stubs/local_log.h:166) — calls, bytes requested, pages actually touched, and a gated tick total — and surface it on the totals line next to the existing reads refused before a fault. Extend tests/startup_local_log_check.cpp with cases whose page-touch counts are hand-computable, so the numbers are pinned rather than asserted loosely.

Deliberately not taking yet: the per-draw phase timers and the frame-copy phase split. Two reasons: this is a hot path, and a QueryPerformanceCounter per probe would distort the thing it measures unless it is carefully gated; and the issue's phase split depends on counters that do not exist yet. Counters first, then phases with a measured baseline to compare against.

What I can verify here: the check builds with clang-cl + an xwin splat and runs under Wine, and startup_local_log_check already asserts probe semantics on mapped, freed and guard pages plus a simulated debugger, so extending it is a real gate rather than a smoke test. I will report the exact commands and the counts I expect per case.

What stays open, and will stay stated as such: whether the 1.3–1.65k faults per present are pressure page-ins or per-range guard re-arms is not something a counter can answer on its own — attribution needs the Windows test PC and the title's scene. Wine timing is not Windows verification, so I will not present any fps or hold-time number as measured.

Overlap: no comments, no assignee, no open PR. The reporter mentions a draft PR series for the phase timers; I will not touch that part, and I will say so in the PR body if the counters land before the phases do.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7380283561 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/3897#issuecomment-7380283561). Originally posted by [triggered02](https://github.com/triggered02) on 2026-12-03T13:43:40Z. --- Claiming the **counter half** of this, not the phase timers. **Slice:** add probe accounting around `probe_readable` (`src/startup_stubs/local_log.h:166`) — calls, bytes requested, pages actually touched, and a gated tick total — and surface it on the totals line next to the existing `reads refused before a fault`. Extend `tests/startup_local_log_check.cpp` with cases whose page-touch counts are hand-computable, so the numbers are pinned rather than asserted loosely. **Deliberately not taking yet:** the per-draw phase timers and the frame-copy phase split. Two reasons: this is a hot path, and a `QueryPerformanceCounter` per probe would distort the thing it measures unless it is carefully gated; and the issue's phase split depends on counters that do not exist yet. Counters first, then phases with a measured baseline to compare against. **What I can verify here:** the check builds with clang-cl + an xwin splat and runs under Wine, and `startup_local_log_check` already asserts probe semantics on mapped, freed and guard pages plus a simulated debugger, so extending it is a real gate rather than a smoke test. I will report the exact commands and the counts I expect per case. **What stays open, and will stay stated as such:** whether the 1.3–1.65k faults per present are pressure page-ins or per-range guard re-arms is *not* something a counter can answer on its own — attribution needs the Windows test PC and the title's scene. Wine timing is not Windows verification, so I will not present any fps or hold-time number as measured. **Overlap:** no comments, no assignee, no open PR. The reporter mentions a draft PR series for the phase timers; I will not touch that part, and I will say so in the PR body if the counters land before the phases do. AI-assisted.
Sign in to join this conversation.
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
R0Y00/Xbox2Windows#3897
No description provided.