[PR #1601] [MERGED] Shader packs, clean room 6: composite-style programs to naga #3623

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1601
Author: @ludovic111
Created: 10/24/2026
Status: ✅ Merged
Merged: 10/25/2026
Merged by: @ludovic111

Base: main ← Head: feat/shader-packs-translate


📝 Commits (5)

  • eb0a6f7 Shader packs, clean room 2: macros and #if conditions
  • 397d529 Shader packs, clean room 3: .properties files with conditional directives
  • 4c65ed2 Shader packs, clean room 4: function-like macros and the standard macros
  • f239955 Shader packs, clean room 5: the GLSL preprocessor and #include
  • b61b25f Shader packs, clean room 6: composite-style programs to naga

📊 Changes

12 files changed (+2537 additions, -7 deletions)

View changed files

📝 Cargo.lock (+12 -0)
📝 crates/horizon-shaders/Cargo.toml (+2 -0)
➕ crates/horizon-shaders/src/condition.rs (+369 -0)
📝 crates/horizon-shaders/src/lib.rs (+14 -0)
➕ crates/horizon-shaders/src/macros.rs (+317 -0)
📝 crates/horizon-shaders/src/pack.rs (+1 -1)
➕ crates/horizon-shaders/src/preprocess.rs (+374 -0)
➕ crates/horizon-shaders/src/properties.rs (+229 -0)
➕ crates/horizon-shaders/src/translate/mod.rs (+436 -0)
➕ crates/horizon-shaders/src/translate/rewrite.rs (+257 -0)
➕ crates/horizon-shaders/src/translate/scan.rs (+399 -0)
📝 crates/horizon-shaders/tests/real_packs.rs (+127 -6)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Shader packs, clean room 6 (slice 4): composite-style programs to naga. Stacked on #1600.

What

translate_composite(vertex, fragment, target): a program's preprocessed GLSL, any version from 110 to 460, compatibility or core, rewritten into the Vulkan-flavoured GLSL 450 naga reads, then parsed and validated into naga modules with the program's interface (uniform block with naga's offsets, samplers and bindings, output locations). The rewrite works on preprocessing tokens and keeps the pack's lines, so errors point at the pack's file and line through the preprocessor's line map.

  • Loose uniforms go into one block shared by both stages (bool stored as int). Samplers are split into texture and sampler objects, combined again where used, and passed as two arguments to the pack's own functions.
  • Compatibility built-ins become declarations of ours (prefix hz_): gl_Vertex, gl_MultiTexCoordN, the matrices and ftransform(), gl_FragData, gl_FragColor, gl_TexCoord, gl_FrontColor, gl_Fog (from vanilla's fog, OQ-28), texture2D and the other old texture functions, shadow2D. Varyings get locations by name across stages; words that became keywords after GLSL 1.x are renamed in old code.
  • naga gaps covered: modf, conditional initializers of globals (run by our main), unsized arrays sized from their constructor.
  • The pack's main is called by one of ours that draws the quad from (0,0) to (1,1) (OQ-6) and adapts GL's conventions (§5.5): clip y negated for every target but the window, so memory rows are GL's rows and gl_FragCoord needs no change; clip z from GL's [-w, w] to [0, w], so stored depth is GL's window depth. In final, gl_FragCoord.y counts from the bottom of the window.

Size: about 1180 lines, over the ~500 target. The translator only works as a whole (the rewrite, the interface and the wrapper main depend on each other), so it is one PR in three files (translate/mod.rs, scan.rs, rewrite.rs) rather than parts that could not be tested alone.

Nothing uses it yet: players see no change (skip-release).

Clean room

Clean-room: implemented from cleanroom/shader-packs-spec.md revision 1, §1.6, §2.2, §5.5, OQ-6, OQ-28 and OQ-29; no other loader's code read. naga's own behaviour was learnt from its documentation, its source and small probes of my own.

How tested

  • Unit tests: compatibility-profile and core-profile programs translate and validate with the expected interface; errors point at the pack file and line.
  • Black box on the public test packs (never committed), tests/real_packs.rs: 105 of 105 composite-style programs (composite, deferred, final, prepare, begin, shadowcomp of the base and dimension folders of four packs) translate and validate.

Self-check (whole stack, on its top branch feat/shader-packs-translate)

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at 16d49fe66, 32 min 35 s)

Check Result
Scope ⚠️ 16 files, +3028 −1; 2864 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ changes with a Cargo.toml
Public tree ✅
Python tests ➖ no Python change
rustfmt ✅ (35 s)
clippy ✅ (3 min 10 s)
tests: workspace ✅ 1955 passed (27 min 39 s)
doc tests ✅ 1 passed (rerun alone: the first run compiled the next slice's uncommitted files in the same worktree)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 326 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 314 more
Label skip-release: players see nothing yet

Parity: the root Cargo.toml change selects 326 harnesses, but nothing in the game depends on the new crate, so they can't change. CI runs them.

Needs Ludovic

Nothing for this PR. Label skip-release because players see nothing yet (the first visible slice is the Shader Packs page, slice 9).

🤖 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/1601 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/24/2026 **Status:** ✅ Merged **Merged:** 10/25/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/shader-packs-translate` --- ### 📝 Commits (5) - [`eb0a6f7`](https://github.com/horizon-rust/horizon/commit/eb0a6f74e6d5911cc63e637b6dcd14076c28ac0e) Shader packs, clean room 2: macros and #if conditions - [`397d529`](https://github.com/horizon-rust/horizon/commit/397d529db72a17a1def83e1d7c50e9f866beb69e) Shader packs, clean room 3: .properties files with conditional directives - [`4c65ed2`](https://github.com/horizon-rust/horizon/commit/4c65ed2f5c6c4e089cf4f0bec4b32ab97004e4bc) Shader packs, clean room 4: function-like macros and the standard macros - [`f239955`](https://github.com/horizon-rust/horizon/commit/f2399559979c1fd1a0e62c578a83ae4e5a29cd75) Shader packs, clean room 5: the GLSL preprocessor and #include - [`b61b25f`](https://github.com/horizon-rust/horizon/commit/b61b25f80fa2afdb7249ccc48c5e2e0f9eb90c68) Shader packs, clean room 6: composite-style programs to naga ### 📊 Changes **12 files changed** (+2537 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+12 -0) 📝 `crates/horizon-shaders/Cargo.toml` (+2 -0) ➕ `crates/horizon-shaders/src/condition.rs` (+369 -0) 📝 `crates/horizon-shaders/src/lib.rs` (+14 -0) ➕ `crates/horizon-shaders/src/macros.rs` (+317 -0) 📝 `crates/horizon-shaders/src/pack.rs` (+1 -1) ➕ `crates/horizon-shaders/src/preprocess.rs` (+374 -0) ➕ `crates/horizon-shaders/src/properties.rs` (+229 -0) ➕ `crates/horizon-shaders/src/translate/mod.rs` (+436 -0) ➕ `crates/horizon-shaders/src/translate/rewrite.rs` (+257 -0) ➕ `crates/horizon-shaders/src/translate/scan.rs` (+399 -0) 📝 `crates/horizon-shaders/tests/real_packs.rs` (+127 -6) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. **Shader packs, clean room 6 (slice 4):** composite-style programs to naga. Stacked on #1600. ## What `translate_composite(vertex, fragment, target)`: a program's preprocessed GLSL, any version from 110 to 460, compatibility or core, rewritten into the Vulkan-flavoured GLSL 450 naga reads, then parsed and validated into naga modules with the program's interface (uniform block with naga's offsets, samplers and bindings, output locations). The rewrite works on preprocessing tokens and keeps the pack's lines, so errors point at the pack's file and line through the preprocessor's line map. - Loose uniforms go into one block shared by both stages (`bool` stored as `int`). Samplers are split into texture and sampler objects, combined again where used, and passed as two arguments to the pack's own functions. - Compatibility built-ins become declarations of ours (prefix `hz_`): `gl_Vertex`, `gl_MultiTexCoordN`, the matrices and `ftransform()`, `gl_FragData`, `gl_FragColor`, `gl_TexCoord`, `gl_FrontColor`, `gl_Fog` (from vanilla's fog, OQ-28), `texture2D` and the other old texture functions, `shadow2D`. Varyings get locations by name across stages; words that became keywords after GLSL 1.x are renamed in old code. - naga gaps covered: `modf`, conditional initializers of globals (run by our `main`), unsized arrays sized from their constructor. - The pack's `main` is called by one of ours that draws the quad from (0,0) to (1,1) (OQ-6) and adapts GL's conventions (§5.5): clip y negated for every target but the window, so memory rows are GL's rows and `gl_FragCoord` needs no change; clip z from GL's [-w, w] to [0, w], so stored depth is GL's window depth. In `final`, `gl_FragCoord.y` counts from the bottom of the window. **Size:** about 1180 lines, over the ~500 target. The translator only works as a whole (the rewrite, the interface and the wrapper `main` depend on each other), so it is one PR in three files (`translate/mod.rs`, `scan.rs`, `rewrite.rs`) rather than parts that could not be tested alone. Nothing uses it yet: players see no change (`skip-release`). ## Clean room Clean-room: implemented from `cleanroom/shader-packs-spec.md` revision 1, §1.6, §2.2, §5.5, OQ-6, OQ-28 and OQ-29; no other loader's code read. naga's own behaviour was learnt from its documentation, its source and small probes of my own. ## How tested - Unit tests: compatibility-profile and core-profile programs translate and validate with the expected interface; errors point at the pack file and line. - Black box on the public test packs (never committed), `tests/real_packs.rs`: **105 of 105** composite-style programs (composite, deferred, final, prepare, begin, shadowcomp of the base and dimension folders of four packs) translate and validate. ## Self-check (whole stack, on its top branch `feat/shader-packs-translate`) **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at 16d49fe66, 32 min 35 s) | Check | Result | | --- | --- | | Scope | ⚠️ 16 files, +3028 −1; 2864 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ changes with a Cargo.toml | | Public tree | ✅ | | Python tests | ➖ no Python change | | rustfmt | ✅ (35 s) | | clippy | ✅ (3 min 10 s) | | tests: workspace | ✅ 1955 passed (27 min 39 s) | | doc tests | ✅ 1 passed (rerun alone: the first run compiled the next slice's uncommitted files in the same worktree) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 326 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 314 more | | Label | `skip-release`: players see nothing yet | Parity: the root `Cargo.toml` change selects 326 harnesses, but nothing in the game depends on the new crate, so they can't change. CI runs them. ## Needs Ludovic Nothing for this PR. Label `skip-release` because players see nothing yet (the first visible slice is the Shader Packs page, slice 9). 🤖 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 04:10:52 +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#3623
No description provided.