Repository navigation
fix(translator): skip image atomics outside the image, return 0 with glc (EGEN-IMGATOMIC-OOB) - #5059
evilclanker9000 wants to merge 2 commits into
Conversation
…th glc (EGEN-IMGATOMIC-OOB) RDNA2 (gfx1036, measured with tools/hw_oracle) leaves memory untouched and returns 0 with glc for an image_atomic_* at x/y past the edge, at -1, or at the row pitch. The translation built OpImageTexelPointer from the raw coordinate, which is undefined in Vulkan. Every 2D/3D image atomic is now guarded by an unsigned coordinate < OpImageQuerySize test.
|
Tested 2025cb3 on AMD Radeon 610M (RADV RAPHAEL_MENDOCINO, subgroup 32..64), Mesa 26.2.6, CachyOS Linux, LEONIDA_VK_DEVICE=RADV: pass.
The three imgatomic fixtures are the existing in-range checks; the out-of-bounds coordinates (x = width, -1, height) were not run on a GPU here, only in the new semantic test. AI-assisted. |
|
Independent check — pass (CPU only, no game files). Environment: Windows 11, CPython 3.15.2.
A whole-corpus translated/spirv-val count is still the usual gate for a rule change; a real-shader disasm corpus exists here and a slice check can follow if reviewers want it. AI-assisted (Devin). |
|
Tested 2025cb3 on native Windows 11 build 26200, RTX 4080 (621.01 / 32.0.16.2101), MSVC 19.44 Release, Khronos validation 1.4.357. The three stock imgatomic fixtures passed. I also exercised the new bounds behavior on the GPU with one synthetic vk_store_test dispatch over seeded 2D and 3D images.
The module passed spirv-val. Before GPU execution I verified that all four texel-pointer blocks were behind the active-lane check and the unsigned coordinate check for every axis. Both the new bounds semantic test and the existing image-atomic semantic tests passed. AI-assisted; synthetic inputs only. |
|
Independent hardware review of Note on overlap with #5077: This PR and #5077 (opened later by @milas6669) address the exact same finding (#4933) and modify the same Environment: Windows 11 x64, Python 3.12.10, SPIRV-Tools v2026.4 (Vulkan SDK 1.4.363.0), Results:
All tested semantic and in-range GPU checks pass; out-of-bounds coordinates are verified structurally in the new semantic test (not executed on GPU by the stock AI-assisted (Gemini 4 Neon). |
|
Tested 2025cb3 on Intel UHD 630 (CFL GT2, subgroup 8..32), Mesa 25.2.8 ANV, Ubuntu 24.04, LEONIDA_VK_DEVICE=Intel: pass.
The full tests/semantic suite and the out-of-bounds coordinates on a GPU were not run here. AI-assisted. |
|
Tested
|
|
Update: the 3D case is now measured too, so the note "not measured on 3D" no longer applies. On gfx1036 (same driver), a 64x1x4 R32_UINT linear volume with 256-byte slices: image_load, image_store and image_atomic (umax/add/cmpswap) with x = 64, y = 1, z = 4 or z = -1 left every seeded word unchanged, and a load or a glc atomic returned 0; the in-range controls worked. |
|
Correction to my comment above: the docs commit I mentioned has not been pushed yet; my push was blocked in this environment. The 3D measurement itself stands (it is in the comment), and the matching |
# Conflicts: # docs/design.md
Claimed in the coordination issue as: EGEN-IMGATOMIC-OOB (finding and claim: #4933 (comment))
What and why
On RDNA2 an
image_atomic_*whose texel coordinate is outside the image leaves memory untouched and returns 0 withglc. The translation builtOpImageTexelPointerfrom the raw coordinates; an out-of-range texel pointer is undefined in Vulkan, so an atomic could land in row padding or in another texel.Every 2D and 3D
image_atomic_*(add/sub/and/or/xor/smin/smax/umin/umax/swap/inc/dec/fmin/fmax/cmpswap/fcmpswap) now runs only for active lanes whose coordinates are< OpImageQuerySize(unsigned per axis, so -1 is out too). Withglca lane that skipped gets 0 through anOpPhi; an inactive lane keepsvdataas before. The plain and cmpswap paths now shareemit_image_atomic; the unused "neutral value" column ofIMG_ATOMICSis gone.Measurement (gfx1036, Windows driver 32.0.21045.16010,
tools/hw_oracle, linear 4x4 R32_UINT T#, every word of the image, its row padding and the bytes after it seeded): umax/umin/or/add/swap/cmpswap at x = width, x = -1, y = height, y = -1, x = row pitch, x = 1000 and (width, height) changed nothing and returned 0; in-range controls updated the texel and returned the old value.Tested
python -I tests/semantic/test_image_atomic_bounds.py(new): before the change 64 of 64 op/dim/glc combinations fail ("no OpImageQuerySize of the atomic's image"); after, OK.test_image_atomics_32,test_fspx_rules: OK before and after.spirv-as/spirv-val(vulkan1.3) on all 16 ops x 2D/3D x glc/no glc, plain and under--wave64-emulate: 128/128 valid.python -m unittest discover -s tests/semantic: the same 6 failures with and without this change (test_loop_ballot_barrier3 FAIL + 2 ERROR,test_vcmp16_opsel.test_spirv_val_compliance1 ERROR; checked on a clean export ofmain).AI-assisted: yes
Notes
docs/design.md).image_storehas the same undefined out-of-range case forOpImageWrite; I left it for a separate PR.Checklist
docs/design.md, with how it was confirmed.