Repository navigation
Conversation
…_get_resinfo Both bits allocate one extra 32-bit status dword after the data words, at vdata[data_count] (RDNA2 machine-readable ISA, TFE/LWE fields; AMD's ISA guides: 'a fetch can return a NACK, which causes a VGPR write into DST+1'; LLVM SIISelLowering.cpp adds the same dword for every image op, atomics included). The word is now written 0: it is non-zero only on a failed fetch of a partially resident texture or a clamped LOD, and the runtime binds whole images only. The status slot follows the dmask-sized data words (one, two for the dmask:0x3 form kept low-dword 32-bit, four for 0xf; after resinfo's packed result words), inside the atomic's if (active) guard so inactive lanes preserve it. The six extra atomics accept the data+status width with tfe/lwe now, cmpswap accepts v[0:2] with dmask:0x3; a cmpswap status with any other dmask is Unsupported (no layout any reference settles). Which bit a failure would set is not established by any cited reference and is not invented. tests/semantic/test_image_status_vgpr.py pins value and position for the nine standard ops (glc and non-glc), the six extra, cmpswap/fcmpswap with compare/sentinel operands intact, the dmask:0x3 high dword untouched, 3D and resinfo (2D, 2D array, packed dmask), against no-tfe/no-lwe controls whose marker survives, plus spirv-val (when on PATH) and unchanged rejections. docs/design.md gains the 'Image tfe / lwe status VGPR' row with how each bit was confirmed. AI-assisted (GLM-5.3)
Grimkeh
left a comment
There was a problem hiding this comment.
Independent Linux CPU review
What changed: rdna2spirv writes the tfe/lwe status VGPR of image_atomic_* and image_get_resinfo.
Checked: tests/semantic/test_image_status_vgpr.py — 23 passed, 3 skipped.
Looks correct; no game files. Overlap risk with other open rdna2spirv.py PRs (#8915 etc.) — rebase whichever lands second.
|
Tested
The agent checked the new Independent check (not the author). Run by an AI agent (DeepSeek V4.1 Flash) and re-run by the orchestrating session (Claude Code) before posting. |
wavehs
left a comment
There was a problem hiding this comment.
Read the whole change and checked the widths against LLVM 23.1.5 (gfx1030) and this repo's decoder. The tfe positions and the resinfo packing are right; the six extra atomics take the status offset from the wrong number, and the lwe gate rejects listings the project itself produces.
Verified good
llvm-mcassembles and disassembles exactly the widthsimage_status_writetargets fortfe:image_atomic_add v[0:1](dmask 0x1),v[0:2](dmask 0x3);image_atomic_swap v[0:1];image_atomic_cmpswap/fcmpswap v[0:2](dmask 0x3);image_get_resinfo v[0:1](dmask 0x1),v[0:2](dmask 0xa),v[0:4](dmask 0xf).python3 -I -m unittest discover -s tests/semantic -p 'test_image_status_vgpr.py': 15 tests pass on macOS arm64, including thespirv-valones, and the status store really is inside the{do}block.
1. The six extra atomics size the status from need_n, not from the dmask (tools/rdna2spirv.py:13295-13298, :13394)
need_n is the opcode's data-word count (1, or 2 for fcmpswap) and ignores the dmask, so it is the status slot only for dmask 0x1. With dmask 0x3, llvm-mc accepts image_atomic_swap v[0:2], … dmask:0x3 tfe (2 data + 1 status; v[0:1] fails with image data size does not match dmask and tfe). The n == need_n + 1 check therefore
- rejects the width a corpus listing can contain, and
- accepts
image_atomic_swap v[0:1], … dmask:0x3 tfe— whichllvm-mcrefuses — and writes the status intov1, that form's second data word, notv2(reproduced:OpStore %reg_v1 %c0withv2's marker left alone).
The second shape is reachable without hand-writing it: rdna2_decode._mimg_data_count prints v[0:1] for any atomic with dmask 0x3 because it never adds the tfe word, so a shader_disasm.py --backend python carve hands the translator exactly that. image_atomic_fcmpswap v[0:4], … dmask:0xf tfe (5 registers) is legal in llvm-mc and is rejected here, while its status slot would be v4.
Fix: take the data-word count from the dmask the way the nine standard ops do at :13490 (1 for 0x1, 2 for 0x3, 4 for 0xf), keep the low-dword behavior for the data itself, and use that number both for the n check and for image_status_write.
2. lwe alone loses the extra atomics and cmpswap (:13296, :13479)
llvm-mc puts no status dword in an lwe-only listing:
image_atomic_swap v0, v[4:5], s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm lwe # assembles
image_atomic_swap v[0:1], … unorm lwe # error: image data size does not match dmask and tfe
# disassembling the same bytes: image_atomic_swap v0, … unorm lwe
and rdna2_decode prints v0 too. Your check wants n == need_n + 1 (2, or 3 for cmpswap), so on this branch image_atomic_{swap,inc,dec,fmin,fmax} … lwe and image_atomic_cmpswap v[0:1] … dmask:0x3 lwe raise Unsupported, while main translates every one of them (checked on both heads). Unless a corpus count shows zero lwe-only atomics, that is a translation regression — and it contradicts the row's own premise that both bits allocate the word, which I agree with (your SIISelLowering.cpp citation is exact: parseTexFail sets IsTexFail for any non-zero texfailctrl, bit 0 tfe / bit 1 lwe, then NumVDataDwords += 1; AddMemOpInit says "Any MIMG instructions that use tfe or lwe require an initialization of the result register"). Accept n == data_words when lwe is set without tfe, still write the status at data_words, and add those two listing shapes to the test.
3. The row's rdna2_decode sentence is not true, and the decoder is missing the word (tools/rdna2_decode.py:394-405, new row in docs/design.md)
the GFX10 atomic width rule of
rdna2_decode._mimg_data_count, which llvm-mc's assembler and disassembler agree on
_mimg_data_count's atomic branch returns before the + (1 if tfe else 0), at both :401 and :405. For image_atomic_add … dmask:0x1 tfe, this repo prints v0 where llvm-mc prints v[0:1], from the same 8 bytes. shader_disasm.py --backend python is a real consumer, and with this PR's n checks that listing is now rejected instead of translated. Add the +1 to both returns (and a case to tests/test_rdna2_decode.py::test_image_atomic_data_width); the function has no lwe parameter, so if the decoder is to model the two-bit rule it needs one — otherwise say in the row that the decoder counts tfe only and that llvm-mc's disassembler still prints lwe-only one register short (that is the trap the offset logic has to live with).
AI-assisted. macOS 27.2.1 arm64, LLVM 23.1.5 (gfx1030), Python 3.15.2; synthetic listings only, no game files.
|
macOS arm64 verification (Apple M3 Pro) — the Tested PR head Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2,
+1 file / +15 tests over the baseline, no new failures ( What I could confirm as correct. The status position matches Finding: The PR treats the two bits as equivalent (
(each row measured by assembling every width and keeping the one that passes; anything else gives Two consequences, both reproduced:
Note that the tests cannot catch either one: they pass the Suggested fix. Make the width and the write depend on status = "tfe" in mods # llvm-mc allocates the status dword for tfe only (23.1.5, measured)If RDNA2 really does allocate a word for Second, smaller: the nine standard atomics never check Third, minor: Lastly, the binary path still disagrees. No extra No game files. AI-assisted. |
wavehs
left a comment
There was a problem hiding this comment.
Read the whole change and checked the widths against LLVM 23.1.5 (gfx1030) and this repo's decoder. The tfe positions and the resinfo packing are right; the six extra atomics take the status offset from the wrong number, and the lwe gate rejects listings the project itself produces.
Verified good
llvm-mcassembles and disassembles exactly the widthsimage_status_writetargets fortfe:image_atomic_add v[0:1](dmask 0x1),v[0:2](dmask 0x3);image_atomic_swap v[0:1];image_atomic_cmpswap/fcmpswap v[0:2](dmask 0x3);image_get_resinfo v[0:1](dmask 0x1),v[0:2](dmask 0xa),v[0:4](dmask 0xf).python3 -I -m unittest discover -s tests/semantic -p 'test_image_status_vgpr.py': 15 tests pass on macOS arm64, including thespirv-valones, and the status store really is inside the{do}block.
1. The six extra atomics size the status from need_n, not from the dmask (tools/rdna2spirv.py:13295-13298, :13394)
need_n is the opcode's data-word count (1, or 2 for fcmpswap) and ignores the dmask, so it is the status slot only for dmask 0x1. With dmask 0x3, llvm-mc accepts image_atomic_swap v[0:2], … dmask:0x3 tfe (2 data + 1 status; v[0:1] fails with image data size does not match dmask and tfe). The n == need_n + 1 check therefore
- rejects the width a corpus listing can contain, and
- accepts
image_atomic_swap v[0:1], … dmask:0x3 tfe— whichllvm-mcrefuses — and writes the status intov1, that form's second data word, notv2(reproduced:OpStore %reg_v1 %c0withv2's marker left alone).
The second shape is reachable without hand-writing it: rdna2_decode._mimg_data_count prints v[0:1] for any atomic with dmask 0x3 because it never adds the tfe word, so a shader_disasm.py --backend python carve hands the translator exactly that. image_atomic_fcmpswap v[0:4], … dmask:0xf tfe (5 registers) is legal in llvm-mc and is rejected here, while its status slot would be v4.
Fix: take the data-word count from the dmask the way the nine standard ops do at :13490 (1 for 0x1, 2 for 0x3, 4 for 0xf), keep the low-dword behavior for the data itself, and use that number both for the n check and for image_status_write.
2. lwe alone loses the extra atomics and cmpswap (:13296, :13479)
llvm-mc puts no status dword in an lwe-only listing:
image_atomic_swap v0, v[4:5], s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm lwe # assembles
image_atomic_swap v[0:1], … unorm lwe # error: image data size does not match dmask and tfe
# disassembling the same bytes: image_atomic_swap v0, … unorm lwe
and rdna2_decode prints v0 too. Your check wants n == need_n + 1 (2, or 3 for cmpswap), so on this branch image_atomic_{swap,inc,dec,fmin,fmax} … lwe and image_atomic_cmpswap v[0:1] … dmask:0x3 lwe raise Unsupported, while main translates every one of them (checked on both heads). Unless a corpus count shows zero lwe-only atomics, that is a translation regression — and it contradicts the row's own premise that both bits allocate the word, which I agree with (your SIISelLowering.cpp citation is exact: parseTexFail sets IsTexFail for any non-zero texfailctrl, bit 0 tfe / bit 1 lwe, then NumVDataDwords += 1; AddMemOpInit says "Any MIMG instructions that use tfe or lwe require an initialization of the result register"). Accept n == data_words when lwe is set without tfe, still write the status at data_words, and add those two listing shapes to the test.
3. The row's rdna2_decode sentence is not true, and the decoder is missing the word (tools/rdna2_decode.py:394-405, new row in docs/design.md)
the GFX10 atomic width rule of
rdna2_decode._mimg_data_count, which llvm-mc's assembler and disassembler agree on
_mimg_data_count's atomic branch returns before the + (1 if tfe else 0), at both :401 and :405. For image_atomic_add … dmask:0x1 tfe, this repo prints v0 where llvm-mc prints v[0:1], from the same 8 bytes. shader_disasm.py --backend python is a real consumer, and with this PR's n checks that listing is now rejected instead of translated. Add the +1 to both returns (and a case to tests/test_rdna2_decode.py::test_image_atomic_data_width); the function has no lwe parameter, so if the decoder is to model the two-bit rule it needs one — otherwise say in the row that the decoder counts tfe only and that llvm-mc's disassembler still prints lwe-only one register short (that is the trap the offset logic has to live with).
AI-assisted. macOS 27.2.1 arm64, LLVM 23.1.5 (gfx1030), Python 3.15.2; synthetic listings only, no game files.
rdna2spirv: write the tfe/lwe status VGPR of image_atomic_* and image_get_resinfo
Fixes the wavehs finding (#8683 (comment)),
claimed as #8683 (comment).
Branch
image-status-vgpr, one commit offmain(867d922f0):6fdef2f80.Not pushed; local only.
What and why
image_atomic_*andimage_get_resinfoaccept thetfe/lwebits but never wrote the extra statusdword, so a shader that reads the status VGPR got the register's old value — a silent wrong
translation. Reproduced on a clean clone of
mainwith hand-written synthetic disassembly (no gamefiles, no GPU):
image_atomic_add v[0:1], v[2:3], s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe— translated,OpAtomicIAddemitted, no store intov1(the status dword).image_get_resinfo v[0:4], v4, s[4:11] dmask:0xf dim:SQ_RSRC_IMG_2D tfe— translated, writesv0..v3only, nothing intov4.lwe. By contrastimage_atomic_cmpswap v[0:2] … dmask:0x3 … tfewas refused(
image_atomic_cmpswap data, the width check) — the six extra atomics likewise refused thedata+status width by accident rather than by decision.
Semantics (what the references settle, and what they do not)
Established, and followed:
(the same package
docs/isa_coverage.mdpins, zip SHA-25682404f1126761b7877595b622afa7e1f311f2f41e89a3abe9aaf8ad045c082e2):TFE = "Texture Fail Enable (for partially resident textures)", LWE = "LOD Warning Enable (for
partially resident textures)" — fields of
ENC_MIMG, present onIMAGE_ATOMIC_*andIMAGE_GET_RESINFO. AMD's ISA guides: TFE "When set, a fetch can return a NACK, which causes aVGPR write into DST+1 (first GPR after all fetch-dest GPRs)".
SIISelLowering.cpp(release/21.x,AMDGPUImageIntrinsiclowering):NumVDataDwords += 1with texfail set, for every imageintrinsic — atomics included (
BaseOpcode->Atomic, 1 dword, 2 for the X2/dmask:0x3forms,4 for the 64-bit
dmask:0xfcmpswap). Verified first-hand:llvm-mc23.1.5(
-mcpu=gfx1030) assembles and disassemblesadd … dmask:0x1 glc tfeasv[0:1],cmpswap … dmask:0x3 glc tfeasv[0:2],cmpswap … dmask:0xf glc tfeasv[0:4],image_get_resinfo … dmask:0xf tfeasv[0:4]— the same widthstools/rdna2_decode._mimg_data_count's atomic branch sizes (decode-side follow-up rdna2_decode: an image atomic with tfe has one more data VGPR, the status dword #7732 isopen for the decoder's own tfe count).
fails or its LOD was clamped; the runtime binds whole images only, with the index-0 fallback
(no sparse binding anywhere in
runtime/src/vulkan_bindless.h), so no fetch fails — andimage_get_resinforeads no memory at all (ISA: "No memory access is performed"). This matcheswhat the sample/load/gather status PRs (rdna2spirv: write tfe/lwe status VGPR for image_sample* (SHADER-1266) #8471, rdna2spirv: write the tfe/lwe status VGPR after every image read (SHADER-1266) #8771, both open, unmerged) write for their ops,
including the shared
%c0constant rather than a newOpConstantin the function body.Not established, and not invented: which bit a failed fetch would set in the status word (the
machine-readable ISA carries only the field descriptions; the failure encoding is not in LLVM or
any guide this repo cites), and
lwe's LOD-warn bit for a resinfo (no sampler, no clamp — nothingdocuments a warn condition there). Both are written as their "nothing happened" value 0, with the
same reasoning as above, and the
docs/design.mdrow says so. No combination was refused onsemantic grounds except
cmpswap+tfewith a dmask other than0x3, where no referencesettles a data layout at all.
What changed
tools/rdna2spirv.py:Gen.image_status_write(vdata, data_words)— oneself.dststore ofself.cu(0)intovdata["r"] + data_words, with the references in its docstring.cmpswap(image_miscatomic branch): withtfe/lwe, the status is writteninside the existing
if (active)guard, after the atomic and anyglcwrite-back, at thedmask-sized data width (1, 2 for the
dmask:0x3form the translator keeps low-dword 32-bit, 4for
dmask:0xf); inactive lanes preserve their status VGPR.cmpswapnow acceptsv[0:2]/n=3withdmask:0x3; acmpswapstatus with any other dmask raisesUnsupported(op + " tfe dmask"); the 64-bitdmask:0xfcmpswap stays refused (n≠3).emit_image_atomic_extra): the operand-width check becomesneed_n + (1 if tfe/lwe else 0), so the data+status width is accepted, and the status iswritten at
vdata["r"] + need_n—cmpswap/fcmpswap's compare and sentinel operands areread from the first
need_nVGPRs and never clobbered.image_get_resinfo: after the dmask's packed result words, the status goes tovdata["r"] + out(out or 1: LLVM forces a dmask of0x1with texfail and no data bit, sothe status never lands on the first result word).
docs/design.md: newImage tfe / lwe status VGPR (atomics, resinfo)contract row with all of theabove and how each bit was confirmed. No GPU claim anywhere.
tests/semantic/test_image_status_vgpr.py(new, stdlib only): status value and position for thenine standard ops (
glcand non-glc, exact SPIR-V atomic opcodes hardcoded), the six extraatomics,
cmpswap/fcmpswapwith the comparand/sentinel registers left intact (and still theOpAtomicCompareExchangecomparand operands), thedmask:0x3form's high dword untouched,3D, and
image_get_resinfo(2D, 2D array, packeddmask:0xa), each against a no-tfe/no-lwecontrol whose marker (0xdeadbeef) survives;
spirv_mini_interp.check_structureCFG validation andspirv-as/spirv-val(when on PATH); and the unchanged rejections (cmpswapdmask:0x1/0xfwith tfe, wrong widths, the no-tfe width rejections,
d16).Tested (CachyOS Linux, CPython 3.15, CPU only; no game files, no GPU, no LLVM needed by the tests)
main:python -I <repro>(script in the session log): both forms translated with nostatus store.
python -I tests/semantic/test_image_status_vgpr.py→ 15 tests OK(spirv-as/spirv-val present and passing on this host).
test_image_atomics_32.pyOK,test_image_gather4_variants.pyOK,test_image_store_dmask.pyOK.python -I scripts/run_semantic_tests.py tests/semantic→448 files, 5972 tests, 2 files failed:
test_image_atomics_guard(47 failures),test_image_store_d16(1 failure). Both are pre-existing onmain: verified bygit stash→ same two files, same counts (47/1) →git stash pop. The finding's second half(they fail under CPython 3.15; CI pins 3.12) is unrelated to this change.
dmask:0x1/glc, adddmask:0x3,cmpswap, fcmpswap 3D, resinfo 2D and 2D-array) translated on stashed
mainand on the branch:SHA-256 digests of the SPIR-V identical.
python -m compileall -q make_game.py tools testsclean;python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_image_status_vgpr.py docs/design.mdexits 0.tools/semantic_mutants.py): the new file kills 6/6 table-entry mutants forimage_atomic_add/image_atomic_umax(hardcoded opcode map) and the comparand-operand mutantof
cmpswap; a hand-made status-value mutation (cu(0)→cu(1)inimage_status_write)fails 40 assertions. Surviving mutants are the atomic value/CAS internals and scope/semantics
constants — not observable by any CPU test (the interpreter has no image memory; those are the
GPU fixtures' territory) and none of them is in the new lines.
Relation to open work
No
Depends on:— this is complete onmain. Overlapping-but-orthogonal open PRs: #8471/#8771(sample/load/gather status VGPR — unmerged; this PR follows their
%c0convention so a mergeorder conflict is a trivial rename if theirs lands first) and #7732 (the decoder's tfe data
count — the translator reads llvm-mc listings whose ranges already include the status dword, so
this PR does not depend on it either way).
AI-assisted (GLM-5.3).
hand-written fixtures only;
check_no_game_data.pyrun on every changed file)main(counts verified against a stash)docs/design.mdwith how it was confirmed