shader: lower s_quadmask_b64 in gfx2hlsl (#1723) #2670

Merged
SimSalabimse merged 3 commits from upstream-pr/2678 into main 2026-11-26 05:11:43 +00:00
SimSalabimse commented 2026-11-26 01:46:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by SimSalabimse on 2026-11-26T01:46:22Z.


Change

Part of #1723: port s_quadmask_b64 from pixel_aot into tools/startup/gfx2hlsl.py.

  • Each output bit is the OR of one four-bit group of the 64-bit source
  • Sixteen nibbles become bits 0..15 of D.lo; D.hi is 0
  • SCC = (D.lo | D.hi) != 0
  • A 32-bit SOP1 literal/inline zero-extends (high word 0) and folds
  • Lane masks, descriptor-bearing SGPRs, and odd-aligned pairs refused

Independent of open #2642 (s_quadmask_b32). Base is main.

AI-assisted.

Verification

Commit under test: this PR head.

python3 -B tests/startup_gfx2hlsl_s_quadmask_b64_check.py
# all ok

python3 -B tests/startup_gfx2hlsl_handler_arity_check.py
python3 -B tests/docs_links_check.py
python3 -B tests/bidi_controls_check.py

All passed on Linux (CPU evaluation of the translated text). Windows WARP/hardware draws were not run here; the fixture is device-free.

Windows (when available):

ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_quadmask_b64$' -V

Evidence and follow-up

  • Hand-assembled SOP1 encodings via disasm_rdna2 / gfx2hlsl.decode; no retail bytes.
  • Negative control: mutating the high-word shift (<< 8 → << 0) diverges from the ISA reference.

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:6617643681 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2678). Originally posted by [SimSalabimse](https://github.com/SimSalabimse) on 2026-11-26T01:46:22Z. --- ## Change Part of [#1723](https://github.com/R0Y00/Xbox2Windows/issues/1723): port `s_quadmask_b64` from `pixel_aot` into `tools/startup/gfx2hlsl.py`. - Each output bit is the OR of one four-bit group of the 64-bit source - Sixteen nibbles become bits 0..15 of `D.lo`; `D.hi` is 0 - `SCC = (D.lo | D.hi) != 0` - A 32-bit SOP1 literal/inline zero-extends (high word 0) and folds - Lane masks, descriptor-bearing SGPRs, and odd-aligned pairs refused Independent of open [#2642](https://github.com/R0Y00/Xbox2Windows/pull/2642) (`s_quadmask_b32`). Base is `main`. AI-assisted. ## Verification Commit under test: this PR head. ```bash python3 -B tests/startup_gfx2hlsl_s_quadmask_b64_check.py # all ok python3 -B tests/startup_gfx2hlsl_handler_arity_check.py python3 -B tests/docs_links_check.py python3 -B tests/bidi_controls_check.py ``` All passed on Linux (CPU evaluation of the translated text). Windows WARP/hardware draws were not run here; the fixture is device-free. Windows (when available): ```powershell ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_quadmask_b64$' -V ``` ## Evidence and follow-up - Hand-assembled SOP1 encodings via `disasm_rdna2` / `gfx2hlsl.decode`; no retail bytes. - Negative control: mutating the high-word shift (`<< 8` → `<< 0`) diverges from the ISA reference. ## 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.
tedin7 commented 2026-11-26 03:03:10 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Review of head 8cbbdc3d (s_quadmask_b64 in gfx2hlsl, Part of #1723).

One blocking finding: negative inline constants are zero-extended instead of sign-extended.

op_s_quadmask_b64, immediate branch (tools/startup/gfx2hlsl.py, the imm = re.fullmatch(r'-?(0x...|\d+)', ops[1]) block): the value is masked to 32 bits and the high word is taken as 0, for every immediate. For an inline integer constant (decoder prints it as a negative decimal, e.g. -1 = SSRC 0xc1) the 64-bit operand is the sign-extended value, so s_quadmask_b64 s[10:11], -1 must give all sixteen nibbles non-zero: D.lo = 0xffff. This PR folds it to 0x000000ff (and scc from that). The repository's own reference does it the other way: tools/pixel_aot.py scalar_u64() returns bits = value & 0xffffffffffffffff for -?\d+ tokens (so -1 -> hi 0xffffffff) and only zero-extends the 32-bit hex literal form (0x[0-9a-f]{1,8}). Same convention as s_mov_b64 exec, -1. The PR text says "A 32-bit SOP1 literal/inline zero-extends"; that holds for the literal, not for the inline negatives -1..-16.

Reproduction on the PR head (decode the words, run the handler): s_quadmask_b64 s[10:11], -1 -> s10 = 0x000000ffu; s11 = 0u, expected 0x0000ffffu; s_quadmask_b64 s[12:13], 0xffffffff -> 0x000000ffu is correct (literal, hi = 0).

Suggested fix: in the immediate branch, if the token is a negative decimal, sign-extend to 64 bits (bits = value & (2**64 - 1), fold nibble_mask(lo) | nibble_mask(hi) << 8); keep hex literals zero-extended. Add -1 (and e.g. -16) to the test's immediate list next to the existing 0xffffffff case; today the CPU reference in the test shares the same assumption, so it cannot catch this. A device readback of a one-instruction program with -1 would also guard it.

What else I checked (all fine)

  • Nibble folding for the register path: low word -> bits 0..7, high word -> bits 8..15, D.hi = 0, SCC = D != 0; even-aligned pairs only; lane masks and descriptor-bearing SGPRs refused.
  • Sibling forms: s_quadmask_b32 already merged (#2642); no other open or merged PR lowers s_quadmask_b64 in gfx2hlsl (#2076 was closed).
  • Linux (worktree at the PR head): tests/startup_gfx2hlsl_s_quadmask_b64_check.py, ..._handler_arity_check.py, ..._scalar_table_arity_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py pass; git diff --check origin/main...HEAD clean.
  • Registration: CMake, windows.yml (one list entry, .github care noted) and AGENTS.md updated.

I did not run Win2025 on this head because of the finding above; happy to once it is fixed. Merge left to the maintainers.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6067948301 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2678#pullrequestreview-6067948301). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-26T02:57:43Z. **Review:** COMMENTED --- Review of head 8cbbdc3d (`s_quadmask_b64` in gfx2hlsl, Part of #1723). **One blocking finding: negative inline constants are zero-extended instead of sign-extended.** `op_s_quadmask_b64`, immediate branch (`tools/startup/gfx2hlsl.py`, the `imm = re.fullmatch(r'-?(0x...|\d+)', ops[1])` block): the value is masked to 32 bits and the high word is taken as 0, for every immediate. For an inline integer constant (decoder prints it as a negative decimal, e.g. `-1` = SSRC 0xc1) the 64-bit operand is the sign-extended value, so `s_quadmask_b64 s[10:11], -1` must give all sixteen nibbles non-zero: `D.lo = 0xffff`. This PR folds it to `0x000000ff` (and `scc` from that). The repository's own reference does it the other way: `tools/pixel_aot.py` `scalar_u64()` returns `bits = value & 0xffffffffffffffff` for `-?\d+` tokens (so `-1` -> hi `0xffffffff`) and only zero-extends the 32-bit hex literal form (`0x[0-9a-f]{1,8}`). Same convention as `s_mov_b64 exec, -1`. The PR text says "A 32-bit SOP1 literal/inline zero-extends"; that holds for the literal, not for the inline negatives -1..-16. Reproduction on the PR head (decode the words, run the handler): `s_quadmask_b64 s[10:11], -1` -> `s10 = 0x000000ffu; s11 = 0u`, expected `0x0000ffffu`; `s_quadmask_b64 s[12:13], 0xffffffff` -> `0x000000ffu` is correct (literal, hi = 0). Suggested fix: in the immediate branch, if the token is a negative decimal, sign-extend to 64 bits (`bits = value & (2**64 - 1)`, fold `nibble_mask(lo) | nibble_mask(hi) << 8`); keep hex literals zero-extended. Add `-1` (and e.g. `-16`) to the test's immediate list next to the existing `0xffffffff` case; today the CPU reference in the test shares the same assumption, so it cannot catch this. A device readback of a one-instruction program with `-1` would also guard it. What else I checked (all fine) - Nibble folding for the register path: low word -> bits 0..7, high word -> bits 8..15, `D.hi = 0`, `SCC = D != 0`; even-aligned pairs only; lane masks and descriptor-bearing SGPRs refused. - Sibling forms: `s_quadmask_b32` already merged (#2642); no other open or merged PR lowers `s_quadmask_b64` in gfx2hlsl (#2076 was closed). - Linux (worktree at the PR head): `tests/startup_gfx2hlsl_s_quadmask_b64_check.py`, `..._handler_arity_check.py`, `..._scalar_table_arity_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py` pass; `git diff --check origin/main...HEAD` clean. - Registration: CMake, `windows.yml` (one list entry, `.github` care noted) and `AGENTS.md` updated. I did not run Win2025 on this head because of the finding above; happy to once it is fixed. Merge left to the maintainers. AI-assisted; commands listed were executed locally.
upstream-sync closed this pull request 2026-11-26 06:01:50 +00:00
R0Y00 commented 2026-11-26 06:01:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-26T05:11:34Z.

Review: APPROVED


The negative inline operands now follow the existing 64-bit integer convention. The encoded -1 and -16 cases give 0xffff and 0xfffe, while separate 32-bit literal controls leave the upper eight result bits clear. The SGPR pair, SCC, range and refusal checks pass, as do the existing s_ff0, BFM and scalar-arity checks. The merge keeps both test registrations and the previous negative control. This verifies the source-built scalar semantics; no GPU draw is claimed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6068863386 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2678#pullrequestreview-6068863386). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-26T05:11:34Z. **Review:** APPROVED --- The negative inline operands now follow the existing 64-bit integer convention. The encoded -1 and -16 cases give 0xffff and 0xfffe, while separate 32-bit literal controls leave the upper eight result bits clear. The SGPR pair, SCC, range and refusal checks pass, as do the existing s_ff0, BFM and scalar-arity checks. The merge keeps both test registrations and the previous negative control. This verifies the source-built scalar semantics; no GPU draw is claimed.
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!2670
No description provided.