shader: lower two-word constant buffer reads in the pixel translator #304

Manually merged
github merged 1 commit from gh-pr/304/head into gh-pr/304/base 2026-11-26 21:41:39 +00:00
Owner

@⁠rasptum on GitHub · 2026-11-21 21:37 UTC · original
rasptum:shader/scalar-buffer-loads → main · +114 −5 · 3 files · 1 commits · merged 2026-11-22 04:01 UTC

Change

tools/pixel_aot.py now lowers s_buffer_load_dwordx2. It reads two consecutive words from the tracked four-SGPR constant descriptor into an SGPR pair, and each word becomes one component of params[...], the same value model the four-word load and the one-word load from #277 use. Before this change the instruction stopped translation with Unsupported instruction.

The rules are the ones the neighbouring loads already apply:

  • the base must be the ready four-SGPR descriptor loaded through s_load_dwordx4;
  • the offset is an immediate (null is offset zero), dword-aligned, and both words must lie inside the 256-byte desktop binding, so the last accepted offset is 248. An 8-byte alignment is not required: the instruction reads two words at any dword-aligned address;
  • the destination is an even-aligned pair no higher than s[104:105]. This is the only pair form LLVM names: LLVM 15 answers s[61:62] with invalid register alignment;
  • both destination words stay unreadable and unwritable until s_waitcnt lgkmcnt(0).

The register-offset form, the eight-word and sixteen-word buffer loads and s_load_dwordx2 remain rejected.

Shared interface touched: the scalar constant load branch of lower() in tools/pixel_aot.py (one pattern and the destination-width check) and the fixture lists in tests/pixel_aot_check.py. fp_operand, the scalar value model and the s_waitcnt handling are unchanged. This builds on #277.

Overlapping open work, checked with git merge-tree --write-tree against each PR head on 2026-11-21, before the final rebase onto b53bfb0:

  • #257 and #279 (scalar ALU) and #232 (vector integer table): no overlap in tools/pixel_aot.py. #279 gets a textual conflict in tests/pixel_aot_check.py only, where both sides add fixtures at the same places. #232 and #257 already conflict with current main in the same files and this change adds no file to that.
  • #176 and #271 (s_waitcnt handling): #271 merges cleanly. #176 already conflicts with current main; this change does not touch the wait handling or sample_pending.
  • #169, #283 and #292 get a textual conflict in tests/pixel_aot_check.py (and #283 in docs/experiments.md), again from adjacent additions. #288 merges cleanly.

None of these needs to land first. I will rebase and rerun if one of them merges before this.

Verification

Commit 28ef21b on main 1292d15 (rebased after #292, #297 and #279 landed; results below are from this commit). Windows 10 22H2 build 19045, debug layer enabled.

Fail before, with the new tests and the translator from main:

python -B tests/pixel_aot_check.py draw <dxc.exe> out/build/dev/offscreen_check.exe warp
ValueError: Unsupported instruction 17: s_buffer_load_dwordx2 s[60:61], s[44:47], 0xc

Pass after:

ctest --preset dev --no-tests=error -R '^pixel_aot_'
Build Adapter pixel_aot_warp pixel_aot_hardware
dev WARP 10.0.19041.5794 (in-box), NVIDIA GeForce RTX 3060 driver 32.0.15.9636 Passed Passed
Agility SDK build WARP 1.0.22, same RTX 3060 Passed Passed

The new draw reads pairs at offsets 12, 20 and 248 and compares all four channels of 4,096 pixels bitwise with a CPU reference, with two sets of constants. The negative controls report pixel_mismatch x=0 y=0 on all three adapters: changing the second word of each pair in the bound buffer (bytes 16, 24 and 252, one draw each) and reading the middle pair one word early.

Full suite, ctest --preset dev --no-tests=error: 145 tests, 126 passed, 17 skipped (capability skips, reported separately from passes), 2 failed. Both failures are on the in-box WARP 10.0.19041 and are outside this change, which touches only tools/pixel_aot.py, tests/pixel_aot_check.py and docs/experiments.md. bc7_draw_warp reports AOT color export differs from CPU reference and fails the same way with the test and translator sources from main. gpu_alias_lookup_writes_warp, a compute test added by #284, reports record=1 field=64 expected=0001f5a0 actual=0007d680. Both pass on WARP 1.0.22.

Full suite on the Agility SDK build with WARP 1.0.22, ctest --test-dir out/build/w10-full --no-tests=error: 145 tests, 140 passed, 3 skipped, 2 failed. The failures are bvh_wave64_warp and wave_shuffle_warp, the known WARP behaviour in #145.

LLVM 15.0.7 round trip:

python -B tests/pixel_aot_check.py binary <llvm-mc> llvm-objcopy.exe LLVM-C.dll

Passed, exit 0, with one caveat: the Windows LLVM 15.0.7 package has no llvm-mc, so a local wrapper outside the repository forwarded the assembler call to clang --target=amdgcn--amdpal -mcpu=gfx1013 -c -x assembler. The test file itself is unchanged, and CI runs it with the real llvm-mc-15. LLVM 15 prints the new fixture lines exactly as written in the test, for example s_buffer_load_dwordx2 s[62:63], s[44:47], 0x14, prints offset zero as null, and prints the register-offset form as s_buffer_load_dwordx2 s[64:65], s[44:47], s60, which the translator rejects. I did not check a newer LLVM spelling.

Pure-Python checks from AGENTS.md (bcpack_check, form_coverage_check, dxcontainer_part_offsets_check, layout_chunks_check, resource_ranges_check, script_state_check, intake/paths_check): all exit 0.

Evidence and follow-up

The fixture is a source-built text program in tests/pixel_aot_check.py (with_scalar_pair_reads), written for this change and submitted under the MIT License like the rest of the test. Each of the six loaded words feeds its own step (multiply, maximum, add, subtract, move, multiply), and the reference asserts that every step is exact in binary32, so the comparison does not depend on rounding direction or fusion. The first pair spans two float4 rows of the desktop buffer.

check_controls adds 20 rejected variants of one load (misaligned and out-of-range offsets, register offset, odd, short, long and out-of-range destinations, wrong base, the one-word and four-word mnemonics with a pair destination, s_load_dwordx2, and the eight-word and sixteen-word loads) plus ordering cases: a load before the descriptor is ready, reads and writes of either word before the wait, a second load into a pending pair, and a load after the descriptor registers were overwritten.

Assumptions: the desktop buffer mirrors the 256 bound bytes word for word, as for the existing loads. Execution with a title's own pipeline state remains unverified.

The README shader row already says supported programs read constants, so it is unchanged. docs/experiments.md has a new paragraph under Offline pixel shader recompilation; the reproduction command there is unchanged: ctest --preset dev -R '^pixel_aot_' -V.

Follow-up another contributor can pick up: the register-offset form of the scalar buffer loads, the eight-word and sixteen-word loads, and the two in-box WARP 10.0.19041 failures noted above (bc7_draw_warp, which I am looking at, and gpu_alias_lookup_writes_warp).

AI-assisted (Claude Code). The Windows results were measured locally.

🤖 Generated with Claude Code

**@⁠rasptum** on GitHub · 2026-11-21 21:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/304) `rasptum:shader/scalar-buffer-loads` → `main` · +114 −5 · 3 files · 1 commits · merged 2026-11-22 04:01 UTC ## Change `tools/pixel_aot.py` now lowers `s_buffer_load_dwordx2`. It reads two consecutive words from the tracked four-SGPR constant descriptor into an SGPR pair, and each word becomes one component of `params[...]`, the same value model the four-word load and the one-word load from #277 use. Before this change the instruction stopped translation with `Unsupported instruction`. The rules are the ones the neighbouring loads already apply: - the base must be the ready four-SGPR descriptor loaded through `s_load_dwordx4`; - the offset is an immediate (`null` is offset zero), dword-aligned, and both words must lie inside the 256-byte desktop binding, so the last accepted offset is 248. An 8-byte alignment is not required: the instruction reads two words at any dword-aligned address; - the destination is an even-aligned pair no higher than `s[104:105]`. This is the only pair form LLVM names: LLVM 15 answers `s[61:62]` with `invalid register alignment`; - both destination words stay unreadable and unwritable until `s_waitcnt lgkmcnt(0)`. The register-offset form, the eight-word and sixteen-word buffer loads and `s_load_dwordx2` remain rejected. Shared interface touched: the scalar constant load branch of `lower()` in `tools/pixel_aot.py` (one pattern and the destination-width check) and the fixture lists in `tests/pixel_aot_check.py`. `fp_operand`, the scalar value model and the `s_waitcnt` handling are unchanged. This builds on #277. Overlapping open work, checked with `git merge-tree --write-tree` against each PR head on 2026-11-21, before the final rebase onto `b53bfb0`: - #257 and #279 (scalar ALU) and #232 (vector integer table): no overlap in `tools/pixel_aot.py`. #279 gets a textual conflict in `tests/pixel_aot_check.py` only, where both sides add fixtures at the same places. #232 and #257 already conflict with current `main` in the same files and this change adds no file to that. - #176 and #271 (`s_waitcnt` handling): #271 merges cleanly. #176 already conflicts with current `main`; this change does not touch the wait handling or `sample_pending`. - #169, #283 and #292 get a textual conflict in `tests/pixel_aot_check.py` (and #283 in `docs/experiments.md`), again from adjacent additions. #288 merges cleanly. None of these needs to land first. I will rebase and rerun if one of them merges before this. ## Verification Commit 28ef21b on `main` 1292d15 (rebased after #292, #297 and #279 landed; results below are from this commit). Windows 10 22H2 build 19045, debug layer enabled. Fail before, with the new tests and the translator from `main`: ``` python -B tests/pixel_aot_check.py draw <dxc.exe> out/build/dev/offscreen_check.exe warp ValueError: Unsupported instruction 17: s_buffer_load_dwordx2 s[60:61], s[44:47], 0xc ``` Pass after: ```powershell ctest --preset dev --no-tests=error -R '^pixel_aot_' ``` | Build | Adapter | `pixel_aot_warp` | `pixel_aot_hardware` | |---|---|---|---| | `dev` | WARP 10.0.19041.5794 (in-box), NVIDIA GeForce RTX 3060 driver 32.0.15.9636 | Passed | Passed | | Agility SDK build | WARP 1.0.22, same RTX 3060 | Passed | Passed | The new draw reads pairs at offsets 12, 20 and 248 and compares all four channels of 4,096 pixels bitwise with a CPU reference, with two sets of constants. The negative controls report `pixel_mismatch x=0 y=0` on all three adapters: changing the second word of each pair in the bound buffer (bytes 16, 24 and 252, one draw each) and reading the middle pair one word early. Full suite, `ctest --preset dev --no-tests=error`: 145 tests, 126 passed, 17 skipped (capability skips, reported separately from passes), 2 failed. Both failures are on the in-box WARP 10.0.19041 and are outside this change, which touches only `tools/pixel_aot.py`, `tests/pixel_aot_check.py` and `docs/experiments.md`. `bc7_draw_warp` reports `AOT color export differs from CPU reference` and fails the same way with the test and translator sources from `main`. `gpu_alias_lookup_writes_warp`, a compute test added by #284, reports `record=1 field=64 expected=0001f5a0 actual=0007d680`. Both pass on WARP 1.0.22. Full suite on the Agility SDK build with WARP 1.0.22, `ctest --test-dir out/build/w10-full --no-tests=error`: 145 tests, 140 passed, 3 skipped, 2 failed. The failures are `bvh_wave64_warp` and `wave_shuffle_warp`, the known WARP behaviour in #145. LLVM 15.0.7 round trip: ``` python -B tests/pixel_aot_check.py binary <llvm-mc> llvm-objcopy.exe LLVM-C.dll ``` Passed, exit 0, with one caveat: the Windows LLVM 15.0.7 package has no `llvm-mc`, so a local wrapper outside the repository forwarded the assembler call to `clang --target=amdgcn--amdpal -mcpu=gfx1013 -c -x assembler`. The test file itself is unchanged, and CI runs it with the real `llvm-mc-15`. LLVM 15 prints the new fixture lines exactly as written in the test, for example `s_buffer_load_dwordx2 s[62:63], s[44:47], 0x14`, prints offset zero as `null`, and prints the register-offset form as `s_buffer_load_dwordx2 s[64:65], s[44:47], s60`, which the translator rejects. I did not check a newer LLVM spelling. Pure-Python checks from `AGENTS.md` (`bcpack_check`, `form_coverage_check`, `dxcontainer_part_offsets_check`, `layout_chunks_check`, `resource_ranges_check`, `script_state_check`, `intake/paths_check`): all exit 0. ## Evidence and follow-up The fixture is a source-built text program in `tests/pixel_aot_check.py` (`with_scalar_pair_reads`), written for this change and submitted under the MIT License like the rest of the test. Each of the six loaded words feeds its own step (multiply, maximum, add, subtract, move, multiply), and the reference asserts that every step is exact in binary32, so the comparison does not depend on rounding direction or fusion. The first pair spans two `float4` rows of the desktop buffer. `check_controls` adds 20 rejected variants of one load (misaligned and out-of-range offsets, register offset, odd, short, long and out-of-range destinations, wrong base, the one-word and four-word mnemonics with a pair destination, `s_load_dwordx2`, and the eight-word and sixteen-word loads) plus ordering cases: a load before the descriptor is ready, reads and writes of either word before the wait, a second load into a pending pair, and a load after the descriptor registers were overwritten. Assumptions: the desktop buffer mirrors the 256 bound bytes word for word, as for the existing loads. Execution with a title's own pipeline state remains unverified. The README shader row already says supported programs read constants, so it is unchanged. `docs/experiments.md` has a new paragraph under [Offline pixel shader recompilation](docs/experiments.md#offline-pixel-shader-recompilation); the reproduction command there is unchanged: `ctest --preset dev -R '^pixel_aot_' -V`. Follow-up another contributor can pick up: the register-offset form of the scalar buffer loads, the eight-word and sixteen-word loads, and the two in-box WARP 10.0.19041 failures noted above (`bc7_draw_warp`, which I am looking at, and `gpu_alias_lookup_writes_warp`). _AI-assisted (Claude Code). The Windows results were measured locally._ 🤖 Generated with [Claude Code](https://claude.com/claude-code)
s_buffer_load_dwordx2 reads two consecutive words from the tracked
four-SGPR constant descriptor into an even-aligned SGPR pair. It follows
the rules of the one-word and four-word loads: a dword-aligned immediate
offset, both words inside the 256-byte binding, and a destination that
stays unreadable until s_waitcnt lgkmcnt(0).

A draw reads pairs at offsets 12, 20 and 248 and checks each of the six
words through an exact binary32 step. Changing the second word of any
pair, or reading a pair one word early, must report a mismatch. Register
offsets, misaligned or out-of-range offsets, odd or wrong-width
destinations and the eight-word and sixteen-word loads stay rejected.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:41:38 +00:00
github manually merged commit d3cd043aef into gh-pr/304/base 2026-11-26 21:41:39 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-21 21:58 UTC · original

At 3bce854 the merge conflicts are in tests/pixel_aot_check.py. Keep the x2 LGKM and alias tests alongside the landed scalar/BFE cases.

**@⁠R0Y00** on GitHub · 2026-11-21 21:58 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/304#issuecomment-7069850485) At `3bce854` the merge conflicts are in `tests/pixel_aot_check.py`. Keep the x2 LGKM and alias tests alongside the landed scalar/BFE cases.
Author
Owner

@⁠rasptum on GitHub · 2026-11-21 22:07 UTC · original

Conflicts resolved

**@⁠rasptum** on GitHub · 2026-11-21 22:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/304#issuecomment-7069952305) Conflicts resolved
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-22 02:38 UTC · original

I reviewed 28ef21b. #283 has since landed, and GitHub now refuses the merge. Both branches replace the check_binary fixture list ending in (ceiling(), translate), (scalar64(), translate) in tests/pixel_aot_check.py. Please retain main’s affine_coordinates() alongside your two-word constant load cases, keep the MAD fixture added by #288, and rerun the LLVM 15 round trip and Windows pixel tests on the reconciled head.

**@⁠R0Y00** on GitHub · 2026-11-22 02:38 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/304#issuecomment-7073033976) I reviewed `28ef21b`. #283 has since landed, and GitHub now refuses the merge. Both branches replace the `check_binary` fixture list ending in `(ceiling(), translate), (scalar64(), translate)` in `tests/pixel_aot_check.py`. Please retain main’s `affine_coordinates()` alongside your two-word constant load cases, keep the MAD fixture added by #288, and rerun the LLVM 15 round trip and Windows pixel tests on the reconciled head.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-22 03:26 UTC · original

I reviewed 8d3113c; it resolves the previous overlap and passed all three jobs. #293 landed immediately before the merge attempt. A test merge now reports just tests/pixel_aot_check.py. Please retain the new class-mask fixture alongside your constant-pair cases there. I’ll prioritize the reconciled head when its checks finish.

**@⁠R0Y00** on GitHub · 2026-11-22 03:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/304#issuecomment-7073535640) I reviewed `8d3113c`; it resolves the previous overlap and passed all three jobs. #293 landed immediately before the merge attempt. A test merge now reports just `tests/pixel_aot_check.py`. Please retain the new class-mask fixture alongside your constant-pair cases there. I’ll prioritize the reconciled head when its checks finish.
This discussion has been locked. Commenting is limited to contributors.
No description provided.