Skip to content

rdna2spirv: out-of-range typed buffer loads keep DST_SEL constant 1 (SHADER-429) - #2486

Closed
LloydNicholson wants to merge 1 commit into
ItsNotRexed:mainfrom
LloydNicholson:shader/oob-dst-sel-one
Closed

LloydNicholson wants to merge 1 commit into
ItsNotRexed:mainfrom
LloydNicholson:shader/oob-dst-sel-one

Conversation

@LloydNicholson

@LloydNicholson LloydNicholson commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as SHADER-429: #2300 (comment)

What and why

The problem. @timelery measured this on RDNA2 (gfx1036, wave32 and wave64), in the finding:

  • When a typed MUBUF load (buffer_load_format_*, d16 included) is out of range, the raw data channels read 0, but DST_SEL still applies.
  • So a channel the V# selects as constant 1 reads 1: integer 1 for UINT/SINT formats, 1.0f for float and norm formats, f16 1.0 for d16.
  • Gen.buffer_load_format instead ended each channel with OpSelect in_bounds result 0 (tools/rdna2spirv.py:1990 on 4947579; the change is e043ced on main 77444fa), which turned that 1 into 0.

The fix (tools/rdna2spirv.py): the final select is removed.

  • When the load is skipped, the raw words are already 0: the OpPhi takes 0 from the skipped branch, and every supported format decodes all-zero words to 0. The swizzled result is therefore 0 for the data channels and 1 for a constant-1 channel.
  • Unchanged: in-range loads; MTBUF (tbuffer_load_format_*), whose selectors come from the instruction as X000…XYZW, have no constant 1 and still read 0 out of range or with an INVALID V# format (the existing test_tbuffer_8_uint_oob_and_invalid_vsharp_format); and the MUBUF in-range DST_SEL=1 rule from SHADER-86.

Docs: a contract row in docs/design.md gives the rule and how it was confirmed.

Tested

AI-assisted (Claude Code). Nobara Linux, RX 9060 XT (RDNA4, GFX1200), RADV Mesa 27.0.0-devel, llvm-mc 22.1.8, SPIRV-Tools 2026.1, on main 77444fa (rebased from 4947579).

  • tests/semantic/test_buffer_load_sub.py: four new cases.
    • Three are out of range (RAW bounds, 4 records, element at byte 4):
      • 8_UINT with DST_SEL (X, 0, 1, 1) reads [0, 0, 1, 1];
      • 32_FLOAT with (1, X, 0, W) reads [1.0f, 0, 0, 0];
      • d16_xy with (1, X) reads 0x00003C00.
    • The fourth is the same d16 load in range, as a control.
    • Red, then green: with main's rdna2spirv.py, the three out-of-range cases fail and the control passes. With the change, all 13 tests in the file pass.
  • tests/semantic: 2,571 tests. With current SPIRV-Tools first on PATH, all pass apart from the suite's own skips.
    • With an old 2024 spirv-val first on PATH, 5 SPIR-V-tools checks fail (test_fma_khr, test_image_coherent). The same 5 fail the same way on main, so they come from that machine's tools, not this change.
  • python -m pytest tests/test_translate.py: 541 passed, 4 skipped.
  • scripts/run_gpu_tests.py: 175/189 passed, 14 skipped, 0 failed after the rebase. Before it, the result was the same with and without the change (170/185, 15 skipped). No test in that suite loads out of range with DST_SEL=1.
  • Other checks: compileall, tests/test_docs_links.py and tests/test_text_write_line_endings.py pass.

Not tested: a native hardware measurement of my own. The rule rests on @timelery's gfx1036 run. An RDNA1/gfx1013-class measurement, the console's own GPU family, would be worth adding.

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.

🤖 Generated with Claude Code

@duudiis

duudiis commented Nov 22, 2026

Copy link
Copy Markdown

Independent comparison of 660342f and #2467 at e701a6f on Windows 11 build 26300, RTX 5070 driver 621.24.

  • The same mixed in-/out-of-range probe from rdna2spirv: preserve DST_SEL=1 on out-of-bounds buffer_load_format (SHADER-429) #2467 matched all 256 lanes through this PR. The fixture covers four formats and full-width and D16 destinations in each wave.
  • A separate compute sweep put each of the 128 possible V# FORMAT field values in its own 32-lane workgroup (including all 41 supported decoders), with zero records and poisoned backing data. It checked both destination widths and DST_SEL=(X,0,1,1) for every lane. Expected outputs matched for both PRs, and the entire readback was byte-identical between them. Both modules passed Vulkan 1.2 validation.
  • All 45 test_buffer_load_*.py tests passed here, including the fixed-format MTBUF checks.

The GPU results support the removal of the redundant output gate on the current format table. This PR also adds the SHADER-429 contract row. Synthetic inputs only. AI-assisted review.

@dac0129

dac0129 commented Nov 22, 2026

Copy link
Copy Markdown

Tested commit 660342f3 on real dual-GPU silicon: pass.

Environment:

  • CPU: AMD Ryzen 7 7800X3D (8C/16T)
  • OS: Windows 11 Build 26200.0 (x64)
  • dGPU: NVIDIA GeForce RTX 4080 (Driver 617.42, Vulkan 1.4.351)
  • iGPU: AMD Radeon(TM) Graphics (RDNA2, Driver 32.0.21045.29003, Vulkan 1.4.315)

Test verification:

  • python -m compileall -q make_game.py tools tests: pass (0 errors)
  • tests/semantic/test_buffer_load_sub.py: 13 passed (OK)
    • Verified out-of-range integer, float, and d16 loads preserving DST_SEL constant 1 (0x1, 0x3F800000, 0x3C00).
  • Buffer regression suite (*buffer*): 76 passed (OK)
  • Wave64 regression suite (test_wave64*): 109 passed (OK)

AI-assisted.

@nonverifiedperson

Copy link
Copy Markdown
Contributor

Independent native check on RDNA2, against this PR's translator (660342f3) and its base (49475796).

Hardware: Radeon iGPU, gfx1036 (Ryzen 7 9800X3D), AMD driver 32.0.13036.4, Windows 10 22H2, through tools/hw_oracle.

Cases (480 in total): one lane, with the V# built in SGPRs (NUM_RECORDS = 16 bytes, OOB_SELECT raw), over every combination of:

  • 8 formats: 8_UINT, 8_SINT, 16_UNORM, 32_UINT, 32_FLOAT, 16_16_FLOAT, 8_8_8_8_UNORM and 32_32_32_32_FLOAT.
  • 6 DST_SEL patterns: XYZW, 1X0W, X011, 1111, 01WX and WZYX.
  • 5 loads: buffer_load_format_x, _xyzw, _d16_xy, _d16_xyzw, and tbuffer_load_format_xyzw with the matching format.
  • 2 offsets: 0 (in range) and 64 (out of range).

The destination VGPRs start as 0xdeadbeef, so a register the load doesn't write shows up. The translator side runs the same body through run_cs from tests/semantic/test_buffer_load_sub.py.

match hardware out-of-range misses
this PR 477 / 480 0 / 240
base 373 / 480 104 / 240
  • wave32 and wave64 gave the same words in all 480 cases, with 0 hardware errors.
  • Out of range, every constant-1 channel reads 1 for UINT/SINT, 1.0f for float/norm and 0x3c00 in a d16 half. The data channels read 0, and the PR gets all of them right.
  • Out of range, tbuffer_load_format_xyzw reads 0 in all four channels whatever DST_SEL is set to, as the PR's design.md row says.
  • python -m unittest discover -s tests/semantic on the PR: 2,571 tests OK (3 skipped).

The 3 remaining misses are not from this PR. They show up the same way on the base. A d16 load of a 32_FLOAT channel holding 0xFE00CDAB (about -4.3e37) gives 0xfbff (-65504) on the hardware, but 0xfc00 (-inf) from the translator. A separate 4-value probe shows that d16 narrowing of f32 channels rounds toward zero on gfx1036. I'll post that as a finding in the coordination issue; it is outside this PR.

No game files. AI-assisted (Claude Code).

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 660342f on Windows 11 (26200) on both GPUs of a two-GPU PC: pass. I ran this PR's scripts/run_gpu_tests.py and tools/ (llvm-mc 21.1.8, SPIRV-Tools from the Vulkan SDK tools) against a fresh runtime build of main 4eb6155.

  • AMD Radeon RDNA2 iGPU (gfx1036), AMD Windows driver 32.0.21045.16010, native wave64: 170/185 passed, 15 skipped, 0 failed.
  • NVIDIA GeForce RTX 5080 (616.92) with LEONIDA_W64_EMULATE=1: 170/185 passed, 15 skipped, 0 failed.
  • tests/semantic/test_buffer_load_sub.py: 13/13 OK.

No game files. AI-assisted check (Claude Code), Vonsek3.

@JRamos1993

Copy link
Copy Markdown
Contributor

Tested 660342f on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:

  • scripts/run_gpu_tests.py: 139/185 passed, 46 skipped, 0 failed. main 4947579 gives 139/185, 46 skipped, 0 failed. All 190 test shaders translate and pass spirv-val.
  • tests/semantic/test_buffer_load_sub.py: ran 13 tests in 1.267s; OK.

AI-assisted (Claude Code).

…SHADER-429)

An out-of-range buffer_load_format_* (d16 included) skips the load, so its raw channels read 0, but DST_SEL still
applies: a channel selected as constant 1 reads integer 1, 1.0f or f16 1.0, as @timelery measured on gfx1036 in
wave32 and wave64. Gen.buffer_load_format zeroed the swizzled result instead, dropping the 1. The raw words are
already 0 when the load is skipped and every format decodes them to 0, so the final select is removed; MTBUF's
identity selectors have no constant 1 and still read 0 out of range or with an INVALID V# format.

tests/semantic/test_buffer_load_sub.py adds integer, float and d16 out-of-range cases (all three fail without the
change) and the in-range d16 one; docs/design.md has the contract row.

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

Copy link
Copy Markdown
Owner

Closing as a duplicate: preserving DST_SEL=1 on out-of-bounds typed buffer loads (SHADER-429) landed on main via #2467 and #2722. Thanks!

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.

7 participants