Skip to content

rdna2spirv: extend image_load_mip to 1D, 2D, 2D_ARRAY, CUBE, and 3D with a16 and d16 - #4206

Open
SweatierKey wants to merge 2 commits into
ItsNotRexed:mainfrom
SweatierKey:feat/image-load-mip-dims
Open

SweatierKey wants to merge 2 commits into
ItsNotRexed:mainfrom
SweatierKey:feat/image-load-mip-dims

Conversation

@SweatierKey

Copy link
Copy Markdown
Contributor

Claimed in #4084 (claim).

What and why

image_load already supports all five sampled image dimensions (1D, 2D, 2D_ARRAY, CUBE, 3D) with a16 packed unsigned 16-bit coordinates and d16 packed 16-bit results through image_load_typed (bindings 0, 3, 5, 6; no storage-image capability). image_load_mip was split into two ad-hoc paths in Gen.image_misc (2D with/without a16, and 3D only without a16) and raised Unsupported on 2D_ARRAY, 3D a16, 1D, and CUBE, while also accidentally setting uses_query = True (OpCapability ImageQuery) on 2D image_load_mip.

Change

  • tools/rdna2spirv.py (Gen.image_load_mip / Gen.image_misc): unified all image_load_mip handling into Gen.image_load_mip:
    • supports SQ_RSRC_IMG_1D (binding 5, x, mip), SQ_RSRC_IMG_2D (binding 0, x, y, mip), SQ_RSRC_IMG_2D_ARRAY (binding 3, x, y, slice, mip), SQ_RSRC_IMG_CUBE (binding 3 via 2D_ARRAY view, x, y, face, mip), and SQ_RSRC_IMG_3D (binding 6, x, y, z, mip);
    • handles both 32-bit and a16 packed unsigned 16-bit coordinate+mip operands via unpack_image_a16_uints, and both 32-bit and d16 packed outputs via image_load_typed;
    • keeps glc, tfe/lwe status returns, short coordinate lists, and dimensions without sampled bindings (1D_ARRAY, etc.) refused as Unsupported;
    • no longer sets spurious OpCapability ImageQuery on image_load_mip.
  • tests/semantic/test_image_load_mip_dims.py: verifies all 5 dimensions × (32-bit, a16) × (normal, d16) for bindings, SPIR-V image dims, float/uint/sint typed fetch aliases, coordinate/LOD extraction, absence of storage-image / ImageQuery capabilities, spirv-val --target-env vulkan1.2 validity, and refusal of unsupported forms.

Tested

Linux (WSL2), Python 3.13.5, spirv-as + spirv-val --target-env vulkan1.2 on PATH, CPU only, no game files:

  • tests/semantic/test_image_load_mip_dims.py: 3/3 OK (20 valid sub-cases all validated by spirv-val + 7 refused sub-cases)
  • tests/test_image_load_typed.py: 21/21 OK
  • tests/test_image_query_translate.py: 10/10 OK
  • tests/semantic/test_image_coherent.py: all OK
  • tests/test_semantic_translator_use.py (3/3), tests/test_text_write_line_endings.py (3/3), tests/test_text_encoding.py (2/2): all OK.

@CaravelaLabs

Copy link
Copy Markdown
Contributor

Automated test: d89648d2 merged onto main aa2988cc on AMD Radeon 8060S (RADV GFX1151, RDNA 3.5), Mesa 25.2.8, Ubuntu 24.04, runtime rebuilt from this branch in a clean sandbox. Result: pass.

  • scripts/run_gpu_tests.py: 192/209 passed, 15 skipped (plain main: 192/209 passed, 15 skipped).
  • Python tests this PR touches: 3 passed, 27 subtests passed.

Same machine and setup as my earlier manual reports. AI-assisted (Claude Code).

@requiemsnkrp

Copy link
Copy Markdown

Tested d89648d2 (merged onto main aa2988cc) on NVIDIA GeForce RTX 3060, driver 32.0.16.1714, Windows 11, MSVC 19.51, Vulkan SDK 1.4.363.0: pass for the CPU and translation checks. No GPU fixture uses image_load_mip, so none of the new forms ran on the GPU.

  • With SDK spirv-as/spirv-val and llvm-mc 21: tests/semantic/test_image_load_mip_dims.py Ran 3 tests ... OK; tests/test_image_load_typed.py Ran 21 tests ... OK; tests/test_image_query_translate.py Ran 10 tests ... OK.
  • runtime/test/shaders/*.asm has no image_load_mip fixture. The nearest GPU check (run_gpu_tests.py --filter mip) gives PASS ps_texture_mip0 two passes, 4096 RGBA32F pixels each exact, but that fixture does not use the instruction this PR changes.
  • Full ctest (-E "present|swapchain|frame_pacer", LEONIDA_VK_VALIDATION=1, llvm-mc build, fixtures translated by this rdna2spirv.py): 100% tests passed, 0 tests failed out of 148 (9 skipped/disabled, same set as main: shader_library_corpus, bink_decode, bink_play_headless, fsr_dispatch, bvh_builder, bink_audio, gameinput, d3d12_rgb9e5_rtv, d3d12_first_light).

AI-assisted (Claude). No game files.

@ray3242

ray3242 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

At d89648d this refuses forms that main (aa2988c) translates. The new image_load_mip() raises Unsupported("image_load_mip status") for every tfe/lwe. On main, those forms went through image_load_typed: the 2D path's packed_mip only excluded tfe/lwe together with a16, and the 3D path only refused d16 with status.

Translated with support.translate_lines (a pixel shader that stores v[0:3]):

line main #4206
image_load_mip v[0:4], v[4:6], s[0:7] dmask:0xf dim:SQ_RSRC_IMG_2D tfe translated Unsupported
... dim:SQ_RSRC_IMG_2D lwe translated Unsupported
image_load_mip v[0:4], v[4:7], s[0:7] dmask:0xf dim:SQ_RSRC_IMG_3D tfe translated Unsupported
image_load_mip v[0:2], v[4:6], s[0:7] dmask:0xf dim:SQ_RSRC_IMG_2D d16 tfe translated Unsupported
... dim:SQ_RSRC_IMG_2D a16 tfe Unsupported Unsupported

No semantic test on main uses image_load_mip with tfe/lwe, so the suite doesn't catch this. Translated counts could drop on the corpus, though, which AGENTS.md treats as a regression. Keeping main's rule would avoid that: refuse status only with a16, and with d16 on 3D. Otherwise, a before/after count over a work folder would show whether any shader uses these forms.

Otherwise the full tests/semantic run at this head has the same 23 failures and 2 errors as the other heads I ran today on this VM, which all come from its old SPIR-V tools. Also, merged locally with #3932 (SHADER-715), tools/rdna2spirv.py combines without conflict, and the LDS tests plus test_image_load_mip_dims pass (30 tests). CPU only, Python 3.12, no GPU.

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

The mip-dependent coordinate mapping and A16 packing are consistent with the RDNA3 instruction layout, and the existing typed-load helper is reused for D16. The translator and semantic test coverage is strong; I found no blocker. There is not yet a direct GPU fixture for image_load_mip, so runtime behavior remains unverified end to end.

@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 no-regression check at head d89648d (macOS 26.4, MoltenVK 1.4.2 direct, subgroup 4..32, llvm-mc 23.1.6, clean full build exit 0 on AppleClang 17).

python -I scripts/run_gpu_tests.py --build runtime/build/linux: 213 shaders translated, 213 pass spirv-val; 127/210 passed, 76 skipped, 7 failed — identical to upstream/main aa2988c on this same M2, and all seven are the known MoltenVK expected failures listed in PR #2909 (cs_fma_fused, ps_ssharp, ps_vcmp_f16/e64, ps_vcmp_f32_nan, ps_vcmpx_f16/e64). No new failure and no new skip from this change.

As requiemsnkrp noted, no GPU fixture uses image_load_mip, so the new dimensions are not exercised by this run; this is a no-regression data point only. Head fetched read-only, no rebase/edit/push. Synthetic shaders and counts only; no game files.

AI-assisted.

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

AI-assisted Windows CPU review at d89648d2. WSL LLVM 21.1.8 assembled 20 new gfx1030 fixtures across dimensions and A16/D16 modes. Six translated on the exact parent and all 20 on this head, with every emitted module passing Vulkan 1.2 validation. Tracing the actual FLOAT/UINT/SINT fetch operands gave packed 2D (21, 32786) at LOD 3, ignoring the unused high half, and packed 3D (33, 57, 32817) at LOD 5. Stubbed-texel CPU checks also confirmed integer saturation and preservation of the final D16 destination's high half.

A scratch merge with #3045 at e34b0c7b resolved the one conflict by keeping the unified mip helper and emitting the sampled access with self.dynamic_sampled_access(ip, f"%{iptr}", iarr, idx). All 20 CLI modules validated and all 20 metadata entries reported SampledImageArrayDynamicIndexing and shaderSampledImageArrayDynamicIndexing. Scratch tree dc25315af4b8b645c233ea8c30a3a9006d8490f1.

Please update the design-contract rows with the expanded dimension, mip and binding layouts and their test basis. For the status behavior already reported, two LLVM-assembled D32 TFE probes confirmed that the parent translates while leaving the seeded status word untouched, and this head rejects them. That distinction is worth recording. Full semantic discovery showed the same seven failures and two errors as the parent. No native texture readback was measured.

@SweatierKey

Copy link
Copy Markdown
Contributor Author

Thank you @CaravelaLabs, @requiemsnkrp, @ray3242, @bobcatchris, @Flyander, and @whattheflop for the thorough checks and reviews!

Addressed @ray3242's and @whattheflop's feedback in 9bdb3c11:

  • No corpus regression on tfe/lwe: Gen.image_load_mip now preserves main's exact status-modifier rule (refusing tfe/lwe only with a16 or 3D d16, and translating non-a16 status forms like 2D tfe/lwe, 2D d16 tfe, and 3D tfe unchanged — leaving the status word unwritten). Added test_status_modifier_compatibility_matches_main and expanded test_refused_forms_stay_unsupported in tests/semantic/test_image_load_mip_dims.py (4/4 OK with spirv-val).
  • Design contract: updated docs/design.md with the expanded image_load_mip 1D/2D/2D_ARRAY/CUBE/3D, a16/d16, binding, and tfe/lwe rules and verification basis (test_docs_links.py, test_docs_repo_paths.py, test_text_write_line_endings.py, test_text_encoding.py all pass).

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

The design-contract update is in place at 9bdb3c11, and all four revised mip-dimension tests passed from the exact tracked tree on Windows with uv CPython 3.12.13. Both A16+D16 2D-array fragment binaries rebuilt byte-for-byte, including the #3045 variants used for the RTX 3080 readback. The two draws matched all 4,096 pixels each, including the mip-0 control, with zero core or synchronization validation diagnostics.

One status corner remains. The follow-up preserves acceptance for the five tested legacy 2D/3D cases, but also accepts TFE for 1D, 2D-array and cube where both the parent and the original PR refused it. In four LLVM-assembled probes (including 2D-array+D16), the validated SPIR-V left the seeded status VGPR at 0x11223344. Could the compatibility exception stay limited to the legacy 2D/3D forms unless the newly accepted dimensions implement the status result? That retains the previous coverage without extending the unwritten result. Status checks were offline only. AI-assisted.

@ray3242

ray3242 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Re-tested at 9bdb3c1: the tfe/lwe regression is fixed. On all six forms from my table, main and this head now give the same result. 2D tfe, 2D lwe, 3D tfe and 2D d16 tfe translate; 2D a16 tfe and 3D d16 tfe stay Unsupported (only the message changed, to image_load_mip status). tests/semantic/test_image_load_mip_dims.py passes 4/4. Thanks.

AI-assisted (Devin), CPU-only.

@akimfomin

Copy link
Copy Markdown

Independent image readback on Windows 11 build 28000, RTX 4070 Ti SUPER / NVIDIA 617.14, exact head 9bdb3c110e99775810206740e09831bbb651075b against main aa2988cc. The synthetic shaders execute image_load_mip and translate to OpImageFetch with explicit Lod.

  • Ordinary 2D: 40/40 cases passed on each version. RGBA8_UNORM and RGBA8_SINT, four A32/A16 × D32/D16 combinations, four locations in mip 0 and a distinct mip 1. Each case matched 4,096 expected pixels. All 40 readbacks were byte-identical between the versions.
  • 2D_ARRAY: 40/40 cases passed on the PR across both layers and mip levels with the four coordinate/result combinations. A scratch variant of vk_texture_test supplied a real two-layer, two-mip image at binding 3 with distinct colors for layer and LOD. Main rejected all 40 identical inputs with Unsupported: image_load_mip 2D_ARRAY.
  • All 120 emitted fragment modules passed Khronos spirv-val --target-env vulkan1.2. The four formerly accepted legacy status cases also translated and validated at main and this head. The earlier PR head d89648d2 rejected all four. The remaining status-output corner raised in review is outside the GPU cases above.

GPU coverage is limited to these 2D and 2D-array fixtures. No Vulkan validation layer enabled during rendering. Synthetic inputs only. AI-assisted.

@SweatierKey

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto main (2d3369a4, head 0662ad32), keeping main's emit_image_atomic_extra, glc rejection, and docs/design.md updates intact.
Verified: test_image_load_mip_dims.py + test_image_load_typed.py + test_image_query_translate.py 37/37 OK with spirv-val.

@Kev-Ball

Copy link
Copy Markdown

Tested 0662ad32 on RTX 3080 Ti, NVIDIA 620.73.04, CachyOS Linux. The 3D image_load_mip readback passed for both A32 and packed A16 coordinates with a full-width RGBA result. All 12 fragment modules passed Vulkan 1.2 SPIR-V validation. Each draw matched the expected texel across 4,096 pixels, and each A16 frame was byte-identical to its A32 control.

Reproduction details: I adapted a scratch copy of vk_texture_test to expose an RGBA8_UNORM 3D sampled image at binding 6, descriptor index 1, with mip extents 4×4×4 and 2×2×2. At coordinate (x,y,z,lod) the uploaded RGBA bytes were (32+x,64+y,96+z,160+lod). I tested (3,0,2,0), (0,2,3,0), (1,0,0,1), (0,1,1,1), (1,0,1,0), (1,0,0,0). This independently varies Z and LOD while holding the other coordinates fixed. For A16 the two address VGPRs held x | y<<16 and z | lod<<16. The unmodified PR translator emitted the shaders; the readback checked every RGBA32F channel against the expected byte divided by 255 (absolute tolerance 1e-7).

AI-assisted; synthetic textures and instruction listings.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 0662ad3 merged with main de67135 on Linux, Python 3.12.16: pass

tests/semantic/test_image_load_mip_dims.py: 4 tests OK. Related: tests/test_image_load_typed.py 23 OK (2 skipped), semantic test_image_coherent.py 4 OK, test_mem_crash_forms.py 1 OK. tests/test_image_load_d16_typed.py cannot be run with python -I here (ModuleNotFoundError: conftest), unrelated to the PR. Negative control (tools/rdna2spirv.py from main, new test kept): 2 failures, 14 errors, so the test demonstrates the change. spirv-as/spirv-val are not installed on Linux, so the test's spirv-val step is skipped in this run; the "validated with spirv-val" claim in docs/design.md was not exercised by me. Semantic tests only, no GPU.

@kapitche

kapitche commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Tested 42eae3a merged with main 561b65a on Linux (WSL2), CPython 3.12.16, CPU only: pass.

  • tests/semantic/test_image_load_mip_dims.py: 4/4 on Linux (spirv-val not on PATH there, so validation skipped); 4/4 on native Windows, CPython 3.13.1, with spirv-as/spirv-val on PATH (validation active); tests/test_image_load_typed.py: 23 (2 skipped); tests/test_image_query_translate.py: 10/10.
  • Full semantic parity with the ci: run the semantic suite one file per process on every CPU (405 s -> 83 s on 4 jobs) #4357 runner (copied to scratch, --jobs 4): main 433 files / 6150 tests, 0 files not ok; merged 434 files / 6154 tests, 0 files not ok.
  • Negative control: with main's tools/rdna2spirv.py the new test fails (failures=2, errors=14).
  • No GPU run: the PR itself says dedicated GPU fixtures for the non-2D forms are not added, and none ran here.

@lunarminus

Copy link
Copy Markdown

Tested 42eae3ad merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: pass

  • Base: the merge onto d0835dd9 was a fast-forward. 42eae3ad already contains main through 561b65a8, so the tree I tested is the PR head itself: 561b65a8 plus this PR's two commits. The PR changes nothing under runtime/ or scripts/, so I used a runtime build of 561b65a8, which has the same sources.
  • CPU tests, with spirv-as/spirv-val (SPIRV-Tools v2026.4) on PATH and LEONIDA_AMD_CLANG=/usr/bin/clang:
    • tests/semantic/test_image_load_mip_dims.py: 4/4 OK. A wrapper counted 24 spirv-as and 24 spirv-val runs, none failing, so the validation step really ran.
    • tests/test_image_load_typed.py: 23/23 OK.
    • tests/test_image_query_translate.py: 10/10 OK.
    • unittest discover -s tests/semantic -p 'test_image*': 50 OK.
    • pytest tests/test_image_load_d16_typed.py: 6 passed.
  • Full tests/semantic: 6154 tests OK (skipped=1, expected failures=1), against 6150 OK with the same skip and expected-failure counts at 561b65a8 without the PR. The difference is the PR's 4 new tests.
  • scripts/run_gpu_tests.py, plain and with LEONIDA_W64_EMULATE=1: 238 shaders translated, 238 pass spirv-val, 216/232 passed, 16 skipped, no failures in either mode.
  • Per-test comparison:
    • Against 561b65a8 without the PR, both modes: identical result on every test.
    • Against d0835dd9 without the PR (196/210, 14 skipped): no test changed result. The 22 tests missing from that run came in with main after d0835dd9, not with this PR. 20 of them pass; ps_live_width and ps_m2_literal skip.
  • GPU coverage: no fixture under runtime/test/shaders uses image_load_mip, so the new 1D, 2D-array, cube, 3D and a16/d16 forms did not run on this GPU. For this change, the GPU run only shows that nothing else regressed. Nobody in the thread named an AMD- or 32-wide-specific command, so I ran nothing more.

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

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested 42eae3a merged onto main 561b65a on Apple M4, macOS 27.2.1, Python 3.15.2 and 3.12.16: pass. There are two small follow-ups below; neither blocks.

  • The merge onto 561b65a is clean. The rebase now uses main's dynamic_sampled_access (rdna2spirv: support 1D, 3D, CUBE, and a16 in image_get_lod #5338), so it fits with that change. I translated a 60-form matrix: 5 dims × 32-bit/a16 × ±d16 × none/tfe/lwe. Every one of the 40 accepted forms declares SampledImageArrayDynamicIndexing, and the 1D forms also declare Sampled1D. The CLI index lists shaderSampledImageArrayDynamicIndexing for 1D, 2D_ARRAY a16 d16, CUBE and 3D a16. All 40 pass spirv-val with vulkan1.2 and vulkan1.3.
  • No regression against main. Every form main translates still translates. For 2D, the only change in the output is the dropped OpCapability ImageQuery. For 3D, only the ID numbering changes. image_get_resinfo output is byte-identical.
  • I checked the a16 layout with LLVM 23.1.6 llc -mcpu=gfx1030 on llvm.amdgcn.image.load.mip.{1d,2d,2darray,cube,3d} with i16 coordinates. 1D packs (x, mip) into one VGPR. 2D packs (x, y) and (mip, unused). 2D_ARRAY, CUBE and 3D pack (x, y) and (slice/face/z, mip). In each word the first value is in the low half. This matches Gen.image_load_mip. OpImageFetch … Lod only ever gets a non-MS, non-Cube image, because CUBE goes through the 2D-array view with the face as the layer, the same as main's image_load.
  • Tests:
    • On both Pythons: test_image_load_mip_dims.py 4 OK, tests/test_image_load_typed.py 23 OK, tests/test_image_query_translate.py 10 OK, test_sampled_dynamic_index 6 OK, test_image_coherent 10 OK, test_mem_crash_forms 1 OK.
    • compileall and git diff --check are clean.
    • Semantic suite: Ran 6154 tests, OK (skipped=1, expected failures=1); main 561b65a is Ran 6150, OK (skipped=1, expected failures=1). The extra 4 are the new tests, and there are no failures or errors on either side.
  • Corpus slice (shard 0/64): 415 translated, 415 spirv-val-valid, the same as main. 1 of the 415 .spv files differs from main, because of the ImageQuery capability. Over the whole corpus, image_load_mip occurs 726 times in 259 shaders. All of those are 2D or 3D, with no a16, d16, tfe or lwe, so the game doesn't reach the new forms yet.
  • I ran 12 mutations: 10 caught, 1 survived, 1 equivalent. Caught: wrong LOD operand, swapped a16 halves, status refusal removed, every status refused, ImageQuery re-added, 3D on the 2D-array binding, cube on the 2D binding, one packed word too few, short-address check removed. Ignoring d16 on every dimension was caught too, but only by the existing 2D test in test_image_load_typed.py.
  • Survived: ignoring d16 on 1D/2D_ARRAY/CUBE/3D. Then the d16 subcases write v0..v3 unpacked, and all tests still pass. test_all_five_dims_* checks the fetches but not which VGPRs get written. Fix: for the d16 subcases, assert that the stores land only in v0..v1, using the same OpStore %vgpr check as test_2d_explicit_mip_d16_packs_only_selected_components. The equivalent one dropped the dynamic-index helper, which changed nothing: the typed aliases still set the capability.
  • Still open from the review at 9bdb3c1: tools/rdna2spirv.py:12651 accepts tfe/lwe on 1D, 2D_ARRAY and CUBE without a16. That is 12 forms, including d16 tfe. Main refused them, and with this change the status VGPR is left unwritten. That matches main's plain image_load, which also leaves it unwritten. But docs/design.md:395 says these forms "otherwise translate like main", and for these dims they didn't translate at all on main. No shader in the corpus uses them. Either limit the exception to 2D/3D, or write 0 to the status VGPR, and then reword that sentence.
  • GPU: no fixture in runtime/test/shaders uses image_load_mip. The only other path this touches, image_get_resinfo, translates byte-identically. So I ran nothing on the M4 for this PR.

AI-assisted.

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.