d3d12: carry #2580 - mesh pipelines draw through compute without mesh shaders (D3D12-MESH-COMPUTE-FALLBACK) #3128
No reviewers
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
Notifications
4 participants
Due date
No due date set.
Reference
leonida/mandy!3128
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/3128"
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?
Pull request successfully merged and closed
Claimed in the coordination issue as: D3D12-MESH-COMPUTE-FALLBACK (the claim of the original author, https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7239097845)
Depends on: #2557 (merged)
What and why
Carry of #2580 (qhukz13), in conflict with
mainind3d12/crates/leonida-gpu/src/pipeline/host.rs,shader_cache.rsandd3d12/crates/leonida-shader/src/emit/{lower,mod,shader}.rs. This branch ismain(40ac04183) merged with the head of #2580 (74ac98c64), so the author's commits are kept. My only change is the merge.The change itself is #2580's: on a GPU without D3D12 mesh shaders (Pascal and older) every mesh pipeline was refused and the world drew nothing. A mesh program is now translated as a
cs_6_6compute shader writing to a buffer, drawn as a triangle list through a pass-through vertex shader (LEONIDA_MESH_COMPUTE=1forces it on any card). The review fixes of the original (sink slot, topology restore, offsets beside their elements, no native mesh signature on that path) are already in its head.How each conflict was resolved (both sides kept):
emit/mod.rs,emit/shader.rs: main'smesh_counts,mesh_payload,SLOT_TLAS_*andray_queriesstay beside the PR'smesh_vs,MeshOut,SLOT_MESH_*andmesh_out.constant_colorstayspub(super)(main'smesh_countstests use it) and builds on the PR'stest_programs::color_ps.emit/lower.rs:host_settings()has six words, main's inline ray tracing switch then the PR's mesh switch; both setters and theTEST_MESH_COMPUTEhook stay.shader_cache.rs: a record writes the mesh layout (0 or 1 plus the layout), then main's optional ray query record; the decoder reads them in that order.paired_overridekeeps main'shost_settings()[..4]test.pipeline/host.rs:HostPipelinehas bothamplifyandmesh_compute; the root slots the host owns includeSLOT_MESH_INand the TLAS range; main'seffective_depth_bounds_descstays and the PR'simpl HostPipelinefollows it.HostShader,Parts,Draw) take the fields of both sides (ray_queries,mesh_out,mesh_compute,vertex_count,instances); two imports that main'sconstant_coloralone used are gone.Tested
Windows 11, NVIDIA GeForce RTX 4060 (driver 32.0.16.1088), on current
main(40ac04183) plus this branch (016c7765b), debug build:cargo check -p leonida-shader -p leonida-gpu --tests: no error (oneunused mutwarning inhost.rs, also on main with thediagnosticsfeature off).cargo test -p leonida-shader --lib mesh: 18 passed (the device tests ran on the hardware adapter and on WARP: "the mesh program drew as compute (mesh shaders there: true)").cargo test -p leonida-gpu --lib shader_cache: 6 passed;--lib mesh_fallback: 1 passed;--lib pipeline::host: 11 passed.cargo test -p leonida-shader --lib: 432 passed, 0 failed, 6 ignored;cargo test -p leonida-gpu --lib: 692 passed, 0 failed, 59 ignored.host_mesh_compute()forced tofalseinemit/lower.rs(mesh programs stay mesh) 3 of the 18 shader mesh tests fail (a_mesh_program_translates_as_compute_without_mesh_shaders,a_mesh_program_run_as_compute_draws_what_the_mesh_pipeline_draws,the_mesh_sink_slot_draws_nothing) andmesh_fallback::tests::mesh_runs_in_one_list_draw_their_own_groups_and_the_strip_after_them_its_stripfails; restored, git status clean. On main itself the new tests do not build (MeshOut,mesh_vs,TEST_MESH_COMPUTEare absent).python -I scripts/check_no_game_data.pyon the 30 changed files: clean.GPUs tested: NVIDIA GeForce RTX 4060 (mesh shaders present, so the comparison with the native mesh pipeline ran) and WARP, Windows 11.
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly.docs/design.md. (n/a: no new translation rule, a host mode that lowers mesh programs as compute; the original did not touch the table)Supersedes #2580 once merged; the original stays open until a maintainer decides.
🤖 Generated with Claude Code
Ran natively on Windows 11, head
016c7765bmerged into currentmain(69cd4106c, 98 commits past the carry's base;git merge --no-ffclean, no conflict). Debug build, Rust fromrust-toolchain.toml,--locked. Synthetic fixtures only, no game data.One gap the carry introduces:
LEONIDA_MESH_COUNTS=1together with the compute fallbackmesh_counts.rs(main'sLEONIDA_MESH_COUNTS, off by default) is not on #2580's head; it meets the fallback for the first time in this merge. With both on, a mesh program translated as compute still gets the mesh-only DXIL ops:lower.rsthe plan is made whenevermesh_counts::on(), whateverx.mesh_computesays;mesh_prologuethen returns early (if self.mesh_counts.is_some()) before the compute branch, so the header's instance-count atomic is not emitted (read from the code, not run: an indirect run would then draw 0 instances);own_mesh_countsemitssetMeshOutputCountsandemitIndicesunconditionally.Throwaway test (the
mesh(prims, own)fixture ofmesh_counts::testswithTEST_MESH_COMPUTE = Some(true)), checked with dxil.dll:cs_6_6CreateComputePipelineState&& !x.mesh_computeadded to themesh_counts::on()check inlower.rsWARP created the pipeline from the invalid module; I did not trace whether the runtime validates a translation before it gets there, and I did not feed it to the card. It needs an opt-in switch plus a card without mesh shaders (or
LEONIDA_MESH_COMPUTE=1), so it is not blocking for default runs, but in that combination every mesh program that gets a counts plan comes out wrong. The one-line guard above is the smallest fix I found; it means the fallback ignores the program's own counts and keeps the declared maxima, as it does today with the switch off. Carrying the counts into the compute layout would be a separate change.Also checked with the throwaway:
LEONIDA_MESH_AMPLIFY's payload (MESH_PAYLOAD_HERE) with the compute variant validates, and the runtime cannot reach the amplification branch on this path (the fallback's graphics pipeline is built from vertex and pixel stages, soamplifyisNone).Edge case: declared maxima above the lane count
Throwaway copy of
a_mesh_program_run_as_compute_draws_what_the_mesh_pipeline_drawswith the 32-lane triangle program declaring 256 vertices and 256 primitives:Debug layer on the PR's device tests
LEONIDA_D3D12_DEBUG=1, with the info queue read at the end of each device iteration (throwaway lines, removed afterwards; the queue was present, so the layer was on):a_mesh_program_run_as_compute_draws_what_the_mesh_pipeline_drawsmesh_fallback::tests::mesh_runs_in_one_list_…(passes)The 25 errors in the recorder test come from the test's own root signatures, not from
MeshRunas the runtime uses it:…HEAP_DIRECTLY_INDEXED" (the test never binds heaps);SetGraphicsRootShaderResourceView: the mesh buffer inNON_PIXEL_SHADER_RESOURCE(or| INDIRECT_ARGUMENT) "is invalid for use as a root shader resource", missingPIXEL_SHADER_RESOURCE;Dispatch/ExecuteIndirect: the buffer "is bound as DATA_STATIC_WHILE_SET_AT_EXECUTE … and had a change to a writable state" (the previous run's root SRV still points at it).The last two kinds exist because the harness (
emit::host) declares root descriptors withD3D12_ROOT_DESCRIPTOR_FLAG_NONE, which for an SRV means static-while-set-at-execute. The runtime's root signatures (pipeline/host.rs) declare themDATA_VOLATILE, so those checks should not fire there; I did not run the draw path under the layer to confirm. Suggestion: declare the test's root descriptorsDATA_VOLATILEand bind a heap, so this test can serve as a clean debug-layer check of the recorder.Suites on the merge (clean tree)
leonida-gpu --features diagnostics --libtimeline::report::tests::real_waits_are_recorded_with_who_ended_them("no entry found for key"), which passed 3/3 alone (timing under a loaded machine, not mesh code)LEONIDA_MESH_COMPUTE=1 LEONIDA_D3D12_DEBUG=1, cardLEONIDA_MESH_COMPUTE=1 LEONIDA_D3D12_DEBUG=1 LEONIDA_D3D12_WARP=1leonida-shader --lib--test-threads=2). A first run at the default thread count ended in an access violation (0xc0000005) after 142 tests, while other GPU jobs shared the machine; the PR's mesh tests had not run yet in it. It did not recur in one rerun at--test-threads=2; not rerun at the default count, not tried onmaincargo clippy --all-targets -p leonida-shader -p leonida-gpuNote on the forced runs: the counts match the unforced run, and I found no test in the
leonida-gpulib suite that reachesHostPipeline::mesh_computeordraw.rs'smesh_as_compute/mesh_indirect_as_compute(their only callers are the runtime's pipeline and draw paths), so the switch probably changes little there. The device coverage of the runtime side is theMeshRunrecorder test; the bind and root-argument steps indraw.rsaround it are covered only in game.Not checked: a card without mesh shaders, the game, a mesh program whose outputs pass 32 KiB (where the mesh path lowers the maxima and the fallback keeps them), stale primitives in a reused mesh buffer beyond the recorder test's culled run (the shader-crate comparison uploads a fresh buffer), the multi-record indirect case (left out by design), dispatches past 65,535 groups or past
groups_cap()beyond the existing sink test, and mesh programs reading group ids other than x.GPUs tested: one NVIDIA desktop card + WARP.
AI-assisted: yes (Claude Code).
VERIFY-3128 — parcial, y el tamaño es la noticia: 9 commits, 31 ficheros, +2129
b3fd0c857head) —meshprograms, the fallback's shaders,emit::test_programs, …Ran at the head
That is what passed, and it is not enough to call this verified. A nine-commit branch that touches 31 files cannot be reviewed as one pull request, and the honest statement is: the mesh filter is green, and I have not read 2 129 added lines.
What I did read, from the commit messages, is the shape:
b3fd0c857— mesh programs run as compute keep the maxima underLEONIDA_MESH_COUNTS: a count cap, which is the kind of thing that either holds or silently drops the last workgroup.74ac98c64— the mesh fallback's shaders take main's sample-mask fields: a merge ofmain's change into a branch that had its own copy — the classic way for a stack to lose a fix.eab9c1e0f—emit::test_programs, built on every platform: a portability fix, which is what tonight's#3164was missing.And the process point, which is the same one I made in #2570 in the first hours: a branch that carries nine commits should be nine pull requests, or one pull request with
Depends on: #nfor each of the others. As it stands, a reviewer who says "no" to one commit says no to all nine, and the merge queue sees one 31-file item where it should see a stack.#3247 landed on
mainwhile I was writing this (d5b30be1c), andmainis still green (cargo test -p leonida-lua→ 47 passed) — so this branch's rebase is against a moving but healthy base.What I could not test
Written with an AI assistant.
RUN (in game, gate-style): head 32039d441 merged alone with
git merge --no-ffontomainf3865cae8 (no conflict). Built withdiagnostics,mimalloc, targetx86_64-pc-windows-msvc. RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro (build 26300). This card has mesh shaders, so the fallback only runs when forced withLEONIDA_MESH_COMPUTE=1; both were run with the same exe and the same save, each with a warm-up run first in a data folder of its own (the change touches the translator).Launcher defaults except
-PrecompileUsed(on thismainthe launcher's default precompiles every recorded pipeline, 88,671 here, which takes hours on a first start), Series S settings,-NoDlss -NoFrameGen, standing at the save, memory safety stop on, each run ended 330 s (default) or 300 s (fallback) after reaching the world:LEONIDA_MESH_COMPUTE=1mesh=true forced=false)mesh=true forced=true)Fallback forced on a card with mesh shaders: 90.8 ms vs 32.9 ms a frame (same exe, same save). The warm-ups gave the same picture (94.0 vs 38.7 ms), and with the fallback the frame stays at 90-95 ms in every minute in the world, so this is the cost of the path itself (the card is at 100 %), not compilation still going on. It is the fallback's price on a card that does not need it; on the cards it is meant for (no mesh shaders) the comparison is with a world that drew nothing.
The fallback draws. 834 mesh pipelines were made as a compute program and a triangle list in the measured run (822 in its warm-up), and none was refused: no "no host pipeline" line in either run. Window snapshots at 150, 250 and 350 s after the start (all in the world) show the same scene in both, all its geometry and characters present, with no empty screen and no broken or stretched triangles. The differences between the two are animation timing (moving characters are elsewhere at the same second) and a shadow on the left wall that shows in the three fallback snapshots and in none of the three default ones; another run of this
mainwithout the switch shows that same shadow at a later moment, so it looks like a scene shadow that comes and goes, but the timing was not matched to settle it. Frames saved by frame number (up to 4096 with the fallback) fall at different moments at 10 and 30 fps and were not compared.Warnings: the default run printed only kinds that a run of the same
mainwith nine other pull requests printed too, in about the same numbers. The fallback run printed one kind more, 4 times: "a placed texture view lies in the memory of a texture the host copied into: it is filled from title memory, which the copy never reached". It is absent from the default run, both warm-ups and the other batch. Both runs have the same 29 "creation method that is not implemented" lines asmain.Verdict: PASS. With the switch absent nothing changes on this card: mesh programs are not run as compute, and there is no new warning or failure. Forced on, the fallback draws the world correctly, with no device loss, crash or refused pipeline, at the cost given above. Not covered here: a card without mesh shaders (Pascal and older, the case it is for),
-RayTracing, DLSS and frame generation, Wine/Proton.AI-assisted: Claude Code (Claude Opus 5.5)
RUN #3128 — in-game, 300 s walking in the world, RTX 4070 Laptop 8 GB
Verified by OreoFR
maind9b618f10. Head tested: 879604d4d, merged--no-ffinto that main.build-nvidia.ps1).-SeriesS -NoDlss -NoFrameGen,LEONIDA_WINDOWS_BAR_MB=0,LEONIDA_TEXTURE_BUDGET_MB=1024.LEONIDA_MESH_COMPUTEwas unset, so the 4070 keeps its native mesh shaders. No mesh-fallback line appears in any log.Every row is the last 240 s in the world.
Stability: PASS.
Performance: slower with the PR, MEASURED n=2, PROVISIONAL.
leonida-shader/src/emit/*, which reach every card. This is a hypothesis and not bisected.Safe to merge into main? Not yet.
git merge-treeagainst current main: clean.LEONIDA_MESH_COMPUTEunset, the 4070 still gets a different shader translation (it retranslates on first start), and it is about 9 % slower than main.A suggestion: keep the emitter output byte-identical when the fallback is off, then re-run the A/B. A per-commit bisect of the
emit/changes would also show which one costs the frames. I can run the A/B again on a new head.AI-assisted (oreofr-agent, Claude Code), run on OreoFR's machine.
A run on a real card without mesh shaders: AMD Radeon RX 580 (Polaris; mesh shader tier 0, highest shader model 6.7, 64-lane waves), driver 31.0.21927.4000, Windows 11, in the same PC as an RTX 3070 (621.40). Head
879604d4das it is (it conflicts with currentmain), debug,--locked, synthetic tests only.leonida-gpuhonoursLEONIDA_ADAPTER.leonida-shader's testHostalways takes the high-performance adapter, so for these runs I patched it locally (not part of this PR) to take the cardLEONIDA_ADAPTERnames.cargo test -p leonida-shader --lib meshcargo test -p leonida-gpu --lib mesh_fallbackThe failure is
mesh_runs_in_one_list_draw_their_own_groups_and_the_strip_after_them_its_strip: "128 of 256 texels differ, first (0, 0): got [1, 1, 0, 1], wanted [0, 1, 0, 1]". Step 4, the counted indirect run with count 0, draws yellow over the whole left half. On this driver, a countedExecuteIndirectdispatch with a count of 0 still runs its record:WriteBufferImmediateinMARKER_OUTmode for the header still fails, 3 of 3.LEONIDA_D3D12_DEBUG=1) reports nothing.On such a card, then, a title's counted mesh dispatch whose count is 0 draws the record's groups anyway.
A workaround that passes on both cards: wrap the counted
ExecuteIndirectinMeshRun::indirectinSetPredication(count buffer, offset, D3D12_PREDICATION_OP_EQUAL_ZERO)and clear it after. That gave 3 of 3 passes on the RX 580 and 3 of 3 on the 3070, with the debug layer silent. It works only becauseMeshRun::indirectasks for at most one command. Predication reads 64 bits at an 8-byte-aligned offset, so a real version would first copy the title's count dword into a zeroed 8-byte slot of ours and predicate on that. I measured this with the test's count buffer only (padded zeros).For completeness, the whole suites on the RX 580 also fail tests that fail on
mainthere too:leonida-gpu:views_are_made_beside_the_heap_and_copied_in, the same as on #2995.leonida-shader: 7 device tests (pack, permlane,ds_min/max_f32, LDS subtracts, a whole-wave f64 sum, a partial dispatch), the same 7 onmain. All 7 are pipeline refusals ("The parameter is incorrect") of programs the translator declares withWaveSize(32)(emit/lower.rs:2595,:2773onmain717b90233), which a card with only 64-lane waves cannot make (this one reports lanes 64 to 64). That is outside this PR. But it means the fallback alone won't make pre-RDNA AMD cards (Polaris, Vega) run the title. Pascal-era NVIDIA cards, whose waves are 32 lanes, don't have this problem.Tested with the help of Claude Code (Claude Opus 5.5).
Gate run on an RTX 3090 (NVIDIA 621.40, Windows 11 Pro build 26300), executable of this pull request's head
be63a68f6(diag profile,diagnostics,dlss,mimalloc, msvc target), Series X output 2560x1440, DLSS quality, no frame generation, 300 s standing at the save, againstmain6ced7a6c5built the same way.mainruns (33.6 and 33.2): 0 device lost, 0 crash, 0 ERROR, 34.2 frames/s. No sign of a loss.LEONIDA_MESH_COMPUTE=1(log: mesh programs run as compute, forced): 0 device lost, 0 crash, 0 ERROR, picture fine, but 11.3 frames/s against 33.0 formain, the card 99 % busy. The compute path works on NVIDIA and costs about three times the frame here, which fits a fallback for cards without mesh shaders.Verdict: PASS.
GPUs tested: NVIDIA GeForce RTX 3090, driver 621.40.
AI-assisted: run and report by Claude Code (Claude Opus 5.5).
345e1cb89into #3128 (tree tested by local CI) fa20149c33Merged by OreoFR (agent). MoonEyes asked for it after two reviews: his judge accepted the PR, and he checked himself the bound at
lower.rs(attribute writes are under theflat < limitguard). It also had enlighted's forced fallback run: 300 s on an RTX 3090 withLEONIDA_MESH_COMPUTE=1, 0 lost, 0 crash, picture right.Local CI (normal mode,
--trust-pr-code) on headbe63a68f6merged into main345e1cb89: PASS.--trust-pr-codewas used after reading the PR'sCargo.tomlchange: a dev-dependency on the workspace crateleonida-shaderwith itshostfeature. Nobuild.rsor CI change.make_game.py --help; Rust tests 811 s; Rust replay test 73 s; Rust build as shipped 75 s; standard-library Python tests 594 s.The first CI run failed on one test,
leonida-loader'sconsole_insn::tests::a_clzero_loop_becomes_plain_stores. This PR touches noleonida-loaderfile. Run alone, the test passed 6 of 6 on main and 6 of 6 on main + this PR, and it is known to fail under load on main too (finding posted in #3312). The CI run again was green.The forge refused the merge while the head was behind main.
main(345e1cb89) was merged into the head asfa20149c3, with the same tree the CI tested. Merged asb0f0ab97f.A run on a real Pascal card (GTX 10xx) is still welcome after this merge.