Repository navigation
startup: prove v_med3_f32 results uniform for v_readfirstlane_b32 - #2198
Conversation
The uniformity proof behind v_readfirstlane_b32 did not follow v_med3_f32, so a scalar clamped with a median of three (for example v_med3_f32 v14, s44, 0, 0.5) never reached a proven read. The median is a per-lane function of its three inputs, like the multiply and fused multiply-add already in the set. The check accepts the clamp form and a form with negated, absolute and clamped scalar sources. It refuses a median with a lane-varying source or a lane-mask source. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…firstlane-med3 # Conflicts: # docs/experiments.md
tedin7
left a comment
There was a problem hiding this comment.
Review of head 5ba0b508fa351ed5b271b3819564b7f28ac0dc57 (comment only).
Summary: Adds v_med3_f32 to UNIFORM_VALU so v_readfirstlane_b32 can read its result when all three sources are uniform. The change is correct and small. No P1 or P2 findings.
Checked
v_med3_f32is a per-lane function of its three inputs (med3()helper,tools/startup/gfx2hlsl.py:2556). It reads no lane id or other lane, so the uniformity proof holds.v_med3_f32is inVEC_F(gfx2hlsl.py:2307), so the existing-/|x|source-modifier stripping and theclamp/mul:2/mul:4/div:2output-modifier allowlist apply to it, like the other float ops. All three sources must be uniform (all(self.uniform_source(tok) ...)), so a varying third source is refused.- Tests: two accepted cases (plain, and with negation/abs/clamp) and two refusals (varying VGPR source, lane-mask source). Docs sentence in
docs/experiments.mdmatches the code. - Clean-room and neutral title: OK. Mergeable. Linux Python CI check passes; Windows and fixture jobs were still pending when I looked.
Commands run locally (worktree at the head above)
python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py->Readfirstlane uniformity checks: 0 failedpython3 tests/docs_links_check.py->Checked 18 Markdown files and 405 links.python3 tests/bidi_controls_check.py->no bidirectional controls.git diff --check origin/main...HEAD-> clean- Mutation: removed
'v_med3_f32'fromUNIFORM_VALU-> the check reports2 failed(both new accepted cases are caught). Reverted withgit checkout -- ..
Notes
- nit: the refusal tests do not cover a med3 chain across an
execwrite or past the entry block. Those paths are shared with the other listed ops, so this is not blocking. - No Windows run: the change is a table entry plus Linux-testable translation, with no new HLSL emitted, so I did not queue the VM.
AI-assisted; commands listed were executed locally.
…firstlane-med3 # Conflicts: # docs/experiments.md
|
Merged current Since #2203 is on AI-assisted (Claude Code). |
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head d584331d9725e8c09fc239768f121ac1cc61c8c6 (comment only). My earlier review covered 5ba0b508.
Summary: The head merges main and adds one new accepted case and one new refused case to the recompute check, plus the doc sentence. The UNIFORM_VALU entry for v_med3_f32 is unchanged in substance. No P1 or P2 findings.
Checked
git diff --stat origin/main...HEADis 4 files, 17 insertions, 6 deletions:gfx2hlsl.py(one table entry and its comment), the two readfirstlane checks, anddocs/experiments.md.- The new recompute case (
median of three after a join) expectss9 = U(med3(F(s3), F(0x00000000u), 0.5));. That matches the translator'smed3lowering. - The new refusal (
median of three across an EXEC write) closes the nit from my earlier review. - Mergeable. CI: Linux Python checks pass, fixture assemble/translate passes, Windows build still pending when I looked.
Commands run locally (worktree at the head above)
python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py->Readfirstlane uniformity checks: 0 failedpython3 -B tests/startup_gfx2hlsl_readfirstlane_recompute_check.py->Readfirstlane recompute checks: 0 failedpython3 tests/docs_links_check.py->Checked 18 Markdown files and 409 links.python3 tests/bidi_controls_check.py->no bidirectional controls.git diff --check origin/main...HEAD-> clean- Mutation: removed
'v_med3_f32'fromUNIFORM_VALU. The uniform check reports2 failedand the recompute check reports1 failed. Reverted withgit checkout -- ..
Notes
- No Windows run from me: the change is a table entry plus Linux-testable translation, with no new HLSL form emitted.
- Clean-room and neutral title: OK.
AI-assisted; commands listed were executed locally.
stan495
left a comment
There was a problem hiding this comment.
Verified head d584331d on Windows x64 (Python 3.12).
python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py-> passedpython -B tests/startup_gfx2hlsl_readfirstlane_recompute_check.py-> passedpython -B tests/docs_links_check.py-> passed (18 Markdown files, 409 links)
Verdict: Approved at d584331d.
Change
Part of #1723. Follows #1931, #2153 and #2183.
The uniformity proof behind
v_readfirstlane_b32follows a list of lane-pure VALU operations (UNIFORM_VALU).v_med3_f32was not in it. Compiled pixel shaders clamp a scalar with a median of three and read the result back, for example:The median is a per-lane function of its three inputs (
med3()in the emitted HLSL), like the multiply and fused multiply-add already in the list. This change adds it. Source and output modifiers follow the existing float rules: negation, absolute value and clamp. Nothing else changes.Where it applies: in branch-free code, and in the entry block of a program with branches (#2183). Past the entry block, the read still needs a further rule, which this PR does not add.
Open PR #2095 changes the
v_med3_f32lowering for a NaN source (med3_32()). The operation stays a per-lane function, so the proof is unaffected.6883eeb3) with this branch conflicts intools/startup/gfx2hlsl.pyandCMakeLists.txt. startup: return the minimum of the three on v_med3_f32 with a NaN source #2095 conflicts the same way withorigin/mainalone (the helper list now also hasmul_hi_u32), so this branch adds no textual conflict of its own.med3(tomed3_32(.Verification
On
fd457299(origin/main) merged into this branch, head5ba0b508:python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py:Readfirstlane uniformity checks: 0 failed.python -B tests/docs_links_check.py: passes.git diff --check origin/main...HEAD: clean. The changed files are LF in the index.v_med3_f32from the set fails "median of three" and "median of three scalar sources". The existing negative control, which empties the set, also covers both.Local measurement, not reproducible from the repository: on its own, this changes none of 383 locally cached requests, and the 75 that translated keep byte-identical HLSL. In one full-screen pixel pipeline from a captured frame, three reads have this form. They sit past the entry block of a branched program, so they also need the further rule mentioned above.
Evidence and follow-up
The fixture is hand-written disassembly text. It is not taken from any title.
[0, 0.5]clamp form, and a form with negated, absolute and clamped scalar sources.docs/experiments.md(uniform sources ofv_readfirstlane_b32) lists the operation. Reproduce with:Checklist
AI-assisted (Claude Code). All commands above were run locally.
🤖 Generated with Claude Code