startup: prove v_med3_f32 results uniform for v_readfirstlane_b32 #2190

Merged
NiiRoZz merged 3 commits from upstream-pr/2198 into main 2026-11-25 06:46:39 +00:00
NiiRoZz commented 2026-11-25 04:17:03 +00:00 (Migrated from github.com)

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_b32 follows a list of lane-pure VALU operations (UNIFORM_VALU). v_med3_f32 was not in it. Compiled pixel shaders clamp a scalar with a median of three and read the result back, for example:

v_med3_f32 v7, s2, 0, 0.5
v_readfirstlane_b32 s9, v7

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_f32 lowering for a NaN source (med3_32()). The operation stays a per-lane function, so the proof is unaffected.

  • A trial merge of #2095's head (6883eeb3) with this branch conflicts in tools/startup/gfx2hlsl.py and CMakeLists.txt. #2095 conflicts the same way with origin/main alone (the helper list now also has mul_hi_u32), so this branch adds no textual conflict of its own.
  • If #2095 lands first, the two expected lines here change from med3( to med3_32(.

Verification

On fd457299 (origin/main) merged into this branch, head 5ba0b508:

  • 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.
  • Mutant: removing v_med3_f32 from 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.

  • Accepted: the [0, 0.5] clamp form, and a form with negated, absolute and clamped scalar sources.
  • Refused: a median with a lane-varying source, and a median with a lane-mask source.

docs/experiments.md (uniform sources of v_readfirstlane_b32) lists the operation. 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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6597092841 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2198). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T04:17:03Z. --- ## Change Part of #1723. Follows #1931, #2153 and #2183. The uniformity proof behind `v_readfirstlane_b32` follows a list of lane-pure VALU operations (`UNIFORM_VALU`). `v_med3_f32` was not in it. Compiled pixel shaders clamp a scalar with a median of three and read the result back, for example: ``` v_med3_f32 v7, s2, 0, 0.5 v_readfirstlane_b32 s9, v7 ``` 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_f32` lowering for a NaN source (`med3_32()`). The operation stays a per-lane function, so the proof is unaffected. - A trial merge of #2095's head (`6883eeb3`) with this branch conflicts in `tools/startup/gfx2hlsl.py` and `CMakeLists.txt`. #2095 conflicts the same way with `origin/main` alone (the helper list now also has `mul_hi_u32`), so this branch adds no textual conflict of its own. - If #2095 lands first, the two expected lines here change from `med3(` to `med3_32(`. ## Verification On `fd457299` (`origin/main`) merged into this branch, head `5ba0b508`: - `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. - Mutant: removing `v_med3_f32` from 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. - Accepted: the `[0, 0.5]` clamp form, and a form with negated, absolute and clamped scalar sources. - Refused: a median with a lane-varying source, and a median with a lane-mask source. `docs/experiments.md` (uniform sources of `v_readfirstlane_b32`) lists the operation. Reproduce with: ```powershell ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_readfirstlane_uniform$' -V ``` ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] 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](https://claude.com/claude-code)
tedin7 commented 2026-11-25 05:04:51 +00:00 (Migrated from github.com)

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_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_f32 is 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_f32 is in VEC_F (gfx2hlsl.py:2307), so the existing -/|x| source-modifier stripping and the clamp/mul:2/mul:4/div:2 output-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.md matches 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 failed
  • python3 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' from UNIFORM_VALU -> the check reports 2 failed (both new accepted cases are caught). Reverted with git checkout -- ..

Notes

  • nit: the refusal tests do not cover a med3 chain across an exec write 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051795622 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2198#pullrequestreview-6051795622). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T04:18:26Z. **Review:** COMMENTED --- 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_f32` is 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_f32` is in `VEC_F` (`gfx2hlsl.py:2307`), so the existing `-`/`|x|` source-modifier stripping and the `clamp`/`mul:2`/`mul:4`/`div:2` output-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.md` matches 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 failed` - `python3 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'` from `UNIFORM_VALU` -> the check reports `2 failed` (both new accepted cases are caught). Reverted with `git checkout -- .`. **Notes** - nit: the refusal tests do not cover a med3 chain across an `exec` write 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.
tedin7 commented 2026-11-25 06:01:24 +00:00 (Migrated from github.com)

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 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...HEAD is 4 files, 17 insertions, 6 deletions: gfx2hlsl.py (one table entry and its comment), the two readfirstlane checks, and docs/experiments.md.
  • The new recompute case (median of three after a join) expects s9 = U(med3(F(s3), F(0x00000000u), 0.5));. That matches the translator's med3 lowering.
  • 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 failed
  • python3 -B tests/startup_gfx2hlsl_readfirstlane_recompute_check.py -> Readfirstlane recompute checks: 0 failed
  • python3 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' from UNIFORM_VALU. The uniform check reports 2 failed and the recompute check reports 1 failed. Reverted with git 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6052489696 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2198#pullrequestreview-6052489696). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T05:49:32Z. **Review:** COMMENTED --- 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...HEAD` is 4 files, 17 insertions, 6 deletions: `gfx2hlsl.py` (one table entry and its comment), the two readfirstlane checks, and `docs/experiments.md`. - The new recompute case (`median of three after a join`) expects `s9 = U(med3(F(s3), F(0x00000000u), 0.5));`. That matches the translator's `med3` lowering. - 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 failed` - `python3 -B tests/startup_gfx2hlsl_readfirstlane_recompute_check.py` -> `Readfirstlane recompute checks: 0 failed` - `python3 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'` from `UNIFORM_VALU`. The uniform check reports `2 failed` and the recompute check reports `1 failed`. Reverted with `git 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.
NiiRoZz commented 2026-11-25 06:01:38 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T05:47:08Z.


Merged current main into the branch (d584331d). The only conflict was the docs/experiments.md paragraph that #2203 also edits; it now carries main'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 without v_med3_f32 in the set), and a median chain across an exec write, which is refused. Both checks, the docs links check and git diff --check pass.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7154136151 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2198#issuecomment-7154136151). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T05:47:08Z. --- Merged current `main` into the branch (`d584331d`). The only conflict was the `docs/experiments.md` paragraph that #2203 also edits; it now carries `main`'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 without `v_med3_f32` in the set), and a median chain across an `exec` write, which is refused. Both checks, the docs links check and `git diff --check` pass. AI-assisted (Claude Code).
upstream-sync closed this pull request 2026-11-25 07:00:59 +00:00
stan495 commented 2026-11-25 07:01:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by stan495 on 2026-11-25T06:34:45Z.

Review: APPROVED


Verified head d584331d on Windows x64 (Python 3.12).

  • python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py -> passed
  • python -B tests/startup_gfx2hlsl_readfirstlane_recompute_check.py -> passed
  • python -B tests/docs_links_check.py -> passed (18 Markdown files, 409 links)

Verdict: Approved at d584331d.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6052911859 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2198#pullrequestreview-6052911859). Originally posted by [stan495](https://github.com/stan495) on 2026-11-25T06:34:45Z. **Review:** APPROVED --- Verified head `d584331d` on Windows x64 (Python 3.12). - `python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py` -> passed - `python -B tests/startup_gfx2hlsl_readfirstlane_recompute_check.py` -> passed - `python -B tests/docs_links_check.py` -> passed (18 Markdown files, 409 links) Verdict: Approved at `d584331d`.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2190
No description provided.