Skip to content

Older devices: BC views and uploads use the CPU-decoded texture - #776

Closed
bmle69 wants to merge 1 commit into
LNPANDY:mainfrom
bmle69:fix/bc-cpu-views-and-uploads
Closed

bmle69 wants to merge 1 commit into
LNPANDY:mainfrom
bmle69:fix/bc-cpu-views-and-uploads

Conversation

@bmle69

@bmle69 bmle69 commented Nov 5, 2026

Copy link
Copy Markdown

Fix or feature

  • Fix
  • Feature

What and why

With tex_bc_cpu on a GPU without BC support (A15/A16), bc-cpu-decode makes a BC texture in the format the decoder produces (RGBA8, R8, RG8, RGBA16F), but two paths in nvn_mtl.m still treated it as BC.

Abort on the first BC view. tex_by_id and clear_tex asked Metal for the view's BC format, which the device can't make, so the result was MTLPixelFormatInvalid and Metal's validation aborted (exit 134):

texture upgraded to allow format views ser=4348 base format 10 → view format 140
failed assertion `Texture Creation: texture view pixelFormat (MTLPixelFormatInvalid) not castable.
source texture pixelFormat (MTLPixelFormatR8Unorm)
bt: … tex_by_id ← encode_args_ ← draw_ ← mtl_exec ← h_nvnQueueSubmitCommands

Now a BC view of a decoded texture takes the decoded format (bc_cpu_view_pf).

Block noise on most textures. pkg_upload_ tried its GPU routes first: direct, deswizzle + blit, and the big-source buffer. Those routes copy compressed blocks unchanged, so raw BC blocks landed in the decoded texture as pixels. Only the CPU route decodes. A decoded BC texture now always takes that route.

GPUs with BC support are unchanged: bc_cpu_view_pf returns 0 when g_bc_cpu is off.

Checked

  • Tests: python3 tools/engine.py check passes (47 patches on 7249ee9f). nvn_mtl.m compiles for arm64 iOS 26 (-fsyntax-only).
  • Test for a fix: no unit test. The bug needs a Metal device without BC support (a Mac always has BC, so g_bc_cpu can't be on there). Checked on a device instead, below.
  • Run on a device: Super Mario Bros. Wonder 010015100B514000, iPhone 13 Pro (A15), iOS 27.0.1, NX2Apple 1.1.0's engine with the same change (DM_PROF_TEX_BC_CPU=1).
    • Before: abort at frame 3.
    • With the view fix only: plays, but backgrounds and menu cards are block noise.
    • With both: correct textures at 60 fps over ~13,000 frames, no texture [RED] lines.
    • The patch here is the same change rebased on main; main's new upsrc route gets the same gate.

Screenshots

None, no visible launcher change. (In-game before/after on request.)

Scope

🤖 Generated with Claude Code

Patch 0078 completes bc-cpu-decode. With tex_bc_cpu on a GPU without BC support, a BC view of a
decoded texture asked Metal for a BC format the device cannot make (validation abort), and the GPU
upload routes copied raw BC blocks into the decoded texture (block noise). Views now take the decoded
format and decoded BC textures always take the CPU route. Found on Super Mario Bros. Wonder on an
iPhone 13 Pro (A15).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the patch-queue Changes the patch queue or the upstream pin label Nov 5, 2026
@v0lumehi v0lumehi added bug Something isn't working ios iPhone or iPad labels Nov 6, 2026
@v0lumehi v0lumehi added this to the v1.2.4 milestone Nov 6, 2026
@v0lumehi

v0lumehi commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

@bmle69 thanks for the fix and for the check on a device. Two points. The issue for this crash is #732 (v1.2.4), please link it in the PR. And #446 changes the same area (views and uploads of CPU-decoded BC textures). Please say how this PR relates to #446, so the maintainers can decide which one to take.

@Sword-Wen

Sword-Wen commented Nov 6, 2026 •

Copy link
Copy Markdown

A15 / 4 GB, a second title: same three states, 50,665 frames, no abort

iPad mini 6 (A15, 4 GB), iOS 27.2 (24B119), engine 641d1480 (the 1.1.0 pin), DM_PROF_TEX_BC_CPU=1. The series does not apply on this pin, so I applied the equivalent change by hand - the same two gates, on tex_by_id / clear_tex and on the upload route. Read this as direction-level confirmation, not as a build of this branch. Title: 01008CF01BAAC000 (Echoes of Wisdom) - a different engine generation from Wonder, so the same three states showing up again is worth a line.

state result
1.1.1, as reported in #732 aborts: base format 30 → view format 142 (BC5_RGUnorm → MTLPixelFormatInvalid)
views only no abort, 60 fps, every BC surface is block noise
views + upload gate correct

Before - views fixed, upload still GPU. Hearts, HUD and 2D art are fine; only BC surfaces are wrong, which is why it reads as "textures broken" rather than "renderer broken":

before

After - same room, same build, decoded textures forced onto the CPU route:

after

Why the middle state belongs in the PR description. tex_desc already allocates the decoded format, so while the GPU route stays open, the deswizzle copies compressed block rows into an uncompressed texture: one 8-byte BC1/BC5 block becomes one RGBA8 texel, so a 4×4 block collapses to a single speckle at quarter scale - exactly the pattern above. 0078 already gates all three routes (direct, the big-source buffer, use_gpu), so this is not a request to change the patch. It is a note that anyone who picks up only half of it gets a silently wrong image instead of an abort, and that is harder to report.

4 GB budget, one session, 940 s / 50,665 frames:

  • 0.695% dropped frames (352); p99 is 16.67 ms in 147 of 169 windows and 33.34 ms in the other 22 - every slow window misses at most one vsync, none worse
  • peak footprint 2,557 MiB (frames 28,200-28,800, one heavy area), steady ~2,150-2,200 MiB afterwards; resident 2,187 MB, GPU allocated 1,450 MB at the end. That is roughly 300 MiB under the ~2.8 GiB a foreground app gets on a 4 GB device: no jetsam, no swap growth over 15.7 minutes
  • thermal climbed 0 → 2 around frame 30,000 and stayed there; frame rate did not fall with it
  • what is left is upload, not shader work: 3,477 ms of texture upload across the whole session, worst single frame 320.8 ms for 234 textures / 49.5 MB at a region load. Run-time pipeline compilation is 16 pipelines / 548 ms, the rest comes from the prebuild archive

Two long frames (10.8 s at 144.9 s, 5.9 s at 482.5 s) are not engine work: whole frame is large while submit+present is 9.8 ms and 65.2 ms with zero pipelines and zero uploads - the app was suspended, not stalled. Ignore them when reading the max.

Check:

grep "on-screen up to frame" Documents/log.txt | grep -o "p99 [0-9.]* ms" | awk '{v=$2+0; n++; if (v>16.7) c++} END {print n" windows, "c" over 16.7 ms"}'
169 windows, 22 over 16.7 ms

On the two questions the maintainer raised: this is a datapoint for #732, and for the choice against #446 it says only that with these two gates and nothing else, two different titles on A15 run correctly and stay inside 4 GB - no startup dispatch is needed for them. Separately, #777 would land right on the 47-50 MB upload spikes above.

If an A15 run against this branch is useful before the merge, I can rebuild once it is rebased on the current pin and repeat the session.

@thehobbit85

Copy link
Copy Markdown
Contributor

Closing as superseded by #888, now merged into main at 908e4e8.

I compared this PR’s complete scope (one engine patch plus the series entry). The landed patch keeps CPU-decoded BC textures off the direct, large-source and staged GPU compressed-block upload paths, and maps sampled and clear views to the decoder’s formats. It also covers attachment/render-target views. That covers the upload/view changes proposed here, with no distinct code left to merge from this PR.

Landed implementation: https://github.com/LNPANDY/NX2Apple/blob/908e4e848fd232304381fc19d4d847fcc10fc4c2/patches/0088-nvn-decode-bc-uploads-before-copying-into-unpack.patch

The current-pin production GPU regression passed 349 checks on Apple M2 Max, all CI checks were green, and the maintainer tried the CI-built app before the GitHub merge. This does not claim a fresh current-pin A15 gameplay run. Thank you for isolating both halves of the fix, and for the additional historical device evidence in this discussion. #732 remains the linked problem report. #446 still has separate work and remains open.

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

Labels

bug Something isn't working ios iPhone or iPad patch-queue Changes the patch queue or the upstream pin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants