Skip to content

GPU measurement tools: a profiled frame in every n, A/B phases in one run, GPU captures, and gpuprof.py - #225

Closed
v0lumehi wants to merge 6 commits into
seedds:mainfrom
v0lumehi:gpu-tools
Closed

v0lumehi wants to merge 6 commits into
seedds:mainfrom
v0lumehi:gpu-tools

Conversation

@v0lumehi

@v0lumehi v0lumehi commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of #142: Breath of the Wild performance on iPhone and Mac. These are the measurement tools behind the numbers in #142 and #159.

Builds on #191 (the Mac benchmark): this PR contains its commits; the last four commits are new here.

GPU measurement tools for the device and the Mac

All switches are off by default.

Switch / tool What it does
DM_NVN_GPUPROF=every:<n> One profiled frame in every n, each reported on its own, so a device run can be profiled without timing a scene to a frame number. Render-pass lines add the attachments' load / store KB and pixel formats.
DM_NVN_PASSDUMP=every:<n> Dumps a frame's passes halfway between two profiled frames.
DM_AB=<frames> Switches set to ab alternate in phases of one run. An [ab] line per phase gives GPU / frame time p50 / p90 / mean and attachment traffic. DM_NVN_BARRIER=ab is the first such switch.
DM_GPU_CAPTURE=<frame>[:<n>] or gpu:<ms>[:<after>] Metal GPU traces for Xcode. gpu:<ms> fires after 60 frames in a row over <ms>. Traces go to gpu_captures/ (DM_GPU_CAPTURE_DIR), and only that folder is pruned to the newest DM_GPU_CAPTURE_KEEP. DM_METAL_CAPTURE=1 adds MetalCaptureEnabled to the IPA; on the Mac, MTL_CAPTURE_ENABLED=1.
dm/tools/gpuprof.py Summarises the [gpuprof] and [ab] lines of a run log or an iPhone log.txt: per-frame totals, the mean per pass shape or per size class (full / half / quarter of the largest colour pass, G-buffer-like passes apart), one frame's timeline with its gaps, and A/B medians.

Two fixes in the capture code:

  • gpu:<ms> could fire in frame 0;
  • a failed capture was retried every frame.

Docs

  • docs/agents/05-debugging.md: "GPU time on the device", a recipe for profiling via Documents/env.txt and reading the lines.
  • The switches in docs/agents/04-graphics.md and docs/development.md.
  • A reference entry in docs/reference/shaders.md (GPU frame captures need pipelines built through the device), and the symptom index.

Checked

  • Local CI-equivalent run: host tests, graphics CPU tests, every graphics test builds, dmhost for three profiles, the iOS compile check and the tool tests (including test_gpuprof.py on a synthetic log and test_docs) pass.
  • gpuprof.py on a real Mac run log.
  • The profile lines were used on the iPhone 17 Pro Max for the measurements in Breath of the Wild at 120 fps on iPhone and Mac, then 4K: start here (follow-up to #142) #159.
  • A Mac run after the clean-up (Breath of the Wild, M2 Max, 100 s, DM_NVN_GPUPROF=every:300 DM_NVN_PASSDUMP=every:1200 DM_AB=300 DM_NVN_BARRIER=ab DM_GPU_CAPTURE=2400 MTL_CAPTURE_ENABLED=1):
    • [gpuprof] frame lines every 300 frames, with the attachment ledger (e.g. in the world: 154 render passes, 446 MB loaded / 488 MB stored);
    • [ab] lines for four alternating phases;
    • frame 2400 captured into gpu_captures/dm_<date>-<time>_f2400.gputrace. The folder held three older dm_*.gputrace, another .gputrace and a text file: the two oldest dm_* were removed (keep 2, the new one included), the rest stayed;
    • gpuprof.py read the log (per-frame totals; the captured frame shows the capture's own stall as its span).

v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 26, 2026
…oes not reset g_px_dcu / g_px_dcc, the DM_NVN_DC_UNWRITTEN / DM_NVN_DC_COVERED latches of the diagnostic commits seedds#225 replaced (botw-fx has them, my-main does not)
…platform mac along a fixed route and reports frame-time percentiles

A route is a line of the profile's new bench.tsv: the scripted input (DM_KEYS, seconds from the start) and the measured window, from when the scene is loaded. Each run starts from a copy of the same save and reads the host's per-frame rows (DM_NVN_TSV): frame time (start to start) and time on screen at p50 / p95 / p99 / max, frames longer than 1.5 frame times, dropped frames, GPU time p50 / p95, the game's speed against real time where the frame step logs it, and the [RED] lines. Variants (environment switches, or another host, shader libraries, rewritten modules or pipeline archive) run in turn, repeated, and are reported as medians with their range in results.md / results.json beside each run's log, frames.tsv and two screenshots at the same moments. Breath of the Wild has three routes: a save in Zora's Domain with the camera turning and Link walking (zora-pan), the same standing still, and a probe for the load time.

Used for the baseline in issue seedds#159: main + seedds#76 + seedds#158 on an M2 Max at 900p and a 120 fps target, three variants, two runs each. docs/development.md ("A benchmark on the Mac") and dm/games/README.md describe it; dm/tools/tests/test_bench.py checks the window, the percentiles (nearest rank) and that every bench.tsv parses.
… variable frame step); at 60 or 30 the host matches the screen to the cap itself, and the forced 120 Hz link ran Breath of the Wild at 2.4 times real time at --fps 60
…GPUPROF=every:<n>), pass dumps every n frames (DM_NVN_PASSDUMP=every:<n>), and in-process A/B phases (DM_AB=<frames>)

- DM_NVN_GPUPROF=every:<n> profiles the frames that are multiples of n, each reported on its own, for a phone run whose scene cannot be timed to a frame number. A render pass line now also gives what the pass loaded and stored of its attachments (KB, the bandwidth ledger's view, counted from the previous pass end whether that pass was profiled or not) and the Metal pixel formats of colour attachment 0 and of depth / stencil; the frame line gives the render passes and their attachment traffic.
- DM_NVN_PASSDUMP=every:<n> dumps one frame in every n, halfway between two profiled frames.
- DM_AB=<frames> alternates the switches set to ab in phases of that many frames, and prints an [ab] line per phase: GPU and frame time (p50 / p90 / mean without the phase's first quarter), attachment traffic and passes per frame. ab:<k,...>/<n> runs four configurations of two switches. DM_NVN_BARRIER=ab is its first switch.
…[:<frames>], or gpu:<ms>[:<after frame>] for the first frame after 60 frames in a row past <ms> of GPU time

- The trace goes to its own folder, DM_GPU_CAPTURE_DIR, by default gpu_captures/ in the working directory (the app's Documents on iOS, the run folder on the Mac), as dm_<date>-<time>_f<frame>.gputrace. A trace takes 1.5-2 GB, so before each capture that folder alone is pruned to the newest DM_GPU_CAPTURE_KEEP (default 2, the new one included); nothing outside it is removed.
- The setting is read again when it changes, so the Mac's DM_CTL "env DM_GPU_CAPTURE=..." can set it while the game runs. 60 frames in a row: a single long frame in a light scene fired the first iPhone capture.
- It captures the Metal 4 queue: Metal refuses to capture a Metal 4 device. A run that may capture (DM_GPU_CAPTURE or MTL_CAPTURE_ENABLED) builds its pipelines through the MTLDevice, because Metal cannot capture pipelines made from bases and its Metal 4 to 3 conversion for the capture layer crashed on the pipeline archive.
- iOS: DM_METAL_CAPTURE=1 when build_ipa.sh makes the project adds MetalCaptureEnabled to the app's Info.plist, without which iOS writes no GPU trace. The Mac needs MTL_CAPTURE_ENABLED=1 in the environment.
…log or an iPhone's log.txt

Per-frame totals (sum, span, idle time between encoders, draws, attachment traffic), then the mean per frame of each pass shape (size, colours, depth, pixel formats) or, with --by class, of each size class relative to the frame's largest colour pass (full, half, quarter ... per axis; passes with four colours or more, a deferred renderer's G-buffer, apart), so the split holds for every game and resolution. --timeline <frame> lists one frame's encoders in GPU order with the gaps between them; --ab gives the medians of the DM_AB phases per configuration and their difference from the base. Tested on a synthetic log (dm/tools/tests/test_gpuprof.py).
…s, development.md), and a reference entry: GPU frame captures need pipelines built through the device

05-debugging.md gets a recipe for profiling one frame in every n on the iPhone through Documents/env.txt, reading the [gpuprof] lines with dm/tools/gpuprof.py, A/B phases in one run (DM_AB) and captures for Xcode's Metal debugger. The reference entry (shaders.md, Pipelines and caches) explains why a run that may capture builds its pipelines through the MTLDevice and captures the Metal 4 queue; symptom index updated, and a line under Breath of the Wild's "Found on this game".
v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 26, 2026
…oes not reset g_px_dcu / g_px_dcc, the DM_NVN_DC_UNWRITTEN / DM_NVN_DC_COVERED latches of the diagnostic commits seedds#225 replaced (botw-fx has them, my-main does not)
v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 26, 2026
…oes not reset g_px_dcu / g_px_dcc, the DM_NVN_DC_UNWRITTEN / DM_NVN_DC_COVERED latches of the diagnostic commits seedds#225 replaced (botw-fx has them, my-main does not)
seedds added a commit that referenced this pull request Oct 26, 2026
Add periodic encoder profiles with attachment traffic and formats, alternating A/B measurement phases, bounded Metal trace capture, and gpuprof.py log summaries. Preserve main's offline pipeline-archive integration while adding the capture build setting.

Close periodic samples at frame boundaries through the last committed shared-event fence, so every:1 reports without mixing frames or reusing an unresolved heap. Add 28 CPU checks of production profiling code and include them in CI; document the mechanism and update the symptom index.

Validated with all 31 CI-style Python test files, the profiling regression, a Mac host build, and all 133 iOS source compiles. Profiling completion and heap ownership were checked with synthetic counter/event objects; no new real-GPU or gameplay validation.

Co-authored-by: v0lumehi <aljic.zijad@gmail.com>
@seedds

seedds commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Landed on main as fb20bce, after #191's benchmark commit, with Co-authored-by: v0lumehi <aljic.zijad@gmail.com>.

Included the periodic GPU profiles, A/B phases, bounded Metal captures, log summaries and documentation. Fixed DM_NVN_GPUPROF=every:1: the old report condition waited for an unselected frame, which never exists at interval 1. Periodic samples now close at a frame boundary and resolve after the last committed shared-event fence, keeping the heap protected while its report is pending. Both conflicts with main were resolved while preserving the offline pipeline-archive resource argument and capture build setting.

Validation: 28 synthetic production-code profiling checks, all 31 CI-style Python test files, the Mac host build, and all 133 iOS source compiles passed. Focused tests passed again after rebasing onto latest main. The profiling checks use synthetic counters and completion events; actual Metal callback timing and real-GPU/gameplay behavior have not been newly validated. Closing because the implementation and fixes have landed directly on main.

@seedds seedds closed this Oct 26, 2026
@v0lumehi
v0lumehi deleted the gpu-tools branch October 26, 2026 09:29
v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 26, 2026
…oes not reset g_px_dcu / g_px_dcc, the DM_NVN_DC_UNWRITTEN / DM_NVN_DC_COVERED latches of the diagnostic commits seedds#225 replaced (botw-fx has them, my-main does not)
v0lumehi added a commit to v0lumehi/nxnative that referenced this pull request Oct 26, 2026
…oes not reset g_px_dcu / g_px_dcc, the DM_NVN_DC_UNWRITTEN / DM_NVN_DC_COVERED latches of the diagnostic commits seedds#225 replaced (botw-fx has them, my-main does not)
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Add periodic encoder profiles with attachment traffic and formats, alternating A/B measurement phases, bounded Metal trace capture, and gpuprof.py log summaries. Preserve main's offline pipeline-archive integration while adding the capture build setting.

Close periodic samples at frame boundaries through the last committed shared-event fence, so every:1 reports without mixing frames or reusing an unresolved heap. Add 28 CPU checks of production profiling code and include them in CI; document the mechanism and update the symptom index.

Validated with all 31 CI-style Python test files, the profiling regression, a Mac host build, and all 133 iOS source compiles. Profiling completion and heap ownership were checked with synthetic counter/event objects; no new real-GPU or gameplay validation.

Co-authored-by: v0lumehi <aljic.zijad@gmail.com>
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.

2 participants