Skip to content

shader: accept any zero VGPR in the mesh group-index exchange - #3537

Merged
tedin7 merged 9 commits into
R0Y00:mainfrom
lambirou:shader/mesh-v6-exchange
Nov 30, 2026
Merged

tedin7 merged 9 commits into
R0Y00:mainfrom
lambirou:shader/mesh-v6-exchange

Conversation

@lambirou

@lambirou lambirou commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The native mesh frontend refused four shapes from the real slot 57 workload:

  • the group-index exchange when its zero-address VGPR was not v0;
  • an output count without a proven unsigned bound;
  • position VGPRs defined under a partial EXEC mask and exported after an LDS branch;
  • a creation root whose table reads constant data through a CBV range and through one descriptor past the last declared range.

Change

  • Read the zero-address VGPR from the first v_mov_b32_e32 of the group-index exchange and rebuild its DS fields around it.
  • Clamp output counts to the layout's maximum vertices/primitives.
  • Add X2W_MESH57_PARTIAL_ZERO=1: keep the last partial value for mesh reads/exports and materialize a missing merge edge as zero. The default path still refuses an unproven partial VGPR.
  • Add an 85-word source-built real-shape fixture and its wrong-zero-VGPR control.
  • Accept a table read whose slot a CBV range declares, and one past the last declared range, as a byte window. s_buffer_load carries no format, filtering or typed element, so the descriptor's memory read as raw dwords is the same value. The submission still resolves each slot's token and refuses anything that is not a buffer SRV or a CBV.

Validation

python -B tests/startup_mesh57_real_shape_check.py out/build/dev/compile_dxil.exe <dxc>
ctest --preset dev --no-tests=error -R '^native_fixed_mesh57_'
  • Source-built real shape: MS 4,876 bytes, PS 2,386; opt-in accepted; wrong zero VGPR refused.
  • native_fixed_mesh57_* warp+hardware: 26/26 passed (13 variants, including the two new _cbv cases).
  • native_fixed_mesh57_cbv_warp|hardware: the same MS reads the same dword through a table slot declared as a CBV; PSO created and pixels match the SRV variant.
  • native_fixed_mesh57_cbv_uav_warp|hardware: the same slot declared as a UAV is still refused with MS buffer slot outside a verified SRV range.
  • Captured title requests: without the opt-in the depth-only request refuses at graphics register undefined on an incoming path: 265; with X2W_MESH57_PARTIAL_ZERO=1 it compiles to a 12,680-byte MS. Four of the twelve live captures are depth-only and compile (3e8243, 0acf7c, 30d597, fd8f); with their reviewed profiles they create a native PSO, forward one indirect DispatchMesh and complete a depth readback, locally, without their bytes entering the repository. The partial-EXEC path is a heuristic for lanes the shader has not proven defined, not the final per-VGPR EXEC proof.

Limits

The empty-PS depth-only profile, DispatchMesh and pixel readback for a captured key remain the next tranche; they need the runtime fixture branch, which this PR does not carry. The Linux Python job fails on startup_triage_run_check.py because a source reason is missing from COMPUTE_DISPATCH_REASONS; this PR does not touch that tool. Windows and the gfx1013 fixture jobs pass.

Refs #2413

The native mesh frontend matched the group-index exchange only when the
zero-address VGPR was v0. The real slot 57 shape uses v6. Read the VGPR from
the first v_mov_b32_e32 and rebuild the second move and both DS address
fields, then clear the selected VGPR instead of v0.

Add a source-built 85-word real-shape fixture with the v6 exchange, a
formatted heap read through v_readfirstlane_b32, three DS writes and reads,
five barriers, GS_ALLOC_REQ and pos0/prim exports. compile_dxil produces a
4,828-byte MS and a 2,386-byte PS. A mismatched zero VGPR (v5 with DS fields
still naming v6) is refused.

This tranche covers the compiler shape; the direct-heap runtime profile and
the draw/readback remain for the next one.
The real title request stores counts from a formatted load without a proven
unsigned bound, so the native frontend refused the count exchange. Clamp the
two loaded counts to the layout maxima before setMeshOutputCounts; the real
request now passes the exchange and stops later on an undefined incoming VGPR.

The source-built real-shape test exercises the clamp path and reports the
larger 4,876-byte MS.
@lambirou

Copy link
Copy Markdown
Contributor Author

The Linux Python check fails in tests/startup_triage_run_check.py because the source reason an output UAV interval exceeds the D3D12 buffer view element limit is absent from COMPUTE_DISPATCH_REASONS in tools/startup/triage_run.py. This PR does not touch the triage tooling; the Windows build/test and gfx1013 fixture jobs pass. I will leave the draft as-is until that separate triage-list update lands, rather than mixing it into this mesh change.

@lambirou

Copy link
Copy Markdown
Contributor Author

Next blocker on the captured title request: the compiler stops at +0x46c exp pos0 v9, v10, v11, v6. Those four VGPRs are computed at +0x340..+0x37c, before the LDS count exchange branch, then exported after the branch join. Instrumenting the merge shows v9 present on one edge and absent or empty on the other, so merge_edges erases it. The next slice is to preserve/phi a VGPR defined before the exchange across that join instead of treating an absent symbolic entry as undefined. The clamp and v6 changes are committed; this diagnosis is not.

A real slot 57 request defines its position VGPRs under a partial EXEC mask
and exports them after an LDS branch. The default merge still refuses that
shape. X2W_MESH57_PARTIAL_ZERO=1 keeps the last partial value for mesh reads
and exports and materializes a missing merge edge as zero.

With the opt-in, one captured title request compiles to a 12,680-byte MS and
a 2,310-byte PS; without it the same request refuses at graphics register
undefined. The source-built real-shape test exercises the opt-in and keeps the
wrong-zero-VGPR control refused. The default behavior is unchanged.
@R0Y00 R0Y00 added the priority: P0 Highest project priority label Nov 30, 2026 — with ChatGPT Codex Connector
X2W_MESH_DUMP_LAYOUT=1 prints the guest-root SGPR, root parameter, constant
count and resource-heap SGPR used by a raw mesh translation. This is the
mapping needed to author a Mesh57Profile from a captured request.
Accept v_sub_nc_u32, v_subrev_nc_u32, v_add_co_ci_u32, s_cmpk_lg_i32 and
s_lshl2_add_u32 in the mesh lowerer, reusing the shared ALU implementations.

On twelve captured live slot 57 requests, four depth-only requests already
compiled; the new forms move the remaining multi-byte requests past their
first ALU refusal. The next stops are heap-slot provenance, v_readfirstlane,
a raw root descriptor and an unmapped export target.
The mesh raw root-buffer path now accepts root_stride_one_high with the
0x31016fac byte-count format, and allows OFFEN to carry a nonzero immediate
offset. The live request 314407020a96f733 moves from +0x330 to its next
refusal at +0x614, a resource-heap descriptor load.
@lambirou

Copy link
Copy Markdown
Contributor Author

Linux is red on startup_triage_run_check, and the cause is on main, not in this branch: #3471 added the reason an output UAV interval exceeds the D3D12 buffer view element limit to src/startup_stubs/d3d12_compute_dispatch.inl without adding it to COMPUTE_DISPATCH_REASONS. The merge ref this job checks out contains that source, so the reason check fails here too. #3559 fixes the allowlist; it is green and mergeable. Once it lands, a re-run of this job should pass without touching the mesh code.

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed f3590da0 (draft) by reading the diff; not built or run.

Verdict: comment. No MUST in what I read. The draft needs splitting and tests that tell the opt-in apart from the default before it is ready.

  • SHOULD Split it. The title covers the zero-VGPR exchange, but the eight commits also carry the count clamp, the X2W_MESH57_PARTIAL_ZERO heuristic, X2W_MESH_DUMP_LAYOUT, a wider mesh ALU subset (s_lshl2_add_u32, s_cmpk_lg_i32, v_sub_nc_u32, v_subrev_nc_u32, v_add_co_ci_u32), the OFFEN root V# change and CBV/past-table slots. The body does not mention the last three. The zero-VGPR change, the clamp and the CBV slots each stand alone.
  • SHOULD The opt-in has no test that shows what it does. real.m57 compiles without X2W_MESH57_PARTIAL_ZERO too (tests/startup_mesh57_real_shape_check.py:66-94), so the opt-in step would pass if the switch did nothing. Add a source-built shape that is refused by default and accepted with the switch (the +0x46c exp pos0 join you described). It also needs a runtime check, because "missing edge = 0" applies to every VGPR (reg>=256) in merge_edges (src/gfx1013_direct_mesh.inl:255-271), not only the partial writes.
  • SHOULD Assert the refusal text in the wrong-zero-VGPR control (:83). Today any refusal passes, not just the zero_vgpr!=5 gate.
  • NIT src/gfx1013_direct_compute.inl:925 drops the zero-immediate check (0x3fff → 0x1000) without a test. The offset is added at :933, so I see no wrong read.
  • NIT CMakePresets.json adds compile_dxil to the pr build targets, but no new test is in the pr filter, so CI builds it without using it.
  • Checked, no finding: the exchange words are read after the >= 60 size check, and the DS fields are rebuilt correctly around zero_vgpr. indirect_table_buffer already resolves slot-17 CBV tokens from location + size. An unbounded range keeps past_table false.

Tests: native_fixed_mesh57_cbv_* proves that a CBV-declared slot reads the same dword and that a UAV-declared slot is still refused. startup_mesh57_real_shape proves the v6 exchange compiles. Nothing covers the clamp, the ALU additions or the OFFEN change. CI ran none of these (not in the Windows pr filter, and the Linux job does not build compile_dxil).

@lambirou

Copy link
Copy Markdown
Contributor Author

Review follow-up on 756c58cb:

  • The opt-in is now tested for real: the source-built fixture is refused without X2W_MESH57_PARTIAL_ZERO at +0x148 (graphics register undefined on an incoming path: 265) and accepted with it; the IR carries the phi and the export consumes it. This exercises the general reg>=256 rule in merge_edges, not only already-marked partial writes.
  • The wrong-zero-VGPR control asserts the exact refusal text in both modes.
  • Count clamp, the five ALU forms, and the OFFEN root V# offset now have source-built checks. The IDXEN negative control covers the zero-immediate NIT.
  • startup_mesh57_real_shape is in the pr test filter; ctest --preset pr -N lists 87 tests, including it.
  • Targeted ctest --preset dev -R '^startup_mesh57_real_shape$|^native_fixed_mesh57_' passes 27/27, and 28/28 including startup_tools_lint, with no skips.

Split status: the CBV/past-table lot is extracted to #3565. The remaining plan is: zero-VGPR, count clamp, partial-EXEC opt-in, wider ALU, OFFEN root V#, and the layout dump as separate lots; their tests currently share the real-shape harness, so the harness needs sub-case extraction before those branches can stand alone.

@lambirou
lambirou marked this pull request as ready for review November 30, 2026 09:09

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review at 756c58cb (previous: f3590da0), by reading the diff; not built or run.

Verdict: approve. The test gaps from my first pass are closed. The split is under way, so it can follow. No MUST.

  • Opt-in: partial is refused by default at +0x148 with graphics register undefined on an incoming path: 265 and accepted with X2W_MESH57_PARTIAL_ZERO=1. The test also requires the phi i32 [ 0, … ], [ 1065353216, … ] and that the export bitcasts that phi, so a switch that did nothing, or zeroed the wrong edge, would now fail. It exercises the general reg>=256 rule in merge_edges, as I asked.
  • The wrong-zero-VGPR control asserts the exact +0x4 refusal in both modes.
  • Clamp, ALU and OFFEN now each have a source-built check that reads the emitted IR through X2W_DUMP_SHADER_IR: the two count selects feed the counts, the v_add_co_ci_u32 refusal comes without a reaching VCC (+0x144 … register 106), and OFFEN offset 16 lands in the address. The new comment at gfx1013_direct_compute.inl:923 explains why the 0x1000 mask is enough: the raw-load decoder refuses IDXEN first.
  • CI: startup_mesh57_real_shape is in the pr filter now, and run 46383882043 passed it, so the compile_dxil build target is no longer unused.
  • SHOULD (can follow): f3590da0 is still on the branch, although #3565 merged the same change. Its native_mesh57.inl diff is byte-identical, and the PR merges cleanly with main 5de27d2b, so nothing breaks. A rebase would drop the commit and keep the history honest. The rest of the split (zero-VGPR, clamp, opt-in, ALU, OFFEN, layout dump) is as planned in your reply.
  • NIT: X2W_DUMP_SHADER_IR is documented only in docs/experiments/native-fixed-mesh57.md. One line in the compile_dxil usage text would help anyone outside mesh find it.

@lambirou
lambirou force-pushed the shader/mesh-v6-exchange branch from 756c58c to e6ee730 Compare November 30, 2026 09:39
@lambirou

Copy link
Copy Markdown
Contributor Author

Re-review follow-up at e6ee7309:

The remaining split (zero-VGPR, clamp, opt-in, ALU, OFFEN, layout dump) is unchanged and can follow.

@lukaslw-lab lukaslw-lab left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed e6ee7309 by reading the diff; not built or run.

Verdict: approve. The rebase only drops f3590da0 and adds the usage line; the mesh changes are the ones approved at 756c58cb.

  • Checked: git range-diff from 756c58cb to e6ee7309. Commits f0b966b8…5a1edb31 are identical, and 3d4f93b0 is identical to 756c58cb. f3590da0 is gone and its change is on main as #3565 (a7e8298c). The diff and docs/experiments/native-fixed-mesh57.md no longer mention the CBV or past-table reads.
  • Checked: e6ee7309 adds only the X2W_DUMP_SHADER_IR=FILE line to the compile_dxil usage text (tools/startup/compile_dxil.cpp:1591). It matches the reader at :336 and the doc note at native-fixed-mesh57.md:162.
  • NIT The PR body still describes the CBV and past-table change and counts the two _cbv cases in "26/26 (13 variants)". Both now belong to #3565, so the body should drop them so the squash message matches the diff.

Tests: startup_mesh57_real_shape is in the pr filter. CI ran it on this head and every job passed, including the Linux Python job.

@tedin7
tedin7 merged commit 617ce7c into R0Y00:main Nov 30, 2026
5 checks passed
R0Y00 pushed a commit that referenced this pull request Nov 30, 2026
#3537 replaced the "mesh count exchange exceeds declared range" refusal
with a clamp to the declared output range, but the too-many-primitives case
still expected the refusal, so native_direct_mesh failed on main. The case
now checks that the vertex and primitive counts are clamped to 3 and 1 and
that the clamped values reach setMeshOutputCounts.

Co-authored-by: lukaslw-lab <291379150+lukaslw-lab@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: P0 Highest project priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants