[PR #3646] [MERGED] Shader packs: a program the shader compiler panics on no longer crashes the game #5120

Closed
opened 2026-11-03 05:10:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3646
Author: @d3grando
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @levzzz5154

Base: main ← Head: fix-3525


📝 Commits (2)

  • 17e0143 Shader packs: a program the shader compiler panics on no longer crashes the game
  • 21fdd33 Merge main into fix-3525

📊 Changes

3 files changed (+201 additions, -76 deletions)

View changed files

📝 crates/horizon-client-render/src/crash.rs (+68 -5)
📝 crates/horizon-client-render/src/gfx/pack_post.rs (+37 -3)
📝 crates/horizon-client/src/game/shader_packs.rs (+96 -68)

📄 Description

🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves.

Fixes #3525

What and why

Picking the Iris pack Photon v1.4 crashed the game as the pack loaded:

panicked at naga-30.0.1/src/back/spv/block.rs:3847:56:
internal error: entered unreachable code: Expression [89] is not cached!
  at <wgpu_hal::vulkan::Device>::compile_stage
  at <wgpu_core::...>::create_render_pipeline
  at <horizon_client::gfx::pack_post::PackPost>::new

The pack stays picked in horizon-graphics.txt, so every later world load crashed the same way until the player edited the file by hand.

Root cause. pack_post::build_pass already builds each pack program's pipeline inside checked, under a validation error scope. A program wgpu rejects is skipped with a note ("<name>: skipped: …"). But wgpu-hal's Vulkan backend only writes the naga module to SPIR-V when the pipeline is made, and naga's SPIR-V writer reports a module it can't write by panicking, not with an error. Nothing in the repo caught a panic, so the hook made a crash report and the game ended. On Windows the same happens on Vulkan, which is what Auto picks first. In my run 9 of Photon's gbuffers programs hit it (gbuffers_basic, _entities, _block, _particles, _hand, _weather, …).

Fix.

  • crash::contain(f) (new). It runs f under catch_unwind and returns a panic as Err(message). The panic hook recognises a panic inside contain (a thread-local depth). It logs it as Recovered from an error: … with its stack, makes no crash report, and does not set the one-report-per-run flag. A later real crash is still reported.
  • pack_post::checked runs create inside contain. A compiler panic becomes that pass's error, <name>: skipped: the shader compiler failed: …, exactly like a validation error. The rest of the pack runs and the device keeps working.
  • game/shader_packs.rs: the whole load of a shaders/ pack (reading, translating, set_shader_pack) runs inside contain. If anything else in it panics, shader_pack_failed turns the pack off:
    • no pack runs, and the dimension is marked loaded without one, so it isn't retried every frame;
    • the pick is cleared and saved, so the next start doesn't load the pack again;
    • the chat says "Shader pack could not be loaded and was turned off" in red, as a refused Horizon pack already does (native_shaders.rs).

The naga bug itself (glsl-in → spv-out on these programs) is upstream. With this change it costs Photon those passes instead of the game.

About #1544 (Solas): Solas v3.8 no longer crashes on current main. It loads with 8 programs and skips the rest with validation notes. This change also covers a Solas-style panic, if one comes back.

Vanilla reference

None: shader packs are a Horizon-only feature that vanilla doesn't have, so there is no vanilla method to match. A program that fails is skipped with a note, as checked already did for wgpu validation errors, and a pack that can't be loaded at all is turned off with a red chat line, as a refused Horizon pack already is (native_shaders.rs).

Test

  • gfx::pack_post::tests::a_shader_compiler_panic_skips_the_pass (GPU; it returns early with no adapter, like the other GPU tests here). checked gets a closure that panics with naga's message. The test expects an Err with that message, then checks that the device still creates a buffer and still reports a validation error.
  • crash::tests::contained_panics_come_back_as_errors: values pass through, panics come back as errors, nesting works, and the depth is back to 0 afterwards.

Before (checked back to let value = Ok::<T, String>(create());, the test kept):

test gfx::pack_post::tests::a_shader_compiler_panic_skips_the_pass ... FAILED
thread 'gfx::pack_post::tests::a_shader_compiler_panic_skips_the_pass' panicked at crates\horizon-client-render\src\gfx\pack_post.rs:2647:13:
internal error: entered unreachable code: Expression [89] is not cached!
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 513 filtered out

After:

test gfx::pack_post::tests::a_shader_compiler_panic_skips_the_pass ... ok
test crash::tests::contained_panics_come_back_as_errors ... ok
test crash::tests::a_panic_becomes_a_report ... ok
test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 503 filtered out

In game (Windows 11, Vulkan, photon_v1.4.zip from Modrinth, sha512 2dec8708…)

  • Before (main build, Photon picked): the world loaded, then the game crashed with the same panic as the report (Expression [89] is not cached! in naga/src/back/spv/block.rs:3847) and wrote a crash report. The pick stayed in horizon-graphics.txt.
  • After (same home, same pick): no crash and no crash report. The log shows 9 Recovered from an error: … is not cached! entries and gbuffers_*: skipped: the shader compiler failed: … notes. After the contained panics, wgpu still reports ordinary validation errors (Photon's composite5–composite21 are skipped for incompatible color target formats, a separate problem main never got far enough to show), the pack's working program (composite22) runs, and the world renders and keeps running. Photon itself doesn't look right yet: most of its programs are skipped. This PR fixes the crash, not Photon's rendering.
  • Fallback path: I made a temporary build (not in this PR) that panics inside the pack load. It logged shader pack photon_v1.4.zip: turned off: … and showed the red chat line "Shader pack photon_v1.4.zip could not be loaded and was turned off". horizon-graphics.txt then had pickedShaderPack: empty, there was no crash report, and the world kept rendering without a pack.

Self-check

tools/pr_ready.py doesn't run on Windows, so I ran its steps by hand:

cargo fmt --all -- --check
cargo clippy -p horizon-client-render --all-targets -- -D warnings
cargo clippy -p horizon-client --features mods --all-targets -- -D warnings
cargo test -p horizon-client-render --lib -- gfx::pack_post::tests crash::tests
cargo build --profile fast -p horizon-client --features mods --bins

All pass.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/3646 **Author:** [@d3grando](https://github.com/d3grando) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `fix-3525` --- ### 📝 Commits (2) - [`17e0143`](https://github.com/horizon-rust/horizon/commit/17e0143745a196d9fa5f268ff656b0e95bd5fd65) Shader packs: a program the shader compiler panics on no longer crashes the game - [`21fdd33`](https://github.com/horizon-rust/horizon/commit/21fdd33cdf6272e3a22e24f70b09ab69abd685cd) Merge main into fix-3525 ### 📊 Changes **3 files changed** (+201 additions, -76 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/crash.rs` (+68 -5) 📝 `crates/horizon-client-render/src/gfx/pack_post.rs` (+37 -3) 📝 `crates/horizon-client/src/game/shader_packs.rs` (+96 -68) </details> ### 📄 Description > 🤖 Opened by d3grando's AI agent (Claude Code, Claude Opus 5.5), not by d3grando themselves. Fixes #3525 ## What and why Picking the Iris pack **Photon v1.4** crashed the game as the pack loaded: ``` panicked at naga-30.0.1/src/back/spv/block.rs:3847:56: internal error: entered unreachable code: Expression [89] is not cached! at <wgpu_hal::vulkan::Device>::compile_stage at <wgpu_core::...>::create_render_pipeline at <horizon_client::gfx::pack_post::PackPost>::new ``` The pack stays picked in `horizon-graphics.txt`, so every later world load crashed the same way until the player edited the file by hand. **Root cause.** `pack_post::build_pass` already builds each pack program's pipeline inside `checked`, under a validation error scope. A program wgpu rejects is skipped with a note ("`<name>: skipped: …`"). But wgpu-hal's Vulkan backend only writes the naga module to SPIR-V when the pipeline is made, and naga's SPIR-V writer reports a module it can't write by panicking, not with an error. Nothing in the repo caught a panic, so the hook made a crash report and the game ended. On Windows the same happens on Vulkan, which is what Auto picks first. In my run 9 of Photon's gbuffers programs hit it (`gbuffers_basic`, `_entities`, `_block`, `_particles`, `_hand`, `_weather`, …). **Fix.** - **`crash::contain(f)`** (new). It runs `f` under `catch_unwind` and returns a panic as `Err(message)`. The panic hook recognises a panic inside `contain` (a thread-local depth). It logs it as `Recovered from an error: …` with its stack, makes no crash report, and does not set the one-report-per-run flag. A later real crash is still reported. - **`pack_post::checked`** runs `create` inside `contain`. A compiler panic becomes that pass's error, `<name>: skipped: the shader compiler failed: …`, exactly like a validation error. The rest of the pack runs and the device keeps working. - **`game/shader_packs.rs`**: the whole load of a `shaders/` pack (reading, translating, `set_shader_pack`) runs inside `contain`. If anything else in it panics, `shader_pack_failed` turns the pack off: - no pack runs, and the dimension is marked loaded without one, so it isn't retried every frame; - the pick is cleared and saved, so the next start doesn't load the pack again; - the chat says *"Shader pack <name> could not be loaded and was turned off"* in red, as a refused Horizon pack already does (`native_shaders.rs`). The naga bug itself (glsl-in → spv-out on these programs) is upstream. With this change it costs Photon those passes instead of the game. About #1544 (Solas): Solas v3.8 no longer crashes on current `main`. It loads with 8 programs and skips the rest with validation notes. This change also covers a Solas-style panic, if one comes back. ## Vanilla reference None: shader packs are a Horizon-only feature that vanilla doesn't have, so there is no vanilla method to match. A program that fails is skipped with a note, as `checked` already did for wgpu validation errors, and a pack that can't be loaded at all is turned off with a red chat line, as a refused Horizon pack already is (`native_shaders.rs`). ## Test - `gfx::pack_post::tests::a_shader_compiler_panic_skips_the_pass` (GPU; it returns early with no adapter, like the other GPU tests here). `checked` gets a closure that panics with naga's message. The test expects an `Err` with that message, then checks that the device still creates a buffer and still reports a validation error. - `crash::tests::contained_panics_come_back_as_errors`: values pass through, panics come back as errors, nesting works, and the depth is back to 0 afterwards. Before (`checked` back to `let value = Ok::<T, String>(create());`, the test kept): ``` test gfx::pack_post::tests::a_shader_compiler_panic_skips_the_pass ... FAILED thread 'gfx::pack_post::tests::a_shader_compiler_panic_skips_the_pass' panicked at crates\horizon-client-render\src\gfx\pack_post.rs:2647:13: internal error: entered unreachable code: Expression [89] is not cached! test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 513 filtered out ``` After: ``` test gfx::pack_post::tests::a_shader_compiler_panic_skips_the_pass ... ok test crash::tests::contained_panics_come_back_as_errors ... ok test crash::tests::a_panic_becomes_a_report ... ok test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 503 filtered out ``` ## In game (Windows 11, Vulkan, `photon_v1.4.zip` from Modrinth, sha512 `2dec8708…`) - **Before** (`main` build, Photon picked): the world loaded, then the game crashed with the same panic as the report (`Expression [89] is not cached!` in `naga/src/back/spv/block.rs:3847`) and wrote a crash report. The pick stayed in `horizon-graphics.txt`. - **After** (same home, same pick): no crash and no crash report. The log shows 9 `Recovered from an error: … is not cached!` entries and `gbuffers_*: skipped: the shader compiler failed: …` notes. After the contained panics, wgpu still reports ordinary validation errors (Photon's `composite5`–`composite21` are skipped for incompatible color target formats, a separate problem `main` never got far enough to show), the pack's working program (`composite22`) runs, and the world renders and keeps running. Photon itself doesn't look right yet: most of its programs are skipped. This PR fixes the crash, not Photon's rendering. - **Fallback path**: I made a temporary build (not in this PR) that panics inside the pack load. It logged `shader pack photon_v1.4.zip: turned off: …` and showed the red chat line *"Shader pack photon_v1.4.zip could not be loaded and was turned off"*. `horizon-graphics.txt` then had `pickedShaderPack:` empty, there was no crash report, and the world kept rendering without a pack. ## Self-check `tools/pr_ready.py` doesn't run on Windows, so I ran its steps by hand: ``` cargo fmt --all -- --check cargo clippy -p horizon-client-render --all-targets -- -D warnings cargo clippy -p horizon-client --features mods --all-targets -- -D warnings cargo test -p horizon-client-render --lib -- gfx::pack_post::tests crash::tests cargo build --profile fast -p horizon-client --features mods --bins ``` All pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:10:23 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5120
No description provided.