d3d12: most of the card's busy time is "thin" (few warps resident); the largest share is mesh output space, and wrapped VS meshlets run 2-5x faster as indexed VS draws (RTX 5060) #3180

Open
opened 2026-12-02 18:29:20 +00:00 by github-bot · 3 comments
Owner

@⁠plapha on GitHub · 2026-12-02 16:56 UTC · original

findings.md already notes that the card waits inside its work. We tried to put numbers on it and found one mechanism behind it. Setup: RTX 5060 8 GB, a foxhound/VIctory-based build (the translator differs from mandy's, but the title's wrapped programs are the same). The frame is a light one: 960×540 internal, ray tracing skipped, so it does less work than the console's 720p frame.

1. Thin and thick time (one captured frame, hardware samples every 4.8 µs)

Sampled command time is 34.06 ms. We split it by resident warps per SM (mesh + vertex + pixel + compute):

time share of warp × time
thick (≥ 4 warps/SM) 12.27 ms 92.3 %
thin (< 4 warps/SM) 21.79 ms 7.7 %

With the threshold at 2 or 8 instead of 4, thin time stays at 18–24 ms. The clocks stay up (median 2785 MHz) and the card draws about 50 W of its 145 W. Of the warps that are resident, 10 % issue and 46 % wait on memory.

Thin time by layer: geometry 10.5 ms, copies 4.1 ms (98 % of copy time is thin), chains of short commands 7.2 ms.

This also explains a pattern we kept seeing: removing one kind of work saves less than its share of the per-command cost, because the thin time is spread over all commands rather than owned by any one of them.

2. Geometry: the wrapped vertex programs are held by output space, not by their code

Bench (no game; the same captured meshlets of one foliage program with 9 outputs, 600 and 900 groups, warm caches), µs per meshlet:

path µs
mesh as translated 1.12 / 0.77
same, with the title's real pixel program 0.80 / 0.54
same meshlets as indexed VS draws (index buffer built once per block) 0.22 / 0.22
mesh, outputs cut to position only (wrong picture, for measuring) 0.34 / 0.20

Cutting only the outputs gives most of the gain, so the limit is output space, not the shader body.

Nsight on the same bench, VTG warps resident per SM: mesh 1.4, VS 7.0–7.4, position-only mesh 5.5. The output buffer (ISBE) is near full in all three: the mesh warps finish early, and their outputs hold the buffer until rasterization takes them. Low occupancy is the consequence, not the cause.

This would also explain why LEONIDA_MESH_COUNTS gained nothing (d183/d184): the reservation follows the declared output size × the maxima, not the counts.

In game, moving two programs (≈7.4 % of sampled time) to the VS path gave −0.9 ± 0.6 ms of GPU busy (same-run A/B, 95 %). With the real pixel program, the bench predicts 1.4–1.75 ms. A build with ten such programs is waiting for a timing run.

3. What would help

  • The thin/thick split on other cards (resident warps per SM from GPU Trace samples, bucketed by a threshold), to see whether this holds beyond one NVIDIA card.
  • Timing #2580's path forced on (LEONIDA_MESH_COMPUTE=1) on an NVIDIA card. It ends in an ordinary VS draw, so it may show the same gain.

Caveats: one card, one frame; bench numbers are per meshlet on warm caches, not frame time; draws that pick their meshlets from a per-draw table (about a third of the share) are not covered yet. We do not claim that thin time equals the translation's cost against native: our frame is lighter than the console's, so that comparison needs a matched workload first.

**@⁠plapha** on GitHub · 2026-12-02 16:56 UTC · [original](https://github.com/ProjectLeonida/mandy/issues/3180) findings.md already notes that the card waits inside its work. We tried to put numbers on it and found one mechanism behind it. Setup: RTX 5060 8 GB, a foxhound/VIctory-based build (the translator differs from mandy's, but the title's wrapped programs are the same). The frame is a light one: 960×540 internal, ray tracing skipped, so it does less work than the console's 720p frame. ### 1. Thin and thick time (one captured frame, hardware samples every 4.8 µs) Sampled command time is 34.06 ms. We split it by resident warps per SM (mesh + vertex + pixel + compute): | | time | share of warp × time | |---|---|---| | thick (≥ 4 warps/SM) | 12.27 ms | 92.3 % | | thin (< 4 warps/SM) | 21.79 ms | 7.7 % | With the threshold at 2 or 8 instead of 4, thin time stays at 18–24 ms. The clocks stay up (median 2785 MHz) and the card draws about 50 W of its 145 W. Of the warps that are resident, 10 % issue and 46 % wait on memory. Thin time by layer: geometry 10.5 ms, copies 4.1 ms (98 % of copy time is thin), chains of short commands 7.2 ms. This also explains a pattern we kept seeing: removing one kind of work saves less than its share of the per-command cost, because the thin time is spread over all commands rather than owned by any one of them. ### 2. Geometry: the wrapped vertex programs are held by output space, not by their code Bench (no game; the same captured meshlets of one foliage program with 9 outputs, 600 and 900 groups, warm caches), µs per meshlet: | path | µs | |---|---| | mesh as translated | 1.12 / 0.77 | | same, with the title's real pixel program | 0.80 / 0.54 | | same meshlets as indexed VS draws (index buffer built once per block) | 0.22 / 0.22 | | mesh, outputs cut to position only (wrong picture, for measuring) | 0.34 / 0.20 | Cutting only the outputs gives most of the gain, so the limit is output space, not the shader body. Nsight on the same bench, VTG warps resident per SM: mesh 1.4, VS 7.0–7.4, position-only mesh 5.5. The output buffer (ISBE) is near full in all three: the mesh warps finish early, and their outputs hold the buffer until rasterization takes them. Low occupancy is the consequence, not the cause. This would also explain why `LEONIDA_MESH_COUNTS` gained nothing (d183/d184): the reservation follows the declared output size × the maxima, not the counts. In game, moving two programs (≈7.4 % of sampled time) to the VS path gave −0.9 ± 0.6 ms of GPU busy (same-run A/B, 95 %). With the real pixel program, the bench predicts 1.4–1.75 ms. A build with ten such programs is waiting for a timing run. ### 3. What would help - The thin/thick split on other cards (resident warps per SM from GPU Trace samples, bucketed by a threshold), to see whether this holds beyond one NVIDIA card. - Timing #2580's path forced on (`LEONIDA_MESH_COMPUTE=1`) on an NVIDIA card. It ends in an ordinary VS draw, so it may show the same gain. Caveats: one card, one frame; bench numbers are per meshlet on warm caches, not frame time; draws that pick their meshlets from a per-draw table (about a third of the share) are not covered yet. We do not claim that thin time equals the translation's cost against native: our frame is lighter than the console's, so that comparison needs a matched workload first.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 18:29:20 +00:00
Author
Owner

@⁠Default0009 on GitHub · 2026-12-03 00:06 UTC · original

Card: RTX 2070 Super 8 GB (Turing, no mesh shaders), Windows, 32 GB DDR4. Build: PR #3128 head (32039d441, main merged in), diag profile with diagnostics,mimalloc.

What I timed: the item in section 3 of the issue, LEONIDA_MESH_COMPUTE=1 forced on, against the default (=0). Same save, same standing spot, about 3 minutes in the world per run, run in the order A B B A. The first A was a throwaway warm-up. The switch is read once at device creation, so this is separate runs, not LEONIDA_AB. The settings line and mesh programs run as compute: true ... forced=true confirm which path each run used.

MEASURED (n = 2 runs per side, plus 1 warm-up). Windows of the leonida_gpu::host fps line with at least 200 draws a frame:

run LEONIDA_MESH_COMPUTE windows median ms/frame fps p10 / p90 ms
warm-up 0 33 90.3 11.1 81 / 127
2 1 17 158.7 6.3 144 / 195
3 1 18 168.2 5.9 145 / 193
4 0 13 87.8 11.4 78 / 858

Forcing the path on costs about 70–80 ms a frame (about 12 fps down to about 6). The two runs on each side differ by 2–10 ms, so the gap is far larger than the run-to-run spread. With two runs a side it is below the minimum abba takes, so there is no standard error.

Checks: in all B runs the log ends with 0 being made, so the pipelines were done and this is not warm-up. Draws dropped for lack of a host pipeline are the same on both sides (about 300 of about 6,500). Draws a frame are similar (5.9–7.1k on B, 6.4–6.7k on A). The frame's GPU time was 95 ms in the one B run I read it for.

READ IN CODE / ASSUMED: the cost looks like a compute pass plus a separate vertex draw for each of the 6k or more mesh draws, so the per-draw fixed cost swamps any output-space gain. I haven't profiled the compute path, so this is a guess.

What it means for the issue: on a card with no mesh shaders, the global switch is not a speed-up. The gain the issue measured came from moving a few heavy wrapped programs to the vertex path. That needs a per-program choice, not a switch for every program. Caveats: one card, one scene, a debug-info diag build, clocks not locked.

**@⁠Default0009** on GitHub · 2026-12-03 00:06 UTC · [original](https://github.com/ProjectLeonida/mandy/issues/3180#issuecomment-7362806300) Card: RTX 2070 Super 8 GB (Turing, no mesh shaders), Windows, 32 GB DDR4. Build: PR #3128 head (32039d441, main merged in), diag profile with diagnostics,mimalloc. What I timed: the item in section 3 of the issue, LEONIDA_MESH_COMPUTE=1 forced on, against the default (=0). Same save, same standing spot, about 3 minutes in the world per run, run in the order A B B A. The first A was a throwaway warm-up. The switch is read once at device creation, so this is separate runs, not LEONIDA_AB. The settings line and mesh programs run as compute: true ... forced=true confirm which path each run used. MEASURED (n = 2 runs per side, plus 1 warm-up). Windows of the leonida_gpu::host fps line with at least 200 draws a frame: | run | LEONIDA_MESH_COMPUTE | windows | median ms/frame | fps | p10 / p90 ms | |---------|----------------------|---------|-----------------|------|--------------| | warm-up | 0 | 33 | 90.3 | 11.1 | 81 / 127 | | 2 | 1 | 17 | 158.7 | 6.3 | 144 / 195 | | 3 | 1 | 18 | 168.2 | 5.9 | 145 / 193 | | 4 | 0 | 13 | 87.8 | 11.4 | 78 / 858 | Forcing the path on costs about 70–80 ms a frame (about 12 fps down to about 6). The two runs on each side differ by 2–10 ms, so the gap is far larger than the run-to-run spread. With two runs a side it is below the minimum abba takes, so there is no standard error. Checks: in all B runs the log ends with 0 being made, so the pipelines were done and this is not warm-up. Draws dropped for lack of a host pipeline are the same on both sides (about 300 of about 6,500). Draws a frame are similar (5.9–7.1k on B, 6.4–6.7k on A). The frame's GPU time was 95 ms in the one B run I read it for. READ IN CODE / ASSUMED: the cost looks like a compute pass plus a separate vertex draw for each of the 6k or more mesh draws, so the per-draw fixed cost swamps any output-space gain. I haven't profiled the compute path, so this is a guess. What it means for the issue: on a card with no mesh shaders, the global switch is not a speed-up. The gain the issue measured came from moving a few heavy wrapped programs to the vertex path. That needs a per-program choice, not a switch for every program. Caveats: one card, one scene, a debug-info diag build, clocks not locked.
Author
Owner

@⁠plapha on GitHub · 2026-12-03 00:26 UTC · original

Thanks for timing it. Two runs a side with a 2–10 ms spread against a 70–80 ms gap is clear.

You're right that #2580 was the wrong stand-in, and suggesting it was my mistake. It runs the whole mesh program as compute on every draw and then draws the result, so each draw pays twice. What we measured works differently:

  • the index buffer is built once per geometry block and cached (invalidated through the write watch), and each draw then goes straight through a VS form of the program, with no compute pass per draw;
  • it is opt-in per program (allowlist), and a per-draw gate keeps draws whose meshlet selection comes from a per-draw table on the mesh path.

So I agree with your conclusion: it has to be a per-program choice, not a global switch.

Patches and a write-up: https://gist.github.com/plapha/11dfa9c33d1af9ffbdabc71401770e32. They're against a VIctory-based tree, so they won't apply to mandy as-is; read them as a reference.

A small note: Turing does have mesh shaders (D3D12 tier 1), and your =0 runs were drawing through native mesh pipelines. That doesn't change your result, only the label.

A timing run with ten allowlisted programs is next; I'll post the frame numbers here.

**@⁠plapha** on GitHub · 2026-12-03 00:26 UTC · [original](https://github.com/ProjectLeonida/mandy/issues/3180#issuecomment-7363202307) Thanks for timing it. Two runs a side with a 2–10 ms spread against a 70–80 ms gap is clear. You're right that #2580 was the wrong stand-in, and suggesting it was my mistake. It runs the whole mesh program as compute on every draw and then draws the result, so each draw pays twice. What we measured works differently: - the index buffer is built **once per geometry block** and cached (invalidated through the write watch), and each draw then goes straight through a VS form of the program, with no compute pass per draw; - it is opt-in **per program** (allowlist), and a per-draw gate keeps draws whose meshlet selection comes from a per-draw table on the mesh path. So I agree with your conclusion: it has to be a per-program choice, not a global switch. Patches and a write-up: https://gist.github.com/plapha/11dfa9c33d1af9ffbdabc71401770e32. They're against a VIctory-based tree, so they won't apply to mandy as-is; read them as a reference. A small note: Turing does have mesh shaders (D3D12 tier 1), and your `=0` runs were drawing through native mesh pipelines. That doesn't change your result, only the label. A timing run with ten allowlisted programs is next; I'll post the frame numbers here.
Author
Owner

@⁠MoonEyes on GitHub · 2026-12-03 16:26 UTC · original

This was generated by AI during triage.

Triage Notes

What we've established so far:

  • The issue reports a measured low-occupancy/mesh-output bottleneck and a warm-cache benchmark where indexed VS draws were faster for one captured workload.
  • The attempted LEONIDA_MESH_COMPUTE=1 test on an RTX 2070 is not an equivalent validation: the reporter confirms it runs a compute pass on every draw, unlike the proposed cached index-buffer and per-program allowlist approach.
  • The reporter says a ten-program allowlist timing run is next; no such result is posted yet.

What we still need from you (@⁠plapha):

  • Please post the planned in-game A/B for the ten allowlisted programs, with the exact build/switches and comparable frame-time measurements. That result will show whether the benchmark finding translates into a viable runtime optimization.
**@⁠MoonEyes** on GitHub · 2026-12-03 16:26 UTC · [original](https://github.com/ProjectLeonida/mandy/issues/3180#issuecomment-7384840038) > *This was generated by AI during triage.* ## Triage Notes **What we've established so far:** - The issue reports a measured low-occupancy/mesh-output bottleneck and a warm-cache benchmark where indexed VS draws were faster for one captured workload. - The attempted `LEONIDA_MESH_COMPUTE=1` test on an RTX 2070 is not an equivalent validation: the reporter confirms it runs a compute pass on every draw, unlike the proposed cached index-buffer and per-program allowlist approach. - The reporter says a ten-program allowlist timing run is next; no such result is posted yet. **What we still need from you (@⁠plapha):** - Please post the planned in-game A/B for the ten allowlisted programs, with the exact build/switches and comparable frame-time measurements. That result will show whether the benchmark finding translates into a viable runtime optimization.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/ubiquitarianism--leonida#3180
No description provided.