[PR #6335] [CLOSED] Shader packs: a parameter or local named like a bool uniform hides it #6806

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6335
Author: @MSedgeMC
Created: 11/1/2026
Status: ❌ Closed

Base: main ← Head: fix/sh-bool-scope


📝 Commits (1)

  • 3acf8db Shader packs: a parameter or local named like a bool uniform hides it

📊 Changes

2 files changed (+123 additions, -9 deletions)

View changed files

📝 crates/horizon-shaders/src/translate/mod.rs (+46 -0)
📝 crates/horizon-shaders/src/translate/rewrite.rs (+77 -9)

📄 Description

Fixes #6241.

GLSL's scoping (4.60, 4.2): a parameter is in scope in its function's body and a local from the end of its declaration to the end of its block, so a bool uniform declared outside is hidden there, and the name is the uniform everywhere else - in a local's own initializer, and after its block ends.

Horizon keeps bool uniforms in the uniform block as int and rewrites every token naming one into (hz_bool_<name> != 0), a parameter's and a local's own declaration included: float f(in bool hideGUI) became float f(in bool (hz_bool_hideGUI != 0)), and naga refused the program with "Expected RightParen, found LeftParen".

A declaration of a name that also names a bool uniform now hides it from the end of its initializer to the end of its own scope - its block, its function for a parameter, its ) for a prototype - and a name used as a conversion (float(hideGUI)) is not a declaration. A local that hides a sampler went through the same code path and hid it to the end of the function; it now ends with its block as well, which is the same rule; say if you would rather have that in a PR of its own.

Proven:

  • cargo test -q -p horizon-shaders --lib on the build VM: 109 passed.
  • The same tests on a branch with only the two new tests and none of the fix: bool_uniforms_hidden_by_parameters_and_locals fails with composite.fsh:4: Expected RightParen, found LeftParen (the error in the issue), and a_local_hides_a_sampler_to_the_end_of_its_block fails with composite.fsh:6: Bad call.
  • cargo clippy -q -p horizon-shaders --all-targets clean, rustfmt --edition 2024 --check clean on both changed files.

Not proven: no real pack was translated or rendered: the pack corpus is not available here, so real_packs (HORIZON_TEST_SHADER_PACKS) was not run, and no pack was drawn in the game.

Kind

  • bug: a crash or a breakage

Vanilla reference

none: the rule is the GLSL 4.60 specification, 4.2 "Scoping", and no vanilla class is involved.

Other projects' code

none. No pack, Iris or OptiFine source was read.

Self-check

cargo test -q -p horizon-shaders --lib on the build VM: 109 passed. cargo clippy -q -p horizon-shaders --all-targets and rustfmt --edition 2024 --check on both changed files: clean.


🔄 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/6335 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/sh-bool-scope` --- ### 📝 Commits (1) - [`3acf8db`](https://github.com/horizon-rust/horizon/commit/3acf8db8de749c3b4cbbc7f65b7fe6e082251213) Shader packs: a parameter or local named like a bool uniform hides it ### 📊 Changes **2 files changed** (+123 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-shaders/src/translate/mod.rs` (+46 -0) 📝 `crates/horizon-shaders/src/translate/rewrite.rs` (+77 -9) </details> ### 📄 Description Fixes #6241. GLSL's scoping (4.60, 4.2): a parameter is in scope in its function's body and a local from the end of its declaration to the end of its block, so a `bool` uniform declared outside is hidden there, and the name is the uniform everywhere else - in a local's own initializer, and after its block ends. Horizon keeps `bool` uniforms in the uniform block as `int` and rewrites every token naming one into `(hz_bool_<name> != 0)`, a parameter's and a local's own declaration included: `float f(in bool hideGUI)` became `float f(in bool (hz_bool_hideGUI != 0))`, and naga refused the program with "Expected RightParen, found LeftParen". A declaration of a name that also names a `bool` uniform now hides it from the end of its initializer to the end of its own scope - its block, its function for a parameter, its `)` for a prototype - and a name used as a conversion (`float(hideGUI)`) is not a declaration. A local that hides a *sampler* went through the same code path and hid it to the end of the function; it now ends with its block as well, which is the same rule; say if you would rather have that in a PR of its own. **Proven:** - `cargo test -q -p horizon-shaders --lib` on the build VM: 109 passed. - The same tests on a branch with only the two new tests and none of the fix: `bool_uniforms_hidden_by_parameters_and_locals` fails with `composite.fsh:4: Expected RightParen, found LeftParen` (the error in the issue), and `a_local_hides_a_sampler_to_the_end_of_its_block` fails with `composite.fsh:6: Bad call`. - `cargo clippy -q -p horizon-shaders --all-targets` clean, `rustfmt --edition 2024 --check` clean on both changed files. **Not proven:** no real pack was translated or rendered: the pack corpus is not available here, so `real_packs` (`HORIZON_TEST_SHADER_PACKS`) was not run, and no pack was drawn in the game. ## Kind - [x] bug: a crash or a breakage ## Vanilla reference none: the rule is the GLSL 4.60 specification, 4.2 "Scoping", and no vanilla class is involved. ## Other projects' code none. No pack, Iris or OptiFine source was read. ## Self-check `cargo test -q -p horizon-shaders --lib` on the build VM: 109 passed. `cargo clippy -q -p horizon-shaders --all-targets` and `rustfmt --edition 2024 --check` on both changed files: clean. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:27:15 +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#6806
No description provided.