Skip to content

nvn/textures: texture checks without conformsToProtocol - #1467

Closed
Xipzer wants to merge 1 commit into
seedds:mainfrom
Xipzer:tex-class-check
Closed

Xipzer wants to merge 1 commit into
seedds:mainfrom
Xipzer:tex-class-check

Conversation

@Xipzer

@Xipzer Xipzer commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

tex_mtl_'s stale sRGB / linear view check (#1069's follow-up) calls conformsToProtocol:@protocol(MTLTexture) on every serial-table object it resolves. That walks the class's protocol lists. In Breath of the Wild, at about 3,000 calls a frame, it was a third of tex_mtl_'s time (44 of 130 samples) and 1.5% of the submit thread on the Mac.

obj_is_tex keeps the answer for the last 8 classes seen. The serial table only holds NvPkg and a few texture classes, so after the first few calls it is one object_getClass and a compare. A racing reader recomputes at worst. Three other per-call checks use it too: mtl_tex_gpu_owned, the GPU-owned test and tex_upgrade's holder check.

Graphics tests pass. t_nvn aborts with the BotW profile on main as well (present snapshots on, up_owner_check from the present path), and passes with DM_PRESENT_SNAP=0.

@github-actions github-actions Bot added the nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests) label Nov 6, 2026
@Xipzer

Xipzer commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Note: I couldn't run scripts/regress.py check for this one. This Mac has Xcode 27.1 (Metal 32023.921), and the chain lock on main names 27.2's 32023.922, so the local games' shaders don't build against main's chain here. The measurements come from my integration branch, which carries the same change on a lock for 27.1. If you can run the check on your side, I'd appreciate it.

@Xipzer

Xipzer commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (04811a6); no changes besides conflict resolution (the g_red_once size line next to obj_is_tex).

FeReuss pushed a commit to FeReuss/nxnative-oot that referenced this pull request Nov 10, 2026
…rmsToProtocol: the answer is kept per class

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Texture checks without conformsToProtocol: the answer is kept per class

tex_mtl_'s stale sRGB / linear view check asked conformsToProtocol:MTLTexture of every serial-table object; it walks
the class's protocol lists. obj_is_tex keeps the answer for the last 8 classes (the serial table holds NvPkg and a
few texture classes). Also mtl_tex_gpu_owned and tex_upgrade's holder check.
@Xipzer Xipzer changed the title Texture checks without conformsToProtocol: the answer is kept per class nvn/textures: texture checks without conformsToProtocol Nov 13, 2026
@Xipzer

Xipzer commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main (2e6edda), retitled to the area/component form. own_view_drop_stale's test uses obj_is_tex; the tex_gpu_touched call site is gone on main (ab41d6a), so that part drops out.

Checked on this commit (M4 Max): host build, make -C dm/gfx/tests run (every target passes), the settings / docs / switch-table tool tests. The host tests pass except audio-device checks (t_audio's device stall here, t_audio_device on clean main in the same session).

@Xipzer

Xipzer commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

Now that this Mac has the chain lock's compiler (Xcode 27.2), scripts/regress.py check on Breath of the Wild 1.9.0, main (2e6edda) against this branch, replacing my earlier note that I could not run it:

regress.py check (full): PASS

Baseline 2e6edda4d334feaf48326407c1718cb96c43e2de 2e6edda, candidate e7f94c2cdfdaf210ad3692f938b7b15fd54a06e8 e7f94c2; Apple M4 Max, macOS 27.2.1, Xcode 27.2; 324.3 s

game status shaders (base → cand) newly failing newly building changed MSL interface (new / known) boot fps p50 frame p99 ms peak MB prepare s new RED
BOTW 01007EF00011E000 PASS 19592/19592 → 19592/19592 0 0 0 0 / 0 ok 59.7 → 59.7 18.13 → 17.5 3236 → 3206 0.21 → 0.05 0

BOTW 01007EF00011E000: PASS

  • screenshots (s: dHash bits / RGB diff / baseline noise): 60: 10/5.67/0, 80: 9/5.78/0
  • baseline: exit None, first frame 2.4 s, max frame 5928, reached True, prepare 0.21 s, prebuild 203.7 s (15767 built, 0 failed), fps 59.7, p50/p99 16.67/18.13 ms, peak 3236 MB
  • candidate: exit None, first frame 2.0 s, max frame 6244, reached True, prepare 0.05 s, prebuild 169.5 s (15767 built, 0 failed), fps 59.7, p50/p99 16.67/17.5 ms, peak 3206 MB
  • time: chain 44 s, smoke 280.2 s

The route's save is my own outdoors save, not the one smoke.tsv was written with.

seedds added a commit that referenced this pull request Nov 18, 2026
Texture resolution repeatedly walks the same Objective-C protocol lists
before checking for a stale sRGB or linear view. Store the class and
conformance result in a small thread-local cache, and use the same
lookup for texture upgrades and GPU ownership checks. The cache holds
class identities without changing the lifetime of the objects checked.

The focused alias and ownership tests pass, as do the iPhone SDK compile
and documentation checks. On an M6, 800,000 comparisons across eight
workers matched the direct query, and the median warm lookup took 3.2 ns
against 74 ns for the direct query. Breath of the Wild 1.9.0 passes the
quick route with pipeline archives off on both hosts.

Co-authored-by: Xipz <60103178+Xipzer@users.noreply.github.com>
@seedds

seedds commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Landed on main in efd1bddd. The commit credits Xipz as co-author for the profiling, per-class cache design, and call sites.

The revised cache keeps eight class/result pairs per thread. Lookup misses still use conformsToProtocol:, and the three call sites keep their existing object lifetimes. This is a general NVN/Metal host optimization. It removes the repeated protocol walks without sharing mutable cache entries between callers.

On an M6, 800,000 comparisons across eight workers matched the direct query, including nil and class eviction. The isolated median was 74 ns per direct query and 3.2 ns per warm-cache lookup. Breath of the Wild 1.9.0 passed the quick regression against 083c5e4f, with all 19,592 shaders building on both sides and zero new red diagnostics. Both quick runs used pipeline archives off after the unmodified baseline stalled in Metal's archive serializer. Concurrent builds make those gameplay timings inconclusive.

The sRGB alias, texture upgrade, and dirty-upload ownership tests passed again after rebase, along with the iPhone SDK compile and docs checks. The iPhone check was compile-only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

nvn NVN on Metal and its tests (dm/gfx/nvn, dm/gfx/tests)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants