shader: a16 does not make image gradients 16-bit; only the _g16 opcodes do #320

Closed
opened 2026-11-27 11:21:47 +00:00 by gagarinyury · 3 comments
gagarinyury commented 2026-11-27 11:21:47 +00:00 (Migrated from github.com)
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T11:21:47Z.


What is wrong

image_addr_dwords (gfx10/fields.rs) and the gradient lowering in lower.rs ("With a16 each direction's gradients start a VGPR") read gradients as f16 pairs whenever an image instruction has a16. On GFX10 the A16 bit packs the coordinates, LOD and clamp, not the gradients: 16-bit gradients come from the separate _g16 opcodes.

LLVM agrees on gfx1010, gfx1013 and gfx1030: image_sample_d v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16 takes 5 address VGPRs (four 32-bit gradients, then x and y as one f16 pair), and with 3 VGPRs, our count, the assembler rejects it ("image address size does not match dim and a16"). image_sample_d_g16 with a16 takes 3. In LLVM's lowering, gradients follow A16 only on targets without G16 (SIISelLowering.cpp: !ST->hasG16() && (IsA16 != IsG16)), and every GFX10 target has FeatureG16.

So image_sample_d, _cd and their _c, _o, _cl forms with a16 translate today but read their gradients and coordinates from the wrong VGPRs. image_sample_cd_g16 and image_sample_c_cd_g16 (with _cl) are not in the opcode table.

How it was found

Decoding LLVM's GFX10 MC tests (llvm/test/MC/AMDGPU/gfx10_asm_*.s, about 30,000 instructions assembled with -mcpu=gfx1030) with gfx10::decode and comparing each register operand's size with LLVM's. Apart from this the differences are small: ds_gws_* without their data VGPR, ds_wrap_rtn_b32 without its second data VGPR, and the VOP3 forms of v_interp_* missing from the table.

Plan

Size and read the gradients by the opcode (32-bit unless _g16), add the missing _cd_g16 opcodes, and test the address sizes against LLVM's encodings plus the lowering of a 2D image_sample_d with a16.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6645426631 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/320). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T11:21:47Z. --- **What is wrong** `image_addr_dwords` (gfx10/fields.rs) and the gradient lowering in `lower.rs` ("With a16 each direction's gradients start a VGPR") read gradients as f16 pairs whenever an image instruction has `a16`. On GFX10 the A16 bit packs the coordinates, LOD and clamp, not the gradients: 16-bit gradients come from the separate `_g16` opcodes. LLVM agrees on gfx1010, gfx1013 and gfx1030: `image_sample_d v[0:3], v[0:4], s[0:7], s[8:11] dmask:0xf dim:SQ_RSRC_IMG_2D a16` takes 5 address VGPRs (four 32-bit gradients, then x and y as one f16 pair), and with 3 VGPRs, our count, the assembler rejects it ("image address size does not match dim and a16"). `image_sample_d_g16` with `a16` takes 3. In LLVM's lowering, gradients follow A16 only on targets without G16 (`SIISelLowering.cpp`: `!ST->hasG16() && (IsA16 != IsG16)`), and every GFX10 target has `FeatureG16`. So `image_sample_d`, `_cd` and their `_c`, `_o`, `_cl` forms with `a16` translate today but read their gradients and coordinates from the wrong VGPRs. `image_sample_cd_g16` and `image_sample_c_cd_g16` (with `_cl`) are not in the opcode table. **How it was found** Decoding LLVM's GFX10 MC tests (`llvm/test/MC/AMDGPU/gfx10_asm_*.s`, about 30,000 instructions assembled with `-mcpu=gfx1030`) with `gfx10::decode` and comparing each register operand's size with LLVM's. Apart from this the differences are small: `ds_gws_*` without their data VGPR, `ds_wrap_rtn_b32` without its second data VGPR, and the VOP3 forms of `v_interp_*` missing from the table. **Plan** Size and read the gradients by the opcode (32-bit unless `_g16`), add the missing `_cd_g16` opcodes, and test the address sizes against LLVM's encodings plus the lowering of a 2D `image_sample_d` with `a16`.
gagarinyury commented 2026-11-27 11:21:56 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by gagarinyury on 2026-11-27T11:21:56Z.


/claim

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216988645 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/320#issuecomment-7216988645). Originally posted by [gagarinyury](https://github.com/gagarinyury) on 2026-11-27T11:21:56Z. --- /claim
github-actions[bot] commented 2026-11-27 11:22:08 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by github-actions[bot] on 2026-11-27T11:22:08Z.


Claimed by @gagarinyury. Open a draft pull request with Refs #320 in its description within 24 hours, or the claim expires.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7216992230 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/320#issuecomment-7216992230). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-27T11:22:08Z. --- Claimed by @gagarinyury. Open a draft pull request with `Refs #320` in its description within 24 hours, or the claim expires.
LakshanSivakumar commented 2026-11-28 00:36:12 +00:00 (Migrated from github.com)
Author
Contributor

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-28T00:36:12Z.


Thank you for this. It is fixed on main by #322. I have not checked every case from this report in the game myself, so please retest on main a6a58361 and reopen this if you still see it. Closing as fixed.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7231043350 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/issues/320#issuecomment-7231043350). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-28T00:36:12Z. --- Thank you for this. It is fixed on main by #322. I have not checked every case from this report in the game myself, so please retest on main a6a58361 and reopen this if you still see it. Closing as fixed.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS#320
No description provided.