startup: keep or refuse non-constant scalar symbols at joins in gfx2hlsl #2284
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2292"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T10:24:57Z.
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
aa17c956, rebased on origin/main5fa712ee; 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 #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
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:29:53Z.
Review: COMMENTED
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_writesas is and adds a basic-block/dominatorjoined_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-> cleanMutations (both killed):
names_one_valuefordescchanged toreturn True-> new fixture fails on themodified-desc /descnumassertion.joined_registers(b in reach and b >= t) -> new fixture fails (23 in joined_registers()[0xc]).Findings
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.Stage.__init__retranslate loop): termination relies on the monotone kept -> run -> refuse order; the dict only grows, andrefusalsis truncated per pass. No change needed.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.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T11:01:30Z.
I reproduced the host checks on
5e6ec7ab. One join case still needs a decision in the implementation before this lands:DESC_ONE_PATHsetss30 = 0and takes the branch over the onlys_load_dwordx8that writess[16:23], then consumes that descriptor at the target. The check currently requires translation intor0.Load, so the generated shader reads an apparently valid texture using provenance from the predecessor that never executed. Please treat a missing descriptor definition on a reaching edge as unproven, or prove the edge cannot reach the use. Turn this fixture into a refusal control and keep the existingDESC_SAMEacceptance check. Also keep distinct pointer offsets separate if their symbolic tuples compare equal. Once the lowering is settled, the cache key needs to cover the resulting generated code.Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T11:14:48Z.
Review: APPROVED
Verified head
5e6ec7abcef0b8ce5ddefaf3f2959b7d52492976on Windows 11 (26200.9974).Reviewed the
tools/startup/gfx2hlsl.pydiff (joined_registers(),names_one_value(),run_time_symbol(),scalar_destinations(), and the boundedStage.__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)tests/startup_gfx2hlsl_*_check.pychecks -> passedpython -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-> cleanNo P1/P2 findings. Approve on
5e6ec7abcef0b8ce5ddefaf3f2959b7d52492976.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:31:41Z.
Review: COMMENTED
Re-review of head
aa17c95646683d3895f417e00264758a071c6429(previous review covered5e6ec7a).Result: no P1, no P2. Two optional nits.
What changed since
5e6ec7a75053419(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.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.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).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./O2and coverage jobs were skipped.Mutations (each restored with
git checkout -- .)names_one_valueacceptsptr/ptrhiof any length: killed byPTR_OFFSETS(accepted, expected a refusal).if False:): killed byDESC_ONE_PATH.'added'mark removed from the add handler: killed byPTR_OFFSETS.Nits (non-blocking)
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.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.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T11:45:45Z.
Review: COMMENTED
Review of head
78a1cd09347d89328e70f5710da55392fd736f2d(comment only).Scope read:
git diff --stat origin/main...HEAD(10 files, +598/-31). I read thegfx2hlsl.pyjoin logic (joined_registers,names_one_value,run_time_symbol,scalar_destinations, theStage.__init__retranslation loop and the join handling intranslate). 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
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.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.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T11:32:11Z.
Done in
aa17c956(rebased on main5fa712ee). 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.DESC_ONE_PATHis a refusal control;DESC_SAMEis still accepted and kept. An add on a pointer now marks its symbol, and only an untouched pointer names one value at a join;PTR_OFFSETS(add 4 vs add 8 on the same base) is refused. Disabling either rule makes its control fail. The shader cache revision moved tox2w-startup-shader-10in a separate commit. Not run: the llvm-mc binary check (the new fixture words are hand-encoded) and the WARP/hardware dispatches.AI-assisted (Claude Code).