[PR #5670] [MERGED] Renderer: cut block sprites by the GPU's texture array limit #6427

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

📋 Pull Request Information

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

Base: main ← Head: fix/sprite-split-adapter-limit


📝 Commits (1)

  • 475af96 Renderer: cut block sprites by the GPU's texture array limit

📊 Changes

1 file changed (+134 additions, -32 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+134 -32)

📄 Description

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

Fixes a startup crash reported on Discord (2026-11-01): GPU supports 512 texture layers; 1291 required on a GPU whose max_texture_array_layers is 512.

Terrain already draws block sprites from up to 8 texture arrays (#647), but the layers per array were always 2048 (or HORIZON_SPRITE_SPLIT), never the adapter's limit. 1291 sprites fit in 3 arrays of 512.

Change (crates/horizon-client-render/src/gfx.rs)

  • layer_split: split = min(SPRITE_SPLIT, HORIZON_SPRITE_SPLIT, adapter's max_texture_array_layers); on OpenGL, one less when a full array is a multiple of 6 and array_layers would pad it past the limit.
  • Computed once in Renderer::new (no per-frame cost), stored in Renderer::sprite_split, and used by the sprite arrays, terrain.wgsl's SPRITE_SPLIT constant, the animator, the emission stats and the shader pack atlas (which called sprite_split() before).
  • check_layers (adapter selection) now fails only when the sprites need more than 8 arrays of that split, with a clear message.
  • Mip chains the resource worker prepared before the adapter was known are cut again (PreparedTextures::resplit) when the adapter's split is smaller. Nothing changes on GPUs with 2048+ layers.

Tests

  • sprite_split_follows_the_adapters_layer_limit: 512 limit + 1291 layers → 512; env only lowers; OpenGL padding (600 → 599); 128 limit → error.
  • prepared_texture_uploads_preserve_layer_order_and_settings now also checks resplit gives the same arrays as cutting directly.
  • Mac mini (M4 Pro, Metal), fresh scratch homes, horizon-ctl launch --offscreen, tp to the same spot: HORIZON_SPRITE_SPLIT=512 logs 1291 block textures in 3 arrays and renders the same terrain and textures as the default split (only the random player skin and clouds differ).

pr_ready (tools/pr_ready.py --quick on ludovics-mac-mini, against origin/main at ba8b5b414, 5 min 55 s)

Check Result
Scope ✅ 1 files, +134 −32
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 511 passed (2 min 27 s)
rustfmt ✅ (16 s)
clippy ✅ (2 min 0 s)
tests: horizon-client-render ✅ 830 passed (25 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 117 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer, breaking_model and 105 more
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/5670 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/sprite-split-adapter-limit` --- ### 📝 Commits (1) - [`475af96`](https://github.com/horizon-rust/horizon/commit/475af9674a0a27e5be45100cfb333603054290a0) Renderer: cut block sprites by the GPU's texture array limit ### 📊 Changes **1 file changed** (+134 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+134 -32) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes a startup crash reported on Discord (2026-11-01): `GPU supports 512 texture layers; 1291 required` on a GPU whose `max_texture_array_layers` is 512. Terrain already draws block sprites from up to 8 texture arrays (#647), but the layers per array were always 2048 (or `HORIZON_SPRITE_SPLIT`), never the adapter's limit. 1291 sprites fit in 3 arrays of 512. **Change** (`crates/horizon-client-render/src/gfx.rs`) - `layer_split`: split = min(`SPRITE_SPLIT`, `HORIZON_SPRITE_SPLIT`, adapter's `max_texture_array_layers`); on OpenGL, one less when a full array is a multiple of 6 and `array_layers` would pad it past the limit. - Computed once in `Renderer::new` (no per-frame cost), stored in `Renderer::sprite_split`, and used by the sprite arrays, terrain.wgsl's `SPRITE_SPLIT` constant, the animator, the emission stats and the shader pack atlas (which called `sprite_split()` before). - `check_layers` (adapter selection) now fails only when the sprites need more than 8 arrays of that split, with a clear message. - Mip chains the resource worker prepared before the adapter was known are cut again (`PreparedTextures::resplit`) when the adapter's split is smaller. Nothing changes on GPUs with 2048+ layers. **Tests** - `sprite_split_follows_the_adapters_layer_limit`: 512 limit + 1291 layers → 512; env only lowers; OpenGL padding (600 → 599); 128 limit → error. - `prepared_texture_uploads_preserve_layer_order_and_settings` now also checks `resplit` gives the same arrays as cutting directly. - Mac mini (M4 Pro, Metal), fresh scratch homes, `horizon-ctl launch --offscreen`, tp to the same spot: `HORIZON_SPRITE_SPLIT=512` logs `1291 block textures in 3 arrays` and renders the same terrain and textures as the default split (only the random player skin and clouds differ). **pr_ready** (`tools/pr_ready.py --quick` on ludovics-mac-mini, against origin/main at ba8b5b414, 5 min 55 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +134 −32 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 511 passed (2 min 27 s) | | rustfmt | ✅ (16 s) | | clippy | ✅ (2 min 0 s) | | tests: horizon-client-render | ✅ 830 passed (25 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 117 affected, to run in CI (--quick): ambient_sound, arrow, audio_attributes, auto_jump, block_entity_anim, block_entity_render, block_entity_tickers, block_particles, block_removal, block_tint, block_transformer, breaking_model and 105 more | | 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:20:26 +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#6427
No description provided.