startup: model the SCC of s_add, s_sub, s_min and s_max in gfx2hlsl #2770

Merged
tedin7 merged 8 commits from upstream-pr/2778 into main 2026-11-26 09:33:27 +00:00
tedin7 commented 2026-11-26 08:15:06 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:15:06Z.


Part of #1723

What this unblocks: stops silently wrong shader output when a branch or select reads the SCC of s_add, s_sub, s_min or s_max.
Source: AMD "RDNA 2" Instruction Set Architecture reference guide, SOP2 instructions S_ADD_U32, S_SUB_U32, S_ADD_I32, S_SUB_I32, S_MIN_, S_MAX_ (SCC result definitions) and SOPC / S_CBRANCH_SCC branches that read SCC.

What changed

s_add_u32/i32, s_sub_u32/i32, s_min_u32/i32 and s_max_u32/i32 were in SCC_UNMODELLED: the lowering emitted the result and left the emitted scc as it was. A later s_cbranch_scc0/1, s_cselect or src_scc read a stale value (for example s_add_u32 s23, s7, -1 then s_cbranch_scc1 branched on a variable that was never assigned).

  • (a) The SCC of these forms is now emitted from the sources, ahead of the destination write (the destination can be a source), as the RDNA 2 ISA defines it: s_add_u32 carry out, s_sub_u32 borrow (S0 < S1), s_add_i32 / s_sub_i32 signed overflow, s_min / s_max SCC = (D == S0), i.e. the first source was chosen (equal operands included). A null destination keeps only the SCC. Uniformity of the SCC follows its sources like any other SCC write.
  • (b) Safety net: an instruction that writes SCC (per scalar_effects, plus s_wqm and s_quadmask) and emits nothing for it is recorded; a later SCC reader reachable from it is refused by name: scc from an SCC write that is not modelled in <reader>.
  • (c) The existing controls that expected the old refusals now check the new behaviour: the address-carry near misses in startup_gfx2hlsl_compute_check.py (an intervening s_sub_u32, a non-adjacent high add, a different addend or destination now translate with the exact SCC; the branch-into-the-add and the elided descriptor arithmetic stay refused), startup_gfx2hlsl_src_scc_check.py (reads after s_add_u32 see its carry), startup_gfx2hlsl_scalar_null_check.py (a null destination computes only its SCC), startup_gfx2hlsl_readfirstlane_uniform_check.py (a select after a carry from a uniform source is proven uniform) and the golden HLSL of startup_gfx2hlsl_heap_record_check.py / heap_word_check.py (one more scc = ... line per add).

Same shape in the HLSL of 18 existing translated shapes: one more scc = ... line each, nothing newly translated or refused.

Tests

  • New real-GPU readback case S in tests/startup_gfx2hlsl_compute_check.py (startup_gfx2hlsl_compute_{warp,hardware}): a 4 x 4 grid of 16 groups (the runner accepts at most 5 per axis; S0 from the x index, S1 from the y index), S0 and S1 each from {0, -1, 0x7fffffff, 0x80000000}; all eight forms, each with the destination apart from S0 and with the destination equal to S0; per group a word of the 16 SCC bits and a hash of the 16 results, against a Python reference written from the ISA rules.
  • Wrong-value controls s-min-strict (strict compare in s_min_u32) and s-borrow-flipped (operands of the borrow swapped), registered in CMakeLists.txt like the other controls; each must be rejected at a word.
  • check_scc_modelled: the exact SCC text of each form ahead of the branch (fails on main), and the named refusal for a reader after s_wqm.

What stays open

  • The s_min / s_max equal-operand SCC follows the ISA pseudo-code (SCC = D == S0); the WARP readback checks the lowering against that rule, not against silicon.
  • s_addc_u32 / s_subb_u32 remain refused.

Verification:

  • python3 -B tests/startup_gfx2hlsl_compute_check.py and ... binary llvm-mc-19: pass.
  • python3 -B tests/startup_gfx2hlsl_{heap_record,heap_word,readfirstlane_uniform,scalar_null,src_scc}_check.py: pass.
  • Sweep tests/*check.py against origin/main: only the scripts named above changed, each updated in this PR (see the sweep below).
  • Win2025 WARP dev+release: pending Stage-2.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6622385047 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:15:06Z. --- Part of #1723 What this unblocks: stops silently wrong shader output when a branch or select reads the SCC of `s_add`, `s_sub`, `s_min` or `s_max`. Source: AMD "RDNA 2" Instruction Set Architecture reference guide, SOP2 instructions S_ADD_U32, S_SUB_U32, S_ADD_I32, S_SUB_I32, S_MIN_*, S_MAX_* (SCC result definitions) and SOPC / S_CBRANCH_SCC branches that read SCC. ## What changed `s_add_u32/i32`, `s_sub_u32/i32`, `s_min_u32/i32` and `s_max_u32/i32` were in `SCC_UNMODELLED`: the lowering emitted the result and left the emitted `scc` as it was. A later `s_cbranch_scc0/1`, `s_cselect` or `src_scc` read a stale value (for example `s_add_u32 s23, s7, -1` then `s_cbranch_scc1` branched on a variable that was never assigned). - (a) The SCC of these forms is now emitted from the sources, ahead of the destination write (the destination can be a source), as the RDNA 2 ISA defines it: `s_add_u32` carry out, `s_sub_u32` borrow (S0 < S1), `s_add_i32` / `s_sub_i32` signed overflow, `s_min` / `s_max` SCC = (D == S0), i.e. the first source was chosen (equal operands included). A `null` destination keeps only the SCC. Uniformity of the SCC follows its sources like any other SCC write. - (b) Safety net: an instruction that writes SCC (per `scalar_effects`, plus `s_wqm` and `s_quadmask`) and emits nothing for it is recorded; a later SCC reader reachable from it is refused by name: `scc from an SCC write that is not modelled in <reader>`. - (c) The existing controls that expected the old refusals now check the new behaviour: the address-carry near misses in `startup_gfx2hlsl_compute_check.py` (an intervening `s_sub_u32`, a non-adjacent high add, a different addend or destination now translate with the exact SCC; the branch-into-the-add and the elided descriptor arithmetic stay refused), `startup_gfx2hlsl_src_scc_check.py` (reads after `s_add_u32` see its carry), `startup_gfx2hlsl_scalar_null_check.py` (a null destination computes only its SCC), `startup_gfx2hlsl_readfirstlane_uniform_check.py` (a select after a carry from a uniform source is proven uniform) and the golden HLSL of `startup_gfx2hlsl_heap_record_check.py` / `heap_word_check.py` (one more `scc = ...` line per add). Same shape in the HLSL of 18 existing translated shapes: one more `scc = ...` line each, nothing newly translated or refused. ## Tests - New real-GPU readback case `S` in `tests/startup_gfx2hlsl_compute_check.py` (`startup_gfx2hlsl_compute_{warp,hardware}`): a 4 x 4 grid of 16 groups (the runner accepts at most 5 per axis; S0 from the x index, S1 from the y index), S0 and S1 each from {0, -1, 0x7fffffff, 0x80000000}; all eight forms, each with the destination apart from S0 and with the destination equal to S0; per group a word of the 16 SCC bits and a hash of the 16 results, against a Python reference written from the ISA rules. - Wrong-value controls `s-min-strict` (strict compare in `s_min_u32`) and `s-borrow-flipped` (operands of the borrow swapped), registered in `CMakeLists.txt` like the other controls; each must be rejected at a word. - `check_scc_modelled`: the exact SCC text of each form ahead of the branch (fails on `main`), and the named refusal for a reader after `s_wqm`. ## What stays open - The `s_min` / `s_max` equal-operand SCC follows the ISA pseudo-code (`SCC = D == S0`); the WARP readback checks the lowering against that rule, not against silicon. - `s_addc_u32` / `s_subb_u32` remain refused. Verification: - `python3 -B tests/startup_gfx2hlsl_compute_check.py` and `... binary llvm-mc-19`: pass. - `python3 -B tests/startup_gfx2hlsl_{heap_record,heap_word,readfirstlane_uniform,scalar_null,src_scc}_check.py`: pass. - Sweep `tests/*check.py` against `origin/main`: only the scripts named above changed, each updated in this PR (see the sweep below). - Win2025 WARP dev+release: pending Stage-2. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 09:04:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:48:44Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 17a05d9a49

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6070955031 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#pullrequestreview-6070955031). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T08:48:44Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `17a05d9a49` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
tedin7 commented 2026-11-26 09:04:48 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:59:44Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6071098323 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#pullrequestreview-6071098323). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:59:44Z. **Review:** COMMENTED --- _No description provided._
tedin7 commented 2026-11-26 09:04:49 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:59:47Z.

Review: COMMENTED


No description provided.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6071098893 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#pullrequestreview-6071098893). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:59:47Z. **Review:** COMMENTED --- _No description provided._
R0Y00 commented 2026-11-26 09:04:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T08:30:01Z.


Two findings on cfd84d2d from a native Windows 11 build 26200 Release run.

  1. All four new SCC control CTests fail before dispatch with Invalid compute store reference. Case S uses 16×1×1 groups, but read_store_reference caps each axis at 5. Command: ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_compute_s-(min-strict|borrow-flipped)_(warp|hardware)$' -V. In a local test-only control limited to 16×1×1, all four ran. The min mutation changed 4/320 words and flipped borrow changed 12/320 on each adapter, as expected. Please keep all sixteen input pairs and use a fixture shape that the reader accepts, or extend the test reader with a bounded case.
  2. With that same test-only control, the exact case S shader generated by main at 96a7b4fb had 16/320 mismatches on each adapter (first word expected 0000ff00, actual 00000000). The new shader had 0/320. Both use the same compute cache key with identical inputs, so existing cached bytecode can mask the fix. Please advance the shared runtime/offline key after the other shader guard PRs and retain a known-answer check.

WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 with debug enabled. Six focused Python controls passed before the test-only reader edit.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186668050 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#issuecomment-7186668050). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T08:30:01Z. --- Two findings on `cfd84d2d` from a native Windows 11 build 26200 Release run. 1. All four new SCC control CTests fail before dispatch with `Invalid compute store reference`. Case S uses 16×1×1 groups, but `read_store_reference` caps each axis at 5. Command: `ctest --preset release --no-tests=error -j 1 -R '^startup_gfx2hlsl_compute_s-(min-strict|borrow-flipped)_(warp|hardware)$' -V`. In a local test-only control limited to 16×1×1, all four ran. The min mutation changed 4/320 words and flipped borrow changed 12/320 on each adapter, as expected. Please keep all sixteen input pairs and use a fixture shape that the reader accepts, or extend the test reader with a bounded case. 2. With that same test-only control, the exact case S shader generated by main at `96a7b4fb` had 16/320 mismatches on each adapter (first word expected `0000ff00`, actual `00000000`). The new shader had 0/320. Both use the same compute cache key with identical inputs, so existing cached bytecode can mask the fix. Please advance the shared runtime/offline key after the other shader guard PRs and retain a known-answer check. WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 with debug enabled. Six focused Python controls passed before the test-only reader edit.
RavenCurseBurg commented 2026-11-26 09:04:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T08:39:41Z.


I will independently verify the newly modelled SCC outputs when the scalar destination aliases the second input, including carry/borrow, signed overflow and equal min/max operands. I will source-assemble a separate fixture, use a CPU integer reference, and check the stored results and SCC observations on native Intel, NVIDIA and WARP.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186865392 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#issuecomment-7186865392). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T08:39:41Z. --- I will independently verify the newly modelled SCC outputs when the scalar destination aliases the **second** input, including carry/borrow, signed overflow and equal min/max operands. I will source-assemble a separate fixture, use a CPU integer reference, and check the stored results and SCC observations on native Intel, NVIDIA and WARP.
tedin7 commented 2026-11-26 09:04:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:45:55Z.


Thank you for the native run. Both findings, on head edc27b203:

  1. Group axis: case S is a 4 x 4 x 1 grid now (S0 from the x index, S1 from the y index), so read_store_reference accepts it with all sixteen input pairs and no C++ change. The expected words and the two controls (s-min-strict, s-borrow-flipped) are unchanged; each control text still occurs exactly once in the generated HLSL.
  2. Cache key: the graphics and compute revisions advance from x2w-startup-shader-25 / 25cs to 26 / 26cs (runtime d3d12_draw.inl, offline gfx2hlsl.py, the two C++ test mirrors, the docs line). The known-answer checks stay and carry the new values: the graphics vector pair in startup_shader_cache_key_check.py (recomputed with a separate FNV-1a loop, same result) and the framed compute key in startup_compute_request_offline_check.py; startup_gfx2hlsl_fract_check.py pins the revision. The C++ targets were not built here. Note for the merge order: any other PR that changes translated output without advancing the revision (for example the whole-wave branch refusals in #2772, whose refused programs could still be served from a cached translation) is covered by this bump only if this PR merges after it; if this one merges first, the later PR needs its own bump to 27.

Verification:

  • python3 -B tests/startup_gfx2hlsl_compute_check.py (and binary llvm-mc-19), startup_shader_cache_key_check.py, startup_compute_request_offline_check.py, startup_gfx2hlsl_fract_check.py, startup_gfx2hlsl_buffer_store_check.py, startup_packed_position_provenance_check.py: pass.
  • tests/*check.py sweep against origin/main: no script changes result.
  • Win2025 WARP dev+release: pending Stage-2.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186990400 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#issuecomment-7186990400). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:45:55Z. --- Thank you for the native run. Both findings, on head edc27b203: 1. Group axis: case S is a 4 x 4 x 1 grid now (S0 from the x index, S1 from the y index), so `read_store_reference` accepts it with all sixteen input pairs and no C++ change. The expected words and the two controls (`s-min-strict`, `s-borrow-flipped`) are unchanged; each control text still occurs exactly once in the generated HLSL. 2. Cache key: the graphics and compute revisions advance from `x2w-startup-shader-25` / `25cs` to `26` / `26cs` (runtime `d3d12_draw.inl`, offline `gfx2hlsl.py`, the two C++ test mirrors, the docs line). The known-answer checks stay and carry the new values: the graphics vector pair in `startup_shader_cache_key_check.py` (recomputed with a separate FNV-1a loop, same result) and the framed compute key in `startup_compute_request_offline_check.py`; `startup_gfx2hlsl_fract_check.py` pins the revision. The C++ targets were not built here. Note for the merge order: any other PR that changes translated output without advancing the revision (for example the whole-wave branch refusals in #2772, whose refused programs could still be served from a cached translation) is covered by this bump only if this PR merges after it; if this one merges first, the later PR needs its own bump to 27. Verification: - `python3 -B tests/startup_gfx2hlsl_compute_check.py` (and `binary llvm-mc-19`), `startup_shader_cache_key_check.py`, `startup_compute_request_offline_check.py`, `startup_gfx2hlsl_fract_check.py`, `startup_gfx2hlsl_buffer_store_check.py`, `startup_packed_position_provenance_check.py`: pass. - `tests/*check.py` sweep against `origin/main`: no script changes result. - Win2025 WARP dev+release: pending Stage-2. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 09:04:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:40:22Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T09:14:09.781866Z 04d19ce Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186878986 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#issuecomment-7186878986). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T08:40:22Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"04d19ce641c0246fb6e7507336d33eb21f2a0ad9","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-26T09:14:09.781866Z">2026-11-26T09:14:09.781866Z</relative-time> | `04d19ce` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
tedin7 commented 2026-11-26 09:04:55 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:40:09Z.


Independent Stage-2 gate of head e2659bf4c: PASS (supersedes my earlier receipts for 17a05d9a4, edc27b203 and 04d19ce64).

Checked:

  • The SCC rule of s_add_u32/i32, s_sub_u32/i32 and s_min/s_max_u32/i32 (add_sub_min_max_scc) evaluated with u32 / int semantics over 39200 operand pairs per run (edge values and random) against the RDNA 2 ISA rule written out by hand: 0 mismatches. The SCC is emitted ahead of the destination write, also when the destination is a source.
  • The GPU readback case S now dispatches 4x4 groups (the runner takes at most 5 per axis) and runs; the two wrong-value controls are rejected at a word.

Verification:

  • python3 -B tests/startup_gfx2hlsl_compute_check.py and ... binary llvm-mc-19, and the five other scripts of the PR: pass on Linux; sweep of tests/*check.py against origin/main: 0 scripts change result.
  • x2w_pipe.py win2025 2778 --force --keep-release --regex 'gfx2hlsl|startup_compute' on WARP: dev 450/450 and release 450/450 passed, including startup_gfx2hlsl_compute_{warp,hardware}, ..._s-min-strict_{warp,hardware} and ..._s-borrow-flipped_{warp,hardware}.

Open, as the PR says: the s_min / s_max equal-operand SCC follows the ISA pseudo-code, checked against that rule and not against silicon.

Update, head 04d19ce64 (fixes the two review threads of edc27b203):

  • src_scc as an operand of s_add / s_sub / s_min / s_max: the destination is written first and the SCC after, from the incoming SCC; a destination that is also a source (or m0, exec, vcc, null) is refused by name. All eight forms with src_scc as first or second operand give the right destination and SCC.
  • check_scc_modelled is now called from the controls; with the old order (SCC first) startup_gfx2hlsl_src_scc_check fails.
  • x2w_pipe.py win2025 2778 --force --keep-release --regex 'gfx2hlsl|startup_compute|shader_cache_key' on WARP: dev 451/451 and release 451/451 passed; Linux scripts and the sweep against origin/main (0 scripts change result) pass.

Update, head e2659bf4c (main merged in, cache revision 27): fresh_gate GO (0 behind origin/main); the same Linux scripts, the src_scc forms and the sweep against origin/main (0 scripts change result) pass; x2w_pipe.py win2025 2778 --force --keep-release --regex 'gfx2hlsl|startup_compute|shader_cache_key': dev 453/453 and release 453/453 passed.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7186874616 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#issuecomment-7186874616). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:40:09Z. --- Independent Stage-2 gate of head e2659bf4c: PASS (supersedes my earlier receipts for 17a05d9a4, edc27b203 and 04d19ce64). Checked: - The SCC rule of s_add_u32/i32, s_sub_u32/i32 and s_min/s_max_u32/i32 (`add_sub_min_max_scc`) evaluated with u32 / int semantics over 39200 operand pairs per run (edge values and random) against the RDNA 2 ISA rule written out by hand: 0 mismatches. The SCC is emitted ahead of the destination write, also when the destination is a source. - The GPU readback case S now dispatches 4x4 groups (the runner takes at most 5 per axis) and runs; the two wrong-value controls are rejected at a word. Verification: - `python3 -B tests/startup_gfx2hlsl_compute_check.py` and `... binary llvm-mc-19`, and the five other scripts of the PR: pass on Linux; sweep of `tests/*check.py` against `origin/main`: 0 scripts change result. - `x2w_pipe.py win2025 2778 --force --keep-release --regex 'gfx2hlsl|startup_compute'` on WARP: dev 450/450 and release 450/450 passed, including `startup_gfx2hlsl_compute_{warp,hardware}`, `..._s-min-strict_{warp,hardware}` and `..._s-borrow-flipped_{warp,hardware}`. Open, as the PR says: the s_min / s_max equal-operand SCC follows the ISA pseudo-code, checked against that rule and not against silicon. Update, head 04d19ce64 (fixes the two review threads of edc27b203): - `src_scc` as an operand of s_add / s_sub / s_min / s_max: the destination is written first and the SCC after, from the incoming SCC; a destination that is also a source (or m0, exec, vcc, null) is refused by name. All eight forms with `src_scc` as first or second operand give the right destination and SCC. - `check_scc_modelled` is now called from the controls; with the old order (SCC first) `startup_gfx2hlsl_src_scc_check` fails. - `x2w_pipe.py win2025 2778 --force --keep-release --regex 'gfx2hlsl|startup_compute|shader_cache_key'` on WARP: dev 451/451 and release 451/451 passed; Linux scripts and the sweep against `origin/main` (0 scripts change result) pass. Update, head e2659bf4c (main merged in, cache revision 27): `fresh_gate` GO (0 behind `origin/main`); the same Linux scripts, the `src_scc` forms and the sweep against `origin/main` (0 scripts change result) pass; `x2w_pipe.py win2025 2778 --force --keep-release --regex 'gfx2hlsl|startup_compute|shader_cache_key'`: dev 453/453 and release 453/453 passed. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-26 09:04:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:48:44Z.

Code review location: tools/startup/gfx2hlsl.py; line 5177

@@ -5173,7 +5173,8 @@ def src_sym(t):
             self.set_scc('(%s) < %s' % (expr, values[0]))
             self.address_carry_reader = self.address_carry_pairs[self.pc]
         elif base in SCC_UNMODELLED:
-            self.scc_verified = False
+            # From the sources, before the destination is written (it can be a source).
+            self.set_scc(add_sub_min_max_scc(base, values[0], values[1], expr))

P1 Badge Snapshot incoming SCC before emitting its replacement

When an operand is src_scc, values and expr contain a live reference to the HLSL scc variable. This assignment overwrites that variable before the destination expression is emitted, so the destination reads the outgoing SCC instead of the incoming operand. For example, s_cmp_eq_u32 0, 0; s_add_u32 s1, src_scc, 1 now clears scc and then assigns s1 = 1, although the ISA result and the parent lowering produce 2. The newly accepted non-adjacent carry-read adds are affected too. Preserve the incoming SCC or compute the result into a temporary before committing the new SCC.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4705804212 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#discussion_r4705804212). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T08:48:44Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 5177 ~~~~diff @@ -5173,7 +5173,8 @@ def src_sym(t): self.set_scc('(%s) < %s' % (expr, values[0])) self.address_carry_reader = self.address_carry_pairs[self.pc] elif base in SCC_UNMODELLED: - self.scc_verified = False + # From the sources, before the destination is written (it can be a source). + self.set_scc(add_sub_min_max_scc(base, values[0], values[1], expr)) ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Snapshot incoming SCC before emitting its replacement** When an operand is `src_scc`, `values` and `expr` contain a live reference to the HLSL `scc` variable. This assignment overwrites that variable before the destination expression is emitted, so the destination reads the outgoing SCC instead of the incoming operand. For example, `s_cmp_eq_u32 0, 0; s_add_u32 s1, src_scc, 1` now clears `scc` and then assigns `s1 = 1`, although the ISA result and the parent lowering produce `2`. The newly accepted non-adjacent carry-read adds are affected too. Preserve the incoming SCC or compute the result into a temporary before committing the new SCC. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-26 09:04:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-26T08:48:44Z.

Code review location: tests/startup_gfx2hlsl_compute_check.py; line 1258

@@ -1176,6 +1255,35 @@ def splice_words(*chunks, at=STORE_A):
     return WORDS_A[:at] + b''.join(chunks) + WORDS_A[at:]
 
 
+def check_scc_modelled():

P2 Badge Invoke the new SCC regression helper from the controls runner

A repository-wide search finds only this definition: neither check_controls() nor any __main__ mode calls it. Consequently, the per-form branch assertions and both s_wqm stale-SCC refusal cases are skipped by the Linux and CTest controls runs. Wire this helper into check_controls() so those regressions are exercised. Calling it directly currently also exposes a hidden assertion failure: the decoder returns s_cbranch_scc1 label_0x8, while the assertion expects s_cbranch_scc1 1.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4705804221 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#discussion_r4705804221). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-26T08:48:44Z. **Code review location:** `tests/startup_gfx2hlsl_compute_check.py`; line 1258 ~~~~diff @@ -1176,6 +1255,35 @@ def splice_words(*chunks, at=STORE_A): return WORDS_A[:at] + b''.join(chunks) + WORDS_A[at:] +def check_scc_modelled(): ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Invoke the new SCC regression helper from the controls runner** A repository-wide search finds only this definition: neither `check_controls()` nor any `__main__` mode calls it. Consequently, the per-form branch assertions and both `s_wqm` stale-SCC refusal cases are skipped by the Linux and CTest controls runs. Wire this helper into `check_controls()` so those regressions are exercised. Calling it directly currently also exposes a hidden assertion failure: the decoder returns `s_cbranch_scc1 label_0x8`, while the assertion expects `s_cbranch_scc1 1`. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
tedin7 commented 2026-11-26 09:04:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:59:44Z.

Code review location: tools/startup/gfx2hlsl.py; line 5177

@@ -5173,7 +5173,8 @@ def src_sym(t):
             self.set_scc('(%s) < %s' % (expr, values[0]))
             self.address_carry_reader = self.address_carry_pairs[self.pc]
         elif base in SCC_UNMODELLED:
-            self.scc_verified = False
+            # From the sources, before the destination is written (it can be a source).
+            self.set_scc(add_sub_min_max_scc(base, values[0], values[1], expr))

Real, and fixed on 04d19ce64: when an operand is src_scc, the add now writes its destination first and emits its own SCC afterwards, so the destination reads the incoming SCC (s_cmp_eq_u32 0, 0; s_add_u32 s1, src_scc, 1 gives s1 = (scc ? 1u : 0u) + 1u; and only then the carry). A destination that is also a source, or m0 / exec / vcc / null, combined with src_scc is refused by name (the carry could not be computed from unchanged sources). The previous assertion in startup_gfx2hlsl_src_scc_check.py only checked that the SCC line preceded a later reader, so it encoded the wrong order; it now pins the order and the refusal, and fails on the previous head. Linux: the six affected scripts and the sweep against origin/main pass (0 differ).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4705917675 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#discussion_r4705917675). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:59:44Z. **Code review location:** `tools/startup/gfx2hlsl.py`; line 5177 ~~~~diff @@ -5173,7 +5173,8 @@ def src_sym(t): self.set_scc('(%s) < %s' % (expr, values[0])) self.address_carry_reader = self.address_carry_pairs[self.pc] elif base in SCC_UNMODELLED: - self.scc_verified = False + # From the sources, before the destination is written (it can be a source). + self.set_scc(add_sub_min_max_scc(base, values[0], values[1], expr)) ~~~~ --- Real, and fixed on 04d19ce64: when an operand is `src_scc`, the add now writes its destination first and emits its own SCC afterwards, so the destination reads the incoming SCC (`s_cmp_eq_u32 0, 0; s_add_u32 s1, src_scc, 1` gives `s1 = (scc ? 1u : 0u) + 1u;` and only then the carry). A destination that is also a source, or m0 / exec / vcc / null, combined with `src_scc` is refused by name (the carry could not be computed from unchanged sources). The previous assertion in `startup_gfx2hlsl_src_scc_check.py` only checked that the SCC line preceded a later reader, so it encoded the wrong order; it now pins the order and the refusal, and fails on the previous head. Linux: the six affected scripts and the sweep against `origin/main` pass (0 differ). AI-assisted; commands listed were executed locally.
tedin7 commented 2026-11-26 09:04:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-26T08:59:47Z.

Code review location: tests/startup_gfx2hlsl_compute_check.py; line 1258

@@ -1176,6 +1255,35 @@ def splice_words(*chunks, at=STORE_A):
     return WORDS_A[:at] + b''.join(chunks) + WORDS_A[at:]
 
 
+def check_scc_modelled():

Real, and fixed on 04d19ce64: check_scc_modelled is now called from check_controls() (the call had been lost because it was added next to a helper that lives on another branch). Running it exposed the decoder text of the branch word (s_cbranch_scc1 label_0x8); the word check now compares the mnemonic for branches. The per-form SCC assertions and both s_wqm stale-SCC refusals run in the Linux and CTest controls now (checked by counting the call).

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4705918091 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#discussion_r4705918091). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T08:59:47Z. **Code review location:** `tests/startup_gfx2hlsl_compute_check.py`; line 1258 ~~~~diff @@ -1176,6 +1255,35 @@ def splice_words(*chunks, at=STORE_A): return WORDS_A[:at] + b''.join(chunks) + WORDS_A[at:] +def check_scc_modelled(): ~~~~ --- Real, and fixed on 04d19ce64: `check_scc_modelled` is now called from `check_controls()` (the call had been lost because it was added next to a helper that lives on another branch). Running it exposed the decoder text of the branch word (`s_cbranch_scc1 label_0x8`); the word check now compares the mnemonic for branches. The per-form SCC assertions and both `s_wqm` stale-SCC refusals run in the Linux and CTest controls now (checked by counting the call). AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 10:03:56 +00:00
R0Y00 commented 2026-11-26 10:03:56 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T09:33:19Z.

Review: APPROVED


Rechecked current e2659bf4 on native Windows 11 build 26200, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 with debug enabled. The 4×4×1 case ran through the unmodified renderer and matched all 320 words on both adapters. The strict-min tie and flipped-borrow controls gave 4 and 12 differences respectively on each. The compute translation tests and both graphics/compute cache-key checks passed. The shared runtime/offline revision is now 27/27cs. This resolves my two findings about the fixture grid and old cached shader reuse.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6071615907 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#pullrequestreview-6071615907). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T09:33:19Z. **Review:** APPROVED --- Rechecked current `e2659bf4` on native Windows 11 build 26200, WARP 10.0.26100.9818 and RTX 4060 Laptop 32.0.16.1656 with debug enabled. The 4×4×1 case ran through the unmodified renderer and matched all 320 words on both adapters. The strict-min tie and flipped-borrow controls gave 4 and 12 differences respectively on each. The compute translation tests and both graphics/compute cache-key checks passed. The shared runtime/offline revision is now 27/27cs. This resolves my two findings about the fixture grid and old cached shader reuse.
RavenCurseBurg commented 2026-11-26 10:04:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-26T09:16:04Z.


I checked the second-source alias on PR head 17a05d9a. For each of eight scalar ops the guest sets s21 = s5, executes op s21, s4, s21, and immediately saves SCC with s_cselect_b32. The two operands come from runtime root constants. Six input words, including equality, signed limits and unsigned wrap, give 36 ordered pairs. The CPU reference uses unbounded integer arithmetic and the PR's first-source tie rule.

WARP, Intel UHD 770 and RTX 4060 each passed all 36 dispatches with the translated DXC shader. Each readback checks 16 result/flag words and 304 sentinel words. Moving unsigned-add carry calculation after the aliased write produced exactly the 16 predicted word-1 failures on each adapter. The other 20 input pairs still passed that modified shader.

Reproduction script and guest assembly generator. With LLVM 15, DXC 1.9 and the MSVC-built renderer, run:

python tests/verify_second_operand_scc.py <clang> <llvm-objcopy> <dxc> <offscreen_check> warp

For physical adapters use hardware and set XBOX2WINDOWS_ADAPTER to the adapter substring. This covers the translated D3D12 behavior of the eight operations. I didn't measure tie behavior on native gfx1013 hardware.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7187688837 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2778#issuecomment-7187688837). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T09:16:04Z. --- I checked the second-source alias on PR head `17a05d9a`. For each of eight scalar ops the guest sets `s21 = s5`, executes `op s21, s4, s21`, and immediately saves SCC with `s_cselect_b32`. The two operands come from runtime root constants. Six input words, including equality, signed limits and unsigned wrap, give 36 ordered pairs. The CPU reference uses unbounded integer arithmetic and the PR's first-source tie rule. WARP, Intel UHD 770 and RTX 4060 each passed all 36 dispatches with the translated DXC shader. Each readback checks 16 result/flag words and 304 sentinel words. Moving unsigned-add carry calculation after the aliased write produced exactly the 16 predicted word-1 failures on each adapter. The other 20 input pairs still passed that modified shader. [Reproduction script and guest assembly generator](https://github.com/RavenCurseBurg/Xbox2Windows/blob/66123332bbadaeb6ae16e7584c308717d9e76626/tests/verify_second_operand_scc.py). With LLVM 15, DXC 1.9 and the MSVC-built renderer, run: ```text python tests/verify_second_operand_scc.py <clang> <llvm-objcopy> <dxc> <offscreen_check> warp ``` For physical adapters use `hardware` and set `XBOX2WINDOWS_ADAPTER` to the adapter substring. This covers the translated D3D12 behavior of the eight operations. I didn't measure tie behavior on native gfx1013 hardware.
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!2770
No description provided.