Skip to content

Shader split: decompress zstd files in-process, so a worker no longer deadlocks against the zstd command's pipes (Ocarina of Time's split hung at 88 %) - #1463

Closed
jonpage0 wants to merge 1 commit into
seedds:mainfrom
jonpage0:shader-split-zstd-in-process

Conversation

@jonpage0

@jonpage0 jonpage0 commented Nov 6, 2026

Copy link
Copy Markdown

What and why

Symptom: building The Legend of Zelda: Ocarina of Time (0400486024DEC000, v131072) as a Mac app from current main stops for good at the shader split: splitting: 88%, 164,256/186,587 files, then no new line, the worker processes asleep and four zstd -d -c -q children at 0 % CPU.

Cause: since #394, unzs in dm/gfx/tools/shader_split.py feeds a frame without a dictionary to the zstd command on stdin while capturing its stdout (subprocess.run(..., input=d, capture_output=True)). Once a frame is larger than the pipe buffers the two block on each other: the worker's write waits for zstd to read, and zstd's output write waits for the worker to drain stdout, which subprocess.run does only after the write has finished. Ocarina's sound archives are big enough; the split hangs with every worker in that state.

Fix: unzs decompresses in-process with compression.zstd (Python 3.14; backports.zstd before), which the dictionary frames already go through (unzs_dict): no pipes, and a bounded RomFS image entry is read the same way as a file. An invalid stream is a red line naming the path, as the other readers do.

Reference entry: The split hangs decompressing a large zstd file; the symptom index is regenerated.

Checked

  • python3 -m unittest dm/tools/tests/test_split_zstd.py: 4 tests, OK (a 2 MB+ file and the same bytes as a bounded RomFS image entry, with subprocess.run patched to fail; concatenated frames; a dictionary frame through its named dictionary; truncation and a checksum error rejected with the path in the message).
  • python3 -m unittest dm/tools/tests/test_docs.py: OK; python3 dm/tools/docs_symptoms.py --check: current.
  • Games built: Ocarina of Time v131072 on an M3 Max (36 GB, macOS 27.0.1, Python 3.14): with the change the split goes past file 164,256 (the full build was still running when this was opened; I will add its result).
  • Not run: other games' splits (the change touches only frames without a dictionary, which took the zstd command before; the bytes are the same).

Docs

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

🤖 Generated with Claude Code

… deadlocks against the zstd command's pipes

Feeding the zstd CLI through stdin while capturing stdout deadlocks on macOS once a frame is larger than the pipe buffers: the worker's blocking write waits for zstd to read, while zstd's output writer waits for the worker to drain stdout. Ocarina of Time's sound archives hit it at 88% of the split (164,256 of 186,587 files), and the build hung for good. compression.zstd (Python 3.14, backports.zstd before) is already used for dictionary frames; it decompresses frames without one too. test_split_zstd.py covers files and bounded RomFS entries.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers tools Tools and scripts (dm/tools, scripts) docs Documentation labels Nov 6, 2026
@jonpage0

jonpage0 commented Nov 6, 2026

Copy link
Copy Markdown
Author

With the change, the same Ocarina of Time build's split finished: ✓ [3/6] shader split (2:17): 42,854 shaders (186,587 files), and the build went on to the Mac shaders stage (42,854 shaders compiling). Before it, the split sat at file 164,256 for 10 minutes with the four zstd children idle until I killed it.

@jonpage0

jonpage0 commented Nov 6, 2026

Copy link
Copy Markdown
Author

The full build finished on the fixed split: Mac shaders 42,847 of 42,854 (49:36 on this M3 Max), the pipeline archive and the app (36.0 GB); the game runs through Kokiri Forest from it. The 7 that did not translate are ATOMG.CAS (0x3a9, six FoliageShader compute shaders) and one 0x481, which #1414 covers; unrelated to this change.

gnosticgeek pushed a commit to gnosticgeek/nxforge that referenced this pull request Nov 6, 2026
v0lumehi pushed a commit to LNPANDY/NX2Apple that referenced this pull request Nov 9, 2026
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>
v0lumehi added a commit to LNPANDY/NX2Apple that referenced this pull request Nov 9, 2026
Shader split: decompress zstd in-process, so the split no longer hangs at 99% (patch of seedds/nxnative#1463)
Aeonitis pushed a commit to Aeonitis/nxnative that referenced this pull request Nov 9, 2026
…cess (Ocarina of Time's split hung at 88 %)
FeReuss pushed a commit to FeReuss/nxnative-oot that referenced this pull request Nov 10, 2026
…std files in-process, so a worker no longer deadlocks against the zstd command's pipes (Ocarina of Time's split hung at 88 %

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
lucaszhongsj pushed a commit to lucaszhongsj/nxnative that referenced this pull request Nov 19, 2026
… deadlocks against the zstd command's pipes

Feeding the zstd CLI through stdin while capturing stdout deadlocks on macOS once a frame is larger than the pipe buffers: the worker's blocking write waits for zstd to read, while zstd's output writer waits for the worker to drain stdout. Ocarina of Time's sound archives hit it at 88% of the split (164,256 of 186,587 files), and the build hung for good. compression.zstd (Python 3.14, backports.zstd before) is already used for dictionary frames; it decompresses frames without one too. test_split_zstd.py covers files and bounded RomFS entries.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
(cherry picked from commit 82a24a4)

Upstream-Status: forwarded seedds#1463
Reason: Shader splits of Tears of the Kingdom and Ocarina of Time hang at 99% with every worker blocked writing to an idle zstd child; until upstream merges seedds#1463
Issue: LNPANDY/NX2Apple#837
@eric1932

Copy link
Copy Markdown
Contributor

Thanks for tracing the hang in these two games to the two ends of the zstd pipe waiting on each other. I didn't see this PR when I worked on #3002. Main now decodes in process as well (6aaf73b); linking it here so the two can be compared.

@seedds

seedds commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @jonpage0 for pinning down the zstd hang and confirming a complete 42,854-shader split on Ocarina of Time. Main now decodes zstd in process as well (6aaf73b). The landed checks found identical shader packages and tables across three games and the synthetic archives. I'm closing the duplicate implementation.

@seedds seedds closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation packing Building an IPA or a Mac app: the NSP script, extraction, the shader split, the packers tools Tools and scripts (dm/tools, scripts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants