Repository navigation
Shader split: decompress zstd in-process, so the split no longer hangs at 99% (patch of seedds/nxnative#1463) - #1037
Merged
Conversation
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>
1 task done
…-process # Conflicts: # patches/series
Renumber patch to 0101, next free on main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix or 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 -qchild and its main thread inos.write(): the worker feeds a frame to thezstdcommand on stdin while capturing its stdout (unzsindm/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.unzsdecompresses frames without a dictionary in-process withcompression.zstd(Python 3.14,backports.zstdbefore), 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 addsdocs/reference/shaders.md#the-split-hangs-decompressing-a-large-zstd-file;syncregenerates the symptom index, so the patch leavesdocs/agents/symptoms.mdout. The next bump drops the patch once upstream merges #1463.It applied with no conflict on the pin
c78d7375bea9plus the current 64 patches (#1463's base671c68e1is 106 commits behind the pin, and no patch here touchesunzs).New dependency: none. The zstd module is already required.
build_ipa_from_nsp.pystops its preflight withoutcompression.zstdorbackports.zstd. The launcher's bundled CPython 3.13 shipsbackports.zstd==1.8.0(frontend/bundled-python/requirements.txt), and the Qt front end installs it as well. Thezstdcommand stays required for now, sincenlg4_unzsstill uses it (below).Other places that pipe into an external zstd, checked across
engine/(dm/,scripts/),frontend/,frontend-qt/andtools/:shader_split.pynlg4_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.datafiles), 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.pyoodle_askkeeps 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.pyuse the zstd module, not the command. Indm/games/profile_guess.pyzstdis only a file-magic label.build_ipa_from_nsp.pynameszstdonly in its tool preflight. The launchers only check that the command is installed or install it.Checked
python3 tools/engine.py check: 65 patches apply cleanly toc78d7375bea9. Aftersync:dm/tools/tests/test_split_zstd.py(4 tests) andtest_docs.pyOK. Every test file that importsshader_split(39 files indm/tools/tests/anddm/gfx/tests/, among themtest_nlg4,test_size_prefixed_frames,test_shader_split_progress,test_romfs_read) OK on Python 3.15.2./Applications/NX2Apple.app/Contents/Resources/python/bin/python3.13, 3.13.18,backports.zstd):test_split_zstd.pyOK.test_split_zstd.pyfrom Saves and Rebuilds #1463. A 2 MB+ file, and the same bytes as a bounded RomFS image entry, decode withsubprocess.runpatched to fail. Concatenated frames, a dictionary frame through its named dictionary, truncation and a bad checksum rejected with the path. With the oldshader_split.pyit fails (1 failure, 2 errors), with the patch it passes.subprocess.runcall 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.tools/try-pr <this PR>) and say whether the split now passes 303,856/304,243.Screenshots
None, no visible change.
Scope
dm/,scripts/,docs/,ref/) is added to the repository: a change there is a patch inpatches/(a commit inengine/, thentools/engine.py export, andtools/engine.py checkpasses), with itsUpstream-Statusforwarded seedds/nxnative#1463The number 0106 is a placeholder (0099 to 0105 are taken by open PRs). Whoever merges renumbers it.
🤖 Generated with Claude Code