Skip to content

rdna2spirv: a 16-bit MUBUF store at byte 3 in scratch swizzle reaches the next swizzled dword (measured, gfx1036) - #7348

Open
sperm wants to merge 1 commit into
ItsNotRexed:mainfrom
sperm:shader-store-short-swizzle-step
Open

sperm wants to merge 1 commit into
ItsNotRexed:mainfrom
sperm:shader-store-short-swizzle-step

Conversation

@sperm

@sperm sperm commented Nov 23, 2026

Copy link
Copy Markdown

Claim: #7049 comment, the hardware side of @iLucasRT's scratch-swizzle finding. Their probe cases are their own claim and branch (iLucasRT:buffer-sub16-swizzle-probe). This PR doesn't include them, so it doesn't conflict with their PR.

What and why

In scratch swizzle (SWIZZLE_ENABLE=1, idxen=0, ADD_TID_ENABLE=1), a 16-bit MUBUF access at byte 3 of a lane's dword reaches one byte of the next dword. The translator took two different views of which dword that is:

Cause: buffer_sub asked buffer_address for a typed element (elem="fmt", format 1 or 7). For 1 or 2 bytes that gives the same bounds check as elem=nbytes. But a typed element never gets the scratch-swizzle step, so the second byte stepped linearly. buffer_sub's own docstring already said "in a swizzled buffer the next dword is step bytes on". It now passes elem=nbytes.

Measured (gfx1036, RDNA2)

tools/buffer_swizzle_probe.py --oracle both from @iLucasRT's branch, run through tools/hw_oracle (DRM backend) on the Raphael iGPU (1002:13c0, gfx1036, compute engine 10.0), wave32 and wave64:

case (byte 3, scratch swizzle) hardware translator before translator after
buffer_load_ushort (IS 8, lane 2) second byte from +4×IS +4×IS ✓ +4×IS ✓
buffer_store_short (IS 16, lane 5) high byte to +4×IS (0x54); 0x18 untouched linear 0x18 ✗ +4×IS ✓
buffer_load_short_d16 (a local case, same shape as the ushort one; not pushed) 0xabcd285e: +4×IS, high half kept 0xabcd0c5e linear ✗ +4×IS ✓

Every probe group with the fix: 22 of 24 match, no wave32/64 difference. The two cases left are typed_and_atomic_x2/scratch_swz_fmt16_suppressed and scratch_swz_mtbuf_atomic_x2_and_4b_ctrl. They mismatch the same way on main, so this PR doesn't touch them. In the second, even the 4-byte typed control reads back the output fill (0xdead0000) on hardware, so the case may not be storing at all. That looks like a probe question rather than a translator one; I'll post it as a finding.

Tested

Linux, Python 3.14.10, main 8575d36ed.

  • tests/semantic/test_buffer_sub_dword.py: new ScratchSwizzleCrossing, the measured case on the CPU for buffer_store_short, buffer_store_short_d16_hi, buffer_load_ushort and buffer_load_short_d16. 8 tests, OK.

  • Negative control: with main's translator, 3 of those subtests fail: both stores and the d16 load.

  • Full tests/semantic (5891 tests): the same two failures as main and nothing else. Those are test_image_atomics_guard and test_image_store_d16, already reported red on main by @dadsmallbuk1.

  • docs/design.md: the contract row now names the measurement. test_docs_design_rows passes. test_docs_links fails on main and here alike (the dev-tools.md anchor, @Unix-Epoch's finding).

  • No game data in this PR.

  • The changed rule's row in the docs/design.md contract table says how it was confirmed (a native gfx1036 measurement).

AI-assisted (Claude Code).

🤖 Generated with Claude Code

… the next swizzled dword (measured, gfx1036)

buffer_sub (the d16 loads and the 8/16-bit stores) asked buffer_address for a typed element (elem="fmt", format 1
or 7). That gives the same 1/2-byte bounds check as elem=nbytes, but a typed element gets no scratch-swizzle step,
so a buffer_store_short at byte 3 wrote its high byte to the linear next dword, the next lane's.

Measured natively on gfx1036 (RDNA2), wave32 and wave64, with @iLucasRT's tools/buffer_swizzle_probe.py cases: the
store's high byte lands in the next swizzled dword (+4*IS), as buffer_load_ushort's does, and a local
buffer_load_short_d16 case reads it from there too. buffer_sub now passes elem=nbytes, so it gets the step.

tests/semantic/test_buffer_sub_dword.py: the measured case on the CPU (lane 5, IS 16) for buffer_store_short,
buffer_store_short_d16_hi, buffer_load_ushort and buffer_load_short_d16. docs/design.md row updated.

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

@devnull34 devnull34 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified: passes all semantic and rdna2spirv CLI tests. Passing elem=nbytes in buffer_sub ensures raw buffer addressing returns the scratch swizzle step so 16-bit stores at byte 3 properly write the high byte into the next swizzled dword rather than linear adjacent lane memory.

@DeSunShine

Copy link
Copy Markdown
Contributor

Tested 1041c6bcd merged into main 6f58bd2c5 on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363, llvm-mc 23.1.6, Python 3.15: pass.

  • python -m pytest -q tests/semantic/test_buffer_sub_dword.py: 8 passed, 123 subtests passed.
  • python -I scripts/run_gpu_tests.py (native): 191/240 passed, 48 skipped, only FAIL is ms_wave_info_s3 (same counts and failure as plain main 6f58bd2c5).
  • LEONIDA_W64_EMULATE=1 python -I scripts/run_gpu_tests.py: 222/240 passed, 17 skipped, only FAIL is ms_wave_info_s3 (same as plain main).

AI-assisted (Claude Code).

@JRamos1993

JRamos1993 commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 1041c6b merged onto main 3d21852 on an RTX 5090 (driver 621.24), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:

  • scripts/run_gpu_tests.py: 192/241 passed, 48 skipped, 1 failed. main 3d21852 gives 192/241, 48 skipped, 1 failed (ms_wave_info_s3). All 247 test shaders translate and pass spirv-val.
  • Failures: the same as main's on this machine; the PR adds none.
  • tests/semantic/test_buffer_sub_dword.py: ran 8 tests in 1.971s; OK.

AI-assisted (Claude Code).

@Etr0p

Etr0p commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 1041c6b on Radeon 610M (gfx1036, RDNA2), AMD 26.11.2, Windows 11 26200: match. This is an independent native measurement on a second gfx1036, through the Windows driver path of tools/hw_oracle (#6393, applied locally, LEONIDA_HW_ARCH=gfx1036) rather than DRM.

The probe is tools/buffer_swizzle_probe.py --oracle both from @iLucasRT's #7353 (applied locally), wave32 and wave64:

translator result
this PR 24 cases: 24 match, 0 known divergence, 0 unexpected mismatch, 0 wave32/64 diff
main (tools/rdna2spirv.py from main, same probe) 24 cases: 23 match, 1 unexpected mismatch: scratch_swz_store_short_cross

The two crossing cases on hardware, the same in wave32 and wave64:

  • scratch_swz_load_ushort_cross: 0x285e. The second byte comes from +4×IS, and the translator gives the same before and after.
  • scratch_swz_store_short_cross: the readbacks are 0x34ed0014 0x5eed0018 0x5eed0012 0x5eed0058. So the high byte 0x12 lands at 0x54 (+4×IS), and 0x18 is untouched. main's translator gives 0x34ed0014 0x5eed0012 0x5eed0054 0x5eed0058 (linear 0x18), and this PR gives exactly the hardware words.

One difference from your DRM run: here typed_and_atomic_x2/scratch_swz_fmt16_suppressed and scratch_swz_mtbuf_atomic_x2_and_4b_ctrl match on both main and the PR. So the two leftover cases you saw are not reproduced through the Windows driver.

Semantic tests on this PR: python -I tests/semantic/test_buffer_sub_dword.py ran 8 tests, OK. Negative control (tools/rdna2spirv.py from the merge base, PR tests): FAILED (failures=3), buffer_store_short, buffer_store_short_d16_hi and buffer_load_short_d16, as the description says.

Synthetic values only, no game files. 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.

5 participants