startup: translate slot 57 mesh requests of one group-memory shape #2439
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2447"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T17:00:36Z.
Refs #2413
Refs #1760
Stacked on the
s_waitcnt_depctrchange (branchstartup/gfx2hlsl-waitcnt-depctr): the accepted shape contains that wait. Merge that one first; this branch then holds one commit.What changes
tools/startup/gfx2hlsl.pytranslates a slot 57 mesh request when the mesh program has exactly this shape, and refuses every other program with the first difference:exec = 1(lane 0 of each wave), the mask saved in an SGPR pair. Wave 0 (s3bits 24..27 zero) stores entryv5 >> 7at group-memory byte 8, waits (s_waitcnt_depctr 0xffe3) and passes a barrier; every other wave passes a barrier and reads byte 8.GS_ALLOC_REQwithm0 = P << 12 | Vbuilt from those two registers. Every other wave passes a barrier and reads both words back into the same P and V.s_endpgm. Exports only here:pos0andparamunderexec = -1narrowed by onev_cmpx_gt_i32 V, thread, the primitive export under the same with P.threadis thev_mbcntpair overwave << 6.mesh_skeletonproves the shape before any code is emitted: the instruction sequence of both exchanges, the six group-memory accesses at their literal addresses and in order, every branch target, the registers not overlapping, one request, one writer. Each path passes three barriers and each store has one writer lane, with a wait and a barrier before every read. The walk over the code outside the exchanges refuses, each with its own message: a branch, a group-memory access, barrier or request, a lane spill, a write tos3, to the saved mask or (after the exchange) to P or V, a use ofm0or of the exchange's SCC, an EXEC or VCC use as a wave mask other than the two forms above, a read of a VGPR the two arms leave different or that still holds an entry value, a read of an entry SGPR the root does not define, a read ofs3other than its wave index, a vector compare into an SGPR, an export before the exchange or under the wrong count, a missing or secondpos0or primitive export. A loop is a branch outside the exchanges, so no access, barrier or export can sit in one.The lowering keeps one writer and one barrier:
P and V are run-time values. The stage is
[numthreads(128, 1, 1)]with 128 vertices and 128 triangles declared, the D3D12 limit for the thread count of a mesh shader and the two wave64 waves of a group.Run-time clamps, which the source program does not have:
twrites vertextand primitivet, so a larger count names outputs no thread writes.V - 1, and no primitive is published without a vertex. An index at or past the vertex count has no defined vertex.The first exchange (the group index word) is not emitted: its result is refused when used as a number, because what
v5holds at entry is not verified.Handlers shared with other stages:
exporthands a mesh stage tomesh_exportat its top,op_v_mbcnt_lo_u32_b32has a mesh branch,setup_entrya mesh case, andPipelinetakes the kind of its vertex-producing stage from a class attribute. Vertex, pixel and compute stages take the same paths as before.translate_requestwrites<key>.ms57.hlsl,<key>.ps57.hlsl, theirms_6_5andps_6_0bytecode (.ms57.cso,.ps57.cso) and<key>.ms57.txtlast. No runtime path loads these names, so a draw still does not use them. A refusal publishes only<key>.fail, as before.Tests
tests/startup_mesh57_skeleton.sis a source-built program with the shape and a trivial body: counts from two root constants, positions and one parameter from a raw buffer, packed indices from the same buffer.Result:
startup_mesh57_skeletonpassed,startup_mesh57_skeleton_draw_warppassed,startup_mesh57_skeleton_draw_hardwarepassed, no skip.debug_errors=0 debug_warnings=0.debug_errors=0 debug_warnings=0.58a673cf(local, before any rebase).The draw mode sends the fixture through the request path, draws the compiled pair with
offscreen_check --mesh-indexedand compares the 32x32 read-back with a CPU rasteriser in the check (pixel centres, top-left rule, flat colour of the first vertex). Cases (vertices, primitives): (12, 4), (12, 1), (7, 4) where indices clamp, (0, 4) where nothing is drawn. All reportpixels=1024 mismatches=0.Negative controls:
pixels=1024 mismatches=1andDraw reference mismatch;.failpublished: a request built from another register, no barrier between the store and the reads, a store by every lane, no wait before the first barrier, a branch that leaves the exchange, a barrier after the exchange, a branch after the exchange, a position export under the primitive count, a read of a register the exchange leaves different per wave, a read of an entry VGPR, of an entry SGPR, and ofs3as a whole;Existing pure-Python checks of the touched handlers exit 0:
startup_gfx2hlsl_refusals_check,startup_translator_check,startup_gfx2hlsl_scalar_m0_check,startup_gfx2hlsl_compute_check,startup_compute_translate_check,startup_compute_lds_b64_check,startup_compute_request_offline_check,startup_gfx2hlsl_export_mask_check,startup_flat_param_check,startup_ngg_slice_check,startup_stream_fetch_check,startup_stream_interface_check.Measured on a local set of 298 slot 57 requests
0 of 298 translate. Both exchanges match in 281. First refusal per request:
s_cselect_b64on a wave maskOn the mesh program alone (pixel stage ignored): 244 branch, 37
s_cselect_b64, 16 group-index exchange, 1 count exchange.Not covered
s_cselect_b64on a wave mask, the variant that does not save the lane mask.pos1and other export targets, formatted loads in a mesh body.GroupMemoryBarrierWithGroupSyncagree outside this shape. The claim holds for this shape only: one writer, a barrier before every read.🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:32:04Z.
Review: COMMENTED
Review of head
58a673cf(code and tests only, comment review).Checked
s_waitcnt_depctr) is the same change as #2445, which is still OPEN. So this PR depends on #2445 and cannot land before it. The author states this in the body..github/workflows/windows.yml: only two test lines added in the Windows matrix and the Linux list. The PR's own CI run on this head shows "Build and test on Windows" and "Run platform-independent Python checks on Linux" green, so the added entries ran. I did not run the CI job myself.CMakeLists.txt: two newadd_testentries (offline check, plus adrawvariant per adapter withSKIP_RETURN_CODE 77). The pattern matchesmesh_pixel_pipeline_*.AGENTS.mdlist updated.Commands run (Linux, in a review worktree)
python3 -B tests/startup_gfx2hlsl_waitcnt_depctr_check.py: okpython3 -B tests/startup_mesh57_skeleton_check.py(nobinary/drawmode;llvm-mc-15and dxc are not installed here, so the embedded-words check and the draw check were NOT run by me): okpython3 -B tests/startup_gfx2hlsl_watch_check.py: passedpython3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD: cleanmin(lds[n], 128u)inop_x2w_mesh_countswith an unclamped form. The skeleton check FAILS with expected-vs-got lines. Reverted.tid == 0usingle-writer guard on theldsstore. The check FAILS. Reverted.Notes for the maintainer
drawmode (WARP/hardware readback). I did not run it, and I did not see a Windows result from the author posted on this head. The only evidence I can cite is the PR's CI run on this head.gfx2hlsl.pychange; I read the count-exchange lowering and sampled the refusal paths.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T18:40:38Z.
Review: CHANGES_REQUESTED
Review of commit
58a673cf. Thes_waitcnt_depctrcommit has since landed onmainas #2445, so I reviewed only the second commit. The shape proof is careful, and the tests and most mutants behave as described. Two P2s need addressing before merge.What I checked
mesh_skeleton, thex2w_mesh_*handlers,mesh_export, themsbranch ofv_mbcnt,MeshPipeline.hlsl_ms,translate_mesh57andpending_keys.x2w-startup-shader-14/14csare unchanged, and the vs, ps and cs paths emit the same text, since the new code is gated onkind == 'ms'. Before this change every slot 57 request produced only.fail, so no bump is needed.Findings
tools/startup/gfx2hlsl.py:4177).mesh_exportemitstris[tid] = min(uint3(w, w >> 10, w >> 20) & 1023u, ...)and draws every primitive whose thread passesP > thread.ac_nir_pack_ngg_prim_exp_argsets it for culled primitives.tools/mesh_entry_aot.py:856already refusespacked & 0xC0000000for that reason.pixels=1024 mismatches=66(exit 1) on both the AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010) and WARP 10.0.26100.9818, withdebug_errors=0. 66 is exactly that triangle's coverage.& 1023ufolds an edge flag into the index.511u, emit a degenerate or culled primitive when bit 31 is set, and add a draw case with the null bit set.mainin.github/workflows/windows.yml,AGENTS.mdandCMakeLists.txt, because the depctr lines are already there.tests/startup_gfx2hlsl_watch_check.py:111from #2421 (the null-export-only pixel stage) still expects'slot 57 mesh code emission is unavailable', and that string no longer exists here. The file auto-merges, so on a trial merge with both sides kept,startup_gfx2hlsl_watchfails withgot unsupported: slot 57 mesh group-index exchange: instruction 1 of the accepted shape (s_mov_b64) is absent.export target null, with only.failpublished. That is safe, but an explicit "depth-only slot 57 pair is not covered" refusal would read better, and the watch expectation needs updating either way.s_and_b32destination is not checked against the saved lane mask (kept atgfx2hlsl.py:1167; the overlap check at :1156–1160 doesn't include it). Changing fixture word8706ff03to8704ff03(s_and_b32 s4, s3, 0xf000000, which overwritess[4:5]) still translates, withif (tid == 0u) { lds[0] = s13; lds[1] = s14; }. On hardware, wave 0's saved mask would be 0. Please add that destination to the overlap check.v_mbcnt_hihalf and wave 1 aren't exercised. A mutant that sets the mbcnt-hi termmax(tid & 63u, 32u) - 32uto0upasses every test. A case with counts of 65 or more, mostly degenerate triangles with the visible ones at high slots, would cover it.Commands executed (Windows 11 build 26300, DXC from SDK 10.0.26100, llvm-mc 15.0.7, debug layer enabled)
startup_mesh57_skeleton_draw_*, cases (12,4), (12,1), (7,4), (0,4)mismatches=0mismatches=0startup_mesh57_skeleton,waitcnt_depctr,watch(at this head)binary(LLVM 15.0.7)okThere were no capability skips.
Negative control
gfx2hlsl.py, reverted after)FAIL draw of 7 vertices, 4 primitiveson both adaptersnot afterFAIL a position export under the primitive count: got 'ok'v_mbcnt_hiterm set to0uAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T18:31:05Z.
Five mutations on the refusal proofs: two caught, three survive — and one of those is a near-duplicate of a proof that is covered
Baseline on this branch at
58a673cf:startup_mesh57_skeleton_check.py→ok,startup_gfx2hlsl_waitcnt_depctr_check.py→ the five-immediate/three-refusal summary, both exit 0.mesh_skeletonslot 57 mesh %s: instruction %d of the accepted shape (%s) is absentslot 57 mesh %s: a branch leaves the accepted shapeslot 57 mesh program does not end with s_endpgmslot 57 mesh count exchange: registers of the accepted shape overlapslot 57 mesh count exchange: the compared register is not the wave indexThe third survivor is the one I would look at first: there are two proofs about the wave index and only one is exercised
The fixture pins
slot 57 mesh: s3 is read other than as the wave index(its line 108, a mutated instruction word). The code has a second, similarly-named proof with a different message —slot 57 mesh count exchange: the compared register is not the wave index— and removing that one changes nothing in the fixture. So a reader scanning the refusal list sees "the wave index is checked", and it is, but not at that site; the two are distinguishable only by message text, which is exactly the kind of pair that drifts apart later.Concretely: either that proof is unreachable for every program the accepted shape can reach (then it is dead and should go, with the reason written down), or it guards a real input that has no case yet.
The other two survivors
does not end with s_endpgm: every fixture program ends withs_endpgm(line 41 shows it in the happy-path program), so no case omits it. A one-line fixture — the same program with the last instruction dropped — would pin it.registers of the accepted shape overlap: no fixture program reuses a register between the count and group-index exchanges, so the overlap proof is unexercised.Both are cheap to add and both are the kind of proof that is easy to delete later while "simplifying" the shape test.
What the two caught rows establish
The missing-instruction proof is exercised at four different instruction indices (15, 13, 4, 8 — the fixture asserts the exact index and mnemonic), and the branch proof is exercised too. Those are the two that decide whether a program "is" the accepted shape, so the shape recognition is properly tested; the three survivors are all about the edges of that recognition.
One structural note
mesh_skeletongrows 380 lines in this PR and carries its own micro-interpreter (mesh_run,mesh_vregs,lands). That is a lot of new machinery in one PR, and it is the part I would most want a second pair of eyes on — not because I found anything wrong, but because the refusal proofs above are only as good as the fixture's ability to build the programs that hit them, and eleven of the thirteen fixture cases are mutations of one skeleton.AI-assisted; the five mutations were run locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T19:19:47Z.
Review: APPROVED
Approved at head
b1c81d24. My four findings from the review of58a673cfare addressed in22664c8b, which I re-verified at this head. This approval replaces my change request.Re-verification
Windows 11 build 26300,
--preset dev,offscreen_checkbuilt atb1c81d24. AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32029.2010) and WARP 10.0.26100.9818, debug layer enabled.main(6fc112d2, clean): 5/5 pass.Findings, now pinned
gfx2hlsl.py, reverted)& 1023uindexw >> 31 != 0u ? (uint3)0u : … & 511u1023u: draw fails on both. Both fail atvertices=128 primitives=128 first=112 flags=['80000000', '20080200']: got (1, False), want (0, True).mainmerged; the depth-only pixel stage is refused asslot 57 mesh with a depth-only pixel stage is not coveredstartup_gfx2hlsl_watch_check.py:111andstartup_mesh57_skeleton_check.py:154expect that text, and both passstartup_mesh57_skeleton_check.py:111:8704ff03is a refusal casev_mbcnt_hiterm set to0u: draw fails on both adapters (it survived at58a673cf)The PR claims no start-up progress, since no run-time path loads the translated pair, so there was no executable claim to verify.
Merge checks: required CI passed at this head ("Build and test on Windows" and both Linux jobs). The
/O2and coverage skips come from explicit workflow conditions. There are no unresolved review threads. The #2445 dependency has landed. I read the author's full response and @ChazY11's and @tedin7's reviews.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T19:15:18Z.
Review round addressed. Head is now
b1c81d24: a merge ofmain, the fix commit22664c8b, then a second clean merge ofmain(after that merge only the mesh57, watch, sop2-complement, translator and depctr checks were re-run; the draw was not).To MasterDomino
Thanks. All four findings reproduced here and are addressed in
22664c8b.511uand gives a primitive with bit 31 set one vertex three times, so it covers no pixel. Edge flags are ignored (triangles are filled); bit 30 is not modelled. The format is the one the primitive-export row ofdocs/experiments.mdalready states (9-bit index, edge flag in bit 9, bit 31 null). The draw has a new case with the first triangle null and the second carrying all three edge flags. Against the lowering of58a673cfthat case fails on WARP (exit 1); with the fix it passes. Restoring& 1023uor dropping the null test each fails that case.mainis merged (d9e93126); the three list conflicts keep onewaitcnt_depctrentry each. A null-export-only pixel stage is now refused intranslate_mesh57asslot 57 mesh with a depth-only pixel stage is not covered, before the mesh shape is read, andstartup_gfx2hlsl_watch_check.pyexpects that. The mesh57 check pairs its accepted fixture with the same pixel stage. Removing the refusal fails both checks.8704ff03translated before. The destination is now part of the overlap check and that word is a refusal case (registers of the accepted shape overlap).v_and_b32 v4, 15, v0; words checked with llvm-mc 15.0.7), so every thread stays inside the 512-byte buffer and the four earlier cases are unchanged. The new case runs 128 vertices and 128 primitives with the triangles on vertices 112..123 (wave 1, lanes 48..59). Thev_mbcnt_hiterm set to0unow fails it.Results at
22664c8b, Windows 11 build 26300, debug layer enabled, DXC 1.9.0.5512,offscreen_checkbuilt from an earliermain:startup_mesh57_skeleton_check.py draw, five casesmismatches=0,debug_errors=0mismatches=0,debug_errors=0startup_mesh57_skeleton_check.py(offline andbinary),startup_gfx2hlsl_waitcnt_depctr_check.py,startup_translator_check.pyand every no-argumentstartup_gfx2hlsl_*_check.py(68 scripts in all) exit 0. No capability skips.gfx2hlsl.py, reverted)v_mbcnt_hiterm0u1023uNot done: the null, edge-flag and high-thread controls share one draw case, so a failure there does not say which of the three broke.
To ChazY11
Thanks, all three survivors were real gaps (I re-ran the three removals against the tests of
58a673cf: exit 0 each). Each now has a control in22664c8b, and each of your three mutations failsstartup_mesh57_skeleton_check.py.the compared register is not the wave index: kept, not a duplicate. Thes3 is read other than as the wave indexproof looks at reads ofs3. This one looks at the register the count exchange compares. A program can derive the thread index correctly and then rewrite that register before the count barrier; only this proof refuses it. The new case does exactly that (s_mov_b32 s6, s8in place of a wait): without the proof it translates.registers of the accepted shape overlap: kept. New case: the wave test writes the saved lane-0 mask (also MasterDomino's finding 3, which added that register to the check). It pins the proof as a whole; the other clauses of that condition do not each have their own case.does not end with s_endpgm: kept. A request cannot reach it:translate_mesh57refuses a missing terminator first, with another message.MeshPipelinecan be built directly, as the draw mode does, and the walk takes the last instruction as the terminator without reading it, so the proof stays and the new case builds the pipeline withs_nopin place ofs_endpgm.On the size of
mesh_skeleton: agreed that it wants a second reader. Most cases are still mutations of one skeleton; that has not changed in this round.To tedin7
Thanks for the check and the two mutations.
main(d9e93126); thes_waitcnt_depctrcommit is the one that landed as #2445.mismatches=0).🤖 Generated with Claude Code