[PR #4983] [MERGED] Rendering Optimization: Cull offscreen animated sprites #5989

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4983
Author: @elythepreciouscat
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: perf/cull-offscreen-animated-sprites


📝 Commits (7)

  • addeaf1 Renderer: cull offscreen animated sprites
  • 2e0198a Renderer: optimize animated sprite layer culling
  • ba89dc1 Merge main to resolve renderer mesh conflict
  • 0f25a86 Merge origin/main into animated sprite culling
  • b7a7aa8 Merge origin/main (picks up #5251's compile fixes)
  • 79d05b5 Merge origin/main (picks up #5304's hub.rs build fix)
  • 2880dda Merge origin/main: fluid quads take main's face shade and still record animated layers

📊 Changes

5 files changed (+214 additions, -7 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+81 -3)
📝 crates/horizon-client-render/src/gfx/animate.rs (+88 -4)
📝 crates/horizon-client-render/src/lod/mesh.rs (+2 -0)
📝 crates/horizon-client-render/src/mesher.rs (+38 -0)
📝 crates/horizon-client-render/src/mesher/fluid.rs (+5 -0)

📄 Description

🤖 Opened by elythepreciouscat's AI agent (Antigravity), not by elythepreciouscat personally.

Fixes #4859 (Supersedes #4860)

Summary of Changes

  1. Smart animated texture culling (gfx/animate.rs, gfx.rs):

    • Track animated sprite layers while terrain and fluid meshes emit quads, including LOD meshes, instead of rescanning every terrain vertex during upload.
    • Store the visible animated-layer set as a bitset, making each sprite's active-layer check O(1) instead of scanning a vector.
    • Collect active layers from visible sections, visible/fading LOD tiles, and shadow sections, then enqueue animation uploads before terrain draws using the current visibility mask.
    • Keep opaque-layer masking in the mesh metadata so opaque animated blocks (magma, lava, prismarine, sea lanterns, command blocks, sculk, and similar sprites) are identified correctly.
    • Scope the culling to the block/terrain atlas; the separate HUD/entity atlas (held items, hotbar, dropped items, particles, and block-entity geometry) continues through hud.animate_sprites every frame.
  2. Testing:

    • Retained and updated the selective sprite collection and opaque-layer tests.
    • Added mesh metadata coverage through the existing upload test path.

Corrected live benchmark

Both variants used release binaries, the current worktree horizon-ctl, isolated HORIZON_HOME/XDG homes, audio disabled, the same generated scene, and the llvmpipe Vulkan backend. Baseline was launcher v0.2.97; candidate was this branch at commit 2e0198ab3.

Scenario Metric Baseline Candidate Change
Offscreen Average FPS 15.3 17.4 +13.1%
Offscreen CPU frame time 64.55 ms 54.93 ms −14.9%
Offscreen GPU frame time 59.14 ms 56.07 ms −5.2%
Onscreen Average FPS 18.7 28.3 +50.9%
Onscreen CPU frame time 50.39 ms 31.82 ms −36.8%
Onscreen GPU frame time 48.59 ms 34.11 ms −29.8%

The initial report used a stale instrumented executable and a stale control client, so its scene-building commands failed and its numbers were not a comparison of this source. The run above was repeated from clean isolated homes with the current binaries.

Validation

  • python3 tools/pr_ready.py --quick: ✅ 481 Python tests, clippy, rustfmt, 652 renderer tests, and doc tests.
  • cargo test --locked -p horizon-client-render --tests: ✅ 652 passed, 17 ignored.
  • cargo fmt --all -- --check: ✅
  • cargo build --release --locked -p horizon-client --bin horizon-client --bin horizon-ctl: ✅

(The vertical occlusion search clamping in occlusion.rs remains split into its own dedicated PR as requested in #4860's review.)

🤖 Generated with 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/4983 **Author:** [@elythepreciouscat](https://github.com/elythepreciouscat) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/cull-offscreen-animated-sprites` --- ### 📝 Commits (7) - [`addeaf1`](https://github.com/horizon-rust/horizon/commit/addeaf1c58c02e89def27ad4733ae23b9f645808) Renderer: cull offscreen animated sprites - [`2e0198a`](https://github.com/horizon-rust/horizon/commit/2e0198ab3b98433300d6caed0cc843624f0376a7) Renderer: optimize animated sprite layer culling - [`ba89dc1`](https://github.com/horizon-rust/horizon/commit/ba89dc137e3fe7f53ba2304ff1f3d6b829770650) Merge main to resolve renderer mesh conflict - [`0f25a86`](https://github.com/horizon-rust/horizon/commit/0f25a86b375e099b5438f5810dce8ae2c19ec3ba) Merge origin/main into animated sprite culling - [`b7a7aa8`](https://github.com/horizon-rust/horizon/commit/b7a7aa8fc3aa9e667abfbb8eb351d4fd88bffd8c) Merge origin/main (picks up #5251's compile fixes) - [`79d05b5`](https://github.com/horizon-rust/horizon/commit/79d05b573ec0ec131592b089fb2d8f611d818263) Merge origin/main (picks up #5304's hub.rs build fix) - [`2880dda`](https://github.com/horizon-rust/horizon/commit/2880dda4d398cb10d75c9176324f481a6ac58653) Merge origin/main: fluid quads take main's face shade and still record animated layers ### 📊 Changes **5 files changed** (+214 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+81 -3) 📝 `crates/horizon-client-render/src/gfx/animate.rs` (+88 -4) 📝 `crates/horizon-client-render/src/lod/mesh.rs` (+2 -0) 📝 `crates/horizon-client-render/src/mesher.rs` (+38 -0) 📝 `crates/horizon-client-render/src/mesher/fluid.rs` (+5 -0) </details> ### 📄 Description > 🤖 Opened by elythepreciouscat's AI agent (Antigravity), not by elythepreciouscat personally. Fixes #4859 (Supersedes #4860) ### Summary of Changes 1. **Smart animated texture culling (`gfx/animate.rs`, `gfx.rs`)**: - Track animated sprite layers while terrain and fluid meshes emit quads, including LOD meshes, instead of rescanning every terrain vertex during upload. - Store the visible animated-layer set as a bitset, making each sprite's active-layer check O(1) instead of scanning a vector. - Collect active layers from visible sections, visible/fading LOD tiles, and shadow sections, then enqueue animation uploads before terrain draws using the current visibility mask. - Keep opaque-layer masking in the mesh metadata so opaque animated blocks (magma, lava, prismarine, sea lanterns, command blocks, sculk, and similar sprites) are identified correctly. - Scope the culling to the block/terrain atlas; the separate HUD/entity atlas (held items, hotbar, dropped items, particles, and block-entity geometry) continues through `hud.animate_sprites` every frame. 2. **Testing**: - Retained and updated the selective sprite collection and opaque-layer tests. - Added mesh metadata coverage through the existing upload test path. ### Corrected live benchmark Both variants used release binaries, the current worktree `horizon-ctl`, isolated `HORIZON_HOME`/XDG homes, audio disabled, the same generated scene, and the llvmpipe Vulkan backend. Baseline was launcher v0.2.97; candidate was this branch at commit `2e0198ab3`. | Scenario | Metric | Baseline | Candidate | Change | | --- | ---: | ---: | ---: | ---: | | Offscreen | Average FPS | 15.3 | 17.4 | **+13.1%** | | Offscreen | CPU frame time | 64.55 ms | 54.93 ms | **−14.9%** | | Offscreen | GPU frame time | 59.14 ms | 56.07 ms | **−5.2%** | | Onscreen | Average FPS | 18.7 | 28.3 | **+50.9%** | | Onscreen | CPU frame time | 50.39 ms | 31.82 ms | **−36.8%** | | Onscreen | GPU frame time | 48.59 ms | 34.11 ms | **−29.8%** | The initial report used a stale instrumented executable and a stale control client, so its scene-building commands failed and its numbers were not a comparison of this source. The run above was repeated from clean isolated homes with the current binaries. ### Validation - `python3 tools/pr_ready.py --quick`: ✅ 481 Python tests, clippy, rustfmt, 652 renderer tests, and doc tests. - `cargo test --locked -p horizon-client-render --tests`: ✅ 652 passed, 17 ignored. - `cargo fmt --all -- --check`: ✅ - `cargo build --release --locked -p horizon-client --bin horizon-client --bin horizon-ctl`: ✅ *(The vertical occlusion search clamping in `occlusion.rs` remains split into its own dedicated PR as requested in #4860's review.)* 🤖 Generated with [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 05:16: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#5989
No description provided.