[PR #128] [MERGED] Terrain gets its own 28-byte vertex without a normal (was 36) #2342

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

📋 Pull Request Information

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

Base: main ← Head: perf/terrain-vertex-32


📝 Commits (2)

  • ea93297 Report the section arena and device memory in the control status
  • 840e8ad Give terrain its own 28-byte vertex without a normal

📊 Changes

7 files changed (+111 additions, -38 deletions)

View changed files

📝 crates/horizon-client/examples/section_mesh_fixture.rs (+8 -4)
📝 crates/horizon-client/src/game/control.rs (+7 -0)
📝 crates/horizon-client/src/gfx.rs (+40 -7)
📝 crates/horizon-client/src/gfx/arena.rs (+4 -0)
📝 crates/horizon-client/src/mesher.rs (+42 -18)
📝 crates/horizon-client/src/mesher/fluid.rs (+5 -4)
📝 crates/horizon-client/src/terrain.wgsl (+5 -5)

📄 Description

What was wrong

#52 added an RGBA8_SNORM normal to the vertex struct that terrain and entities share, for entity.wgsl's directional entity light. Every section vertex grew from 32 to 36 bytes although vs_terrain never reads the normal: #52 only uses it for mobs, players, items in hand, block entities and other entity-pipeline geometry.

What vanilla does

Terrain uses DefaultVertexFormat.BLOCK: position, colour, UV0, UV2 (lightmap), 28 bytes, no normal used for lighting. The face shade (BlockAndTintGetter.getShade per direction) and ambient occlusion are baked into the vertex colour by ModelBlockRenderer; the terrain shaders only multiply that colour by the lightmap. Entity lighting (light.glsl minecraft_mix_light) needs Normal, so NEW_ENTITY keeps it.

The change

  • Sections mesh into a new TerrainVertex: position (3 × f32), UV (2 × f32), the sprite layer as u16 (bit 15 marks opaque leaves, forceOpaque, was bit 31), the two light bytes as u16, RGBA8 colour: 28 bytes. Every value vs_terrain / fs_solid read is unchanged; the vertex buffer layout and terrain.wgsl follow. A test checks the attribute offsets against the struct and its size.
  • Entity vertices keep Vertex with its normal.
  • The control socket's status reports the section arena's bytes, the bytes resident sections use in it, and the backend allocator's allocated/reserved device memory (Vulkan), to measure this (separate commit).

How tested

Fixed view over seed 1234's village (graphics_bench's), render distance 16, ticks frozen, measured once every chunk is meshed, offscreen on the RTX 4080; two interleaved runs per build (measure.py in ~/code/horizon-parity/screens/terrain-vertex/). Same 5472 resident sections:

before (36 B) after (28 B) change
terrain vertex bytes 373.97 / 373.94 MB 290.72 / 290.80 MB −22.2 % (28/36)
section vertex arena 419.4 MB 327.2 MB −92.3 MB
GPU memory allocated (Vulkan allocator) 550.6 MB 458.3 MB −92.3 MB
uploaded during a 12 s flight 254.1 / 252.6 MB 197.8 / 196.3 MB −22 %
process RSS 1.90 / 1.93 GB 1.90 / 1.91 GB unchanged (meshes are not kept on the CPU)

Frame rates (static 249–346 vs 301–347 fps, flight 141–177 vs 173–188 fps) varied more between runs than between builds (other sessions shared the CPU), so no speed claim. graphics_bench.py --offscreen (rd 8, 16, 32, four flights) gave the same per-section ratio: 79.1 KB → 61.8 KB per resident section at rd 8 (0.781).

Equivalence: tools/test_section_mesh_parity.py (Mac mini): 112 scenes, 1 008 927 / 1 008 927 quads identical to the vanilla client. A pixel diff of the fixed-view screenshots does not settle it on its own: two runs of the same build already differ by up to 46–51 levels (animated textures, sky), as much as before vs after (43); the frames are in ~/code/horizon-parity/screens/terrain-vertex/ on ludodesktop.

cargo fmt --check, cargo clippy --workspace --all-targets -D warnings clean; cargo test -p horizon-client --lib 413 passed (Mac mini); tools/check_public_tree.py passed.

🤖 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/128 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/14/2026 **Status:** ✅ Merged **Merged:** 10/14/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/terrain-vertex-32` --- ### 📝 Commits (2) - [`ea93297`](https://github.com/horizon-rust/horizon/commit/ea9329757917927656b1b51a5666828ccc1982a6) Report the section arena and device memory in the control status - [`840e8ad`](https://github.com/horizon-rust/horizon/commit/840e8ad4a865fd30f87e6a6e643a036327865ff3) Give terrain its own 28-byte vertex without a normal ### 📊 Changes **7 files changed** (+111 additions, -38 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/examples/section_mesh_fixture.rs` (+8 -4) 📝 `crates/horizon-client/src/game/control.rs` (+7 -0) 📝 `crates/horizon-client/src/gfx.rs` (+40 -7) 📝 `crates/horizon-client/src/gfx/arena.rs` (+4 -0) 📝 `crates/horizon-client/src/mesher.rs` (+42 -18) 📝 `crates/horizon-client/src/mesher/fluid.rs` (+5 -4) 📝 `crates/horizon-client/src/terrain.wgsl` (+5 -5) </details> ### 📄 Description ## What was wrong #52 added an RGBA8_SNORM normal to the vertex struct that terrain and entities share, for `entity.wgsl`'s directional entity light. Every section vertex grew from 32 to **36 bytes** although `vs_terrain` never reads the normal: #52 only uses it for mobs, players, items in hand, block entities and other entity-pipeline geometry. ## What vanilla does Terrain uses `DefaultVertexFormat.BLOCK`: position, colour, UV0, UV2 (lightmap), **28 bytes**, no normal used for lighting. The face shade (`BlockAndTintGetter.getShade` per direction) and ambient occlusion are baked into the vertex colour by `ModelBlockRenderer`; the terrain shaders only multiply that colour by the lightmap. Entity lighting (`light.glsl` `minecraft_mix_light`) needs `Normal`, so `NEW_ENTITY` keeps it. ## The change - Sections mesh into a new `TerrainVertex`: position (3 × f32), UV (2 × f32), the sprite layer as u16 (bit 15 marks opaque leaves, `forceOpaque`, was bit 31), the two light bytes as u16, RGBA8 colour: **28 bytes**. Every value `vs_terrain` / `fs_solid` read is unchanged; the vertex buffer layout and `terrain.wgsl` follow. A test checks the attribute offsets against the struct and its size. - Entity vertices keep `Vertex` with its normal. - The control socket's `status` reports the section arena's bytes, the bytes resident sections use in it, and the backend allocator's allocated/reserved device memory (Vulkan), to measure this (separate commit). ## How tested Fixed view over seed 1234's village (graphics_bench's), render distance 16, ticks frozen, measured once every chunk is meshed, offscreen on the RTX 4080; two interleaved runs per build (`measure.py` in `~/code/horizon-parity/screens/terrain-vertex/`). Same 5472 resident sections: | | before (36 B) | after (28 B) | change | |---|---|---|---| | terrain vertex bytes | 373.97 / 373.94 MB | 290.72 / 290.80 MB | **−22.2 %** (28/36) | | section vertex arena | 419.4 MB | 327.2 MB | −92.3 MB | | GPU memory allocated (Vulkan allocator) | 550.6 MB | 458.3 MB | −92.3 MB | | uploaded during a 12 s flight | 254.1 / 252.6 MB | 197.8 / 196.3 MB | −22 % | | process RSS | 1.90 / 1.93 GB | 1.90 / 1.91 GB | unchanged (meshes are not kept on the CPU) | Frame rates (static 249–346 vs 301–347 fps, flight 141–177 vs 173–188 fps) varied more between runs than between builds (other sessions shared the CPU), so no speed claim. `graphics_bench.py --offscreen` (rd 8, 16, 32, four flights) gave the same per-section ratio: 79.1 KB → 61.8 KB per resident section at rd 8 (0.781). Equivalence: `tools/test_section_mesh_parity.py` (Mac mini): 112 scenes, **1 008 927 / 1 008 927 quads identical** to the vanilla client. A pixel diff of the fixed-view screenshots does not settle it on its own: two runs of the *same* build already differ by up to 46–51 levels (animated textures, sky), as much as before vs after (43); the frames are in `~/code/horizon-parity/screens/terrain-vertex/` on ludodesktop. `cargo fmt --check`, `cargo clippy --workspace --all-targets -D warnings` clean; `cargo test -p horizon-client --lib` 413 passed (Mac mini); `tools/check_public_tree.py` passed. 🤖 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:55:08 +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#2342
No description provided.