Skip to content

Shader split: decompress zstd in-process, so the split no longer hangs at 99% (patch of seedds/nxnative#1463) - #1037

Merged
v0lumehi merged 3 commits into
LNPANDY:mainfrom
Haseenesss:fix/837-split-zstd-in-process
Nov 9, 2026
Merged

v0lumehi merged 3 commits into
LNPANDY:mainfrom
Haseenesss:fix/837-split-zstd-in-process

Conversation

@Haseenesss

Copy link
Copy Markdown
Contributor

Fix or feature

  • Fix
  • Feature

Feature from outside: not a feature.

What and why

Fixes #837.

The shader split of Tears of the Kingdom stops for good at 303,856/304,243 files and Ocarina of Time's at 170,960/186,587, with every process idle. The process tree in #837 shows each of the 24 workers with a live, idle zstd -d -c -q child and its main thread in os.write(): the worker feeds a frame to the zstd command on stdin while capturing its stdout (unzs in dm/gfx/tools/shader_split.py), and the two end up waiting on each other's pipe.

This PR carries seedds/nxnative#1463 by Jon Page as patch 0106 (forwarded seedds/nxnative#1463), cherry-picked unchanged with its author kept. unzs decompresses frames without a dictionary in-process with compression.zstd (Python 3.14, backports.zstd before), the module the dictionary frames already go through (unzs_dict). No child, no pipe. A bounded RomFS image entry is read the same way, and an invalid stream is a red line naming the path. The patch also adds docs/reference/shaders.md#the-split-hangs-decompressing-a-large-zstd-file; sync regenerates the symptom index, so the patch leaves docs/agents/symptoms.md out. The next bump drops the patch once upstream merges #1463.

It applied with no conflict on the pin c78d7375bea9 plus the current 64 patches (#1463's base 671c68e1 is 106 commits behind the pin, and no patch here touches unzs).

New dependency: none. The zstd module is already required. build_ipa_from_nsp.py stops its preflight without compression.zstd or backports.zstd. The launcher's bundled CPython 3.13 ships backports.zstd==1.8.0 (frontend/bundled-python/requirements.txt), and the Qt front end installs it as well. The zstd command stays required for now, since nlg4_unzs still uses it (below).

Other places that pipe into an external zstd, checked across engine/ (dm/, scripts/), frontend/, frontend-qt/ and tools/:

  • shader_split.py nlg4_unzs (line 1334) has the same pattern: subprocess.run(['zstd', '-d', '-c', '-q'], input=..., capture_output=True). Saves and Rebuilds #1463 leaves it alone. It reads Next Level Games revision-4 archives only (Mario Strikers: Battle League, Luigi's Mansion 3 .data files), not the two games of Shader split freezes with every process idle (Tears of the Kingdom stalls at 303,856/304,243, Ocarina of Time at 170,960/186,587) #837, so this PR keeps the patch identical to upstream's, which lets it drop cleanly on a bump. If it ever hangs the same way, the fix is the same one line (zstd_mod().decompress(b''.join(frames))), best sent to upstream alongside Saves and Rebuilds #1463.
  • shader_split.py oodle_ask keeps a long-lived host on stdin/stdout pipes, but as request then reply: it writes the whole request, then reads. That is not the simultaneous write-and-read that blocks here.
  • scripts/build_ipa_from_nsp.py, scripts/pack_nup.py, dm/tools/nro_collect.py use the zstd module, not the command. In dm/games/profile_guess.py zstd is only a file-magic label. build_ipa_from_nsp.py names zstd only in its tool preflight. The launchers only check that the command is installed or install it.

Checked

  • Tests: python3 tools/engine.py check: 65 patches apply cleanly to c78d7375bea9. After sync: dm/tools/tests/test_split_zstd.py (4 tests) and test_docs.py OK. Every test file that imports shader_split (39 files in dm/tools/tests/ and dm/gfx/tests/, among them test_nlg4, test_size_prefixed_frames, test_shader_split_progress, test_romfs_read) OK on Python 3.15.2.
  • With the launcher's own Python (/Applications/NX2Apple.app/Contents/Resources/python/bin/python3.13, 3.13.18, backports.zstd): test_split_zstd.py OK.
  • Test for a fix: test_split_zstd.py from Saves and Rebuilds #1463. A 2 MB+ file, and the same bytes as a bounded RomFS image entry, decode with subprocess.run patched to fail. Concatenated frames, a dictionary frame through its named dictionary, truncation and a bad checksum rejected with the path. With the old shader_split.py it fails (1 failure, 2 errors), with the patch it passes.
  • Not reproduced here: a pool of 12 workers piping 4,000 zstd streams of 16 KB to 3 MB through the old subprocess.run call did not hang on this Mac (macOS 27.2, Python 3.15.2). The hang depends on timing, which a synthetic run does not catch. The evidence that this is the cause is the process tree in Shader split freezes with every process idle (Tears of the Kingdom stalls at 303,856/304,243, Ocarina of Time at 170,960/186,587) #837 and Saves and Rebuilds #1463's author's run: Ocarina of Time's split, stuck at 164,256 before, finished all 186,587 files and the game ran through Kokiri Forest.
  • Run on a device or Mac: not run with a game. Tears of the Kingdom and Ocarina of Time are not on this machine. @justinfarrar, please build Tears of the Kingdom (and Ocarina of Time if you have it) with this PR's test build (tools/try-pr <this PR>) and say whether the split now passes 303,856/304,243.

Screenshots

None, no visible change.

Scope

  • No engine file (dm/, scripts/, docs/, ref/) is added to the repository: a change there is a patch in patches/ (a commit in engine/, then tools/engine.py export, and tools/engine.py check passes), with its Upstream-Status
  • A fix to the engine or a game profile also goes to seedds/nxnative as a PR in parallel: this PR's patch says forwarded seedds/nxnative#1463
  • A change to a launcher view has before and after screenshots above (no launcher change)
  • No keys, game files or data extracted from a game in the change or the attachments

The number 0106 is a placeholder (0099 to 0105 are taken by open PRs). Whoever merges renumbers it.

🤖 Generated with Claude Code

The shader split of Tears of the Kingdom (303,856/304,243) and Ocarina of
Time (170,960/186,587) stops for good with every worker in os.write() to an
idle `zstd -d -c -q` child. Carry seedds/nxnative#1463 (Jon Page,
cherry-picked unchanged) until upstream merges it: `unzs` decompresses
frames without a dictionary with compression.zstd / backports.zstd, the
module the dictionary frames already use, so no child and no pipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Haseenesss and others added 2 commits November 9, 2026 22:25
Renumber patch to 0101, next free on main
@v0lumehi
v0lumehi merged commit f292c03 into LNPANDY:main Nov 9, 2026
17 checks passed
@Haseenesss
Haseenesss deleted the fix/837-split-zstd-in-process branch November 13, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

patch-queue Changes the patch queue or the upstream pin

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shader split freezes with every process idle (Tears of the Kingdom stalls at 303,856/304,243, Ocarina of Time at 170,960/186,587)

2 participants