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

Manually merged
github merged 3 commits from gh-pr/2678/head into gh-pr/2678/base 2026-11-27 01:14:03 +00:00
Owner

@⁠SimSalabimse on GitHub · 2026-11-26 01:46 UTC · original
SimSalabimse:cursor/gfx2hlsl-s-quadmask-b64-f686 → main · +247 −1 · 6 files · 3 commits · merged 2026-11-26 05:11 UTC

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.
**@⁠SimSalabimse** on GitHub · 2026-11-26 01:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2678) `SimSalabimse:cursor/gfx2hlsl-s-quadmask-b64-f686` → `main` · +247 −1 · 6 files · 3 commits · merged 2026-11-26 05:11 UTC ## Change Part of [#1723](https://git.gtahub.st/github/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://git.gtahub.st/github/R0Y00--Xbox2Windows/pulls/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.
Port the pixel_aot 64-bit nibble collapse (sixteen bits in D.lo, D.hi = 0).
SCC follows the full result. Lane masks, descriptors, and odd pairs refused.

Co-authored-by: SimSalabimse <[email protected]>
#2405 added s_mul_hi_i32 (and an early arity refuse for both mul_hi forms).
The negative control still expected only one non-IndexError survivor.

Co-authored-by: SimSalabimse <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 01:14:00 +00:00
github manually merged commit 9b7a93da82 into gh-pr/2678/base 2026-11-27 01:14:03 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-26 02:57 UTC · original · reviewed

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.

**@⁠tedin7** on GitHub · 2026-11-26 02:57 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2678#pullrequestreview-6067948301) · **reviewed** 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.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-26 05:11 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-11-26 05:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2678#pullrequestreview-6068863386) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.