[GH-ISSUE #997] [performance] Persistent GPU-side table of resident section meshes instead of rebuilding the indirect draw list each frame #274

Closed
opened 2026-11-02 15:37:50 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @ludovic111 on GitHub (Oct 19, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/997

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

Suggested on Discord by constantine9012 in #general (2026-10-19).

Today the renderer clears and refills draws (DrawIndexedIndirectArgs) on the CPU every frame from the visible sections (gfx.rs, around the self.draws.clear() / push loop), uploads it, and draws with one indirect multi-draw per pass; occlusion culling (#939, Vulkan) splits it into two phases.

Idea: keep a persistent GPU table with one entry per resident section mesh (arena offsets, counts, bounds), updated only when meshes load, change or unload; each frame a compute pass culls the table (frustum, occlusion) and writes the compacted indirect arguments (and a count for multi_draw_indexed_indirect_count where supported), so the CPU no longer walks every visible section.

First measure: the CPU time of building and uploading the draw list at render distance 16/32 (and with #771's LOD on), against the frame budget on the HD 620 and the Mac. Metal's per-draw replay (wgpu-hal issues one draw per multi-draw entry, and gfx/flat.rs batching takes over from 4,096 draws) limits what this gains there. Parity: identical visible sets and screenshots.

Originally created by @ludovic111 on GitHub (Oct 19, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/997 > 🤖 Filed by Ludovic's AI agent (Claude), not by Ludovic himself. Suggested on Discord by **constantine9012** in #general (2026-10-19). Today the renderer clears and refills `draws` (`DrawIndexedIndirectArgs`) on the CPU every frame from the visible sections (`gfx.rs`, around the `self.draws.clear()` / `push` loop), uploads it, and draws with one indirect multi-draw per pass; occlusion culling (#939, Vulkan) splits it into two phases. Idea: keep a persistent GPU table with one entry per resident section mesh (arena offsets, counts, bounds), updated only when meshes load, change or unload; each frame a compute pass culls the table (frustum, occlusion) and writes the compacted indirect arguments (and a count for `multi_draw_indexed_indirect_count` where supported), so the CPU no longer walks every visible section. First measure: the CPU time of building and uploading the draw list at render distance 16/32 (and with #771's LOD on), against the frame budget on the HD 620 and the Mac. Metal's per-draw replay (wgpu-hal issues one draw per multi-draw entry, and `gfx/flat.rs` batching takes over from 4,096 draws) limits what this gains there. Parity: identical visible sets and screenshots.
bsakaguchi 2026-11-02 15:37:50 +07:00
Author
Owner

@ludovic111 commented on GitHub (Oct 19, 2026):

🤖 Agent: measurement for this issue (perf-frame-10), before building anything.

A temporary span draw_list around the CPU side this issue would replace: the instance-origin list, the per-section facing ranges, and the indirect-draw list from self.origins.clear() to phase1_draws. LODs off, seed 1234, 8 s benches:

machine RD view draw_list ms/frame visibility encode CPU ms GPU ms
Mac mini M4 Pro 16 overview / meadow / peak 0.003 / 0.001 / 0.001 ≤ 0.002 0.27–0.35 0.97–1.08 0.14–0.23
Mac mini M4 Pro 32 overview / meadow / peak 0.46 / 0.12 / 0.27 0.05–0.20 0.34–1.54 1.94–3.47 0.33–0.85
ThinkPad Kaby Lake-U, HD 620 16 overview / meadow 0.014 / 0.003 ≤ 0.008 1.11–1.78 2.31–3.42 3.89–5.87
ThinkPad Kaby Lake-U, HD 620 32 overview / meadow 1.06 / 0.64 1.00–1.42 2.70–5.11 6.37–10.59 6.30–16.91
  • At RD 16 the rebuild costs nothing measurable. At RD 32 it is 0.1–0.5 ms on the M4 Pro and 0.6–1.1 ms on the 4-thread laptop, about 10% of its CPU frame.
  • With LODs on (#771, LOD 64, RD 12, HD 620), far tiles add 3.8 M quads, and the HD 620's GPU time follows the quad count (5 ms for far terrain: card#23 / perf-frame-10). A GPU-side table would not change that.
  • encode is the bigger CPU item on both machines (2.7–5.1 ms on the laptop at RD 32).

So a GPU table saves at most the draw_list share, about 1 ms, only at RD 32 on weak CPUs, and only where the frame is CPU-bound. Data: ~/code/horizon-parity/shots/perf-frame-10/. Nothing implemented.

<!-- gh-comment-id:6268076221 --> @ludovic111 commented on GitHub (Oct 19, 2026): 🤖 Agent: measurement for this issue (perf-frame-10), before building anything. A temporary span `draw_list` around the CPU side this issue would replace: the instance-origin list, the per-section facing ranges, and the indirect-draw list from `self.origins.clear()` to `phase1_draws`. LODs off, seed 1234, 8 s benches: | machine | RD | view | `draw_list` ms/frame | `visibility` | `encode` | CPU ms | GPU ms | | --- | --- | --- | --- | --- | --- | --- | --- | | Mac mini M4 Pro | 16 | overview / meadow / peak | 0.003 / 0.001 / 0.001 | ≤ 0.002 | 0.27–0.35 | 0.97–1.08 | 0.14–0.23 | | Mac mini M4 Pro | 32 | overview / meadow / peak | 0.46 / 0.12 / 0.27 | 0.05–0.20 | 0.34–1.54 | 1.94–3.47 | 0.33–0.85 | | ThinkPad Kaby Lake-U, HD 620 | 16 | overview / meadow | 0.014 / 0.003 | ≤ 0.008 | 1.11–1.78 | 2.31–3.42 | 3.89–5.87 | | ThinkPad Kaby Lake-U, HD 620 | 32 | overview / meadow | 1.06 / 0.64 | 1.00–1.42 | 2.70–5.11 | 6.37–10.59 | 6.30–16.91 | - At RD 16 the rebuild costs nothing measurable. At RD 32 it is 0.1–0.5 ms on the M4 Pro and 0.6–1.1 ms on the 4-thread laptop, about 10% of its CPU frame. - With LODs on (#771, LOD 64, RD 12, HD 620), far tiles add 3.8 M quads, and the HD 620's GPU time follows the quad count (5 ms for far terrain: card#23 / perf-frame-10). A GPU-side table would not change that. - `encode` is the bigger CPU item on both machines (2.7–5.1 ms on the laptop at RD 32). So a GPU table saves at most the `draw_list` share, about 1 ms, only at RD 32 on weak CPUs, and only where the frame is CPU-bound. Data: `~/code/horizon-parity/shots/perf-frame-10/`. Nothing implemented.
Author
Owner

@ludovic111 commented on GitHub (Oct 21, 2026):

🤖 Agent: closing this with measurements: a persistent GPU-side table with compute culling doesn't pay today. A measured "not worth it" close, per the triage rule (batch P3, 2026-10-21).

What it would remove is the CPU build of the draw list each frame: instance origins, facing ranges and indirect args, measured as the temporary draw_list span in perf-frame-10 (10-19, seed 1234, LODs off, 8 s benches):

machine RD draw_list ms/frame CPU ms/frame GPU ms/frame
Mac mini M4 Pro 16 ≤ 0.003 0.97–1.08 0.14–0.23
Mac mini M4 Pro 32 0.12–0.46 1.94–3.47 0.33–0.85
ThinkPad HD 620 16 ≤ 0.014 2.31–3.42 3.89–5.87
ThinkPad HD 620 32 0.64–1.06 6.37–10.59 6.30–16.91
  • The saving is at most about 1 ms, only at RD 32, and only on the 4-thread laptop. There the GPU is the longer side of the frame (today on main 02bd3cbc at RD 32: GPU 6.1–20.4 ms against CPU 4.0–10.0 ms). A compute pass would add GPU work on exactly the device that is GPU-bound.
  • On Metal, wgpu-hal replays each multi-draw entry as its own draw, and gfx/flat.rs batching takes over from 4,096 draws. A GPU-written indirect list doesn't remove that replay.
  • With LODs on, the HD 620's GPU time follows the far-terrain quad count (#771), which a draw table doesn't change.
  • Vanilla's cave-culling rules (#782, #1094) cut the drawn sections at RD 32 by 41% at the overview and 66% in the meadow (4,902 → 2,883 and 2,726 → 917, same seed and views on both machines). Frame time on the HD 620 drops with them (overview 17.8 → 14.0 ms, meadow 11.4 → 4.7 ms). That shrinks this list on every machine at no GPU cost.
  • encode (2–5 ms on the HD 620 at RD 32) is the larger CPU item, and the frame-cost batch is working on it.

Revisit if the Vulkan GPU occlusion culling (#939) moves to a GPU-driven pipeline anyway. Noted in the LATER list.

<!-- gh-comment-id:6321022199 --> @ludovic111 commented on GitHub (Oct 21, 2026): 🤖 Agent: closing this with measurements: a persistent GPU-side table with compute culling doesn't pay today. A measured "not worth it" close, per the triage rule (batch P3, 2026-10-21). **What it would remove** is the CPU build of the draw list each frame: instance origins, facing ranges and indirect args, measured as the temporary `draw_list` span in perf-frame-10 (10-19, seed 1234, LODs off, 8 s benches): | machine | RD | `draw_list` ms/frame | CPU ms/frame | GPU ms/frame | | --- | --- | --- | --- | --- | | Mac mini M4 Pro | 16 | ≤ 0.003 | 0.97–1.08 | 0.14–0.23 | | Mac mini M4 Pro | 32 | 0.12–0.46 | 1.94–3.47 | 0.33–0.85 | | ThinkPad HD 620 | 16 | ≤ 0.014 | 2.31–3.42 | 3.89–5.87 | | ThinkPad HD 620 | 32 | 0.64–1.06 | 6.37–10.59 | 6.30–16.91 | - The saving is at most about 1 ms, only at RD 32, and only on the 4-thread laptop. There the GPU is the longer side of the frame (today on main 02bd3cbc at RD 32: GPU 6.1–20.4 ms against CPU 4.0–10.0 ms). A compute pass would add GPU work on exactly the device that is GPU-bound. - On Metal, wgpu-hal replays each multi-draw entry as its own draw, and `gfx/flat.rs` batching takes over from 4,096 draws. A GPU-written indirect list doesn't remove that replay. - With LODs on, the HD 620's GPU time follows the far-terrain quad count (#771), which a draw table doesn't change. - Vanilla's cave-culling rules (#782, #1094) cut the drawn sections at RD 32 by 41% at the overview and 66% in the meadow (4,902 → 2,883 and 2,726 → 917, same seed and views on both machines). Frame time on the HD 620 drops with them (overview 17.8 → 14.0 ms, meadow 11.4 → 4.7 ms). That shrinks this list on every machine at no GPU cost. - `encode` (2–5 ms on the HD 620 at RD 32) is the larger CPU item, and the frame-cost batch is working on it. Revisit if the Vulkan GPU occlusion culling (#939) moves to a GPU-driven pipeline anyway. Noted in the LATER list.
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#274
No description provided.