Skip to content

startup: prove v_cvt_f32_u32 results uniform for v_readfirstlane_b32 - #2153

Merged
R0Y00 merged 1 commit into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-readfirstlane-scalar-def
Nov 25, 2026
Merged

R0Y00 merged 1 commit into
R0Y00:mainfrom
NiiRoZz:startup/gfx2hlsl-readfirstlane-scalar-def

Conversation

@NiiRoZz

@NiiRoZz NiiRoZz commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Change

Part of #1723. Follows #1931.

v_readfirstlane_b32 is lowered to a plain copy only when its VGPR source is proven uniform. #1931 follows a list of lane-pure VALU operations in straight-line code with a known exec. The list has v_rcp_f32, v_mul_f32 and v_cvt_u32_f32 but not v_cvt_f32_u32. Compiled shaders compute the unsigned-division reciprocal estimate from a uniform scalar and read the result back:

v_cvt_f32_u32_e32 v7, s2
v_rcp_f32_e32     v7, v7
v_mul_f32_e32     v7, 0x4f7ffffe, v7
v_cvt_u32_f32_e32 v7, v7
v_readfirstlane_b32 s9, v7

That chain was refused at its first step. v_cvt_f32_u32 is a per-lane function of its input bits (float(x)), so this change adds it to UNIFORM_VALU. Nothing else changes. The source, exec, branch and overwrite rules from #1931 still apply, and the conversion's SDWA and DPP forms are still not followed.

Relation to #2060 (open, reviewed at head 454fd64): #2060 admits programs with branches when no instruction in the program writes exec. This change does not touch branches. The two compose. In the sample below, all 369 branched stages that contain the read also write exec somewhere, so #2060 does not change them, with or without this change. Both PRs edit the same docs/experiments.md paragraph, so whichever lands second needs a small text merge.

Verification

On a81beb55 plus this commit:

  • python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: Readfirstlane uniformity checks: 0 failed.
  • python -B tests/startup_uniform_lane_check.py: passes.
  • python -B tests/docs_links_check.py and python -B tests/bidi_controls_check.py: pass.

Mutants of the rule, each applied to a copy of gfx2hlsl.py and run against the check. Each is a single edit, except the two "both gates" rows:

Mutant Result First failing case
drop v_cvt_f32_u32 from the set killed unsigned to float conversion, division reciprocal chain
skip the source uniformity check killed conversion of an entry VGPR, conversion of a mask
keep a proof across an overwrite killed overwrite inside the chain
treat lane masks as uniform killed mask from uniform compare
skip the exec gate of the read killed compare / saveexec writes exec
skip both exec gates (proof and read) killed exec write inside the chain, unknown exec
skip both branch gates (proof and read) killed chain in a program with branches, definition in another block
skip only one branch gate, or only the proof's exec gate survives the remaining gate refuses alone

Local measurement, not reproducible from the repository: 266 graphics pipelines used by indirect draws in one captured frame, translated offline with translate_request.

  • Before: 252 stop at v_readfirstlane_b32 requires a proven uniform source.
  • After: 64 of them move on and stop next at s_mul_hi_u32. 188 still stop at the read; all of their read sites are in programs with branches. None of the 266 translates fully either way.
  • Re-translating those 266, plus 117 cached requests from other local runs (383 in all), changed only those 64 results. The 75 requests that translated before give byte-identical HLSL.

Evidence and follow-up

The fixture is hand-written disassembly text, the same style as the existing check. It is not taken from any title.

New accepted cases: the conversion alone, and the full reciprocal chain. New refused cases: the conversion of an entry VGPR, the conversion of a lane mask, an exec write inside the chain, an overwrite inside the chain, the chain in a program with branches, and a definition in another block. The existing negative control, which empties the allowlist, now also covers the two new accepted cases.

Follow-up, not in this PR: the remaining read sites in the sample are all in programs with branches.

  • 369 are in the entry block, before the first branch and before any branch target. Program-order tracking is exact there.
  • 574 are in later blocks under a changed exec.

docs/experiments.md (uniform sources of v_readfirstlane_b32) lists the new opcode and test cases. Reproduce with:

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_readfirstlane_uniform$' -V

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code). All commands above were run locally.

🤖 Generated with Claude Code

The straight-line uniformity proof (R0Y00#1931) followed v_rcp_f32, v_mul_f32
and v_cvt_u32_f32 but not v_cvt_f32_u32, so the unsigned-division
reciprocal estimate (v_cvt_f32_u32 of a uniform scalar, v_rcp_f32,
v_mul_f32 by 0x4f7ffffe, v_cvt_u32_f32) never reached a proven read.
The conversion is a per-lane function of its input bits.

The check covers the conversion and the full chain, and keeps the
chain refused from a lane-varying source or a lane mask, across an
exec write or an overwrite, and in a program with branches.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@tedin7 tedin7 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Review at head 6d8ab3d317b3721fc7491f198578eb9b5c4d0b36.

Summary: One-word change, v_cvt_f32_u32 added to UNIFORM_VALU (tools/startup/gfx2hlsl.py:327). The conversion is a pure per-lane function of its source bits, like its siblings v_cvt_u32_f32 and v_cvt_f32_ubyte0. The existing source, exec, branch and overwrite gates still apply. No P1 or P2 found.

Commands run locally on the PR head:

  • python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: Readfirstlane uniformity checks: 0 failed
  • python3 tests/docs_links_check.py: self-test passed, 18 files, 396 links
  • python3 tests/bidi_controls_check.py: 1429 files, no bidi controls
  • git diff --check origin/main...HEAD: clean
  • Mutation: removed v_cvt_f32_u32 from UNIFORM_VALU. Result: 2 failed (the new accepted cases). Reverted with git checkout -- ..
  • gh pr checks: Linux checks, gfx1013 fixtures and Windows build pass. The /O2 and chart jobs were skipped.
  • Mergeable, title neutral, no clean-room concerns seen in the 3 touched files.

Findings:

  • P1: none.
  • P2: none.
  • nit: The new refused cases cover entry VGPR, mask source, exec write, overwrite, branches and cross-block definition. A refused case for a v_cvt_f32_u32 with SDWA/DPP modifiers would pin the "still not followed" claim in the body. The modifier gate already rejects it, so this is optional.
  • nit: As the body says, this and #2060 both edit the same docs/experiments.md paragraph, so the second to land needs a small text merge.

No Windows run: the change is a set-membership edit in Python analysis code with no new HLSL lowering, so the Linux check is enough.

AI-assisted; commands listed were executed locally.

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.

3 participants