gfx2hlsl: extend the uniform compute load proof to multi-register loads #2446

Merged
NiiRoZz merged 6 commits from upstream-pr/2454 into main 2026-11-26 03:08:08 +00:00
NiiRoZz commented 2026-11-25 17:14:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T17:14:18Z.


Depends on #2446: this branch is stacked on it, so the diff shows that commit too until it merges; this pull request then holds one commit. Refs #2274.

What / Why

The entry-block rule for a compute buffer load with a uniform address (#2446) covers one destination register. Compilers also load pairs and quads (buffer_load_format_xy v[2:3], buffer_load_dwordx4 v[8:11]) and read one component with v_readfirstlane_b32.

Change

Accept buffer_load_dwordx2/x3/x4 and buffer_load_format_xy/xyz/xyzw under the same conditions (compute, entry block, exec known, uniform address). Each destination register is marked uniform, but the range must have exactly the length the opcode writes (otherwise a register the load leaves alone could be marked). No recompute expression is recorded.

Tests

python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: 0 failed. Positives: x2 first/second word, x4 last word, overwriting a varying register, formatted xy. Negatives: x2 into three registers, x2 into one register, varying offset, a register outside the loaded range. All tests/startup_gfx2hlsl_*.py and tests/startup_translator_check.py: exit 0.

Measured (256 compute requests)

First refusal v_readfirstlane_b32: 115 before, 95 after (20 move on; next: s_pack_ll_b32 42, v_mul_hi_u32 35, src_scc in s_add_u32 14, buffer store without offen 12, formatted load descriptor words 10).

Limits (why there is no "past the entry block" PR)

The remaining readfirstlane refusals past the entry block are about ten different shapes (loads past a join, exec narrowed between a recompute chain's parts, loaded vectors in later blocks, image_load, per-lane values), none above 8 requests. The one general idea, accepting a copy of a uniform VGPR when exec is known past the entry block, flips three existing refusal tests in startup_gfx2hlsl_readfirstlane_recompute_check.py (scalar rewritten or reloaded between definition and read). I did not change those tests; it is a maintainer decision whether copy semantics make them obsolete. Not touched: SGPR proofs across joins (#2274).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6609761923 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2454). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T17:14:18Z. --- Depends on #2446: this branch is stacked on it, so the diff shows that commit too until it merges; this pull request then holds one commit. Refs #2274. ## What / Why The entry-block rule for a compute buffer load with a uniform address (#2446) covers one destination register. Compilers also load pairs and quads (`buffer_load_format_xy v[2:3]`, `buffer_load_dwordx4 v[8:11]`) and read one component with `v_readfirstlane_b32`. ## Change Accept `buffer_load_dwordx2/x3/x4` and `buffer_load_format_xy/xyz/xyzw` under the same conditions (compute, entry block, exec known, uniform address). Each destination register is marked uniform, but the range must have exactly the length the opcode writes (otherwise a register the load leaves alone could be marked). No recompute expression is recorded. ## Tests `python -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py`: 0 failed. Positives: x2 first/second word, x4 last word, overwriting a varying register, formatted xy. Negatives: x2 into three registers, x2 into one register, varying offset, a register outside the loaded range. All `tests/startup_gfx2hlsl_*.py` and `tests/startup_translator_check.py`: exit 0. ## Measured (256 compute requests) First refusal `v_readfirstlane_b32`: 115 before, 95 after (20 move on; next: s_pack_ll_b32 42, v_mul_hi_u32 35, src_scc in s_add_u32 14, buffer store without offen 12, formatted load descriptor words 10). ## Limits (why there is no "past the entry block" PR) The remaining readfirstlane refusals past the entry block are about ten different shapes (loads past a join, exec narrowed between a recompute chain's parts, loaded vectors in later blocks, image_load, per-lane values), none above 8 requests. The one general idea, accepting a copy of a uniform VGPR when exec is known past the entry block, flips three existing refusal tests in `startup_gfx2hlsl_readfirstlane_recompute_check.py` (scalar rewritten or reloaded between definition and read). I did not change those tests; it is a maintainer decision whether copy semantics make them obsolete. Not touched: SGPR proofs across joins (#2274). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
tedin7 commented 2026-11-25 19:03:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:25:52Z.

Review: COMMENTED


Review of head a485968 (comment only, no Windows run on my side; the PR body lists no Windows results, so nothing here covers any SHA on Windows).

Checked against origin/main:

  • Logic in tools/startup/gfx2hlsl.py (UNIFORM_LOAD_WORDS, the loaded gate, loaded_regs): the destination range must have exactly the length the opcode writes, tfe/lds style modifiers are rejected by the modifier whitelist, and the recompute expression is dropped for every loaded register. I found no correctness problem.
  • Scope is small and additive: 2 files, no launcher/CI/hook changes. No other open or merged PR covers multi-register loads.
  • Dependency: this branch is stacked on #2446, which is still OPEN. It should not merge before #2446. The diff against main includes that commit.

Commands run locally:

  • python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py -> 0 failed
  • git diff --check origin/main...HEAD -> clean
  • python3 tests/docs_links_check.py and python3 tests/bidi_controls_check.py -> OK
  • Mutation 1: relaxed the exact-length check (== count to >= count) -> the test fails (good, it guards the length rule).
  • Mutation 2: changed the buffer_load_dwordx3 word count from 3 to 4 -> the test still passes.

Finding (P2, non-blocking): the x3 opcodes (buffer_load_dwordx3, buffer_load_format_xyz) have no test, so a wrong word count there goes unnoticed (mutation 2). Suggest one positive (v[2:4]) and one negative (x3 into two or four registers) case next to the existing x2/x4 ones.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6062853426 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2454#pullrequestreview-6062853426). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T18:25:52Z. **Review:** COMMENTED --- Review of head a485968 (comment only, no Windows run on my side; the PR body lists no Windows results, so nothing here covers any SHA on Windows). Checked against origin/main: - Logic in `tools/startup/gfx2hlsl.py` (UNIFORM_LOAD_WORDS, the `loaded` gate, `loaded_regs`): the destination range must have exactly the length the opcode writes, tfe/lds style modifiers are rejected by the modifier whitelist, and the recompute expression is dropped for every loaded register. I found no correctness problem. - Scope is small and additive: 2 files, no launcher/CI/hook changes. No other open or merged PR covers multi-register loads. - Dependency: this branch is stacked on #2446, which is still OPEN. It should not merge before #2446. The diff against main includes that commit. Commands run locally: - `python3 -B tests/startup_gfx2hlsl_readfirstlane_uniform_check.py` -> 0 failed - `git diff --check origin/main...HEAD` -> clean - `python3 tests/docs_links_check.py` and `python3 tests/bidi_controls_check.py` -> OK - Mutation 1: relaxed the exact-length check (`== count` to `>= count`) -> the test fails (good, it guards the length rule). - Mutation 2: changed the `buffer_load_dwordx3` word count from 3 to 4 -> the test still passes. Finding (P2, non-blocking): the x3 opcodes (`buffer_load_dwordx3`, `buffer_load_format_xyz`) have no test, so a wrong word count there goes unnoticed (mutation 2). Suggest one positive (`v[2:4]`) and one negative (x3 into two or four registers) case next to the existing x2/x4 ones. AI-assisted; commands listed were executed locally.
ChazY11 commented 2026-11-25 19:04:13 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T18:26:48Z.


Six mutations: three caught, three survive — and one survivor is load-bearing against a translator crash

Baseline: Readfirstlane uniformity checks: 0 failed, whole startup_gfx2hlsl_* family green.

mutation of the uniform-load condition result
the descriptor/source must be uniform caught
the destination-range width check (candidate[2] - candidate[1] + 1 == count) caught
the word count for buffer_load_dwordx2 (2 → 3) caught
the modifier whitelist widened (any modifier accepted) survived
len(ops) == 4 dropped survived
self.tracks_uniformity() requirement dropped survived

The len(ops) == 4 survivor is load-bearing, and the failure is a crash

This one is not cosmetic. With the conjunct removed, a short operand list reaches the new condition and reads ops[3] before anything else refuses it:

baseline:  buffer_load_dword v1, off, s[0:3]   ->  refused: buffer load with 3 operands, expected 4
mutant:    buffer_load_dword v1, off, s[0:3]   ->  IndexError at gfx2hlsl.py:1956 in one
                                                       (ops[1] == 'off' or self.uniform_source(ops[1])) and self.uniform_source(ops[3]))

buffer_load_dword v1, off (two operands) crashes the same way. The existing operand-count refusal lives in buffer_address, which this condition is evaluated before, so today the conjunct is the only thing standing between a short list and translator crash in buffer_load_dword: IndexError — the exact marker the refusal census reads as a translator defect rather than as text the translator does not lower.

That makes it the one I would pin first, and it is one case: a three-operand buffer_load_dword in a compute program, asserting the refusal text and not an exception. Cheap, and it turns an unstated ordering dependency into a tested property.

The other two survivors

  • modifier whitelist widened: ('idxen', 'offen', 'glc', 'slc', 'dlc') plus offset: is what keeps tfe / lds / swizzle forms out. Widening it to accept anything is invisible to the fixture, so no case exercises a modifier outside that set.
  • tracks_uniformity() dropped: the whole proof is about tracking, so dropping the gate should be visible somewhere; it is not. Worth a case where uniformity tracking is off (a barrier or a non-entry block) and the load must not be treated as uniform.

Neither of these two changes an output I could observe, so I am reporting them as unexercised rather than as defects.

What the three caught rows establish

The width check catching x2 mis-sized to 3 words is the interesting one: it means the fixture distinguishes a load's word count from its destination range, rather than asserting the expression text loosely. The uniform-descriptor rule and the width rule are the two that decide whether a value is really lane-invariant, and both are pinned.

AI-assisted; the six mutations and the crash probe were run locally on Windows 11 build 26300.9974.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7170917859 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2454#issuecomment-7170917859). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T18:26:48Z. --- ## Six mutations: three caught, three survive — and one survivor is load-bearing against a translator crash Baseline: `Readfirstlane uniformity checks: 0 failed`, whole `startup_gfx2hlsl_*` family green. | mutation of the uniform-load condition | result | |---|---| | the descriptor/source must be uniform | **caught** | | the destination-range width check (`candidate[2] - candidate[1] + 1 == count`) | **caught** | | the word count for `buffer_load_dwordx2` (2 → 3) | **caught** | | the modifier whitelist widened (any modifier accepted) | survived | | `len(ops) == 4` dropped | survived | | `self.tracks_uniformity()` requirement dropped | survived | ### The `len(ops) == 4` survivor is load-bearing, and the failure is a crash This one is not cosmetic. With the conjunct removed, a short operand list reaches the new condition and reads `ops[3]` **before** anything else refuses it: ```text baseline: buffer_load_dword v1, off, s[0:3] -> refused: buffer load with 3 operands, expected 4 mutant: buffer_load_dword v1, off, s[0:3] -> IndexError at gfx2hlsl.py:1956 in one (ops[1] == 'off' or self.uniform_source(ops[1])) and self.uniform_source(ops[3])) ``` `buffer_load_dword v1, off` (two operands) crashes the same way. The existing operand-count refusal lives in `buffer_address`, which this condition is evaluated *before*, so today the conjunct is the only thing standing between a short list and `translator crash in buffer_load_dword: IndexError` — the exact marker the refusal census reads as a translator defect rather than as text the translator does not lower. That makes it the one I would pin first, and it is one case: a three-operand `buffer_load_dword` in a compute program, asserting the refusal text and not an exception. Cheap, and it turns an unstated ordering dependency into a tested property. ### The other two survivors - **modifier whitelist widened**: `('idxen', 'offen', 'glc', 'slc', 'dlc')` plus `offset:` is what keeps `tfe` / `lds` / swizzle forms out. Widening it to accept anything is invisible to the fixture, so no case exercises a modifier outside that set. - **`tracks_uniformity()` dropped**: the whole proof is about tracking, so dropping the gate should be visible somewhere; it is not. Worth a case where uniformity tracking is off (a barrier or a non-entry block) and the load must not be treated as uniform. Neither of these two changes an output I could observe, so I am reporting them as unexercised rather than as defects. ### What the three caught rows establish The width check catching `x2` mis-sized to 3 words is the interesting one: it means the fixture distinguishes a load's word count from its destination range, rather than asserting the expression text loosely. The uniform-descriptor rule and the width rule are the two that decide whether a value is really lane-invariant, and both are pinned. AI-assisted; the six mutations and the crash probe were run locally on Windows 11 build 26300.9974.
tedin7 commented 2026-11-26 03:03:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:39:35Z.


Merged origin/main into this branch (no conflicts, no rebase, no force-push); main's arity_check is fixed (#2659) so the earlier block is gone. New head: a84a6c82.

Commands executed locally:

  • git merge origin/main (clean; CMakeLists.txt foreach/endforeach balanced 370/370)
  • python3 tests/startup_gfx2hlsl_readfirstlane_uniform_check.py (0 failed), tests/docs_links_check.py, tests/bidi_controls_check.py, git diff --check origin/main...HEAD: all ok
  • Win2025 WARP dev + release via x2w_pipe.py win2025 2454 --patch <merge delta> --wait 7200: build and Python checks PASS (exit 0)

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181004217 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2454#issuecomment-7181004217). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:39:35Z. --- Merged origin/main into this branch (no conflicts, no rebase, no force-push); main's arity_check is fixed (#2659) so the earlier block is gone. New head: a84a6c82. Commands executed locally: - `git merge origin/main` (clean; CMakeLists.txt foreach/endforeach balanced 370/370) - `python3 tests/startup_gfx2hlsl_readfirstlane_uniform_check.py` (0 failed), `tests/docs_links_check.py`, `tests/bidi_controls_check.py`, `git diff --check origin/main...HEAD`: all ok - Win2025 WARP dev + release via `x2w_pipe.py win2025 2454 --patch <merge delta> --wait 7200`: build and Python checks PASS (exit 0) AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 03:03:25 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T02:51:12Z.


Merged current main into this branch again (merge commit 54f08ec85, no rebase, no force push). The PR had gone back into conflict after the wave-index uniformity work landed.

  • The only conflict was in tests/startup_gfx2hlsl_readfirstlane_uniform_check.py: this PR's multi-register load cases and main's wave-index and thread-id-base cases were added at the same spot. Both blocks are kept, and each loop keeps its own check(... refused ...) line.
  • tools/startup/gfx2hlsl.py merged without conflicts.
  • Linux, on 54f08ec85: python3 tests/startup_gfx2hlsl_readfirstlane_uniform_check.py (0 failed), python3 tests/startup_gfx2hlsl_compute_check.py ok, python3 tests/docs_links_check.py ok, python3 tests/bidi_controls_check.py ok, git diff --check clean.
  • Win2025 dev + release on the content passed before this merge (receipt above).

Squash merge is queued for when this head's CI is green.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7181176248 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2454#issuecomment-7181176248). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:51:12Z. --- Merged current `main` into this branch again (merge commit `54f08ec85`, no rebase, no force push). The PR had gone back into conflict after the wave-index uniformity work landed. - The only conflict was in `tests/startup_gfx2hlsl_readfirstlane_uniform_check.py`: this PR's multi-register load cases and `main`'s wave-index and thread-id-base cases were added at the same spot. Both blocks are kept, and each loop keeps its own `check(... refused ...)` line. - `tools/startup/gfx2hlsl.py` merged without conflicts. - Linux, on `54f08ec85`: `python3 tests/startup_gfx2hlsl_readfirstlane_uniform_check.py` (0 failed), `python3 tests/startup_gfx2hlsl_compute_check.py` ok, `python3 tests/docs_links_check.py` ok, `python3 tests/bidi_controls_check.py` ok, `git diff --check` clean. - Win2025 dev + release on the content passed before this merge (receipt above). Squash merge is queued for when this head's CI is green. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 04:04:08 +00:00
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!2446
No description provided.