Skip to content

STATS: Split the reloaded pass bytes (splitMiB) by the reason a pass ended - #206

Merged
jdrly merged 2 commits into
mainfrom
perf/80-split-clear-reasons
Nov 14, 2026
Merged

jdrly merged 2 commits into
mainfrom
perf/80-split-clear-reasons

Conversation

@jdrly

@jdrly jdrly commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

What changes

The 0.1.5 STATS averages had splitMiB at 445 per frame: attachments reloaded because a pass ended and the next one reopened them. splitCheck already classified each split's count by reason, but it added all the bytes to one counter. Which reason carries the bytes decides the next step: an in-pass clear, for example, could only remove the clear reason's share. This PR splits those bytes by reason, and #127's slice 3 counts the clear paths, for profiled sessions only. STATS now ends with splitMiB by reason, and with how clears were carried out: ending an open pass, flushed as a pending clear, as a pass of their own, or as a scissored draw.

Closes #80. Part of #127: slice 3 (clear eligibility), the last of its four slices (#193 and #202 had the others). What #127 still lacks: the split bytes by the clear's aspect (see below), and its profile-off bench rounds and profile-on overhead, which wait for #198's bench set.

  • ADR: none (ADR-0007 for the performance evidence)

New STATS fields, per render-thread frame, named in PERFORMANCE.md §4, driver/d3d9/d3d9_stats.h and driver/mtl/mtl_render_stats.h:

  • splitMiBSubmit, splitMiBXfer, splitMiBClear, splitMiBOther: splitMiB by the reason the split's previous pass ended, as split= is classified. The four add up to splitMiB, each rounded on its own.
  • clrOpen (full-surface clears that ended an open pass), clrPending (folded clears that got a pass of their own because nothing drew there; also in clrPass), clrViewFull (color clears through the part-surface path whose rect covers the whole mip level), clrRect (part-surface color clears: a scissored draw), clrRectDs (part-surface depth/stencil clears: a draw).

How to verify

  • scripts/run-native-tests.sh: stats_test covers the new fields and rstats::countSplit, the split classification splitCheck uses.
  • With D9MT_PROFILE=1, bench_4k: in every STATS line, the four splitMiB* reasons add up to splitMiB, within rounding.

Evidence

Proof. Head 350df71, base 8713666.

  • Native tests, on jd-ai-server (x86_64 Linux, g++): stats_test OK.

  • Controls. The test doesn't build against main's headers. With the branch's headers, each of these mutations makes it fail:

    • submit and xfer bytes swapped in the line
    • the total printed as other
    • open and pending swapped
    • clrRectDs not taken as a per-frame delta
    • submit bytes counted as xfer in countSplit
    • clear checked before transfer
    • other bytes dropped
  • Hosted Checks on 350df71: green (run 43591761353). stats_test passes there, and the AIR codegen is 25fc2491f11d0902328bd623fa12d2d73b7eeebb877e6dfd30d85b78c8e7a6c2, unchanged.

  • GPU hash gate on the rented M1 (Apple M1, macOS 27.0), gpu-ci run 43591713686, head 350df71 against main 8713666, variants=default,profile targets=27 allow-notclean=code_depth_bias. Verdict: pass. AIR target 27 only: the diff adds profile-only counting on the clear paths and changes no shader, codegen or draw path, and the AIR target only changes the shader codegen.

  • STATS: Split the reloaded pass bytes (splitMiB) by the reason a pass ended #80's runtime check, on the rented M1 (Apple M1, macOS 27.0, Wine cx-26.3.0-8; 2026-11-14 12:59). One run of bench_4k (300 frames, 4 post passes, 1 depth clear) through perf-abba.sh with D9MT_PROFILE=1, for main 8713666 (d3d9.dll d175e287…) and for 82e2fbe (1f436b92…). Both used main's bridge, since this PR changes no bridge file. 82e2fbe is round 1's head; round 2 moved the same classification into countSplit and two clear counts after the pipeline lookup. Each run logged 30 STATS lines. Main's end without the new fields. On the PR, in all 30 lines the four reasons add up to splitMiB within rounding:

    STATS t=1 … split=1.0 splitSubmit=0.9 splitXfer=0.0 splitClear=0.1 splitMiB=31.6 … | splitMiBSubmit=28.5 splitMiBXfer=0.0 splitMiBClear=3.2 splitMiBOther=0.0 | clrOpen=1.0 clrPending=0.1 clrViewFull=0.0 clrRect=0.0 clrRectDs=0.0
    STATS t=2 … split=1.0 splitSubmit=1.0 splitXfer=0.0 splitClear=0.0 splitMiB=31.6 … | splitMiBSubmit=31.6 splitMiBXfer=0.0 splitMiBClear=0.0 splitMiBOther=0.0 | clrOpen=1.0 clrPending=0.0 clrViewFull=0.0 clrRect=0.0 clrRectDs=0.0
    
    • The first second's 28.5 + 3.2 is 31.7 against 31.6: rounding. The other 29 lines are 31.6 = 31.6.
    • The bytes follow the counts (splitSubmit=0.9 splitClear=0.1).
    • clrOpen=1.0: one full-surface clear a frame ends an open pass. I haven't traced which of bench_4k's clears it is.
    • One run per side with profiling on gives no timing comparison.

Performance (PERFORMANCE.md §1). Kind: a diagnostic. With D9MT_PROFILE unset:

  • splitCheck runs only under profiling, as before.
  • Each clear path gets one predictable branch.
  • The render-thread stats array has 9 more counters, published at endFrame as before.

Nothing per draw. Timing is pending: the representative guard isn't calibrated yet, and no benchmark ran for this PR.

Definition of Done

  • Clean x64/x86 builds: hosted Checks 43591761353.
  • Hash suite frame-identical to base: default and profile, AIR target 27, gpu-ci 43591713686.
  • Not a bug fix. The tests have failing controls (above).
  • Native tests pass. Threading: the counters are the render thread's and are published through rstats::Totals as before.
  • Performance: bounded review above, timing recorded as pending.
  • AIR codegen id: no codegen input changed.
  • No new environment variable or option.
  • No new term, no changed decision.
  • Independent review: APPROVE.
  • UAT (STATS: Split the reloaded pass bytes (splitMiB) by the reason a pass ended #80): a SWTOR session with Debug Logging, where each STATS line shows the reloaded bytes by reason next to splitMiB.

Review

Codex (gpt-6.1-sol, reasoning high), two rounds.

  • Round 1 at 82e2fbe: CHANGES REQUESTED.
    • High: the test checked pre-classified snapshots, so it couldn't catch a wrong classification in splitCheck. Fixed in 350df71. The classification moved into rstats::countSplit, which splitCheck calls with the same three conditions as before, and the test drives it directly.
    • Low: clrOpen described as the target's own pass. Fixed: any open pass.
    • Low: an alignment explanation of clrViewFull that the code doesn't support. Fixed: described by the backend branch.
    • Low: the rect counters counted before the pipeline lookup that can skip the draw. Fixed: they count after it.
    • Low, pre-existing: rstats::Totals::snapshot loads each counter on its own while the render thread publishes them one by one, so a STATS line can mix two frames' totals. For STATS: Split the reloaded pass bytes (splitMiB) by the reason a pass ended #80, the reasons can then miss splitMiB by one frame's worth in a line that raced the publish. Not fixed here; see Follow-ups.
  • Round 2 at 350df71: every finding fixed except the deferred pre-existing Low.
  • Verdict: APPROVE

Risks and what I didn't do

Risk. With profiling off, a player could only notice if the clear-path branches cost time. Clears are a few per frame, and the hash suite catches any change in frames. With profiling on, a wrong classification would mislead the speed work. The native test covers the classification, and bench_4k's sums cover it at run time.

How to revert. Revert the squash commit.

Not done: the split bytes by the clear's aspect (color, depth, stencil), which #127 lists next to the reason. The reason split answers #80's question first; the aspect split can follow if the clear reason turns out to carry the bytes.

Follow-ups

  • rstats::Totals::snapshot() isn't coherent with publish(): a STATS line can mix two frames' render-thread totals (pre-existing; the review's Low).

…count the clear paths (profile-only)

Closes #80; part of #127 (slice 3). splitCheck adds each split's load bytes to
the counter of its reason (submit, transfer, clear, other) next to SplitBytes,
and STATS appends splitMiBSubmit/Xfer/Clear/Other, which add up to splitMiB.
The clear paths count clears that ended an open pass, pending clears that got a
pass of their own, full-surface clears through the part-surface path, and
part-surface color and depth/stencil clears (clrOpen, clrPending, clrViewFull,
clrRect, clrRectDs). Everything behind D9MT_PROFILE: splitCheck already is, and
each clear path gets one predictable branch.
…ers splitCheck's reasons

Review round 1: the test only checked pre-classified snapshots (High). Also count
clrRect/clrRectDs after the pipeline lookup that can skip the draw, and describe
clrOpen and clrViewFull by what the backend does (Lows).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

STATS: Split the reloaded pass bytes (splitMiB) by the reason a pass ended

1 participant