Skip to content

buffer_swizzle_probe: a 16-bit load and store crossing a dword in scratch swizzle - #7353

Open
iLucasRT wants to merge 9 commits into
ItsNotRexed:mainfrom
iLucasRT:buffer-sub16-swizzle-probe
Open

iLucasRT wants to merge 9 commits into
ItsNotRexed:mainfrom
iLucasRT:buffer-sub16-swizzle-probe

Conversation

@iLucasRT

Copy link
Copy Markdown

Claimed in the coordination issue as: BUILD-2570 (finding: #7049 (comment))

What and why

A buffer_load_ushort or buffer_store_short at byte 3 of a dword also reaches one byte of the next dword. In scratch
swizzle (SWIZZLE_ENABLE=1, ADD_TID_ENABLE=1, idxen=0) the translator now answers that two ways:

Neither has been measured natively. Two cases in the multi_dword_stepping group answer both on an RDNA2 GPU with
python -I tools/buffer_swizzle_probe.py --oracle both --group multi_dword_stepping:

  • scratch_swz_load_ushort_cross (IS=8, lane 2): 0x285e if the second byte steps +4*IS, 0x0c5e if linear;
  • scratch_swz_store_short_cross (IS=16, lane 5, stride 16 so both dwords are in range): the high byte lands in
    dword 0x54 (+4*IS) or 0x18 (linear).

Translator side today (CPU, wave32 and wave64 alike): the load gives 0x285e and the store writes 0x18. So at most
one of the two can match the hardware.

Tested

Tested: the probe's translator mode (24 cases, all run), --self-test and tests/test_buffer_swizzle_probe.py pass.
Not run on hardware: this machine has only an RDNA3 GPU (RX 7900 XTX), whose V# swizzle fields differ from RDNA2's.
No game files.
The branch is merged with main 0c46fa1, where #1864 (buffer_store_short) has landed. Measuring it and fixing the
translator is claimed separately as SHADER-1137.

AI-assisted: yes (Claude)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No new translator rule in this PR.)

LouisRiverstone and others added 9 commits November 23, 2026 01:46
buffer_load_{u,s}byte_d16[_hi], buffer_load_short_d16[_hi] and
buffer_store_byte/short[_d16_hi] (BUFFER_SUB16): one 16-bit half of vdata
is loaded or stored, the other kept; bounds checked at the access's own
size; stores merge each byte with atomic and/or. The plain
buffer_load_{u,s}byte / {u,s}short are main's buffer_load_sub; the tests
check them too. Fixes Box16Rehydration's buffer_store_short.
@caua-an asked on ItsNotRexed#1864 for a dedicated GPU fixture. Lane 0 seeds three
dwords and loads into a register holding 0xBEEF1234, so each of the six d16
loads (ubyte/sbyte/short, low and high half) shows the half it writes, the
half it keeps and sbyte's sign extension; buffer_store_byte_d16_hi and
buffer_store_short_d16_hi take bits 23:16 / 31:16. Passes on llvmpipe with
LLVM 21 and 23; main's translator can't translate it. Registered in check.py,
run_gpu_tests.py and regen_fixtures.py; tests/semantic/
test_buffer_sub16_fixture.py runs it on the CPU. docs/design.md row points
at it.
@tylerstraub ran the new fixture on an NVIDIA RTX 5090 (595.99.02, Linux): all
eight words. The row named llvmpipe only.
@YaBulochka on ItsNotRexed#1864: cs_w32_buffer_sub16 has the _d16_hi stores but not the
plain buffer_store_byte / buffer_store_short, and docs/embedded_shaders.md
names plain buffer_store_short as Box16Rehydration's blocker. Lane 0 seeds six
dwords, stores bytes and shorts into them (one short at byte 3, whose high byte
lands in the next dword; a byte and a short whose data has high bits set) and
reads them back, also through buffer_load_ubyte / buffer_load_sshort. Passes on
llvmpipe with LLVM 21 and 23; main's translator can't translate it. CPU test
tests/semantic/test_buffer_store_sub_fixture.py; docs/design.md row updated.
…e base pointer (Apple M4)

@sovljanskii on ItsNotRexed#1864: on an Apple M4 (MoltenVK 1.4.2) cs_w32_buffer_store_sub
read 0 for every buffer_load_{u,s}short at byte 2 or 3 of a dword. The 16-bit
path loaded its second dword through a second OpConvertUToPtr of the same host
address (a run-time V#), which Apple's compiler mishandles; indexing the same
PSB array by idx1 * index_stride (step = 4 * index_stride) reads right and keeps
the scratch-swizzle layout. Patch by @sovljanskii, tested by them on the M4
(154/219, the only change cs_w32_buffer_store_sub FAIL -> PASS). Here: buffer
semantic tests and swizzle suites OK, llvmpipe 147/219 0 failed, full semantic
suite only main's known failures.
# Conflicts:
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
#	tests/semantic/regen_fixtures.py
# Conflicts:
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
#	tests/semantic/regen_fixtures.py
…atch swizzle

Depends on: ItsNotRexed#1864 (buffer_store_short).

A buffer_load_ushort or buffer_store_short at byte 3 of a dword also reaches one byte of the next dword. In scratch
swizzle (SWIZZLE_ENABLE=1, ADD_TID_ENABLE=1, idxen=0) the translator now answers that two ways:

- buffer_load_sub (main) takes the second byte from the next swizzled dword, +4*IS bytes on, as multi-dword raw
  accesses step (measured on gfx1036, SHADER-343);
- buffer_store_short (ItsNotRexed#1864) writes it to the linear next dword, +4 bytes on, which in that mode belongs to the next
  lane.

Neither has been measured natively. Two cases in the multi_dword_stepping group answer both on an RDNA2 GPU with
`python -I tools/buffer_swizzle_probe.py --oracle both --group multi_dword_stepping`:

- scratch_swz_load_ushort_cross (IS=8, lane 2): 0x285e if the second byte steps +4*IS, 0x0c5e if linear;
- scratch_swz_store_short_cross (IS=16, lane 5, stride 16 so both dwords are in range): the high byte lands in
  dword 0x54 (+4*IS) or 0x18 (linear).

Translator side today (CPU, wave32 and wave64 alike): the load gives 0x285e and the store writes 0x18. So at most
one of the two can match the hardware.

Tested: the probe's translator mode (24 cases, all run), --self-test and tests/test_buffer_swizzle_probe.py pass.
Not run on hardware: this machine has only an RDNA3 GPU (RX 7900 XTX), whose V# swizzle fields differ from RDNA2's.
No game files.

AI-assisted (Claude).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ItsNotRexed#1864 is on main now, so this branch carries only the two probe cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rojasruiz

Copy link
Copy Markdown

Checked 5bfd5d7 merged onto main 5cf3daf (clean merge) on Linux 7.2.15, CPython 3.14: the translator side passes and matches the PR's description. The hardware measurement is still open: my GPU is an NVIDIA RTX 3080, so there is no --oracle hw result here, and this still needs someone with an RDNA2 card.

  • --self-test: 24 cases across 8 groups translated and ran on CPU OK.
  • --oracle translator --group multi_dword_stepping: 8 cases: 8 match, 0 known divergence, 0 unexpected mismatch, 0 wave32/64 diff. The two new cases give what the PR says the translator does today:
    • scratch_swz_load_ushort_cross: 0x0000285e (second byte from +4*IS);
    • scratch_swz_store_short_cross: 0x34ed0014 0x5eed0012 0x5eed0054 0x5eed0058. The high byte 0x12 lands in the linear next dword (seed 0x5eed0018), and the +4*IS dword 0x5eed0054 is untouched.
  • tests/test_buffer_swizzle_probe.py: 8 passed. tests/semantic (443 files / 5,889 tests) and run_gpu_tests.py (190/239): both identical to main. check_no_game_data.py on the file: clean.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants