[PR #502] [MERGED] Animated textures: cache every animation frame's mip chain #2604

Closed
opened 2026-11-02 15:57:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

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

Base: main ← Head: fix/animated-texture-tick-spikes


📝 Commits (2)

  • 1e1c3b7 Stop animated textures from slowing every tick's frame
  • dbe28ed Merge origin/main: use #501's staging belt, keep only the animation cache change

📊 Changes

1 file changed (+31 additions, -2 deletions)

View changed files

📝 crates/horizon-client/src/gfx.rs (+31 -2)

📄 Description

What

The sprite animation mip-chain cache was too small for vanilla. Sprite array layers are 64 px (the largest sprite), so one frame's mip chain is 21.8 KB, but it was stored in a 32 KB Vec. The 8 MiB budget held 256 chains, while vanilla's 54 animated sprites have 594 frames. The other 338 frames had their 64 px resample plus 6-level mip chain rebuilt on the render thread every time their animation reached them. This is part of the per-tick frame spike in #495.

This PR only keeps all 594 frames cached (13 MB), so 338 frames no longer have their mip chains rebuilt on the render thread:

  • ANIMATION_MIP_BUDGET goes from 8 MiB to 32 MiB.
  • mip_chain allocates its exact size (with a debug_assert_eq! on the length), so the cache's capacity accounting matches the data. All 594 frames fit in about 13 MB. HD packs stay bounded as before.
  • New tests: mip_chain_allocates_exactly_its_size, and every_vanilla_animation_frame_stays_cached (594 frames of 64 px chains stay cached within the budget).

Texels are unchanged.

The staging part moved to #501

This PR used to also send the animated sprites' uploads through one reused staging buffer (gfx/uploads.rs) and add an animate span. #501 did the upload part with wgpu::util::StagingBelt (gfx/upload.rs), recorded into the frame's encoder, and it is merged into main. This branch now merges main, uses #501's path, and drops uploads.rs, its tests and the animate span.

Checks

  • cargo fmt --all --check: ok
  • cargo clippy --workspace --all-targets -- -D warnings: ok
  • cargo test -p horizon-client --lib: 752 passed, 0 failed, 5 ignored
  • Local parity, tools/parity.py --changed origin/main: 84 passed, 0 failed (67.3 min)

Refs #495

🤖 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/502 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/animated-texture-tick-spikes` --- ### 📝 Commits (2) - [`1e1c3b7`](https://github.com/horizon-rust/horizon/commit/1e1c3b79e5267a532dc6a68444027edc83a3a299) Stop animated textures from slowing every tick's frame - [`dbe28ed`](https://github.com/horizon-rust/horizon/commit/dbe28edc9ba3563a7464404dc474f6e38d55b9b6) Merge origin/main: use #501's staging belt, keep only the animation cache change ### 📊 Changes **1 file changed** (+31 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/gfx.rs` (+31 -2) </details> ### 📄 Description ## What The sprite animation mip-chain cache was too small for vanilla. Sprite array layers are 64 px (the largest sprite), so one frame's mip chain is 21.8 KB, but it was stored in a 32 KB `Vec`. The 8 MiB budget held 256 chains, while vanilla's 54 animated sprites have **594 frames**. The other 338 frames had their 64 px resample plus 6-level mip chain rebuilt on the render thread every time their animation reached them. This is part of the per-tick frame spike in #495. This PR only keeps all 594 frames cached (13 MB), so 338 frames no longer have their mip chains rebuilt on the render thread: - `ANIMATION_MIP_BUDGET` goes from 8 MiB to 32 MiB. - `mip_chain` allocates its exact size (with a `debug_assert_eq!` on the length), so the cache's capacity accounting matches the data. All 594 frames fit in about 13 MB. HD packs stay bounded as before. - New tests: `mip_chain_allocates_exactly_its_size`, and `every_vanilla_animation_frame_stays_cached` (594 frames of 64 px chains stay cached within the budget). Texels are unchanged. ## The staging part moved to #501 This PR used to also send the animated sprites' uploads through one reused staging buffer (`gfx/uploads.rs`) and add an `animate` span. #501 did the upload part with `wgpu::util::StagingBelt` (`gfx/upload.rs`), recorded into the frame's encoder, and it is merged into main. This branch now merges main, uses #501's path, and drops `uploads.rs`, its tests and the `animate` span. ## Checks - `cargo fmt --all --check`: ok - `cargo clippy --workspace --all-targets -- -D warnings`: ok - `cargo test -p horizon-client --lib`: 752 passed, 0 failed, 5 ignored - Local parity, `tools/parity.py --changed origin/main`: **84 passed, 0 failed** (67.3 min) Refs #495 🤖 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-02 15:57:33 +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#2604
No description provided.