Skip to content

compute_store_aot: accept two-exit compute programs, then lower a guarded read–compute–write kernel #721

Open

Description

@roansystemlabs

Problem

After #708, the next compute stops in the fixed-profile archive rescan (docs/experiments.md) are:

  • 1,002 of 2,689 CS records stop at "Unverified multi-exit program". pixel_aot.container_code() accepts a second s_endpgm only for pixel programs (stage == 0 and markers == 2, verified by _check_two_exits from shader: bound and verify two-exit FSSM pixel programs #477). Every compute (and mesh) program with more than one exit is rejected before any instruction is lowered. The compute_store_aot CLI also calls container_code(..., stage=5) without llvm, which the two-exit check needs.
  • 621 CS records pass extraction but stop at the fixed store lowering. compute_store_aot stores known words (immediates, constant-buffer words or the dispatch-thread index) into one raw UAV. It has no vector memory reads, no general ALU and no control flow. Address forms such as a v_mad_u32_u24 row pitch are rejected.
  • Overlap with shader: accept 2D/3D and wider thread groups in compute_store_aot #708. shader_profile_audit.classify() reads the PSV0 group size before it calls container_code(). The 1,054 records that stopped at thread-group dimensions were never checked for exits, so some of them will now stop at the multi-exit check. We cannot measure that overlap without the archive.

For pixel programs, docs/experiments.md reports that 5,465 of 6,189 multi-marker records (88%) had exactly two markers. If compute looks similar, the two-exit case covers most of the 1,002, but that is an assumption until counted.

Proposal

The goal is the first real compute kernel from the console format: an edge guard, a buffer read, some arithmetic and a guarded store, dispatched as 8×8 groups and verified on hardware. We would do it in small PRs, each one reviewable on its own, and start each step only after the previous one has landed.

  1. Exits. Let compute (stage == 5) use the same _check_two_exits verifier and rules as shader: bound and verify two-exit FSSM pixel programs #477: a direct branch to the block after the early exit, skipped alignment NOPs allowed, and rejection of unresolved transfers, branches into literals or padding, and disconnected blocks. The compute_store_aot CLI would pass llvm through. Source-built two-exit compute fixtures would get the same negative controls as the pixel ones. This step extracts the code span only; lowering comes next. Mesh (stage == 13) stays as it is.

  2. Guard. Lower the early exit in compute_store_aot, in two forms:

    • (a) a wave-uniform condition (s_cmp* + s_cbranch_scc0/1 around the early s_endpgm) becomes if (cond) return;;
    • (b) a per-lane condition (v_cmp* + s_and_saveexec_b64, with an exec branch around the early s_endpgm) becomes a store guarded by if.

    The exact branch shapes would come from the LLVM 15 compile of source kernels (see Verification) before any lowering code. Stores are side effects, so the per-lane select of shader: how should pixel_aot represent exec-masked conditional regions and branches? #338 option A (shader: lower single forward exec-masked regions in pixel_aot #651) does not apply here; the guard has to be a real branch. Everything outside these two forms is rejected.

  3. Reads. buffer_load_dword (idxen/offen) from another caller-bound buffer descriptor, with vmcnt waits tracked like the current lgkmcnt waits.

  4. Arithmetic. A small integer and float subset for addresses and values (add, mul, mad, shifts, min/max, v_mad_u32_u24 row pitch). See question 2.

  5. First kernel. A complete guarded read, compute and write kernel with 8×8 groups and a 2D dispatch, with half of the threads out of range. After this PR, we would ask you for a CS rescan.

Alternatives

  • Wait for the compute stage of the SPIR-V bridge. It is a separate path; this proposal only extends the existing compute_store_aot profile, one verified form at a time.
  • Lower general compute control flow (else branches, nesting, loops) at once. That is a larger review and a design question; the two guard forms above are the smallest step that a typical if (id >= n) return; kernel needs.

Verification

All inputs are source-built synthetic kernels; no game files.

  • Assembly: gfx1013 fixtures are written in LLVM 15 syntax and assembled and decoded with llvm-mc-15 / libLLVM-15.so.1 in the Ubuntu CI job. For the exit and guard forms, we would include the LLVM 15 compile and disassembly of small source kernels (llc-15 -mcpu=gfx1013) with uniform and per-lane early returns. The PR would quote the exact commands.
  • GPU checks: full-buffer readback, bit for bit, against an independent per-invocation model, on _warp and _hardware. Hardware runs use an RTX 3070 on Windows 11 with the D3D12 debug layer on; each PR records the commit, driver, Windows build and GPU load. We also run the pure-Python checks from AGENTS.md.
  • Negative controls:
    • exits: wrong branch target, a branch into a literal, a disconnected exit;
    • guard: inverted condition, guard ignored, wrong bound;
    • reads: swapped source and destination descriptors, wrong offset;
    • every step: a changed guard word.
  • Census: fixture results are reported separately from any archive rescan, as you asked on compute_store_aot: accept 2D/3D and wider thread groups #701.

Limits stated up front:

  • We do not have the archive. The census numbers above are yours, and the effect of each step needs a maintainer rescan.
  • Steps 3 to 5 will meet instructions that are not lowered yet. Many records will move to a later first stop rather than complete.

Questions

  1. Exit count. Could you share the end-marker histogram for the 1,002 multi-exit CS records, as docs/experiments.md does for pixel (two/three/four/five markers and the most common layout)? It tells us whether step 1 should stay two-exit only.
  2. ALU. For step 4, should compute reuse the pixel_aot ALU lowering, or keep a small separate subset inside compute_store_aot? We will follow your choice.
  3. shader: bound and verify two-exit FSSM pixel programs #477. You wrote the two-exit verifier. Would you rather extend it to compute yourself? Then we would start from step 2 once that lands.

AI-assisted: yes

Checklist

Activity

  1. R0Y00 commented on Nov 22, 2026

    @R0Y00
    Owner

    Please start with the source-built two-exit extraction PR. Reuse #477's branch and instruction-boundary checks, keep the stage and exact-marker limit explicit, and have the compute CLI and audit pass through LLVM. Include wrong-target, literal/padding and disconnected-exit controls. No new compute marker histogram is available here, so keep the counts separate from expected coverage. For a later lowering PR, model a per-lane guard as actual control flow around memory side effects. Keep the initial ALU subset small, reusing individual helpers only when their semantics match. The extraction PR can proceed independently of that decision.

  2. roansystemlabs commented on Nov 22, 2026

    @roansystemlabs
    ContributorAuthor

    Thanks. Starting the source-built two-exit extraction PR now, scoped exactly as above (extraction only; the per-lane guard and ALU subset stay for later PRs). I'll link it here.

  3. roansystemlabs commented on Nov 22, 2026

    @roansystemlabs
    ContributorAuthor

    To keep the plan visible: we intend to carry the whole sequence in this issue ourselves, one small PR at a time (two-exit extraction → per-lane guard as control flow → vector reads → small ALU subset → first read–compute–write kernel), each opened only after the previous one is reviewed. The extraction PR is in progress now.

  4. roansystemlabs commented on Nov 23, 2026

    @roansystemlabs
    ContributorAuthor

    Step 1 is up: #738 (extraction only; no lowering). The per-lane guard comes next, as control flow around the store.

  5. roansystemlabs commented on Nov 23, 2026

    @roansystemlabs
    ContributorAuthor

    Thanks for merging #738. Step 2 (the per-lane guard as control flow around the store) is next.

  6. R0Y00 commented on Nov 23, 2026

    @R0Y00
    Owner

    Step 1 merged in #738 after the SPIR-V cache repair. Source-built LLVM 15 fixtures now exercise the #477 verifier for two-exit compute programs. This is extraction only, with no new archive count. The per-lane guard can proceed around the store as discussed, and this issue remains open for the later steps.

  7. roansystemlabs commented on Nov 23, 2026

    @roansystemlabs
    ContributorAuthor

    Step 2 is up: #776 (per-lane guard lowered as an if around the masked stores; unmasked stores after the exec restore stay outside). Vector reads come next.

  8. R0Y00 commented on Nov 23, 2026

    @R0Y00
    Owner

    #776 merged as e861e7e. The LLVM 15 fixtures now verify both guard shapes: masked stores to exit and a restored mask with later unconditional stores. WARP and RTX compared the buffers, and both Windows configurations and both Linux checks passed. This covers the store-guard step. The issue stays open for vector reads and the combined read–compute–write fixture.

  9. 22 remaining items

  10. henriazz10 commented on Nov 25, 2026

    @henriazz10
    Contributor

    I'd like to take the general per-lane compare and select for compute_store_aot (gfx1013), as one PR.

    Today v_cmp_* is accepted only as a lane-guard opener, with five predicates and operands that must be verified uniform, and v_cndmask_b32_e64 only with an SGPR that holds a known constant mask. This slice adds the following.

    • Compares. The VOPC compares on known words:
      • v_cmp_{f,lt,eq,le,gt,ne,ge,t}_{u32,i32}, e32 into vcc_lo and e64 into an SGPR;
      • v_cmp_{f,lt,eq,le,gt,lg,ge,o,u,nge,nlg,ngt,nle,neq,nlt,tru}_f32, with the IEEE unordered rules for NaN.
    • Per-lane result. Each result is tracked as a per-lane condition: each thread's own bit of the mask. That is independent of the wave size, because only the same lane reads it.
    • Select. v_cndmask_b32_e32 vD, S0, vS1, vcc_lo and v_cndmask_b32_e64 ..., vcc_lo|sN select on that condition.
    • Refused. Any other reader of the condition stays refused: scalar ALU, branches, s_and_saveexec on a per-lane condition built from loaded data, and the add-with-carry _ci forms. The existing guard path, the constant-mask select and the carry/borrow tracking keep their current behavior. A compare or carry that rewrites VCC invalidates the previous per-lane value.
    • Modifiers. Source modifiers (neg/abs on f32) are refused unless modelled. clamp and SDWA are refused.

    Evidence:

    • an independent Python model with the full truth tables, covering equal values, signed and unsigned order across 0x80000000, ±0, NaN on either side, and infinities;
    • a source-built fixture with a unique word per thread;
    • reference and recompiled-HLSL mutations (swapped predicates, signed for unsigned, ordered for unordered);
    • draws on WARP and hardware;
    • the LLVM 15 round trip;
    • form-coverage records.

    The open SDWA comparison PR (#1670) is for pixel_aot and does not overlap with this.

    AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) writes it, and Claude Code reviews it.

  11. added a commit that references this issue on Nov 25, 2026
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