shader: extend v_readfirstlane_b32 lowering to branched control flow in gfx2hlsl (Part of #1723) #2060
No reviewers
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows!2060
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2060/head"
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?
@tedin7 on GitHub · 2026-11-24 23:46 UTC · original
tedin7:x2w-r22-readfirstlane-branch→main· +165 −5 · 4 files · 4 commits · closed without mergingPart of #1723
What this unblocks: 719 draw refusals (v_readfirstlane_b32 with branches).
v_readfirstlane_b32was refused in any shader that has a branch. Now a source is proven uniform inside one basic block, even when the shader has branches elsewhere.exec/exec_lo/exec_hi,*saveexec*,v_cmpx*), soexec_knownholds on every path.Tests:
tests/startup_readfirstlane_branch_check.py, registered asstartup_readfirstlane_branchinCMakeLists.txt. It fails onorigin/mainand passes here. It also checks that a join between the proof and the read, and an exec write, are still refused.tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: the "branch after read" case moved from refused to accepted, which is the intended change.Verification: (local Linux run; Win2025 not run, this is a Python-only change)
python3 -B tests/startup_readfirstlane_branch_check.py: passes; the same file against the previousgfx2hlsl.pyraisesv_readfirstlane_b32 requires a proven uniform source.python3 -B tests/startup_gfx2hlsl_*_check.py,tests/startup_uniform_lane_check.py,tests/startup_ngg_slice_check.py: all pass.tests/startup_*_check.pyneed Windows probe binaries or arguments and were not run.AI-assisted; commands listed were executed locally.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:46 UTC · original · edited 2026-11-24 23:54 UTC
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
0cf2155ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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[bot] on GitHub · 2026-11-24 23:54 UTC · original
If a later block executes
s_andn2_wrexec_b32ors_andn2_wrexec_b64and branches back to an earlier producer/read block, this check still leavesproof_ok=True: these instructions write EXEC implicitly, but their destination is an SGPR and their names match none of these checks. The existing WREXEC handler setsexec_known=False, but only after the earlier block has already been proven and emitted without predication. Consequently, the newly accepted shader can execute that block under a changed mask despite its entry-mask assumptions. Include both supported WREXEC forms in the global EXEC-write check.Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:54 UTC · original
When a later compare block branches back to an earlier
s_cselect_b32 s2, 1, 0followed by a VGPR copy and first-lane read, the select's implicit SCC dependency is absent from this fixed point. For example,v_cmp_lt_f32intovcc_lofollowed bys_cmp_eq_u32 vcc_lo, 0makes the emitted HLSL SCC lane-dependent, yettainted_sremains empty andscc_uniformis still initially true when the earlier block is translated. A synthetic machine-code fixture therefore newly acceptss9 = v7even though its source varies between invocations at execution time. Include SCC producers and consumers in the whole-program proof, or conservatively refuse these reads.Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:54 UTC · original
When a later block copies a lane mask through
m0into an SGPR and then jumps back to an earlier producer/read block, this source list fails to taint the SGPR.reg_range('m0')also returnsNone, sov_cmpintovcc_lo, followed bys_mov_b32 m0, vcc_loands_mov_b32 s2, m0, leavestainted_sempty. An earlierv_mov_b32 v7, s2followed byv_readfirstlane_b32 s9, v7is consequently accepted, althoughs2is lane-dependent in the emitted HLSL when that block executes. Treatm0conservatively as non-uniform, asuniform_source()already does, or track its dependencies globally.Useful? React with 👍 / 👎.
@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:54 UTC · original
This change admits shaders containing branches, but
docs/experiments.md:11646still explicitly states that the read requires “a branch-free program”; neither that section nor the README is updated. This leaves the published support boundary incorrect. Update the capability description with the new block-local proof and EXEC restrictions and document the new branch fixture's reproduction command.AGENTS.mdexplicitly requires a README or experiments update whenever a public capability changes.AGENTS.md reference: AGENTS.md:L211-L212
Useful? React with 👍 / 👎.
@tedin7 on GitHub · 2026-11-25 01:00 UTC · original
Fixed in 454fd640 (rebased on main; push pending): WREXEC (s_andn2_wrexec_b32/b64) now disables the proof program-wide. Tests extended in tests/startup_readfirstlane_branch_check.py. AI-assisted; commands listed were executed locally: python3 tests/startup_readfirstlane_branch_check.py, startup_gfx2hlsl_readfirstlane_uniform_check.py, startup_gfx2hlsl_mad_check.py.
@tedin7 on GitHub · 2026-11-25 01:01 UTC · original
Fixed in 454fd640 (rebased on main; push pending): a per-lane SCC (compare fed by vcc/exec/tainted regs) now taints s_cselect/s_cmov/s_addc/s_subb destinations across backward edges. Tests extended in tests/startup_readfirstlane_branch_check.py. AI-assisted; commands listed were executed locally: python3 tests/startup_readfirstlane_branch_check.py, startup_gfx2hlsl_readfirstlane_uniform_check.py, startup_gfx2hlsl_mad_check.py.
@tedin7 on GitHub · 2026-11-25 01:01 UTC · original
Fixed in 454fd640 (rebased on main; push pending): m0 is now tracked as a tainted scalar in the whole-program scan. Tests extended in tests/startup_readfirstlane_branch_check.py. AI-assisted; commands listed were executed locally: python3 tests/startup_readfirstlane_branch_check.py, startup_gfx2hlsl_readfirstlane_uniform_check.py, startup_gfx2hlsl_mad_check.py.
@tedin7 on GitHub · 2026-11-25 01:01 UTC · original
Fixed in 454fd640 (rebased on main; push pending): docs/experiments.md now describes the block-local proof, the exec restrictions and the new test command. Tests extended in tests/startup_readfirstlane_branch_check.py. AI-assisted; commands listed were executed locally: python3 tests/startup_readfirstlane_branch_check.py, startup_gfx2hlsl_readfirstlane_uniform_check.py, startup_gfx2hlsl_mad_check.py.
@R0Y00 on GitHub · 2026-11-25 03:47 UTC · original
Please keep the merged #2183 entry-block proof when updating this PR. Exercise one accepted case per rule, with #2060's taint and CFG checks covering later blocks. Keep both refusal sets, especially entry loops and varying sources after a join.
@tedin7 on GitHub · 2026-11-25 04:11 UTC · original
Thanks @R0Y00. The branch is rebased and pushed as
c346072cb90fae2009386d3e1561e7c5fa911c6f(mergeable).Covered in this head:
tests/startup_readfirstlane_branch_check.py.Verification (Windows Server 2025, MSVC 14.44, D3D12 WARP, default 3-slot pool):
python3 x2w_pipe.py win2025 2060 --force --regex 'startup_readfirstlane_branch|startup_uniform_lane|startup_ngg_slice' --py-checks tests/startup_readfirstlane_branch_check.pyctest --preset dev): 3/3 passedctest --preset release): 3/3 passedtests/startup_readfirstlane_branch_check.py: okNote: the unfocused run failed because the generated command was too long for the Windows shell, so I ran the focused targets above.
AI-assisted; commands listed were executed locally.
@tedin7 on GitHub · 2026-11-25 06:18 UTC · original
Closing as superseded: the branched
v_readfirstlane_b32entry-block and post-entry-block lowering landed onmainvia #2183 and #2203.@chatgpt-codex-connector[bot] on GitHub · 2026-11-24 23:54 UTC · original · reviewed
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
0cf21551f9ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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".
@R0Y00 on GitHub · 2026-11-25 04:48 UTC · original · requested changes
At
c346072c, the branch proof misses values that vary through control flow. I ran a synthetic Stage input that compares varying v0 into VCC, branches on vccz, sets s7 to 1 on the fallthrough arm and 2 on the target arm, then joins forv_mov_b32 v4, s7; v_readfirstlane_b32 s6, v4. The proof accepts it with no refusals, and the common block actually emitsv4 = 0x00000002u; s6 = v4;even on the path that assigned 1. The scan tracks scalar dataflow, but the branch condition never taints the two constant writes, and the scalar constant recorded from the last visited block leaks into the join.Please retain the entry proof from #2183 and refuse this later-block case until the scalar inputs are proven on all incoming paths or redefined in the block itself. Add the two distinct-arm constants as a negative control, alongside a same-block redefinition positive. #2203 changes the same proof area, so please coordinate the shared controls there before updating both branches.
Pull request closed