Skip to content

rdna2spirv: image_load_pck, image_load_pck_sgn, image_load_mip_pck(_sgn): raw texel dwords, measured on RDNA2 - #3152

Open
Vonsek wants to merge 4 commits into
ItsNotRexed:mainfrom
Vonsek:feat/image-load-pck
Open

Vonsek wants to merge 4 commits into
ItsNotRexed:mainfrom
Vonsek:feat/image-load-pck

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: #2891 (comment)

What and why

image_load_pck, image_load_pck_sgn, image_load_mip_pck and image_load_mip_pck_sgn raised Unsupported. What they do was not clear from the ISA text, so I measured it on the Radeon (gfx1036, driver 26.10.1) with raw kernels through tools/hw_oracle (the T# kernel of tools/image_fuzz.py, wave32):

  • The result is the texel's memory bytes as dwords (little endian, zero padded), whatever the FORMAT's numeric type (UNORM, UINT, SINT and FLOAT give the same bytes) and whatever DST_SEL says.
  • dmask bit k selects dword k of the texel, not component k. The selected dwords go to consecutive VGPRs in ascending bit order; a dword past the texel's size is 0 (dmask 0x2 on a 4-byte texel gives 0, on a 16_16_16_16 texel its second dword).
  • _sgn sign extends dword 0 of a texel under 32 bits (1 byte from bit 7, 2 bytes from bit 15); 4-byte and bigger texels are the raw dwords.
  • The _mip forms with mip 0 are the same; an out of range coordinate gives 0 (all result VGPRs).

Translation: the typed fetch of image_load / image_load_mip (so the existing uint/sint/float views and lookup), then the components are put back into bytes with the FORMAT's own widths from a 512-entry table built from tools/gfx10_formats.json: integers masked, UNORM rounded back to the integer (exact for 8 and 16 bits), FLOAT16 narrowed, FLOAT32 as is. Only formats of 8, 16 or 32-bit components of those kinds are rebuilt; every other FORMAT (packed bit fields like 5_6_5 and 10_10_10_2, SNORM, sRGB, scaled, depth, block compressed) gives 0. The raw bits cannot be recovered exactly from the fetch (SNORM -128 and -127 both fetch as -1.0) and the runtime binds no raw integer view of an image; that is the limit of this approach and is in the docs/design.md row. d16, a16, glc, tfe and the 3D / array mip forms stay Unsupported. image_store_pck is not here: it is not the trivial mirror (it needs the forward conversion per format).

vk_store_test now also creates an rgba8 image (also viewed as R8G8B8A8_UINT), an R16G16B16A16_UINT and an R8_UINT image, filled in words mode, as elements 5..7 of the sampled array (the sampled array grew from 5 to 8 elements); the existing tests are unchanged (rerun, below).

Tested

  • tests/test_image_load_pck.py: the format table, the measured words through a model of the packing, translation of every form and dimension, the refusals, spirv-val. On main the module does not import (no table, the ops raise Unsupported).
  • GPU fixtures cs_imgpck_rgba8 (rgba8 as UNORM and as a UINT view, plain and mip form), cs_imgpck_rgba16 (dmask selecting dword 1, _sgn on an 8-byte texel) and cs_imgpck_r8 (8_UINT, zero and sign extension), every one of the 64 texels of the uint and sint image, formulas in the headers. On main all three fail to translate. With the change, on both GPUs (device lines NVIDIA GeForce RTX 5080 and AMD Radeon(TM) Graphics, selected with LEONIDA_VK_DEVICE): 3/3 exact.
  • Existing vk_store_test fixtures (cs_imgatomic, cs_imgatomic3d, cs_resinfo, cs_imgload, cs_imgload_d16, cs_imgstore) still pass on both GPUs.
  • Negative controls (each reverted): no sign extension in _sgn fails cs_imgpck_r8 (34 of 64 sint words, first word 1: 0x89 instead of 0xffffff89); every dmask bit taking dword 0 fails cs_imgpck_rgba16 (64 of 64, 0x6e5b4835 instead of 0xbaa79481); dropping the UNORM branch fails cs_imgpck_rgba8 (all zeros). All on both GPUs. Removing the +0.5 of the UNORM rounding does not fail on these values (they convert exactly).
  • python -m unittest discover -s tests/semantic 4142 tests OK (4 skipped); regen_fixtures.py --check, tests/test_shader_checks.py, tests/test_image_load_typed.py, tests/test_isa_coverage.py, tests/test_hw_oracle.py pass.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • The new translator rule is in the contract table of docs/design.md, with how it was confirmed (measured on gfx1036 and GPU fixtures).

AI-assisted.

…d image_load_mip_pck_sgn (measured on RDNA2)

Raw texel dwords, dmask bit k selects dword k, _sgn sign extends a texel under 32 bits. Rebuilt from the typed fetch for
8, 16 and 32 bit integer, UNORM and FLOAT formats; others give 0. GPU fixtures cs_imgpck_* through vk_store_test.

AI-assisted.
@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 data point. Tested head e75901f on Apple M2 (Mac14,3), macOS 26.4 (25E246), MoltenVK 1.4.2 (direct), subgroup 4..32, llvm-mc 23.1.6, Python 3.13.18.

python -I scripts/run_gpu_tests.py --filter imgpck --build runtime/build/linux: 3 shaders translated, 3 pass spirv-val; 3/3 passed — cs_imgpck_r8, cs_imgpck_rgba16 and cs_imgpck_rgba8 each "all 64 words of the uint image, the sint image and the volume exact". These fixtures do not translate on unpatched main here, so this is a real new result on an Apple GPU, adding to the NVIDIA and AMD runs in the PR body.

Build note: full build fails on AppleClang 17 at vk_pipeline_check.cpp:567 (BUILD-822, fixed by open PR #2927); all GPU binaries built, so the run above is valid. Head fetched unchanged into a separate worktree; no rebase/edit/push. Synthetic shaders and counts only; no game files.

AI-assisted.

@emirduran707

Copy link
Copy Markdown
Contributor

Tested e75901f on AMD Radeon RX 9060 XT (RDNA4), AMD driver 26.10.44 (LLPC, Vulkan driver 2.0.395), Windows 11 Pro 10.0.26300, subgroup 32..64: pass. The checks above have no AMD run from outside the author; this adds an AMD card with native 64-wide subgroups.

  • python -I scripts/run_gpu_tests.py --build <build> --filter <fixture>, one run per new fixture:
    • cs_imgpck_r8: PASS, all 64 words of the uint image, the sint image and the volume exact; same with LEONIDA_W64_EMULATE=1
    • cs_imgpck_rgba16: PASS, all 64 words of the uint image, the sint image and the volume exact; same with LEONIDA_W64_EMULATE=1
    • cs_imgpck_rgba8: PASS, all 64 words of the uint image, the sint image and the volume exact; same with LEONIDA_W64_EMULATE=1
  • Whole suite (native wave64): 197 shaders translated, 197 pass spirv-val; 178/192 passed, 14 skipped, 0 failed. The skips are the 14 fixtures the d3d12_* tests run.
  • build.py + check.py: 217 shaders: 217 translated, 217 pass spirv-val; 167 of 170 pass, 3 skipped; ok for cs_imgpck_r8, cs_imgpck_rgba16, cs_imgpck_rgba8.
  • CPU: tests/test_shader_checks.py 69 OK, tests/test_run_gpu_tests.py 34 OK, tests/semantic/regen_fixtures.py --check clean. I did not run the whole tests/semantic suite.

Test programs: built from this head with MSVC 14.44 (scripts\build_runtime.ps1), so the PR's C++ changes are in them; the translator, runner and check.py are this PR's too. llvm-mc 21.1.8 (native), Vulkan SDK 1.4.363.0. No negative control run here. No game files. AI-assisted (Claude Code).

@javdc

javdc commented Nov 22, 2026

Copy link
Copy Markdown

Tested e75901f on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass.

Python tests:

  • python3 tests/test_image_load_pck.py — 7/7 OK

Full GPU suite (built PR runtime in a separate build dir due to runtime/test/vk_store_test.cpp changes, then ran suite against that build):

  • python3 -I scripts/run_gpu_tests.py --build /home/deck/leonida-work/pr3152-build — 178/192 passed, 14 skipped, 0 failed (includes 3 new cs_imgpck_* fixtures). Skips are the expected D3D12-owned skips on this Deck.

AI-assisted (OpenCode).

@crastinator

Copy link
Copy Markdown
Contributor

Tested e75901f merged into main 16282101 (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New tests pass natively: cs_imgpck_r8 (all 64 words of the uint image, the sint image and the volume exact); cs_imgpck_rgba16 (all 64 words of the uint image, the sint image and the volume exact); cs_imgpck_rgba8 (all 64 words of the uint image, the sint image and the volume exact).
  • Whole run_gpu_tests.py: 178/192 native, 178/192 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 37/37.
  • tests/test_image_load_pck.py: 7 passed, 152 subtests passed.

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

@zzEmmazz

Copy link
Copy Markdown
Contributor

Tested e75901f7, applied alone on main 16282101: pass.
Windows 11 (26200), MSVC 14.50 (VS 2026), Ninja RelWithDebInfo. Two GPUs: Ryzen 7 9700X iGPU (RDNA2, AMD 32.0.21042.62) and RTX 3070 (NVIDIA 610.74), picked with LEONIDA_VK_DEVICE.

  • Tests and fixtures only (main's translator, the PR's vk_store_test): python -I tests/test_image_load_pck.py stops with AttributeError: type object 'Gen' has no attribute 'pck_format_table'; run_gpu_tests.py --filter cs_imgpck gives 0 of 3 translated on both GPUs (missing .spv (translation failed)).
  • Whole PR: tests/test_image_load_pck.py 7 OK. Runtime build OK. cs_imgpck_r8, cs_imgpck_rgba8, cs_imgpck_rgba16 PASS on both GPUs.
  • Whole GPU suite with the PR: Radeon 177/192 passed, 15 skipped; RTX 3070 145/192 passed, 46 skipped, 1 failed. Test by test the only difference from main is the three new PASS lines; 197 of 197 shaders translate and pass spirv-val.
  • Baseline on main 16282101: Radeon 174/189 passed, 15 skipped; RTX 3070 142/189 passed, 46 skipped, 1 failed (ps_sdwa_f16_const, which also fails there on clean main, 3 of 3 runs alone).
  • pytest tests/test_translate.py: 547 passed, 4 skipped. tests/test_shader_checks.py 69 OK, tests/test_run_gpu_tests.py 34 OK, tests/test_docs_design_rows.py OK.
  • Read, not measured: in Gen.image_pck_words, self.cf(0.5) if hasattr(self, 'cf') else '%fhalf_g' always takes the second branch, since Gen has no cf.

Not checked: the gfx1036 measurement the expected words come from (it needs native AMD execution, which was not done here; the GPU runs above execute the translated SPIR-V), and the complete tests/semantic suite. main moved to f847748c after this run and GitHub now reports the PR as conflicting with it; a rebase was not tested.

AI-assisted.
@iurysf

iurysf commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 56988e14 (merged with main f847748c; the earlier tests cite e75901f7) on RTX 4070 (Ada, NVIDIA 621.01, subgroup 32..32), Windows 11 (10.0.26300), llvm-mc 23.1.6 (AMDGPU), spirv-val from Vulkan SDK 1.4.363.1, Python 3.14.6: pass.

  • scripts/run_gpu_tests.py: 156/202 passed, 46 skipped, 0 failed (153/199 on f847748c; the +3 are cs_imgpck_r8, cs_imgpck_rgba8 and cs_imgpck_rgba16, each "all 64 words of the uint image, the sint image and the volume exact", with vk_store_test built from this head). pytest tests/test_image_load_pck.py: 7 passed, 152 subtests; tests/test_translate.py: 568 passed (562 on the base). The full tests/semantic suite: 7322 OK on both. The docs tests pass.
  • Negative control: with only tools/rdna2spirv.py restored to f847748c, the three cs_imgpck_* fixtures fail (missing .spv (translation failed)) and test_image_load_pck.py fails to collect ('Gen' has no attribute 'pck_format_table'); with the change they pass.

Not tested: wave64, AMD/Intel/Mesa/MoltenVK, the hardware oracle. Tested with AI assistance (Claude); synthetic programs only, no game data.

docs/design.md
tools/rdna2spirv.py

AI-assisted.
@Kev-Ball

Copy link
Copy Markdown

Tested 7191ec96 on an NVIDIA GeForce RTX 3080 Ti (32-lane subgroups), driver 620.73.04, CachyOS Linux 7.3.5-2-cachyos. I rebuilt the Vulkan harnesses from this revision and selected the NVIDIA device explicitly.

Ran the PR’s synthetic fixtures through scripts/run_gpu_tests.py --build runtime/build/linux --filter <fixture> --require-pass. All three shaders translated and passed Vulkan SPIR-V validation. GPU readback passed:

  • cs_imgpck_r8 — all 64 words of the uint image, the sint image and the volume exact.
  • cs_imgpck_rgba16 — all 64 words of the uint image, the sint image and the volume exact.
  • cs_imgpck_rgba8 — all 64 words of the uint image, the sint image and the volume exact.

AI-assisted verification with synthetic inputs.

docs/design.md
tools/rdna2spirv.py

AI-assisted.
@Etr0p

Etr0p commented Nov 23, 2026

Copy link
Copy Markdown

Tested 17007df (the current head, newer than the runs above) on AMD Radeon 610M (RDNA2 iGPU, AMD 26.11.2 / 32.0.21045.29003, subgroup 32..64) and NVIDIA GeForce RTX 5070 Ti Laptop GPU (Blackwell, 621.24, subgroup 32..32), Windows 11 Home 26200: pass.

Same laptop, one GPU at a time through LEONIDA_VK_DEVICE. Test programs (including the changed vk_store_test) rebuilt from this head with llvm-mingw 23.1.6; llvm-mc 23.1.6 (conda-forge), SPIRV-Tools v2026.4 (Vulkan SDK 1.4.363.0), Python 3.13.14.

scripts/run_gpu_tests.py (full) Result cs_imgpck_r8, cs_imgpck_rgba8, cs_imgpck_rgba16
Radeon 610M, native 198/220 passed, 22 skipped, 0 failed all three PASS: all 64 words of the uint image, the sint image and the volume exact
RTX 5070 Ti Laptop, native 173/220 passed, 47 skipped, 0 failed all three PASS, the same line
RTX 5070 Ti Laptop, LEONIDA_W64_EMULATE=1 204/220 passed, 16 skipped, 0 failed all three PASS, the same line

224 shaders translated, 224 pass spirv-val in each run. I did not run the CPU tests of this PR. One run of each. No game files. AI-assisted (Claude Code).

@junaydirfan

Copy link
Copy Markdown

Tested 17007df9 merged into main 98fa503f on Linux (CachyOS, kernel 7.3.5), llvm-mc 23.1.5, LEONIDA_W64_EMULATE=1, test programs built from the merge: pass.

GPU driver run_gpu_tests.py main
Intel Raptor Lake-S iGPU (Xe-LP), subgroup 8..32 Mesa ANV 26.3.1 189/220 passed, 31 skipped, 0 failed 186/217
RTX 4080 Laptop GPU (Ada), subgroup 32 NVIDIA 620.73.04 204/220 passed, 16 skipped, 0 failed 201/217

New in this PR:

  • cs_imgpck_r8: Intel PASS, all 64 words of the uint image, the sint image and the volume exact; RTX 4080 PASS, all 64 words of the uint image, the sint image and the volume exact
  • cs_imgpck_rgba16: Intel PASS, all 64 words of the uint image, the sint image and the volume exact; RTX 4080 PASS, all 64 words of the uint image, the sint image and the volume exact
  • cs_imgpck_rgba8: Intel PASS, all 64 words of the uint image, the sint image and the volume exact; RTX 4080 PASS, all 64 words of the uint image, the sint image and the volume exact

Every other test has the same result as on main on both GPUs.

@lunarminus

Copy link
Copy Markdown

Tested 17007df9 merged onto main d0835dd9 on an AMD Radeon 760M (RDNA3 iGPU, gfx1103, subgroup 32..64), RADV Mesa 26.3.1, CachyOS Linux: fail (merge-conflict markers are committed in docs/design.md, which fails tests/test_docs_table_rows.py; the GPU side passes)

  • The merge was a fast-forward. 17007df9 already contains main through 0db7fed5, so the tested tree is the head itself. I rebuilt the runtime from it, so this PR's vk_store_test changes are in the test programs.
  • Failing: docs/design.md lines 376–383 still hold <<<<<<< HEAD / ======= / >>>>>>> upstream/main from the 56988e14 "Merge upstream/main" commit. They are still there in 7191ec96 and 17007df9. Neither parent of 56988e14 has them. The HEAD side has the "Typed image loads" row unchanged from the merge base, as it was before main rewrote it, plus this PR's new image_load_pck row. The upstream/main side has main's rewritten "Typed image loads" row plus the "Packed 2D mip-load addresses" and "3D explicit-mip loads" rows. Both "Typed image loads" rows are in the file now. python -I tests/test_docs_table_rows.py fails with docs/design.md:377: table row without a table header. It passes on d0835dd9 and on 0db7fed5. A fix probably keeps main's three rows, adds the new image_load_pck row, and drops the markers and the older row.
  • scripts/run_gpu_tests.py: 205/220 passed, 15 skipped, 0 failed, both natively and with LEONIDA_W64_EMULATE=1. 224 shaders translated and 224 passed spirv-val in each run. The device line is AMD Radeon 760M Graphics (RADV PHOENIX) (subgroup 32..64).
  • Per-test comparison with d0835dd9 without the PR (196/210 passed, 14 skipped in each mode): all 210 result lines of that baseline show the same PASS/SKIP result in the PR run, in both modes. Ten tests are not in that baseline. Three come from this PR: cs_imgpck_r8, cs_imgpck_rgba16 and cs_imgpck_rgba8, all PASS. The other 7 came with main after d0835dd9: cs_smem_sconst_off, ps_far_branch, ps_sample_c, ps_sample_c_b, ps_texture_cl and ps_texture_b_cl PASS, and ps_m2_literal is SKIP (run by d3d12_m2_textured_test).
  • run_gpu_tests.py --filter imgpck --require-pass: 3/3 passed in both modes (3 translated, 3 pass spirv-val). Each fixture printed all 64 words of the uint image, the sint image and the volume exact.
  • CPU tests:
    • tests/test_image_load_pck.py: 7 passed, 152 subtests (pytest), and 7 OK with python -I.
    • tests/test_image_load_typed.py: 23 OK. tests/test_shader_checks.py: 79 OK. tests/test_isa_coverage.py: 20 OK, 4 skipped. tests/test_hw_oracle.py: 45 OK, 3 skipped.
    • tests/semantic/regen_fixtures.py --check: exit 0, no output. discover -s tests/semantic -p 'test_image*.py': 42 OK.
    • The other tests/test_docs_*.py files pass, test_docs_design_rows.py included.
  • python -m unittest discover -s tests/semantic: 6245 tests, failures=3, errors=2, skipped=1, expected failures=1. All five are wave64-emulate cases in test_loop_ballot_barrier.py. The same 3 failures and 2 errors appear on 0db7fed5 without this PR, so this PR did not cause them.
  • Not run: the gfx1036 hardware-oracle measurement behind the expected words, since this is RDNA3 and not native RDNA2 execution, and no negative control.

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

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.