startup: recompute uniform v_readfirstlane_b32 sources past the entry block #2195
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2203"
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-25T04:32:27Z.
Change
Part of #1723. Follows #1931, #2153 and #2183.
Since #2183,
v_readfirstlane_b32in a program with branches is proven only in the entry block. Past it, every read is still refused. Thereexecis usually unknown (after an else arm, a WQM toggle or a restore). Copying this lane's VGPR is then wrong for a lane that was inactive at the definition, because its VGPR still holds an older value.This change lowers such a read to the uniform expression that defined the VGPR, rebuilt from scalars and constants. For example, after
v_mul_f32 v7, s3, 2.0the read becomess9 = U(F(s3) * 2.0);.Why the value is right. The hardware returns
vSfrom the first active laneLat the read. IfLran the definitionvS = E(x), thenvS[L] = E(x), wherexis a set of SGPRs and constants. Ifxis unchanged since the definition, every lane can computeE(x)from its own scalar copies.Lran the definition when, between the definition and the read:execwrite. That covers explicit writes,saveexec,wrexec,v_cmpx, WQM,s_movreldand any write tos[126:127]. Soexecat the read equalsexecat the definition, andLwas active at the definition. Narrowing is refused as well as widening, which is stricter than needed.vS. This is the existing overwrite rule.Ereads. VOP3b carry-out and division-scale destinations count as writes, ands_movreldcounts as a write to every SGPR.E. An SCC from before the last branch target is not trusted.The definition may run under any
exec, because the read never looks at an inactive lane's VGPR copy. The one case where hardware can differ is a read with no active lane. The ISA then returns lane 0's VGPR, which compiled code cannot rely on.Unchanged:
s_endpgmin a branch-free program stays refused.What it enables: reads in later blocks whose defining expression is uniform and unchanged since the last join. Reads whose scalars come from before the last join stay refused.
Sites that read a
v_med3_f32result also need the separate change that addsv_med3_f32to the uniform set. This branch does not depend on it.Relation to #2060 (open, tedin7, head
c346072c, reviewed for this draft): #2060 also proves reads past the entry block, on different conditions.execwritestainted_s) marks themexecwrite. There each accepts reads the other refuses.uniform_sourceunconditionally, so it would also refuse pre-join scalars that #2060 trusts. If both land, the since-join test should apply only where #2060's proof does not.docs/experiments.mdparagraph.execsomewhere.Verification
Run on
fd457299(origin/main) plus this branch (051b0919, then14411478after review).origin/mainat19e04be9merges without conflict.python -B tests/startup_gfx2hlsl_readfirstlane_recompute_check.py:Readfirstlane recompute checks: 0 failed.python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py:Readfirstlane uniformity checks: 0 failed. The case "read after the first terminator" moves from refused to recomputed, which is the intended change.python -B tests/startup_uniform_lane_check.py: passes.python -B tests/startup_gfx2hlsl_op_refusals_check.py:gfx2hlsl op refusals: 3 cases passed.python -B tests/docs_links_check.py: passes.git diff --check origin/main...HEAD: clean. The changed files are LF in the index.CMakeLists.txt(startup_gfx2hlsl_readfirstlane_recompute), the platform-independent Python job in.github/workflows/windows.yml, andAGENTS.md.All 18 mutants of the rule fail the two checks:
execwrite keeps expressionss_movreldwrites nothingv_cmpxnot counted as anexecwriteexectest sees only the first destinationexecrange off by ones_endpgmrecomputedLocal measurement, not reproducible from the repository: 266 graphics pipelines used by indirect draws in one captured frame, plus 117 cached requests from other local runs, 383 requests in all.
translate_request). The 75 requests that translated before give byte-identical HLSL.request_refusals): 160 requests lose at least one refused read, and no request gains one. Refused read sites drop from 616 to 438. In this mode an unsupported instruction is skipped, so its VGPR write is not seen. Some reads counted as cleared may therefore read an overwritten source. The first-refusal results and the byte-identical translating requests are the firm numbers.Evidence and follow-up
The fixture is hand-written disassembly text. It is not taken from any title.
tests/startup_gfx2hlsl_readfirstlane_recompute_check.pyaccepts:execnarrowing or restore before the definitionIt refuses:
execwrite between definition and read: widened (a definition under a narrowerexecthan the read), narrowed,v_cmpx, WQMexecwriteIt also covers the SGPR writes that do not go through the first operand, and the
execwrite detector on every destination operand (a VOP3b carry-out intoexec_loincluded).Follow-up, not in this change:
buffer_load_format_x v0, off, ...) need a proof for that load. The proof depends on how the formatted load is lowered; #2138 is open.docs/experiments.md(uniform sources ofv_readfirstlane_b32) states the rule. Reproduce with:Checklist
AI-assisted (Claude Code). All commands above were run locally.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:39:00Z.
Review: COMMENTED
Review of head
144114786037f15f95ca40d1090e6c85fba64e4c(comment only, no approval).Summary: the approach is sound. Past the entry block,
v_readfirstlane_b32is lowered to the uniform expression that defined the VGPR, rebuilt from scalars and constants. This avoids copying a stale lane VGPR. No P1 or P2 findings.Checks run locally (Linux):
git diff --stat origin/main...HEAD: 7 files, +231/-9. Title is neutral, and the diff has no model names or probe mentions.python3 tests/startup_gfx2hlsl_readfirstlane_recompute_check.py:0 failedpython3 tests/startup_gfx2hlsl_readfirstlane_uniform_check.py:0 failedtests/startup_gfx2hlsl*.pyscripts: exit 0python3 tests/docs_links_check.py: passed (18 files, 405 links)python3 tests/bidi_controls_check.py: passedgit diff --check origin/main...HEAD: cleangh pr checks): Linux checks, gfx1013 fixtures and Windows build/test are green./O2and chart jobs were skipped. The PR is mergeable.Mutations (each reverted with
git checkout -- .), all killed by the new test:uniform_v.clear()at a join: 2 faileduniform_expr.clear()on an EXEC write: 4 failedsince_joinguard inuniform_source: 5 faileddestinations): 3 failedLogic read:
forget_writes, the join reset andset_v/swap.v_swap_b32moves the expression together with the uniform mark. Good.forget_writestreats operand 0 ofs_store_*-style instructions as a destination. This is conservative (it only drops proofs), so it is safe.since_joinadds an SGPR only whenset_sproves it uniform. An SGPR written by an unmodelled path is dropped byforget_writes. This is correct, but a one-line comment on that invariant nearset_swould help future readers.Not run: no Windows WARP run. The change is Python-only lowering inside
gfx2hlsl.py, and it only adds refusals or exact scalar expressions. The PR body and CI show the Windows suite passing. A real D3D12 readback of the recomputed expression is still the gate before Ready, as per the project process.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:52:30Z.
Review: COMMENTED
Re-review of head
a30e744c65388d19e525463b02899f989f7c5770(comment only, no approval).What changed since the previous review (
14411478): only a merge oforigin/main. The PR's own files are unchanged:tools/startup/gfx2hlsl.pyand bothtests/startup_gfx2hlsl_readfirstlane_*_check.pyare identical, and the earlier nit (comment on thesince_joininvariant nearset_s) is now in the code. My earlier findings still stand: no P1, no P2.Checks run locally (Linux):
git diff --stat origin/main...HEAD: 7 files, +233/-9. Title is neutral. The diff has no model names.python3 tests/startup_gfx2hlsl_readfirstlane_recompute_check.py:0 failedpython3 tests/startup_gfx2hlsl_readfirstlane_uniform_check.py:0 failedtests/startup_gfx2hlsl*.pyscripts: exit 0python3 tests/docs_links_check.py: 18 files, 406 links OKpython3 tests/bidi_controls_check.py: OKgit diff --check origin/main...HEAD: cleangh pr checks: Linux checks, gfx1013 fixtures and the Windows build/test are green. The/O2and chart jobs are skipped. The PR is mergeable.Mutation (reverted with
git checkout -- .):uniform_v.clear()at a join withpass: the recompute test reports2 failed, so it is killed. The other mutations from the previous review were not re-run, because the logic is byte-identical.Not run: no Windows WARP run in this review. The Python-only lowering is unchanged since the last review and CI Windows is green on this head. A real D3D12 WARP readback of the recomputed expression remains the gate for the project's process.
Nit: the PR is currently not Draft. If the Win2025 WARP gate has not passed on this head, consider converting it back to Draft first.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T04:47:21Z.
Merged current
maininto the branch (a30e744c): the one conflict was a single line inset_v, where this change's capture of the last definition met the low-16 bookkeeping added by #2139; both are kept. The D16image_loadpath writes throughset_v, so proofs are dropped there as for any other VGPR write. Also added the requested one-line comment nearset_son thesince_joininvariant.Re-run on the merged head: the registered recompute check and the readfirstlane, uniform-lane and op-refusals checks pass, all 18 mutants are still killed,
git diff --checkis clean, and translator output is unchanged on the local sample.AI-assisted (Claude Code).