Skip to content

rdna2spirv: implement image_msaa_load (MIMG 0x80) - #5225

Open
DenRakEiw wants to merge 2 commits into
ItsNotRexed:mainfrom
DenRakEiw:feat/rdna2-image-msaa-load
Open

DenRakEiw wants to merge 2 commits into
ItsNotRexed:mainfrom
DenRakEiw:feat/rdna2-image-msaa-load

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Summary

Implements RDNA2 image_msaa_load (MIMG 0x80) — and shares the same lowering for image_load on SQ_RSRC_IMG_2D_MSAA / SQ_RSRC_IMG_2D_MSAA_ARRAY — in tools/rdna2spirv.py.

Claim: #5032 (comment)

Changes

  • tools/rdna2spirv.py:
    • Added MSAA_DIMS (SQ_RSRC_IMG_2D_MSAA -> index 0, SQ_RSRC_IMG_2D_MSAA_ARRAY -> index 1) and Gen.uses_ms_fetch.
    • Declared MSAA sampled image runtime arrays %msv{0,1,2}_{0,1} (OpTypeImage %float/%uint/%int 2D 0 <arrayed> 1 1 Unknown, MS=1, Sampled=1) at set 0 bindings 20/22/24 (2D_MSAA) and 21/23/25 (2D_MSAA_ARRAY), matching runtime/src/vulkan_bindless.h.
    • Implemented Gen.image_msaa_load: unpacks (x, y, sample_index) for 2D_MSAA and (x, y, slice, sample_index) for 2D_MSAA_ARRAY (including a16 16-bit packed unsigned integer coords and NSA lists), emits OpImageFetch ... Sample <sample_idx>, and delegates numeric-class dispatch (float / uint / sint from T# FORMAT, with miss fallback to index 0 float view), dmask, and d16 packing to image_read_typed.
    • Refuses unsupported modifiers/forms (glc, tfe/lwe, non-MSAA dims, non-VGPR destination, short address).
    • Added image_msaa_load to x_memory_order.
  • tools/rdna2_decode.py:
    • Added image_msaa_load to the _mimg_addr_count load prefix check so _l in _load does not add a spurious LOD address VGPR (verified against llvm-mc -arch=amdgcn -mcpu=gfx1030 -show-encoding for 2D_MSAA, 2D_MSAA_ARRAY, d16, a16, and NSA).
  • tools/wave64_halves.py & tools/wave64_emulate_opt.py:
    • Classified image_msaa_load alongside image_load in LOADS and _x_memory_order_access.
  • tests/semantic/test_image_msaa_load.py:
    • Semantic, binary decode (rdna2_decode.decode_bytes + round-trip translate), unsupported-form, and spirv-as/spirv-val (vulkan1.2) tests across 11 image_msaa_load / MSAA image_load variants.

Verification

  • python -m unittest discover -s tests/semantic -p test_image_msaa_load.py -v: 6/6 OK (including spirv-as + spirv-val C:\VulkanSDK\1.4.363.0\Bin\spirv-val.exe --target-env vulkan1.2 across all 11 MSAA variants)
  • python -I tests/test_image_load_typed.py: 23 tests OK (2 skipped)
  • python -m unittest discover -s tests/semantic -p test_image_coherent.py -v: 10 tests OK (1 skipped)
  • python -I tests/test_isa_coverage.py: 20 tests OK (4 skipped)
  • python -m pytest -W ignore tests/test_image_load_d16_typed.py tests/semantic/test_mem_crash_forms.py -q: 1 passed, 6 skipped
  • python -I tests/test_text_write_line_endings.py: 3/3 OK
  • git diff --check: clean

AI-assisted (Gemini 4 Neon).

@Kev-Ball

Copy link
Copy Markdown

I found a result-semantics mismatch at d2dec3d3. The gfx1030 assembler accepts the fixture’s image_msaa_load v[0:3], v[4:6], s[8:15] dmask:0xf dim:SQ_RSRC_IMG_2D_MSAA unorm. Its translation passes Vulkan 1.2 validation. Inspecting the emitted SPIR-V, however, each numeric-class branch fetches one sample at the same sample index; the float branch extracts components 0, 1, 2 and 3 of that one texel.

RDNA2 MIMG opcode 128 retrieves up to four samples of a single component. LLVM also documents a gfx10 limitation that makes a single-channel texture the appropriate control. A 4× MSAA R32_FLOAT texel with distinct red values in samples 0–3, identity component mapping, and fragment ID 0 separates these behaviors: a single RGBA fetch cannot recover the other three red values. Please cover that case separately from ordinary image_load on an MSAA dimension. AMD RDNA2 ISA, §12.16, opcode 128 · LLVM’s gfx10 limitation

I also scanned all 26,503 retail DXBC listings on my 1.0.2.1 copy. None used image_msaa_load or image_load with an MSAA dimension, so this corpus cannot validate the new result semantics. The finding above is from the synthetic lowering and ISA reference; I have no RDNA2 hardware readback for it. AI-assisted.

@Kam471 Kam471 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.

Ran this at d2dec3d39 on Windows 11 (the repo's no--I invocation, since the test imports support): tests/semantic/test_image_msaa_load.py -> 6 tests, OK; git diff --check clean.

image_msaa_load (MIMG 0x80) is now implemented for 2D_MSAA and 2D_MSAA_ARRAY, with the sample coordinate/a16 path and the decoder/wave64 bookkeeping updated; the new 264-line test covers the operand forms, the sample selection and the rejected shapes through the translator and the interpreter. The PR adds no GPU fixture, so this is CPU evidence only. No blocking issue.

@Atomic258

Copy link
Copy Markdown
Contributor

Tested d2dec3d on Windows Server 2022, CPython 3.13.12, CPU-only: pass

  • python -I -m unittest discover -s tests/semantic -p test_image_msaa_load.py: 6 tests OK (1 skipped)
  • Negative control: fails against main's touched tools (5 failures + 11 errors)
  • git diff --check clean; python -m compileall -q on changed Python files: exit 0

No game files, no GPU. AI-assisted (Devin).

@amarovndres

Copy link
Copy Markdown

Tested d2dec3d3 on Windows 11 Pro (build 26200), Python 3, SPIRV-Tools from Vulkan SDK 1.4.363 on PATH. CPU only. Pass.

  • python -m unittest discover -s tests/semantic -p test_image_msaa_load.py: 6 tests OK.
  • Control, this tree with main 3faac557's tools/rdna2spirv.py, rdna2_decode.py, wave64_emulate_opt.py and wave64_halves.py: FAILED (failures=5, errors=22), so the test needs this PR.
  • Only this PR's new test was run, not the whole tests/semantic suite.

AI-assisted (Claude Code). Hand-written shaders only, no game files.

@DenRakEiw

Copy link
Copy Markdown
Contributor Author

Thanks @Kev-Ball for catching that! Fixed in e0c0930:

  • Separated \image_msaa_load\ (MIMG \

@Kev-Ball

Copy link
Copy Markdown

Retested the sample-selection issue on e0c0930b. I swept all 15 nonempty dmasks for both 2D MSAA and 2D MSAA array, generating a fragment shader for each opcode at each combination. All 60 assembled and passed Vulkan 1.2 spirv-val.

In each float, uint and sint branch, image_msaa_load now fetches once per enabled mask bit, adds that bit’s index to the sample operand, and extracts channel 0 from each fetch. For example, mask 0x9 uses offsets 0 and 3. The ordinary image_load control still fetches exactly once at the original sample index for all 30 combinations. This resolves the one-fetch lowering I reported at d2dec3d3.

AI-assisted. Synthetic translation and inspection of emitted SPIR-V on CachyOS; texture readback was outside this run.

@Dom-in

Dom-in commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Regression check of e0c0930 on AMD Radeon RX 9070 (RDNA4, subgroup 32..64), AMD driver 26.11.2 (LLPC), Windows 11 Pro 26300, Vulkan SDK 1.4.363, scripts/run_gpu_tests.py natively and with LEONIDA_W64_EMULATE=1, PR merged onto main 3faac55: no regressions.

  • Full GPU suite: 198/217 passed, 15 skipped, natively and emulated, the same counts and the same failures as main 3faac55.
  • This PR adds no GPU fixture for image_msaa_load itself, so the result says only that nothing else changed. That holds on a native wave64 AMD GPU too.

AI-assisted (Claude Code).

@lunarminus

Copy link
Copy Markdown

Tested e0c0930b on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

This branch already contains main up to 3faac557, so merging it into my older main checkout was a fast-forward to e0c0930b. I built runtime/ fresh (no build errors) and also ran a control at 3faac557 without this PR, using the same build.

  • python -m unittest discover -s tests/semantic -p test_image_msaa_load.py: 7 tests OK, 0 skipped. SPIRV-Tools v2026.4 spirv-as/spirv-val were on PATH. The same test against 3faac557's tools fails with FAILED (failures=5, errors=24), so it needs this PR.
  • These gave the same results with and without the PR:
    • tests/test_image_load_typed.py: 23 OK
    • tests/test_isa_coverage.py: 20 OK, 4 skipped
    • tests/semantic/test_image_coherent.py: 10 OK
    • pytest tests/test_image_load_d16_typed.py tests/semantic/test_mem_crash_forms.py: 7 passed, 11 subtests passed
  • Full tests/semantic (with LEONIDA_AMD_CLANG): 6252 tests with the PR and 6245 without (the 7 new ones). The failure list is identical before and after the PR: 3 failures and 2 errors, all in test_loop_ballot_barrier's wave64-emulate subtests. None are new.
  • Decoder: I assembled image_msaa_load with llvm-mc -mcpu=gfx1030 for 2D_MSAA, 2D_MSAA_ARRAY, 2D_MSAA_ARRAY a16 and NSA [v4, v9, v6].
    • The PR's rdna2_decode reads 3, 4 and 2 address VGPRs and the NSA list, which matches what was assembled.
    • 3faac557 reads 4, 5 and 3, one extra LOD VGPR in each case.
  • GPU suite (scripts/run_gpu_tests.py), fresh build: 202/217 passed, 15 skipped, both with LEONIDA_W64_EMULATE unset and with it set to 1.
    • Compared test by test with 3faac557 without the PR: no difference in either mode.
    • Compared with an earlier main run at d0835dd9 (196/210, 14 skipped): no test changed result. The 7 tests that are new since then come from main, not from this PR: 6 PASS and ps_m2_literal SKIP.
  • This PR adds no GPU fixture, so these results don't exercise the new lowering on hardware. I did not run a 4x MSAA R32_FLOAT readback.

AI-assisted (Claude Code).

@AwkGrep256

Copy link
Copy Markdown
Contributor

Reviewed head e0c0930, applied to main 3faac55. CPU and code read only. test_image_msaa_load 7/7 pass, including spirv-val --target-env vulkan1.2 on all variants. Full tests/semantic passes except test_loop_ballot_barrier, which fails the same way on main. llvm-mc 23.1.5 agrees that the data size follows dmask (v1 for dmask:0x1, v[1:2] for dmask:0x3; v[1:4] with dmask:0x1 is rejected).

One issue: the uint/sint MSAA bindings may not exist. The module declares and statically uses all three classes (%msv0..2, bindings 20–25), because image_read_typed emits the float, uint and sint reads and picks one by FORMAT at run time. The runtime only creates bindings 22–25 when that class has a multisample fallback: binding_enabled in runtime/src/vulkan_bindless.h:122 returns false when ms_samples[class] is 1. The layer sets uint and sint from ms_fallback_samples(...) (runtime/shims/d3d12_vulkan_device.cpp:4439), and limit_ms_bindings can turn them off on devices with low descriptor limits. On those devices, a pipeline using this module would reference bindings missing from the set layout. Can you confirm, and either fall back to the float binding or have the runtime always create 22–25?

Not checked: the semantics (dmask bit k → sample sample_idx + k, channel 0) come from the ISA text, and the tests check the emitted instructions, not values. I have an RDNA2 GPU (gfx1036) and can run a GPU comparison if you add a fixture. AI-assisted (Claude Code).

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 9a0015c on Windows 11: the translator checks and the GPU descriptor checks pass.

  • CPython 3.14.7: all 7 tests in test_image_msaa_load.py and all 23 tests in test_image_load_typed.py pass. The merge base 561b65a raises Unsupported for image_msaa_load with the new tests.
  • I assembled and validated 15 additional Vulkan 1.2 modules. Each module uses a different nonempty dmask. Each combines image_msaa_load and image_load with both the 2D and array dimensions.
  • I ran ctest -C RelWithDebInfo -V -R "^d3d12_descriptor$" with Vulkan validation on. The AMD Radeon iGPU (32.0.21043.5001) and NVIDIA RTX 4090 (32.0.16.2101) each matched all 448 per-sample reference values. Both also passed the signed and unsigned integer read checks.

The descriptor test uses its own GLSL shader. Direct GPU execution of the new translated instruction remains unverified by this run. AI-assisted.

@timbot103

Copy link
Copy Markdown

Tested 9a0015c, merged onto main 561b65a, against main 561b65a on the same machine, on two GPUs: AMD Radeon Graphics (Ryzen 9000 iGPU, RDNA2, subgroup 32..64), AMD Windows driver 25.10.30.02, and NVIDIA RTX 5080 (32-wide only), driver 616.64. Windows 11 Pro 26200, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8. The test programs come from 561b65a (the PR changes no C++). I ran scripts/run_gpu_tests.py natively and with LEONIDA_W64_EMULATE=1: pass, no change from main.

No game files. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested 9a0015c merged with main 561b65a on Linux (WSL2), Python 3.12.16: pass

  • tests/semantic/test_image_msaa_load.py: 7 run, 6 passed, 1 skipped (needs spirv-as/spirv-val, absent on Linux). Rerun with the Windows spirv-as.exe/spirv-val.exe from the repo's tool folder on PATH through a small wrapper: 7 run, 7 passed, 0 skipped, so every translated variant is accepted by spirv-val --target-env vulkan1.2.
  • Full semantic suite with the ci: run the semantic suite one file per process on every CPU (405 s -> 83 s on 4 jobs) #4357 runner (scripts/run_semantic_tests.py --jobs 3, runner copied in untracked and removed afterwards): 434 files, 6157 tests, 0 files not ok (814 s; the machine was heavily loaded). Main's baseline (561b65a) is 433 files, 6150 tests, 0 not ok, so the delta is exactly the new file's 7 tests and no failing file set changes.
  • Negative control: the four tool files (rdna2spirv.py, rdna2_decode.py, wave64_emulate_opt.py, wave64_halves.py) checked out from main, new test kept: 7 run, 5 failures, 12 errors, 1 skipped; restored afterwards.

Not checked: the hardware meaning of image_msaa_load's dmask (the PR reads bits 0..3 as which consecutive samples of channel 0 to return); I have no RDNA2 measurement or ISA text here to confirm it, and nothing was run on a GPU.

@vanoizer

Copy link
Copy Markdown
Contributor

Tested 9a0015c on AMD gfx1036 (26.11.2) and RTX 4070 Ti SUPER (621.14), Windows 11: pass.

  • PR tests: test_image_msaa_load.py, 7 passed and 32 subtests.
  • semantic: 6157 OK.
  • GPU: AMD 215/232, 0 failed. NVIDIA 183/232 native and 214/232 emulated; the only failure is ms_wave_info_s3, the same as on main.

Setup: Windows 11. GPUs are an AMD Ryzen 7 9800X3D iGPU (RDNA2 gfx1036, driver 26.11.2, subgroup 32..64) and an RTX 4070 Ti SUPER (NVIDIA 621.14, subgroup 32). Each PR was tested in its own worktree with:

  • the PR's own tests (pytest);
  • python -m unittest discover -s tests/semantic;
  • scripts/run_gpu_tests.py three times: AMD native wave64, NVIDIA native, and NVIDIA with LEONIDA_W64_EMULATE=1.

Baseline is main 561b65a8:

Run Passed
AMD native 215/232, 0 failed
NVIDIA native 183/232, 1 failed
NVIDIA emulated 214/232, 1 failed

The NVIDIA failure is ms_wave_info_s3 (known, #5741).

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.