Map 3D: GPU-driven draws for static models #473

Closed
github-bot wants to merge 3 commits from github-bot/gh-473 into master AGit
Owner

@⁠holdmysocks on GitHub · 2026-11-27 12:59 UTC · original
holdmysocks:six-map3d-gpudraws → master · +1265 −94 · 5 files · 3 commits · closed without merging

The 3D map's city views spent most of their CPU frame time on draw calls: about 250 full-detail models drew 2 to 16 calls each, one per material, and each call set its own material bind group. Joining neighbouring meshes (#470) was the last cheap cut. This moves static map models to GPU-driven draws.

What changes:

  • Shared pool. Static models (no skeleton, no strand hair) put their vertices and indices into a few large shared buffers (256 MB of vertices and 128 MB of indices per chunk) instead of two buffers each. Indices address the chunk's whole vertex buffer, so every existing draw path works unchanged. A freed range waits three frames before it is handed out again.
  • Material table and texture pages. Each material is one entry in a shared storage buffer: its uniform plus the slots of its eight textures. Textures sit in pages of 4096 (a texture binding array; slot 0 is white). All of a model's textures go in one page. A page is rebuilt at most every ten frames; until its page is rebuilt, a new model draws the old way.
  • Indirect draws. Each frame, the opaque, coverage-fallback and shadow passes collect one sub-draw per mesh run and write them to one indirect buffer. Each sub-draw's instances are copied with the material index in extra.w. Each pool chunk and texture page (and stencil value) is then one multi_draw_indexed_indirect call. Shadow cascades share the instance copies of the main pass.
  • Shader. The same shader source is transformed for this path: the material group becomes the table and the page, read through the index the vertex program passes on. Naga's derivative-uniformity check is turned off for this module, because the material index is constant over a draw. A unit test parses and validates the transformed shader.
  • What still draws the old way: skinned models, strand hair, see-through and decal surfaces, models with more than 4096 instance copies, and models whose page is not rebuilt yet. Also any device without texture binding arrays, non-uniform indexing or indirect first instance. SIXNG_MAP_GPU_DRAWS=0 turns the path off.
  • Tick line. It now shows sub-draws, indirect calls, instance copies, models drawn the old way, pool chunks, pages, materials and page-rebuild time.
  • Also fixed: the hair blur's strand mask added a base vertex to indices that #470 made absolute.

The draw budget counts calls, so with the path on the screen-size cut can drop, and more detail can load in views where draws were the limit.

Results: to follow from the second PC (A/B with SIXNG_MAP_GPU_DRAWS=0, same four views as #470).

**@⁠holdmysocks** on GitHub · 2026-11-27 12:59 UTC · [original](https://github.com/holdmysocks/SixNG/pull/473) `holdmysocks:six-map3d-gpudraws` → `master` · +1265 −94 · 5 files · 3 commits · closed without merging The 3D map's city views spent most of their CPU frame time on draw calls: about 250 full-detail models drew 2 to 16 calls each, one per material, and each call set its own material bind group. Joining neighbouring meshes (#470) was the last cheap cut. This moves static map models to GPU-driven draws. What changes: - **Shared pool.** Static models (no skeleton, no strand hair) put their vertices and indices into a few large shared buffers (256 MB of vertices and 128 MB of indices per chunk) instead of two buffers each. Indices address the chunk's whole vertex buffer, so every existing draw path works unchanged. A freed range waits three frames before it is handed out again. - **Material table and texture pages.** Each material is one entry in a shared storage buffer: its uniform plus the slots of its eight textures. Textures sit in pages of 4096 (a texture binding array; slot 0 is white). All of a model's textures go in one page. A page is rebuilt at most every ten frames; until its page is rebuilt, a new model draws the old way. - **Indirect draws.** Each frame, the opaque, coverage-fallback and shadow passes collect one sub-draw per mesh run and write them to one indirect buffer. Each sub-draw's instances are copied with the material index in `extra.w`. Each pool chunk and texture page (and stencil value) is then one `multi_draw_indexed_indirect` call. Shadow cascades share the instance copies of the main pass. - **Shader.** The same shader source is transformed for this path: the material group becomes the table and the page, read through the index the vertex program passes on. Naga's derivative-uniformity check is turned off for this module, because the material index is constant over a draw. A unit test parses and validates the transformed shader. - **What still draws the old way:** skinned models, strand hair, see-through and decal surfaces, models with more than 4096 instance copies, and models whose page is not rebuilt yet. Also any device without texture binding arrays, non-uniform indexing or indirect first instance. `SIXNG_MAP_GPU_DRAWS=0` turns the path off. - **Tick line.** It now shows sub-draws, indirect calls, instance copies, models drawn the old way, pool chunks, pages, materials and page-rebuild time. - **Also fixed:** the hair blur's strand mask added a base vertex to indices that #470 made absolute. The draw budget counts calls, so with the path on the screen-size cut can drop, and more detail can load in views where draws were the limit. Results: to follow from the second PC (A/B with `SIXNG_MAP_GPU_DRAWS=0`, same four views as #470).
Static map models keep their geometry in shared pool buffers, their materials in one storage table and their textures in pages of a texture binding array. The opaque, coverage-fallback and shadow passes draw each pool chunk and texture page with one indirect call; each run of meshes is one sub-draw, and its instances carry the material index. Models that do not fit draw the old way. SIXNG_MAP_GPU_DRAWS=0 turns the path off. Also: the hair mask draw no longer adds a base vertex to absolute indices.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:02:26 +00:00
wgpu tracks every view of a bind group each time it is set in a pass. The lists now go page by page, solid shadow casters draw depth-only with the material table alone, and pages bind only their used slots where the device can bind arrays partly.
github-bot closed this pull request 2026-11-27 13:50:11 +00:00
Author
Owner

@⁠holdmysocks on GitHub · 2026-11-27 13:43 UTC · original

Closing this. On the second PC (four city views, path off vs on), it cuts draw calls by 40-65 % and recording time by 0.2-0.9 ms, but encoder finish rises 1.0-2.8 ms at every view.

  • Total CPU per frame, off -> on: s3 8.50 -> 9.38 ms, dtst 8.56 -> 9.55, rs 9.82 -> 12.31, wide 7.06 -> 6.85.
  • Main-pass GPU time is up to 0.5 ms higher and shadow GPU 0.2-0.4 ms higher.
  • VRAM is 1.3-2.8 GB higher: the pool chunks are allocated whole and never fully used. At s3 that pushed the map over its memory budget during a fly-through, and buildings fell back to coarse far-field shapes.
  • Turning off wgpu's indirect validation did not help. Keeping shadows on the old path recovered about half of the finish increase.

The cause is in wgpu-core: setting a bind group in a render pass merges every texture view it holds into the pass's usage tracker. With texture-array pages that is the whole resident texture set, in every pass, instead of only the textures actually drawn. That outweighs the saved draw calls. The remaining calls are mostly map cells and see-through or decal surfaces, which this path does not cover.

Images matched the old path (0.00-0.03 % of pixels differ; rs 0.45 %, from extra props loading in the run with the path on).

**@⁠holdmysocks** on GitHub · 2026-11-27 13:43 UTC · [original](https://github.com/holdmysocks/SixNG/pull/473#issuecomment-7219874532) Closing this. On the second PC (four city views, path off vs on), it cuts draw calls by 40-65 % and recording time by 0.2-0.9 ms, but encoder finish rises 1.0-2.8 ms at every view. - Total CPU per frame, off -> on: s3 8.50 -> 9.38 ms, dtst 8.56 -> 9.55, rs 9.82 -> 12.31, wide 7.06 -> 6.85. - Main-pass GPU time is up to 0.5 ms higher and shadow GPU 0.2-0.4 ms higher. - VRAM is 1.3-2.8 GB higher: the pool chunks are allocated whole and never fully used. At s3 that pushed the map over its memory budget during a fly-through, and buildings fell back to coarse far-field shapes. - Turning off wgpu's indirect validation did not help. Keeping shadows on the old path recovered about half of the finish increase. The cause is in wgpu-core: setting a bind group in a render pass merges every texture view it holds into the pass's usage tracker. With texture-array pages that is the whole resident texture set, in every pass, instead of only the textures actually drawn. That outweighs the saved draw calls. The remaining calls are mostly map cells and see-through or decal surfaces, which this path does not cover. Images matched the old path (0.00-0.03 % of pixels differ; rs 0.45 %, from extra props loading in the run with the path on).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.