[PR #7154] [MERGED] Shader packs: geometry stages whose varyings travel in interface blocks #7380

Closed
opened 2026-11-03 06:38:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7154
Author: @arslanarm
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: shaderpacks/geometry-stage-blocks


📝 Commits (1)

  • d5418e0 Shader packs: geometry stages whose varyings travel in interface blocks

📊 Changes

2 files changed (+154 additions, -53 deletions)

View changed files

📝 crates/horizon-shaders/src/translate/geometry.rs (+76 -34)
📝 crates/horizon-shaders/src/translate/interface_blocks.rs (+78 -19)

📄 Description

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

What and why

Part of #6812.

With Shrimple v0.12, the overworld's shadow program (it has a geometry stage) did not translate on main, so Horizon drew no shadow map: real_packs printed shadow: no program; the shadow map stays clear.

A shadow program with a geometry stage is folded into one vertex stage (translate/geometry.rs), which reads the global declarations of both stages one variable at a time. It did not know interface blocks (GLSL 4.60, 4.3.9). It read a vertex stage's out Block { vec4 a; float b; } v; as one declaration whose "names" were {, the type of every member after the first (float), and }. It then renamed those everywhere in the vertex stage (float → hz_vs_float).

  • Blocks are lowered first. combine runs interface_blocks::flatten over both stages before reading them. flatten now also lowers a block with an instance array, the form a geometry stage's input takes: each member becomes an array, outermost (vIn[i].m → hz_<block>_m[i], float m[2] → hz_<block>_m[][2]).
  • Input and output blocks no longer collide. A geometry stage's input block and output block may share a name ("A block name is allowed to have different definitions in different shader interfaces within the same shader, allowing, for example, an input block and output block to have the same name", 4.3.9). Flattened, both became hz_<block>_<member>. In a geometry stage, input-block members are now hz_in_<block>_<member> (flatten_as), and combine feeds them from the vertex stage's hz_<block>_<member>.
  • A smaller misread of the same kind: qualifiers are now skipped with the translator's full list (scan::QUALIFIERS, which has sample and precise). Before, out sample float x; made float a name. Flattened members carry their qualifiers after out (4.12 allows any order), so this matters for blocks too. I found this while reading the code and reproduced it with my own GLSL; it did not change Shrimple's result.

How the cause was found (black-box only)

  1. real_packs with SHOW_ERRORS=1 on main (898042ced), Shrimple, dimension 0: program/shadow.vsh:26: farisfloatin one stage andhz_vs_float in the other, the same for frameTimeCounter (line 33), program/shadow.fsh:23 for far, then shadow: skipped and shadow: no program; the shadow map stays clear.
  2. Reading geometry.rs: hz_vs_ is put on the names classify says the vertex stage defines or outputs, so a type word was being read as a name. With my own GLSL, an output qualified sample or precise (missing from its qualifier list, unlike scan::QUALIFIERS) does that. Fixing it did not change Shrimple's output. A wider set of my own declarations then showed that an out block with more than one member does the same.
  3. Issue #6812's last comment notes that this pack's gbuffers programs use interface blocks. I lowered blocks before combine: the float errors went away, and the program then failed with world0/shadow.gsh:0: Function [6] 'hz_emit' is invalid: The type of [269] doesn't match the type stored in [268].
  4. hz_emit stores each geometry-stage output into a ring of its type. From the code, I guessed that an input and an output block with the same name flatten to the same identifier. My own GLSL with one block name for both reproduced the error ('hz_emit' is invalid: The type of [84] doesn't match the type stored in [83]). After the hz_in_ prefix, real_packs shows Shrimple's shadow program translated. I checked 4.3.9 afterwards.

I did not open, extract, or read any pack's files, nor Horizon's preprocessed or translated text of any pack. Everything about Shrimple above comes from real_packs's ordinary output, the game's log and screenshots, and the text of issue #6812.

Measured (real_packs, SHOW_ERRORS=1, main 898042ced vs this branch, 40 packs)

Apart from timings, the whole output differs only in Shrimple's dimension 0:

Shrimple, world0 main this branch
shadow programs (shadow, shadow_water, shadow_entities, shadow_block) None, None, None, None Some("shadow"), Some("shadow"), None, None
notes 13 4
shadow: no program; the shadow map stays clear yes no

shadow_entities and shadow_block stay None (shadow: uses a geometry stage (supported for terrain's shadow only); skipped, on main and here). The nether and the end have no shadow pass with this pack, on main and here.

With BACKENDS=1, on a folder holding only Shrimple, the SPIR-V, HLSL, GLSL and MSL writers report 0 errors, 0 panics for all three dimensions (97, 90 and 89 modules). Over all 40 packs, the BACKENDS=1 run stops before Shrimple, on an HLSL writer panic in another pack's composite program, which this change does not touch. I did not compare that with main.

In the game

I ran the scenes ow_ground_noon and ow_ground_sunset with Shrimple: main 898042ced vs this branch, fast builds, Xvfb, fresh homes. The branch build had one more change, since removed: precision statements no longer declare a type. It made no difference to real_packs, whose output is identical with and without it.

  • Main's log has shadow: skipped and shadow: no program; the shadow map stays clear.
  • This branch's log has terrain casts shadows with shadow and translucent terrain casts shadows with shadow.
  • The pictures are still almost black on both, and nearly identical: mean absolute difference 0.1 of 255 at noon, 0 at sunset.

So this PR does not yet make Shrimple look right. Both logs still report its other gaps: imgLocalBlockMask and the texVanillaClouds custom texture "not provided yet", and gbuffers_hand skipped. The issue's comment already names the image and gbuffers_hand. That is why there are no screenshots.

Tests

All three fail on main and pass here. They use my own GLSL:

  • translate::geometry::tests::interface_blocks_pass_between_the_stages: an out block with an instance in the vertex stage, an in block array and an out block of the same name in the geometry stage, an in block in the fragment stage, members with flat. On main: Expected end of file, found Identifier("VertexDatavec4color").
  • translate::geometry::tests::sample_outputs_rename_no_type. On main: `far` is `hz_vs_float` in one stage and `float` in the other.
  • translate::interface_blocks::tests::an_instance_array_makes_each_member_an_array. On main, flatten returns None for it.

other_blocks_stay_as_written no longer lists an instance array; its case is now an instance array used whole, which still stays as written.

Not done: a vertex-stage out block without an instance name keeps its members' plain names, so a geometry stage's in block of the same name does not receive them; such inputs stay zero. GLSL allows such a pair (4.3.9). The vertex → fragment path has the same limitation on main.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only (shader packs; vanilla has no such feature). This follows the OpenGL Shading Language 4.60 specification (https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.html):

  • 4.3.9 Interface Blocks: block-name matching; an input and an output block may share a name.
  • 4.3 Storage Qualifiers (auxiliary sample).
  • 4.9 The Precise Qualifier.
  • 4.12 Order and Repetition of Qualification.

Other projects' code

None. No other project's source was read or copied. What I read: the GLSL 4.60 specification, Horizon's own code, the text of issue #6812, the ordinary output of real_packs (all packs in my folder; which pack each program belongs to and its error messages, as printed), and Horizon's log and screenshots from running Shrimple in the game. No pack's files were opened.

Self-check

pr_ready (tools/pr_ready.py --quick on plony-pc, against origin/main at 898042ced, 58 s)

Check Result
Scope ✅ 2 files, +154 −53
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (32 s)
rustfmt ✅ (7 s)
clippy ✅ (18 s)
tests: horizon-shaders ✅ 141 passed (1 s)
doc tests ✅ 0 passed
content root tests ➖ content root untouched
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/7154 **Author:** [@arslanarm](https://github.com/arslanarm) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `shaderpacks/geometry-stage-blocks` --- ### 📝 Commits (1) - [`d5418e0`](https://github.com/horizon-rust/horizon/commit/d5418e0137c21105732e7184d38d3ffeabedbf93) Shader packs: geometry stages whose varyings travel in interface blocks ### 📊 Changes **2 files changed** (+154 additions, -53 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-shaders/src/translate/geometry.rs` (+76 -34) 📝 `crates/horizon-shaders/src/translate/interface_blocks.rs` (+78 -19) </details> ### 📄 Description > 🤖 Opened by arslanarm's AI agent (Claude Code, Claude Opus 5.5), not by arslanarm personally. ## What and why Part of #6812. With Shrimple v0.12, the overworld's `shadow` program (it has a geometry stage) did not translate on main, so Horizon drew no shadow map: `real_packs` printed `shadow: no program; the shadow map stays clear`. A shadow program with a geometry stage is folded into one vertex stage (`translate/geometry.rs`), which reads the global declarations of both stages one variable at a time. It did not know interface blocks (GLSL 4.60, 4.3.9). It read a vertex stage's `out Block { vec4 a; float b; } v;` as one declaration whose "names" were `{`, the type of every member after the first (`float`), and `}`. It then renamed those everywhere in the vertex stage (`float` → `hz_vs_float`). - **Blocks are lowered first.** `combine` runs `interface_blocks::flatten` over both stages before reading them. `flatten` now also lowers a block with an instance array, the form a geometry stage's input takes: each member becomes an array, outermost (`vIn[i].m` → `hz_<block>_m[i]`, `float m[2]` → `hz_<block>_m[][2]`). - **Input and output blocks no longer collide.** A geometry stage's input block and output block may share a name ("A block name is allowed to have different definitions in different shader interfaces within the same shader, allowing, for example, an input block and output block to have the same name", 4.3.9). Flattened, both became `hz_<block>_<member>`. In a geometry stage, input-block members are now `hz_in_<block>_<member>` (`flatten_as`), and `combine` feeds them from the vertex stage's `hz_<block>_<member>`. - **A smaller misread of the same kind:** qualifiers are now skipped with the translator's full list (`scan::QUALIFIERS`, which has `sample` and `precise`). Before, `out sample float x;` made `float` a name. Flattened members carry their qualifiers after `out` (4.12 allows any order), so this matters for blocks too. I found this while reading the code and reproduced it with my own GLSL; it did **not** change Shrimple's result. ### How the cause was found (black-box only) 1. `real_packs` with `SHOW_ERRORS=1` on main (898042ced), Shrimple, dimension 0: `program/shadow.vsh:26: `far` is `float` in one stage and `hz_vs_float` in the other`, the same for `frameTimeCounter` (line 33), `program/shadow.fsh:23` for `far`, then `shadow: skipped` and `shadow: no program; the shadow map stays clear`. 2. Reading `geometry.rs`: `hz_vs_` is put on the names `classify` says the vertex stage defines or outputs, so a type word was being read as a name. With my own GLSL, an output qualified `sample` or `precise` (missing from its qualifier list, unlike `scan::QUALIFIERS`) does that. Fixing it did not change Shrimple's output. A wider set of my own declarations then showed that an `out` block with more than one member does the same. 3. Issue #6812's last comment notes that this pack's gbuffers programs use interface blocks. I lowered blocks before `combine`: the `float` errors went away, and the program then failed with `world0/shadow.gsh:0: Function [6] 'hz_emit' is invalid: The type of [269] doesn't match the type stored in [268]`. 4. `hz_emit` stores each geometry-stage output into a ring of its type. From the code, I guessed that an input and an output block with the same name flatten to the same identifier. My own GLSL with one block name for both reproduced the error (`'hz_emit' is invalid: The type of [84] doesn't match the type stored in [83]`). After the `hz_in_` prefix, `real_packs` shows Shrimple's shadow program translated. I checked 4.3.9 afterwards. I did not open, extract, or read any pack's files, nor Horizon's preprocessed or translated text of any pack. Everything about Shrimple above comes from `real_packs`'s ordinary output, the game's log and screenshots, and the text of issue #6812. ### Measured (`real_packs`, `SHOW_ERRORS=1`, main 898042ced vs this branch, 40 packs) Apart from timings, the whole output differs only in Shrimple's dimension 0: | Shrimple, `world0` | main | this branch | | --- | --- | --- | | shadow programs (`shadow`, `shadow_water`, `shadow_entities`, `shadow_block`) | `None, None, None, None` | `Some("shadow"), Some("shadow"), None, None` | | notes | 13 | 4 | | `shadow: no program; the shadow map stays clear` | yes | no | `shadow_entities` and `shadow_block` stay `None` (`shadow: uses a geometry stage (supported for terrain's shadow only); skipped`, on main and here). The nether and the end have no shadow pass with this pack, on main and here. With `BACKENDS=1`, on a folder holding only Shrimple, the SPIR-V, HLSL, GLSL and MSL writers report `0 errors, 0 panics` for all three dimensions (97, 90 and 89 modules). Over all 40 packs, the `BACKENDS=1` run stops before Shrimple, on an HLSL writer panic in another pack's `composite` program, which this change does not touch. I did not compare that with main. ### In the game I ran the scenes `ow_ground_noon` and `ow_ground_sunset` with Shrimple: main 898042ced vs this branch, fast builds, Xvfb, fresh homes. The branch build had one more change, since removed: precision statements no longer declare a type. It made no difference to `real_packs`, whose output is identical with and without it. - Main's log has `shadow: skipped` and `shadow: no program; the shadow map stays clear`. - This branch's log has `terrain casts shadows with shadow` and `translucent terrain casts shadows with shadow`. - The pictures are still almost black on both, and nearly identical: mean absolute difference 0.1 of 255 at noon, 0 at sunset. So this PR does not yet make Shrimple look right. Both logs still report its other gaps: `imgLocalBlockMask` and the `texVanillaClouds` custom texture "not provided yet", and `gbuffers_hand` skipped. The issue's comment already names the image and `gbuffers_hand`. That is why there are no screenshots. ### Tests All three fail on main and pass here. They use my own GLSL: - `translate::geometry::tests::interface_blocks_pass_between_the_stages`: an `out` block with an instance in the vertex stage, an `in` block array and an `out` block of the same name in the geometry stage, an `in` block in the fragment stage, members with `flat`. On main: `Expected end of file, found Identifier("VertexDatavec4color")`. - `translate::geometry::tests::sample_outputs_rename_no_type`. On main: `` `far` is `hz_vs_float` in one stage and `float` in the other ``. - `translate::interface_blocks::tests::an_instance_array_makes_each_member_an_array`. On main, `flatten` returns `None` for it. `other_blocks_stay_as_written` no longer lists an instance array; its case is now an instance array used whole, which still stays as written. **Not done:** a vertex-stage `out` block without an instance name keeps its members' plain names, so a geometry stage's `in` block of the same name does not receive them; such inputs stay zero. GLSL allows such a pair (4.3.9). The vertex → fragment path has the same limitation on main. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only (shader packs; vanilla has no such feature). This follows the OpenGL Shading Language 4.60 specification (https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.html): - 4.3.9 Interface Blocks: block-name matching; an input and an output block may share a name. - 4.3 Storage Qualifiers (auxiliary `sample`). - 4.9 The Precise Qualifier. - 4.12 Order and Repetition of Qualification. ## Other projects' code None. No other project's source was read or copied. What I read: the GLSL 4.60 specification, Horizon's own code, the text of issue #6812, the ordinary output of `real_packs` (all packs in my folder; which pack each program belongs to and its error messages, as printed), and Horizon's log and screenshots from running Shrimple in the game. No pack's files were opened. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on plony-pc, against origin/main at 898042ced, 58 s) | Check | Result | | --- | --- | | Scope | ✅ 2 files, +154 −53 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (32 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (18 s) | | tests: horizon-shaders | ✅ 141 passed (1 s) | | doc tests | ✅ 0 passed | | content root tests | ➖ content root untouched | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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 06:38:39 +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#7380
No description provided.