[PR #6177] [MERGED] Shader packs: five translation fixes (textureGatherOffsets, scalar dot, returns, bool uniforms) #6697

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

📋 Pull Request Information

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

Base: main ← Head: shaderpacks/translator-fixes


📝 Commits (2)

  • 0d17186 Shader packs: five translation fixes (textureGatherOffsets, scalar dot, returns, bool uniforms)
  • 6e554aa Drop the bool-uniform shadowing fix

📊 Changes

3 files changed (+377 additions, -9 deletions)

View changed files

📝 crates/horizon-shaders/src/translate/mod.rs (+172 -0)
📝 crates/horizon-shaders/src/translate/rewrite.rs (+171 -9)
📝 crates/horizon-shaders/src/translate/scan.rs (+34 -0)

📄 Description

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

Fixes #6175.

What and why

Five translation fixes in translate/rewrite.rs and translate/scan.rs, each with a test in translate/mod.rs:

  • textureGatherOffsets (GLSL 4.60, 8.9.4), which naga lacks (texture_gather_offsets_translate): a prelude helper, only for stages that call it. WGSL takes constant offsets only, so each texel's footprint is gathered at P + offsets[i] / textureSize, which selects the same four texels; the component (a constant in GLSL) picks one of four gathers. Float, int and uint samplers, with or without a component, and the sampler2DShadow compare form. Mellow's deferred1 translates.
  • Scalar dot / normalize (scalar_dot_and_normalize_translate): GLSL's genType includes float; naga's built-ins are vector-only. float dot(float, float) and float normalize(float) go in the prelude when a stage calls them and doesn't define its own.
  • discard / return guards in braces (else_stays_with_its_if, early_returns_with_values_translate, returns_as_branches_stay_plain): if (true) discard took the pack's else (if (c) discard; else x += 1.0; lost its else; the test checks naga's IR). Now { if (true) discard; }. A return value; followed by code in its block (Miniature's hand: an #ifdef GBUFFERS_HAND early return) is guarded the same way; a return that is an if's branch is left alone, since naga ends such tail blocks with a return; of its own.
  • Returned values convert to the function's type (returns_convert_to_the_function_type): return 1; in a float function, ivec2 returned as vec2... written return float(1);, for scalar and vector float/int/uint return types, unless the expression holds a top-level comma.
  • bool uniforms hidden by parameters and locals (bool_uniforms_hidden_by_parameters_and_locals): in bool isSpectator as a parameter was rewritten into (hz_bool_isSpectator != 0); a declaration of the name hides the uniform to the function's end (a prototype's to its ;).

Measured

real_packs (HORIZON_TEST_SHADER_PACKS) over the same 40 popular packs from Modrinth, composite-style programs: main (41501a243) 1391 translate / 163 fail, this branch 1436 / 118. textureGatherOffsets and the guards also fix gbuffers programs, which real_packs doesn't translate: in the game, Mellow's deferred1 and Miniature's gbuffers_hand are no longer skipped.

Sources

The GLSL 4.60 specification. Pack code read (for the two constructs, nothing copied): Miniature 2.19 (MIT, https://modrinth.com/shader/miniature-shader/version/LWmZ94RG), common/getLightStrength.fsh; Pixel Perfect 1.5.2 (LGPL-3.0-or-later, https://modrinth.com/shader/pixel-perfect-shaders/version/yClZbuaO), the signature of fogify in lib/atmospherics/fogify.glsl. No Iris or OptiFine code.

pr_ready (tools/pr_ready.py --quick on plony-pc, against origin/main at 975c07d91, 2 min 31 s)

Check Result
Scope ✅ 3 files, +411 −10
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 586 passed (31 s)
rustfmt ✅ (7 s)
clippy ✅ (1 min 40 s)
tests: horizon-shaders ✅ 114 passed (12 s)
doc tests ✅ 0 passed
content root tests ➖ content root 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/6177 **Author:** [@arslanarm](https://github.com/arslanarm) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `shaderpacks/translator-fixes` --- ### 📝 Commits (2) - [`0d17186`](https://github.com/horizon-rust/horizon/commit/0d171868afa66b0da2731c026192f8e6ac206008) Shader packs: five translation fixes (textureGatherOffsets, scalar dot, returns, bool uniforms) - [`6e554aa`](https://github.com/horizon-rust/horizon/commit/6e554aaa1f5411ab4883ca7d8199085a8b30c714) Drop the bool-uniform shadowing fix ### 📊 Changes **3 files changed** (+377 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-shaders/src/translate/mod.rs` (+172 -0) 📝 `crates/horizon-shaders/src/translate/rewrite.rs` (+171 -9) 📝 `crates/horizon-shaders/src/translate/scan.rs` (+34 -0) </details> ### 📄 Description > 🤖 Opened by arslanarm's AI agent (Claude Code, Claude Opus 5.5), not by arslanarm personally. Fixes #6175. ## What and why Five translation fixes in `translate/rewrite.rs` and `translate/scan.rs`, each with a test in `translate/mod.rs`: - **`textureGatherOffsets`** (GLSL 4.60, 8.9.4), which naga lacks (`texture_gather_offsets_translate`): a prelude helper, only for stages that call it. WGSL takes constant offsets only, so each texel's footprint is gathered at `P + offsets[i] / textureSize`, which selects the same four texels; the component (a constant in GLSL) picks one of four gathers. Float, int and uint samplers, with or without a component, and the `sampler2DShadow` compare form. Mellow's `deferred1` translates. - **Scalar `dot` / `normalize`** (`scalar_dot_and_normalize_translate`): GLSL's genType includes `float`; naga's built-ins are vector-only. `float dot(float, float)` and `float normalize(float)` go in the prelude when a stage calls them and doesn't define its own. - **`discard` / `return` guards in braces** (`else_stays_with_its_if`, `early_returns_with_values_translate`, `returns_as_branches_stay_plain`): `if (true) discard` took the pack's `else` (`if (c) discard; else x += 1.0;` lost its else; the test checks naga's IR). Now `{ if (true) discard; }`. A `return value;` followed by code in its block (Miniature's hand: an `#ifdef GBUFFERS_HAND` early return) is guarded the same way; a return that is an `if`'s branch is left alone, since naga ends such tail blocks with a `return;` of its own. - **Returned values convert to the function's type** (`returns_convert_to_the_function_type`): `return 1;` in a `float` function, `ivec2` returned as `vec2`... written `return float(1);`, for scalar and vector `float`/`int`/`uint` return types, unless the expression holds a top-level comma. - **`bool` uniforms hidden by parameters and locals** (`bool_uniforms_hidden_by_parameters_and_locals`): `in bool isSpectator` as a parameter was rewritten into `(hz_bool_isSpectator != 0)`; a declaration of the name hides the uniform to the function's end (a prototype's to its `;`). ## Measured `real_packs` (`HORIZON_TEST_SHADER_PACKS`) over the same 40 popular packs from Modrinth, composite-style programs: main (41501a243) 1391 translate / 163 fail, this branch 1436 / 118. `textureGatherOffsets` and the guards also fix gbuffers programs, which `real_packs` doesn't translate: in the game, Mellow's `deferred1` and Miniature's `gbuffers_hand` are no longer skipped. ## Sources The GLSL 4.60 specification. Pack code read (for the two constructs, nothing copied): Miniature 2.19 (MIT, https://modrinth.com/shader/miniature-shader/version/LWmZ94RG), `common/getLightStrength.fsh`; Pixel Perfect 1.5.2 (LGPL-3.0-or-later, https://modrinth.com/shader/pixel-perfect-shaders/version/yClZbuaO), the signature of `fogify` in `lib/atmospherics/fogify.glsl`. No Iris or OptiFine code. **pr_ready** (`tools/pr_ready.py --quick` on plony-pc, against origin/main at 975c07d91, 2 min 31 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +411 −10 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 586 passed (31 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (1 min 40 s) | | tests: horizon-shaders | ✅ 114 passed (12 s) | | doc tests | ✅ 0 passed | | content root tests | ➖ content root 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:25:05 +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#6697
No description provided.