Repository navigation
startup: keep or refuse non-constant scalar symbols at joins in gfx2hlsl - #2292
Conversation
tedin7
left a comment
There was a problem hiding this comment.
Review of head 5e6ec7abcef0b8ce5ddefaf3f2959b7d52492976 (comment only).
Scope / overlap. #2279 (scalar constants at joins) is already merged and this PR is a follow-up on top of it: it keeps join_writes as is and adds a basic-block/dominator joined_registers() plus a symbol meet at joins. No duplicate coverage with #2279. Its test (startup_gfx2hlsl_loop_constants_check.py) still passes on this head. Title is neutral, MIT/clean-room looks fine, mergeable. Branch is 2 commits behind main (25317c63); no conflict reported.
CI: Windows build+test, Linux Python checks, gfx1013 fixtures all pass; /O2 and chart jobs skipped.
Commands run locally on the head:
python3 tests/startup_gfx2hlsl_join_symbols_check.py-> PASSpython3 tests/startup_gfx2hlsl_loop_constants_check.py-> PASSpython3 tests/docs_links_check.py-> 18 files, 436 links OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> clean
Mutations (both killed):
names_one_valuefordescchanged toreturn True-> new fixture fails on themodified-desc /descnumassertion.- Dropped the "later block branches back" term in
joined_registers(b in reach and b >= t) -> new fixture fails (23 in joined_registers()[0xc]).
Findings
- P1: none.
- P2: none.
- nit (
tools/startup/gfx2hlsl.py,names_one_value): equalptrsymbols are treated as one value althoughs_add_u32on a pointer keeps the symbol. The PR documents this as a known gap (exists on main, #2069). Fine to leave. - nit (
Stage.__init__retranslate loop): termination relies on the monotone kept -> run -> refuse order; the dict only grows, andrefusalsis truncated per pass. No change needed. - nit: the new fixture checks exact indented lines, so it will need a touch-up if #1631 lands first (already noted in the body).
Not run: Win2025 WARP. The change is scalar symbol tracking in the Python translator (no new math lowering needing a GPU-readback comparison), and the Windows CI job passed.
AI-assisted; commands listed were executed locally.
|
I reproduced the host checks on |
stan495
left a comment
There was a problem hiding this comment.
Verified head 5e6ec7abcef0b8ce5ddefaf3f2959b7d52492976 on Windows 11 (26200.9974).
Reviewed the tools/startup/gfx2hlsl.py diff (joined_registers(), names_one_value(), run_time_symbol(), scalar_destinations(), and the bounded Stage.__init__ re-translation loop). The dominance + back-reachability check soundly separates writes above the join from loop-body/back-edge writes, keeps only symbols proven identical across all incoming paths, and terminates cleanly.
Ran locally on 5e6ec7ab:
python -B tests/startup_gfx2hlsl_join_symbols_check.py-> passed (loop counters, forward joins, a root-constant loop, 64-bit copies and descriptor joins pass; equal symbols on every path are kept; straight-line code still folds)python -B tests/startup_gfx2hlsl_loop_constants_check.py-> passed (PASS)python -B tests/startup_translator_check.py-> passed (startup translator checks: 0 failed)- All
tests/startup_gfx2hlsl_*_check.pychecks -> passed python -B tests/docs_links_check.py-> passed (18 files, 436 links)python -B tests/bidi_controls_check.py-> passed (1585 tracked files)git diff --check upstream/main...HEAD-> clean
No P1/P2 findings. Approve on 5e6ec7abcef0b8ce5ddefaf3f2959b7d52492976.
Follow-up to R0Y00#2279. Work out the joined registers over the basic blocks and dominators (a proven s_setpc_b64 is an edge). At a join, a register keeps a symbol every path agrees on, reads a constant at run time, and refuses a read when a path brings a descriptor word, pointer or unplaced register. A 64-bit copy assigns its high word at run time. Adds a pure-Python and dispatch check. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…sets in gfx2hlsl A register that holds a non-run-time symbol on one edge into a branch target and has no definition on another is unproven there, so a later read is refused instead of using the symbol of the path that never ran. An add on a pointer now marks its symbol 'added', and only an untouched pointer names one value at a join. DESC_ONE_PATH becomes a refusal control; PTR_OFFSETS is new. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The join-symbol lowering changes the generated HLSL for programs with joins, so translations cached under revision 9 are not reused. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
5e6ec7a to
aa17c95
Compare
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head aa17c95646683d3895f417e00264758a071c6429 (previous review covered 5e6ec7a).
Result: no P1, no P2. Two optional nits.
What changed since 5e6ec7a
75053419(tools/startup/gfx2hlsl.py, join code): a register that holds a non-run-time symbol on one edge into a branch target and has no definition on another edge now gets('joined at a branch target',). That means a later read is refused, and the symbol from the path that never ran is not used.- Same commit:
s_add_u32on aptr/ptrhisymbol now marks it('ptr', src, 'added').names_one_valueacceptsptr/ptrhionly whenlen(sym) == 2, so only an untouched pointer counts as one value at a join. This closes the old "equal ptr symbols" shortcut. aa17c956: cache revision moved tox2w-startup-shader-10. I checked every site:d3d12_draw.inl:235,355,tests/startup_indirect_draw_indexed.cpp:235,gfx2hlsl.py:4300,4309,startup_compute_request_offline_check.py:33anddocs/startup-runtime.md:192all agree.- Test and docs:
DESC_ONE_PATHis now a refusal control,PTR_OFFSETSis new, and theexperiments.mdtext matches the code.
Commands run locally on the PR head (Linux)
python3 tests/startup_gfx2hlsl_join_symbols_check.py: passes (equal symbols on every path are kept, straight-line code still folds).- Neighbours, all exit 0:
startup_gfx2hlsl_{loop_constants,refusals,compute,scalar_m0,root}_check.py,mesh_join_descriptor_check.py,startup_compute_request_offline_check.py,startup_build_rev_check.py. python3 tests/docs_links_check.py: 18 files, 446 links OK.python3 tests/bidi_controls_check.py: OK.git diff --check origin/main...HEAD: clean.- CI on this head: Linux Python checks, gfx1013 fixtures and Windows build/test pass. The
/O2and coverage jobs were skipped.
Mutations (each restored with git checkout -- .)
names_one_valueacceptsptr/ptrhiof any length: killed byPTR_OFFSETS(accepted, expected a refusal).- The new "edge with no definition" branch disabled (
if False:): killed byDESC_ONE_PATH. - The
'added'mark removed from the add handler: killed byPTR_OFFSETS.
Nits (non-blocking)
- The pointer-add handling relies on
len(own) > 2meaning "already marked". If a third tuple field is ever added toptrsymbols, this check breaks quietly. A named helper or constant would make that safer. - The "no definition at all" case only has coverage through
DESC_ONE_PATH(descriptor words). A pointer-symbol variant would pin the other symbol kinds in that branch.
Windows: I did not queue a Win2025 run. The change is translator-side symbol tracking, and the Linux pure-Python tests plus the existing WARP dispatch in CI cover it. Clean-room and title-neutral checks pass, and the PR is mergeable.
AI-assisted; commands listed were executed locally.
|
Done in aa17c95 (rebased on main 5fa712e). A register that holds a symbol with no run-time value on one edge and no definition on another is now unproven at the join, and a later read is refused. AI-assisted (Claude Code). |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 78a1cd09347d89328e70f5710da55392fd736f2d (comment only).
Scope read: git diff --stat origin/main...HEAD (10 files, +598/-31). I read the gfx2hlsl.py join logic (joined_registers, names_one_value, run_time_symbol, scalar_destinations, the Stage.__init__ retranslation loop and the join handling in translate). The title is neutral, the PR is mergeable, and I saw nothing that breaks clean-room rules. At review time the CI checks were still pending.
Commands run locally on this head:
python3 tests/startup_gfx2hlsl_join_symbols_check.py: passes.python3 tests/startup_compute_request_offline_check.py: passes.python3 tests/docs_links_check.py: passes (18 files, 447 links).python3 tests/bidi_controls_check.py: passes (1600 files).git diff --check origin/main...HEAD: clean.
Mutations of the new logic (each reverted with git checkout -- .):
names_one_valuetreats everyptr/ptrhias one value (drops thelen(sym) == 2guard). Killed by the PTR_OFFSETS case.joined_registers: theabove_dominatorstextual-order check is disabled (if False:). Survived: the join-symbols check still passes.joined_registers: the loop-body and later-block write set (b in reach and b >= t) is disabled. Killed.
Findings
- P1: none.
- P2 (1): the textual-order guard in
joined_registers(theabove_dominators/zip(above_dominators, above_dominators[1:])check) has no test that fails when it is removed. This is the path where dominating blocks sit out of execution order. Please add a fixture where a dominator block is placed after its dominated block, or drop the guard if it cannot happen. - Nit:
translate()readsjoined_registers()throughgetattr(self, 'calculated_pc', {})andgetattr(self, 'force_joined', {})for unit probes that skip__init__. This works, but it adds code that exists only for tests. A small Stage factory in the test would be cleaner. - Not verified: no Windows WARP run. The change is a Python-only translation-state change plus a shader cache revision bump, so I judged the Linux checks enough for this review. Final Windows proof is left to the CI and the gate.
AI-assisted; commands listed were executed locally.
Change
Follow-up to #2279. That change drops scalar constants at a branch target that another path writes, over the
textual range between a branch and its target (proven
s_setpc_b64jumps included). It leaves every other symbolunchanged, and two cases in the emitted HLSL stay wrong on main
342d3fa9:descriptor word overwritten on one path is read as a register nothing assigned; an unplaced compute user SGPR
written on one path is read as if placed; the high word of a 64-bit copy is never assigned, so a register
written on only one path reads 0 on the other.
(
s25 = s25 + 0x00000001u;on main, where the hardware adds 1, then 5 twice).What changes (
tools/startup/gfx2hlsl.py, upstream'sjoin_writesis kept as it is):proven
s_setpc_b64is an edge and ends its block, likes_branch; an unproven one adds no edge.one value (a descriptor reloaded from the same table slot, for example). Otherwise it is read at run time when it
holds a constant, and refuses any read before its next write when a path brings a descriptor word, a pointer or
an unplaced register. A path that never wrote the register brings nothing.
stage translate again with that register read at run time, or refused, at the header.
Not covered:
names_one_valuetreats equalptrsymbols as one value althoughs_add_u32on a pointer keeps thesymbol (exists on main; open PR #2069 addresses it). A register written through
s_movrel*counts as writingevery SGPR, which only costs folding.
Overlapping open PRs: #1631 (loop structure in gfx2hlsl) and #2069 touch the same
Stage.translatearea; theexact-indented-line checks in the new fixture will need #1631's indentation if it lands first.
AI-assisted (Claude Code).
Verification
Verification (head aa17c95, rebased on origin/main 5fa712e; Windows, Python 3.13):
python -B tests/startup_gfx2hlsl_join_symbols_check.pypasses.DESC_ONE_PATH(the branch skips the onlys_load_dwordx8that writess[16:23]) and the newPTR_OFFSETS(two paths add 4 and 8 to the same pointer) arerefusal controls;
DESC_SAMEis still accepted and kept.join, and a later read is refused. An add on a pointer marks its symbol
added, and only an untouched pointer namesone value.
DESC_ONE_PATHfail (accepted); dropping theaddedmarkmakes
PTR_OFFSETSfail.tests/startup_gfx2hlsl_*_check.py(53 scripts withstartup_translator_check.py),startup_compute_request_offline_check.py(pinned key recomputed),docs_links_check.py,bidi_controls_check.pypass;git diff --check origin/main...HEADis clean.x2w-startup-shader-10in a separate commit, in the files startup: move the shader cache revision to x2w-startup-shader-9 #2299 touched. The C++ change intests/startup_indirect_draw_indexed.cppis textual and was not built.binaryreassembly of the two new fixture words(no
llvm-mclocally; PTR_OFFSETS words are hand-encoded).Evidence and follow-up
startup_flat_param_check.py; thecompute stage uses the root of
startup_gfx2hlsl_compute_check.py. No retail bytes.startup_gfx2hlsl_join_symbols_folded_*runs the dispatch with the oldOUTSIDEstatement and must give 3, not 11. With this branch's
gfx2hlsl.pyreplaced by main's, the pure-Python checkfails at
DESC_CALC accepted, expected a refusal.binarymode (fixture words against LLVM 15) was not run here, there is nollvm-mconthis machine;
DESC_CALC's words are hand-encoded. The cache effect (graphics and compute requests) was notre-measured on this base.
Checklist
🤖 Generated with Claude Code