[PR #7241] [MERGED] Shader packs: a compute work group size may be a constant expression #7436

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

📋 Pull Request Information

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

Base: main ← Head: shaderpacks/work-group-size-expressions


📝 Commits (1)

  • 6c52fb9 Shader packs: a compute work group size may be a constant expression

📊 Changes

1 file changed (+177 additions, -34 deletions)

View changed files

📝 crates/horizon-shaders/src/translate/mod.rs (+177 -34)

📄 Description

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

What and why

Fixes #7171. This is the last of its four pieces; the others are the #version, anonymous-struct and interface-block PRs for #7171.

The problem: GLSL takes an integer constant expression for local_size_* (GLSL 4.60, 4.4: a layout qualifier's value is an integer-constant-expression; 4.4.1, Compute Shader Inputs). RenderPearl v2.7.2's deferred keeps its work group within the implementation's limit with layout(local_size_x = min(gl_MaxComputeWorkGroupSize.x, N), …) in;. Horizon took a plain number only (`local_size_x` is not a number gl_WorkGroupSize can take), and naga's frontend reads neither the call nor gl_MaxComputeWorkGroupSize.

The fix:

  • work_group_size now works out the expression and writes the value in its place: numbers, + - * / %, brackets, min, max, and gl_MaxComputeWorkGroupSize.x/y/z.
  • gl_MaxComputeWorkGroupSize is the minimum GLSL requires, ivec3(1024, 1024, 64) (7.3); the translation knows no device.
  • gl_WorkGroupSize is the value, as before.
  • A size it can't work out (a named constant, say) is still an error, and the message now says that rather than "not a number".

Measured with real_packs (SHOW_ERRORS=1, 40 packs), main fbb17c980 against this branch. Only RenderPearl's deferred changes, in each dimension: its size error is gone, and the program now stops on shared (the #version PR for #7171). With all four #7171 branches applied, deferred stops on Unexpected runtime-expression at a struct member's array size given as ll.data.length(), a gap outside #7171.

Tests:

  • a_work_group_size_may_be_a_constant_expression (a compute program). Run against main's code it fails: Unknown variable: gl_MaxComputeWorkGroupSize and Expected RightParen, found Dot;
  • work_group_size_is_its_layout, whose old case asserted that 8 * 2 is refused, now checks a min/gl_MaxComputeWorkGroupSize size and a named size still refused.

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). Source: GLSL 4.60 specification, 4.4 (Layout Qualifiers), 4.4.1 (Input Layout Qualifiers, Compute Shader Inputs) and 7.3 (Built-In Constants).

Other projects' code

RenderPearl v2.7.2, MIT: github.com/Luracasmus/renderpearl@86de79c4fa/LICENSE (tag v2.7.2). The files were read from the Modrinth v2.7.2 zip, whose LICENSE is identical to that one.

What was read:

  • deferred.csh, lines 1–13 (its local_size layouts) and 20–32;
  • prelude/config.glsl, lines 23 and 29; buf/ll.glsl, lines 5–6 (for the ll.data.length() note above);
  • a grep of the whole pack for local_size.

What follows RenderPearl: the compute test's layout(local_size_x = min(gl_MaxComputeWorkGroupSize.x, 256), local_size_y = 1, local_size_z = 1) in;, RenderPearl's shape with a number of ours. The rest is written for this.

Self-check

pr_ready (tools/pr_ready.py --quick on plony-pc, against origin/main at fbb17c980, 1 min 29 s)

Check Result
Scope ✅ 1 files, +177 −34
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (35 s)
rustfmt ✅ (6 s)
clippy ✅ (47 s)
tests: horizon-shaders ✅ 143 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/7241 **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/work-group-size-expressions` --- ### 📝 Commits (1) - [`6c52fb9`](https://github.com/horizon-rust/horizon/commit/6c52fb99bc3b42c9be85d37031396a6e28b96bf9) Shader packs: a compute work group size may be a constant expression ### 📊 Changes **1 file changed** (+177 additions, -34 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-shaders/src/translate/mod.rs` (+177 -34) </details> ### 📄 Description > 🤖 Opened by arslanarm's AI agent (Claude Code, Claude Opus 5.5), not by arslanarm personally. ## What and why Fixes #7171. This is the last of its four pieces; the others are the `#version`, anonymous-struct and interface-block PRs for #7171. **The problem:** GLSL takes an integer constant expression for `local_size_*` (GLSL 4.60, 4.4: a layout qualifier's value is an `integer-constant-expression`; 4.4.1, Compute Shader Inputs). RenderPearl v2.7.2's `deferred` keeps its work group within the implementation's limit with `layout(local_size_x = min(gl_MaxComputeWorkGroupSize.x, N), …) in;`. Horizon took a plain number only (`` `local_size_x` is not a number gl_WorkGroupSize can take ``), and naga's frontend reads neither the call nor `gl_MaxComputeWorkGroupSize`. **The fix:** - `work_group_size` now works out the expression and writes the value in its place: numbers, `+ - * / %`, brackets, `min`, `max`, and `gl_MaxComputeWorkGroupSize.x/y/z`. - `gl_MaxComputeWorkGroupSize` is the minimum GLSL requires, `ivec3(1024, 1024, 64)` (7.3); the translation knows no device. - `gl_WorkGroupSize` is the value, as before. - A size it can't work out (a named constant, say) is still an error, and the message now says that rather than "not a number". **Measured** with `real_packs` (`SHOW_ERRORS=1`, 40 packs), main fbb17c980 against this branch. Only RenderPearl's `deferred` changes, in each dimension: its size error is gone, and the program now stops on `shared` (the `#version` PR for #7171). With all four #7171 branches applied, `deferred` stops on `Unexpected runtime-expression` at a struct member's array size given as `ll.data.length()`, a gap outside #7171. Tests: - `a_work_group_size_may_be_a_constant_expression` (a compute program). Run against main's code it fails: `Unknown variable: gl_MaxComputeWorkGroupSize` and `Expected RightParen, found Dot`; - `work_group_size_is_its_layout`, whose old case asserted that `8 * 2` is refused, now checks a `min`/`gl_MaxComputeWorkGroupSize` size and a named size still refused. ## 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). Source: GLSL 4.60 specification, 4.4 (Layout Qualifiers), 4.4.1 (Input Layout Qualifiers, Compute Shader Inputs) and 7.3 (Built-In Constants). ## Other projects' code RenderPearl v2.7.2, MIT: https://github.com/Luracasmus/renderpearl/blob/86de79c4fa7d07fb47628dd9620efb10fb4be9d9/LICENSE (tag v2.7.2). The files were read from the Modrinth v2.7.2 zip, whose `LICENSE` is identical to that one. What was read: - `deferred.csh`, lines 1–13 (its `local_size` layouts) and 20–32; - `prelude/config.glsl`, lines 23 and 29; `buf/ll.glsl`, lines 5–6 (for the `ll.data.length()` note above); - a grep of the whole pack for `local_size`. What follows RenderPearl: the compute test's `layout(local_size_x = min(gl_MaxComputeWorkGroupSize.x, 256), local_size_y = 1, local_size_z = 1) in;`, RenderPearl's shape with a number of ours. The rest is written for this. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on plony-pc, against origin/main at fbb17c980, 1 min 29 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +177 −34 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (35 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (47 s) | | tests: horizon-shaders | ✅ 143 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:39:29 +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#7436
No description provided.