shader: lower compute v_writelane_b32 on known words #1897

Merged
henriazz10 merged 1 commit from upstream-pr/1904 into main 2026-11-24 20:50:09 +00:00
henriazz10 commented 2026-11-24 20:43:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by henriazz10 on 2026-11-24T20:43:57Z.


Change

Refs #1543. This is the v_writelane_b32 vD, sS, lane slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/1543#issuecomment-7142817082. It builds on the v_mbcnt slice (#1782) and touches only tools/compute_store_aot.py, its test, CMakeLists.txt and docs/experiments.md.

  • Outside a guarded region, v_writelane_b32 vD, sS, lane writes the known scalar word sS into lane lane of vD (ignoring exec), leaving other lanes at old_vD:
    • Under wave_size=32, lane is masked to 5 bits: ((gindex & 31u) == (lane & 31u)) ? sS : old_vD, where gindex is SV_GroupIndex.
    • In a group of at most 32 threads without wave_size=32, lane must be a known constant in 0..31 (since wave64 selects lane[5:0]), and lowers as that constant. Larger groups require wave_size=32.
    • Review found the wave64 lane-select defect (lane[5:0]), and it was fixed before publishing.
  • Refused, each with its own control:
    • an unknown or pending scalar source (s30, s12);
    • an unknown or pending lane (s30, s12), or a lane not known to be in 0..31 without wave_size=32 (35 literal, 35 in an SGPR, or a loaded constant word);
    • an unknown old vD (v40);
    • the instruction inside a guarded region (s_and_saveexec_b32 up to the exec restore);
    • a group larger than 32 without wave_size=32;
    • vD above v255 (v256).

Verification

Commit d2b55bd8, rebased onto 8c82879f. Windows 11 build 26300, VS 2019 Build Tools 16.11 (MSVC 14.29), DXC 1.8.2502.11, Python 3.12, debug layer enabled. offscreen_check was built from an earlier main; this PR does not change it.

python -B tests/compute_store_check.py draw-writelane <dxc> <offscreen_check> warp
python -B tests/compute_store_check.py draw-writelane <dxc> <offscreen_check> hardware
python -B tests/docs_links_check.py
python -B tests/bidi_controls_check.py
Backend Adapter / driver Result
WARP Microsoft Basic Render Driver 10.0.26100.9818 exit 0, compared_words=320 mismatches=0, debug_errors=0
hardware NVIDIA GeForce RTX 5080, 32.0.16.1692 exit 0, compared_words=320 mismatches=0, debug_errors=0

The LLVM 15 round trip in Docker (x2w-llvm15) exited 0:

docker run --rm -v "C:\Proyectos\Xbox2Windows\wt-writelane:/src" x2w-llvm15 bash -c 'cp -r /src /w && cd /w && python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1; echo binary_exit=$?'

writelane_binary() decodes the assembled fixture back to the same v_writelane_b32 lines and requires the same translation.

Negative control. With tools/compute_store_aot.py reverted to main, writelane_controls() fails with ValueError: Unsupported compute instruction: v_writelane_b32 v4, s4, 3.

Evidence

The fixture is source-built in LLVM 15 spelling. It runs one group of 64 threads (two wave32 waves) with wave_size=32. Each thread starts with v4 = tid.x + 1, then two v_writelane_b32 instructions write 0x11223344 into lane 3 (SGPR s4 and inline constant 3) and 0x55667788 into lane 31 (literal 0x55667788 and SGPR s5). Both waves receive the writes, and all 320 words are compared against a Python reference.

  • Translation controls. They check the exact HLSL line for 64 threads with wave_size=32 (including lane 35 masked to 3), 32 threads without wave_size=32 (with lane 3), and all rejection conditions (including lane 35 literal/SGPR and a loaded constant-word lane without wave_size=32).
  • Reference controls. Each must fail at its first differing word:
    • gindex without & 31: word 35;
    • lane off by one: word 3;
    • scalar not written: word 3;
    • changed sentinel past the group: word 64.
  • Recompiled-HLSL controls. Each must fail on the device:
    • lane compared without & 31;
    • != for ==;
    • old value replaced by 0.

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 (docs/experiments.md).
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6591036685 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1904). Originally posted by [henriazz10](https://github.com/henriazz10) on 2026-11-24T20:43:57Z. --- ## Change Refs #1543. This is the `v_writelane_b32 vD, sS, lane` slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/1543#issuecomment-7142817082. It builds on the `v_mbcnt` slice (#1782) and touches only `tools/compute_store_aot.py`, its test, `CMakeLists.txt` and `docs/experiments.md`. - Outside a guarded region, `v_writelane_b32 vD, sS, lane` writes the known scalar word `sS` into lane `lane` of `vD` (ignoring `exec`), leaving other lanes at `old_vD`: - Under `wave_size=32`, `lane` is masked to 5 bits: `((gindex & 31u) == (lane & 31u)) ? sS : old_vD`, where `gindex` is `SV_GroupIndex`. - In a group of at most 32 threads without `wave_size=32`, `lane` must be a known constant in `0..31` (since wave64 selects `lane[5:0]`), and lowers as that constant. Larger groups require `wave_size=32`. - Review found the wave64 lane-select defect (`lane[5:0]`), and it was fixed before publishing. - Refused, each with its own control: - an unknown or pending scalar source (`s30`, `s12`); - an unknown or pending lane (`s30`, `s12`), or a lane not known to be in `0..31` without `wave_size=32` (`35` literal, `35` in an SGPR, or a loaded constant word); - an unknown old `vD` (`v40`); - the instruction inside a guarded region (`s_and_saveexec_b32` up to the `exec` restore); - a group larger than 32 without `wave_size=32`; - `vD` above `v255` (`v256`). ## Verification Commit `d2b55bd8`, rebased onto `8c82879f`. Windows 11 build 26300, VS 2019 Build Tools 16.11 (MSVC 14.29), DXC 1.8.2502.11, Python 3.12, debug layer enabled. `offscreen_check` was built from an earlier `main`; this PR does not change it. ```powershell python -B tests/compute_store_check.py draw-writelane <dxc> <offscreen_check> warp python -B tests/compute_store_check.py draw-writelane <dxc> <offscreen_check> hardware python -B tests/docs_links_check.py python -B tests/bidi_controls_check.py ``` | Backend | Adapter / driver | Result | |---|---|---| | WARP | Microsoft Basic Render Driver 10.0.26100.9818 | exit 0, `compared_words=320 mismatches=0`, `debug_errors=0` | | hardware | NVIDIA GeForce RTX 5080, 32.0.16.1692 | exit 0, `compared_words=320 mismatches=0`, `debug_errors=0` | The LLVM 15 round trip in Docker (`x2w-llvm15`) exited 0: ```sh docker run --rm -v "C:\Proyectos\Xbox2Windows\wt-writelane:/src" x2w-llvm15 bash -c 'cp -r /src /w && cd /w && python3 -B tests/compute_store_check.py binary llvm-mc-15 llvm-objcopy-15 /usr/lib/x86_64-linux-gnu/libLLVM-15.so.1; echo binary_exit=$?' ``` `writelane_binary()` decodes the assembled fixture back to the same `v_writelane_b32` lines and requires the same translation. **Negative control.** With `tools/compute_store_aot.py` reverted to `main`, `writelane_controls()` fails with `ValueError: Unsupported compute instruction: v_writelane_b32 v4, s4, 3`. ## Evidence The fixture is source-built in LLVM 15 spelling. It runs one group of 64 threads (two wave32 waves) with `wave_size=32`. Each thread starts with `v4 = tid.x + 1`, then two `v_writelane_b32` instructions write `0x11223344` into lane 3 (SGPR `s4` and inline constant `3`) and `0x55667788` into lane 31 (literal `0x55667788` and SGPR `s5`). Both waves receive the writes, and all 320 words are compared against a Python reference. - **Translation controls.** They check the exact HLSL line for 64 threads with `wave_size=32` (including lane `35` masked to `3`), 32 threads without `wave_size=32` (with lane `3`), and all rejection conditions (including lane `35` literal/SGPR and a loaded constant-word lane without `wave_size=32`). - **Reference controls.** Each must fail at its first differing word: - `gindex` without `& 31`: word 35; - lane off by one: word 3; - scalar not written: word 3; - changed sentinel past the group: word 64. - **Recompiled-HLSL controls.** Each must fail on the device: - lane compared without `& 31`; - `!=` for `==`; - old value replaced by `0`. ## 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 (`docs/experiments.md`). - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 21:01:15 +00:00
tedin7 commented 2026-11-24 21:01:15 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:49:32Z.

Review: COMMENTED


Review of #1904 at head d2b55bd862 (tier TIER_D_ISOLATED_SHADER_OPS). No P1/P2 findings.

Commands run locally:

  • git diff --check origin/main...HEAD: rc=0
  • python3 tests/docs_links_check.py: rc=0 (18 files, 376 links)
  • python3 tests/bidi_controls_check.py: rc=0 (1330 files)
  • python3 -B tests/compute_store_check.py (controls run before mode dispatch): the new writelane_controls() pass; the run ends at the expected KeyError for an unknown mode
  • win2025 1904 --wait 900: Debug (preset dev) 66/66 passed, Release /O2 (preset release) 66/66 passed, 0 compile failures; compute_store_aot_writelane_warp passed in both

Mutations on tools/compute_store_aot.py (each reverted with git checkout -- .):

  1. Lane range check 0 <= lane <= 31 widened to <= 63: tests/compute_store_check.py controls fail (rc=1, "Expected rejection: Unverified writelane lane")
  2. Lane compare == flipped to != in the emitted select: controls fail (rc=1, exact HLSL assertion)

Notes: the draw test also checks four wrong reference outputs and three HLSL mutations against the renderer, which covers the lane mask, the compare and the old-value path. CMake registration matches the sibling tests.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6047166745 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1904#pullrequestreview-6047166745). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-24T20:49:32Z. **Review:** COMMENTED --- Review of #1904 at head d2b55bd86287a41f888cfe70680df1e4d0049630 (tier TIER_D_ISOLATED_SHADER_OPS). No P1/P2 findings. Commands run locally: - git diff --check origin/main...HEAD: rc=0 - python3 tests/docs_links_check.py: rc=0 (18 files, 376 links) - python3 tests/bidi_controls_check.py: rc=0 (1330 files) - python3 -B tests/compute_store_check.py (controls run before mode dispatch): the new writelane_controls() pass; the run ends at the expected KeyError for an unknown mode - win2025 1904 --wait 900: Debug (preset dev) 66/66 passed, Release /O2 (preset release) 66/66 passed, 0 compile failures; compute_store_aot_writelane_warp passed in both Mutations on tools/compute_store_aot.py (each reverted with git checkout -- .): 1. Lane range check `0 <= lane <= 31` widened to `<= 63`: tests/compute_store_check.py controls fail (rc=1, "Expected rejection: Unverified writelane lane") 2. Lane compare `==` flipped to `!=` in the emitted select: controls fail (rc=1, exact HLSL assertion) Notes: the draw test also checks four wrong reference outputs and three HLSL mutations against the renderer, which covers the lane mask, the compare and the old-value path. CMake registration matches the sibling tests. AI-assisted; commands listed were executed locally.
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!1897
No description provided.