Repository navigation
translator: preserve MUBUF DST_SEL=1 on out-of-bounds typed buffer loads (SHADER-429) - #2722
Conversation
…ads (SHADER-429)
On RDNA2 hardware (gfx1036, 746 native kernels via tools/hw_oracle across wave32
and wave64), out-of-bounds MUBUF buffer_load_format_{x,xy,xyz,xyzw} and
buffer_load_format_d16_{x,xy,xyz,xyzw} skip memory access and decode raw data
channels (DST_SEL 4..7) as 0 while V# DST_SEL still runs: DST_SEL=1 yields
1.0f (0x3F800000, d16 0x3C00) iff V# FORMAT[6:0] is a valid float, normalized,
or scaled code (1..77 ending in _UNORM/_SNORM/_USCALED/_SSCALED/_FLOAT), and
integer 1 (0x00000001, d16 0x0001) for UINT/SINT, INVALID (0), and reserved
codes (78..127). MTBUF tbuffer_load_format_* ignores V# DST_SEL and returns 0
in addressed channels when OOB or V# FORMAT=0.
Remove the post-swizzle in_b clamp in Gen.buffer_load_format and classify
float vs integer DST_SEL=1 from the 7-bit GFX10 format table.
AI-assisted.
|
Independent Vulkan check of The same program failed 4/4 representative controls on base |
|
Tested on Linux (WSL2 Ubuntu), Python 3.10.12, CPU only: pass. With upstream/main merged (clean), tests/semantic/test_buffer_oob_dst_sel.py runs 5 tests, OK. Negative control: restoring tools/rdna2spirv.py to upstream/main makes all 5 fail (177 subtest failures). I rebuilt the float-format mask from tools/gfx10_formats.json: 49 codes in 1..77, and the 28 excluded codes are exactly the UINT/SINT ones, matching the comment. Trial merges: clean with #2711 (full tests/semantic with both merged: 2574 tests OK, 3 skipped), but #2710 conflicts in docs/design.md only (two rows added at the same spot in the contract table; keep both). |
|
Reviewed head
LGTM. AI-assisted review. |
|
Tested 10e310f on AMD Radeon RX 9070 XT (RADV GFX1201) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.
No game files. AI-assisted. |
|
Tested 10e310f on NVIDIA GeForce RTX 3070 (Ampere, subgroup 32..32), driver 610.57.04 (Vulkan 1.4.341), Debian 13 (kernel 6.12.115): pass, no regression. A hardware GPU next to the llvmpipe and CPU-only runs above. Base is
The AI-assisted: yes |
|
Tested
Tools: llvm-mc 21.1.8 with AMDGPU target, SPIRV-Tools 2026.1, GCC 13.3.0, Python 3.12.3. No code was edited or pushed; only synthetic fixtures were used. AI-assisted. |
|
Corpus run of
AI-assisted (Claude Code). Counts only; nothing from the game files is included. |
Summary (
SHADER-429)Claim: #2300 (comment)
Fixes out-of-bounds MUBUF typed buffer loads (
buffer_load_format_{x,xy,xyz,xyzw}andbuffer_load_format_d16_{x,xy,xyz,xyzw}) intools/rdna2spirv.py(Gen.buffer_load_format):gfx1036): When a MUBUF typed load is out of bounds (OOB_SELECT0–3,num_records == 0, partial-element spill, or swizzled OOB), memory is not accessed and raw data channels (DST_SEL4..7) read0, while the V#DST_SELswizzle still runs:DST_SEL = 0yields0.DST_SEL = 1yields1.0f(0x3F800000,d160x3C00) iffV#.FORMAT[6:0]is a valid float, normalized, or scaled buffer format (1..77ending in_UNORM,_SNORM,_USCALED,_SSCALED, or_FLOATintools/gfx10_formats.json), and integer1(0x00000001,d160x0001) forUINT/SINT,INVALID(0), and reserved codes (78..127).d16_xandd16_xyzpreserve the unaddressed upper 16 bits of the final destination VGPR on out-of-bounds loads.tbuffer_load_format_*overridesd3with identity selectors (4..7/0), so both out-of-bounds andV#.FORMAT = 0loads continue to return0in every addressed channel.OpSelect %uint {in_b} {r} 0clamp inGen.buffer_load_format(since out-of-boundswordsare already0via the guardedOpPhi, making decoded data channelscomps[0..3] == 0), and classifies float vs. integerDST_SEL=1from_FLOAT_FMT_MASKSover the 7-bit GFX10 format table.docs/design.mdand addstests/semantic/test_buffer_oob_dst_sel.py.Testing
AMD Radeon(TM) Graphics,gfx1036, Windows 11, driver32.0.21042.62):746native kernels viatools/hw_oracle(245wave32 +245wave64 across all41Gen.FORMATSforxyzw,d16_xyzw,d16_xyz,d16_x,OOB_SELECT0–3, partial-element spill, swizzled OOB,tbuffer_load_format_*OOB/FORMAT=0, and inactiveEXEClanes, plus128buffer_load_format_x+128buffer_load_format_d16_xkernels sweeping all1287-bitFORMATcodes0..127) —0mismatches.NVIDIA GeForce RTX 5090, driver32.0.16.1088;AMD Radeon(TM) Graphicsgfx1036, driver32.0.21042.62):1287-bitFORMATcodes acrossxyzw,d16_xyzw,d16_xyz, andd16_xviavk_compute_test(1,152checked words per GPU,0mismatches on both GPUs).scripts/run_gpu_tests.pybuffer suites (cs_fmt_1010102,cs_fmt_sint32,cs_fmt_xy_xyz,cs_oob_select,cs_oob_tail,cs_bounds,cs_buf_swizzle,cs_buf_tail) —8/8passed on both GPUs.spirv-val/ fuzzer tests:python -I tests/semantic/test_buffer_oob_dst_sel.py -v(5/5passed, includingSPIRV-Tools 2026.3spirv-valon native wave64 and--wave64-emulate)python -m unittest discover -s tests/semantic -p "test_*buf*.py",test_*tbuffer*.py,test_value_semantics.py(112/112passed)python -I tools/mem_diff.py --self-test,python -I tools/mem_diff.py --programs 200 --seed 1, andpython -I tests/test_mem_diff.py(200/200programs matched,15/15unit tests passed)python -m compileall -q make_game.py tools testsAI-assisted.