Shaders: 16-bit image derivatives pack two to a dword; cd_g16 and gather4h names #69

Open
github-bot wants to merge 2 commits from github-bot/gh-69 into main AGit
Owner

@⁠lcg007xd-c on GitHub · 2026-11-25 21:34 UTC · original
lcg007xd-c:fix/mimg-g16-decode → main · +100 −1 · 4 files · 2 commits · open

What

image_addr_dwords counted the derivatives of a _g16 form (16-bit gradients) as whole dwords. For example, image_sample_d_g16 on a 2D image was decoded as reading six address VGPRs, but the instruction has four (llvm-mc prints v[0:3]). The same error hit every d_g16 variant in 2D, 3D, cube and the arrays. _g16 now packs the derivatives in pairs, the way a16 already did. Nothing else changes.

The MIMG table also gets the names LLVM uses for 0xE8–0xEF (image_sample_cd_g16 … image_sample_c_cd_cl_o_g16) and 0x61 (image_gather4h). None of them lowers yet. The lowering matches exact names, so they are refused as unsupported, and a test pins that.

Today the lowering refuses d_g16 too, so the wrong count showed up only in the decoded Fields and the SP3 text, plus the extra VGPRs the IR thought those instructions read. It matters as soon as someone lowers _g16.

How it was checked

  • Full sweep against LLVM. I decoded every image_sample* / image_gather4* opcode in the table, in each of the dims that can be sampled (1D, 2D, 3D, cube, 1D array, 2D array), and compared the address size with llvm-mc -triple=amdgcn -mcpu=gfx1030 --disassemble. Before: 32 disagreements, all of them _g16. After: none. The MSAA dims differ for every sample form, because LLVM prints those oddly; you can't sample an MSAA image, so I left them out.
  • New test. g16_derivatives_pack_in_pairs pins 14 of those words to LLVM's exact text, including the new names. It fails without the fields.rs change.
  • New test. g16_and_gather4h_forms_are_refused checks that the lowering returns Unsupported for each of the new names and for d_g16.
  • CI commands. The portable CI commands and Windows-target clippy (--target x86_64-pc-windows-msvc) pass locally.

Not tested: Windows runtime, GPU, and the game. Nothing here changes generated DXIL.

Note: the Windows check job fails on current main for an unrelated reason (5668b8b, missing Layout::bytes_from), which #64 fixes.

🤖 Generated with Claude Code

**@⁠lcg007xd-c** on GitHub · 2026-11-25 21:34 UTC · [original](https://github.com/uiliannn/VItoriaBr/pull/69) `lcg007xd-c:fix/mimg-g16-decode` → `main` · +100 −1 · 4 files · 2 commits · open ## What `image_addr_dwords` counted the derivatives of a `_g16` form (16-bit gradients) as whole dwords. For example, `image_sample_d_g16` on a 2D image was decoded as reading six address VGPRs, but the instruction has four (`llvm-mc` prints `v[0:3]`). The same error hit every `d_g16` variant in 2D, 3D, cube and the arrays. `_g16` now packs the derivatives in pairs, the way `a16` already did. Nothing else changes. The MIMG table also gets the names LLVM uses for 0xE8–0xEF (`image_sample_cd_g16` … `image_sample_c_cd_cl_o_g16`) and 0x61 (`image_gather4h`). None of them lowers yet. The lowering matches exact names, so they are refused as unsupported, and a test pins that. Today the lowering refuses `d_g16` too, so the wrong count showed up only in the decoded `Fields` and the SP3 text, plus the extra VGPRs the IR thought those instructions read. It matters as soon as someone lowers `_g16`. ## How it was checked - **Full sweep against LLVM.** I decoded every `image_sample*` / `image_gather4*` opcode in the table, in each of the dims that can be sampled (1D, 2D, 3D, cube, 1D array, 2D array), and compared the address size with `llvm-mc -triple=amdgcn -mcpu=gfx1030 --disassemble`. Before: 32 disagreements, all of them `_g16`. After: none. The MSAA dims differ for every sample form, because LLVM prints those oddly; you can't sample an MSAA image, so I left them out. - **New test.** `g16_derivatives_pack_in_pairs` pins 14 of those words to LLVM's exact text, including the new names. It fails without the `fields.rs` change. - **New test.** `g16_and_gather4h_forms_are_refused` checks that the lowering returns `Unsupported` for each of the new names and for `d_g16`. - **CI commands.** The portable CI commands and Windows-target clippy (`--target x86_64-pc-windows-msvc`) pass locally. Not tested: Windows runtime, GPU, and the game. Nothing here changes generated DXIL. Note: the Windows `check` job fails on current main for an unrelated reason (5668b8b, missing `Layout::bytes_from`), which #64 fixes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
image_addr_dwords counted a _g16 form's derivatives as whole dwords, so
image_sample_d_g16 on a 2D image read six address VGPRs where the
instruction has four (llvm-mc: v[0:3]), and every d_g16 variant in 2D,
3D, cube and 2D arrays was two (or three) too long. `_g16` now packs the
derivatives in pairs, the way `a16` already did. Against llvm-mc's
disassembly of every image_sample/gather4 opcode in the 1D to 2D-array
dims, the counts now all agree (before: 32 disagreements, all _g16).

The table also gets the names LLVM gives MIMG 0xE8-0xEF
(image_sample_cd_g16 to image_sample_c_cd_cl_o_g16) and 0x61
(image_gather4h). None of these lowers yet; the lowering matches exact
names, and a test checks they are refused as unsupported.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:43:01 +00:00
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/69/head:github-bot/gh-69'
git switch 'github-bot/gh-69'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-69'
git switch 'github-bot/gh-69'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-69'
git switch 'github-bot/gh-69'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-69'
git switch 'main'
git merge --squash 'github-bot/gh-69'
git switch 'main'
git merge --ff-only 'github-bot/gh-69'
git switch 'main'
git merge 'github-bot/gh-69'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.