shader: accept the LLVM 15 group-base form of a compute byte offset #744

Merged
roansystemlabs merged 2 commits from upstream-pr/750 into main 2026-11-23 01:20:04 +00:00
roansystemlabs commented 2026-11-23 00:48:23 +00:00 (Migrated from github.com)

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


Change

Follow-up to #724, as offered in https://github.com/R0Y00/Xbox2Windows/pull/724#issuecomment-7087557206. Refs #701.

LLVM 15 does not build the X byte offset of the 4×4×4 store the way the #724 fixture does. It shifts the group ID in an SGPR first and then adds the local ID and shifts in one VALU instruction. With that sequence the translator on main stops at the first instruction:

Unsupported compute instruction: s_lshl_b32 s0, s2, 2

This PR accepts the two instructions:

  • s_lshl_b32 sD, s<group A>, log2(size A): the group's first dispatch index, only for a power-of-two group dimension and a shift equal to its log2. The destination must not be pending from a descriptor load. The result is not a storable word.
  • v_add_lshl_u32 vD, s<group base A>, v<local A>, shift: (group * size + local) << shift, the same byte offset as v_lshlrev_b32 of the dispatch index. It must use the local ID of the same axis as the group base.

The result gets the same tag as a v_lshlrev_b32 byte offset, so the index_offset and index_plane layouts from #724, their nesting checks and the HLSL they emit are unchanged. The third instruction in the LLVM sequence, v_lshl_add_u32 v1, v1, 4, v3, is already the #724 plane form. The ten existing cases produce the same HLSL as on main.

Fixture

llvm_cube keeps the address instructions that llc-15 produced in the probe linked on #724, with their registers. Only the kernel-argument load (s_load_dwordx2 s[0:1], s[0:1], null) is replaced by s_mov_b32 s1, 0, so the descriptor comes from the table as in the other fixtures:

s_mov_b32 s1, 0
v_lshl_add_u32 v1, s3, 2, v1
s_waitcnt lgkmcnt(0)
s_load_dwordx4 s[8:11], s[0:1], null
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
s_waitcnt lgkmcnt(0)
buffer_store_dword v0, v[0:1], s[8:11], 0 idxen offen
s_endpgm

Probe: Ubuntu 22.04 llvm-15 (15.0.7) on the fork's CI, https://github.com/roansystemlabs/Xbox2Windows/actions/runs/45081718225

llc-15 -mtriple=amdgcn--amdpal -mcpu=gfx1013 -O2 -filetype=obj cube.ll -o cube.o
llvm-objdump-15 -d --mcpu=gfx1013 cube.o

Bindings: --table-reg 0 --descriptor-offset 0 --group-reg 2 --group-reg-y 3 --group-reg-z 4 --stride 136. Emitted HLSL:

[numthreads(4,4,4)]
void main(uint3 tid : SV_DispatchThreadID) {
    outputData.Store(tid.z * 136u + (tid.y << 4u) + (tid.x << 2u) + 0u, tid.z);
}

The 136-byte stride differs from the 132 of cube, so the two readbacks place the planes differently. Docs: the "Two- and three-dimensional thread groups" subsection describes the form, the probe command and the new controls. No README change.

Verification

Commit 20f0c32 on 67edabe. Windows 11 build 26200.9974, D3D12 debug layer enabled, NVIDIA GeForce RTX 3070 (driver 621.01) and WARP (Microsoft Basic Render Driver).

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 passed 20 full 320-word readbacks with mismatches=0 and debug_errors=0 debug_warnings=0: the 17 existing ones and llvm_cube at 1×1×1, 1×1×2 and 1×2×2. The expected words come from the test's per-invocation model, which does not call the translator. The 1×2×2 dispatch writes 256 words in 8 planes of 34 words, with 2 untouched words at the end of each plane and 48 after the last one. The two compute_to_pixel_* debug warnings (D3D12 1328) are pre-existing.

On each adapter, llvm_cube must also fail for:

  • a flipped guard word;
  • the 1×1×1 group count against the 1×2×2 reference;
  • recompiled HLSL with X and Y swapped, X and Z swapped, and Y and Z swapped;
  • recompiled HLSL that ignores Z;
  • recompiled HLSL with half the group X size.

Each recompiled variant runs on the largest dispatch, as for the other shapes, with one exception. Y and Z both span 8 in the 1×2×2 dispatch, so swapping them leaves the buffer unchanged. That swap runs on 1×1×2, where Y spans 4 and Z spans 8. The test names it in MUTATION_DISPATCH. Run on 1×2×2 it escapes (escaped detection with groups=(1, 2, 2), checked with a local mutant below). The other shapes' mutations run on the same dispatch as before.

CPU controls (llvm_cube_controls(), run in both modes) reject:

  • group sizes 4×8×4, 4×4×8, 4×4×2, 4×4×1, 4×1×4 and 4×4×3;
  • group X of 2, and of 8 with Y moved to bit 5, where only the group-base shift no longer matches;
  • group X of 6 with Y moved to bit 5, whose shift still matches but which is not a power of two;
  • a group base with the wrong shift, from a register that is not a group ID, written past s105, written to a register still pending from a descriptor load, or scaled again;
  • the same form on Y with group size 4×2×4 (accepted, exact HLSL checked), then with the Y base shifted by 2, and with group Y of 3: the shift and the power-of-two check use the base's own axis;
  • v_add_lshl_u32 of an unscaled group ID, of the Y group base with local X, of the X group base with local Z, or into a register past v255;
  • X shifts of 1 and 3, through the existing element and row checks;
  • a group base stored as data.

Mutation check (local script, not added to the repo): 14 single-line mutants of the new translator code and 3 of the test, each run through compute_store_check.py draw on WARP and on the RTX 3070. All 17 failed on both adapters.

  • Translator: each guard of the two instructions removed or loosened (pending destination, s105, power of two, shift, shift off by one, group ID instead of group base, local ID of any axis, v255), the group base tagged as a group ID or always on X, the byte offset on the wrong axis or with its shift off by one, tagged as a dispatch index, and a group base accepted as data. All 14 fail in the CPU controls or the exact-HLSL assertion, before any dispatch. The recompiled variants above cover the GPU side.
  • Test: the Y/Z exception removed (escapes on 1×2×2, as above), and the model storing tid.y or using stride 132 (Compute readback differs from CPU reference).

Five more translator mutants, run against the CPU controls only, all fail: the group base accepted from any tagged SGPR, a group base scaled again, the shift or the power-of-two check taken from group X instead of the base's axis, and v_add_lshl_u32 accepting any tagged SGPR as its base.

Pure-Python checks from AGENTS.md (22 scripts, including docs_links_check.py): all exit 0.

compute_store_check.py binary needs LLVM 15 with AMDGPU, which I don't have locally. It ran on the fork's Ubuntu job (LLVM 15) with workflow_dispatch at 182e642, an earlier revision of this branch with the same translator code and fixture (before the rebase on 67edabe and the added group-base CPU controls), and passed: llvm_cube is assembled with llvm-mc-15, decoded through libLLVM-15.so.1 to the same lines, checked for the 4×4×4 PSV0 shape, and the CLI emits the same HLSL. The Linux Python job in that run also passed. Its two Windows jobs were cancelled after about four minutes, before they finished, so the Windows CI result will come from this PR's own checks. Run: https://github.com/roansystemlabs/Xbox2Windows/actions/runs/45087071763 (first attempt).

GPU load during the runs (nvidia-smi): 8 % before and 2 % after the tests, 1 % after the mutants, with about 5.6 GB of 8 GB already in use by other processes on the machine. compute_store_aot_hardware takes 16.9 s against its 45 s timeout; the new case adds one compile, three readbacks and five recompiled variants.

Evidence and follow-up

  • Fixture: LLVM 15 output for our own IR (the cube.ll in the probe run above), MIT. No game files.
  • Assumptions: as in #708 and #724, the group-ID SGPRs are a caller binding. The probe is an amdgpu_kernel, so s2, s3 and s4 follow its kernel-argument pointer. The same run has an amdgpu_cs entry with the IDs as arguments that compiles to the same five address instructions; it confirms the instruction forms, not the registers.
  • Caller responsibility: unchanged from #724. With several groups on an axis, the host keeps the stride and dispatch in range; the fixture keeps dispatch X at one group.
  • Census: not rerun (no archive here). These are fixture results only.
  • Not covered: v_add_lshl_u32 with the operands in the other order, group bases for non-power-of-two sizes (s_mul_i32), and v_lshl_or_b32 or multiply forms.
  • Conflicts: git merge-tree against #738, which also touches compute_store_aot.py, compute_store_check.py and docs/experiments.md, and against #718 merges cleanly, and the CPU controls pass on both merged trees. Against the other open PRs that touch docs/experiments.md, the set of conflicting files is the same as against main.

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.

AI-assisted: yes. Code, tests and this description were prepared with an AI coding agent and checked by running the commands above.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6550004527 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/750). Originally posted by [roansystemlabs](https://github.com/roansystemlabs) on 2026-11-23T00:48:23Z. --- ## Change Follow-up to #724, as offered in https://github.com/R0Y00/Xbox2Windows/pull/724#issuecomment-7087557206. Refs #701. LLVM 15 does not build the X byte offset of the 4×4×4 store the way the #724 fixture does. It shifts the group ID in an SGPR first and then adds the local ID and shifts in one VALU instruction. With that sequence the translator on `main` stops at the first instruction: ``` Unsupported compute instruction: s_lshl_b32 s0, s2, 2 ``` This PR accepts the two instructions: - `s_lshl_b32 sD, s<group A>, log2(size A)`: the group's first dispatch index, only for a power-of-two group dimension and a shift equal to its log2. The destination must not be pending from a descriptor load. The result is not a storable word. - `v_add_lshl_u32 vD, s<group base A>, v<local A>, shift`: `(group * size + local) << shift`, the same byte offset as `v_lshlrev_b32` of the dispatch index. It must use the local ID of the same axis as the group base. The result gets the same tag as a `v_lshlrev_b32` byte offset, so the `index_offset` and `index_plane` layouts from #724, their nesting checks and the HLSL they emit are unchanged. The third instruction in the LLVM sequence, `v_lshl_add_u32 v1, v1, 4, v3`, is already the #724 plane form. The ten existing cases produce the same HLSL as on `main`. ### Fixture `llvm_cube` keeps the address instructions that `llc-15` produced in the probe linked on #724, with their registers. Only the kernel-argument load (`s_load_dwordx2 s[0:1], s[0:1], null`) is replaced by `s_mov_b32 s1, 0`, so the descriptor comes from the table as in the other fixtures: ``` s_mov_b32 s1, 0 v_lshl_add_u32 v1, s3, 2, v1 s_waitcnt lgkmcnt(0) s_load_dwordx4 s[8:11], s[0:1], null 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 s_waitcnt lgkmcnt(0) buffer_store_dword v0, v[0:1], s[8:11], 0 idxen offen s_endpgm ``` Probe: Ubuntu 22.04 `llvm-15` (15.0.7) on the fork's CI, https://github.com/roansystemlabs/Xbox2Windows/actions/runs/45081718225 ```sh llc-15 -mtriple=amdgcn--amdpal -mcpu=gfx1013 -O2 -filetype=obj cube.ll -o cube.o llvm-objdump-15 -d --mcpu=gfx1013 cube.o ``` Bindings: `--table-reg 0 --descriptor-offset 0 --group-reg 2 --group-reg-y 3 --group-reg-z 4 --stride 136`. Emitted HLSL: ```hlsl [numthreads(4,4,4)] void main(uint3 tid : SV_DispatchThreadID) { outputData.Store(tid.z * 136u + (tid.y << 4u) + (tid.x << 2u) + 0u, tid.z); } ``` The 136-byte stride differs from the 132 of `cube`, so the two readbacks place the planes differently. Docs: the "Two- and three-dimensional thread groups" subsection describes the form, the probe command and the new controls. No README change. ## Verification Commit `20f0c32` on `67edabe`. Windows 11 build 26200.9974, D3D12 debug layer enabled, NVIDIA GeForce RTX 3070 (driver 621.01) and WARP (Microsoft Basic Render Driver). ``` 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 passed 20 full 320-word readbacks with `mismatches=0` and `debug_errors=0 debug_warnings=0`: the 17 existing ones and `llvm_cube` at 1×1×1, 1×1×2 and 1×2×2. The expected words come from the test's per-invocation model, which does not call the translator. The 1×2×2 dispatch writes 256 words in 8 planes of 34 words, with 2 untouched words at the end of each plane and 48 after the last one. The two `compute_to_pixel_*` debug warnings (`D3D12 1328`) are pre-existing. On each adapter, `llvm_cube` must also fail for: - a flipped guard word; - the 1×1×1 group count against the 1×2×2 reference; - recompiled HLSL with X and Y swapped, X and Z swapped, and Y and Z swapped; - recompiled HLSL that ignores Z; - recompiled HLSL with half the group X size. Each recompiled variant runs on the largest dispatch, as for the other shapes, with one exception. Y and Z both span 8 in the 1×2×2 dispatch, so swapping them leaves the buffer unchanged. That swap runs on 1×1×2, where Y spans 4 and Z spans 8. The test names it in `MUTATION_DISPATCH`. Run on 1×2×2 it escapes (`escaped detection with groups=(1, 2, 2)`, checked with a local mutant below). The other shapes' mutations run on the same dispatch as before. CPU controls (`llvm_cube_controls()`, run in both modes) reject: - group sizes 4×8×4, 4×4×8, 4×4×2, 4×4×1, 4×1×4 and 4×4×3; - group X of 2, and of 8 with Y moved to bit 5, where only the group-base shift no longer matches; - group X of 6 with Y moved to bit 5, whose shift still matches but which is not a power of two; - a group base with the wrong shift, from a register that is not a group ID, written past `s105`, written to a register still pending from a descriptor load, or scaled again; - the same form on Y with group size 4×2×4 (accepted, exact HLSL checked), then with the Y base shifted by 2, and with group Y of 3: the shift and the power-of-two check use the base's own axis; - `v_add_lshl_u32` of an unscaled group ID, of the Y group base with local X, of the X group base with local Z, or into a register past `v255`; - X shifts of 1 and 3, through the existing element and row checks; - a group base stored as data. Mutation check (local script, not added to the repo): 14 single-line mutants of the new translator code and 3 of the test, each run through `compute_store_check.py draw` on WARP and on the RTX 3070. All 17 failed on both adapters. - Translator: each guard of the two instructions removed or loosened (pending destination, `s105`, power of two, shift, shift off by one, group ID instead of group base, local ID of any axis, `v255`), the group base tagged as a group ID or always on X, the byte offset on the wrong axis or with its shift off by one, tagged as a dispatch index, and a group base accepted as data. All 14 fail in the CPU controls or the exact-HLSL assertion, before any dispatch. The recompiled variants above cover the GPU side. - Test: the Y/Z exception removed (escapes on 1×2×2, as above), and the model storing `tid.y` or using stride 132 (`Compute readback differs from CPU reference`). Five more translator mutants, run against the CPU controls only, all fail: the group base accepted from any tagged SGPR, a group base scaled again, the shift or the power-of-two check taken from group X instead of the base's axis, and `v_add_lshl_u32` accepting any tagged SGPR as its base. Pure-Python checks from `AGENTS.md` (22 scripts, including `docs_links_check.py`): all exit 0. `compute_store_check.py binary` needs LLVM 15 with AMDGPU, which I don't have locally. It ran on the fork's Ubuntu job (LLVM 15) with workflow_dispatch at `182e642`, an earlier revision of this branch with the same translator code and fixture (before the rebase on `67edabe` and the added group-base CPU controls), and passed: `llvm_cube` is assembled with `llvm-mc-15`, decoded through `libLLVM-15.so.1` to the same lines, checked for the 4×4×4 PSV0 shape, and the CLI emits the same HLSL. The Linux Python job in that run also passed. Its two Windows jobs were cancelled after about four minutes, before they finished, so the Windows CI result will come from this PR's own checks. Run: https://github.com/roansystemlabs/Xbox2Windows/actions/runs/45087071763 (first attempt). GPU load during the runs (`nvidia-smi`): 8 % before and 2 % after the tests, 1 % after the mutants, with about 5.6 GB of 8 GB already in use by other processes on the machine. `compute_store_aot_hardware` takes 16.9 s against its 45 s timeout; the new case adds one compile, three readbacks and five recompiled variants. ## Evidence and follow-up - **Fixture:** LLVM 15 output for our own IR (the `cube.ll` in the probe run above), MIT. No game files. - **Assumptions:** as in #708 and #724, the group-ID SGPRs are a caller binding. The probe is an `amdgpu_kernel`, so `s2`, `s3` and `s4` follow its kernel-argument pointer. The same run has an `amdgpu_cs` entry with the IDs as arguments that compiles to the same five address instructions; it confirms the instruction forms, not the registers. - **Caller responsibility:** unchanged from #724. With several groups on an axis, the host keeps the stride and dispatch in range; the fixture keeps dispatch X at one group. - **Census:** not rerun (no archive here). These are fixture results only. - **Not covered:** `v_add_lshl_u32` with the operands in the other order, group bases for non-power-of-two sizes (`s_mul_i32`), and `v_lshl_or_b32` or multiply forms. - **Conflicts:** `git merge-tree` against #738, which also touches `compute_store_aot.py`, `compute_store_check.py` and `docs/experiments.md`, and against #718 merges cleanly, and the CPU controls pass on both merged trees. Against the other open PRs that touch `docs/experiments.md`, the set of conflicting files is the same as against `main`. ## 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. AI-assisted: yes. Code, tests and this description were prepared with an AI coding agent and checked by running the commands above.
upstream-sync closed this pull request 2026-11-24 06:44:36 +00:00
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!744
No description provided.