Skip to content

help wanted: GPU translation, part 2 (mesh shaders) #1998

Backlog

Description

@denn0x

Follow-up to #1760. The source-built slices merged so far (#1913, #1779) cover bounded runtime geometry and multi-primitive lowering. A census of mesh-stage programs from a private corpus (aggregate counts only; about 4,000 distinct programs in the group form: LDS, group barriers, per-lane ranges, v_readfirstlane) shows which constructs still stop a translation. Each row is a separate piece of work that one person can take with a source-built fixture.

Constructs (pick one, say so in a comment)

Item Construct Programs stopped first by it Notes
A Branch on an SCC that depends on a wave lane mask ("any lane active") about 1,190 Needs a group-uniform form: each wave publishes its bit to shared memory, then a barrier, then a uniform branch with exec guards.
B Scalar spills: v_writelane_b32 / v_readlane_b32 used as spill slots for scalar registers, including saved exec masks about 220 A spill slot is per wave, not per lane. Only the constant-lane spill / reload idiom needs recognising; anything else can stay refused. #1543 covers cross-lane operations for compute only.
C Exec mask restored inside a per-lane range (non-spill forms: a copy made before the branch, moved between registers, or joined from several paths) about 120
D Descriptor identity that differs between the two arms of a join about 270 Typically a per-material view, or a null descriptor in one arm. Needs a bounded selection carried through the join.
E Sampler state loaded from a descriptor instead of a static sampler about 260 Related: #1143.
F Second position export (pos1): clip and cull distances about 200 Maps to SV_ClipDistance / SV_CullDistance; the component count comes from pipeline state.
G Scalar written inside a skipped range and live after it about 160
H Waves of one group reaching a different number of group barriers about 125
I Loops (back-edges through the LDS / barrier structure, loop-carried exec masks) about 720 programs contain loops; their first refusals are not yet separated from A-H A census of the loop-specific refusals is itself a useful contribution.

What a contribution needs

  • A source-built mesh pipeline (or a hand-assembled program) that contains the construct, with pixel or buffer read-back and a negative control. No bytes from any retail software.
  • A differential check against an independent CPU model of the wave where the construct changes control flow.
  • LLVM / Mesa semantics cited for each instruction lowered.
  • Refuse precisely what the change does not cover.

Notes

  • Fused and unfused multiply-adds must keep the console rounding (fused: one rounding; unfused: two). Otherwise positions differ between a depth pre-pass and the colour pass that tests depth EQUAL. Measured locally: letting the compiler choose gave differences of more than 1,000 ulp on a position component in one program; the explicit rule gave 0.
  • Counts are first refusals; closing one row exposes the next for some programs.

Related: #1760, #1759, #1541, #1543, #1143.

Activity

  1. changed the title [-]help wanted: mesh-program constructs still without a lowering (spills, lane-mask branches, descriptor joins, clip distances, loops)[/-] [+]help wanted: GPU translation, part 2 (mesh shaders)[/+] on Nov 24, 2026
  2. avt0m4t48 commented on Nov 24, 2026

    @avt0m4t48
    Contributor

    I’ll take item B, the constant-lane scalar spill and reload pattern in the bounded mesh path. The source-built wave64 fixture covers a selected lane outside EXEC and a saved EXEC high word that changes control flow. I’m checking pixel readback before submitting the patch.

  3. avt0m4t48 commented on Nov 24, 2026

    @avt0m4t48
    Contributor

    I’m releasing my claim on item B so someone else can take it. The source-built CPU and DXIL checks passed locally. Pixel readback is still open.

  4. R0Y00 commented on Nov 24, 2026

    @R0Y00
    Owner

    Item B is available again. If the source-built spill/reload fixture is shareable, please link the source revision and its CPU/DXIL test commands here so the next contributor can start at the GPU readback. The remaining discriminator is a wave64 case that recovers a selected lane outside EXEC and a saved high word whose removal changes the fenced pixel result. Use the existing bounded mesh draw fixture and report capability skips separately.

  5. Leyukaka commented on Nov 25, 2026

    @Leyukaka
    Contributor

    Item F (clip and cull distance exports): what blocks it in the mesh tools, from reading tools/mesh_entry_aot.py and tools/mesh_dynamic_aot.py at 5a0b0aa. Nothing was run.

    • Where it stops. The export parser accepts prim, pos0 and param0 only (mesh_entry_aot.py, the export regex). Any other target raises "Unsupported mesh export". mesh_dynamic_aot.py inherits that parser through RuntimeWave(Wave).
    • What is missing. No pipeline register state reaches either lowerer.
      • decode_mesh takes the limits from PSV0 and the code from the DXIL chunk.
      • The static lowerer gets geometry words, limits and an optional vertex header.
      • The dynamic lowerer gets a geometry word count and limits.
      • A search of the tree for PA_CL, CLIP_DIST, CULL_DIST, CCDIST, ClipDistance or CullDistance finds nothing.
    • Why the export alone is not enough. Which position export carries distances, and which components are clip or cull, comes from PA_CL_VS_OUT_CNTL: CLIP_DIST_ENA_0..7, CULL_DIST_ENA_0..7, VS_OUT_CCDIST0/1_VEC_ENA, plus VS_OUT_MISC_VEC_ENA and the USE_VTX_* bits. As far as I know, in Mesa's layout pos1 is the misc vector (point size, layer, viewport) when that is enabled, and the distance vectors then move to pos2/pos3. So pos1 is not always a distance vector, and any guessed layout is wrong for some mix of enables. I have not checked whether the hardware mandates that numbering.
    • What would unblock it.
      • These tools are command-line lowerers with no request or cache key of their own. The state would have to be added to their inputs (a profile or manifest field), and to whatever calls them once they are wired to the runtime.
      • With the decoded enables, the lowerer could declare only the enabled SV_ClipDistanceN / SV_CullDistanceN fields, write the export operands in ascending index order, and refuse unknown or contradictory layouts with the target and reason.
      • The compute fallback's intermediate buffer (positions and PARAM0 at fixed offsets) would need room for the distances too.

    AI-assisted.

  6. akimfomin commented on Nov 25, 2026

    @akimfomin

    Item B independent GPU readback on Leyukaka's exact #2127 head 2dc58a8bdf7e. Thanks to avt0m4t48 for the earlier CPU/DXIL work and the requested inactive-lane and high-word controls. PortBridge used that request to prepare an independently generated fixture.

    With only guest lane 0 active, the source saves EXEC_LO=1 and EXEC_HI=0x100 into inactive lanes 8 and 40. LLVM assembled and decoded the three gfx1013 guest Wave64 programs. On RTX 4070 Ti SUPER (driver 32.0.16.1714, Win11 build 28000), the complete spill drew all 1,024 expected green pixels. Zeroing either word left all 1,024 pixels clear as expected. The stale-pixels-only control kept the good export trace and produced the expected 1,024/1,024 mismatches. D3D12 debug layer was unavailable; the hardware device and fenced readback were verified.

    The passing cases use inline selectors. A separate source-built case with known SGPR selectors still gets the documented refusal. Exact source, CPU/DXIL reproduction and hardware transcript · PortBridge Test Lab. AI-assisted with Codex.

  7. tedin7 commented on Nov 25, 2026

    @tedin7
    Collaborator

    Picking up Item A (branch on SCC any-lane-active in mesh) with unit + WARP/verification tests.

  8. tedin7 commented on Nov 25, 2026

    @tedin7
    Collaborator

    Picking up Item C (non-spill exec mask restore inside a per-lane range) and Item G (scalar written inside a skipped range and live after it) as two separate PRs with mesh tests.

  9. tedin7 commented on Nov 25, 2026

    @tedin7
    Collaborator

    Also picking up Item D (descriptor identity differing between the two arms of a join) as a separate PR with mesh verification tests.

  10. R0Y00 commented on Nov 25, 2026

    @R0Y00
    Owner

    Item B landed in #2127 (498c23c). The bounded translator now handles the constant-lane spill/reload with EXEC cleared and rejects an unwritten slot or mixed ordinary VGPR use. The final head passed the local CPU model, including both EXEC halves. The independent GPU report remains the reference for the fenced inactive-lane/high-word comparison. Keep runtime-geometry support and the other claimed items separate. Independent readback

  11. roansystemlabs commented on Nov 25, 2026

    @roansystemlabs
    Contributor

    I'd like to take item E, sampler state loaded from a descriptor in the bounded mesh path. If someone already has it in progress, I'll step back and review.

    Scope: reuse the opt-in sampler table from #1217/#1237 (s0, space1, 16-byte descriptor stride) for mesh programs in tools/mesh_dynamic_aot.py, where the sampler is loaded with s_load from a heap base plus a constant or bounded offset. Anything else (unbounded index, sampler word changed after the load, mixed static and heap use in one join) stays refused by name.

    Evidence: a source-built mesh pipeline assembled with LLVM 15 llvm-mc for gfx1013 that samples one texture through two different heap samplers (distinct address modes and LOD limits), drawn on WARP and an RTX 3070 with fenced pixel readback. Negative controls: swapped sampler entries and the default-sampler shortcut must change the readback; the guard removed must fail.

    AI-assisted.

  12. RavenCurseBurg commented on Nov 25, 2026

    @RavenCurseBurg
    Contributor

    I'll take the early-exit slice of item H for the bounded two-wave64 mesh lowerers. AMD's RDNA 2 ISA §4.3 says a wave can terminate with S_ENDPGM and the remaining live waves can satisfy later barriers. Both current lowerers require identical barrier-PC lists even though Wave.run already requires each executed path to reach S_ENDPGM.

    I'll exercise a common barrier followed by one wave terminating and the other continuing to a later barrier. Two live waves reaching different barrier PCs at the same phase must still be refused. The tests will use a source-built program, an independent two-wave arrival/termination reference and GPU readback; runtime LDS sharing and loops are outside this slice.

    AMD RDNA 2 ISA, §4.3

    AI-assisted (Codex, GPT-6.2 Astra xhigh).

  13. R0Y00 commented on Nov 25, 2026

    @R0Y00
    Owner

    The item H early-exit slice is available and distinct from #2220. Please proceed with the existing bounded two-wave64 profile. Keep the common first barrier, then let one wave terminate while the survivor reaches its next barrier. Include both wave orders, a readback sentinel that detects a missing surviving-wave write, and a refusal when two live waves reach different barrier PCs. Please include the exact LLVM 15 assembly and WARP/hardware test commands in the PR, with capability skips reported separately.

  14. RavenCurseBurg commented on Nov 25, 2026

    @RavenCurseBurg
    Contributor

    I also reproduced a separate input-path blocker while assembling the early-retirement fixture. #2241 can use a shared final S_ENDPGM. Giving the retiring wave its own reachable S_ENDPGM produces the same mesh exports at the wave-model entry point, but the normal stage-13 container extractor refuses the program before either CLI reaches the model. This is the mesh-stage exclusion noted in #721.

    I’ll take the bounded two-exit mesh-container follow-up. I’ll check the two decoded exits under gfx1013 wave64, preserve the reachability and instruction-boundary checks, and run a real allocation/position/primitive-export fixture through both CLI entry points and a device readback. An incorrectly tagged compute program, an unreachable alternate path and additional exits will remain controls. I’ll keep it separate from #2241.

  15. RavenCurseBurg commented on Nov 25, 2026

    @RavenCurseBurg
    Contributor

    #2241 now covers both requested retirement orders at 5bd2ea09. In the 320-byte reverse-order fixture, wave 0 allocates 68 vertices, writes vertices 0–63, and terminates. Wave 1 traverses the later barrier and supplies vertices 64–67. Both host evaluation orders yield the same barrier traces ([172] and [172, 184]) and primitive indices. The second primitive reads vertex 67.

    The static and runtime CLI results matched all 1,024 pixels on WARP and a physical D3D12 adapter. Keeping vertex 67 at vertex 2’s position instead removes exactly 528 pixels on each adapter. Both live-wave mismatch refusals are still exercised. The PR description now includes the exact LLVM 15 and draw commands.

  16. roansystemlabs commented on Nov 25, 2026

    @roansystemlabs
    Contributor

    I'd like to take item F, the clip and cull distance exports, in the bounded mesh path. If someone already has it in progress, I'll step back and review.

    Following the analysis above, the export alone can't say which position export carries the distances, so the first slice takes the PA_CL_VS_OUT_CNTL word as an explicit input of the lowerer instead of guessing a layout.

    First slice (one PR):

    • tools/mesh_entry_aot.py, and the runtime wave in tools/mesh_dynamic_aot.py that inherits its export parser, accept pos1/pos2 only as the CCDIST0/CCDIST1 vectors the given word enables (CLIP_DIST_ENA_0..7, CULL_DIST_ENA_0..7, VS_OUT_CCDIST0/1_VEC_ENA), with the field layout from Mesa's gfx10 register table and the export order from Mesa's NGG code. The output vertex declares only the enabled SV_ClipDistance / SV_CullDistance components.
    • Refused by name: no state word given, the misc vector enabled (it would move the distances to later exports), a distance export that is not enabled or an enabled one that is missing, duplicate exports, the USE_VTX_* bits, and the compute fallback, whose intermediate buffer has no room for distances yet.
    • Reading the word from the slot 57 state stays out of this PR. @denn0x, if block A also holds PA_CL_VS_OUT_CNTL next to the words decoded in startup: decode slot 57 depth-stencil registers into a desktop state #2124, its position would let a second slice read it from the state; otherwise that stays a separate piece.

    Evidence: source-built mesh programs assembled with LLVM 15 for gfx1013 that export a position plus clip and cull distances, drawn on WARP and an RTX 3070 with fenced pixel readback. A triangle crossing a clip plane must lose exactly the pixels where the interpolated distance is negative, and a primitive whose cull distances are all negative must disappear while its neighbour stays. On current main the same programs stop at "Unsupported mesh export". Negative controls: clip and cull components swapped, CCDIST0 and CCDIST1 swapped, one enabled component dropped, and the guard removed must each fail. Not tested: AMD or Intel GPUs and console hardware.

    AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions