Skip to content

iPhone memory: smaller sampled textures and upload staging released on small devices, a residency probe, and the census and residency reports - #2270

Open
stan69b wants to merge 22 commits into
seedds:mainfrom
stan69b:pr/oot-iphone-smaller-textures
Open

stan69b wants to merge 22 commits into
seedds:mainfrom
stan69b:pr/oot-iphone-smaller-textures

Conversation

@stan69b

@stan69b stan69b commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

This pull request lowers what Ocarina of Time keeps resident on 8 GB devices (Metal working set under 6 GB: iPhone 17, M1 iPad, 8 GB Macs), with the measurements behind it. It is no longer stacked on #1971 and is based on main b6336876.

What it holds

  • Smaller textures. Large sampled textures (2D or 2D array, both sides 512 or more, 2 levels or more) leave out their largest level on small devices. Any use other than sampling makes the texture whole again (tex_undrop). DM_NVN_TEX_DROP_MIP=0/1 forces it off or on. On the iPhone 17: page-ins 468,772 → 32,707, 24.0 → 29.3 fps at the 30 fps cap. Test: t_tex_drop_mip.
  • Upload staging. On small devices, upload staging is released after each batch instead of kept for reuse (DM_NVN_UPLOAD_REUSE): 125 MB less resident on the iPhone 17 at the same speed.
  • Residency probe. t_res_absent and DM_RES_PROBE=1 show that a read through a pointer to a buffer outside the residency set returns zeros, on the iPhone 17 and an M4 Mac alike.
  • Census. It counts a heap once and says who holds the textures at one storage address. It also lists the set's textures by holder and by whether their pool is still alive. A texture over a buffer counts nothing in the breakdowns (res_bytes).
  • Reports. At each memory-pressure warn and critical, and once when the set passes three quarters of the working set, the host runs res_top and the census. The residency line gives a load's peaks and what is in the set by the line that added it.
  • Profile. Ocarina of Time sets pso_mtl4 on.
  • Docs. The iPhone 17 runs (Great Deku Tree, Hyrule Field, castle town, 120 loads with trims) are in the game note; memory.md entries and the symptom index are updated.

Landed on main in another form (not in this PR)

Dropped

@github-actions github-actions Bot added host The Horizon host: SVCs, services, threads, memory (dm/host) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) rewriter The NSO rewriter and per-build patches ios The iPhone and iPad app (dm/ios) mac The Mac front end and app (dm/mac, front_mac.m) tools Tools and scripts (dm/tools, scripts) docs Documentation game: 01006F8002326000 Animal Crossing: New Horizons game: 01007EF00011E000 The Legend of Zelda: Breath of the Wild game: 0400486024DEC000 A game labels Nov 11, 2026
@stan69b stan69b changed the title the iPhone 17 holds Ocarina of Time's 30 fps cap through the first dungeon: smaller textures, staging released and MetalFX for its upscaler on small devices the iPhone 17 holds Ocarina of Time's 30 fps cap through the first dungeon: smaller textures, staging released and MetalFX for its upscaler on small devices, and memory pressure frees what no frame needs Nov 12, 2026
@stan69b
stan69b force-pushed the pr/oot-iphone-smaller-textures branch 4 times, most recently from fb30479 to b8cb0bd Compare November 12, 2026 19:26
@stan69b
stan69b force-pushed the pr/oot-iphone-smaller-textures branch from b8cb0bd to 394a678 Compare November 16, 2026 15:21
@stan69b

stan69b commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main, stacked on the rebased #1971 (its first 37 commits are #1971's).

Dropped because main already has it: c5a352e (MetalFX draws the agl_ndsr_vr* packs). Main's 9e0ddee (#1459) covers every NDSR pack, including the squared input.

Adapted to main:

Added one commit: it restores three of main's rows in docs/env_switches.tsv that the rebase had dropped.

@stan69b

stan69b commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main 31b537f, stacked on the rebased #1971 (its first 37 commits are #1971's).

Adapted to main:

Checked on the rebased tree: the Mac host builds for Ocarina of Time. Passing: t_tex_drop_mip 184, t_pkg_evict 43, t_pkg_spare 59, t_upload_slots 307, t_upload_src 61, t_upgrade_alias 29, t_copy_alias 126, t_rt_lifetime 9, t_window_alias 25, t_res_absent, t_rt_recycle, test_oot_aspect, test_docs, test_env_switches, test_settings and test_launcher_settings. Not run: a game, and regress.py (this Mac has no Ocarina of Time libraries for main's chain 63853cc4c4e3).

@stan69b
stan69b force-pushed the pr/oot-iphone-smaller-textures branch from 394a678 to beda404 Compare November 18, 2026 10:56
seedds added a commit that referenced this pull request Nov 19, 2026
PR #2270 found guest-backed upload buffers accumulating independently
of staging. Allow an opt-in source budget at texture boundaries and
resolve the source again if staging starts a new batch. Sparse gather
addresses remain together, and completion retains each batch’s sources.
Metal readback passed with the budget disabled and at 96 MiB.

Co-authored-by: Stan Bono <3304418+stan69b@users.noreply.github.com>
@seedds

seedds commented Nov 19, 2026

Copy link
Copy Markdown
Owner

@stan69b, the opt-in upload-source budget from this PR is now on main in 31fdefeb. Could you retest this independently on the iPhone 17 with Ocarina of Time?

Use the same 31fdefeb build for both runs, first with DM_NVN_UPLOAD_SRC_MB=0, then with DM_NVN_UPLOAD_SRC_MB=96. Please keep mip quality fixed across both runs, ideally at full quality, and leave upload-staging options, frame-rate cap, dynamic resolution, shader libraries, and save at the same values. The Hyrule Field → Kakariko load would make the result comparable with the residency work in #2566.

Please report peak Metal residency, frame-time p99 around the load, and any visual or GPU errors for each run. A source-buffer breakdown or wired-memory peak would help identify whether the budget made a difference.

@stan69b

stan69b commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for landing the budget as 31fdefe. I can't get to the iPhone 17 right now, but I'll do these two runs as soon as I can:

  • Build: 31fdefe, once with DM_NVN_UPLOAD_SRC_MB=0 and once with 96.
  • Kept the same in both runs: mip quality at full, staging, cap, dynamic resolution, libraries and save.
  • Route: Hyrule Field → Kakariko.
  • Reported here: peak Metal residency, frame-time p99 around the load, and any errors.

I'll do them in the same session as the #2566 pairs so all four are comparable.

@stan69b
stan69b force-pushed the pr/oot-iphone-smaller-textures branch from beda404 to 31bcdaa Compare November 24, 2026 12:51
… where Metal's working set is under 6 GB

On a small device (the iPhone 17 and the M1 iPad, working set 5,461 MB), a texture made from the
game's data (pkg_upload_) is uploaded half size with one level fewer: Metal level k holds the
game's level k+1. This applies to 2D or 2D array textures with both sides 512 or more and 2 levels
or more, and to nothing that renders into or writes the texture (image, compressible, display,
video, linear, sparse, depth, CPU-repacked formats). The GPU's direct deswizzle writes every level,
so a dropped texture takes the staged path.

Only sampling sees the smaller texture. tex_mtl hands it out to the sampled-texture path alone
(treg_tex sets t_drop_ok), and a sampled view's levels shift by one (drop_levels). Every other use
(attachments, copies, image slots in img_binding, readbacks, upgrades) makes the texture whole
again first (tex_undrop), and from then on it stays whole (g_drop_full, keyed by its storage).
tex_upgrade carries the mark to a format view of a sampled texture. Shaders that fetch texels, ask
the size or pick an explicit level read the smaller texture.

The memory report counts dropped textures and MB saved, textures made whole by caller line, and
candidates by their largest side (256 / 512 / 1024 / 2048+), so a run shows what each threshold
would save. DM_NVN_TEX_DROP_MIP=0/1 forces it off or on.

Test: t_tex_drop_mip (177 checks: the device rule, level shift by the CPU and the GPU paths, a
2D array, a re-upload, whole again after another use, kept textures, view levels).
t_direct_upload, t_view_levels, t_pfv, t_upgrade_alias, t_upload_slots and check_t_window_alias
pass. test_env_switches already fails on iphone-a for other switches (DM_NVN_HEAP_RELAXED,
DM_NVN_SUB_DRAIN, removed ones); the new row is not among them.

Rebased onto main's partial re-upload (pkg_written, up_copy_add) and its reup_note: a texture
that leaves out its largest level is re-uploaded whole, as before that change, since the written
images and the copies from the texture it replaces count Metal levels from the game's level 0. tex_undrop calls main's pkg_upload with its eight
arguments, marks the package read whole (part, lost_gen) and notes its serial with own_note, main's
name for ser_note.

Restacked onto main ffb06d6 without seedds#1971: main's staged upload now takes up_big_src with its
may_split argument and falls back to the CPU when the new batch's source is refused; the level
loop over it starts at the dropped level as before. tex_mtl_replay_ref stays for main's
t_upgrade_alias as a call of tex_mtl_replay_at with line 0 (beda404 folded in). The Makefile and
env_switches.tsv keep main's rows that the earlier rebase had dropped (7a37224 is no longer
needed).
…ure whole, and the memory report counts why textures stay whole

On the iPhone 17, smaller textures dropped none in Ocarina of Time: 1,003 of the uploads of 256
and more were refused for write usage, because the game gives its material textures
NVN_TEXTURE_FLAGS_IMAGE (img_usage then adds ShaderWrite); 165 more had one level, and 2 were of
another type. A shader writes such a texture only through an image slot, and img_binding already
makes a dropped texture whole first (tex_undrop), as an attachment does. So only render-target
usage and the compressible, display and video flags keep a texture whole now.

The memory report gets a line of the textures kept whole, by the first rule they fail (type, one
level, samples / linear / repack, sparse pool, render-target usage, flags with their bits, depth,
made whole before).

Test: t_tex_drop_mip 184 checks. An image-flagged texture is dropped when sampled, and made whole
with its write usage for another use.

(cherry picked from commit d78ddfa)
…e iPhone 17's A/B (page-ins 468,772 → 32,707, 24.0 → 29.3 fps at the 30 fps cap), the symptom index and a line in Ocarina of Time's note

The reference entry "Large sampled textures leave out their largest level on small devices",
which the code comment above drop_wants already names: the symptom (the guest paged back from
disk through play), the cause (each texture made from the game's data held twice, as guest bytes
and as a Metal texture), the rule and what keeps a texture whole, and the result.

A/B on the iPhone 17: prmem_off (DM_NVN_TEX_DROP_MIP=0) against prmem_on (the default), portrait,
30 fps cap, dynamic resolution on, frames 6,000-22,500, scripted by the work folder's
m-run/iphone_cam.sh. 672 textures dropped, 396 MB saved, none made whole again; 24.0 → 29.3 fps,
late frames 110 → 12 per 300, windows over 60 ms 47 → 3 of 56, page-ins 468,772 → 32,707,
resident 3,321 → 2,769 MB, headroom 2,822 → 3,374 MB, no visible blur. 8 GB Macs may also fall
under the 6 GB rule; the entry says so.

Restacked onto main without seedds#1971: the game note's line sits in main's "Found on this game", the
entry's links point to the note's Memory section (main's note has no "For an iPhone or iPad build"
section), and the symptom index is regenerated with docs_symptoms.py.
… is under 6 GB, the rule of smaller textures: 125 MB less resident for Ocarina of Time on the iPhone 17 at the same speed

Each of the three upload slots keeps its staging after a batch completes (a primary block grown to
the slot's demand and one overflow, up to 192 MB), so that a scene's load does not allocate and
retire blocks every frame. In play a game uploads a few MB per 300 frames, and on a small device
the blocks stay resident for nothing. up_reuse now defaults to the original one-block policy where
small_working_set holds (the helper drop_wants uses: the iPhone 17, the M1 iPad, 8 GB Macs), with a
log line at the first upload; the Mac's default is unchanged. DM_NVN_UPLOAD_REUSE=0 / 1 still forces
either way.

Measured on the iPhone 17 (r1_base against r1_reuse0, DM_NVN_UPLOAD_REUSE=0, landscape, 30 fps cap,
dynamic resolution on, frames 6,000-22,500, smaller textures on): resident 2,709 → 2,584 MB,
footprint 2.63 → 2.51 GB, headroom +125 MB, speed unchanged (29.1 against 29.2 fps, frame p50
34.0 ms both, 19 against 18 late frames per 300). That build had the reuse off on every device
(iphone-exp 239f3ae1); this commit gates it by the working-set rule instead. Open: releasing only
once uploads have gone quiet, which would keep reuse for a small device's loads.

Test: t_upload_slots checks the rule (5,461 MB releases; 6 GB, 12,124 MB or none keeps) and now runs
with reuse forced on and off, so it no longer depends on the Mac's memory. t_upload_slots (also with
DM_NVN_TEX_DROP_MIP=1), t_upload_budget, t_tex_drop_mip, t_direct_upload, t_pool_standin,
t_view_levels, t_pfv, t_upgrade_alias and t_upscaler_mfx pass; test_env_switches and test_docs
pass. Docs: a memory.md entry, the switch's row, the comment above UP_BLOCK_SIZE, a game-note line.

Restacked onto main without seedds#1971: main already defines small_working_set for its sweep of idle
uploaded textures (pkg_sweep, d08d7da); the one definition now sits with the rule of smaller
textures, before its first use, and pkg_sweep uses it from there. up_reuse sits beside main's
upload-source budget (31fdefe). The memory.md entry points to main's opt-in idle trim
(DM_NVN_UPLOAD_IDLE_MS) and the memory-pressure trim instead of an open item, its link goes to the
note's Memory section, and env_switches.tsv keeps main's DM_NVN_UPLOAD_IDLE_MS and
DM_NVN_UPLOAD_SRC_MB rows around the changed DM_NVN_UPLOAD_REUSE row.
…ree to the Kokiri Emerald at the 30 fps cap, with the eight runs behind it, what did not help, frame generation and what is open

A dated entry under "For an iPhone or iPad build": the build (smaller textures, staging released,
MetalFX for the upscaler, DM_SCREEN_PIXELS=1; branch iphone-exp, chain 39eb2f781d07, PR seedds#2241's
frame generation for part of the play), a table of r1_base, r1_reuse0, r1_chunk256, r1_nocomp0,
r2_mfx_game, r2_mfx_on, b2_play1 and b2_play2 over frames 6,000-22,500, made from the logs. r2_mfx_on
is marked as what it was: MetalFX refused every variant before the square-root shape.

Not this: DM_GUEST_FILE_CHUNK=256M (noise) and DM_NVN_FAMILY_NOCOMPRESS=0 (no gain; the rule
protects the M1 iPad from a GPU hang). Frame generation: 9,000 frames generated with no restart, the
boss at 29.3-29.9 fps shown at 60. Open: the movie cutscenes at 15-18 fps (nn::ndve's network
35-70 ms of GPU), the freeze at a scene state's first visit, the empty CPU profile (seedds#2197) and
DM_MEMSTAT on iOS.

Restacked onto main without seedds#1971: main's note has no "For an iPhone or iPad build" section (it
came with seedds#1971's docs, which main did not take), so the entry opens a new subsection, "iPhone 17
runs", at the end of the note's Memory section. DM_SCREEN_PIXELS is not on main (its commit,
a2bf2c5, needed seedds#1971's screen-shape hooks), so the build's list names it as the branch's switch
instead of linking the Screen shape section.
…a buffer outside the residency set (t_res_absent, DM_RES_PROBE=1)

The raw pool table makes every pool it lists resident, because a shader reaches pools through
pointers loaded from memory, which Metal cannot see. Whether a pool could stay out of the set
until a shader needs it depends on what such an access does. nvn_res_probe.inc measures it: a
Metal 4 queue with the residency set on the queue, as the host has it; a no-copy shared buffer
(anonymous memory or a shared file mapping, as the game's memory is on iOS) read or written
through a pointer held in a resident argument buffer; never resident, evicted (at once, after 32
commits, after 2 s), another buffer over the same pages resident, made resident late, against
resident controls.

Apple M4, macOS 27.2: no case faults the command buffer. A read of a buffer that was never
resident returns zeros, and a write is dropped. A buffer removed from the set still reads
correctly after 32 commits but no longer after 2 s. A buffer added after a zero read reads
correctly from the next commit. A second buffer over the same pages does not help (each buffer
has its own GPU address).

dm/gfx/tests/t_res_absent runs it on the Mac. The host runs it once at start with DM_RES_PROBE=1
(mtl_init, its own queue and set, "[res-probe]" lines) to measure the iPhone. The probe keeps its
feedback dispatch queue for good, as the host does: freed with the probe's queue, it was released
once too often (SIGTRAP in _os_object_release).

(cherry picked from commit dbe335e)
…sidency set returns zeros, measured on the iPhone 17 as on an M4 Mac

memory.md gets a new entry: no command buffer error in any case. A buffer never in the set reads
0 and drops writes (anonymous memory, a shared file mapping, file pages only in the cache).
Another buffer over the same pages does not help. A removed buffer still reads after 32 commits
and reads 0 after 2 s, and a buffer added late reads from the next commit. So residency on demand
learnt from a shader's log would draw the first frame that reaches a pool from zeros and lose its
stores, with nothing to tell. The pools stay resident: no load log, no chain change. A line in
Ocarina of Time's note, and the symptom index.

Restacked onto main without seedds#1971: the note's line goes into main's "Found on this game" alone,
without the seedds#1971 lines it sat beside.
…extures at one storage address

mem_census (DM_CTL restop) summed each texture's allocatedSize over the textures at one storage
address. Textures placed in one heap share its bytes, so a resolution family of 36 sizes in one
15 MB heap counted as 490 MB. On Ocarina of Time at the field's edge (16 GB Mac, 2560x1440) the
line said 1,131 MB of duplicates, 1,089 MB of them family members; counted by allocation, a heap
once, the same route reads 78-122 MB. The line now gives both figures.

A new line gives who holds those textures (live serial, finalized serial, pin, sharing table,
live or retired descriptor), whether they are resident and where their memory is (own recycled
heap, family heap, span heap), and one gives their sharing-table entries by submissions since a
lookup last found them. In Ocarina of Time every such texture is held by a live texture object
of the game's: the game keeps up to 67 sizes of one shadow target at one address and never
finalizes them, so alias_take_over keeps them as it should. 64 MB of the remaining 85 MB is one
4096x4096 target seen as Depth32Float and R32Float.

Gathering the copies made outside a family's heap into it (tried: their serials and views
dropped when a fresh family heap was made) changed nothing measurable on the same route (85-86
MB after, 78-82 before) and loses a copy's own bytes, so it is not part of this.

Rebased onto main's resource owner (nvn_owner.m): the census asks it who holds a texture
(own_shared_locked, and two new accessors, own_ghost_holds_locked and own_alias_seen_locked) and
walks the sharing table with own_alias_each_locked instead of reading its tables.

Restacked onto main without seedds#1971: main has no span heaps (seedds#1971's 32 MB shared heaps, which gave
NvImageHeap its window flag, were held back), so the holders line has no "w" mark; a resolution
family's heap is "f".
…gest size after a commit, the most file pages wired before one commit, and the most bytes of upload reads over guest memory at once

The 300-frame residency line now adds:
- "at most N MB after a commit": the residency set's largest size after any commit since the last
  line (read under g_res_commit_mu), so a load that passes between two lines shows;
- "at most N MB before one commit" in the file-backed clause: the most guest-file bytes wired by
  file_wire for one commit;
- "upload reads over guest memory at most N MB at once": the bytes of up_big_src's zero-copy
  buffers in the set at once, counted per upload batch whether a budget is set or not, and taken
  out when the batch's staging leaves the set.

On the iPhone 17 the field's load had added 732 MB of these reads within 300 frames; on a 16 GB
Mac's field route they peaked at 226-233 MB at once, the set at 4,312-4,316 MB, and up to 867-874
MB of file pages were wired before one commit, from pools made resident (gmem_map), not from the
reads.

Restacked onto main without seedds#1971, and reduced: the budget this commit first added
(up_big_budget, DM_NVN_UPLOAD_SRC_MB, default 96 MB) is on main in its own form as 31fdefe
(up_src_budget, opt-in, default 0, with the source resolved again when staging starts a new batch),
so only the residency line's peaks remain. They sit in main's res_commit_retiring and
mtl_res_stats; the per-batch count (g_up_big_batch) is kept beside main's g_up_src_bytes, which
counts only while a budget is set, and leaves g_ubs_live after res_commit_retiring retires the
batch's staging. t_upload_src's line that turned the budget off is dropped: main's default is off.
…load reads' budget, the census by allocation, and the iPhone 17's death entering Hyrule Field

Restacked onto main without seedds#1971, and reduced. Main already has two of the three memory.md
entries in its own words: "Idle uploaded textures, re-upload spares, and memory-pressure trims"
(d08d7da) has the proc-thrashing death at 67 MB free with the headroom at 2.7 GB and the pressure
trim, and "Guest texture source buffers accumulate within an upload batch" (31fdefe) has the
upload reads' budget. Those two entries are dropped here; main's budget entry gains a "Peaks"
bullet with the residency line's peaks and the Mac's result at 96 MB (it did not bind). The census
entry is kept. The game note's run goes into its "iPhone 17 runs" subsection with links to main's
entries, its "Found on this game" keeps only the census line, and the symptom index is
regenerated. The census entry's last sentence, about the span heaps of seedds#1971's 32 MB
shared heaps (held back from main), is left out.
…ule Field to the castle town, which thrashes under 10 fps

Restacked onto main without seedds#1971: the run is in the note's "iPhone 17 runs" subsection, and the
"Found on this game" line it changed is left out, as its memory.md entry is main's "Idle uploaded
textures, re-upload spares, and memory-pressure trims" (d08d7da), which the note already lists.
…e 17 thrashed at under 1 fps with 6.19 GB wired: the death is not fixed

Restacked onto main without seedds#1971: the run is in the note's "iPhone 17 runs" subsection, and the
"Found on this game" line it changed is left out, as its memory.md entry is main's "Idle uploaded
textures, re-upload spares, and memory-pressure trims" (d08d7da), which the note already lists.
…rashing 11 minutes in, back on the field after the castle town

Restacked onto main without seedds#1971: the run is in the note's "iPhone 17 runs" subsection, and the
"Found on this game" line it changed is left out, as its memory.md entry is main's "Idle uploaded
textures, re-upload spares, and memory-pressure trims" (d08d7da), which the note already lists.
…re event and once past three quarters of the working set after any commit, and its line gives what each source line holds

The iPhone 17 is ended for proc-thrashing, with no GPU error, so no log of it had a residency
breakdown: the one-time res_top at three quarters of Metal's working set (4,096 MB) was checked
only at the 300-frame line, which read 4,059 MB at most while the set passed 4.4 GB between lines.

- res_commit checks the three-quarters line after each commit.
- A memory pressure warn or critical runs res_top and mem_census, each level at most once a
  minute. Both reports run on a utility queue (res_report): res_commit is called with g_mu held
  on some paths, and the census takes it.
- The residency line adds what is in the set now by the line that added it (adds less removals,
  the eight largest) and each one's change since the last line, so a load's leftovers show.
- The 300-frame line's buffer for it grows from 400 to 1,400 bytes: the upload reads' figure was
  cut off on the phone.

Mac reproduction (16 GB M4, guest in files, DM_NVN_WINDOW_ALIAS=1 DM_NVN_TEX_DROP_MIP=1, the
field save, then four tunnel / Kokiri Forest round trips): the set was 3.46 GB on the field,
4.23 GB after the first load into the forest (the 12288x12288 Depth16 target's own 296 MB heap,
+149 MB of textures uploaded from pools, other targets outside the spans), then 4.26-4.28 GB in
the forest and 4.37-4.39 GB in the tunnel, 5-15 MB more per round trip. The set grows on each
new area's first load and does not grow with going back and forth.

Rebased onto main 0c07813: res_add_at and res_remove count each source line's bytes (rs_live_add) beside main's queued changes and set no g_res_dirty; res_commit takes the set's size after its commit under g_res_commit_mu and checks the three-quarters line after releasing it (res_report takes no lock).

Restacked onto main ffb06d6 without seedds#1971: main's memory-pressure source (d08d7da) runs
res_top and mem_census through res_report at each warn and critical; the three-quarters check sits
at the end of main's res_commit_retiring, after its slow-commit line. Main never had seedds#1971's
one-time three-quarters res_top at the 300-frame line, so this commit adds the check rather than
moving it. The power line's buffer for the residency line is 1,400 bytes, as before. g_res_line,
the map from each object in the set to the line that added it, is declared here: it came with
seedds#1971's res_top additions.
…ency set and whether its pool lives, and textures over a buffer count nothing in the set's breakdowns

- res_bytes: a texture made over a buffer (tex_linear's linear textures over their pool's
  buffer) is that buffer's memory. MTLResidencySet counts it once (measured: an 8 MB buffer and
  31 textures over it read 8 MB in allocatedSize), but res_top, the additions by line and the
  set by line summed each texture's allocatedSize, the whole buffer. Ocarina of Time keeps 31-64
  linear targets over one 8 MB pool (flags 0xa2): the iPhone 17's "line 4926: 64, 512 MB" back on
  the field was memory the set did not hold. The set's own total was always right.
- mem_census adds the set's textures by the line that added them, by holder (live serial,
  finalized serial, pin, sharing table, live or retired descriptor) and by whether the memory
  pool of their storage still exists. Uploaded textures now keep their storage range for it
  (g_tex_up_key, apart from res_top's GPU-made textures).

What accumulates on the Mac reproduction (field, Kokiri Forest, back in the tunnel): textures
uploaded from guest memory (the upload's res_add), 1,176 / 1,713 / 1,935 of them, 467 / 634 /
829 MB, all named by live descriptors of texture objects the game has not finalized, in pools
that still exist. They are the game's own live textures; on NVN they cost nothing beyond their
pools, here each is a Metal copy. Nothing in the host holds one after the game lets it go: 17-23
textures (10-12 MB) are named by nothing. Freeing the copies would be an eviction of host
copies of live textures (serial table, packaged entry, sharing table and pool tables at once),
which is not done here.

Rebased onto main's resource owner (nvn_owner.m): the census asks it who holds a texture
(own_ghost_holds_locked, own_shared_locked) instead of reading its tables.

Rebased onto main 0c07813: res_add_at and res_remove count res_bytes beside main's queued changes, without g_res_dirty.

Restacked onto main ffb06d6 without seedds#1971, and reduced to what does not need seedds#1971's res_top
additions: res_top's "residency by the line that added it" and res_top_pools, and the storage
range res_top kept for GPU-made textures (g_tex_range_key), came with seedds#1971 and are not on main.
res_bytes counts in main's res_add (the additions by line), in the set by line, in res_top's
totals and in the census. The census's line of every texture in the set reads the storage range
of uploaded textures only (g_tex_up_key), so a GPU-made texture shows "-" (none recorded) for its
pool.
…e Mac, the breakdowns' count of textures over a buffer, and the reports at memory pressure

The set grows on each area's first load (3.46 GB on the field, 4.23 GB in Kokiri Forest) and not with going back and forth (5-15 MB per round trip over four). What grows is Metal copies of textures the game keeps live in live pools (467 / 634 / 829 MB); freeing them would be an eviction of host copies, not done. The raw-table-only pools (710-778 MB) stay: no safe rule leaves them out.

Restacked onto main without seedds#1971: the reports at memory pressure (res_top and the census at each
warn and critical, the three-quarters check after each commit, the set by line) go into main's
entry "Idle uploaded textures, re-upload spares, and memory-pressure trims" as a "Reports" bullet,
since main's entry replaced the one this commit extended. The breakdowns entry links the note's
Memory section; the note's run says that DM_NVN_WINDOW_ALIAS=1 was seedds#1971's held-back shared
heaps; "Found on this game" keeps the breakdowns line only.
…d through the castle town and Lon Lon Ranch at 6.27 GB wired; guest pools hold 2.1 GB of its set

(cherry picked from commit 0832d01)
…der reaches: 831 of Ocarina of Time's 851 such shaders take an address through a loaded pointer or a loop, and every frame runs about 185 of their draws

Measured, nothing changed in code: the pools the raw pool table lists stay resident. The address of each raw access in the 851 translated shaders that take the table was traced back through their MSL (598 read it through a raw pointer, 233 more through a loop or branch variable, 20 only from buffer words at fixed places); the Mac's field route binds the table about 185 times a frame in every window (raw pool table words at commit).

(cherry picked from commit c680394)
…reed at memory pressure, and what stays of the raw pool table's pools

Restacked onto main without seedds#1971, and reduced: the spares' 3 s retirement and the eviction of
uploaded textures idle for 30 s are on main as d08d7da, documented in main's entry "Idle uploaded
textures, re-upload spares, and memory-pressure trims", so this commit's two memory.md entries,
their "Found on this game" lines and the DM_CTL memtrim line in 05-debugging.md (main has it) are
left out. What stays is the note's iphone-mem3 run, with its links pointing to main's entry.
…s before each, and two of the owner's runs ended at the castle

One driven process ran 60 rounds of the castle town and the field with a
memory pressure trim before each load (2.4 hours, 152,019 idle uploaded
textures freed and made again), at most 6.29 GB wired and the set at
4.43 GB. The owner's first run stopped drawing at the castle entrance's
load with the sound on, the residency commit freeze's signs; the second
ended at the castle gate with no report. Both are open in the game note.

Restacked onto main without seedds#1971: the runs go into the note's "iPhone 17 runs" subsection; the
memory.md change (a blank line moved around the census entry's heading) is already right on the
restacked branch, so memory.md is unchanged.
…pipelines through the Metal 4 path with the pipeline archive made offline and the hybrid pipelines

Through the MTLDevice, each render pipeline first drawn in a scene state the phone had never
drawn compiled on the submit thread: on an iPhone 17 in Kokiri Forest after the first boss,
about 17 pipelines of about 400 ms each made 8 frames of 0.17-1.26 s (6.0 s in all), every wait
"hybrid off". The archive for applegpu_g18p holds every pair's pulling base (30,690) and a
pipeline per compute shader (4,125): 3,501 MB, 28.5 min of metal-tt on the Mac.

From the experiment commit 7e5d12c6 (the game.tsv lines), on main's key: main has the launcher's
setting (DM_PSO_MTL4) and the fix for pipeline bases missing from the archive (2f131ed, the
experiment's 3af843f3), not this profile's default. The game note's "For an iPhone or iPad build"
says so, and dm/games/README.md's pso_mtl4 row names the game. No shader input changes (pso_mtl4
is no shader_* / nvn_* key).

Restacked onto main ffb06d6 without seedds#1971: main's profile still leaves pso_mtl4 at its default
(off), so the key stays. The note's dated bullet sat in seedds#1971's "For an iPhone or iPad build"
section, which main does not have; it is now a row of the note's "What it needs" table.
docs/agents/game-patches.md is regenerated with docs_patches.py: it now lists the key for the game.
RED_ONCE(160) is main's. The warning that a texture which left out its largest level could not be
made whole again now has key 183, past main's highest (178). Frame generation (seedds#2582) takes
179-182, so the two do not collide whichever lands first; g_red_once is 184.

Restacked onto main ffb06d6: the key was 179 on main 31b537f (main's highest 174, frame
generation 175-178); main now uses up to 178 and frame generation moved to 179-182.
@stan69b
stan69b force-pushed the pr/oot-iphone-smaller-textures branch from 31bcdaa to a1e159e Compare November 24, 2026 13:10
@stan69b

stan69b commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main b6336876, and no longer stacked on #1971 (closed; its core is on main as 9143b6f). The branch is now 22 commits.

Dropped because main already has them in its own form:

  • 565359f, ac881b5, 0aec3fe: memory-pressure trim, spare retirement and idle eviction, on main as d08d7da.
  • 46a5aca's budget, on main as 31fdefe. Only the residency line's peaks remain from that commit.
  • The memory.md entries those commits added; main's entries cover them.

Dropped because they need #1971 code that main did not take:

Other changes:

Checked: the Mac host builds for Ocarina of Time. Passing: t_tex_drop_mip 184, t_res_absent, t_upload_slots 307, t_upload_src 61, t_upload_budget, t_upload_idle, t_pkg_spare, t_upgrade_alias, t_pool_cow_residency 29 (main's new test), test_docs and test_env_switches. t_pkg_evict passes but is flaky on main too, and t_rt_recycle fails one check on main as well. No game was run. The description will be updated to match.

@stan69b stan69b changed the title the iPhone 17 holds Ocarina of Time's 30 fps cap through the first dungeon: smaller textures, staging released and MetalFX for its upscaler on small devices, and memory pressure frees what no frame needs iPhone memory: smaller sampled textures and upload staging released on small devices, a residency probe, and the census and residency reports Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation game: 01006F8002326000 Animal Crossing: New Horizons game: 01007EF00011E000 The Legend of Zelda: Breath of the Wild game: 0400486024DEC000 A game host The Horizon host: SVCs, services, threads, memory (dm/host) ios The iPhone and iPad app (dm/ios) mac The Mac front end and app (dm/mac, front_mac.m) nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) rewriter The NSO rewriter and per-build patches tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants