Skip to content

shader: carry pre-branch EXEC mask subset facts into compute execz blocks (#2645 T1) - #2877

Merged
pigalot merged 2 commits into
R0Y00:mainfrom
stan495:startup/compute-execz-mask-subset
Nov 28, 2026
Merged

pigalot merged 2 commits into
R0Y00:mainfrom
stan495:startup/compute-execz-mask-subset

Conversation

@stan495

@stan495 stan495 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Implements compute: prove a loop break inside a block s_cbranch_execz skips (task list) #2645 T1 (mask subset facts) in [\ ools/startup/gfx2hlsl.py](tools/startup/gfx2hlsl.py) (\subset_after, \Stage.execz_refusals):
    • Computes forward must-dataflow of pre-branch mask-subset facts (\sM <= EXEC) across scalar instructions and CFG joins (propagated across bitwise mask instructions via \clear_after, seeded on \s_mov_b32/64 exec, sM\ and non-narrowing ORs, cleared on narrowing/unproven \EXEC\ writes, non-subset rewrites, indirect scalar writes, and joins lacking the fact on any incoming path).
    • Seeds \�efore[b + 1]\ in \Stage.execz_refusals\ with those proven pre-branch subset facts alongside \EXEC_SUBSET\ (('exec', 0), ('exec_hi', 1)), while keeping \EXEC_SUBSET\ as the per-step \exec write\ check invariant so overwritten saved masks cannot be re-injected inside the skipped block.
    • Keeps compute: prove a loop break inside a block s_cbranch_execz skips (task list) #2645 T2\ (\loop exit crosses a backward s_cbranch_scc0), \T3, and \T4\ refused untouched.
  • Adds regression tests, DXC \cs_6_0\ dispatch case \O-loop-subset, and negative control \o-subset-remask-dropped\ in [\ ests/startup_gfx2hlsl_compute_check.py](tests/startup_gfx2hlsl_compute_check.py), [\CMakeLists.txt](CMakeLists.txt), and [\docs/experiments.md](docs/experiments.md).

Test environment & results (commit \33b4e3d0)

  • Host: Windows 11 (\10.0.26200.9974), DXC \1.8.2502.11, D3D12 debug layer enabled (\dev\ preset)
  • Adapters: WARP (\Microsoft Basic Render Driver, \1414:008c, driver \10.0.26100.9818) and \AMD Radeon RX 7900 XTX\ (\1002:744c, driver \32.0.32029.2010)
  • .\out\pe-env\Scripts\python.exe -B tests/startup_gfx2hlsl_compute_check.py: passed (wave vs singleton trace agreement + near-miss disagreement, \O-loop-subset\ + pre-branch \s_and/\s_mov\ subset cases, \LOOP_BREAK_WORDS\ keeping \

@stan495
stan495 force-pushed the startup/compute-execz-mask-subset branch from eb09b2f to 33b4e3d Compare November 26, 2026 16:03

Copy link
Copy Markdown
Contributor

Independent T1 check at 33b4e3d07b980a9c339a0a0cb56359c40abb07de. The pure-Python startup_gfx2hlsl_compute_check.py controls passed, including the original loop-break fixture that still reports the T2 boundary. I ran O-loop-subset directly through run_case() with MSVC Release offscreen_check (the --compute-store-case path is unchanged) and SDK DXC 1.9.2602.17 on Windows 26300.10075. All 320 words matched on in-box WARP 10.0.26100.10068 and physical RTX 4070 32.0.16.2124, with zero debug errors or warnings and no skips. The registered o-subset-remask-dropped mutation differed at exactly three words on both adapters, beginning with word=0 expected=00000009 actual=00000001.

@KelboLive KelboLive 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.

Complex and correct. This PR introduces subset-after tracking (#2645 T1) to prove that scalar words assigned from EXEC before an s_cbranch_execz carry a subset guarantee (sM <= EXEC), which prevents the translator from refusing exec writes inside the skipped block when the assignment is provably safe.

A few observations:

  1. subset_after() handles four categories cleanly:

    • Indirect scalar writes (s_movrel*) drop all non-EXEC facts
    • Bitwise mask instructions propagate via clear_after
    • EXEC writes: drop written wave half unless a move assigns EXEC from a scalar mask word or OR widens EXEC with a bitmask
    • Otherwise keep subset facts surviving clear_after on un-written halves
  2. The fixed-point iteration in execz_refusals() (pre_sub propagation) correctly merges joins via intersection, which is the right lattice operation for subset tracking.

  3. The test harness is comprehensive: subset_after() unit checks, accepted setups (pre_and_copy, pre_mov), near-miss controls (narrowed_saveexec, narrowed_cmpx, overwritten_before/inside, join_one_arm), and the binary o-subset-remask-dropped test. The bad_wave vs bad_singles disagreement check (lane 1 skips in singleton but enters via stale mask in wave) is an excellent mutation test.

  4. One potential concern: the fixed-point loop runs in place over pre_sub without an explicit termination condition beyond changed=False. For very large basic blocks this could be slow, though the fact lattice is small (EXEC_SUBSET + at most ~4 scalar words), so it terminates quickly in practice. Worth noting in a comment for future readers.

Looks solid. This is a quality addition to the translator safety guarantees.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I tried to review 33b4e3d0 over current main 454fc0ed. The trial merge conflicts in docs/experiments.md. Since this PR's base b505c32b, main has added entries there in #3010, #2882, #2871, #2829 and #2857. The other three files merge cleanly.

I'll review it once it is updated with main.

This reply was AI-assisted.

Resolved conflicts:
- docs/experiments.md
@pigalot

pigalot commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

I merged main 50e4f763 into this branch as f4bf0949. The push fast-forwards from 33b4e3d0; there was no rebase and no force-push.

Conflict and resolution.

  • docs/experiments.md. This branch adds its subset_after paragraph to the end of the section before "Startup compute formatted buffer reads". main inserts the new "Scalar run before the EXEC restore at a compute exit target (compute: prove a loop break inside a block s_cbranch_execz skips (task list) #2645 T3)" section in the same place. I kept both: this branch's paragraph stays at the end of its section, and main's section follows it.

tools/startup/gfx2hlsl.py and tests/startup_gfx2hlsl_compute_check.py merged without conflicts. Both sides change execz handling in compute stages (T1 here, T3 on main), so I ran the whole startup_gfx2hlsl_* set.

git diff --check origin/main...HEAD is clean.

What I ran. I built everything in dev and release (/O2), then ran

ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '^startup_gfx2hlsl_' -E '_hardware$'
python with_gpu_lock.py ctest --test-dir out/build/<preset> --no-tests=error -j 1 -R '^startup_gfx2hlsl_.*_hardware$'
  • Debug: non-hardware 270/270 pass; _hardware 117/117 pass.
  • Release: non-hardware 270/270 pass; _hardware 117/117 pass.
  • No skips in either preset.

These runs include this branch's startup_gfx2hlsl_compute_o-subset-remask-dropped_{warp,hardware} and startup_gfx2hlsl_compute_controls.

This needs a re-review from someone else. I won't review or merge it myself.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0 DXC (the one CTest picked up); Python 3.12.10.

This reply was AI-assisted.

@pigalot pigalot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed f4bf0949 (c's merge of main) integrated over current main f41806a9. The merge is clean (tree 371d047d) and git diff --cached --check is clean.

What I traced. subset_after is a forward must-analysis of sM <= EXEC facts. It is seeded by a s_mov of EXEC into an SGPR pair and kept across a s_mov/s_or/s_or_saveexec into EXEC only when the OR keeps an EXEC source word. It is dropped on any other EXEC write, on a write to the fact's word, on s_movrel*, and at a join that lacks it on any edge. execz_refusals seeds the skipped block's entry with those facts, while the per-instruction exec write check still compares against EXEC_SUBSET alone. So a saved mask that is overwritten inside the skipped block can't be restored as a subset. c's docs/experiments.md resolution keeps both sides, and main's T3 work doesn't touch entry.

What I ran.

  • Builds: full dev and release /O2.
  • CPU: ctest --test-dir out/build/<preset> --no-tests=error -j 8 -R '^startup_gfx2hlsl_' -E '_hardware$': 270/270 pass in Debug and in Release.
  • Hardware: ctest --test-dir out/build/dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_compute.*_hardware$': 34/34 pass, with no skips. On the earlier trial over 0fe4cebc the same 34 also passed in release.
  • Full suite: ctest --test-dir out/build/dev --no-tests=error -j 8 -E '(startup_audio|_hardware$)' gives 2016 tests: 1956 pass, 1 fails and 59 are capability skips.
    • The failure is xmem_lazy_commit_off, which passes 5 of 5 runs alone at -j 1.
    • On the earlier trial over 0fe4cebc, the one full-run failure was startup_storage_alloc_failure. Alone at -j 1 it failed 1 of 13 runs.
    • This PR changes only the translator, one Python check, CMakeLists.txt and the docs, so I read both as unrelated intermittent failures.
  • End to end: I spliced s_mov_b64 s[22:23], exec before the branch and s_mov_b64 exec, s[22:23] inside the skipped block. The baseline is accepted, and so is an s_or_b32 exec_lo, exec_lo, s30 widening before the branch.

Mutants of tools/startup/gfx2hlsl.py, each run against tests/startup_gfx2hlsl_compute_check.py after an unmutated baseline that passes:

Mutant Result
pre-branch facts ignored (entry = EXEC_SUBSET) killed (O-loop-subset refused)
join takes the union, not the intersection killed (hangs; the fixpoint never settles)
a non-EXEC write keeps facts on the written word killed
s_movrel* keeps all facts killed
an EXEC write keeps facts on the written half killed
an OR widening isn't recognised killed
s_mov into EXEC adds no source fact killed
the in-block step re-adds the pre-branch facts killed (o-subset-remask-dropped)
the in-block exec write check uses the entry facts killed
any OR into EXEC is treated as a widening survives

Restored afterwards; git diff --quiet is clean.

Non-blocking.

  1. A non-widening OR into EXEC isn't pinned. With the any(...) test replaced by True, s_or_b32 exec_lo, s1, s2 would keep every sM <= EXEC fact, though the new EXEC needn't contain the old one. The code drops the facts correctly today; a near-miss control with that instruction before the branch, which must refuse, would pin it.
  2. The OR check compares the source word with the wrong half. src[p] == ('exec', 'exec_hi')[p] tests source word p against EXEC half p, not against the destination half. For s_or_b32 exec_hi, exec_lo, s30, word 0 is exec_lo, so it counts as a widening and the (s23, 1) fact is kept, but exec_hi = exec_lo | s30 needn't contain the old exec_hi. I checked this by calling subset_after directly. It isn't reachable end to end today: the translator refuses s_or_b32 with destination exec_hi (operand 'exec_hi'). Comparing each source word with the destination word would close it before that destination is ever accepted (unconfirmed suggestion).

Verdict: approve on f4bf0949.

Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088; Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; DXC 1.9.2602.17; Python 3.12.10; wave32; debug layer off.
CI: Build and test on Windows, Assemble and translate gfx1013 fixtures and Run platform-independent Python checks on Linux pass on f4bf0949.

This reply was AI-assisted.

@pigalot
pigalot merged commit 32221f1 into R0Y00:main Nov 28, 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.

4 participants