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
SweatierKey force-pushed the feat/image-load-mip-dims branch from 9bdb3c1 to 0662ad3 Compare November 23, 2026 03:57
@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.

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.

9 participants