[PR #7089] [MERGED] Keep posed entity vertices bit-exact on Metal #7327

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

📋 Pull Request Information

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

Base: main ← Head: perf/skin-exact-metal


📝 Commits (1)

  • 9f01e2b Keep posed entity vertices bit-exact on Metal

📊 Changes

2 files changed (+27 additions, -10 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx/entity_skin.rs (+1 -0)
📝 crates/horizon-client-render/src/gfx/entity_skin.wgsl (+26 -10)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

The GPU posing pass (entity_skin.wgsl, #6756) is meant to write exactly the CPU path's vertices. On the Mac mini it didn't: the_shader_writes_what_the_cpu_reference_computes failed by 1 ulp on positions (1.6704975 vs 1.6704974). It passes on lavapipe, which is why CI (Linux) never saw it.

Cause. wgpu builds Metal libraries with MTLCompileOptions::new(), which leaves fast math on. Metal then fuses col * p.x + pos into one fused multiply-add, and may reorder sums. glam's transform_point3 on the CPU rounds each multiply and add separately.

Fix. Each product and partial sum (positions, the UV lerp, scroll_u) goes through r()/r3(): an xor of the bits with keep, a zero the shader reads from the job's last spare word. The compiler can't prove it's zero, so it can neither fuse nor reassociate, and every operation rounds on its own in glam's order. The cost is a few integer ops per vertex.

The difference was invisible (1 ulp on a position), hence skip-release. Bit-exactness is still what lets the GPU path be compared byte for byte with the CPU path; the items-on-GPU work (#7056) relies on it.

Checks

Mac mini (Metal), head 9f01e2bc4:
cargo test --profile fast -p horizon-client-render --lib entity_skin   main: FAILED (vertex 0, 1 ulp) → this PR: 1 passed
playhorizon (lavapipe), head 9f01e2bc4:
cargo fmt --all -- --check                                   ok
cargo clippy --profile fast -p horizon-client -p horizon-client-lib -p horizon-client-render --lib --bins --tests -- -D warnings   ok, 0 diagnostics
cargo test -p horizon-client-render --lib entity_skin        1 passed
cargo test -p horizon-client-lib --lib mobs::skin            2 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/7089 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/skin-exact-metal` --- ### 📝 Commits (1) - [`9f01e2b`](https://github.com/horizon-rust/horizon/commit/9f01e2bc41d852cc1096694aa832aa83a4623033) Keep posed entity vertices bit-exact on Metal ### 📊 Changes **2 files changed** (+27 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx/entity_skin.rs` (+1 -0) 📝 `crates/horizon-client-render/src/gfx/entity_skin.wgsl` (+26 -10) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. The GPU posing pass (`entity_skin.wgsl`, #6756) is meant to write exactly the CPU path's vertices. On the Mac mini it didn't: `the_shader_writes_what_the_cpu_reference_computes` failed by 1 ulp on positions (`1.6704975` vs `1.6704974`). It passes on lavapipe, which is why CI (Linux) never saw it. **Cause.** wgpu builds Metal libraries with `MTLCompileOptions::new()`, which leaves **fast math on**. Metal then fuses `col * p.x + pos` into one fused multiply-add, and may reorder sums. glam's `transform_point3` on the CPU rounds each multiply and add separately. **Fix.** Each product and partial sum (positions, the UV lerp, `scroll_u`) goes through `r()`/`r3()`: an `xor` of the bits with `keep`, a zero the shader reads from the job's last spare word. The compiler can't prove it's zero, so it can neither fuse nor reassociate, and every operation rounds on its own in glam's order. The cost is a few integer ops per vertex. The difference was invisible (1 ulp on a position), hence `skip-release`. Bit-exactness is still what lets the GPU path be compared byte for byte with the CPU path; the items-on-GPU work (#7056) relies on it. ### Checks ``` Mac mini (Metal), head 9f01e2bc4: cargo test --profile fast -p horizon-client-render --lib entity_skin main: FAILED (vertex 0, 1 ulp) → this PR: 1 passed playhorizon (lavapipe), head 9f01e2bc4: cargo fmt --all -- --check ok cargo clippy --profile fast -p horizon-client -p horizon-client-lib -p horizon-client-render --lib --bins --tests -- -D warnings ok, 0 diagnostics cargo test -p horizon-client-render --lib entity_skin 1 passed cargo test -p horizon-client-lib --lib mobs::skin 2 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-03 06:37:46 +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#7327
No description provided.