startup: prove v_med3_f32 results uniform for v_readfirstlane_b32 #2190
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2198"
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:17:03Z.
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. #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
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T04:18:26Z.
Review: COMMENTED
Review of head
5ba0b508fa351ed5b271b3819564b7f28ac0dc57(comment only).Summary: Adds
v_med3_f32toUNIFORM_VALUsov_readfirstlane_b32can 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.docs/experiments.mdmatches the code.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'v_med3_f32'fromUNIFORM_VALU-> the check reports2 failed(both new accepted cases are caught). Reverted withgit checkout -- ..Notes
execwrite or past the entry block. Those paths are shared with the other listed ops, so this is not blocking.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T05:49:32Z.
Review: COMMENTED
Re-review of head
d584331d9725e8c09fc239768f121ac1cc61c8c6(comment only). My earlier review covered5ba0b508.Summary: The head merges
mainand adds one new accepted case and one new refused case to the recompute check, plus the doc sentence. TheUNIFORM_VALUentry forv_med3_f32is 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.median of three after a join) expectss9 = U(med3(F(s3), F(0x00000000u), 0.5));. That matches the translator'smed3lowering.median of three across an EXEC write) closes the nit from my earlier review.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'v_med3_f32'fromUNIFORM_VALU. The uniform check reports2 failedand the recompute check reports1 failed. Reverted withgit checkout -- ..Notes
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T05:47:08Z.
Merged current
maininto the branch (d584331d). The only conflict was thedocs/experiments.mdparagraph that #2203 also edits; it now carriesmain's text plus the median.Since #2203 is on
main, I also took the review nit and added two cases to the recompute check: a median after a join, which is accepted and recomputed (it fails withoutv_med3_f32in the set), and a median chain across anexecwrite, which is refused. Both checks, the docs links check andgit diff --checkpass.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T06:34:45Z.
Review: APPROVED
Verified head
d584331don 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.