Map 3D: join map-cell batches into fewer draws #475

Manually merged
github merged 1 commit from github-bot/gh-475 into gh-pr/475/base 2026-11-27 14:57:25 +00:00 AGit
Owner

@⁠holdmysocks on GitHub · 2026-11-27 14:23 UTC · original
holdmysocks:six-map3d-celldraws → master · +86 −8 · 3 files · 1 commits · merged 2026-11-27 14:54 UTC

Map cells drew one call per batch, and a batch is one (distance group, texture chunk, pass). In the city views that was 345 to 676 cell batches a frame in the main pass, plus the same again in each shadow cascade, each with its own texture bind group.

What changes:

  • Upload order. When a cell is uploaded, its batches and their indices are laid out by pass, texture chunk, then distance range (near edge, far edge). Batches at neighbouring distances now sit next to each other in the index buffer.
  • Joined draws. In range batches of one pass and chunk that touch draw as one call. A run also extends across batches that are out of range when the gap adds at most half the run's indices; the vertex shader already drops every placement out of its own distance range, so the picture does not change, only some vertex work is added.
  • Bind once per chunk. A chunk's texture bind group is set only when the chunk changes, not per batch.
  • Test. A unit test checks the new order, the batch offsets and the reordered indices.

The draw budget counts calls, so fewer cell calls leave room for more model detail in views where draws were the limit.

Results (RTX 3090, master vs this PR, four city views, path off, 16 runs, no validation errors; the cells unit tests pass):

View Draws main (shadow) before → after Fallback cell draws CPU pass/finish/submit µs GPU shadows/main ms
s3 4119 (1065) → 3976 (935) 136 → 109 1967/5853/1556 → 1852/5830/587 1.95/7.52 → 1.96/8.05
dtst 3923 (995) → 3869 (923) 88 → 78 1848/5999/692 → 1877/5963/565 1.68/7.12 → 1.69/6.99
rs 5276 (1407) → 5166 (1272) 84 → 81 2225/7536/960 → 2272/7642/929 1.58/7.46 → 1.56/7.23
wide 3015 (812) → 2850 (676) 142 → 108 2125/4229/1001 → 2072/4330/1062 1.69/8.65 → 1.69/8.62

Cells drawn, cell batches and model draws are the same on both, so the whole drop is cell draws: 54 to 165 fewer in the main pass and 72 to 136 fewer in shadows. CPU and GPU times move within noise (the 1556 µs submit before at s3 is an outlier) and VRAM is unchanged. Images are pixel-equal at s3, dtst and wide. rs differs by 0.25 % because it settles into one of a few prop-trim states on either build; each build matches the earlier run in the same state.

**@⁠holdmysocks** on GitHub · 2026-11-27 14:23 UTC · [original](https://github.com/holdmysocks/SixNG/pull/475) `holdmysocks:six-map3d-celldraws` → `master` · +86 −8 · 3 files · 1 commits · merged 2026-11-27 14:54 UTC Map cells drew one call per batch, and a batch is one (distance group, texture chunk, pass). In the city views that was 345 to 676 cell batches a frame in the main pass, plus the same again in each shadow cascade, each with its own texture bind group. What changes: - **Upload order.** When a cell is uploaded, its batches and their indices are laid out by pass, texture chunk, then distance range (near edge, far edge). Batches at neighbouring distances now sit next to each other in the index buffer. - **Joined draws.** In range batches of one pass and chunk that touch draw as one call. A run also extends across batches that are out of range when the gap adds at most half the run's indices; the vertex shader already drops every placement out of its own distance range, so the picture does not change, only some vertex work is added. - **Bind once per chunk.** A chunk's texture bind group is set only when the chunk changes, not per batch. - **Test.** A unit test checks the new order, the batch offsets and the reordered indices. The draw budget counts calls, so fewer cell calls leave room for more model detail in views where draws were the limit. Results (RTX 3090, master vs this PR, four city views, path off, 16 runs, no validation errors; the cells unit tests pass): | View | Draws main (shadow) before → after | Fallback cell draws | CPU pass/finish/submit µs | GPU shadows/main ms | |---|---|---|---|---| | s3 | 4119 (1065) → 3976 (935) | 136 → 109 | 1967/5853/1556 → 1852/5830/587 | 1.95/7.52 → 1.96/8.05 | | dtst | 3923 (995) → 3869 (923) | 88 → 78 | 1848/5999/692 → 1877/5963/565 | 1.68/7.12 → 1.69/6.99 | | rs | 5276 (1407) → 5166 (1272) | 84 → 81 | 2225/7536/960 → 2272/7642/929 | 1.58/7.46 → 1.56/7.23 | | wide | 3015 (812) → 2850 (676) | 142 → 108 | 2125/4229/1001 → 2072/4330/1062 | 1.69/8.65 → 1.69/8.62 | Cells drawn, cell batches and model draws are the same on both, so the whole drop is cell draws: 54 to 165 fewer in the main pass and 72 to 136 fewer in shadows. CPU and GPU times move within noise (the 1556 µs submit before at s3 is an outlier) and VRAM is unchanged. Images are pixel-equal at s3, dtst and wide. rs differs by 0.25 % because it settles into one of a few prop-trim states on either build; each build matches the earlier run in the same state.
Cell batches go to the GPU ordered by pass, texture chunk and distance range. Batches in range that touch draw as one call, also across a batch out of range when that adds at most half the call's indices; the vertex shader already drops placements out of range. The chunk's bind group is set only when it changes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 14:25:27 +00:00
github-bot changed target branch from master to gh-pr/475/base 2026-11-27 14:57:24 +00:00
github manually merged commit 41d9b4cba9 into gh-pr/475/base 2026-11-27 14:57:25 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.