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

Closed
madhyn wants to merge 2 commits from upstream-pr/1199 into main
madhyn commented 2026-11-24 20:03:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T20:03:31Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5479424616 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1199). Originally posted by [madhyn](https://github.com/madhyn) on 2026-11-24T20:03:31Z. --- Claimed in the coordination issue as: SHADER-IMAGE-MSAA-LOAD ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7142826368)) 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
thesubtleties commented 2026-11-24 20:47:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by thesubtleties on 2026-11-24T20:47:23Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7144058013 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1199#issuecomment-7144058013). Originally posted by [thesubtleties](https://github.com/thesubtleties) on 2026-11-24T20:47:23Z. --- 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)
titoreinaldo commented 2026-11-24 20:58:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by titoreinaldo on 2026-11-24T20:58:50Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7144313811 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1199#issuecomment-7144313811). Originally posted by [titoreinaldo](https://github.com/titoreinaldo) on 2026-11-24T20:58:50Z. --- 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.
madhyn commented 2026-11-24 21:21:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by madhyn on 2026-11-24T21:21:25Z.


@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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7144821339 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1199#issuecomment-7144821339). Originally posted by [madhyn](https://github.com/madhyn) on 2026-11-24T21:21:25Z. --- @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
MoonEyes commented 2026-11-28 02:54:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:54:33Z.


Hi @madhyn, thanks for this pull request. It currently conflicts with main (conflicting file(s): tools/rdna2spirv.py), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232670989 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1199#issuecomment-7232670989). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:54:33Z. --- Hi @madhyn, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `tools/rdna2spirv.py`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
aslan2142 commented 2026-12-01 11:45:00 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:45:00Z.

Review: CHANGES_REQUESTED


This PR cannot merge in its current state:

  • Merge conflict with main in tools/rdna2spirv.py.
  • No CI run on current head 2fc4f96.

Please rebase onto current main and obtain a green CI run.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130572629 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1199#pullrequestreview-6130572629). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:45:00Z. **Review:** CHANGES_REQUESTED --- This PR cannot merge in its current state: - **Merge conflict** with `main` in `tools/rdna2spirv.py`. - **No CI run** on current head `2fc4f96`. Please rebase onto current `main` and obtain a green CI run. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 16:33:55 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:33:55Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317815924 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1199#issuecomment-7317815924). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:33:55Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
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
ProjectLeonida/mandy!1199
No description provided.