Skip to content

shader: extend v_readfirstlane_b32 lowering to branched control flow in gfx2hlsl (Part of #1723) - #2060

Closed
tedin7 wants to merge 4 commits into
R0Y00:mainfrom
tedin7:x2w-r22-readfirstlane-branch
Closed

tedin7 wants to merge 4 commits into
R0Y00:mainfrom
tedin7:x2w-r22-readfirstlane-branch

Conversation

@tedin7

@tedin7 tedin7 commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Part of #1723

What this unblocks: 719 draw refusals (v_readfirstlane_b32 with branches).

v_readfirstlane_b32 was 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.

  • The VGPR uniformity set is cleared at every block start (branch targets and the instruction after a terminator), so no proof crosses a join or a loop edge.
  • Proofs are refused in a branched shader if any instruction writes exec (exec/exec_lo/exec_hi, *saveexec*, v_cmpx*), so exec_known holds on every path.
  • Scalar sources that can carry a per-lane value (compare results, anything derived from exec/vcc) are found over the whole program, so a loop cannot bring a late mask write back to an earlier read.
  • Shaders without branches behave as before.

Tests:

  • new tests/startup_readfirstlane_branch_check.py, registered as startup_readfirstlane_branch in CMakeLists.txt. It fails on origin/main and 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 previous gfx2hlsl.py raises v_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.
  • The remaining tests/startup_*_check.py need Windows probe binaries or arguments and were not run.
  • The 719 count comes from the task brief; I did not re-run the shader scan.

AI-assisted; commands listed were executed locally.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T23:54:22.048998Z 0cf2155 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment thread tools/startup/gfx2hlsl.py Resolved
Comment thread tools/startup/gfx2hlsl.py Resolved
Comment thread tools/startup/gfx2hlsl.py Resolved
Comment thread tools/startup/gfx2hlsl.py Resolved
@R0Y00

R0Y00 commented Nov 25, 2026

Copy link
Copy Markdown
Owner

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.

…e shader has branches

Part of R0Y00#1723. VGPR uniformity is proven per basic block and cleared at every join; refused when any instruction writes exec; scalar sources that can carry a lane mask are excluded program-wide.
@tedin7
tedin7 force-pushed the x2w-r22-readfirstlane-branch branch from f9865ac to c346072 Compare November 25, 2026 04:07
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @R0Y00. The branch is rebased and pushed as c346072cb90fae2009386d3e1561e7c5fa911c6f (mergeable).

Covered in this head:

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.py
  • dev (ctest --preset dev): 3/3 passed
  • release (ctest --preset release): 3/3 passed
  • Python check tests/startup_readfirstlane_branch_check.py: ok

Note: 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.

@R0Y00 R0Y00 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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 for v_mov_b32 v4, s7; v_readfirstlane_b32 s6, v4. The proof accepts it with no refusals, and the common block actually emits v4 = 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.

A scalar register written in a later block is only a proven source in a block that redefines it; the value recorded from the last visited arm no longer leaks into the join. Adds the two-arm negative control and a same-block redefinition positive.
@tedin7
tedin7 force-pushed the x2w-r22-readfirstlane-branch branch from b3ad651 to fc30b13 Compare November 25, 2026 05:08
@tedin7

tedin7 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Closing as superseded: the branched v_readfirstlane_b32 entry-block and post-entry-block lowering landed on main via #2183 and #2203.

@tedin7 tedin7 closed this Nov 25, 2026
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.

2 participants