Repository navigation
Raw global memory loads through one pointer resolve its pool once, and the pool table search is a loop: Ocarina of Time's colour-pass mesh shaders stop looking up the pool table per word (chain 723dc3a3e17d) - #1752
deanpektas27 wants to merge 2 commits into
Conversation
…ve its pool once: Ocarina of Time's colour-pass mesh shaders no longer look up the pool table for every word they read, frame time p50 22.1 → 18.8 ms and p95 38.9 → 22.6 ms on an M3 Max (chain ad6a64058f5f) GlobalToStorage.ResolveRawRuns groups the raw loads whose address is a base plus a constant offset c >= 0, as the decoder builds it (low = base low + c, high = base high + carry, or the carry alone for a high word of 0), by the base's value (the same SSA values or the same pure integer operations of them). A run of two loads or more calls RawResolveRange once, at the nearest block dominating its loads, for [base + min c, base + max c + 4): the entry it chose last, else the chunk's hint, else the search, or 0 when no single entry holds the range; its delta is read there once. Each load calls the resolved helper, which moves the address by that delta with no table read, and takes the full lookup on entry 0. Stores and atomics keep the per-access path. The 11 colour-pass mesh shaders read each vertex's attributes word by word through 5 pointers: 253 to 506 lookups a thread (about 7 memory reads per word), and the pass that draws them was 5.8 ms of geometry and 0.2 ms of pixels at 683x384. After: 122 resolves, 490 resolved loads and 16 single lookups in the larger ones; that pass about 3.5 ms, the main colour pass 2.8 → 1.4-2.2 ms with more draws, GPU p50 22.0 → 17.1 ms, and the game's dynamic resolution rises above its minimum again. Measured over a longer, more varied play than the baseline, so indicative. dm/gfx/tests/test_dmsh_raw_run.py checks the translated shape and runs the two helpers on the GPU over runs inside a pool, above 4 GiB through the hint, across adjacent pools, into a gap, in a gap and at address 0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F2HonzMnSwhcWL1SPBk2PG
…earch at every raw lookup, and Ocarina of Time's compute pipelines for its foliage's reaction to a sword took 11.3 s to build the first time, a 12 s freeze; fresh builds of the slowest are 2.57 → 1.59 s and 2.33 → 1.44 s (chain 723dc3a3e17d) EmitTableSearch emits the binary search of GlobalToStorage's raw pool table as a loop of GmemMapLog2 steps, for the per-access helper and for RawResolveRange. It runs only when the last entry and the hint both missed, but Metal inlines every helper at every call site, so the unrolled form was copied hundreds of times into each shader with raw lookups, and the resolves of the previous change added one more copy each (77e64b1d8200eac3: 2.57 s unrolled, 3.71 s with the resolves, 1.59 s with the loop; its metallib 508 → 290 KB). test_dmsh_raw_last.py and test_dmsh_raw_run.py read through the search on the GPU (gaps, adjacent pools, address 0) and pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01F2HonzMnSwhcWL1SPBk2PG
|
Added bf4b0fb: the pool table's binary search is now a loop ( Why. Playing on the first commit, cutting the foliage that reacts to a sword in Kokiri Forest's hidden area (where the boulder circles the chest) froze the game for about 12 s. The The four large ones ( Fresh pipeline builds (
The first one's metallib is 508 KB on main, 654 KB on the first commit and 290 KB with the loop. The search runs only when the last entry and the hint both miss. Not yet measured: in-game frame time with the loop. Still open, a separate host matter: compute pipelines are built on the submit thread at their first dispatch. A shader the prewarm list doesn't hold still pauses the game for its build, now about 40% shorter than on main. The regression report above predates both this commit and the rebase. The 2,247 changed shaders are the same set. |
…chain header (chain 48f5dda3c8ff) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
A data point from our tree: there, vertex shaders already read raw memory 16 bytes at a time (four adjacent words as one load), and this PR's task/mesh-only port showed no measurable gain in Hyrule Castle Town (A/B, 2 walks before, 3 after, M4 Pro). Main has since made 64- and 128-bit raw loads one vector load (04419bc), so a measurement on current main would be the one that counts. |
…ument, dynamic table count, hint words 6/7): loads through one pointer at constant offsets resolve their pool once; main's 64/128-bit vector loads keep their helper; a resolved range whose end wraps past 2^64 takes entry 0 (the per-access path)
…ites is rewritten too (the value keeps its flush; the add is Metal's); raw-load tests follow seedds#1663's table (count in entry 0, hint words 6 and 7, pointer site argument), and the seedds#1752 GPU test adds a run whose end wraps past 2^64
…1752, ported onto vector loads) loads and seedds#1813's miss zeroing: a vector load joins its base's run and reads through RawResolvedV2/V4; a lone vector load keeps its own helper. Chain 64cad52bbad5.
…eedds#1663 with PR seedds#1752 ported onto them (pointer sites, dynamic table counts, 128-bit raw loads as one vector load), BarrierExits (a compute thread that returns before a barrier keeps arriving at the later ones), float atomic adds and the other Ryujinx changes this branch carries; dmsh_xlate rebuilt from these sources and dmsh_chain.lock updated
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section.
…e pointer resolve their pool once; seedds#1585's site path joins EmitAccess) Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR): - seedds#1585 by nafields (open): Raw global memory through a pointer read when the draw is bound: the host fills each fixed-offset pointer's pool range before the draw (chain 1ffcb6b77740) - seedds#1751 by deanpektas27 (open): DM_NVN_GPUPROF_GEOM: split each render pass's GPU time into geometry and pixels - seedds#1752 by deanpektas27 (open): Raw global memory loads through one pointer resolve its pool once, and the pool table search is a loop: Ocarina of Time's colour-pass mesh shaders stop looking up the pool table per word (chain 723dc3a3e17d)
…s), the resolved helper takes (lo, hi, site, entry, delta): without this no run was resolved; the two raw tests take the site Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR): - seedds#1585 by nafields (open): Raw global memory through a pointer read when the draw is bound: the host fills each fixed-offset pointer's pool range before the draw (chain 1ffcb6b77740) - seedds#1752 by deanpektas27 (open): Raw global memory loads through one pointer resolve its pool once, and the pool table search is a loop: Ocarina of Time's colour-pass mesh shaders stop looking up the pool table per word (chain 723dc3a3e17d)
…), on top of the seedds#1585 site fix Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR): - seedds#1585 by nafields (open): Raw global memory through a pointer read when the draw is bound: the host fills each fixed-offset pointer's pool range before the draw (chain 1ffcb6b77740) - seedds#1752 by deanpektas27 (open): Raw global memory loads through one pointer resolve its pool once, and the pool table search is a loop: Ocarina of Time's colour-pass mesh shaders stop looking up the pool table per word (chain 723dc3a3e17d)
…t raw loads as one vector load, occlusion conditions read once landed, dynamic-resolution stub; hand-merged with the seedds#1585 sites and the seedds#1752 resolved runs) Upstream pull requests applied in this commit (their authors' work, brought onto this tree with a three-way merge; the description is in each PR): - seedds#1585 by nafields (open): Raw global memory through a pointer read when the draw is bound: the host fills each fixed-offset pointer's pool range before the draw (chain 1ffcb6b77740) - seedds#1752 by deanpektas27 (open): Raw global memory loads through one pointer resolve its pool once, and the pool table search is a loop: Ocarina of Time's colour-pass mesh shaders stop looking up the pool table per word (chain 723dc3a3e17d)
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section.
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section.
…eedds#1663 with PR seedds#1752 ported onto them (pointer sites, dynamic table counts, 128-bit raw loads as one vector load), BarrierExits (a compute thread that returns before a barrier keeps arriving at the later ones), float atomic adds and the other Ryujinx changes this branch carries; dmsh_xlate rebuilt from these sources and dmsh_chain.lock updated
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section.
|
Measurements for this change from Ocarina of Time ( Port. Measured:
|
…orted onto vector loads (PR seedds#1752) the pool table search is a loop) carried onto upstream's vector loads. Source and tests only: the translator binary, dmsh_chain.lock and the chain header need a rebuild with dm/tools/native_tools.sh.
…kept-entry cache, tests take the seven kept words; DM_GFX_SCALE (chain e87f5802f90a) The port of PR seedds#1752 (AmateurWizrd's 11fa67f on main's vector loads) merged with the seven private words of the per-access lookup: a resolved helper moves by the run's delta, and its fallback lookup keeps the cache. test_dmsh_raw_run and test_dmsh_raw_last match one or more kept words and pass them in their GPU harness. DM_GFX_SCALE answers a graphics scale tier; unset, the answer follows the operation mode as before. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… tested area at 59-60 fps), DM_PRESENT_LINK=0, the graphics scale tier, the final sweep and soak Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section.
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section.
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section.
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section.
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section. (cherry picked from commit d17df17)
…d the allocator pool tried and reverted Game note, "For an iPhone or iPad build": a new current bullet for the iPhone 17 at the owner's Kokiri spot. Its table gives the GPU span, the GPU work and the gaps before and inside submissions, before and after A-2. Gameplay GPU p50 is 21-24 ms, under the cap's 33.3 ms, so shader pull requests seedds#1752 and seedds#1833 were not tried. The frame is CPU-bound at 16-20 fps under thermal state 1-2. The bullet records the uncapped A/B of A-2, and a command allocator pool of 128 that removed its waits but no frame time, at a cost of about 300 MB (not kept). Open: translation cost, samples-passed reports, footprint growth. The CPU timeline the table was measured with is a local diagnostic, not in this pull request. rendering.md: the A-2 entry gets its measured result. A Found-on line in the note, and the outdated iPhone line under "Not run on an iPhone yet" now points to the section. (cherry picked from commit d17df17)
|
Thank you @deanpektas27 for the Ocarina of Time mesh-pass profiling and for pointing out both the repeated pool lookups and the unrolled table-search compile stalls (and thanks to @FifteenPen and @AmateurWizrd for the follow-up tests). Closing this PR because both parts have now been superseded on Checking whether current |
What and why
Symptom. In Ocarina of Time (
0400486024DEC000, v131072), the colour pass that draws the game's own task/mesh geometry took about 6 ms of GPU at the minimum dynamic resolution, 683x384. Nearly all of it was geometry: 5.8 ms, against 0.2 ms after it (measured withDM_NVN_GPUPROF_GEOMfrom #1751). The same geometry in the game's depth pre-pass costs about 0.2 ms. Dropping all mesh draws (DM_NVN_SKIP_MESH=1) removed about 8 ms a frame and the 40 ms spikes.Cause. The 11 colour-pass mesh shaders read each vertex's attributes word by word through 5 pointers they load from a storage buffer. Each 32-bit load took its own trip through the raw pool table (Raw global memory lookups that start from their last entry). Even on a last-entry hit that is the entry's four bounds plus its two delta words, about 7 memory reads per word of data, at 253 to 506 loads per thread. The pre-pass versions read only the position and have 0 or 1 such load.
Change. General, in the translator (
GlobalToStorage.ResolveRawRuns), for loads only:RawValueKey): the decoder computes a pointer plus a uniform register again for each instruction.RawResolveRangeonce, at the nearest block that dominates its loads, with a base whose definition reaches that point. It finds the entry holding the whole range [base + min c, base + max c + 4): the entry it chose last, else the chunk's hint, else the search. It returns 0 when no single entry holds the range. The entry's delta is read there once.Reference entry: Raw global memory loads through one pointer that resolve its pool once. The game note has a line for it. Chain
ad6a64058f5f.In each larger colour-pass mesh shader this gives 506 lookups → 122 resolves, 490 resolved loads and 16 single lookups. The shader reloads its pointers inside each guarded block, so there is a run per block; the resolve's own last entry makes all but the first of each pointer's resolves a hit.
Checked
Tests:
dm/gfx/tests/test_dmsh_raw_run.py(DMSH_TEST_XLATE). It checks the translated shape: three loads at +0, +4 and +12 through one pointer call the range helper once, before them, then the resolved helper three times, with no per-access helper left.dm/gfx/tests/test_dmsh_*.pypass with the new translator.test_dmsh_pairs.pyneedsDM_GAMEset.tool_lock.py --check-tools,dm/tools/tests/test_nsp_chain.py,test_xlate_anycpu.pyandtest_docs.pypass.dm/tools/tests/test_env_switches.pyfails on main too, for unrelated switches. With this PR alone it would also listDM_NVN_GPUPROF_GEOM, which the reference entry names; DM_NVN_GPUPROF_GEOM: split each render pass's GPU time into geometry and pixels #1751 adds it.Game run: The Legend of Zelda: Ocarina of Time (
0400486024DEC000, v131072, Mac build), two runs on an M3 Max, both around Kakariko Village withDM_NVN_GPUPROF=every:300 DM_NVN_GPUPROF_GEOM=1: about a minute at one spot before, and a longer, more varied play after. So these numbers are indicative, not a matched A/B.[RED]kinds.Devices and OS: M3 Max (36 GB), macOS 27.0.1, Xcode 27.2.
regress.py check --games 0400486024DEC000: the only game with a local Mac build. Ocarina has nosmoke.tsvroute, so this is the static chain check only, with no boot. No other game was checked here; owners of games with raw global memory shaders (Donkey Kong Bananza's terrain and agl compute; the SDK vertex shader588e242a52f5f7aain Tears of the Kingdom and Wonder) are the ones to run it.The report was made before rebasing onto
eed7c429: baselinebd979ced, candidate this change at chain84e2efe99fef. The rebase brought only upstream's own chain change51ecd693(pixel output masks, other code), which conflicted on the generateddmsh_chain.halone. The translator tests above were run again on the rebased tree.CHANGED: 2,247 shaders' MSL changed (reflection 0, variants 1,406), the shaders with a raw lookup. That matches the reference entry's count of Ocarina shaders with such a lookup (2,241 there). No shader newly fails, and no pipeline interface changed.
Docs
docs/reference/<subsystem>.mdentry, andpython3 dm/tools/docs_symptoms.pywas rundmsh_chain.py --headerwas run anddm/gfx/nvn/dmsh_chain.his part of the change🤖 Generated with Claude Code
https://claude.ai/code/session_01F2HonzMnSwhcWL1SPBk2PG