Skip to content

feat: lower group-uniform any-lane SCC branch in mesh programs - #2142

Merged
R0Y00 merged 3 commits into
R0Y00:mainfrom
tedin7:x2w-1998a-mesh-scc-branch
Nov 25, 2026
Merged

R0Y00 merged 3 commits into
R0Y00:mainfrom
tedin7:x2w-1998a-mesh-scc-branch

Conversation

@tedin7

@tedin7 tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Part of #1998

What this unblocks: mesh programs that branch on "any lane active" across both waves (Item A, about 1,190 programs) can now be lowered instead of refused.

What changed

  • The two-wave64 mesh interpreter runs waves in lockstep between barriers and models LDS publish (ds_write_b32), s_barrier, ds_read_b32, v_readfirstlane_b32 and SCC branches (s_cbranch_scc0, s_cbranch_scc1).
  • 64-bit scalar compares (s_cmp_lg_u64, s_cmp_eq_u64) and s_cmp_lg_u32 are accepted. Unsupported widths are refused by name.
  • Refused: reads nobody published, stores not waited before the barrier, reads before their wait, own-store reads before a barrier, conflicting stores, dynamic or unaligned LDS addresses.
  • New source-built program tests/mesh_scc_any_lane.s with embedded bytes.
  • New tests registered in CMake: mesh_scc_any_lane_cpu, mesh_scc_any_lane_draw_{hardware,warp}.
  • Docs: docs/experiments.md.

Verification

Executed locally (Linux, CPU only):

python3 -B tests/mesh_scc_any_lane_check.py
python3 -B tests/mesh_dynamic_geometry_check.py
python3 -B tests/mesh_dynamic_aot_check.py
python3 -B tests/mesh_amplification_refusal_check.py
python3 -B tests/mesh_multi_check.py
python3 -B tests/pso_readiness_check.py

All passed. A dry run of the lowering gave (4,2) for T in {0,64,100,127} and (3,1) for T in {128,200}. The three mutants (own flag only, flipped branch, 32-bit mask compare) give (3,1) at T=100.

NOT run yet (needs Win2025, Stage 2):

ctest --preset release --no-tests=error -R "mesh_scc_any_lane" -V
python3 -B tests/mesh_scc_any_lane_check.py binary llvm-mc llvm-objcopy libLLVM-15.so.1

The D3D12 WARP readback test and the LLVM reassembly check of the hand-encoded bytes are pending. Draft until they pass.

AI-assisted; commands listed were executed locally.

@tedin7
tedin7 marked this pull request as ready for review November 25, 2026 01:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T01:45:15.051571Z 6fa78fc Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6fa78fc62e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tools/mesh_entry_aot.py Resolved
Comment thread tools/mesh_entry_aot.py Resolved
Comment thread tools/mesh_entry_aot.py Resolved
@thepatrickworld

Copy link
Copy Markdown
Contributor

Draw run on hardware — RX 9070 XT, driver 32.0.32029.2010:

mesh_pipeline_ms=0.167
pixels=1024 mismatches=0     (six times, one per threshold)
mutant: own flag only / flipped branch / 32-bit mask compare

The six thresholds each draw the full quad when a wave has a live lane, and all 1024 pixels match; the three mutants are rejected, so the check separates the any-lane flag from a per-lane one.

Limits: AMD only, no NVIDIA; mesh pipelines are the one path WARP does not implement, so there is no second adapter to compare against here.

AI-assisted.

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

I replayed the same 32 local mesh-stage samples through lower() on main e94e14ff and this head 8b77c25f. The comparison used the bounded two-wave evaluator with identical synthetic geometry inputs. Branch displacements were decoded as signed instruction immediates and checked against their byte targets. Main stopped at s_cbranch_scc1 in all 32. This head reached the LDS store on the wave-zero path and stopped at s_waitcnt_depctr in all 32. No complete shader or pixel result is claimed.

The shared pattern is a single-lane LDS store in one wave and a read in another, with distinct static barrier instructions on the two branches. This makes the existing cross-wave LDS scheduling valuable to the slot 57 follow-up. A source-built control for the observed dependency-counter wait and barrier pair would test the next step without adding a broad wait-as-no-op fallback. Runtime tracking

Model LDS publish, s_barrier and SCC branches (s_cbranch_scc0/scc1, 64-bit
s_cmp) in the two-wave64 mesh interpreter, with precise refusals. Adds a CPU
check and a WARP/hardware draw check with mutant controls.
…in mesh lowering

Check all waves against all staged stores before clearing any, validate the final interval, and refuse vector destinations with an unwaited LDS read.

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Follow-up to the two-wave LDS review above. I published the wait and barrier follow-up on an integration branch with #2253 and both commits from this PR, preserving their authorship. The follow-up depends on both PRs and main's retired-wave handling from #2241.

For gfx1013, s_waitcnt_depctr 0xffe3 retires the tracked VM_VSRC source-register dependency. The model continues to track LDS completion with lgkmcnt(0) and publishes only when live waves reach the same barrier. The source-built two-wave control reads the original stored word after the producer overwrites the source register. The controls for an absent dependency wait, a different immediate, missing store and load completion waits, and different static barrier instructions each refuse. RDNA 2 ISA §§4.3, 4.4, 12.5

python -B tests/mesh_scc_any_lane_check.py, python -B tests/mesh_dynamic_geometry_check.py, python -B tests/mesh_dynamic_aot_check.py, and python -B tests/startup_gfx2hlsl_watch_check.py passed. The 19-instruction source-built control decoded identically in the checked-in decoder and the LLVM 15 disassembler. The translated draw control (python -B tests/mesh_scc_any_lane_draw_check.py <dxc> <offscreen_check> <warp|hardware>) matched 1,024/1,024 pixels on WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 under Windows 11 build 26200.9974, with no D3D12 debug errors or warnings.

@R0Y00

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

I merged main into the PR branch at 59a1189c. The CMake conflict now retains both the SCC any-lane tests and #2244's two-exit tests. Six host-side suites passed. With the D3D12 debug layer enabled, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 each matched all 1,024 pixels at all six thresholds and detected the three mutations. This verifies the existing SCC fixture. The dependent wait/barrier follow-up linked above still has its own acceptance checks.

@R0Y00
R0Y00 enabled auto-merge (squash) November 25, 2026 08:30
@R0Y00
R0Y00 merged commit a540a47 into R0Y00:main Nov 25, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants