Skip to content

shader_split: read GLSLC outputs kept in Unity TextAssets - #238

Closed
Amost- wants to merge 1 commit into
seedds:mainfrom
Amost-:pr/unity-textasset-shaders
Closed

Amost- wants to merge 1 commit into
seedds:mainfrom
Amost-:pr/unity-textasset-shaders

Conversation

@Amost-

@Amost- Amost- commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

FINAL FANTASY CRYSTAL CHRONICLES Remastered Edition (Unity 2018.4.2f1 IL2CPP, SDK 8.2.1) drew its terrain with black holes, and the log listed about 57 shader keys "not in the shader map". The shaders were not in any Unity Shader object: the game keeps 1,160 whole GLSLC outputs (1,207 distinct shaders) of its own in the TextAsset shader.switch.vfxsb in Data/resources.assets, which it hands to NVN itself. shader_split.py read only Shader and ComputeShader objects, and its fallback for loose GLSLC outputs skips Unity files.

  • unityfs.text_assets reads each TextAsset's name and bytes without a type tree (the object starts with m_Name and m_Script in every Unity version these tools read). The header and object-table parsing moves out of serialized_objects into _tables, shared by both; serialized_objects behaves as before.
  • unity_text_glslc, called from unity_shaders, decodes a file's TextAssets only when the file holds the GLSLC magic, and passes those that do to glslc_shaders, which keeps only outputs that pass its own checks. A Unity file without such a TextAsset is not decoded further, so other games' tables are unchanged.
  • Entry: docs/reference/shaders.md, "GLSLC outputs in a Unity TextAsset".

Checked

  • This branch alone on main (9a56ecf): the host unit tests; every test in dm/tools/tests, dm/ios/tests and dm/gfx/tests; dmhost for Super Mario Bros. Wonder (NVN), Hades (Vulkan) and Digimon Story Cyber Sleuth (GL); the iOS compile check.
  • New test: test_unity_text_glslc.py, a synthetic serialized file with one TextAsset holding a GLSLC output and one without (no game data).
  • On the game: the split went from 30,428 to 31,635 shaders; the [RED] "not in the shader map" lines went from 86 to 0 in four Mac runs of 60 to 220 s, and the terrain draws whole.

Not checked

  • Other Unity games' splits byte for byte: their files were not on hand. The magic gate keeps files without such a TextAsset on the old path.
  • The game's three Unity 2018.4 ComputeShader objects are still skipped with the existing [RED] line; no run asked for one.

One of three independent PRs from the same bring-up; they touch separate code and can land in any order.

🤖 Generated with Claude Code

FINAL FANTASY CRYSTAL CHRONICLES Remastered Edition (Unity 2018.4.2f1) draws its
maps and effects with programs outside Unity's Shader objects: the TextAsset
shader.switch.vfxsb in Data/resources.assets holds 1,160 whole GLSLC outputs
(1,207 distinct shaders); without them its terrain drew with black holes.
unityfs.text_assets reads TextAsset names and bytes without a type tree (the
tables now parsed by _tables, shared with serialized_objects); unity_text_glslc
passes those holding the GLSLC magic to glslc_shaders. Files without the magic are
not decoded, so other games' tables are unchanged. Documented in
docs/reference/shaders.md; test_unity_text_glslc.py covers it with a synthetic
serialized file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
seedds added a commit that referenced this pull request Oct 26, 2026
…tAsset reads (#203, #238)

#203 as submitted stopped the shader split of Tears of the Kingdom with a
TypeError: its 1,202 Cave/.../C.crbin.<hash>/*.quad files are a 4-byte hash
(the one in their folder name), then a zstd frame, so they pass the gate,
and on the length mismatch the error path took len() of None. The PR checked
Wonder and Yoshi only; of the RomFS of 39 games on hand, only those files
have a frame at +4.

- unsized: a frame whose header records a size other than the prefix is not
  such a container and is read as it is, without decompressing it
  (frame_size). A frame that records none (Kirby's LZ4 frames) must
  decompress to exactly the prefix's size: the whole output is compared,
  where the PR's max_length cut a longer frame at the prefix and let it pass.
- The dictionary handling is shared with unzs (zs_dict_id, unzs_dict). A
  dictionary ZDICTS does not have is still reported, not fatal, as in the PR:
  the ID may be any bytes after a magic at +4.
- unityfs.text_assets: an object shorter than the two length fields, or one
  whose name padding leaves no room for the script's length, is left out
  instead of reading past its end (struct.error, which stopped the split).

Checked:
- Kirby and the Forgotten Land (base and update 1.1.0): 121 shaders before,
  27,288 after (27,302 with the update), no [RED] line. 5,121 zstd frames
  record their size, equal to the prefix; 2,080 + 354 LZ4 frames record none
  and decompress to the prefix's size. The PR's "383 in lyt/" is 378.
- Tears of the Kingdom: the full split exits 1 with #203 alone; with this
  commit its package and tables are byte-identical to main's, no [RED] line.
- main's split and this branch's give byte-identical packages and tables on
  Monster Train 2, Ace Attorney Investigations Collection, AI: THE SOMNIUM
  FILES, nirvanA Initiative, BALL x PIT, Advance Wars 1+2, Brain Memory
  Training Academy (Unity 2017.4 to 6000) and Super Mario Bros. Wonder.
- New test_size_prefixed_frames.py; test_unity_text_glslc.py covers short
  objects (fails on #238's unityfs.py). All of dm/tools/tests pass.
- Not checked here: FINAL FANTASY CRYSTAL CHRONICLES (#238's game) is not on
  hand; Kirby has not been run.
@seedds

seedds commented Oct 26, 2026

Copy link
Copy Markdown
Owner

Thank you, this is on main as 1c857ca, with a small follow-up in eb858ec: text_assets now leaves out an object shorter than its two length fields, or one whose name padding leaves no room for the script's length, instead of reading past its end (a struct.error would have stopped the split). The test file covers it.

Checked here: main's split and this one give byte-identical packages and tables on the seven Unity games on hand (Unity 2017.4 to 6000: Monster Train 2, Ace Attorney Investigations Collection, both AI: THE SOMNIUM FILES, BALL x PIT, Advance Wars 1+2, Brain Memory Training Academy). FINAL FANTASY CRYSTAL CHRONICLES Remastered Edition is not on hand, so the gain itself is checked only by your runs. Could you run main's shader_split.py on it and post the shader count and whether the not in the shader map lines are still gone?

@seedds seedds closed this Oct 26, 2026
@Amost-

Amost- commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks! I built FINAL FANTASY CRYSTAL CHRONICLES Remastered Edition 1.0.3 for the Mac from main (ce9b30b), with #285's profile and main's tables (through DM_GAMES_DIR):

Separately, on macOS 27.0.1 (M2 Pro): starts on one saved pipeline archive (17 files: 13 with a vertex layout, so compaction runs, plus 3 new bases) crash in the first flush: CRASH sig=11 pc=dispatch_retain+0 lr=-[_MTLBinaryArchive materializeAirNTFromOnlineForSlice:entryList:]+0x1c4, from arch_flush → serializeAsArchiveAndFlushToURL. It crashed 11 of 13 times on copies of that archive, including 2 of 3 with e72991d's nvn_mtl.m change reverted, so I don't think it's that change. A fresh archive works, and a 12-file archive from another run compacted without a crash. I can share the archive if it helps.

@Amost-

Amost- commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Follow-up on the pipeline-archive crash: with main's tip (1402ded, the host built from #285's branch) the same archive no longer crashes — 0 of 5 starts, each opening its 17 files, writing a new file and compacting the 13 old ones, the flush that crashed 11 of 13 starts with the ce9b30b host. So 1402ded's "archive build folders never taken at a recapture" looks like the fix; one thing I can't explain is that a ce9b30b host with e72991d's nvn_mtl.m hunk reverted still crashed 2 of 3. The archive copy is still here if you want it.

Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
…tAsset reads (seedds#203, seedds#238)

seedds#203 as submitted stopped the shader split of Tears of the Kingdom with a
TypeError: its 1,202 Cave/.../C.crbin.<hash>/*.quad files are a 4-byte hash
(the one in their folder name), then a zstd frame, so they pass the gate,
and on the length mismatch the error path took len() of None. The PR checked
Wonder and Yoshi only; of the RomFS of 39 games on hand, only those files
have a frame at +4.

- unsized: a frame whose header records a size other than the prefix is not
  such a container and is read as it is, without decompressing it
  (frame_size). A frame that records none (Kirby's LZ4 frames) must
  decompress to exactly the prefix's size: the whole output is compared,
  where the PR's max_length cut a longer frame at the prefix and let it pass.
- The dictionary handling is shared with unzs (zs_dict_id, unzs_dict). A
  dictionary ZDICTS does not have is still reported, not fatal, as in the PR:
  the ID may be any bytes after a magic at +4.
- unityfs.text_assets: an object shorter than the two length fields, or one
  whose name padding leaves no room for the script's length, is left out
  instead of reading past its end (struct.error, which stopped the split).

Checked:
- Kirby and the Forgotten Land (base and update 1.1.0): 121 shaders before,
  27,288 after (27,302 with the update), no [RED] line. 5,121 zstd frames
  record their size, equal to the prefix; 2,080 + 354 LZ4 frames record none
  and decompress to the prefix's size. The PR's "383 in lyt/" is 378.
- Tears of the Kingdom: the full split exits 1 with seedds#203 alone; with this
  commit its package and tables are byte-identical to main's, no [RED] line.
- main's split and this branch's give byte-identical packages and tables on
  Monster Train 2, Ace Attorney Investigations Collection, AI: THE SOMNIUM
  FILES, nirvanA Initiative, BALL x PIT, Advance Wars 1+2, Brain Memory
  Training Academy (Unity 2017.4 to 6000) and Super Mario Bros. Wonder.
- New test_size_prefixed_frames.py; test_unity_text_glslc.py covers short
  objects (fails on seedds#238's unityfs.py). All of dm/tools/tests pass.
- Not checked here: FINAL FANTASY CRYSTAL CHRONICLES (seedds#238's game) is not on
  hand; Kirby has not been run.
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