[PR #7866] Shader packs: lower rewritten global constant initializers #7870

Open
opened 2026-11-03 07:25:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7866
Author: @gigamans442
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: fix/global-constant-division-candidate-20261102


📝 Commits (2)

  • 4092cfd Fix global constants made runtime by zero division rewriting
  • ba0474c Bind lowered array lengths in declaration scope

📊 Changes

3 files changed (+538 additions, -23 deletions)

View changed files

📝 crates/horizon-shaders/src/translate/rewrite.rs (+53 -3)
📝 crates/horizon-shaders/src/translate/scan.rs (+128 -20)
➕ crates/horizon-shaders/tests/global_constant_division.rs (+357 -0)

📄 Description

🤖 Opened by gigamans442's AI agent (Codex, GPT-6.1 Sol), not by gigamans442 personally.

What and why

Fixes #7824.

A GLSL 1.20 const float audit = -1.0 / 0.0; makes the standard-pack loader skip its program with Unexpected runtime-expression: the existing compatibility rewrite changes the denominator to runtime hz_zero, but initializer lowering leaves the declaration constant.

Recognize that existing rewrite when selecting global initializers to run before the pack's main function. Preserve file/declarator order for dependent globals, and retain unrelated finite comma declarators as constants so they still work in array sizes and case labels. A sized array's type-only .length() remains constant through a collision-safe binding captured in declaration scope, including when a local shadows its authored size name, and synthesized multidimensional initializer return types retain the declared array shape. The existing runtime arithmetic policy is unchanged; no finite clamp or particular division-zero result is imposed.

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 standard shader-pack compatibility. GLSL 1.20 §§4.3.3 and 5.9 allow operators over constant operands and specify an unspecified value for division by zero. These tests assert acceptance, validation/backend emission and initialization order, not a numeric result for that division.

Other projects' code

None copied or adapted. This change uses MIT Horizon source at 0bcd2f15, public GLSL specification text and original asset-free fixtures. The external translator's unlicensed implementation/helpers, Iris/OptiFine/Sodium implementations and third-party shader-pack implementations were not read or copied for this fix.

Earlier private Skyline experiments included shader-pack source inspection; this contribution transfers none of that implementation and makes no blanket clean-room provenance claim. No private packs, worlds, player data or assets are included.

Self-check

Fresh public main 0bcd2f15, original three-case Pack::open → load_post + Naga validation/SPIR-V controls: 2 passed, 1 failed. The global-const zero-division case fails with the reported diagnostic; the nonconst-zero and finite-const controls pass. Source stayed unchanged during the preserved baseline.

Final exact head ba0474c12: 158 shader library tests + 17 original regression tests passed, including declaration-scope array lengths under local shadows, identifier collisions, named/multidimensional array types, dependent initialization order, finite comma declarators and invalid user-call/shadow diagnostics.

The declaration-scope regression passes with expected constant 2 on unchanged finite main, fails on the earlier candidate when a local count is loaded, and passes after capture of the declared size. Tests do not assert the numeric zero-division result.

The original local named-array control also failed on unchanged main with a finite denominator (Unknown variable: count); that pre-existing limitation is preserved in the evidence and is outside this fix. The committed test covers a global constant-sized array, finite local shadow arithmetic and global constant case labels instead.

cargo fmt --all -- --check, shader-package all-target Clippy with warnings denied and shader doc tests passed (0 doc tests). The real-pack test remains ignored because HORIZON_TEST_SHADER_PACKS is unset; no real-pack gameplay result is claimed. Matching CI run 41540636931 passed on exact head ba0474c12ceff570134aa38db96c3e89afd54ea9: public-tree and Python checks, workspace formatting, workspace all-target Clippy with warnings denied, the no-default-features server Clippy check, workspace library/binary/integration tests (including all 17 regressions), and workspace doc tests. Launcher verification passed; unrelated parity jobs were skipped.

The local full tools/pr_ready.py fallback was intentionally interrupted at Clippy when that matching CI started. Its public-tree, Python and formatting checks passed; it produced no complete self-check block. The broader checks above are actual CI results, not a fabricated local block.

🤖 Generated with Codex.


🔄 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/7866 **Author:** [@gigamans442](https://github.com/gigamans442) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/global-constant-division-candidate-20261102` --- ### 📝 Commits (2) - [`4092cfd`](https://github.com/horizon-rust/horizon/commit/4092cfd0bbdaeefa36f9534be867181ce98433c6) Fix global constants made runtime by zero division rewriting - [`ba0474c`](https://github.com/horizon-rust/horizon/commit/ba0474c12ceff570134aa38db96c3e89afd54ea9) Bind lowered array lengths in declaration scope ### 📊 Changes **3 files changed** (+538 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-shaders/src/translate/rewrite.rs` (+53 -3) 📝 `crates/horizon-shaders/src/translate/scan.rs` (+128 -20) ➕ `crates/horizon-shaders/tests/global_constant_division.rs` (+357 -0) </details> ### 📄 Description > 🤖 Opened by gigamans442's AI agent (Codex, GPT-6.1 Sol), not by gigamans442 personally. ## What and why Fixes #7824. A GLSL 1.20 `const float audit = -1.0 / 0.0;` makes the standard-pack loader skip its program with `Unexpected runtime-expression`: the existing compatibility rewrite changes the denominator to runtime `hz_zero`, but initializer lowering leaves the declaration constant. Recognize that existing rewrite when selecting global initializers to run before the pack's main function. Preserve file/declarator order for dependent globals, and retain unrelated finite comma declarators as constants so they still work in array sizes and case labels. A sized array's type-only `.length()` remains constant through a collision-safe binding captured in declaration scope, including when a local shadows its authored size name, and synthesized multidimensional initializer return types retain the declared array shape. The existing runtime arithmetic policy is unchanged; no finite clamp or particular division-zero result is imposed. ## 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 standard shader-pack compatibility. [GLSL 1.20 §§4.3.3 and 5.9](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.1.20.pdf) allow operators over constant operands and specify an unspecified value for division by zero. These tests assert acceptance, validation/backend emission and initialization order, not a numeric result for that division. ## Other projects' code None copied or adapted. This change uses [MIT Horizon source at 0bcd2f15](https://github.com/horizon-rust/horizon/tree/0bcd2f15678532560589773f674fb6290b075005), public GLSL specification text and original asset-free fixtures. The external translator's unlicensed implementation/helpers, Iris/OptiFine/Sodium implementations and third-party shader-pack implementations were not read or copied for this fix. Earlier private Skyline experiments included shader-pack source inspection; this contribution transfers none of that implementation and makes no blanket clean-room provenance claim. No private packs, worlds, player data or assets are included. ## Self-check Fresh public main 0bcd2f15, original three-case `Pack::open` → `load_post` + Naga validation/SPIR-V controls: **2 passed, 1 failed**. The global-const zero-division case fails with the reported diagnostic; the nonconst-zero and finite-const controls pass. Source stayed unchanged during the preserved baseline. Final exact head `ba0474c12`: **158 shader library tests + 17 original regression tests passed**, including declaration-scope array lengths under local shadows, identifier collisions, named/multidimensional array types, dependent initialization order, finite comma declarators and invalid user-call/shadow diagnostics. The declaration-scope regression passes with expected constant `2` on unchanged finite main, fails on the earlier candidate when a local `count` is loaded, and passes after capture of the declared size. Tests do not assert the numeric zero-division result. The original local named-array control also failed on unchanged main with a finite denominator (`Unknown variable: count`); that pre-existing limitation is preserved in the evidence and is outside this fix. The committed test covers a global constant-sized array, finite local shadow arithmetic and global constant case labels instead. `cargo fmt --all -- --check`, shader-package all-target Clippy with warnings denied and shader doc tests passed (0 doc tests). The real-pack test remains ignored because `HORIZON_TEST_SHADER_PACKS` is unset; no real-pack gameplay result is claimed. [Matching CI run 41540636931](https://github.com/horizon-rust/horizon/actions/runs/41540636931) passed on exact head `ba0474c12ceff570134aa38db96c3e89afd54ea9`: public-tree and Python checks, workspace formatting, workspace all-target Clippy with warnings denied, the no-default-features server Clippy check, workspace library/binary/integration tests (including all 17 regressions), and workspace doc tests. Launcher verification passed; unrelated parity jobs were skipped. The local full `tools/pr_ready.py` fallback was intentionally interrupted at Clippy when that matching CI started. Its public-tree, Python and formatting checks passed; it produced no complete self-check block. The broader checks above are actual CI results, not a fabricated local block. 🤖 Generated with [Codex](https://openai.com/codex/). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7870
No description provided.