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

Open
github-bot wants to merge 1 commit from github-bot/gh-477 into master AGit
Owner

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

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: to follow from the second PC (A/B against master at the same four city views as #475).

**@⁠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 · open 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: to follow from the second PC (A/B against master at the same four city views as #475).
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
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/477/head:github-bot/gh-477'
git switch 'github-bot/gh-477'

Merge

Merge the changes and update on Forgejo.
git switch 'master'
git merge --no-ff 'github-bot/gh-477'
git switch 'github-bot/gh-477'
git rebase 'master'
git switch 'master'
git merge --ff-only 'github-bot/gh-477'
git switch 'github-bot/gh-477'
git rebase 'master'
git switch 'master'
git merge --no-ff 'github-bot/gh-477'
git switch 'master'
git merge --squash 'github-bot/gh-477'
git switch 'master'
git merge --ff-only 'github-bot/gh-477'
git switch 'master'
git merge 'github-bot/gh-477'
git push origin 'master'
This discussion has been locked. Commenting is limited to contributors.
No description provided.