shader: lower scalar add, sub, and, or, xor and shift on known words in the compute store profile #1083

Merged
tedin7 merged 4 commits from upstream-pr/1090 into main 2026-11-24 02:04:14 +00:00
tedin7 commented 2026-11-24 00:48:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T00:48:28Z.


Change

The compute store profile now accepts s_add_u32, s_sub_u32, s_and_b32, s_or_b32, s_xor_b32 and s_lshr_b32 on known words (constant-buffer words, inline constants, literals and earlier results). The result is an inline HLSL expression, can feed vector instructions, and is data only: not an address and not a lane-guard compare operand. SCC is not modelled because no accepted instruction reads it. Docs: new "Scalar ALU on known words" section in docs/experiments.md.

Refs #721 (step 4, arithmetic). The vector ALU additions in #1083 touch the same files; this change adds a separate table, regex branch and test function, and does not edit the lines #1083 changes.

This change was AI-assisted.

Verification

  • python3 -B tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so: exit 0 with this change.
  • Negative control: the same command with tools/compute_store_aot.py from origin/main fails with Unsupported compute instruction: s_add_u32 s16, s0, 7.
  • Added a dedicated 320-word readback (draw_scalar, case read_scalar, mode draw-guard-read) with an independent Python reference (scalar_chain/scalar_word). Inputs make the add and the sub both wrap, and the minimum take each operand (35 lanes the product, 115 the chain, last run). Wrong references (max for min, each of add/sub/and/or/xor dropped, shift by 2, wrong xor operand) must fail at the exact first differing word, and the same six edits to the translated HLSL must fail the readback.
  • Not run: the draw mode itself (needs D3D12 on Windows; CI Windows jobs are the check). Locally I confirmed each reference control differs at word 0, each HLSL edit changes the source, and the translated chain expression evaluated in Python equals scalar_chain for bounds 0, 17 and 150.

Evidence and follow-up

  • The fixture is the existing synthetic read-compute-write program with a six-instruction scalar chain inserted, assembled with llvm-mc; the test requires the decoded program to lower to the same HLSL as its text, and the exact expression is checked.
  • Rejections covered: signed, carry-in and 64-bit forms, unwritten, descriptor, exec-mask and pending sources, destinations past s105 or pending, a vector or over-wide source, overwriting the saved exec mask, use as address or guard operand, and the expression-size limit.
  • Follow-up: a runtime reference for the scalar chain so it can join the draw modes.

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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6572027454 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1090). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T00:48:28Z. --- ## Change The compute store profile now accepts `s_add_u32`, `s_sub_u32`, `s_and_b32`, `s_or_b32`, `s_xor_b32` and `s_lshr_b32` on known words (constant-buffer words, inline constants, literals and earlier results). The result is an inline HLSL expression, can feed vector instructions, and is data only: not an address and not a lane-guard compare operand. SCC is not modelled because no accepted instruction reads it. Docs: new "Scalar ALU on known words" section in `docs/experiments.md`. Refs #721 (step 4, arithmetic). The vector ALU additions in #1083 touch the same files; this change adds a separate table, regex branch and test function, and does not edit the lines #1083 changes. This change was AI-assisted. ## Verification - `python3 -B tests/compute_store_check.py binary llvm-mc-19 llvm-objcopy-19 /usr/lib/llvm-19/lib/libLLVM-19.so`: exit 0 with this change. - Negative control: the same command with `tools/compute_store_aot.py` from origin/main fails with `Unsupported compute instruction: s_add_u32 s16, s0, 7`. - Added a dedicated 320-word readback (`draw_scalar`, case `read_scalar`, mode draw-guard-read) with an independent Python reference (`scalar_chain`/`scalar_word`). Inputs make the add and the sub both wrap, and the minimum take each operand (35 lanes the product, 115 the chain, last run). Wrong references (max for min, each of add/sub/and/or/xor dropped, shift by 2, wrong xor operand) must fail at the exact first differing word, and the same six edits to the translated HLSL must fail the readback. - Not run: the draw mode itself (needs D3D12 on Windows; CI Windows jobs are the check). Locally I confirmed each reference control differs at word 0, each HLSL edit changes the source, and the translated chain expression evaluated in Python equals `scalar_chain` for bounds 0, 17 and 150. ## Evidence and follow-up - The fixture is the existing synthetic read-compute-write program with a six-instruction scalar chain inserted, assembled with llvm-mc; the test requires the decoded program to lower to the same HLSL as its text, and the exact expression is checked. - Rejections covered: signed, carry-in and 64-bit forms, unwritten, descriptor, exec-mask and pending sources, destinations past s105 or pending, a vector or over-wide source, overwriting the saved exec mask, use as address or guard operand, and the expression-size limit. - Follow-up: a runtime reference for the scalar chain so it can join the draw modes. ## 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.
upstream-sync closed this pull request 2026-11-24 06:46:15 +00:00
chatgpt-codex-connector[bot commented 2026-11-24 06:49:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T00:48:41Z.


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-24T00:52:06.016520Z 16df191 PR opened
ℹ️ 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:7118457040 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1090#issuecomment-7118457040). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-24T00:48:41Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"16df191a00c7ba1b540bca6369fc952696ea8dff","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-24T00:52:06.016520Z">2026-11-24T00:52:06.016520Z</relative-time> | `16df191` | PR opened | <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-24 06:50:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T01:33:31Z.


AI-assisted. Merged origin/main into the branch to resolve a conflict in tests/compute_store_check.py (both sides added independent cases; both are kept). tests/compute_store_check.py passes locally with LLVM 19.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7119219120 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1090#issuecomment-7119219120). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T01:33:31Z. --- AI-assisted. Merged origin/main into the branch to resolve a conflict in tests/compute_store_check.py (both sides added independent cases; both are kept). tests/compute_store_check.py passes locally with LLVM 19.
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!1083
No description provided.