Skip to content

NSP script: remove the shader libraries of older chain versions after a successful build - #682

Closed
v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:nsp-prune-stale-chain
Closed

v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:nsp-prune-stale-chain

Conversation

@v0lumehi

@v0lumehi v0lumehi commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Every change to the shader chain translates all shaders again into a new b-<chain> folder, and nothing removed the old ones. A Breath of the Wild build folder held b-157e1b96c8da (2.1 GB) and b-a78f966a7b38 (2.3 GB) besides the current chain, 4.4 GB of libraries nothing reads, and every upstream update that changes the chain adds another 2 GB per game.

build_shaders now calls prune_stale_chains last. It removes the b-<12 hex digits> folders of other chain versions in shader/cache (Mac) and shader/ios (iOS), and their keys (shader/ios/b-<chain>.key, shader/mac-b-<chain>.key), and logs one line: removed old shader libraries b-… (N GB). It runs only after the libraries, their tables, the regression check and the reuse key of the current chain are in place, so a build that stops or fails keeps the old libraries. A reused build prunes too, so folders left by earlier builds go at the next run.

What reads b-* folders, and why deleting the old ones is safe:

  • The host (DM_MSL_DIR, nvn_mtl.m), pack_app.py, build_ipa.sh, pso_offline.py and regress.py take only the current chain's folder.
  • shader_regressions.py compares the new build with the newest other b-*/_b_build.json. That check has run before the prune, and the next chain change compares with the folder that stays, so no report has to be moved.
  • dmsh_build.py takes the libraries of older folders into the Metal compile cache before it translates. The first build of the new chain has done that already. Only a chain that comes back (an older checkout) compiles again what the cache does not hold.
  • The Metal compile cache (dmsh_mtlcache.py, shader/cache/cas/metallib) is not touched. It is keyed by the MSL text and the compiler, not by the chain, so entries are shared across chains. It grows only with new MSL, and no code removes an entry, so it is not bounded.

Reference entry: Old shader library folders grew a game's build folder with each chain change. It is linked from the Breath of the Wild note, and the symptom index is updated.

Checked

  • Tests: all dm/tools/tests/test_*.py pass. New in test_nsp_mac.py: two old chains removed and the current kept, a failed build and a build without libraries keep everything, other names (cas, a file, a malformed name) stay. dm/tools/lint_python.py: 0 new findings.
  • Games run, with title ID and version: none, the change touches only the build folder after a finished shader build. The 4.4 GB is the size of the two old chain folders in a real Breath of the Wild build folder (measured with du), the removal itself is tested on fake folders.
  • Devices and OS: Apple silicon Mac, macOS 26.
  • Regression check on games: not run, no chain tool, host or translation output changes.

Docs

  • The finding is in its docs/reference/shaders.md entry and the game note, and python3 dm/tools/docs_symptoms.py was run (the symptom index)
  • A chain tool changed: not applicable
  • No game files, keys or data extracted from a game in the change or the attachments

… a successful build

Every change to the shader chain translates all shaders again into a new b-<chain> folder, and nothing removed the old ones: a Breath of the Wild build folder held b-157e1b96c8da (2.1 GB) and b-a78f966a7b38 (2.3 GB) besides the current one, and each upstream update added another.

build_shaders now calls prune_stale_chains last, after the libraries, their tables, the regression check and the reuse key of the current chain are in place (a reused build prunes too). It removes the b-<12 hex digits> folders of other chains in shader/cache and shader/ios and their keys (ios/b-<chain>.key, mac-b-<chain>.key), and logs one line with the freed size. A build that stops or fails earlier keeps the old libraries. Nothing else reads an old folder: the host and the packers take only the current chain, shader_regressions.py compares with the next chain's predecessor, which is the folder that stays, and the Metal compile cache already took the old libraries in. The compile cache is not touched.

Tests in test_nsp_mac.py: two old chains are removed and the current one stays, a failed build and a build without libraries keep everything, other names (cas, a file, a malformed name) stay. Reference entry in docs/reference/shaders.md, the Breath of the Wild note and the symptom index.
tmrsm pushed a commit to tmrsm/NX2Apple that referenced this pull request Oct 29, 2026
…Free space

Every change to the shader chain translates all shaders again into a new b-<chain> folder, and nothing removed the old ones. A Breath of the Wild build folder held two (2.1 GB and 2.3 GB, 4.4 GB together), and each upstream update adds another.

Patch 0032 (forwarded as seedds/nxnative#682): after a successful shader build the NSP script removes the b-<old> folders in shader/cache and shader/ios and their keys, and logs the freed size. A failed or stopped build keeps them.

The Mac launcher's Free space sheet gets an "Old shader versions" row for folders that were left before this change or by another checkout. It lists the b-<12 hex digits> folders (and keys) that are not the current chain, with their sizes, and removing them costs nothing on the next build. The current chain is DMSH_CHAIN in the checkout's dm/gfx/nvn/dmsh_chain.h, read as the NSP script's chain_of() does. Without it nothing counts as old. The Shader output row stays as it is, and choosing both counts the old versions once. Strings in zh, en and sv, and the Qt table regenerated (the Qt front end has no Free space feature).
seedds added a commit that referenced this pull request Oct 30, 2026
… a successful build (PR #682)

Every change to the shader chain translates all shaders again into a new b-<chain> folder, and nothing
removed the old ones: a Breath of the Wild build folder held b-157e1b96c8da (2.1 GB) and b-a78f966a7b38
(2.3 GB) besides the current one, and each upstream update added another.

build_shaders now calls prune_stale_chains last, after the libraries, their tables, the regression check
and the reuse key of the current chain are in place (a reused build prunes too). It removes the
b-<12 hex digits> folders of other chains in shader/cache and shader/ios and their keys
(ios/b-<chain>.key, mac-b-<chain>.key), and logs one line with the freed size. A build that stops or
fails earlier keeps the old libraries. Nothing else reads an old folder: the host and the packers take
only the current chain, regress.py builds its chains in the work folder, shader_regressions.py compares
with the folder that stays, and the Metal compile cache already holds what the old libraries compiled.
The compile cache is not touched.

A folder that cannot be removed (a permission error, a locked file) is a [RED] line, not an error: the
build is done, and the next one tries again.

Tests in test_nsp_mac.py: two old chains are removed and the current one stays, a failed build and a
build without libraries keep everything, a removal that fails keeps the build, other names (cas, a file,
a malformed name) stay. Reference entry in docs/reference/shaders.md, the Breath of the Wild note and
the symptom index.

Co-authored-by: v0lumehi <[email protected]>
@seedds

seedds commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Landed on main as 8b06fab, with you as co-author. Thank you: the pruning, its tests and the docs are yours and almost unchanged.

One addition: a folder that cannot be removed (a permission error, a locked file) now logs a [RED] could not remove old shader libraries … line instead of failing the build, since the build is already done at that point and the next one tries again. test_failed_prune_keeps_the_build covers it. All tool tests and the lint ratchet pass.

@seedds seedds closed this Oct 30, 2026
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
… a successful build (PR seedds#682)

Every change to the shader chain translates all shaders again into a new b-<chain> folder, and nothing
removed the old ones: a Breath of the Wild build folder held b-157e1b96c8da (2.1 GB) and b-a78f966a7b38
(2.3 GB) besides the current one, and each upstream update added another.

build_shaders now calls prune_stale_chains last, after the libraries, their tables, the regression check
and the reuse key of the current chain are in place (a reused build prunes too). It removes the
b-<12 hex digits> folders of other chains in shader/cache and shader/ios and their keys
(ios/b-<chain>.key, mac-b-<chain>.key), and logs one line with the freed size. A build that stops or
fails earlier keeps the old libraries. Nothing else reads an old folder: the host and the packers take
only the current chain, regress.py builds its chains in the work folder, shader_regressions.py compares
with the folder that stays, and the Metal compile cache already holds what the old libraries compiled.
The compile cache is not touched.

A folder that cannot be removed (a permission error, a locked file) is a [RED] line, not an error: the
build is done, and the next one tries again.

Tests in test_nsp_mac.py: two old chains are removed and the current one stays, a failed build and a
build without libraries keep everything, a removal that fails keeps the build, other names (cas, a file,
a malformed name) stay. Reference entry in docs/reference/shaders.md, the Breath of the Wild note and
the symptom index.

Co-authored-by: v0lumehi <[email protected]>
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