Map 3D: group model meshes by material so they draw as one call #477

Manually merged
github merged 1 commit from github-bot/gh-477 into gh-pr/477/base 2026-11-27 17:16:45 +00:00 AGit
Owner

@⁠holdmysocks on GitHub · 2026-11-27 16:40 UTC · original
holdmysocks:six-map3d-matorder → master · +166 −46 · 3 files · 1 commits · merged 2026-11-27 17:10 UTC

City views spend most of their CPU frame time recording draw calls. Model meshes were drawn in file order, so #470's joining of neighbouring meshes rarely found two of one material side by side: the busiest models drew 30 to 70 calls for 50 to 90 meshes. Decal and see-through meshes drew one call each and rebound everything per mesh (#471 tried joining them in file order and gained little).

What changes:

  • Buffer layout. When a model is uploaded, its meshes go into its shared vertex and index buffers grouped by kind (solid, cut-out, decal, see-through), then by material, then in their own order. The model keeps its meshes in file order; a new order list gives the buffer order, and the draw loops walk it.
  • Main and shadow passes. The existing joining now sees a model's meshes of one material next to each other, so they draw as one call. In the shadow passes all of a model's solid meshes follow on, so they are usually one call.
  • Decals and see-through. These keep their order (by layer, then far to near) but bind only what changed, and a mesh joins the pending draw when it follows on in the same model, material and pipeline. Opaque-mode decals write depth and do not blend, so their order matters only between coplanar ones; they are now sorted far to near by model rather than by mesh, which keeps a model's together. Blended decals and see-through meshes stay far to near by mesh.
  • Empty draws dropped. Models whose instances are all coverage fallbacks are left out of the decal and see-through lists.
  • Tick line. The draws field now also shows the decal and see-through calls.
  • Test. A unit test checks the layout order.

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

View Draws main (shadow) before → after Decal/see-through after Model draws main/shadow before → after CPU finish µs before → after
s3 3976 (933) → 3861 (856) 1117 2142/542 → 2106/466 5853 → 5694
dtst 3869 (905) → 3776 (833) 1149 2165/658 → 2128/577 5902 → 5760
rs 5248 (1311) → 5114 (1179) 1507 2956/735 → 2922/648 7621 → 7385
wide 2850 (676) → 2780 (650) 680 1302/232 → 1302/206 4151 → 3933

Draws fall by 70 to 134 in the main pass and 26 to 132 in shadows. Encoder finish time drops 140 to 240 µs in every view; pass and submit time move both ways within noise, and GPU time and VRAM are unchanged. The busiest models still draw about one call per mesh: their meshes mostly have a material each, so grouping cannot join them. Images: no pixel differs by more than 16 levels in any view; at most 0.19 % differ at all, single edge pixels in far patches where coplanar opaque decals now resolve ties in model order.

**@⁠holdmysocks** on GitHub · 2026-11-27 16:40 UTC · [original](https://github.com/holdmysocks/SixNG/pull/477) `holdmysocks:six-map3d-matorder` → `master` · +166 −46 · 3 files · 1 commits · merged 2026-11-27 17:10 UTC City views spend most of their CPU frame time recording draw calls. Model meshes were drawn in file order, so #470's joining of neighbouring meshes rarely found two of one material side by side: the busiest models drew 30 to 70 calls for 50 to 90 meshes. Decal and see-through meshes drew one call each and rebound everything per mesh (#471 tried joining them in file order and gained little). What changes: - **Buffer layout.** When a model is uploaded, its meshes go into its shared vertex and index buffers grouped by kind (solid, cut-out, decal, see-through), then by material, then in their own order. The model keeps its meshes in file order; a new `order` list gives the buffer order, and the draw loops walk it. - **Main and shadow passes.** The existing joining now sees a model's meshes of one material next to each other, so they draw as one call. In the shadow passes all of a model's solid meshes follow on, so they are usually one call. - **Decals and see-through.** These keep their order (by layer, then far to near) but bind only what changed, and a mesh joins the pending draw when it follows on in the same model, material and pipeline. Opaque-mode decals write depth and do not blend, so their order matters only between coplanar ones; they are now sorted far to near by model rather than by mesh, which keeps a model's together. Blended decals and see-through meshes stay far to near by mesh. - **Empty draws dropped.** Models whose instances are all coverage fallbacks are left out of the decal and see-through lists. - **Tick line.** The draws field now also shows the decal and see-through calls. - **Test.** A unit test checks the layout order. Results (RTX 3090, master vs this PR, four city views, path off, 16 runs, no panics or validation errors; the order and cells unit tests pass): | View | Draws main (shadow) before → after | Decal/see-through after | Model draws main/shadow before → after | CPU finish µs before → after | |---|---|---|---|---| | s3 | 3976 (933) → 3861 (856) | 1117 | 2142/542 → 2106/466 | 5853 → 5694 | | dtst | 3869 (905) → 3776 (833) | 1149 | 2165/658 → 2128/577 | 5902 → 5760 | | rs | 5248 (1311) → 5114 (1179) | 1507 | 2956/735 → 2922/648 | 7621 → 7385 | | wide | 2850 (676) → 2780 (650) | 680 | 1302/232 → 1302/206 | 4151 → 3933 | Draws fall by 70 to 134 in the main pass and 26 to 132 in shadows. Encoder finish time drops 140 to 240 µs in every view; pass and submit time move both ways within noise, and GPU time and VRAM are unchanged. The busiest models still draw about one call per mesh: their meshes mostly have a material each, so grouping cannot join them. Images: no pixel differs by more than 16 levels in any view; at most 0.19 % differ at all, single edge pixels in far patches where coplanar opaque decals now resolve ties in model order.
A model's meshes go into its shared buffers grouped by kind (solid, cut-out, decal, see-through) and then by material, and are drawn in that order. Meshes of one material then follow on and draw as one call in the main pass, and a model's solid meshes draw as one call in the shadow passes. Decal and see-through meshes keep their layer and far-to-near order, bind only what changed, and join the pending draw when they follow on in the same model and material; opaque-mode decals are kept together per model. Models with nothing to draw normally are skipped. The tick line counts decal and see-through draws.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 16:42:12 +00:00
Author
Owner

@⁠maple-quartz18 on GitHub · 2026-11-27 16:50 UTC · original

mesh shaders

**@⁠maple-quartz18** on GitHub · 2026-11-27 16:50 UTC · [original](https://github.com/holdmysocks/SixNG/pull/477#issuecomment-7223727923) mesh shaders
github-bot changed target branch from master to gh-pr/477/base 2026-11-27 17:16:44 +00:00
github manually merged commit 65dac4b589 into gh-pr/477/base 2026-11-27 17:16:45 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.