d3d12: measure mesh-output reservation and add the indexed-VS eligibility predicate (#3180) #3468

Code

Clone this repository

Checkout

From your project repository, check out a new branch and test the changes.

git fetch -u  "d3d12/mesh-output-fill:KelboLive-d3d12/mesh-output-fill"
git switch "KelboLive-d3d12/mesh-output-fill"
Open
leonida/mandy
KelboLive wants to merge 2 commits from KelboLive/mandy:d3d12/mesh-output-fill into main

This pull request can be merged automatically.

Conversation
Reviewers 0 approvals
  • No reviewers
Details
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 'd3d12/mesh-output-fill:KelboLive-d3d12/mesh-output-fill'
git switch 'KelboLive-d3d12/mesh-output-fill'
First-time contributor

What/why

#3180: native mesh is thin because the title declares 128x128 output maxima and the reservation follows the declaration; the audit proposed measuring used/reserved output bytes per group and a pure eligibility predicate for a future indexed-VS form. This adds the measurement and the predicate, no behaviour change.

Added

leonida-shader emit/mesh_fill.rs:

  • mesh_out_fill(layout, v, p) = (v*vertex_stride + p*primitive_stride) / group_bytes, with group_bytes == 0 -> 0.
  • indexed_vs_eligible(threads, layout, facts): threads <= 128, max_vertices <= 128, max_primitives <= 128, no per-primitive outputs, no LDS, no barriers, no writes, only first-lane cross-lane reads.
  • TranslationFacts / CrossLane, fill_bucket and fill_histogram with FILL_BUCKETS.
  • HostShader::mesh_output_layout() reads the fallback mesh_out, else parses the emitted PSV0 maxima and OSG1/PSG1 strides (post-clamp values).

leonida-gpu mesh_fill (diagnostics only): one line per mesh program every five seconds, with declared maxima, strides, group_bytes, direct-dispatch group counts and reserved MB a frame; layouts cached per program name. With actual counts supplied it prints the fill, and indirect runs with GPU-only counts say so.

Native-path limitation (stated in the log)

The native path can report reserved bytes, not true fill: the console M0 becomes SetMeshOutputCounts (and an LDS exchange with LEONIDA_MESH_COUNTS) inside the shader and is never stored in the mesh-buffer header, which holds D3D12 draw arguments. Making it readable would require a diagnostic store in the translated shader - a translation change, out of scope here. The fill path is unit-tested and ready for a future source.

Tests

  • leonida-shader: 453 passed, 10 new mesh_fill tests + a layout read-back.
  • leonida-gpu: 755 serial, 3 diagnostics mesh_fill tests; clippy clean for both crates; no-game-data and diff clean.

Unverified

No game run: whether reporting reserved-only is enough to size the indexed-VS opportunity on the real title (the actual (v,p) histogram is still missing), and whether indexed_vs_eligible's mapping from the real Lower/Shader fields is exact for every program (documented approximations: barriers from no_barrier/fence_only, cross-lane from exchange/split_lds/WAVE_OPS). The ten-program in-game A/B remains the missing evidence for the frame-time claim.

Item: D3D12-MESH-OUTPUT-FILL, claimed in #3312. Depends on: none.
AI-assisted: DeepSeek V4.1 Flash (OpenCode); the #3180 audit defined the probe and the predicate.

## What/why #3180: native mesh is thin because the title declares 128x128 output maxima and the reservation follows the **declaration**; the audit proposed measuring used/reserved output bytes per group and a pure eligibility predicate for a future indexed-VS form. This adds the measurement and the predicate, **no behaviour change**. ## Added **`leonida-shader` `emit/mesh_fill.rs`:** - `mesh_out_fill(layout, v, p)` = `(v*vertex_stride + p*primitive_stride) / group_bytes`, with `group_bytes == 0` -> 0. - `indexed_vs_eligible(threads, layout, facts)`: `threads <= 128`, `max_vertices <= 128`, `max_primitives <= 128`, no per-primitive outputs, no LDS, no barriers, no writes, only first-lane cross-lane reads. - `TranslationFacts` / `CrossLane`, `fill_bucket` and `fill_histogram` with `FILL_BUCKETS`. - `HostShader::mesh_output_layout()` reads the fallback `mesh_out`, else parses the emitted PSV0 maxima and OSG1/PSG1 strides (post-clamp values). **`leonida-gpu` `mesh_fill` (diagnostics only):** one line per mesh program every five seconds, with declared maxima, strides, `group_bytes`, direct-dispatch group counts and **reserved MB a frame**; layouts cached per program name. With actual counts supplied it prints the fill, and indirect runs with GPU-only counts say so. ## Native-path limitation (stated in the log) The native path can report **reserved** bytes, not true fill: the console M0 becomes `SetMeshOutputCounts` (and an LDS exchange with `LEONIDA_MESH_COUNTS`) inside the shader and is never stored in the mesh-buffer header, which holds D3D12 draw arguments. Making it readable would require a diagnostic store in the translated shader - a translation change, out of scope here. The fill path is unit-tested and ready for a future source. ## Tests - `leonida-shader`: **453 passed**, 10 new `mesh_fill` tests + a layout read-back. - `leonida-gpu`: **755 serial**, 3 diagnostics `mesh_fill` tests; clippy clean for both crates; no-game-data and diff clean. ## Unverified No game run: whether reporting reserved-only is enough to size the indexed-VS opportunity on the real title (the actual `(v,p)` histogram is still missing), and whether `indexed_vs_eligible`'s mapping from the real `Lower`/`Shader` fields is exact for every program (documented approximations: barriers from `no_barrier`/`fence_only`, cross-lane from `exchange`/`split_lds`/`WAVE_OPS`). The ten-program in-game A/B remains the missing evidence for the frame-time claim. Item: D3D12-MESH-OUTPUT-FILL, claimed in #3312. Depends on: none. AI-assisted: DeepSeek V4.1 Flash (OpenCode); the #3180 audit defined the probe and the predicate.
KelboLive force-pushed d3d12/mesh-output-fill from f684c6216c to 26b567a972 2026-12-04 15:10:42 +00:00 Compare
Author
First-time contributor

Rebased onto main 44c480a5f (head 26b567a97). No conflicts. Re-ran: leonida-shader 453 passed, GPU lib 758 passed, 0 failed, 60 ignored.

Rebased onto `main` `44c480a5f` (head `26b567a97`). No conflicts. Re-ran: `leonida-shader` 453 passed, GPU lib 758 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/mesh-output-fill from 26b567a972 to 54b59d757f 2026-12-04 16:01:45 +00:00 Compare
Author
First-time contributor

Replayed onto main bba262b94 (head 54b59d757). No conflicts. Re-ran: leonida-shader 456 passed, 0 failed, 6 ignored; GPU lib 777 passed, 0 failed, 60 ignored.

Replayed onto `main` `bba262b94` (head `54b59d757`). No conflicts. Re-ran: `leonida-shader` 456 passed, 0 failed, 6 ignored; GPU lib 777 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/mesh-output-fill from 54b59d757f to a0b770b4bc 2026-12-04 16:16:04 +00:00 Compare
Author
First-time contributor

Replayed onto main e1be896b2 (head a0b770b4b). No conflicts. GPU 777 passed; shader 456 passed, 6 ignored.

One extra docs commit: LEONIDA_MESH_COUNTS is read in mesh_fill.rs now, so its generated row moved and --check failed. Regenerated.

Replayed onto `main` `e1be896b2` (head `a0b770b4b`). No conflicts. GPU 777 passed; shader 456 passed, 6 ignored. One extra docs commit: `LEONIDA_MESH_COUNTS` is read in `mesh_fill.rs` now, so its generated row moved and `--check` failed. Regenerated.
KelboLive force-pushed d3d12/mesh-output-fill from a0b770b4bc to 5af0a53d6f 2026-12-04 16:32:42 +00:00 Compare
Author
First-time contributor

Replayed onto main 00e245be5 (head 5af0a53d6). No conflicts; switch page --check ok. GPU 787 passed, 0 failed, 60 ignored. The leonida-shader suite was last green at 456 on this code (the rebase touched no shader source).

Replayed onto `main` `00e245be5` (head `5af0a53d6`). No conflicts; switch page `--check` ok. GPU 787 passed, 0 failed, 60 ignored. The `leonida-shader` suite was last green at 456 on this code (the rebase touched no shader source).
KelboLive force-pushed d3d12/mesh-output-fill from 5af0a53d6f to c77c35f389 2026-12-04 17:15:23 +00:00 Compare
Author
First-time contributor

Replayed onto main f22b9fa64 (head c77c35f38). No conflicts; switch page ok. GPU 790 passed, 0 failed, 60 ignored.

Replayed onto `main` `f22b9fa64` (head `c77c35f38`). No conflicts; switch page ok. GPU 790 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/mesh-output-fill from c77c35f389 to dbdefc4d60 2026-12-04 18:30:30 +00:00 Compare
Author
First-time contributor

Replayed onto main 6491bc1a1 (head dbdefc4d6). No conflicts; switch page ok. GPU 790 passed, 0 failed, 60 ignored.

Replayed onto `main` `6491bc1a1` (head `dbdefc4d6`). No conflicts; switch page ok. GPU 790 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/mesh-output-fill from dbdefc4d60 to c5a00abc35 2026-12-04 18:44:22 +00:00 Compare
Author
First-time contributor

Replayed onto main 6b0498d37 (head c5a00abc3). No conflicts. GPU 790 passed, 0 failed, 60 ignored.

Replayed onto `main` `6b0498d37` (head `c5a00abc3`). No conflicts. GPU 790 passed, 0 failed, 60 ignored.
First-time contributor

RUN — c5a00abc35 (rebased on main 6b0498d37), NVIDIA RTX 5070 12 GB, Windows 11.

Static & unit checks

  • cargo test -p leonida-shader --lib --locked mesh_fill: 10/10 PASS
  • cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings: 0 warnings
  • python -I tools/d3d12_switches.py --check & python -I scripts/check_no_game_data.py: PASS

Live 315 s run (-SeriesS -NoFrameGen -NoPrecompile -AutoMenu)

  • World telemetry (27 samples with >= 1000 draws, max_draws = 5,294): median 22.8 fps (43.8 ms, p10 12.9, p90 24.7; 3000-4999 draws, 16 samples: median 23.4 fps).
  • Runtime health: 0 ERROR lines, 0 mesh_fill warnings, device-lost.txt = false, peak video memory 8,057 / 11,176 MB.

Live leonida_gpu::mesh_fill aggregates (clean-room summary, no shader hashes)

  • Declared maxima: all active mesh pipelines declared 128 vertices / 128 primitives, with 3,584-33,280 B/group (final snapshot median 15,360 B/group). All lines reported fill reserved only on the native path, as expected.
  • Across 127 in-world snapshots (>= 100 mesh pipelines): median 189 pipelines per snapshot, median direct-dispatch reservation 6,465 groups/frame (52.00 MB reserved/frame), median 78,333 indirect dispatches per snapshot with GPU-only group counts.
  • Final snapshot (187 pipelines): 52 direct-dispatch (6,465 groups/frame, 51.39 MB reserved/frame; largest single pipeline 10.39 MB/frame at 2,029 groups * 5,120 B/group) + 135 indirect-only (81,536 indirect dispatches with GPU-only group counts — ~72% of active mesh pipelines) + 0 idle.
  • Peak direct-dispatch snapshot (207 pipelines): 9,441 groups/frame, 154.93 MB reserved/frame (largest single pipeline 39.96 MB/frame at 1,419 groups * 28,160 B/group) + 30,380 indirect dispatches (129 indirect-only, 1 both).

One live observation (cadence & log volume)

  • In d3d12/crates/leonida-gpu/src/host.rs, crate::mesh_fill::line(frames) is called in Meter::lines outside the if five { ... } block, so it fires every ~1 s (139 snapshots, median 1.02 s cadence) rather than every 5 s as stated in the PR description and doc comment.
  • Because diagnostics is enabled in standard test runs, this emitted 25,052 INFO lines in 315 s (~189 lines/s in-world, ~41% of the 60,596-line log), repeating the long fill reserved only (...) note on every line. Moving crate::mesh_fill::line(frames) inside if five { ... } (and optionally summarizing or gating the per-pipeline dump behind an opt-in switch) would match the documented 5 s cadence and significantly cut log noise.

AI-assisted.

RUN — `c5a00abc35` (rebased on `main` `6b0498d37`), `NVIDIA RTX 5070 12 GB`, `Windows 11`. ### Static & unit checks - `cargo test -p leonida-shader --lib --locked mesh_fill`: `10/10` PASS - `cargo clippy -p leonida-gpu --all-targets --locked -- -D warnings`: `0` warnings - `python -I tools/d3d12_switches.py --check` & `python -I scripts/check_no_game_data.py`: PASS ### Live 315 s run (`-SeriesS -NoFrameGen -NoPrecompile -AutoMenu`) - World telemetry (`27` samples with `>= 1000` draws, `max_draws = 5,294`): median `22.8 fps` (`43.8 ms`, p10 `12.9`, p90 `24.7`; `3000-4999` draws, `16` samples: median `23.4 fps`). - Runtime health: `0` `ERROR` lines, `0` `mesh_fill` warnings, `device-lost.txt = false`, peak video memory `8,057 / 11,176 MB`. ### Live `leonida_gpu::mesh_fill` aggregates (clean-room summary, no shader hashes) - Declared maxima: all active mesh pipelines declared `128 vertices / 128 primitives`, with `3,584-33,280` B/group (final snapshot median `15,360` B/group). All lines reported `fill reserved only` on the native path, as expected. - Across `127` in-world snapshots (`>= 100` mesh pipelines): median `189` pipelines per snapshot, median direct-dispatch reservation `6,465` groups/frame (`52.00 MB` reserved/frame), median `78,333` indirect dispatches per snapshot with GPU-only group counts. - Final snapshot (`187` pipelines): `52` direct-dispatch (`6,465` groups/frame, `51.39 MB` reserved/frame; largest single pipeline `10.39 MB`/frame at `2,029` groups * `5,120` B/group) + `135` indirect-only (`81,536` indirect dispatches with GPU-only group counts — ~72% of active mesh pipelines) + `0` idle. - Peak direct-dispatch snapshot (`207` pipelines): `9,441` groups/frame, `154.93 MB` reserved/frame (largest single pipeline `39.96 MB`/frame at `1,419` groups * `28,160` B/group) + `30,380` indirect dispatches (`129` indirect-only, `1` both). ### One live observation (cadence & log volume) - In `d3d12/crates/leonida-gpu/src/host.rs`, `crate::mesh_fill::line(frames)` is called in `Meter::lines` outside the `if five { ... }` block, so it fires every **~1 s** (`139` snapshots, median `1.02 s` cadence) rather than every **5 s** as stated in the PR description and doc comment. - Because `diagnostics` is enabled in standard test runs, this emitted **`25,052` `INFO` lines** in 315 s (~`189` lines/s in-world, ~41% of the `60,596`-line log), repeating the long `fill reserved only (...)` note on every line. Moving `crate::mesh_fill::line(frames)` inside `if five { ... }` (and optionally summarizing or gating the per-pipeline dump behind an opt-in switch) would match the documented 5 s cadence and significantly cut log noise. AI-assisted.
KelboLive force-pushed d3d12/mesh-output-fill from c5a00abc35 to eeefb7f665 2026-12-04 20:53:07 +00:00 Compare
Author
First-time contributor

Replayed onto main 0036195a7 (head eeefb7f66). No conflicts. 790 passed, 0 failed, 60 ignored.

Replayed onto `main` `0036195a7` (head `eeefb7f66`). No conflicts. 790 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/mesh-output-fill from eeefb7f665 to c82f118919 2026-12-04 23:20:30 +00:00 Compare
Author
First-time contributor

Replayed onto main f4b0404e9 (head c82f11891). No conflicts. 790 passed, 0 failed, 60 ignored.

Replayed onto `main` `f4b0404e9` (head `c82f11891`). No conflicts. 790 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/mesh-output-fill from c82f118919 to 48e8f56245 2026-12-05 05:34:53 +00:00 Compare
Author
First-time contributor

Replayed onto main 93b9d90a2 (head 48e8f5624). No conflicts. 790 passed, 0 failed, 60 ignored.

Replayed onto `main` `93b9d90a2` (head `48e8f5624`). No conflicts. 790 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/mesh-output-fill from 48e8f56245 to d130d9b379 2026-12-05 08:44:30 +00:00 Compare
Author
First-time contributor

Replayed onto main c5355dd25 (head d130d9b37). No conflicts. 791 passed, 0 failed, 60 ignored.

Replayed onto `main` `c5355dd25` (head `d130d9b37`). No conflicts. 791 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/mesh-output-fill from d130d9b379 to 6b4b1f479c 2026-12-05 08:53:27 +00:00 Compare
Author
First-time contributor

Replayed onto main e1b0248c1 (head 6b4b1f479). No conflicts. 791 passed, 0 failed, 60 ignored.

Replayed onto `main` `e1b0248c1` (head `6b4b1f479`). No conflicts. 791 passed, 0 failed, 60 ignored.
KelboLive force-pushed d3d12/mesh-output-fill from 6b4b1f479c to d130b35ee8 2026-12-05 09:59:47 +00:00 Compare
Author
First-time contributor

Replayed onto main d99bb4d7a (head d130b35ee). No conflicts. 794 passed, 0 failed, 60 ignored.

Replayed onto `main` `d99bb4d7a` (head `d130b35ee`). No conflicts. 794 passed, 0 failed, 60 ignored.
Sign in to join this conversation.
No description provided.