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
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Reference
No Branch/Tag specified
Notifications
3 participants
Due date
No due date set.
Reference
leonida/mandy#3180
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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):
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:
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_COUNTSgained 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
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.
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:
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.
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:
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
=0runs 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.
Triage Notes
What we've established so far:
LEONIDA_MESH_COMPUTE=1test 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.What we still need from you (@plapha):
Closing note from our side.
We are not going to run the ten-program in-game A/B, and we are not turning X5 into a pull request. Since posting this we mapped the whole frame's dependency graph (RTX 5060, 540p capture). The GPU time is spread over the G-buffer, shadow and lighting stages, and moving geometry alone from mesh to VS only kept about a third to six tenths of its bench gain in game. We are moving to replacing the G-buffer stage as a whole on a PC path (equal outputs for the passes after it), which covers the geometry part, so a separate allowlist run would not change our next step. We will open a separate issue for that and link it here.
What stays here for anyone who wants it:
On #3371, which quotes the 70–80 ms from this thread: that number is the #2580 / #3128 path (a compute pass on every draw, then a pass-through VS), not ours. Ours builds the index buffer once per geometry block, caches it, and draws straight through a VS form of the program. It could be a starting point for cards without mesh shaders, with two limits: it is enabled per program (draws that pick meshlets from a per-draw table stay on the mesh path, so it is not a complete fallback), and it was only measured on an RTX 5060.
Maintainers, please close this issue; there is nothing left that needs an answer from us.
Read-only audit of the evidence and of mandy's paths (no game run, no build). The mechanism is plausible and the number that matters is 64 % of sampled time, not 92.3 %.
Arithmetic correction. 12.27 ms thick / 21.79 ms thin of 34.06 ms is 36 % thick / 64 % thin by time. The 92.3 / 7.7 column is warp x time, not time. The thin time is robust to the 2/4/8 threshold. That still makes thin the majority of sampled time, but the occupancy-weighted share is small.
Why the native path is thin. The title declares 128 vertices / 128 primitives (
native.rs:856-870), and the D3D12 output footprint is computed from those maxima and the output signature (emit/container.rs:132-147,emit/lower.rs:6947-6971). The runtime lowers maxima only when they exceed 32 KiB, and only to the lane count.LEONIDA_MESH_COUNTSchanges the runtimeSetMeshOutputCounts, not the declaration the reservation follows, which matches the repo's own measurement that it made the frame worse (docs/findings.md:1777-1782). Cutting outputs to position-only raising occupancy 1.4 -> 5.5 warps/SM is the strongest evidence that output bytes, not the shader body, set occupancy.What mandy does not have: an indexed-VS path.
mainhas native mesh and the compute fallback only. The fallback drawsmax_primitives * 3vertices per group after a compute pass per draw (mesh_fallback.rs:71), which is why the RTX 2070LEONIDA_MESH_COMPUTE=1result (70-80 ms slower) is not a test of the X5 idea. The runtime cannot merge meshlets, lower the per-group native reservation, change the output signature, or use the per-draw-table draws through a block index; the only runtime-owned lever is a per-program VS form with the X5 eligibility restrictions and a per-draw gate.Probe I would add first:
mesh.output_fill- used vs reserved output bytes per group (v*vertex_stride + p*primitive_strideovergroup_bytes), reported per program with a(v,p)histogram (0, 1-8, 9-32, 33-64, 65-128, >128) and fill p10/p50/p90. It turns the hardware inference into a title-data measurement, separates 'few groups, big meshlets' from 'many groups, tiny meshlets', and predicts the indexed-VS ceiling (1 - fill). The counts come from the group header's M0, whichLEONIDA_MESH_COUNTSalready locates (emit/mesh_counts.rs); on the native path without that switch every group reports the declared maxima, so the header is the only honest source.The smallest device-free predicate is a pure
mesh_out_fill(layout, v, p)plusindexed_vs_eligible(threads, layout, facts)(<=128 threads/verts/prims, no per-primitive outputs, no LDS/barriers/writes, only first-lane cross-lane reads), unit-testable withMeshOutfixtures. It is necessary, not sufficient - it does not prove cheaper.Still missing for the frame-time claim: the ten-program in-game A/B the reporter declined, the actual meshlet histogram, the share of draws that use a per-draw table (one third, per the issue), and cross-card thin/thick. Unproven: that D3D12 reserves by declared maxima (the issue gives no driver citation), that the title's meshlets are tiny, and the 'ISBE near full in all three' sentence, which is inconsistent with the indexed-VS case if ISBE is the mesh-output store.