shader: track both VCC halves for unsigned MAD64 carry #2979

Merged
chadhyatt merged 1 commit from upstream-pr/2979 into main 2026-11-27 05:02:10 +00:00
chadhyatt commented 2026-11-27 01:52:35 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-27T01:52:35Z.


The decoded v_mad_u64_u32 VOP3B carry-out uses the same wave64 lane mask convention as unsigned add/subtract. Include it in the high-half may-write classification so a stale clear vcc_hi fact cannot survive the skipped-block proof. Preserve discarded/signed admission and rotate the paired graphics/compute cache keys.

Verification on Apple Silicon macOS, tested commit 3286a2630932007d67f906f5f6b7febbf1d2f7ed against 6ee878d8: all passed with python3 -B tests/startup_gfx2hlsl_mad64_check.py, tests/startup_shader_cache_key_check.py, tests/startup_compute_request_offline_check.py, tests/startup_gfx2hlsl_buffer_store_check.py, tests/startup_packed_position_provenance_check.py, tests/startup_gfx2hlsl_fract_check.py, and tests/startup_shader_cache_rekey_check.py. The MAD64 controls cover 1,400 arithmetic rows and stale-fact/adjacent/null controls; new graphics key vectors were independently computed with C++. No Windows or GPU execution claimed in this run.

AI-assisted backport patch from x2w-microlift.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:5519808242 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2979). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-27T01:52:35Z. --- The decoded `v_mad_u64_u32` VOP3B carry-out uses the same wave64 lane mask convention as unsigned add/subtract. Include it in the high-half may-write classification so a stale clear `vcc_hi` fact cannot survive the skipped-block proof. Preserve discarded/signed admission and rotate the paired graphics/compute cache keys. Verification on Apple Silicon macOS, tested commit `3286a2630932007d67f906f5f6b7febbf1d2f7ed` against `6ee878d8`: all passed with `python3 -B tests/startup_gfx2hlsl_mad64_check.py`, `tests/startup_shader_cache_key_check.py`, `tests/startup_compute_request_offline_check.py`, `tests/startup_gfx2hlsl_buffer_store_check.py`, `tests/startup_packed_position_provenance_check.py`, `tests/startup_gfx2hlsl_fract_check.py`, and `tests/startup_shader_cache_rekey_check.py`. The MAD64 controls cover 1,400 arithmetic rows and stale-fact/adjacent/null controls; new graphics key vectors were independently computed with C++. No Windows or GPU execution claimed in this run. AI-assisted backport patch from x2w-microlift.
thepatrickworld commented 2026-11-27 02:31:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by thepatrickworld on 2026-11-27T02:31:19Z.


Portable check of 3286a263 on Linux: the new control bites, and one link stays unpinned

Environment

No GPU on this host (my Windows machine is unreachable this cycle), so this is the portable half only: no draw, no DXC, no adaptor, no debug layer. Linux x86-64, Python 3.11.16, a fresh clone, worktrees at 3286a263 (head) and 6ee878d8 (base). git status --porcelain --untracked-files=no is empty at head; the base worktree is that commit untouched, and the only file it carries is the fixture copied in for the negative control below. sha256(tools/startup/gfx2hlsl.py) at head: 3d793b4ae08b6c3dacae643aed4211d9cd7af7a8f9ce9b686846bc9013d96f1f.

Commands and observed

The six Python fixtures the diff touches, plus startup_shader_cache_rekey_check.py which the body names, in their no-argument mode at head. All exit 0.

python3 -B tests/startup_gfx2hlsl_mad64_check.py
python3 -B tests/startup_shader_cache_key_check.py
python3 -B tests/startup_compute_request_offline_check.py
python3 -B tests/startup_gfx2hlsl_buffer_store_check.py
python3 -B tests/startup_gfx2hlsl_fract_check.py
python3 -B tests/startup_packed_position_provenance_check.py
python3 -B tests/startup_shader_cache_rekey_check.py

The new control bites

With the head fixture copied onto the base translator and nothing else changed, the may-write table fails on its first row and the run stops there:

v_mad_u64_u32 v[12:13], vcc_lo, v18, v19, v[20:21] may-writes vcc and vcc_hi: MISMATCH
AssertionError: v_mad_u64_u32 v[12:13], vcc_lo, v18, v19, v[20:21] may-writes vcc and vcc_hi

That assert ends the run, so the join case is never reached in that pass. Measured directly against the base helpers, with start = {('exec', 0), ('exec_hi', 1), ('vcc_hi', 0)}:

base  clear_after('v_mad_u64_u32', mad, scalar_effects(...)[2], start)
      -> {('exec', 0), ('exec_hi', 1), ('vcc_hi', 0)}     the clear fact survives
head  the same call
      -> {('exec', 0), ('exec_hi', 1)}

Mutants of the fix

One line at a time, each edit applied once, sha256 of the file recorded before and after, git status --porcelain --untracked-files=no empty after git checkout --:

  • dropping the 'vcc' in writes guard for the mad64 is killed by the null row: ... null ... may-writes no VCC half: MISMATCH;
  • recording vcc_hi in writes instead of may is killed by the vcc_lo row: ... vcc_lo ... may-writes vcc and vcc_hi: MISMATCH;
  • adding v_mad_i64_i32 to the tuple survives, and no accepted form changes behaviour: scalar_effects then reports may = {'vcc', 'vcc_hi'} for a signed mad64 with a vcc_lo destination, but mad64() refuses that form (only null is lowered), so it never reaches the analysis.

Scope of the prefix list: v_addc_co_u32 and v_subb_co_u32 have no op_ handler and are refused; v_mad_i64_i32 is accepted only with null, so its real carry destination is refused. Within the forms this translator accepts, the prefixed set is the one that can reach may.add('vcc_hi').

execz_refusals feeds clear_after the third element of scalar_effects (gfx2hlsl.py:2941, clear_after(*self.ins[i][2:], effects[i][2], before[i])). Passing the second one, writes without may, is not equivalent: for the same ('vcc_hi', 0) fact, clear_after then keeps it across v_cmp_gt_u32 vcc_lo, across v_add_co_u32 vcc_lo and across this mad64.

The new control cannot see that, because it calls clear_after directly with scalar_effects(...)[2] and never goes through the call site; that mutant survives startup_gfx2hlsl_mad64_check (rc=0) and startup_gfx2hlsl_vcc_hi_check (PASS). Separately, no exit code changes across the 277 tests/startup_*.py run in no-argument mode (0 rc changes; 76 were already non-zero at baseline), so no existing fixture's status pins it either. That last measurement compares status only, not failure text.

The shape where a ('vcc_hi', 0) fact can exist is not out of the model's reach: wave32_vcc_hi keeps vcc_hi spelled as vcc_hi on two of the four two-instruction texts I fed it, s_mov_b32 vcc_hi, 0 followed by v_cmp_gt_u32 vcc_lo or by this mad64, and does not raise there, where it renames the same write to s_mov_b32 s105, 0 when nothing else names VCC. I did not assemble a program where such a block is skipped by s_cbranch_execz, nor run the translation end to end, so this does not show that a real shader produces the fact, only that the text reaches the model.

Where the checks run

startup_gfx2hlsl_mad64_check.py is in the python-linux job's script list (windows.yml:358, ubuntu-24.04, no if: and no paths: on that job), so these controls run on every pull request. The ctest entry is not in the pr preset's include regex, so the ctest path does not reach it before merge; the Python job does.

Limits

One host, no GPU, no draw, no DXC, no debug layer; nothing here says the translated mad64 is right on an adaptor, and the draw evidence stays where the body left it. The two C++ tests the diff touches carry the cache revision only and were neither built nor run here.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7208198258 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2979#issuecomment-7208198258). Originally posted by [thepatrickworld](https://github.com/thepatrickworld) on 2026-11-27T02:31:19Z. --- **Portable check of `3286a263` on Linux: the new control bites, and one link stays unpinned** ### Environment No GPU on this host (my Windows machine is unreachable this cycle), so this is the portable half only: no draw, no DXC, no adaptor, no debug layer. Linux x86-64, Python 3.11.16, a fresh clone, worktrees at `3286a263` (head) and `6ee878d8` (base). `git status --porcelain --untracked-files=no` is empty at head; the base worktree is that commit untouched, and the only file it carries is the fixture copied in for the negative control below. `sha256(tools/startup/gfx2hlsl.py)` at head: `3d793b4ae08b6c3dacae643aed4211d9cd7af7a8f9ce9b686846bc9013d96f1f`. ### Commands and observed The six Python fixtures the diff touches, plus `startup_shader_cache_rekey_check.py` which the body names, in their no-argument mode at head. All exit 0. ``` python3 -B tests/startup_gfx2hlsl_mad64_check.py python3 -B tests/startup_shader_cache_key_check.py python3 -B tests/startup_compute_request_offline_check.py python3 -B tests/startup_gfx2hlsl_buffer_store_check.py python3 -B tests/startup_gfx2hlsl_fract_check.py python3 -B tests/startup_packed_position_provenance_check.py python3 -B tests/startup_shader_cache_rekey_check.py ``` ### The new control bites With the head fixture copied onto the base translator and nothing else changed, the may-write table fails on its first row and the run stops there: ``` v_mad_u64_u32 v[12:13], vcc_lo, v18, v19, v[20:21] may-writes vcc and vcc_hi: MISMATCH AssertionError: v_mad_u64_u32 v[12:13], vcc_lo, v18, v19, v[20:21] may-writes vcc and vcc_hi ``` That assert ends the run, so the join case is never reached in that pass. Measured directly against the base helpers, with `start = {('exec', 0), ('exec_hi', 1), ('vcc_hi', 0)}`: ``` base clear_after('v_mad_u64_u32', mad, scalar_effects(...)[2], start) -> {('exec', 0), ('exec_hi', 1), ('vcc_hi', 0)} the clear fact survives head the same call -> {('exec', 0), ('exec_hi', 1)} ``` ### Mutants of the fix One line at a time, each edit applied once, `sha256` of the file recorded before and after, `git status --porcelain --untracked-files=no` empty after `git checkout --`: - dropping the `'vcc' in writes` guard for the mad64 is killed by the `null` row: `... null ... may-writes no VCC half: MISMATCH`; - recording `vcc_hi` in `writes` instead of `may` is killed by the `vcc_lo` row: `... vcc_lo ... may-writes vcc and vcc_hi: MISMATCH`; - adding `v_mad_i64_i32` to the tuple survives, and no accepted form changes behaviour: `scalar_effects` then reports `may = {'vcc', 'vcc_hi'}` for a signed mad64 with a `vcc_lo` destination, but `mad64()` refuses that form (`only null is lowered`), so it never reaches the analysis. Scope of the prefix list: `v_addc_co_u32` and `v_subb_co_u32` have no `op_` handler and are refused; `v_mad_i64_i32` is accepted only with `null`, so its real carry destination is refused. Within the forms this translator accepts, the prefixed set is the one that can reach `may.add('vcc_hi')`. ### One link the fixtures do not pin `execz_refusals` feeds `clear_after` the third element of `scalar_effects` (`gfx2hlsl.py:2941`, `clear_after(*self.ins[i][2:], effects[i][2], before[i])`). Passing the second one, `writes` without `may`, is not equivalent: for the same `('vcc_hi', 0)` fact, `clear_after` then keeps it across `v_cmp_gt_u32 vcc_lo`, across `v_add_co_u32 vcc_lo` and across this mad64. The new control cannot see that, because it calls `clear_after` directly with `scalar_effects(...)[2]` and never goes through the call site; that mutant survives `startup_gfx2hlsl_mad64_check` (rc=0) and `startup_gfx2hlsl_vcc_hi_check` (PASS). Separately, no exit code changes across the 277 `tests/startup_*.py` run in no-argument mode (0 rc changes; 76 were already non-zero at baseline), so no existing fixture's status pins it either. That last measurement compares status only, not failure text. The shape where a `('vcc_hi', 0)` fact can exist is not out of the model's reach: `wave32_vcc_hi` keeps `vcc_hi` spelled as `vcc_hi` on two of the four two-instruction texts I fed it, `s_mov_b32 vcc_hi, 0` followed by `v_cmp_gt_u32 vcc_lo` or by this mad64, and does not raise there, where it renames the same write to `s_mov_b32 s105, 0` when nothing else names VCC. I did not assemble a program where such a block is skipped by `s_cbranch_execz`, nor run the translation end to end, so this does not show that a real shader produces the fact, only that the text reaches the model. ### Where the checks run `startup_gfx2hlsl_mad64_check.py` is in the `python-linux` job's script list (`windows.yml:358`, ubuntu-24.04, no `if:` and no `paths:` on that job), so these controls run on every pull request. The ctest entry is not in the `pr` preset's include regex, so the ctest path does not reach it before merge; the Python job does. ### Limits One host, no GPU, no draw, no DXC, no debug layer; nothing here says the translated mad64 is right on an adaptor, and the draw evidence stays where the body left it. The two C++ tests the diff touches carry the cache revision only and were neither built nor run here. _AI-assisted._
chadhyatt commented 2026-11-27 02:32:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-27T02:32:39Z.


Thanks, the independently reproduced negative control confirms the intended table change. The missing call-site coverage is a useful distinction; I will add a source-built end-to-end execz control if the actual supported pipeline can express the fact, without changing the lowering or overstating adapter verification.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7208221328 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2979#issuecomment-7208221328). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-27T02:32:39Z. --- Thanks, the independently reproduced negative control confirms the intended table change. The missing call-site coverage is a useful distinction; I will add a source-built end-to-end execz control if the actual supported pipeline can express the fact, without changing the lowering or overstating adapter verification.
KelboLive commented 2026-11-27 04:17:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-27T04:17:15Z.

Review: COMMENTED


Important nuance — the wave64 skipped-block liveness proof needs both VCC halves tracked for unsigned VOP3B carry-out. A discarded carry doesn't invalidate either half, but the proof must not let a stale clear vcc_hi fact survive a skipped-block join.

Findings

✅ What works well

  • Correct semantics: v_mad_u64_u32 carry-out with vcc_lo may also write vcc_hi in the wave64 convention. The discarded carry doesn't invalidate either half — the high-half clear fact from the previous block can survive through the join without being invalidated by a discarded carry.
  • docs/experiments.md update: Adds one clear sentence in the mad64 section documenting the VCC half tracking nuance. Consistent with the existing documentation style.
  • Cache key rotation: "rotate the paired graphics/compute cache keys" — ensures the updated tracking semantics are reflected in the cache key computation so old cache entries don't produce stale results.
  • Verification: The test list includes the MAD64 controls (startup_gfx2hlsl_mad64_check.py), shader cache key check, compute request offline check, and rekey check — all pure-Python, runnable on Apple Silicon. Good regression prevention.

⚠️ Minor observations

  1. startup_gfx2hlsl_mad64_check.py: The PR says this "verifies these effects and the clear-fact transfer at a skipped-block join." If this test is new or changed, consider whether it was run against a baseline where both VCC halves were NOT tracked (to show the before/after difference). A note in the PR body about what the test specifically validates (e.g., "the test creates a skipped block after a mad64 with discarded carry and checks that vcc_hi remains clear") would help reviewers who aren't deep in the skipped-block proofs.

  2. Scope: The PR mentions "preserve discarded/signed admission" — the signed form's null destination behavior is unchanged. This is correctly documented in the docs/experiments.md entry which notes "The signed form's admitted null destination is unchanged."

Recommendation

Looks ready. Clean doc update with the necessary behavior change for the skipped-block proof.

🏷 If the skipped-block proof framework gains more VOP3B carry-out instructions in future PRs, consider whether these VCC-half tracking rules should be centralized in a shared data structure rather than scattered across individual instruction handlers.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083431778 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2979#pullrequestreview-6083431778). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-27T04:17:15Z. **Review:** COMMENTED --- Important nuance — the wave64 skipped-block liveness proof needs both VCC halves tracked for unsigned VOP3B carry-out. A discarded carry doesn't invalidate either half, but the proof must not let a stale clear `vcc_hi` fact survive a skipped-block join. ## Findings ### ✅ What works well - **Correct semantics**: `v_mad_u64_u32` carry-out with `vcc_lo` may also write `vcc_hi` in the wave64 convention. The discarded carry doesn't invalidate either half — the high-half clear fact from the previous block can survive through the join without being invalidated by a discarded carry. - **`docs/experiments.md` update**: Adds one clear sentence in the mad64 section documenting the VCC half tracking nuance. Consistent with the existing documentation style. - **Cache key rotation**: "rotate the paired graphics/compute cache keys" — ensures the updated tracking semantics are reflected in the cache key computation so old cache entries don't produce stale results. - **Verification**: The test list includes the MAD64 controls (`startup_gfx2hlsl_mad64_check.py`), shader cache key check, compute request offline check, and rekey check — all pure-Python, runnable on Apple Silicon. Good regression prevention. ### ⚠️ Minor observations 1. **`startup_gfx2hlsl_mad64_check.py`**: The PR says this "verifies these effects and the clear-fact transfer at a skipped-block join." If this test is new or changed, consider whether it was run against a baseline where both VCC halves were NOT tracked (to show the before/after difference). A note in the PR body about what the test specifically validates (e.g., "the test creates a skipped block after a mad64 with discarded carry and checks that vcc_hi remains clear") would help reviewers who aren't deep in the skipped-block proofs. 2. **Scope**: The PR mentions "preserve discarded/signed admission" — the signed form's `null` destination behavior is unchanged. This is correctly documented in the `docs/experiments.md` entry which notes "The signed form's admitted null destination is unchanged." ### Recommendation Looks ready. Clean doc update with the necessary behavior change for the skipped-block proof. 🏷 If the skipped-block proof framework gains more VOP3B carry-out instructions in future PRs, consider whether these VCC-half tracking rules should be centralized in a shared data structure rather than scattered across individual instruction handlers.
chadhyatt commented 2026-11-27 04:18:39 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-27T04:18:39Z.


Thanks. The independent baseline result in thepatrickworld’s earlier comment confirms the new VCC-half control fails on the pre-change translator and passes at this head, including discarded-carry preservation. The helper-level transfer is pinned; no claim of additional end-to-end skipped-block coverage or GPU execution. Ready from my side.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7209694693 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2979#issuecomment-7209694693). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-27T04:18:39Z. --- Thanks. The independent baseline result in thepatrickworld’s earlier comment confirms the new VCC-half control fails on the pre-change translator and passes at this head, including discarded-carry preservation. The helper-level transfer is pinned; no claim of additional end-to-end skipped-block coverage or GPU execution. Ready from my side.
R0Y00 commented 2026-11-27 05:00:52 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T05:00:52Z.

Review: APPROVED


Reviewed 3286a2630932007d67f906f5f6b7febbf1d2f7ed. The may-write proof now covers both VCC halves for unsigned VOP3B carry, and both C++ and Python request seeds were bumped together. In a Release merge trial with main 57f9e07f, the MAD64 controls and WARP/hardware readbacks, shader cache key, offline compute request, stream draw and compute dispatch passed. The new helper-level control covers the stale-high-half proof; the draw fixtures cover the existing lowering. Independent Windows 11 26200.9974 testing used WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 where applicable. Required Windows CI passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6083688469 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2979#pullrequestreview-6083688469). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T05:00:52Z. **Review:** APPROVED --- Reviewed `3286a2630932007d67f906f5f6b7febbf1d2f7ed`. The may-write proof now covers both VCC halves for unsigned VOP3B carry, and both C++ and Python request seeds were bumped together. In a Release merge trial with main `57f9e07f`, the MAD64 controls and WARP/hardware readbacks, shader cache key, offline compute request, stream draw and compute dispatch passed. The new helper-level control covers the stale-high-half proof; the draw fixtures cover the existing lowering. Independent Windows 11 26200.9974 testing used WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 where applicable. Required Windows CI passed.
chadhyatt commented 2026-11-27 05:02:00 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-27T05:02:00Z.


Thanks for the exact-head merge trial and Windows controls. Recorded the approval, including both request seed updates and the stale-high-half proof; no further changes from my side.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7210292257 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2979#issuecomment-7210292257). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-27T05:02:00Z. --- Thanks for the exact-head merge trial and Windows controls. Recorded the approval, including both request seed updates and the stale-high-half proof; no further changes from my side.
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!2979
No description provided.