[PR #560] [MERGED] Renderer: skip wgpu's indirect-draw validation in release builds (−0.05..0.11 ms/frame of render thread at RD 32) #2642

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

📋 Pull Request Information

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

Base: main ← Head: perf/skip-indirect-validation


📝 Commits (1)

  • 05d1b92 Renderer: skip wgpu's indirect-draw validation in release builds

📊 Changes

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

View changed files

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

📄 Description

What

Release builds now create the wgpu instance without InstanceFlags::VALIDATION_INDIRECT_CALL. Debug builds (tests, harness probes in dev) keep it, and WGPU_VALIDATION_INDIRECT_CALL=1 turns it back on in any build.

Why

Since wgpu 25, release builds validate every indirect draw by default. Every frame, wgpu-core records metadata for each indirect draw (DrawBatcher::add, one hash-map entry per draw) and uploads it. It then runs a compute pass (Draw::inject_validation_pass) that copies the clamped arguments into its own buffer before the render pass, and the draws read that copy. The point is to stop untrusted WebGPU content from reading out of bounds.

Horizon's only indirect draws are the section draws that Renderer::render writes from resident sections, and they are in bounds by construction:

  • each index count is a quad range of one section, at most index_quads, which upload grows to cover every section;
  • base vertex plus vertex count stays inside the section's own arena allocation in the bound page;
  • first_instance is the section's index in this frame's visible list, below the origins written to instances that frame (its capacity grows first).

At render distance 32 that is about 8,000 draws per frame validated for nothing. They cost CPU time on the render thread, plus a compute dispatch and a copy of all the arguments on the GPU.

Measurements

Mac mini M4 Pro (Metal), 1280x720 offscreen, seed 1234 creative world, at -960 125 272, yaw 0, pitch 35, noon, render distance 32 (2,681 sections drawn, about 8,000 draws), VSync off, unlimited FPS. Each run: horizon-ctl bench 15 once the world is ready, then an 8 s Time Profiler capture. "Profiled ms/frame" is main-thread samples (1 ms each, running only) in that function divided by the frames rendered during the capture. Base and new binaries were built from the same commit, with and without this change.

The machine was shared with other agents' CI (load average 45–75 on 14 threads). Under that load the main thread spends most of each frame preempted or on efficiency cores, so wall-clock FPS swings 2–15x between identical binaries. The rows to read are the profiled ones.

main this PR main this PR
Average FPS 23 ¹ 406 371 386
1% low FPS 2 ¹ 66 57 47
CPU ms/frame, median 6.94 ¹ 1.74 1.82 1.79
GPU ms/frame n/a ² n/a n/a n/a
Profiled: indirect validation (inject_validation_pass + DrawContext::add) 0.104 0.000 0.106 0.000
Profiled: Metal draws (draw_indexed_indirect) 0.242 0.293 0.239 0.282
Profiled: Renderer::render total 0.850 0.935 0.932 0.843

Three more pairs under heavier load (load average 70) show the same validation rows: 0.109 / 0.081 / 0.047 ms per frame on main, 0.000 with this PR.

¹ This main run caught the integrated server ticking 22 ms per frame (the world was still settling after launch), so its FPS isn't comparable.
² Metal on Apple Silicon has no timestamp queries inside encoders, so the game can't time the GPU. On Vulkan the removed compute pass is GPU time saved as well. Not measured here: the ThinkPad runs go through perf-cores-1.

The Renderer::render totals move with the contention noise, by more than the 0.05–0.11 ms removed. That removed work is 6–12% of Renderer::render.

Correctness

  • Screenshots against origin/main at two views (village street from above, pitch 35, and a hillside at eye level, pitch 3), RD 32, ticks frozen, mobs removed, clouds and animated textures off so a run can repeat. The hillside is pixel-identical. The village view differs in 15 pixels, a ±1 band at the top edge and a few isolated pixels; two runs of main itself differ in 97 pixels at the same places.
  • New test indirect_draws_are_validated_only_in_debug_builds.
cargo fmt --all --check                                   ok
cargo clippy --workspace --all-targets -- -D warnings      ok
cargo test -p horizon-client --lib                        756 passed, 5 ignored
tools/parity.py --changed origin/main (84 harnesses)       84 passed, 0 failed (one run on this + #561 merged together)

Needs from Ludovic: nothing.

🤖 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/560 **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:** `perf/skip-indirect-validation` --- ### 📝 Commits (1) - [`05d1b92`](https://github.com/horizon-rust/horizon/commit/05d1b92d56f6bf357fde51f2c9934d7239fd6c4f) Renderer: skip wgpu's indirect-draw validation in release builds ### 📊 Changes **1 file changed** (+29 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/gfx.rs` (+29 -2) </details> ### 📄 Description ## What Release builds now create the wgpu instance without `InstanceFlags::VALIDATION_INDIRECT_CALL`. Debug builds (tests, harness probes in dev) keep it, and `WGPU_VALIDATION_INDIRECT_CALL=1` turns it back on in any build. ## Why Since wgpu 25, release builds validate every indirect draw by default. Every frame, wgpu-core records metadata for each indirect draw (`DrawBatcher::add`, one hash-map entry per draw) and uploads it. It then runs a compute pass (`Draw::inject_validation_pass`) that copies the clamped arguments into its own buffer before the render pass, and the draws read that copy. The point is to stop untrusted WebGPU content from reading out of bounds. Horizon's only indirect draws are the section draws that `Renderer::render` writes from resident sections, and they are in bounds by construction: - each index count is a quad range of one section, at most `index_quads`, which `upload` grows to cover every section; - base vertex plus vertex count stays inside the section's own arena allocation in the bound page; - `first_instance` is the section's index in this frame's visible list, below the origins written to `instances` that frame (its capacity grows first). At render distance 32 that is about 8,000 draws per frame validated for nothing. They cost CPU time on the render thread, plus a compute dispatch and a copy of all the arguments on the GPU. ## Measurements Mac mini M4 Pro (Metal), 1280x720 offscreen, seed 1234 creative world, at -960 125 272, yaw 0, pitch 35, noon, render distance 32 (2,681 sections drawn, about 8,000 draws), VSync off, unlimited FPS. Each run: `horizon-ctl bench 15` once the world is ready, then an 8 s Time Profiler capture. "Profiled ms/frame" is main-thread samples (1 ms each, running only) in that function divided by the frames rendered during the capture. Base and new binaries were built from the same commit, with and without this change. The machine was shared with other agents' CI (load average 45–75 on 14 threads). Under that load the main thread spends most of each frame preempted or on efficiency cores, so wall-clock FPS swings 2–15x between identical binaries. The rows to read are the profiled ones. | | main | this PR | main | this PR | |---|---|---|---|---| | Average FPS | 23 ¹ | 406 | 371 | 386 | | 1% low FPS | 2 ¹ | 66 | 57 | 47 | | CPU ms/frame, median | 6.94 ¹ | 1.74 | 1.82 | 1.79 | | GPU ms/frame | n/a ² | n/a | n/a | n/a | | Profiled: indirect validation (`inject_validation_pass` + `DrawContext::add`) | 0.104 | 0.000 | 0.106 | 0.000 | | Profiled: Metal draws (`draw_indexed_indirect`) | 0.242 | 0.293 | 0.239 | 0.282 | | Profiled: `Renderer::render` total | 0.850 | 0.935 | 0.932 | 0.843 | Three more pairs under heavier load (load average 70) show the same validation rows: 0.109 / 0.081 / 0.047 ms per frame on main, 0.000 with this PR. ¹ This main run caught the integrated server ticking 22 ms per frame (the world was still settling after launch), so its FPS isn't comparable. ² Metal on Apple Silicon has no timestamp queries inside encoders, so the game can't time the GPU. On Vulkan the removed compute pass is GPU time saved as well. Not measured here: the ThinkPad runs go through perf-cores-1. The `Renderer::render` totals move with the contention noise, by more than the 0.05–0.11 ms removed. That removed work is 6–12% of `Renderer::render`. ## Correctness - Screenshots against origin/main at two views (village street from above, pitch 35, and a hillside at eye level, pitch 3), RD 32, ticks frozen, mobs removed, clouds and animated textures off so a run can repeat. The hillside is pixel-identical. The village view differs in 15 pixels, a ±1 band at the top edge and a few isolated pixels; two runs of main itself differ in 97 pixels at the same places. - New test `indirect_draws_are_validated_only_in_debug_builds`. ``` cargo fmt --all --check ok cargo clippy --workspace --all-targets -- -D warnings ok cargo test -p horizon-client --lib 756 passed, 5 ignored tools/parity.py --changed origin/main (84 harnesses) 84 passed, 0 failed (one run on this + #561 merged together) ``` Needs from Ludovic: nothing. 🤖 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:53 +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#2642
No description provided.