rdna2spirv: lower image_msaa_load through set-0 MSAA bindings 20-25 (SHADER-IMAGE-MSAA-LOAD) #1199

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

@⁠madhyn on GitHub · 2026-11-24 20:03 UTC · original
madhyn:fix/image-msaa-load → main · +218 −14 · 5 files · 2 commits · open

Claimed in the coordination issue as: SHADER-IMAGE-MSAA-LOAD (claim)

Follow-up to roanh47's finding in #14 and #1183 (RT-MSAA-DEPTH-SRV).

What and why

  • tools/rdna2spirv.py: lower image_msaa_load for dim:SQ_RSRC_IMG_2D_MSAA and dim:SQ_RSRC_IMG_2D_MSAA_ARRAY via OpImageFetch ... Sample %sample, declaring the set-0 multisampled sampled-image arrays at bindings 20–25 (20/22/24 for 2DMS float/uint/sint and 21/23/25 for 2DMS-array float/uint/sint, matching runtime/src/vulkan_bindless.h::sampled_binding). Handles a16 (u16 packed coords/slice/sample) and d16 via image_read_typed. Non-MSAA dimensions, glc, tfe, lwe, and non-VGPR destinations raise Unsupported.
  • tools/wave64_halves.py, tools/wave64_emulate_opt.py: classify image_msaa_load with image_load for memory ordering and d16 packing.
  • tests/semantic/test_image_msaa_load.py: checks bindings 20–25, OpTypeImage ... MS=1, OpImageFetch ... Sample, a16/d16, --wave64-emulate, Unsupported rejections, and spirv-val --target-env vulkan1.3.
  • docs/design.md: documents the image_msaa_load contract row.

Tested

  • PYTHONPATH=tests/semantic python3 -m unittest tests/semantic/test_image_msaa_load.py tests/semantic/test_sample_typed_dims.py tests/semantic/test_image_coherent.py tests/semantic/test_image_store_d16.py tests/semantic/test_image_store_dmask.py tests/semantic/test_mem_crash_forms.py: 37 tests passed (0.577 s), including spirv-as + spirv-val --target-env vulkan1.3.
  • python3 -m unittest discover -s tests -p "test_docs_*.py": 47 tests passed (12.097 s).
  • python3 runtime/test/shaders/build.py runtime/build/linux: 284/284 fixtures translated and passed spirv-val.
  • Not measured: GPU readback on an MSAA image (current vk_harness / vk_compute_test harnesses only allocate single-sample images).

AI-assisted: yes

**@⁠madhyn** on GitHub · 2026-11-24 20:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1199) `madhyn:fix/image-msaa-load` → `main` · +218 −14 · 5 files · 2 commits · open Claimed in the coordination issue as: SHADER-IMAGE-MSAA-LOAD ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)) Follow-up to `roanh47`'s finding in #14 and #1183 (`RT-MSAA-DEPTH-SRV`). ### What and why - `tools/rdna2spirv.py`: lower `image_msaa_load` for `dim:SQ_RSRC_IMG_2D_MSAA` and `dim:SQ_RSRC_IMG_2D_MSAA_ARRAY` via `OpImageFetch ... Sample %sample`, declaring the set-0 multisampled sampled-image arrays at bindings 20–25 (`20/22/24` for 2DMS float/uint/sint and `21/23/25` for 2DMS-array float/uint/sint, matching `runtime/src/vulkan_bindless.h::sampled_binding`). Handles `a16` (u16 packed coords/slice/sample) and `d16` via `image_read_typed`. Non-MSAA dimensions, `glc`, `tfe`, `lwe`, and non-VGPR destinations raise `Unsupported`. - `tools/wave64_halves.py`, `tools/wave64_emulate_opt.py`: classify `image_msaa_load` with `image_load` for memory ordering and `d16` packing. - `tests/semantic/test_image_msaa_load.py`: checks bindings 20–25, `OpTypeImage ... MS=1`, `OpImageFetch ... Sample`, `a16`/`d16`, `--wave64-emulate`, `Unsupported` rejections, and `spirv-val --target-env vulkan1.3`. - `docs/design.md`: documents the `image_msaa_load` contract row. ### Tested - `PYTHONPATH=tests/semantic python3 -m unittest tests/semantic/test_image_msaa_load.py tests/semantic/test_sample_typed_dims.py tests/semantic/test_image_coherent.py tests/semantic/test_image_store_d16.py tests/semantic/test_image_store_dmask.py tests/semantic/test_mem_crash_forms.py`: **37 tests passed** (0.577 s), including `spirv-as` + `spirv-val --target-env vulkan1.3`. - `python3 -m unittest discover -s tests -p "test_docs_*.py"`: **47 tests passed** (12.097 s). - `python3 runtime/test/shaders/build.py runtime/build/linux`: **284/284** fixtures translated and passed `spirv-val`. - Not measured: GPU readback on an MSAA image (current `vk_harness` / `vk_compute_test` harnesses only allocate single-sample images). AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:42:37 +00:00
Author
Owner

@⁠thesubtleties on GitHub · 2026-11-24 20:47 UTC · original

CPU check of 4cd974867, applied to main 3aa97542: run_semantic_tests.py tests/semantic 471 files / 6,172 tests, 0 failed.

llvm-mc 23.1.5 agrees with the operand shape: on gfx1013 and gfx1030 the data is sized by dmask (v1 with dmask:0x1, v[1:4] with 0xf), and the four-register dmask:0x1 gather form is accepted only on gfx1100.

A question: LLVM's image intrinsic optimizer (PR 67151) reportedly limits its MSAA combine to gfx11 because the gfx10 instruction only works correctly with single-channel formats. I only saw a summary of that; should multi-channel formats be refused or noted as unmeasured?

Not tested: GPU, hardware. AI-assisted (Claude Code)

**@⁠thesubtleties** on GitHub · 2026-11-24 20:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1199#issuecomment-7144058013) CPU check of `4cd974867`, applied to main `3aa97542`: `run_semantic_tests.py tests/semantic` 471 files / 6,172 tests, 0 failed. `llvm-mc` 23.1.5 agrees with the operand shape: on gfx1013 and gfx1030 the data is sized by `dmask` (`v1` with `dmask:0x1`, `v[1:4]` with `0xf`), and the four-register `dmask:0x1` gather form is accepted only on gfx1100. A question: LLVM's [image intrinsic optimizer](https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20230918/1211820.html) (PR 67151) reportedly limits its MSAA combine to gfx11 because the gfx10 instruction only works correctly with single-channel formats. I only saw a summary of that; should multi-channel formats be refused or noted as unmeasured? Not tested: GPU, hardware. AI-assisted (Claude Code)
Author
Owner

@⁠titoreinaldo on GitHub · 2026-11-24 20:58 UTC · original

I checked the architecture-specific amdgpu_isa_rdna2.xml in AMD’s machine-readable ISA. Its IMAGE_MSAA_LOAD description explicitly says “Load up to 4 samples of 1 component from an MSAA resource with a user-specified fragment ID.” The ordinary IMAGE_LOAD uses the address layout in RDNA2 table 42. This matters even with an R32_UINT texture. If four samples at one pixel contain 11, 22, 33 and 44, one OpImageFetch at sample zero on that texture yields (11,0,0,1). It cannot return the other three samples. A fixture with distinct sample values would catch that difference before declaring the specialized opcode supported. The exact GFX10 sample-base and mask mapping still needs independent verification.

I claimed the ordinary per-sample image_load on #14. I’ll credit this PR for the existing typed binding layout and keep the specialized opcode with this PR. I checked the public XML and the emitted operation on 4cd97486. I haven’t measured a native RDNA2 card. Codex-assisted.

**@⁠titoreinaldo** on GitHub · 2026-11-24 20:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1199#issuecomment-7144313811) I checked the architecture-specific `amdgpu_isa_rdna2.xml` in [AMD’s machine-readable ISA](https://gpuopen.com/machine-readable-isa/). Its `IMAGE_MSAA_LOAD` description explicitly says “Load up to 4 samples of 1 component from an MSAA resource with a user-specified fragment ID.” The ordinary `IMAGE_LOAD` uses the address layout in [RDNA2 table 42](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf#page=72). This matters even with an R32_UINT texture. If four samples at one pixel contain 11, 22, 33 and 44, one `OpImageFetch` at sample zero on that texture yields `(11,0,0,1)`. It cannot return the other three samples. A fixture with distinct sample values would catch that difference before declaring the specialized opcode supported. The exact GFX10 sample-base and mask mapping still needs independent verification. I claimed the ordinary per-sample `image_load` on #14. I’ll credit this PR for the existing typed binding layout and keep the specialized opcode with this PR. I checked the public XML and the emitted operation on `4cd97486`. I haven’t measured a native RDNA2 card. Codex-assisted.
Author
Owner

@⁠madhyn on GitHub · 2026-11-24 21:21 UTC · original

@⁠titoreinaldo @⁠thesubtleties Thanks for checking amdgpu_isa_rdna2.xml and LLVM PR 67151 — updated image_msaa_load_typed in tools/rdna2spirv.py:

  • When dmask == 0x1, it emits a single OpImageFetch ... Sample %sample.
  • When dmask enables multiple lanes (e.g. dmask:0xf), it emits one OpImageFetch ... Sample (%sample + k) per active bit k (0..3), extracts component 0 from each sample, and packs them via OpCompositeConstruct.
  • Updated tests/semantic/test_image_msaa_load.py (5/5 tests pass, including spirv-as + spirv-val on all 4 variants).

AI-assisted: yes

**@⁠madhyn** on GitHub · 2026-11-24 21:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1199#issuecomment-7144821339) @⁠titoreinaldo @⁠thesubtleties Thanks for checking `amdgpu_isa_rdna2.xml` and LLVM PR 67151 — updated `image_msaa_load_typed` in `tools/rdna2spirv.py`: - When `dmask == 0x1`, it emits a single `OpImageFetch ... Sample %sample`. - When `dmask` enables multiple lanes (e.g. `dmask:0xf`), it emits one `OpImageFetch ... Sample (%sample + k)` per active bit `k` (`0..3`), extracts component `0` from each sample, and packs them via `OpCompositeConstruct`. - Updated `tests/semantic/test_image_msaa_load.py` (5/5 tests pass, including `spirv-as` + `spirv-val` on all 4 variants). AI-assisted: yes
This pull request has changes conflicting with the target branch.
  • tools/rdna2spirv.py
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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