Map 3D: cull the meshes of few-placement models one by one #485

Manually merged
github merged 1 commit from github-bot/gh-485 into gh-pr/485/base 2026-11-27 18:46:52 +00:00 AGit
Owner

@⁠holdmysocks on GitHub · 2026-11-27 18:11 UTC · original
holdmysocks:six-map3d-meshcull → master · +144 −3 · 3 files · 1 commits · merged 2026-11-27 18:43 UTC

The city views' coverage fallbacks (coarse SLOD tiles drawn near the camera where nothing finer covers the ground) cost 400 to 970 draws a frame. They are whole-area tiles, so the camera sits inside or next to them and many of their meshes are behind it or off to the side, but every mesh was drawn. The same holds for the busiest normally drawn models: SLOD tiles and buildings with one placement and 50 to 110 meshes.

What changes:

  • Per-mesh bounds. Each mesh gets a bounding sphere around its centre when it is uploaded.
  • Transforms on the CPU. A model placed at most 8 times keeps its placements' transforms (and largest axis scale) on the CPU, in the order of its instance buffer: normal placements first, then fallbacks.
  • Culling. In the opaque and coverage-fallback passes, a mesh is skipped when none of the placements drawn in that pass puts its sphere inside the view's four sides. In the shadow passes the test is the cascade's box, the same test whole models already get. Skinned models and strand hair are not culled.
  • No split draws. When culled meshes lie between two that would have joined into one draw (same material in the main pass, any solid material in shadows), the draw still spans them. The cull can only remove draws, never turn one into two.
  • Tick line. It now shows the meshes culled per frame as meshes culled [main, fallbacks, shadows].
  • Test. A unit test checks the view test in front of, behind and beside the camera.

Results (RTX 3090, master vs this PR, four city views plus a 30 s fly, path off, 18 runs, no panics or validation errors; the cull, order and cells unit tests pass):

View Draws main (shadow) before → after Meshes culled [main, fallbacks, shadows] Fallback model draws Model draws main/shadow CPU finish µs
s3 3861 (855) → 3200 (739) 461, 200, 780 400 → 200 2106/466 → 1445/350 5550 → 4886
dtst 3776 (850) → 3142 (635) 475, 159, 1123 393 → 234 2128/577 → 1494/408 5642 → 5375
rs 5114 (1197) → 4457 (991) 668, 203, 1337 969 → 766 2922/648 → 2219/445 7195 → 6845
wide 2780 (650) → 2101 (644) 490, 189, 18 506 → 317 1302/206 → 623/200 3797 → 3305

Draws fall by 630 to 680 per frame in every view. Encoder finish time drops 270 to 660 µs; pass time rises in three views (the sphere tests), by less than finish falls in two of them. GPU time is unchanged within noise. In a 30 s fly from s3 the mean frame time falls from 26.8 to 22.1 ms (p99 55.6 to 46.2 ms, frames over 33 ms 13.0 % to 5.2 %).

Images: s3, dtst and wide match master (at most 6 pixels over 16 levels, none at the image border). At rs the freed draw budget lets more detail load (1171 models instead of 952), so small props such as café furniture and rooftop units show, with their shadows. Nothing is missing at the edges, and there are no shadow holes, in the still views or the fly.

**@⁠holdmysocks** on GitHub · 2026-11-27 18:11 UTC · [original](https://github.com/holdmysocks/SixNG/pull/485) `holdmysocks:six-map3d-meshcull` → `master` · +144 −3 · 3 files · 1 commits · merged 2026-11-27 18:43 UTC The city views' coverage fallbacks (coarse SLOD tiles drawn near the camera where nothing finer covers the ground) cost 400 to 970 draws a frame. They are whole-area tiles, so the camera sits inside or next to them and many of their meshes are behind it or off to the side, but every mesh was drawn. The same holds for the busiest normally drawn models: SLOD tiles and buildings with one placement and 50 to 110 meshes. What changes: - **Per-mesh bounds.** Each mesh gets a bounding sphere around its centre when it is uploaded. - **Transforms on the CPU.** A model placed at most 8 times keeps its placements' transforms (and largest axis scale) on the CPU, in the order of its instance buffer: normal placements first, then fallbacks. - **Culling.** In the opaque and coverage-fallback passes, a mesh is skipped when none of the placements drawn in that pass puts its sphere inside the view's four sides. In the shadow passes the test is the cascade's box, the same test whole models already get. Skinned models and strand hair are not culled. - **No split draws.** When culled meshes lie between two that would have joined into one draw (same material in the main pass, any solid material in shadows), the draw still spans them. The cull can only remove draws, never turn one into two. - **Tick line.** It now shows the meshes culled per frame as `meshes culled [main, fallbacks, shadows]`. - **Test.** A unit test checks the view test in front of, behind and beside the camera. Results (RTX 3090, master vs this PR, four city views plus a 30 s fly, path off, 18 runs, no panics or validation errors; the cull, order and cells unit tests pass): | View | Draws main (shadow) before → after | Meshes culled [main, fallbacks, shadows] | Fallback model draws | Model draws main/shadow | CPU finish µs | |---|---|---|---|---|---| | s3 | 3861 (855) → 3200 (739) | 461, 200, 780 | 400 → 200 | 2106/466 → 1445/350 | 5550 → 4886 | | dtst | 3776 (850) → 3142 (635) | 475, 159, 1123 | 393 → 234 | 2128/577 → 1494/408 | 5642 → 5375 | | rs | 5114 (1197) → 4457 (991) | 668, 203, 1337 | 969 → 766 | 2922/648 → 2219/445 | 7195 → 6845 | | wide | 2780 (650) → 2101 (644) | 490, 189, 18 | 506 → 317 | 1302/206 → 623/200 | 3797 → 3305 | Draws fall by 630 to 680 per frame in every view. Encoder finish time drops 270 to 660 µs; pass time rises in three views (the sphere tests), by less than finish falls in two of them. GPU time is unchanged within noise. In a 30 s fly from s3 the mean frame time falls from 26.8 to 22.1 ms (p99 55.6 to 46.2 ms, frames over 33 ms 13.0 % to 5.2 %). Images: s3, dtst and wide match master (at most 6 pixels over 16 levels, none at the image border). At rs the freed draw budget lets more detail load (1171 models instead of 952), so small props such as café furniture and rooftop units show, with their shadows. Nothing is missing at the edges, and there are no shadow holes, in the still views or the fly.
A model placed at most 8 times keeps its placements' transforms on the CPU, and each mesh is tested on its bounding sphere: against the view's sides in the opaque and coverage-fallback passes and against each shadow cascade's box. Meshes no placement shows are skipped; culled meshes between two that would join stay inside the draw, so the cull never splits a draw. The tick line shows meshes culled per frame (main, fallbacks, shadows).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 18:13:15 +00:00
github-bot changed target branch from master to gh-pr/485/base 2026-11-27 18:46:50 +00:00
github manually merged commit 336ba14ad2 into gh-pr/485/base 2026-11-27 18:46:52 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.