startup: lower s_brev_b64 in gfx2hlsl #3029

Manually merged
github merged 1 commit from github-bot/gh-3029 into gh-pr/3029/base 2026-11-27 12:30:52 +00:00 AGit
Owner

@⁠R0D4X on GitHub · 2026-11-27 08:45 UTC · original
R0D4X:feat/gfx2hlsl-s-brev64 → main · +414 −0 · 4 files · 1 commits · merged 2026-11-27 12:27 UTC

What this changes

Adds lowering for the 64-bit scalar bit-reverse SOP1 instruction s_brev_b64 in tools/startup/gfx2hlsl.py (already decoded by tools/disasm_rdna2.py, alongside the existing 32-bit s_brev_b32).

  • Semantics: Reverses all 64 bits of S0 into SGPR pair s[D:D+1] (D.lo = reversebits(S0.hi), D.hi = reversebits(S0.lo)), leaving SCC unchanged.
  • Constant folding & in-place aliasing: Folds known constants (null, sign-extended inline integers -16..64, zero-extended 32-bit hex literals, and constant-tracked SGPRs). When D == S0 (s_brev_b64 s[4:5], s[4:5]), emits a scoped temporary so both halves are read before being overwritten, and swaps their tracked uniformity accordingly.
  • Safety checks: Refuses bad operand counts, modifiers, lane masks (including masks / mask_high on either half of D or S0), descriptor-bearing SGPRs, VGPR pairs, single/odd/out-of-range SGPRs, floats, m0, and src_scc.

Tests added

  • tests/startup_gfx2hlsl_s_brev64_check.py: SOP1 binary decode via G.decode(), disjoint and in-place aliasing checks, inline -1 sign-extension and 0x80000001 zero-extension, constant folding, uniformity swap checks, refusal cases, unlowered control, and FXC ps_5_1 + DXC ps_6_0 GPU readback draws (including a negative-control draw).
  • Registered via tests/cmake/startup_gfx2hlsl_s_brev64.cmake and tests/checks/python-linux/startup_gfx2hlsl_s_brev64.txt.

Verification

  • Commit: f8b78b2c (on upstream/main 3b6c38a8)
  • Host: Windows 11 x64 (10.0.26300.9974), MSVC 19.44.35230, Windows SDK 10.0.26100.0, FXC + DXC 1.9.2602.17, D3D12 debug layer enabled
  • Adapters: WARP (1414:008c, driver 10.0.26100.9818) and NVIDIA GeForce RTX 5080 (10de:2c02, driver 32.0.16.2124)

Results:

  • ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_brev64|^startup_tools_lint$' -V -> 4/4 passed, 0 skipped (debug_errors=0 debug_warnings=0 on all draws)
  • ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_s_brev64' -> 3/3 passed, 0 skipped
  • Repo & neighbor checks (docs_links_check.py, bidi_controls_check.py, startup_gfx2hlsl_scalar_brev_fold_check.py, scalar/arity/null/refusal checks, git diff --check) -> all passed
  • 5 live mutations on gfx2hlsl.py (breaking in-place aliasing, skipping half swap, sign-extending 32-bit literals, dropping mask_high guard, wrong in-place uniformity swap) -> 5/5 caught (rc=1)

Scope: Covers synthetic gfx1013 SOP1 fixtures translated by gfx2hlsl.py and run on WARP and RTX 5080; does not establish full-title startup or frame rate.

**@⁠R0D4X** on GitHub · 2026-11-27 08:45 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3029) `R0D4X:feat/gfx2hlsl-s-brev64` → `main` · +414 −0 · 4 files · 1 commits · merged 2026-11-27 12:27 UTC ## What this changes Adds lowering for the 64-bit scalar bit-reverse SOP1 instruction `s_brev_b64` in `tools/startup/gfx2hlsl.py` (already decoded by `tools/disasm_rdna2.py`, alongside the existing 32-bit `s_brev_b32`). - **Semantics:** Reverses all 64 bits of `S0` into SGPR pair `s[D:D+1]` (`D.lo = reversebits(S0.hi)`, `D.hi = reversebits(S0.lo)`), leaving `SCC` unchanged. - **Constant folding & in-place aliasing:** Folds known constants (`null`, sign-extended inline integers `-16..64`, zero-extended 32-bit hex literals, and constant-tracked SGPRs). When `D == S0` (`s_brev_b64 s[4:5], s[4:5]`), emits a scoped temporary so both halves are read before being overwritten, and swaps their tracked uniformity accordingly. - **Safety checks:** Refuses bad operand counts, modifiers, lane masks (including `masks` / `mask_high` on either half of `D` or `S0`), descriptor-bearing SGPRs, VGPR pairs, single/odd/out-of-range SGPRs, floats, `m0`, and `src_scc`. ## Tests added - `tests/startup_gfx2hlsl_s_brev64_check.py`: SOP1 binary decode via `G.decode()`, disjoint and in-place aliasing checks, inline `-1` sign-extension and `0x80000001` zero-extension, constant folding, uniformity swap checks, refusal cases, unlowered control, and FXC `ps_5_1` + DXC `ps_6_0` GPU readback draws (including a negative-control draw). - Registered via `tests/cmake/startup_gfx2hlsl_s_brev64.cmake` and `tests/checks/python-linux/startup_gfx2hlsl_s_brev64.txt`. ## Verification - **Commit:** `f8b78b2c` (on `upstream/main` `3b6c38a8`) - **Host:** Windows 11 x64 (`10.0.26300.9974`), MSVC `19.44.35230`, Windows SDK `10.0.26100.0`, FXC + DXC `1.9.2602.17`, D3D12 debug layer enabled - **Adapters:** WARP (`1414:008c`, driver `10.0.26100.9818`) and NVIDIA GeForce RTX 5080 (`10de:2c02`, driver `32.0.16.2124`) Results: - `ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_s_brev64|^startup_tools_lint$' -V` -> **4/4 passed, 0 skipped** (`debug_errors=0 debug_warnings=0` on all draws) - `ctest --preset release --no-tests=error -R '^startup_gfx2hlsl_s_brev64'` -> **3/3 passed, 0 skipped** - Repo & neighbor checks (`docs_links_check.py`, `bidi_controls_check.py`, `startup_gfx2hlsl_scalar_brev_fold_check.py`, scalar/arity/null/refusal checks, `git diff --check`) -> **all passed** - 5 live mutations on `gfx2hlsl.py` (breaking in-place aliasing, skipping half swap, sign-extending 32-bit literals, dropping `mask_high` guard, wrong in-place uniformity swap) -> **5/5 caught (`rc=1`)** *Scope:* Covers synthetic gfx1013 SOP1 fixtures translated by `gfx2hlsl.py` and run on WARP and RTX 5080; does not establish full-title startup or frame rate.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 08:49:17 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-27 10:06 UTC · original · reviewed

Review of head f8b78b2c (comment only).

Read the diff of tools/startup/gfx2hlsl.py (73 lines): op_s_brev_b64 swaps and bit-reverses the two halves (D.lo = reverse(S0.hi), D.hi = reverse(S0.lo)), folds constants, uses a scoped temporary when D == S0, and refuses lane masks and non-integer symbolic sources. Immediate sources go through the existing i64_words (decimal strings, so the int(lo[:-1]) fold is safe).

The PR's check has the real thing a lowering needs: startup_gfx2hlsl_s_brev64_warp / _hardware draw the translated shader and compare the readback with a CPU reference, plus a _controls test.

Ran locally (Linux): python3 -B tests/startup_gfx2hlsl_s_brev64_check.py (controls): ok.

  • Mutation A: the in-place (D == S0) path reverses hi for both words: the controls fail ("in-place SGPR pair aliasing (8 cases)").
  • Mutation B: the disjoint path writes reversebits(hi) into the high word: the controls fail ("disjoint SGPR pair (8 cases)").

No defect found. It only lacks a Windows receipt on this head: ctest -R "startup_gfx2hlsl_s_brev64" (dev + release).

AI-assisted; commands listed were executed locally.

**@⁠tedin7** on GitHub · 2026-11-27 10:06 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3029#pullrequestreview-6086487095) · **reviewed** Review of head f8b78b2c (comment only). Read the diff of `tools/startup/gfx2hlsl.py` (73 lines): `op_s_brev_b64` swaps and bit-reverses the two halves (D.lo = reverse(S0.hi), D.hi = reverse(S0.lo)), folds constants, uses a scoped temporary when D == S0, and refuses lane masks and non-integer symbolic sources. Immediate sources go through the existing `i64_words` (decimal strings, so the `int(lo[:-1])` fold is safe). The PR's check has the real thing a lowering needs: `startup_gfx2hlsl_s_brev64_warp` / `_hardware` draw the translated shader and compare the readback with a CPU reference, plus a `_controls` test. Ran locally (Linux): `python3 -B tests/startup_gfx2hlsl_s_brev64_check.py` (controls): ok. - Mutation A: the in-place (D == S0) path reverses `hi` for both words: the controls fail ("in-place SGPR pair aliasing (8 cases)"). - Mutation B: the disjoint path writes `reversebits(hi)` into the high word: the controls fail ("disjoint SGPR pair (8 cases)"). No defect found. It only lacks a Windows receipt on this head: `ctest -R "startup_gfx2hlsl_s_brev64"` (dev + release). AI-assisted; commands listed were executed locally.
github-bot changed target branch from main to gh-pr/3029/base 2026-11-27 12:30:50 +00:00
github manually merged commit f8b78b2c45 into gh-pr/3029/base 2026-11-27 12:30:52 +00:00
Author
Owner

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

Reviewed f8b78b2c with main 1ec2c938 (integration tree 68aed76a). The two reversed halves, in-place temporary, constant folding and per-half tracking agree with the existing scalar write rules. python -B tests/startup_gfx2hlsl_s_brev64_check.py passed, and its draw <dxc> <offscreen_check> <warp|hardware> <fxc> invocation passed on both adapters with both Debug and Release /O2 renderers. The reused renderer was built from the unchanged renderer source on this base. The source-built wrong-output and invalid-operand controls passed. Windows 11 26200.9974, SDK 10.0.26100, WARP 10.0.26100.9818, RTX 4060 Laptop driver 32.0.16.1656, D3D12 debug layer enabled. Hosted Windows, Linux Python and gfx1013 passed.

**@⁠R0Y00** on GitHub · 2026-11-27 12:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3029#pullrequestreview-6088121406) · **approved these changes** Reviewed `f8b78b2c` with `main` `1ec2c938` (integration tree `68aed76a`). The two reversed halves, in-place temporary, constant folding and per-half tracking agree with the existing scalar write rules. `python -B tests/startup_gfx2hlsl_s_brev64_check.py` passed, and its `draw <dxc> <offscreen_check> <warp|hardware> <fxc>` invocation passed on both adapters with both Debug and Release /O2 renderers. The reused renderer was built from the unchanged renderer source on this base. The source-built wrong-output and invalid-operand controls passed. Windows 11 26200.9974, SDK 10.0.26100, WARP 10.0.26100.9818, RTX 4060 Laptop driver 32.0.16.1656, D3D12 debug layer enabled. Hosted Windows, Linux Python and gfx1013 passed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.