[PR #7203] [MERGED] Shader packs: storage buffers as large as their shaders' blocks #7409

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

📋 Pull Request Information

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

Base: main ← Head: shaderpacks/storage-buffer-min-size


📝 Commits (1)

  • 35972b0 Shader packs: storage buffers as large as their shaders' blocks

📊 Changes

3 files changed (+128 additions, -3 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx/pack_images.rs (+39 -2)
📝 crates/horizon-client-render/src/gfx/pack_post.rs (+3 -1)
📝 crates/horizon-shaders/src/post.rs (+86 -0)

📄 Description

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

What and why

Fixes #7178.

A pack declares each storage buffer's size in shaders.properties (bufferObject.<n> = <bytes> …, Iris ShaderDoc, "Shader Storage Buffer Objects"). A shader may bind it as a larger block: std430 rounds a block's size up to its largest member's alignment. OpenGL binds the smaller buffer anyway. wgpu refuses the draw or dispatch, and its validation error stopped the render submit thread. As a result, RenderPearl v2.7.2 and Visual Vibrance v0.3.5a crashed the game on their first frame in a world:

  • RenderPearl: "the buffer bound at binding index 1 is bound with size 40980 where the shader expects 40992";
  • Visual Vibrance: "… binding index 0 … size 40 where the shader expects 48".

The changes:

  • horizon-shaders: Post::buffer_minimums reads, from every translated stage of every program (passes, geometry draws, shadow programs, compute stages), the size of each storage block in set 4, using naga's own layout, which is what wgpu checks the binding against. It keeps the largest per binding.
  • gfx/pack_images.rs: each storage buffer is made at least that large, still a multiple of 4. A larger declared size is kept as it is.

Not in this PR: turning a pack off, instead of crashing, when its frame fails wgpu's validation. That needs an error scope on the submit thread and a way back to the game, so it gets its own issue and PR.

Measured

  • real_packs over Modrinth's 40 most-downloaded packs, main 3783aa54b vs this branch, SHOW_ERRORS=1: identical, line for line, apart from timings (the test creates no GPU buffers; this only adds a method).
  • In the game (fast build, Xvfb, fresh homes, scenes ow_ground_noon, ow_ground_sunset, nether_wastes, vignette off). On main (a fast build of 6d91fa694, ow_ground_noon; the storage-buffer code is unchanged up to 3783aa54b), both packs crash on the first frame with the errors above. With this branch, both render every scene, and the log has no wgpu error.
  • Mean absolute difference to Iris 1.11.7 + Sodium 0.9.2 on the same scenes (of 255; mean brightness Horizon / Iris):
Pack ow_ground_noon ow_ground_sunset nether_wastes
RenderPearl 18.2 (98 / 91) 11.7 (56 / 55) 5.4 (28 / 31)
Visual Vibrance 34.8 (63 / 89) 31.0 (47 / 67) 8.8 (42 / 49)

The differences that remain are other gaps. RenderPearl's gbuffers programs still fail to translate (textureQueryLod, and its declarations: #7170, #7171), so its terrain draws as the game's own. Visual Vibrance's overworld is darker than in Iris, which this PR doesn't address.

Tests:

  • post::tests::storage_buffers_need_their_blocks_size (horizon-shaders): a compute stage and a fragment stage bind the same buffer as blocks of different sizes, declared smaller than either. The largest block wins (48 bytes for 40 declared). A block with an array gets its element count's size (64).
  • gfx::pack_images::tests::a_buffer_is_at_least_its_shaders_block: the declared size grows to the block, a larger declared size stays, and per-pixel buffers follow the render size.

Both are new; Post::buffer_minimums doesn't exist on main.

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). Sources: Iris ShaderDoc ("Shader Storage Buffer Objects"), wgpu's validation errors in Horizon's log, and black-box runs of Iris 1.11.7 with the two packs.

Other projects' code

none. No Iris, OptiFine or pack code read. RenderPearl and Visual Vibrance were only run as black boxes; the sizes above come from Horizon's own log.

Self-check

pr_ready (tools/pr_ready.py --quick on plony-pc, against origin/main at 3783aa54b, 3 min 30 s)

Check Result
Scope ✅ 3 files, +128 −3
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (39 s)
rustfmt ✅ (8 s)
clippy ✅ (1 min 45 s)
tests: horizon-client-render, horizon-shaders ✅ 1297 passed (56 s)
doc tests ✅ 0 passed (1 s)
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/7203 **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/storage-buffer-min-size` --- ### 📝 Commits (1) - [`35972b0`](https://github.com/horizon-rust/horizon/commit/35972b0eab8d9566e3ac4e14a0fe7be73fb71976) Shader packs: storage buffers as large as their shaders' blocks ### 📊 Changes **3 files changed** (+128 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx/pack_images.rs` (+39 -2) 📝 `crates/horizon-client-render/src/gfx/pack_post.rs` (+3 -1) 📝 `crates/horizon-shaders/src/post.rs` (+86 -0) </details> ### 📄 Description > 🤖 Opened by arslanarm's AI agent (Claude Code, Claude Opus 5.5), not by arslanarm personally. ## What and why Fixes #7178. A pack declares each storage buffer's size in `shaders.properties` (`bufferObject.<n> = <bytes> …`, Iris ShaderDoc, "Shader Storage Buffer Objects"). A shader may bind it as a larger block: std430 rounds a block's size up to its largest member's alignment. OpenGL binds the smaller buffer anyway. wgpu refuses the draw or dispatch, and its validation error stopped the render submit thread. As a result, RenderPearl v2.7.2 and Visual Vibrance v0.3.5a crashed the game on their first frame in a world: - RenderPearl: "the buffer bound at binding index 1 is bound with size 40980 where the shader expects 40992"; - Visual Vibrance: "… binding index 0 … size 40 where the shader expects 48". The changes: - `horizon-shaders`: `Post::buffer_minimums` reads, from every translated stage of every program (passes, geometry draws, shadow programs, compute stages), the size of each storage block in set 4, using naga's own layout, which is what wgpu checks the binding against. It keeps the largest per binding. - `gfx/pack_images.rs`: each storage buffer is made at least that large, still a multiple of 4. A larger declared size is kept as it is. Not in this PR: turning a pack off, instead of crashing, when its frame fails wgpu's validation. That needs an error scope on the submit thread and a way back to the game, so it gets its own issue and PR. ### Measured - `real_packs` over Modrinth's 40 most-downloaded packs, main 3783aa54b vs this branch, `SHOW_ERRORS=1`: identical, line for line, apart from timings (the test creates no GPU buffers; this only adds a method). - In the game (fast build, Xvfb, fresh homes, scenes `ow_ground_noon`, `ow_ground_sunset`, `nether_wastes`, vignette off). On main (a fast build of 6d91fa694, `ow_ground_noon`; the storage-buffer code is unchanged up to 3783aa54b), both packs crash on the first frame with the errors above. With this branch, both render every scene, and the log has no wgpu error. - Mean absolute difference to Iris 1.11.7 + Sodium 0.9.2 on the same scenes (of 255; mean brightness Horizon / Iris): | Pack | ow_ground_noon | ow_ground_sunset | nether_wastes | | --- | --- | --- | --- | | RenderPearl | 18.2 (98 / 91) | 11.7 (56 / 55) | 5.4 (28 / 31) | | Visual Vibrance | 34.8 (63 / 89) | 31.0 (47 / 67) | 8.8 (42 / 49) | The differences that remain are other gaps. RenderPearl's gbuffers programs still fail to translate (`textureQueryLod`, and its declarations: #7170, #7171), so its terrain draws as the game's own. Visual Vibrance's overworld is darker than in Iris, which this PR doesn't address. Tests: - `post::tests::storage_buffers_need_their_blocks_size` (`horizon-shaders`): a compute stage and a fragment stage bind the same buffer as blocks of different sizes, declared smaller than either. The largest block wins (48 bytes for 40 declared). A block with an array gets its element count's size (64). - `gfx::pack_images::tests::a_buffer_is_at_least_its_shaders_block`: the declared size grows to the block, a larger declared size stays, and per-pixel buffers follow the render size. Both are new; `Post::buffer_minimums` doesn't exist on main. ## 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). Sources: Iris ShaderDoc ("Shader Storage Buffer Objects"), wgpu's validation errors in Horizon's log, and black-box runs of Iris 1.11.7 with the two packs. ## Other projects' code none. No Iris, OptiFine or pack code read. RenderPearl and Visual Vibrance were only run as black boxes; the sizes above come from Horizon's own log. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on plony-pc, against origin/main at 3783aa54b, 3 min 30 s) | Check | Result | | --- | --- | | Scope | ✅ 3 files, +128 −3 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (39 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (1 min 45 s) | | tests: horizon-client-render, horizon-shaders | ✅ 1297 passed (56 s) | | doc tests | ✅ 0 passed (1 s) | | 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:07 +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#7409
No description provided.