[PR #5779] [MERGED] Renderer: finish and submit frames on a submit thread (+32% FPS in CPU-bound views) #6491

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

📋 Pull Request Information

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

Base: main ← Head: perf/encoder-finish


📝 Commits (4)

  • c961481 Renderer: finish and submit frames on a submit thread; the hand in the world pass
  • 70acb20 Merge main into #5779
  • fea41f8 Submit thread: on by default on Linux only, where it was measured faster
  • 5e97453 Merge main into #5779

📊 Changes

6 files changed (+418 additions, -28 deletions)

View changed files

📝 crates/horizon-client-render/src/gfx.rs (+142 -15)
📝 crates/horizon-client-render/src/gfx/cull.rs (+15 -13)
📝 crates/horizon-client-render/src/gfx/native_render.rs (+13 -0)
➕ crates/horizon-client-render/src/gfx/submit.rs (+228 -0)
📝 crates/horizon-client-render/src/terrain.wgsl (+5 -0)
📝 crates/horizon-client/src/game/mods.rs (+15 -0)

📄 Description

🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally.

Closes #5777.

At uncapped frame rates the window's thread spent ~85 µs a frame in wgpu's CommandEncoder::finish (wgpu-core validates, tracks and encodes the whole frame there; recording the passes takes only ~10 µs) and ~25 µs in Queue::submit.

What changes

  • Submit thread (gfx/submit.rs): Renderer::queue is now a submit::Queue that derefs to wgpu::Queue. draw_frame hands the frame's encoder (and surface texture) to a "Render submit" thread, which finishes, submits and presents it while the main thread builds the next frame. Every use of the queue waits for that frame first, so writes, copies and other submissions keep the order they had on one thread, without touching the ~70 call sites. The surface is reconfigured, released or recreated only after the wait.
    • These frames stay in place: screenshot readbacks, frames with error scopes (they're per thread), VSync (Fifo, which needs pre_present_notify), a reconfigure, the first frame (startup log), and HDR's first-present marker.
    • Culling's readback map_async runs on the submit thread right after the submission, as it did before. GPU timers and the offscreen in-flight limit are taken in at the start of the next frame (land_frame), and also in wait_in_flight for split screen.
    • HORIZON_SUBMIT_THREAD=0 turns it off.
  • Hand in the world pass: when nothing runs between the world pass and the hand (no scaled world, HDR, shader-pack hand, or native mod built in that could draw in native_world_drawn), the hand draws at the end of the world pass after a full-screen depth reset to the far plane. That saves one render pass, ~10 µs of wgpu encoding a frame. Pixel-identical in screenshots.

Benchmark

RTX 4060, Linux/Vulkan, RD 12, fixed views of seed world, bench 8 s, medians over repeats. base is origin/main (c51dcda01).

Offscreen, 4 repeats:

view base FPS this PR FPS base CPU/frame this PR CPU/frame GPU/frame
village (CPU-bound) 2229 2941 (+32%) 435 µs 328 µs ~290–310 µs
mountain (GPU-bound) 2364 2269 352 µs* 429 µs* ~380–430 µs

Windowed (Immediate), 2 repeats:

view base FPS this PR FPS
village 2135 2645 (+24%)
mountain 2150 2223

*Mountain is GPU-bound, and its GPU time is bimodal from run to run (~380 or ~430 µs). The same binary with the thread off and on gave 2199/2200/2487/2221 vs 2435/2248/2230/2477 FPS, so its difference is that, not the thread. Its CPU figure includes the wait for the GPU.

Where the remaining ~330 µs CPU frame goes (village): ~110 µs building the Frame in the game, ~47 µs section visibility, ~60 µs draw lists, ~10 µs pass recording. For 5000+ FPS those are next, and the GPU (~0.3 ms here) caps this view at ~3300 FPS anyway.

Tried and not done: render bundles (the passes' recording is ~10 µs, and the finish they'd shorten is now off the main thread), and folding the screen-effects pass into the HUD's first pass (only frames with overlays, a few µs).

Tests

submit::tests::writes_after_a_frame_on_the_thread_land_after_it: a frame on the thread copies a buffer, then the main thread writes that buffer; the copy must hold the old data. It fails with the wait removed from Deref.

Seen while benchmarking, also on main: windowed screenshots sometimes show clouds as long spiky triangles (not caused by this PR, both builds show it intermittently).

pr_ready

pr_ready (tools/pr_ready.py --quick on archlinux, against origin/main at c51dcda01, 6 min 9 s)

Check Result
Scope ⚠️ counted untracked local worktrees; the diff is 6 files, +407 −28
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 511 passed (27 s)
rustfmt ✅ (7 s)
clippy ✅ (55 s)
tests: horizon-client, horizon-client-render ✅ 2466 passed (4 min 35 s)
doc tests ✅ 0 passed (2 s)
Parity ➖ 365 affected, to run in CI (--quick)

🤖 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/5779 **Author:** [@rdbtCVS](https://github.com/rdbtCVS) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `perf/encoder-finish` --- ### 📝 Commits (4) - [`c961481`](https://github.com/horizon-rust/horizon/commit/c9614815f406c447cceb181367901414d1d525e6) Renderer: finish and submit frames on a submit thread; the hand in the world pass - [`70acb20`](https://github.com/horizon-rust/horizon/commit/70acb2002521ecd672dd7b6760df7d54d62ffa2b) Merge main into #5779 - [`fea41f8`](https://github.com/horizon-rust/horizon/commit/fea41f8676a97e1f26a5febaa47b2e3839f2ba68) Submit thread: on by default on Linux only, where it was measured faster - [`5e97453`](https://github.com/horizon-rust/horizon/commit/5e9745363f5ad5304870ce8bdfb8dcb6b8400be4) Merge main into #5779 ### 📊 Changes **6 files changed** (+418 additions, -28 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/gfx.rs` (+142 -15) 📝 `crates/horizon-client-render/src/gfx/cull.rs` (+15 -13) 📝 `crates/horizon-client-render/src/gfx/native_render.rs` (+13 -0) ➕ `crates/horizon-client-render/src/gfx/submit.rs` (+228 -0) 📝 `crates/horizon-client-render/src/terrain.wgsl` (+5 -0) 📝 `crates/horizon-client/src/game/mods.rs` (+15 -0) </details> ### 📄 Description > 🤖 Opened by rdbtCVS's AI agent (Claude Code, Claude Opus 5.5), not by rdbtCVS personally. Closes #5777. At uncapped frame rates the window's thread spent ~85 µs a frame in wgpu's `CommandEncoder::finish` (wgpu-core validates, tracks and encodes the whole frame there; recording the passes takes only ~10 µs) and ~25 µs in `Queue::submit`. ## What changes - **Submit thread** (`gfx/submit.rs`): `Renderer::queue` is now a `submit::Queue` that derefs to `wgpu::Queue`. `draw_frame` hands the frame's encoder (and surface texture) to a "Render submit" thread, which finishes, submits and presents it while the main thread builds the next frame. **Every use of the queue waits for that frame first**, so writes, copies and other submissions keep the order they had on one thread, without touching the ~70 call sites. The surface is reconfigured, released or recreated only after the wait. - These frames stay in place: screenshot readbacks, frames with error scopes (they're per thread), VSync (Fifo, which needs `pre_present_notify`), a reconfigure, the first frame (startup log), and HDR's first-present marker. - Culling's readback `map_async` runs on the submit thread right after the submission, as it did before. GPU timers and the offscreen in-flight limit are taken in at the start of the next frame (`land_frame`), and also in `wait_in_flight` for split screen. - `HORIZON_SUBMIT_THREAD=0` turns it off. - **Hand in the world pass**: when nothing runs between the world pass and the hand (no scaled world, HDR, shader-pack hand, or native mod built in that could draw in `native_world_drawn`), the hand draws at the end of the world pass after a full-screen depth reset to the far plane. That saves one render pass, ~10 µs of wgpu encoding a frame. Pixel-identical in screenshots. ## Benchmark RTX 4060, Linux/Vulkan, RD 12, fixed views of seed world, `bench 8` s, medians over repeats. `base` is origin/main (c51dcda01). Offscreen, 4 repeats: | view | base FPS | this PR FPS | base CPU/frame | this PR CPU/frame | GPU/frame | |---|---|---|---|---|---| | village (CPU-bound) | 2229 | **2941 (+32%)** | 435 µs | 328 µs | ~290–310 µs | | mountain (GPU-bound) | 2364 | 2269 | 352 µs* | 429 µs* | ~380–430 µs | Windowed (Immediate), 2 repeats: | view | base FPS | this PR FPS | |---|---|---| | village | 2135 | **2645 (+24%)** | | mountain | 2150 | 2223 | \*Mountain is GPU-bound, and its GPU time is bimodal from run to run (~380 or ~430 µs). The same binary with the thread off and on gave 2199/2200/2487/2221 vs 2435/2248/2230/2477 FPS, so its difference is that, not the thread. Its CPU figure includes the wait for the GPU. Where the remaining ~330 µs CPU frame goes (village): ~110 µs building the `Frame` in the game, ~47 µs section visibility, ~60 µs draw lists, ~10 µs pass recording. For 5000+ FPS those are next, and the GPU (~0.3 ms here) caps this view at ~3300 FPS anyway. Tried and not done: render bundles (the passes' recording is ~10 µs, and the finish they'd shorten is now off the main thread), and folding the screen-effects pass into the HUD's first pass (only frames with overlays, a few µs). ## Tests `submit::tests::writes_after_a_frame_on_the_thread_land_after_it`: a frame on the thread copies a buffer, then the main thread writes that buffer; the copy must hold the old data. It fails with the wait removed from `Deref`. Seen while benchmarking, also on main: windowed screenshots sometimes show clouds as long spiky triangles (not caused by this PR, both builds show it intermittently). <details><summary>pr_ready</summary> **pr_ready** (`tools/pr_ready.py --quick` on archlinux, against origin/main at c51dcda01, 6 min 9 s) | Check | Result | | --- | --- | | Scope | ⚠️ counted untracked local worktrees; the diff is 6 files, +407 −28 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 511 passed (27 s) | | rustfmt | ✅ (7 s) | | clippy | ✅ (55 s) | | tests: horizon-client, horizon-client-render | ✅ 2466 passed (4 min 35 s) | | doc tests | ✅ 0 passed (2 s) | | Parity | ➖ 365 affected, to run in CI (--quick) | </details> 🤖 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:21:25 +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#6491
No description provided.