[PR #6612] [MERGED] Cache static block entity models in per-section GPU buffers #6981

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

📋 Pull Request Information

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

Base: main ← Head: perf/static-block-entity-batching


📝 Commits (10+)

  • 29c042c Batch static block entity rendering by section
  • b90be5a Update matched block-entity benchmark evidence
  • 6675c76 Keep entity occlusion culling off block entities
  • 9b1b967 Merge branch 'main' into perf/static-block-entity-batching
  • 21098a3 Regenerate mod API output
  • c13fcd6 Merge origin/main into perf/static-block-entity-batching
  • 1f420bf Add block entity graphics text to English language table
  • 00d205e Merge branch 'main' into perf/static-block-entity-batching
  • b1fb827 Merge branch 'main' into perf/static-block-entity-batching
  • e56cf5c Entity Culling still culls block entities when no model cache is on

📊 Changes

26 files changed (+3530 additions, -170 deletions)

View changed files

📝 crates/horizon-client-render/src/block_entity_render.rs (+1191 -126)
➕ crates/horizon-client-render/src/block_entity_render_tests.rs (+1536 -0)
📝 crates/horizon-client-render/src/gfx.rs (+374 -5)
📝 crates/horizon-client-render/src/gfx/pack_uniforms.rs (+3 -0)
📝 crates/horizon-client-render/src/graphics.rs (+60 -1)
📝 crates/horizon-client-render/src/graphics_ui.rs (+97 -3)
📝 crates/horizon-client-render/src/hud.rs (+9 -0)
➕ crates/horizon-client-render/src/static_entity.wgsl (+21 -0)
📝 crates/horizon-client/assets/horizon/lang/de_de.json (+4 -0)
📝 crates/horizon-client/assets/horizon/lang/en_us.json (+19 -0)
📝 crates/horizon-client/assets/horizon/lang/es_es.json (+4 -0)
📝 crates/horizon-client/assets/horizon/lang/fr_fr.json (+4 -0)
📝 crates/horizon-client/assets/horizon/lang/pl_pl.json (+4 -0)
📝 crates/horizon-client/assets/horizon/lang/ru_ru.json (+4 -0)
📝 crates/horizon-client/assets/horizon/lang/tr_tr.json (+4 -0)
📝 crates/horizon-client/assets/horizon/lang/uk_ua.json (+4 -0)
📝 crates/horizon-client/assets/horizon/lang/zh_cn.json (+4 -0)
📝 crates/horizon-client/examples/probe/block_entity_render_fixture.rs (+3 -1)
📝 crates/horizon-client/src/control.rs (+50 -0)
📝 crates/horizon-client/src/game.rs (+122 -27)

...and 6 more files

📄 Description

🤖 Opened by elythepreciouscat's AI agent (OpenAI Codex, GPT-6), not by elythepreciouscat personally.

What and why

Fixes #6039
Fixes #6644.

Cache stable block-entity model geometry in per-section GPU buffers to reduce repeated vertex extraction, uploads and draw preparation in chest-heavy scenes. The seven per-type controls live under Advanced Graphics → Block Entities. Model caches are off by default; the existing sign-text cache remains on by default.

The cache keeps only settled geometry. Opening shulkers and chests, ringing bells, decorated-pot wobble and sherd changes, banner flags/patterns, and statue pose changes continue through the animated renderer path. Shader-pack span callbacks still use the regular per-frame entity buffer; Entity Culling alone no longer forces that fallback. Fractional-alpha pack sprites stay on the existing blended pipeline.

Implementation details:

  • Build snapshots from loaded nearby sections, independently of the block-level frustum set. Camera rotation updates the section draw list without rebuilding vertices.
  • Keep entity occlusion on ordinary entity meshes. Block entities retain section and per-block frustum culling, and Entity Culling no longer disables their per-section GPU snapshots. Native mod block entities use their render bounds. Entity Culling help now describes Off, Synchronous and Asynchronous separately.
  • Rebase section geometry with one camera transform, retaining the integer camera block until the shader subtracts section origins.
  • Invalidate only changed sections for mesh/light and block-entity membership updates. Atlas identity changes invalidate cached UVs even when sprite rectangles remain at the same coordinates.
  • Keep opaque/cutout cached geometry out of the blended pipeline. Track snapshot rebuilds, CPU snapshot bytes, GPU bytes uploaded, and static/dynamic entities drawn in horizon-ctl bench output.
  • Add behavior tests for animation transitions, chest variants and double chests, section revisions, atlas reloads, cache toggles, and matching cached/direct vertices. Extend the parity fixture for waxed copper chest and statue variants.

Benchmark

Two 20-second horizon-ctl bench runs per setting, after a 10-second warm-up. The cache-on run used a copy of the same saved world as cache-off. Both used the same camera position (-0.5, 101, -10.5), yaw 0°, and pitch −35°; the screenshots below are this matched pair. The scene is a 32×32 stone platform and a no-gap chest array 32 blocks wide, 32 high and four deep (4,096 alternating regular and trapped chests).

Both runs used offscreen Vulkan at 675×727, render distance 6, VSync off, maxFps:260, and inactivityFpsLimit:minimized. All seven cache switches were off in the baseline; only chests were enabled in the candidate.

Host: Intel HD Graphics 4000 (Ivy Bridge), Intel Mesa 26.2.4.

Setting Mean FPS (runs) Mean 1% low Mean CPU/frame Static draws/frame Dynamic draws/frame
Caches off 44.19 (44.29, 44.09) 23.09 22.54 ms 0 3,552
Chests on 56.34 (56.37, 56.30) 39.21 17.62 ms 4,096 0

That is 27.5% higher mean FPS, 21.8% lower CPU time, and 1.70× the 1% low. During both measured cache-on windows, snapshot rebuilds, snapshot bytes built and GPU bytes uploaded were all zero; the snapshots had settled during warm-up. The Mesa driver reports timestamp queries unsupported on Ivy Bridge, so GPU time reads as zero and is not a usable comparison here.

Cache off: matched chest-wall view with performance graph

Chest cache on: same camera pose and performance graph

Kind

  • parity
  • bug
  • perf
  • feature
  • extra
  • tooling
  • docs

Vanilla reference

Horizon-only rendering optimization. Vanilla 26.3's block-entity model geometry, state and animation outputs remain the reference; cached and direct paths are compared in the new behavior tests and tools/test_block_entity_render_parity.py. The previous quick check selected the affected parity harnesses for CI rather than running them locally.

Other projects' code

None.

Self-check

The requested previous pr_ready --quick result was on the earlier base eb0d9e580; it is included below and was not rerun. Since then, the branch was fast-forwarded to origin/main at 8d93d68f, conflicts were resolved, and the current head passed CARGO_BUILD_JOBS=8 cargo build --profile fast -p horizon-client (7m 17s).

pr_ready (tools/pr_ready.py --quick on omarchy, against origin/main at eb0d9e580, 23 min 45 s)

Check Result
Scope ⚠️ 15 files, +3453 −168; 3609 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 595 passed (1 min 8 s)
rustfmt ✅ (16 s)
clippy ✅ (2 min 23 s)
tests: horizon-client, horizon-client-lib, horizon-client-render ✅ 2907 passed (19 min 22 s)
doc tests ✅ 0 passed (26 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 ➖ 369 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, armor_stand_frost, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes and 357 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The scope warning is real: 15 files and over 3,400 added lines. The renderer, per-section GPU path, settings and tests are one integrated change; splitting out model types or invalidation paths would leave partial behavior. block_entity_render_tests.rs carries the transition and parity coverage for the seven independently selectable caches.

Screenshots

See the two benchmark-scene captures above; the performance graph is visible in each.

🤖 Generated with OpenAI 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/6612 **Author:** [@elythepreciouscat](https://github.com/elythepreciouscat) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/static-block-entity-batching` --- ### 📝 Commits (10+) - [`29c042c`](https://github.com/horizon-rust/horizon/commit/29c042c74c9907275a205c208e9f63e24e439f29) Batch static block entity rendering by section - [`b90be5a`](https://github.com/horizon-rust/horizon/commit/b90be5a701dc0cf58e3907e0528b4253d59a8577) Update matched block-entity benchmark evidence - [`6675c76`](https://github.com/horizon-rust/horizon/commit/6675c767e71d9aa3a19e4cbca9933bcf0173cce0) Keep entity occlusion culling off block entities - [`9b1b967`](https://github.com/horizon-rust/horizon/commit/9b1b96779da6fdbc7c53bd8f1a6135d7914970f1) Merge branch 'main' into perf/static-block-entity-batching - [`21098a3`](https://github.com/horizon-rust/horizon/commit/21098a36519715e551b13965932f1c7d89c9e2e9) Regenerate mod API output - [`c13fcd6`](https://github.com/horizon-rust/horizon/commit/c13fcd609e726935e1a594481c23a382830172a0) Merge origin/main into perf/static-block-entity-batching - [`1f420bf`](https://github.com/horizon-rust/horizon/commit/1f420bfc12943cb9d4815b29a2de0df4859c9260) Add block entity graphics text to English language table - [`00d205e`](https://github.com/horizon-rust/horizon/commit/00d205ee470989026f26435ffc94eeddafa9d7f6) Merge branch 'main' into perf/static-block-entity-batching - [`b1fb827`](https://github.com/horizon-rust/horizon/commit/b1fb827affd5baf1a18a6acf47fd8bce7fe4b55e) Merge branch 'main' into perf/static-block-entity-batching - [`e56cf5c`](https://github.com/horizon-rust/horizon/commit/e56cf5c26183845e162e9c1017ff0ee7211db7d7) Entity Culling still culls block entities when no model cache is on ### 📊 Changes **26 files changed** (+3530 additions, -170 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/block_entity_render.rs` (+1191 -126) ➕ `crates/horizon-client-render/src/block_entity_render_tests.rs` (+1536 -0) 📝 `crates/horizon-client-render/src/gfx.rs` (+374 -5) 📝 `crates/horizon-client-render/src/gfx/pack_uniforms.rs` (+3 -0) 📝 `crates/horizon-client-render/src/graphics.rs` (+60 -1) 📝 `crates/horizon-client-render/src/graphics_ui.rs` (+97 -3) 📝 `crates/horizon-client-render/src/hud.rs` (+9 -0) ➕ `crates/horizon-client-render/src/static_entity.wgsl` (+21 -0) 📝 `crates/horizon-client/assets/horizon/lang/de_de.json` (+4 -0) 📝 `crates/horizon-client/assets/horizon/lang/en_us.json` (+19 -0) 📝 `crates/horizon-client/assets/horizon/lang/es_es.json` (+4 -0) 📝 `crates/horizon-client/assets/horizon/lang/fr_fr.json` (+4 -0) 📝 `crates/horizon-client/assets/horizon/lang/pl_pl.json` (+4 -0) 📝 `crates/horizon-client/assets/horizon/lang/ru_ru.json` (+4 -0) 📝 `crates/horizon-client/assets/horizon/lang/tr_tr.json` (+4 -0) 📝 `crates/horizon-client/assets/horizon/lang/uk_ua.json` (+4 -0) 📝 `crates/horizon-client/assets/horizon/lang/zh_cn.json` (+4 -0) 📝 `crates/horizon-client/examples/probe/block_entity_render_fixture.rs` (+3 -1) 📝 `crates/horizon-client/src/control.rs` (+50 -0) 📝 `crates/horizon-client/src/game.rs` (+122 -27) _...and 6 more files_ </details> ### 📄 Description > 🤖 Opened by elythepreciouscat's AI agent (OpenAI Codex, GPT-6), not by elythepreciouscat personally. ## What and why Fixes #6039 Fixes #6644. Cache stable block-entity model geometry in per-section GPU buffers to reduce repeated vertex extraction, uploads and draw preparation in chest-heavy scenes. The seven per-type controls live under **Advanced Graphics → Block Entities**. Model caches are off by default; the existing sign-text cache remains on by default. The cache keeps only settled geometry. Opening shulkers and chests, ringing bells, decorated-pot wobble and sherd changes, banner flags/patterns, and statue pose changes continue through the animated renderer path. Shader-pack span callbacks still use the regular per-frame entity buffer; Entity Culling alone no longer forces that fallback. Fractional-alpha pack sprites stay on the existing blended pipeline. Implementation details: - Build snapshots from loaded nearby sections, independently of the block-level frustum set. Camera rotation updates the section draw list without rebuilding vertices. - Keep entity occlusion on ordinary entity meshes. Block entities retain section and per-block frustum culling, and Entity Culling no longer disables their per-section GPU snapshots. Native mod block entities use their render bounds. Entity Culling help now describes Off, Synchronous and Asynchronous separately. - Rebase section geometry with one camera transform, retaining the integer camera block until the shader subtracts section origins. - Invalidate only changed sections for mesh/light and block-entity membership updates. Atlas identity changes invalidate cached UVs even when sprite rectangles remain at the same coordinates. - Keep opaque/cutout cached geometry out of the blended pipeline. Track snapshot rebuilds, CPU snapshot bytes, GPU bytes uploaded, and static/dynamic entities drawn in `horizon-ctl bench` output. - Add behavior tests for animation transitions, chest variants and double chests, section revisions, atlas reloads, cache toggles, and matching cached/direct vertices. Extend the parity fixture for waxed copper chest and statue variants. ## Benchmark Two 20-second `horizon-ctl bench` runs per setting, after a 10-second warm-up. The cache-on run used a copy of the same saved world as cache-off. Both used the same camera position `(-0.5, 101, -10.5)`, yaw `0°`, and pitch `−35°`; the screenshots below are this matched pair. The scene is a 32×32 stone platform and a no-gap chest array 32 blocks wide, 32 high and four deep (4,096 alternating regular and trapped chests). Both runs used offscreen Vulkan at 675×727, render distance 6, VSync off, `maxFps:260`, and `inactivityFpsLimit:minimized`. All seven cache switches were off in the baseline; only chests were enabled in the candidate. Host: Intel HD Graphics 4000 (Ivy Bridge), Intel Mesa 26.2.4. | Setting | Mean FPS (runs) | Mean 1% low | Mean CPU/frame | Static draws/frame | Dynamic draws/frame | | --- | ---: | ---: | ---: | ---: | ---: | | Caches off | 44.19 (44.29, 44.09) | 23.09 | 22.54 ms | 0 | 3,552 | | Chests on | 56.34 (56.37, 56.30) | 39.21 | 17.62 ms | 4,096 | 0 | That is **27.5% higher mean FPS**, **21.8% lower CPU time**, and **1.70× the 1% low**. During both measured cache-on windows, snapshot rebuilds, snapshot bytes built and GPU bytes uploaded were all zero; the snapshots had settled during warm-up. The Mesa driver reports timestamp queries unsupported on Ivy Bridge, so GPU time reads as zero and is not a usable comparison here. ![Cache off: matched chest-wall view with performance graph](https://github.com/elythepreciouscat/horizon/blob/perf/static-block-entity-batching/docs/media/static-block-entity-batching-off.png?raw=1) ![Chest cache on: same camera pose and performance graph](https://github.com/elythepreciouscat/horizon/blob/perf/static-block-entity-batching/docs/media/static-block-entity-batching-on.png?raw=1) ## Kind - [ ] parity - [ ] bug - [x] perf - [ ] feature - [ ] extra - [ ] tooling - [ ] docs ## Vanilla reference Horizon-only rendering optimization. Vanilla 26.3's block-entity model geometry, state and animation outputs remain the reference; cached and direct paths are compared in the new behavior tests and `tools/test_block_entity_render_parity.py`. The previous quick check selected the affected parity harnesses for CI rather than running them locally. ## Other projects' code None. ## Self-check The requested previous `pr_ready --quick` result was on the earlier base `eb0d9e580`; it is included below and was not rerun. Since then, the branch was fast-forwarded to `origin/main` at `8d93d68f`, conflicts were resolved, and the current head passed `CARGO_BUILD_JOBS=8 cargo build --profile fast -p horizon-client` (7m 17s). **pr_ready** (`tools/pr_ready.py --quick` on omarchy, against origin/main at eb0d9e580, 23 min 45 s) | Check | Result | | --- | --- | | Scope | ⚠️ 15 files, +3453 −168; 3609 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 595 passed (1 min 8 s) | | rustfmt | ✅ (16 s) | | clippy | ✅ (2 min 23 s) | | tests: horizon-client, horizon-client-lib, horizon-client-render | ✅ 2907 passed (19 min 22 s) | | doc tests | ✅ 0 passed (26 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 | ➖ 369 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, armor_stand_frost, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes and 357 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The scope warning is real: 15 files and over 3,400 added lines. The renderer, per-section GPU path, settings and tests are one integrated change; splitting out model types or invalidation paths would leave partial behavior. `block_entity_render_tests.rs` carries the transition and parity coverage for the seven independently selectable caches. ## Screenshots See the two benchmark-scene captures above; the performance graph is visible in each. 🤖 Generated with [OpenAI Codex](https://openai.com/codex) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:30:36 +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#6981
No description provided.