startup: lower s_cmp_eq_u64 and s_cmp_lg_u64 in gfx2hlsl #2891

Manually merged
github merged 1 commit from github-bot/gh-2891 into gh-pr/2891/base 2026-11-27 04:46:00 +00:00 AGit
Owner

@⁠R0D4X on GitHub · 2026-11-26 16:42 UTC · original
R0D4X:feat/gfx2hlsl-s-cmp64 → main · +403 −0 · 4 files · 1 commits · merged 2026-11-27 04:45 UTC

What this changes

Adds lowering for the 64-bit scalar equality comparisons s_cmp_eq_u64 and s_cmp_lg_u64 in tools/startup/gfx2hlsl.py (previously refused as unlowered, though already decoded by tools/disasm_rdna2.py).

  • Lowering: Compares both 32-bit halves and writes SCC via Stage.set_scc:
    • s_cmp_eq_u64: ((a0 == b0) && (a1 == b1))
    • s_cmp_lg_u64: ((a0 != b0) || (a1 != b1))
  • Operands: Accepts even-aligned SGPR pairs (s[0:1]..s[104:105]), null (0, 0), sign-extended inline integers (-16..64), and zero-extended 32-bit hex literals.
  • Safety checks: Refuses bad operand counts, modifiers, lane masks (including masks / mask_high on either half of a pair), VGPRs, odd or out-of-range SGPR pairs, float inline constants, m0, and src_scc.

Tests added

  • tests/startup_gfx2hlsl_s_cmp64_check.py: SOPC binary decode via G.decode(), 242 pair comparisons, inline -1 sign-extension and 0x80000001 zero-extension checks, uniformity tracking, 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_cmp64.cmake and tests/checks/python-linux/startup_gfx2hlsl_s_cmp64.txt.

Verification

  • Commit: edda1e78 (on upstream/main b505c32b)
  • 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_cmp64|^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_cmp64' -> 3/3 passed, 0 skipped
  • Repo & neighbor checks (docs_links_check.py, bidi_controls_check.py, scalar/arity/null/refusal checks, git diff --check) -> all passed
  • 5 live mutations on gfx2hlsl.py (dropping high-word compare, wrong lg join, dropping VGPR/mask-high guards, sign-extending 32-bit literals) -> 5/5 caught (rc=1)

Scope: Covers synthetic gfx1013 SOPC 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-26 16:42 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2891) `R0D4X:feat/gfx2hlsl-s-cmp64` → `main` · +403 −0 · 4 files · 1 commits · merged 2026-11-27 04:45 UTC ## What this changes Adds lowering for the 64-bit scalar equality comparisons `s_cmp_eq_u64` and `s_cmp_lg_u64` in `tools/startup/gfx2hlsl.py` (previously refused as unlowered, though already decoded by `tools/disasm_rdna2.py`). - **Lowering:** Compares both 32-bit halves and writes `SCC` via `Stage.set_scc`: - `s_cmp_eq_u64`: `((a0 == b0) && (a1 == b1))` - `s_cmp_lg_u64`: `((a0 != b0) || (a1 != b1))` - **Operands:** Accepts even-aligned SGPR pairs (`s[0:1]`..`s[104:105]`), `null` (`0, 0`), sign-extended inline integers (`-16..64`), and zero-extended 32-bit hex literals. - **Safety checks:** Refuses bad operand counts, modifiers, lane masks (including `masks` / `mask_high` on either half of a pair), VGPRs, odd or out-of-range SGPR pairs, float inline constants, `m0`, and `src_scc`. ## Tests added - `tests/startup_gfx2hlsl_s_cmp64_check.py`: SOPC binary decode via `G.decode()`, 242 pair comparisons, inline `-1` sign-extension and `0x80000001` zero-extension checks, uniformity tracking, 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_cmp64.cmake` and `tests/checks/python-linux/startup_gfx2hlsl_s_cmp64.txt`. ## Verification - **Commit:** `edda1e78` (on `upstream/main` `b505c32b`) - **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_cmp64|^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_cmp64'` -> **3/3 passed, 0 skipped** - Repo & neighbor checks (`docs_links_check.py`, `bidi_controls_check.py`, scalar/arity/null/refusal checks, `git diff --check`) -> **all passed** - 5 live mutations on `gfx2hlsl.py` (dropping high-word compare, wrong `lg` join, dropping VGPR/mask-high guards, sign-extending 32-bit literals) -> **5/5 caught (`rc=1`)** *Scope:* Covers synthetic gfx1013 SOPC 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 01:28:03 +00:00
Author
Owner

@⁠Leyukaka on GitHub · 2026-11-26 21:39 UTC · original

Review of head edda1e78, from reading the diff against main 6ee878d8 (not run).

The lowering reads as correct:

  • both 32-bit halves are compared;
  • inline -1 is sign-extended and 32-bit hex literals are zero-extended for the u64 compares;
  • SCC is marked verified and its uniformity follows the four source words;
  • lane masks and descriptor words are refused.

Steps 2 and 3 of the check would catch a low-word-only compare and a zero-extended -1.

Two test gaps:

  1. Step 10 does not exercise the translator. Its five checks are built only from ref_cmp64 and Python literals, and none calls G, Probe, run_one or eval_scc_expr, so they pass with any handler. Patching the handler, as step 9 does by deleting it, and asserting that the grid fails would make it a mutation control.
  2. The draw only compares constants. ps_words() loads s4..s7 with s_mov_b32 of literals, which Stage.scalar tracks as ('const', value). S() then emits them as literals, so every draw case compiles to a compare of constants, such as scc = ((0x12345678u == 0x12345678u) && (0x9abcdef0u == 0x9abcdef0u));, and the compare never reads s4..s7. The draw still checks the expression's shape through the compiler's folding, but not run-time SGPR reads. One case with a non-constant s[4:5]/s[6:7] would cover that path. The fixture's root signature has no parameters, so it needs a run-time source added.

AI-assisted.

**@⁠Leyukaka** on GitHub · 2026-11-26 21:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2891#issuecomment-7203934121) Review of head `edda1e78`, from reading the diff against main `6ee878d8` (not run). The lowering reads as correct: - both 32-bit halves are compared; - inline `-1` is sign-extended and 32-bit hex literals are zero-extended for the u64 compares; - SCC is marked verified and its uniformity follows the four source words; - lane masks and descriptor words are refused. Steps 2 and 3 of the check would catch a low-word-only compare and a zero-extended `-1`. Two test gaps: 1. **Step 10 does not exercise the translator.** Its five checks are built only from `ref_cmp64` and Python literals, and none calls `G`, `Probe`, `run_one` or `eval_scc_expr`, so they pass with any handler. Patching the handler, as step 9 does by deleting it, and asserting that the grid fails would make it a mutation control. 2. **The draw only compares constants.** `ps_words()` loads `s4`..`s7` with `s_mov_b32` of literals, which `Stage.scalar` tracks as `('const', value)`. `S()` then emits them as literals, so every draw case compiles to a compare of constants, such as `scc = ((0x12345678u == 0x12345678u) && (0x9abcdef0u == 0x9abcdef0u));`, and the compare never reads `s4`..`s7`. The draw still checks the expression's shape through the compiler's folding, but not run-time SGPR reads. One case with a non-constant `s[4:5]`/`s[6:7]` would cover that path. The fixture's root signature has no parameters, so it needs a run-time source added. AI-assisted.
Author
Owner

@⁠thepatrickworld on GitHub · 2026-11-26 22:21 UTC · original

Independent AMD RDNA 4 result on edda1e78: the three entries pass, and the compared values are folded before the module reaches the driver. Not a code change; measurements only.

Environment

Windows 11 10.0.26200.9974, MSVC 19.44.35230 (toolset 14.44.35207), Windows SDK 10.0.26100.0 — DXC 1.9.2602.17 and FXC taken from .../Windows Kits/10/bin/10.0.26100.0/x64/. dev preset, debug_layer=unavailable (not installed on this host). Adapter AMD Radeon RX 9070 XT (1002:7550), driver 32.0.32029.2010. Worktree at edda1e78c71f1c9b7c7296d579b3c3c50fbb516a, git status --porcelain --untracked-files=no empty.

Commands

cmake --preset dev "-DINTAKE_PYTHON=C:/Users/walde/Downloads/x2w-pr641/out/pe-env/Scripts/python.exe"
cmake --build --preset dev --target offscreen_check
set "XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT"
ctest --preset dev --no-tests=error -R "^startup_gfx2hlsl_s_cmp64" -V

Observed

3/3 passed, 0 skipped, 10.41 s (controls 0.51, warp 4.42, hardware 5.41); ctest -N reports 2445 tests and registers the three new entries. On the card: 16 renderer invocations (the 7 GPU_VECTORS × {FXC ps_5_1, DXC ps_6_0} plus one negative-control draw per compiler), 16 startup_flat_param words= readbacks (one per invocation, the negative controls included), both negative controls rejected, and every invocation printed backend=hardware debug_layer=unavailable / adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550 / driver=32.0.32029.2010.

Mutation matrix

Four mutants in tools/startup/gfx2hlsl.py (the new block, lines 10034-10056), each restored with git checkout -- <file>:

  • low word only (both ops) → MISMATCH s_cmp_eq_u64 a=(0x0,0x0) b=(0x0,0x1) got=True want=False
  • lg joined with && instead of || → MISMATCH s_cmp_lg_u64 a=(0x0,0x0) b=(0x1,0x0) got=False want=True
  • halves of the second operand swapped → MISMATCH s_cmp_eq_u64 a=(0x1,0x0) b=(0x1,0x0) got=False want=True
  • 32-bit hex literal sign-extended instead of zero-extended → 32-bit hex literal zero-extends to 64 bits: MISMATCH

The first three die in the 242-case pair grid (step 2), the fourth in the hex-literal check (step 4). Step 10 never ran under any of them — the control run stops at its first failure — and by construction it could not see them: its five checks compare ref_cmp64 with Python expressions and never call the handler (tests/startup_gfx2hlsl_s_cmp64_check.py:293-305). The hardware entry also fails for each mutant (ctest rc=8) but in 0.29-0.31 s instead of 5.41 s, because run_draw() calls run_controls() first (line 321): no mutant reaches a compile, let alone a draw. After each restoration the sha256 matched the original, git status was empty and the controls exited 0. Three of these re-run mutations the description names (high-word drop, lg join, sign-extended literal); swapping the halves of the second operand is not among them. Reading: the Python checks are the pin here, and the draw adds no mutation coverage — the file working as intended, not a hole.

What the emitted shader contains

The fixture's PS for diff_hi_only already carries the comparison its own constants resolve:

scc = ((0x12345678u == 0x12345678u) && (0x9abcdef0u == 0x9abcdef1u));

Dumping the DXIL of all seven vectors (compiled through the fixture's own compile_hlsl, so the flags are identical) gives a 6-line main with four dx.op.storeOutput.f32 calls on immediate arguments, and no icmp, and, or or select. At -Od that vector still has none (79-line main, the same four immediates). There is therefore no run-time 64-bit operand in the module: for the DXC ps_6_0 pair, WARP and the card compile the same text and receive the same module, so what passes covers translation, export and readback on both adapters, not a run-time compare. The FXC ps_5_1 DXBC was not dumped. This is the measurement behind @⁠Leyukaka's second point, taken on the AMD host.

CI

tests/checks/python-linux/startup_gfx2hlsl_s_cmp64.txt is picked up by the python-linux job (--from-dir tests/checks/python-linux, .github/workflows/windows.yml:199), which runs on every pull request and push, so the controls are covered. s_cmp64 is not in the pr test preset's include regex (CMakePresets.json:45), so neither draw runs on a pull_request; after merge the push sweep (ctest --preset dev ... -E '_hardware$') runs _warp and excludes only _hardware.

Where a run-time source already exists

tests/startup_gfx2hlsl_bfm_b64_check.py passes four entry words as the sixth --startup-flat-param argument (asserted for pipe.uds[:3]), and its PS reads them from the cbuffer entry : register(b0) { uint ud0; ... } that gfx2hlsl.py emits (uint bw = ud1 & 63u, shl64(..., ud2)). A s_cmp64 vector in that form would make the operands run-time reads; whether the comparison then survives to an icmp is untested here.

Limits

One machine, one adapter, no debug layer, -Od dumped for one vector only, FXC output not dumped. Nothing here speaks to title startup or frame rate.

AI-assisted.

**@⁠thepatrickworld** on GitHub · 2026-11-26 22:21 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2891#issuecomment-7204595872) **Independent AMD RDNA 4 result on `edda1e78`: the three entries pass, and the compared values are folded before the module reaches the driver.** Not a code change; measurements only. ### Environment Windows 11 `10.0.26200.9974`, MSVC `19.44.35230` (toolset `14.44.35207`), Windows SDK `10.0.26100.0` — DXC `1.9.2602.17` and FXC taken from `.../Windows Kits/10/bin/10.0.26100.0/x64/`. `dev` preset, `debug_layer=unavailable` (not installed on this host). Adapter `AMD Radeon RX 9070 XT` (`1002:7550`), driver `32.0.32029.2010`. Worktree at `edda1e78c71f1c9b7c7296d579b3c3c50fbb516a`, `git status --porcelain --untracked-files=no` empty. ### Commands ``` cmake --preset dev "-DINTAKE_PYTHON=C:/Users/walde/Downloads/x2w-pr641/out/pe-env/Scripts/python.exe" cmake --build --preset dev --target offscreen_check set "XBOX2WINDOWS_ADAPTER=AMD Radeon RX 9070 XT" ctest --preset dev --no-tests=error -R "^startup_gfx2hlsl_s_cmp64" -V ``` ### Observed 3/3 passed, 0 skipped, 10.41 s (`controls` 0.51, `warp` 4.42, `hardware` 5.41); `ctest -N` reports 2445 tests and registers the three new entries. On the card: 16 renderer invocations (the 7 `GPU_VECTORS` × {FXC `ps_5_1`, DXC `ps_6_0`} plus one negative-control draw per compiler), 16 `startup_flat_param words=` readbacks (one per invocation, the negative controls included), both negative controls rejected, and every invocation printed `backend=hardware debug_layer=unavailable` / `adapter=AMD Radeon RX 9070 XT vendor=1002 device=7550` / `driver=32.0.32029.2010`. ### Mutation matrix Four mutants in `tools/startup/gfx2hlsl.py` (the new block, lines 10034-10056), each restored with `git checkout -- <file>`: - low word only (both ops) → `MISMATCH s_cmp_eq_u64 a=(0x0,0x0) b=(0x0,0x1) got=True want=False` - `lg` joined with `&&` instead of `||` → `MISMATCH s_cmp_lg_u64 a=(0x0,0x0) b=(0x1,0x0) got=False want=True` - halves of the second operand swapped → `MISMATCH s_cmp_eq_u64 a=(0x1,0x0) b=(0x1,0x0) got=False want=True` - 32-bit hex literal sign-extended instead of zero-extended → `32-bit hex literal zero-extends to 64 bits: MISMATCH` The first three die in the 242-case pair grid (step 2), the fourth in the hex-literal check (step 4). Step 10 never ran under any of them — the control run stops at its first failure — and by construction it could not see them: its five checks compare `ref_cmp64` with Python expressions and never call the handler (`tests/startup_gfx2hlsl_s_cmp64_check.py:293-305`). The hardware entry also fails for each mutant (ctest `rc=8`) but in 0.29-0.31 s instead of 5.41 s, because `run_draw()` calls `run_controls()` first (line 321): no mutant reaches a compile, let alone a draw. After each restoration the sha256 matched the original, `git status` was empty and the controls exited 0. Three of these re-run mutations the description names (high-word drop, `lg` join, sign-extended literal); swapping the halves of the second operand is not among them. Reading: the Python checks are the pin here, and the draw adds no mutation coverage — the file working as intended, not a hole. ### What the emitted shader contains The fixture's PS for `diff_hi_only` already carries the comparison its own constants resolve: ``` scc = ((0x12345678u == 0x12345678u) && (0x9abcdef0u == 0x9abcdef1u)); ``` Dumping the DXIL of all seven vectors (compiled through the fixture's own `compile_hlsl`, so the flags are identical) gives a 6-line `main` with four `dx.op.storeOutput.f32` calls on immediate arguments, and no `icmp`, `and`, `or` or `select`. At `-Od` that vector still has none (79-line `main`, the same four immediates). There is therefore no run-time 64-bit operand in the module: for the DXC `ps_6_0` pair, WARP and the card compile the same text and receive the same module, so what passes covers translation, export and readback on both adapters, not a run-time compare. The FXC `ps_5_1` DXBC was not dumped. This is the measurement behind @⁠Leyukaka's second point, taken on the AMD host. ### CI `tests/checks/python-linux/startup_gfx2hlsl_s_cmp64.txt` is picked up by the `python-linux` job (`--from-dir tests/checks/python-linux`, `.github/workflows/windows.yml:199`), which runs on every pull request and push, so the controls are covered. `s_cmp64` is not in the `pr` test preset's include regex (`CMakePresets.json:45`), so neither draw runs on a `pull_request`; after merge the push sweep (`ctest --preset dev ... -E '_hardware$'`) runs `_warp` and excludes only `_hardware`. ### Where a run-time source already exists `tests/startup_gfx2hlsl_bfm_b64_check.py` passes four entry words as the sixth `--startup-flat-param` argument (asserted for `pipe.uds[:3]`), and its PS reads them from the `cbuffer entry : register(b0) { uint ud0; ... }` that `gfx2hlsl.py` emits (`uint bw = ud1 & 63u`, `shl64(..., ud2)`). A `s_cmp64` vector in that form would make the operands run-time reads; whether the comparison then survives to an `icmp` is untested here. ### Limits One machine, one adapter, no debug layer, `-Od` dumped for one vector only, FXC output not dumped. Nothing here speaks to title startup or frame rate. _AI-assisted._
github-bot changed target branch from main to gh-pr/2891/base 2026-11-27 04:45:59 +00:00
github manually merged commit edda1e78c7 into gh-pr/2891/base 2026-11-27 04:46:00 +00:00
Author
Owner

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

Reviewed edda1e78c71f1c9b7c7296d579b3c3c50fbb516a. The lowering compares both words and retains the lane-mask refusals. This fixture's operands can constant-fold in DXC, so the readbacks cover end-to-end translation and export; they are not runtime-variable compare coverage. I built the clean integration tree with current main 50488e1c in Release on Windows 11 26200.9974, then ran ctest --preset release --no-tests=error --output-on-failure -R '^startup_gfx2hlsl_s_cmp64_'. Its portable, WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656) tests all passed. D3D12 debug-layer output showed zero errors or warnings. Required Windows CI passed.

**@⁠R0Y00** on GitHub · 2026-11-27 04:44 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/2891#pullrequestreview-6083586609) · **approved these changes** Reviewed `edda1e78c71f1c9b7c7296d579b3c3c50fbb516a`. The lowering compares both words and retains the lane-mask refusals. This fixture's operands can constant-fold in DXC, so the readbacks cover end-to-end translation and export; they are not runtime-variable compare coverage. I built the clean integration tree with current main `50488e1c` in Release on Windows 11 26200.9974, then ran `ctest --preset release --no-tests=error --output-on-failure -R '^startup_gfx2hlsl_s_cmp64_'`. Its portable, WARP (10.0.26100.9818) and RTX 4060 Laptop (32.0.16.1656) tests all passed. D3D12 debug-layer output showed zero errors or warnings. Required Windows CI passed.
This discussion has been locked. Commenting is limited to contributors.
No description provided.