[PR #485] [MERGED] Reuse cloud geometry and GPU buffers between frames #2599

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

📋 Pull Request Information

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

Base: main ← Head: codex/issue-480-cloud-cpu


📝 Commits (2)

  • 56fec97 Reuse cloud geometry and GPU buffers between frames
  • 45397e4 Merge main and reconcile cloud caching with see-through text

📊 Changes

5 files changed (+357 additions, -154 deletions)

View changed files

📝 crates/horizon-client/src/clouds.rs (+213 -0)
📝 crates/horizon-client/src/entity.wgsl (+15 -2)
📝 crates/horizon-client/src/game.rs (+19 -117)
📝 crates/horizon-client/src/gfx.rs (+104 -27)
📝 crates/horizon-client/src/gfx/entity_batch.rs (+6 -8)

📄 Description

What and why

Fixes #480.

Visible clouds currently regenerate their entire mesh every frame, then pass through dynamic entity grouping/copying and another GPU upload. The repeated cell traversal grows quadratically with Cloud Distance, even while stationary. Buffer capacity was already reused; unconditional mesh generation and uploads were the bottleneck.

Retain the cloud mesh and its GPU vertex buffer separately from dynamic entities. Rebuild when the wrapped cloud cell, vertical face-selection region, Fast/Fancy mode, or radius changes. Update movement and the existing four packed face colors through an 80-byte uniform each frame. Resource reload constructs a new renderer/cache, and existing wgpu ownership handles cleanup. Existing face selection, winding, traversal order and fog behavior are preserved.

Benchmarks

Fresh optimized builds on the same Windows PC, RTX 5080 / Vulkan, seed 1234, render distance 12, 1280×720, Immediate presentation, VSync off, unlimited FPS, idle throttling disabled. Each sample is horizon-ctl bench 6 after active streaming jobs settle. Player/view: /tp @s -529.5 66 68.5 0 0.

Clouds Distance Before FPS After FPS Before CPU ms/frame After CPU ms/frame
Fancy 128 379.8 1579.5 2.407 0.479
Fast 128 466.8 1542.4 1.920 0.488
Off — 1539.1 1562.6 0.440 0.481

Fancy 128 preparation fell from 1.495 to 0.215 ms and render CPU time from 0.731 to 0.211 ms. GPU time was 0.103 → 0.124 ms. Additional after-only samples: Fast 32, 1558.6 FPS / 0.482 ms CPU; Fancy 64, 1493.3 FPS / 0.497 ms CPU.

Measurements compare upstream 4224687e5 with this cloud fix applied, before the clean rebase onto current main 8da9c8c4c. Final formatting, Clippy, library tests and cloud parity were rerun after rebasing. These are individual six-second samples, with simulation/background activity not frozen; small differences are noise.

Validation

  • All 3,190 existing cloud-render parity cases match the pinned 26.3 client (face selection/traversal coverage, not full framebuffer parity).
  • All eight cloud tests pass, including 100 successive cache hits while sub-cell movement/time/color change, plus cell, vertical-region, mode, distance and drift invalidation.
  • Before rebasing, client/control binary tests passed: 47 and 15 respectively (one client test ignored).
  • Live smoke checks covered Fast/Fancy, Off/on, distances 32/64/128, stationary rendering, rotation, cell crossings, vertical movement and resource reload without GPU validation errors. The contributor manually tested the optimized build and confirmed it works well.
  • Full client library tests after rebasing: 732 passed, 5 failed, 5 ignored. The failing modules are unchanged: crash-stack path formatting; resource-cache output recovery (Windows Access Denied); session-lock exclusivity; and two server-properties tests (CRLF/LF expectations). They were not changed as part of this performance fix. No separate baseline runtime run was used to establish their prior status.
  • Extended visual/animation coverage, custom resource packs, other dimensions/world transitions and other GPUs remain unverified. No intended visual change.

Vanilla reference

Inspected the checksum-pinned Minecraft Java Edition 26.3 implementation locally using Horizon's research workflow, including tools/rea_vanilla.py's CloudRenderer.prepare render-preparation overload, and the local bytecode/decompiled reference:

  • net.minecraft.client.renderer.CloudRenderer.prepare (texture and per-frame overloads), apply, buildMesh, tryBuildCell, buildFlatCell, buildExtrudedCell, markForRebuild, render, endFrame, close.
  • LevelRenderer.prepareTranslucents, invalidateCompiledGeometry, endFrame, close.
  • Harness: tools/test_cloud_render_parity.py.

Also consulted mcsrc.dev and Sodium's 26.3 CloudRendererMixin. Sodium optimizes compact face encoding while relying on vanilla's mesh reuse; that encoding rewrite was unnecessary here. Its different interior-neighbor rule was not adopted. No third-party implementation code was copied.


🔄 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/485 **Author:** [@LookImEcho-Rick](https://github.com/LookImEcho-Rick) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `codex/issue-480-cloud-cpu` --- ### 📝 Commits (2) - [`56fec97`](https://github.com/horizon-rust/horizon/commit/56fec974ee9070484151b48bd9ebb8521ad88712) Reuse cloud geometry and GPU buffers between frames - [`45397e4`](https://github.com/horizon-rust/horizon/commit/45397e4b304cb5e81df5fde4354549fc31b2ec32) Merge main and reconcile cloud caching with see-through text ### 📊 Changes **5 files changed** (+357 additions, -154 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/clouds.rs` (+213 -0) 📝 `crates/horizon-client/src/entity.wgsl` (+15 -2) 📝 `crates/horizon-client/src/game.rs` (+19 -117) 📝 `crates/horizon-client/src/gfx.rs` (+104 -27) 📝 `crates/horizon-client/src/gfx/entity_batch.rs` (+6 -8) </details> ### 📄 Description ## What and why Fixes #480. Visible clouds currently regenerate their entire mesh every frame, then pass through dynamic entity grouping/copying and another GPU upload. The repeated cell traversal grows quadratically with Cloud Distance, even while stationary. Buffer capacity was already reused; unconditional mesh generation and uploads were the bottleneck. Retain the cloud mesh and its GPU vertex buffer separately from dynamic entities. Rebuild when the wrapped cloud cell, vertical face-selection region, Fast/Fancy mode, or radius changes. Update movement and the existing four packed face colors through an 80-byte uniform each frame. Resource reload constructs a new renderer/cache, and existing wgpu ownership handles cleanup. Existing face selection, winding, traversal order and fog behavior are preserved. ### Benchmarks Fresh optimized builds on the same Windows PC, RTX 5080 / Vulkan, seed 1234, render distance 12, 1280×720, Immediate presentation, VSync off, unlimited FPS, idle throttling disabled. Each sample is `horizon-ctl bench 6` after active streaming jobs settle. Player/view: `/tp @s -529.5 66 68.5 0 0`. | Clouds | Distance | Before FPS | After FPS | Before CPU ms/frame | After CPU ms/frame | | --- | ---: | ---: | ---: | ---: | ---: | | Fancy | 128 | 379.8 | 1579.5 | 2.407 | 0.479 | | Fast | 128 | 466.8 | 1542.4 | 1.920 | 0.488 | | Off | — | 1539.1 | 1562.6 | 0.440 | 0.481 | Fancy 128 preparation fell from 1.495 to 0.215 ms and render CPU time from 0.731 to 0.211 ms. GPU time was 0.103 → 0.124 ms. Additional after-only samples: Fast 32, 1558.6 FPS / 0.482 ms CPU; Fancy 64, 1493.3 FPS / 0.497 ms CPU. Measurements compare upstream `4224687e5` with this cloud fix applied, before the clean rebase onto current main `8da9c8c4c`. Final formatting, Clippy, library tests and cloud parity were rerun after rebasing. These are individual six-second samples, with simulation/background activity not frozen; small differences are noise. ### Validation - All 3,190 existing cloud-render parity cases match the pinned 26.3 client (face selection/traversal coverage, not full framebuffer parity). - All eight cloud tests pass, including 100 successive cache hits while sub-cell movement/time/color change, plus cell, vertical-region, mode, distance and drift invalidation. - Before rebasing, client/control binary tests passed: 47 and 15 respectively (one client test ignored). - Live smoke checks covered Fast/Fancy, Off/on, distances 32/64/128, stationary rendering, rotation, cell crossings, vertical movement and resource reload without GPU validation errors. The contributor manually tested the optimized build and confirmed it works well. - Full client library tests after rebasing: **732 passed, 5 failed, 5 ignored**. The failing modules are unchanged: crash-stack path formatting; resource-cache output recovery (Windows Access Denied); session-lock exclusivity; and two server-properties tests (CRLF/LF expectations). They were not changed as part of this performance fix. No separate baseline runtime run was used to establish their prior status. - Extended visual/animation coverage, custom resource packs, other dimensions/world transitions and other GPUs remain unverified. No intended visual change. ## Vanilla reference Inspected the checksum-pinned Minecraft Java Edition 26.3 implementation locally using Horizon's research workflow, including `tools/rea_vanilla.py`'s `CloudRenderer.prepare` render-preparation overload, and the local bytecode/decompiled reference: - `net.minecraft.client.renderer.CloudRenderer.prepare` (texture and per-frame overloads), `apply`, `buildMesh`, `tryBuildCell`, `buildFlatCell`, `buildExtrudedCell`, `markForRebuild`, `render`, `endFrame`, `close`. - `LevelRenderer.prepareTranslucents`, `invalidateCompiledGeometry`, `endFrame`, `close`. - Harness: `tools/test_cloud_render_parity.py`. Also consulted [mcsrc.dev](https://mcsrc.dev/) and [Sodium's 26.3 CloudRendererMixin](https://github.com/CaffeineMC/sodium/blob/d553ceeea0f33a59aff9258711ae044fdee5e489/common/src/main/java/net/caffeinemc/mods/sodium/mixin/features/render/world/clouds/CloudRendererMixin.java). Sodium optimizes compact face encoding while relying on vanilla's mesh reuse; that encoding rewrite was unnecessary here. Its different interior-neighbor rule was not adopted. No third-party implementation code was copied. --- <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:30 +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#2599
No description provided.