Skip to content

rdna2spirv: write the tfe/lwe status VGPR of image_atomic_* and image_get_resinfo - #8941

Open
pyotrkk wants to merge 1 commit into
ItsNotRexed:mainfrom
pyotrkk:image-status-vgpr
Open

pyotrkk wants to merge 1 commit into
ItsNotRexed:mainfrom
pyotrkk:image-status-vgpr

Conversation

@pyotrkk

@pyotrkk pyotrkk commented Nov 23, 2026

Copy link
Copy Markdown

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 off main (867d922f0): 6fdef2f80.
Not pushed; local only.

What and why

image_atomic_* and image_get_resinfo accept the tfe/lwe bits but never wrote the extra status
dword, so a shader that reads the status VGPR got the register's old value — a silent wrong
translation. Reproduced on a clean clone of main with hand-written synthetic disassembly (no game
files, no GPU):

  • image_atomic_add v[0:1], v[2:3], s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D unorm tfe — translated,
    OpAtomicIAdd emitted, no store into v1 (the status dword).
  • image_get_resinfo v[0:4], v4, s[4:11] dmask:0xf dim:SQ_RSRC_IMG_2D tfe — translated, writes
    v0..v3 only, nothing into v4.
  • Same for lwe. By contrast image_atomic_cmpswap v[0:2] … dmask:0x3 … tfe was refused
    (image_atomic_cmpswap data, the width check) — the six extra atomics likewise refused the
    data+status width by accident rather than by decision.

Semantics (what the references settle, and what they do not)

Established, and followed:

  • Both bits allocate one status VGPR after the data words. AMD's machine-readable RDNA2 ISA
    (the same package docs/isa_coverage.md pins, zip SHA-256 82404f1126761b7877595b622afa7e1f311f2f41e89a3abe9aaf8ad045c082e2):
    TFE = "Texture Fail Enable (for partially resident textures)", LWE = "LOD Warning Enable (for
    partially resident textures)" — fields of ENC_MIMG, present on IMAGE_ATOMIC_* and
    IMAGE_GET_RESINFO. AMD's ISA guides: TFE "When set, a fetch can return a NACK, which causes a
    VGPR write into DST+1 (first GPR after all fetch-dest GPRs)".
  • The data width before the status. LLVM SIISelLowering.cpp (release/21.x,
    AMDGPUImageIntrinsic lowering): NumVDataDwords += 1 with texfail set, for every image
    intrinsic — atomics included (BaseOpcode->Atomic, 1 dword, 2 for the X2/dmask:0x3 forms,
    4 for the 64-bit dmask:0xf cmpswap). Verified first-hand: llvm-mc 23.1.5
    (-mcpu=gfx1030) assembles and disassembles add … dmask:0x1 glc tfe as v[0:1],
    cmpswap … dmask:0x3 glc tfe as v[0:2], cmpswap … dmask:0xf glc tfe as v[0:4],
    image_get_resinfo … dmask:0xf tfe as v[0:4] — the same widths
    tools/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 is
    open for the decoder's own tfe count).
  • The value: 0. The status is non-zero only when a fetch of a partially resident texture
    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 — and
    image_get_resinfo reads no memory at all (ISA: "No memory access is performed"). This matches
    what 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 %c0 constant rather than a new OpConstant in 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 — nothing
documents a warn condition there). Both are written as their "nothing happened" value 0, with the
same reasoning as above, and the docs/design.md row says so. No combination was refused on
semantic grounds except cmpswap + tfe with a dmask other than 0x3, where no reference
settles a data layout at all.

What changed

tools/rdna2spirv.py:

  • New Gen.image_status_write(vdata, data_words) — one self.dst store of self.cu(0) into
    vdata["r"] + data_words, with the references in its docstring.
  • Standard nine + cmpswap (image_misc atomic branch): with tfe/lwe, the status is written
    inside the existing if (active) guard, after the atomic and any glc write-back, at the
    dmask-sized data width (1, 2 for the dmask:0x3 form the translator keeps low-dword 32-bit, 4
    for dmask:0xf); inactive lanes preserve their status VGPR. cmpswap now accepts
    v[0:2]/n=3 with dmask:0x3; a cmpswap status with any other dmask raises
    Unsupported(op + " tfe dmask"); the 64-bit dmask:0xf cmpswap stays refused (n≠3).
  • The six extra atomics (emit_image_atomic_extra): the operand-width check becomes
    need_n + (1 if tfe/lwe else 0), so the data+status width is accepted, and the status is
    written at vdata["r"] + need_n — cmpswap/fcmpswap's compare and sentinel operands are
    read from the first need_n VGPRs and never clobbered.
  • image_get_resinfo: after the dmask's packed result words, the status goes to
    vdata["r"] + out (out or 1: LLVM forces a dmask of 0x1 with texfail and no data bit, so
    the status never lands on the first result word).

docs/design.md: new Image tfe / lwe status VGPR (atomics, resinfo) contract row with all of the
above 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 the
nine standard ops (glc and non-glc, exact SPIR-V atomic opcodes hardcoded), the six extra
atomics, cmpswap/fcmpswap with the comparand/sentinel registers left intact (and still the
OpAtomicCompareExchange comparand operands), the dmask:0x3 form's high dword untouched,
3D, and image_get_resinfo (2D, 2D array, packed dmask:0xa), each against a no-tfe/no-lwe
control whose marker (0xdeadbeef) survives; spirv_mini_interp.check_structure CFG validation and
spirv-as/spirv-val (when on PATH); and the unchanged rejections (cmpswap dmask:0x1/0xf
with 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)

  • Repro on main: python -I <repro> (script in the session log): both forms translated with no
    status store.
  • New file: python -I tests/semantic/test_image_status_vgpr.py → 15 tests OK
    (spirv-as/spirv-val present and passing on this host).
  • Neighbouring image tests: test_image_atomics_32.py OK, test_image_gather4_variants.py OK,
    test_image_store_dmask.py OK.
  • Full suite: 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 on main: verified by
    git 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.
  • No-tfe output unchanged: six control programs (add dmask:0x1/glc, add dmask:0x3,
    cmpswap, fcmpswap 3D, resinfo 2D and 2D-array) translated on stashed main and on the branch:
    SHA-256 digests of the SPIR-V identical.
  • python -m compileall -q make_game.py tools tests clean;
    python -I scripts/check_no_game_data.py tools/rdna2spirv.py tests/semantic/test_image_status_vgpr.py docs/design.md exits 0.
  • Mutants (tools/semantic_mutants.py): the new file kills 6/6 table-entry mutants for
    image_atomic_add/image_atomic_umax (hardcoded opcode map) and the comparand-operand mutant
    of cmpswap; a hand-made status-value mutation (cu(0) → cu(1) in image_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 on main. Overlapping-but-orthogonal open PRs: #8471/#8771
(sample/load/gather status VGPR — unmerged; this PR follows their %c0 convention so a merge
order 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).

  • No game data, keys or decryption, including in logs or reports quoted here (synthetic
    hand-written fixtures only; check_no_game_data.py run on every changed file)
  • No GPU needed; no GPU claim made (CPU tests + ISA/LLVM/llvm-mc references only)
  • The two red semantic files are pre-existing on main (counts verified against a stash)
  • New translator rule recorded in docs/design.md with how it was confirmed

…_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 Grimkeh 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.

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.

@ne1i

ne1i commented Nov 23, 2026

Copy link
Copy Markdown

Tested 6fdef2f8 on Linux, CPython 3.14, CPU only, merged onto main 867d922f0: pass

  • python -m unittest discover -s tests/semantic -p test_image_status_vgpr.py: Ran 15 tests, OK. With only tools/rdna2spirv.py reverted to main: FAILED (failures=23, errors=17), so the new tests exercise the change.
  • compileall and scripts/check_no_game_data.py on the changed files: clean.

The agent checked the new docs/design.md row against the lowering and against LLVM's NumVDataDwords accounting and reports it matches; I did not repeat that.

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 wavehs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-mc assembles and disassembles exactly the widths image_status_write targets for tfe: 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 the spirv-val ones, 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 — which llvm-mc refuses — and writes the status into v1, that form's second data word, not v2 (reproduced: OpStore %reg_v1 %c0 with v2'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.

@wavehs

wavehs commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

macOS arm64 verification (Apple M3 Pro) — the tfe half is right, the lwe half writes past the declared VGPRs and refuses forms that translate today

Tested PR head 6fdef2f8, which fast-forwards onto main 867d922f0 (merge 6fdef2f80), no conflicts.

Host: macOS 27.2.1, Apple M3 Pro (arm64), CPython 3.15.2, llvm-mc 23.1.5 (Homebrew, AMDGPU target), SPIRV-Tools v2026.4.

Check Result
python3 -I tests/semantic/test_image_status_vgpr.py 15/15 pass
Full translator suite 448 files, 5,972 tests, 81 s — 2 files failed
main baseline 447 files, 5,957 tests, the same 2 files

+1 file / +15 tests over the baseline, no new failures (test_image_atomics_guard and test_image_store_d16 fail on unmodified main here). Negative control: main's translator with only the new test file → 23 failures and 17 errors, e.g. AssertionError: 'OpStore %reg_v1 %c0' not found in '… OpAtomicIAdd %uint %t89 %c1 %c0 %t85 | OpBranch %t87_end' — the tests bind to the change.

What I could confirm as correct. The status position matches llvm-mc's own operand-size rule on every tfe form I tried: dmask:0x1 → 2 VGPRs, dmask:0xa → 3, dmask:0xf → 5 for image_get_resinfo, and 2 / 3 for image_atomic_add / cmpswap with dmask:0x1 / 0x3. The write sits inside the if (active) block, not after it — dumped for cmpswap: %t87_do = OpLabel / %t91 = OpAtomicCompareExchange … / OpStore %reg_v2 %c0 / %t88_end = OpLabel, so inactive lanes really do keep the old status word. The no-tfe controls keep their marker.

Finding: llvm-mc allocates the status dword for tfe only, never for lwe

The PR treats the two bits as equivalent (status = "tfe" in mods or "lwe" in mods, rdna2spirv.py:13296, :13473, :13483, :13511, :13537) and the docstring justifies it with "LLVM's image-intrinsic lowering adds the same dword for every image op". llvm-mc 23.1.5 — the tool that produces the text this translator consumes — disagrees, and its check is exact:

form tfe lwe
image_get_resinfo dmask:0xa 3 VGPRs 2
image_get_resinfo dmask:0xf 5 VGPRs 4
image_atomic_add dmask:0x1 2 VGPRs 1
image_atomic_cmpswap dmask:0x3 3 VGPRs 2

(each row measured by assembling every width and keeping the one that passes; anything else gives error: image data size does not match dmask and tfe). So for lwe, the width the translator now insists on is a width no shader in the corpus will have, and the width the corpus does have is the one the translator now treats as "one data word, then the status".

Two consequences, both reproduced:

  1. Silent write one VGPR past the instruction's operand range. image_get_resinfo v[0:1], v3, s[4:11] dmask:0xa dim:SQ_RSRC_IMG_2D lwe — exactly the text llvm-mc prints for a lwe resinfo — is accepted and the translator adds OpStore %reg_v2 %c0 after the two width words. v2 was 0x12345678 before the instruction and is not part of the instruction at all. The same happens for the nine standard atomics: image_atomic_add v[0:0], … dmask:0x1 lwe is accepted and writes v1. This is worse than the bug the PR fixes: the old code dropped the status, the new code overwrites a live register.

  2. Forms that translate today become Unsupported. On main both of these translate (status dropped, as before):

    image_atomic_swap    v[0:0], v[4:5], s[4:11] dmask:0x1 dim:SQ_RSRC_IMG_2D lwe   -> OK on main
    image_atomic_cmpswap v[0:1], v[4:5], s[4:11] dmask:0x3 dim:SQ_RSRC_IMG_2D lwe   -> OK on main
    

    With the PR both raise (Unsupported: image_atomic_swap operands, Unsupported: image_atomic_cmpswap data), because the width check now wants the extra dword that llvm-mc never prints for lwe. That is a translation-count regression in the "fix, don't disable" direction, and the doc row's "the extra six atomics now accept n = data + 1 with tfe/lwe (they used to reject the width)" describes the tfe case only.

Note that the tests cannot catch either one: they pass the lwe forms with the tfe width (test_resinfo_tfe_and_lwe_status uses v[0:4] for dmask:0xf, which llvm-mc rejects for lwe), so every lwe case in the suite is a spelling no shader will arrive in.

Suggested fix. Make the width and the write depend on tfe alone, and refuse lwe until someone measures what it does:

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 lwe (the ISA XML only carries the field descriptions, as the docstring says), then the text still never declares it, so no translation can place it without guessing which register the disassembly gave to something else — Unsupported("image_… lwe") is the honest answer there, and it is one line. Add the lwe widths from the table above as tests either way.

Second, smaller: the nine standard atomics never check vdata's width. The else branch only requires vdata["k"] == "vgpr", so image_atomic_add v[0:0], … dmask:0x1 tfe — one VGPR for a form that needs two — is accepted and the status lands in v1, outside the declared range. The six extras and cmpswap do check (image_atomic_swap v[0:0] … tfe → Unsupported: image_atomic_swap operands). llvm-mc refuses such text, so this is only reachable from hand-written .asm (which regen_fixtures.py copies verbatim and this repo does author), but the check is one line and makes the five paths agree.

Third, minor: dmask:0x0 with tfe on resinfo. llvm-mc accepts only v[0:1] for it and keeps dmask at 0 in the encoding (dmask:0x0 tfe → [0x08,0x00,0x39,0xf0,…], dmask:0x1 tfe → [0x08,0x01,0x45,0xf0,…]), so "LLVM forces a dmask of 0x1 with texfail and no data bit" (rdna2spirv.py:13534-13537) is not what happens: LLVM only sizes the operand range as one data word plus the status. The translator matches that placement (out or 1 → v1) and writes no data word, which is harmless because dmask:0x0 asked for none, but the comment states a mechanism that the bytes do not show.

Lastly, the binary path still disagrees. tools/shader_disasm.py decodes through rdna2_decode._mimg_data_count, which returns early for image_atomic_* (rdna2_decode.py:397-405) before the + (1 if tfe else 0) at :412, and _decode_one reads lwe at :1201 but passes only bool(tfe) at :1225. Decoding 08 01 45 f0 02 00 01 00 (image_atomic_add v[0:1], v[2:3], s[4:11] dmask:0x1 tfe) gives VDATA n = 1, and an lwe form gets no extra word at all — so a disassemble → translate round trip loses the status slot. Not a regression, but it is the same table the docstring cites as the source of the width rule, and it should agree with the translator.

No extra Unsupported beyond what the change needs was added; the diagnostics I did see are clear about which operand is wrong.

No game files. AI-assisted.

@wavehs wavehs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-mc assembles and disassembles exactly the widths image_status_write targets for tfe: 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 the spirv-val ones, 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 — which llvm-mc refuses — and writes the status into v1, that form's second data word, not v2 (reproduced: OpStore %reg_v1 %c0 with v2'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.

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.

4 participants