shader: lower three-axis compute stores with a folded plane offset #718

Merged
Not-Saii merged 1 commit from upstream-pr/724 into main 2026-11-22 23:23:36 +00:00
Not-Saii commented 2026-11-22 23:10:41 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-22T23:10:41Z.


Change

Completes the remaining 4×4×4 case of #701. After #708, store layouts encoded at most two address axes. This adds a third indexed layout to tools/compute_store_aot.py:

  • v_lshl_add_u32 vD, v(row dispatch index), shift, v(column byte offset) produces a plane byte offset. The column operand must be a v_lshlrev_b32 byte offset, and row and column must be different axes.
  • buffer_store_* v[i:i+1] ... idxen offen with a dispatch index on a third axis and that plane offset emits tid.I * stride + (tid.R << row_shift) + (tid.C << shift) + offset.
  • Bounds: the element fits its column (offset + 4·count ≤ 1 << shift), one group's columns fit one row (dims[C] << shift ≤ 1 << row_shift), and one group's rows fit the stride (dims[R] << row_shift ≤ stride). All three axes count toward the existing "every invocation of the group is separated" check.

The existing layouts, --group-reg behavior and shader_profile_audit.py candidates are unchanged. The audit already passes group Z as group X + 2 when Z > 1.

Fixes #701

Verification

Base 121fdc3, commit b0fa545. Windows 11 build 26300.9974, MSVC 19.44.35230, Windows SDK 10.0.26100 (DXC from the SDK), Python 3.14.8, LLVM 15.0.7 (LLVM-C.dll). Debug layer unavailable.

ctest --preset dev --no-tests=error -R '^compute_store_aot_' --output-on-failure
Test Adapter Result
compute_store_aot_hardware NVIDIA GeForce RTX 4090, driver 32.0.16.1088 Passed. 4×4×4 at groups=1x2x2: compared_words=320 mismatches=0
compute_store_aot_warp WARP Passed
ctest --preset dev --no-tests=error -R 'compute|shader_metadata|shader_profile|pso_'

17/17 passed, no skips.

All 22 pure-Python checks listed in AGENTS.md pass on Windows, including docs_links_check.py.

Not run locally: tests/compute_store_check.py binary. The LLVM 15 Windows installer does not ship llvm-mc, so the Ubuntu CI job (LLVM 15) assembles the new fixture and checks disassembly against the CPU lowering. As a partial local check, a hand-encoded VOP3 v_lshl_add_u32 v7, v4, 4, v5 disassembled with LLVM 15 LLVM-C.dll prints exactly that line, which matches the new pattern. I did not run the release preset.

Evidence and follow-up

New fixture CUBE in tests/compute_store_check.py is original synthetic gfx1013 assembly written for this test (MIT). Group 4×4×4, dispatch Z through idxen, (tid.y << 4) + (tid.x << 2) through offen, stride 132, one word per invocation storing dispatch Z. Dispatches 1×1×1 and 1×2×2 are compared over all 320 words against an independent per-invocation model. The 132-byte stride covers both groups' rows in Y and leaves one guard word per plane.

Failure cases that must and do fail:

  • On the adapter: a flipped guard word; the 1×1×1 group count against the 1×2×2 reference; recompiled HLSL with X/Y swapped; recompiled HLSL that ignores Z; recompiled HLSL with half the group X size.
  • CPU rejections, each checked for its intended diagnostic:
    • Z = 1 (v2 undefined) and wrong sizes on each axis;
    • missing, duplicate or overwritten group-Z register;
    • row and column from the same axis, or index and row from the same axis;
    • a raw local ID as the row, or an index as the column;
    • column overflow of a row, element overflow of a column, stride 60;
    • a plane offset without idxen, from a misaligned register pair, or stored as data.

Assumptions: the group-Z SGPR binding remains a caller assumption, as for X and Y. Like the existing two-axis layout, the bounds are per group: the caller's stride and dispatch must keep every plane in range. This is fixture evidence only. Any change to the archive CS counts needs a maintainer rescan.

docs/experiments.md "Two- and three-dimensional thread groups" now describes the third store form, the 4×4×4 fixture row and the new controls.

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.

This change is AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6549042923 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/724). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-22T23:10:41Z. --- ## Change Completes the remaining 4×4×4 case of #701. After #708, store layouts encoded at most two address axes. This adds a third indexed layout to `tools/compute_store_aot.py`: - `v_lshl_add_u32 vD, v(row dispatch index), shift, v(column byte offset)` produces a plane byte offset. The column operand must be a `v_lshlrev_b32` byte offset, and row and column must be different axes. - `buffer_store_* v[i:i+1] ... idxen offen` with a dispatch index on a third axis and that plane offset emits `tid.I * stride + (tid.R << row_shift) + (tid.C << shift) + offset`. - Bounds: the element fits its column (`offset + 4·count ≤ 1 << shift`), one group's columns fit one row (`dims[C] << shift ≤ 1 << row_shift`), and one group's rows fit the stride (`dims[R] << row_shift ≤ stride`). All three axes count toward the existing "every invocation of the group is separated" check. The existing layouts, `--group-reg` behavior and `shader_profile_audit.py` candidates are unchanged. The audit already passes group Z as group X + 2 when Z > 1. Fixes #701 ## Verification Base `121fdc3`, commit `b0fa545`. Windows 11 build 26300.9974, MSVC 19.44.35230, Windows SDK 10.0.26100 (DXC from the SDK), Python 3.14.8, LLVM 15.0.7 (`LLVM-C.dll`). Debug layer unavailable. ```powershell ctest --preset dev --no-tests=error -R '^compute_store_aot_' --output-on-failure ``` | Test | Adapter | Result | |---|---|---| | `compute_store_aot_hardware` | NVIDIA GeForce RTX 4090, driver 32.0.16.1088 | Passed. 4×4×4 at `groups=1x2x2`: `compared_words=320 mismatches=0` | | `compute_store_aot_warp` | WARP | Passed | ```powershell ctest --preset dev --no-tests=error -R 'compute|shader_metadata|shader_profile|pso_' ``` 17/17 passed, no skips. All 22 pure-Python checks listed in `AGENTS.md` pass on Windows, including `docs_links_check.py`. Not run locally: `tests/compute_store_check.py binary`. The LLVM 15 Windows installer does not ship `llvm-mc`, so the Ubuntu CI job (LLVM 15) assembles the new fixture and checks disassembly against the CPU lowering. As a partial local check, a hand-encoded VOP3 `v_lshl_add_u32 v7, v4, 4, v5` disassembled with LLVM 15 `LLVM-C.dll` prints exactly that line, which matches the new pattern. I did not run the `release` preset. ## Evidence and follow-up New fixture `CUBE` in `tests/compute_store_check.py` is original synthetic gfx1013 assembly written for this test (MIT). Group 4×4×4, dispatch Z through `idxen`, `(tid.y << 4) + (tid.x << 2)` through `offen`, stride 132, one word per invocation storing dispatch Z. Dispatches 1×1×1 and 1×2×2 are compared over all 320 words against an independent per-invocation model. The 132-byte stride covers both groups' rows in Y and leaves one guard word per plane. Failure cases that must and do fail: - **On the adapter:** a flipped guard word; the 1×1×1 group count against the 1×2×2 reference; recompiled HLSL with X/Y swapped; recompiled HLSL that ignores Z; recompiled HLSL with half the group X size. - **CPU rejections**, each checked for its intended diagnostic: - Z = 1 (`v2` undefined) and wrong sizes on each axis; - missing, duplicate or overwritten group-Z register; - row and column from the same axis, or index and row from the same axis; - a raw local ID as the row, or an index as the column; - column overflow of a row, element overflow of a column, stride 60; - a plane offset without `idxen`, from a misaligned register pair, or stored as data. Assumptions: the group-Z SGPR binding remains a caller assumption, as for X and Y. Like the existing two-axis layout, the bounds are per group: the caller's stride and dispatch must keep every plane in range. This is fixture evidence only. Any change to the archive CS counts needs a maintainer rescan. `docs/experiments.md` "Two- and three-dimensional thread groups" now describes the third store form, the 4×4×4 fixture row and the new controls. ## 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. This change is AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:44:30 +00:00
rwZephyr commented 2026-11-24 06:48:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rwZephyr on 2026-11-22T23:21:15Z.


Independent Windows 10 validation of the remaining 4×4×4 case from #701 on b0fa5451923b96f9d36ee4e178a48fd7ef0bb262. Windows 10 22H2 build 19045.6466, MSVC 19.44.35230, Windows SDK 10.0.26100.0, DXC 1.8.2502.11, Debug with /MTd. D3D12 debug layer unavailable on both backends.

cmake --preset dev "-DINTAKE_PYTHON=$((Get-Command python).Source)" "-DDXC_EXECUTABLE=$dxc" -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug
cmake --build --preset dev --parallel 4 --target offscreen_check
$env:XBOX2WINDOWS_ADAPTER = 'RTX 3060 Ti'
ctest --preset dev --no-tests=error -V -R '^compute_store_aot_(hardware|warp)$'
  • Hardware: RTX 3060 Ti (10de:2414), driver 621.24 (32.0.16.2124 via DXGI). Passed.
  • Software: In-box WARP (1414:008c), driver 10.0.19041.5794. Passed.
  • Skipped: Zero.

I also ran draw_grid(..., "cube") directly after compiling the fixture with -T cs_6_0 -E main. Both adapters matched all 320 reference words for each dispatch (1×1×1 and 1×2×2). The five negative controls returned exit 1 with the same word mismatch counts on both adapters.

Control Mismatched words First mismatching word
Flipped guard 1 32
Wrong group count 192 16
Swapped X/Y 96 20
Ignored Z 224 4
Halved group X 128 2

The base translator at 121fdc3 rejected the same CUBE program at v_lshl_add_u32 v7, v4, 4, v5 before dispatch.

AI-assisted. All reported runs were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7087510120 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/724#issuecomment-7087510120). Originally posted by [rwZephyr](https://github.com/rwZephyr) on 2026-11-22T23:21:15Z. --- Independent Windows 10 validation of the remaining 4×4×4 case from #701 on `b0fa5451923b96f9d36ee4e178a48fd7ef0bb262`. Windows 10 22H2 build `19045.6466`, MSVC `19.44.35230`, Windows SDK `10.0.26100.0`, DXC `1.8.2502.11`, Debug with `/MTd`. D3D12 debug layer unavailable on both backends. ```powershell cmake --preset dev "-DINTAKE_PYTHON=$((Get-Command python).Source)" "-DDXC_EXECUTABLE=$dxc" -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebug cmake --build --preset dev --parallel 4 --target offscreen_check $env:XBOX2WINDOWS_ADAPTER = 'RTX 3060 Ti' ctest --preset dev --no-tests=error -V -R '^compute_store_aot_(hardware|warp)$' ``` - **Hardware:** RTX 3060 Ti (`10de:2414`), driver `621.24` (`32.0.16.2124` via DXGI). Passed. - **Software:** In-box WARP (`1414:008c`), driver `10.0.19041.5794`. Passed. - **Skipped:** Zero. I also ran `draw_grid(..., "cube")` directly after compiling the fixture with `-T cs_6_0 -E main`. Both adapters matched all 320 reference words for each dispatch (`1×1×1` and `1×2×2`). The five negative controls returned exit 1 with the same word mismatch counts on both adapters. | Control | Mismatched words | First mismatching word | | --- | ---: | ---: | | Flipped guard | 1 | 32 | | Wrong group count | 192 | 16 | | Swapped X/Y | 96 | 20 | | Ignored Z | 224 | 4 | | Halved group X | 128 | 2 | The base translator at `121fdc3` rejected the same `CUBE` program at `v_lshl_add_u32 v7, v4, 4, v5` before dispatch. AI-assisted. All reported runs were executed locally.
roansystemlabs commented 2026-11-24 06:48:51 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-22T23:25:00Z.


Thanks for picking this up. We had a local branch on the same 4×4×4 case; since you claimed it first, we won't open a duplicate. Two things from it that may help.

Independent run with the debug layer. Head b0fa545, Windows 11 build 26200.9974, D3D12 debug layer enabled, NVIDIA GeForce RTX 3070 (driver 621.01) and WARP:

ctest --preset dev --no-tests=error -R "^(compute_store_aot_|compute_mesh_texture_|compute_to_pixel_|offscreen_warp|compute_|shader_metadata_census)" -V
100% tests passed, 0 tests failed out of 12

compute_store_aot_hardware and compute_store_aot_warp each report 17 full readbacks with compared_words=320 mismatches=0 and debug_errors=0 debug_warnings=0, including the 4×4×4 cube at groups=1x1x1 and groups=1x2x2. The only debug warnings in the run are the two existing D3D12 1328 ones in compute_to_pixel_*.

What LLVM 15 emits for this address. We compiled the same layout (row = dispatch Z through vindex, offset = (dispatch Y << 4) + (dispatch X << 2), storing dispatch Z) with the Ubuntu llvm-15 package (15.0.7):

llc-15 -mtriple=amdgcn--amdpal -mcpu=gfx1013 -O2 -filetype=obj cube.ll -o cube.o
llvm-objdump-15 -d --mcpu=gfx1013 cube.o
v_lshl_add_u32 v1, s3, 2, v1
s_lshl_b32 s0, s2, 2
v_add_lshl_u32 v3, s0, v0, 2
v_lshl_add_u32 v0, s4, 2, v2
v_lshl_add_u32 v1, v1, 4, v3
buffer_store_dword v0, v[0:1], s[8:11], 0 idxen offen

Run log: https://github.com/roansystemlabs/Xbox2Windows/actions/runs/45081718225 (b_kernel.ll is an amdgpu_kernel; h_cs_args.ll is an amdgpu_cs entry taking the IDs as arguments and gives the same five address instructions). LLVM folds the X term as s_lshl_b32 of the group ID followed by v_add_lshl_u32 with the local ID, not v_lshl_add_u32 + v_lshlrev_b32. The plane step itself (v_lshl_add_u32 v1, v1, 4, v3) matches your pattern, but its column operand comes from v_add_lshl_u32. With this sequence (descriptor load as in the other fixtures, --group-reg 2 --group-reg-y 3 --group-reg-z 4 --stride 136), lower() at b0fa545 raises Unsupported compute instruction: s_lshl_b32 s0, s2, 2. This isn't a defect in your fixture, but compiler-generated 4×4×4 stores of this shape would still stop there. Our branch already accepts these three instructions with source-built fixtures and full readbacks on WARP and RTX 3070, so we'll offer that as a small follow-up on top of #724 once it lands.

AI-assisted: yes.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7087557206 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/724#issuecomment-7087557206). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-22T23:25:00Z. --- Thanks for picking this up. We had a local branch on the same 4×4×4 case; since you claimed it first, we won't open a duplicate. Two things from it that may help. **Independent run with the debug layer.** Head `b0fa545`, Windows 11 build 26200.9974, D3D12 debug layer enabled, NVIDIA GeForce RTX 3070 (driver 621.01) and WARP: ``` ctest --preset dev --no-tests=error -R "^(compute_store_aot_|compute_mesh_texture_|compute_to_pixel_|offscreen_warp|compute_|shader_metadata_census)" -V 100% tests passed, 0 tests failed out of 12 ``` `compute_store_aot_hardware` and `compute_store_aot_warp` each report 17 full readbacks with `compared_words=320 mismatches=0` and `debug_errors=0 debug_warnings=0`, including the 4×4×4 cube at `groups=1x1x1` and `groups=1x2x2`. The only debug warnings in the run are the two existing `D3D12 1328` ones in `compute_to_pixel_*`. **What LLVM 15 emits for this address.** We compiled the same layout (row = dispatch Z through `vindex`, offset = `(dispatch Y << 4) + (dispatch X << 2)`, storing dispatch Z) with the Ubuntu `llvm-15` package (15.0.7): ```sh llc-15 -mtriple=amdgcn--amdpal -mcpu=gfx1013 -O2 -filetype=obj cube.ll -o cube.o llvm-objdump-15 -d --mcpu=gfx1013 cube.o ``` ``` v_lshl_add_u32 v1, s3, 2, v1 s_lshl_b32 s0, s2, 2 v_add_lshl_u32 v3, s0, v0, 2 v_lshl_add_u32 v0, s4, 2, v2 v_lshl_add_u32 v1, v1, 4, v3 buffer_store_dword v0, v[0:1], s[8:11], 0 idxen offen ``` Run log: https://github.com/roansystemlabs/Xbox2Windows/actions/runs/45081718225 (`b_kernel.ll` is an `amdgpu_kernel`; `h_cs_args.ll` is an `amdgpu_cs` entry taking the IDs as arguments and gives the same five address instructions). LLVM folds the X term as `s_lshl_b32` of the group ID followed by `v_add_lshl_u32` with the local ID, not `v_lshl_add_u32` + `v_lshlrev_b32`. The plane step itself (`v_lshl_add_u32 v1, v1, 4, v3`) matches your pattern, but its column operand comes from `v_add_lshl_u32`. With this sequence (descriptor load as in the other fixtures, `--group-reg 2 --group-reg-y 3 --group-reg-z 4 --stride 136`), `lower()` at `b0fa545` raises `Unsupported compute instruction: s_lshl_b32 s0, s2, 2`. This isn't a defect in your fixture, but compiler-generated 4×4×4 stores of this shape would still stop there. Our branch already accepts these three instructions with source-built fixtures and full readbacks on WARP and RTX 3070, so we'll offer that as a small follow-up on top of #724 once it lands. AI-assisted: yes.
roansystemlabs commented 2026-11-24 06:48:54 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by roansystemlabs on 2026-11-23T00:48:34Z.


Follow-up as mentioned above: #750 (accepts the LLVM 15 group-base form, s_lshl_b32 + v_add_lshl_u32, with a fixture taken from the actual llc-15 output).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7088650380 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/724#issuecomment-7088650380). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-23T00:48:34Z. --- Follow-up as mentioned above: #750 (accepts the LLVM 15 group-base form, `s_lshl_b32` + `v_add_lshl_u32`, with a fixture taken from the actual `llc-15` output).
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!718
No description provided.