Skip to content

GPU tests for the MIMG ops that had none: image atomics, image_get_resinfo, image_get_lod, 32-bit BVH (TEST-184) - #1419

Merged
ItsNotRexed merged 6 commits into
ItsNotRexed:mainfrom
aslan2142:test-184-image-ops
Nov 22, 2026
Merged

ItsNotRexed merged 6 commits into
ItsNotRexed:mainfrom
aslan2142:test-184-image-ops

Conversation

@aslan2142

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: TEST-184 (claim)

What and why

The translator handles the image atomics, image_get_resinfo, image_get_lod and the 32-bit image_bvh_intersect_ray, but no test ran them (@Vonsek's inventory). This adds six hand-written fixtures. No translator change was needed: every word came out as derived.

Fixture Runs on Checks
cs_imgatomic vk_store_test words all ten atomics on a 2D r32 uint image, 17 cases
cs_imgatomic3d vk_store_test words six cases on a 4x4x4 volume (the separate 3D path)
cs_resinfo vk_store_test words a 16x4 image with five mip levels
ps_get_lod vk_texture_test --two-mip, two draws clamped and calculated LOD, 2D
ps_get_lod_array vk_texture_test the same on a 2D array
cs_bvh32 vk_compute_test bvh the 11-dword address form, on the scene of cs_bvh
  • The expected words are derived in each .asm header from the RDNA2 ISA definition of the instruction, not from translator output.
  • Atomics: 0xfffffff0 separates the signed min/max from the unsigned ones, and each of the four has a case that goes the other way. cmpswap hits and misses. One op runs without glc, so the data register must keep its operand. 63 lanes are off in the single-thread cases, and 64 threads add 1 to one texel.
  • image_get_resinfo: levels 0, 1 and 3 in full (the height stays 1 at level 3), then dmask 0x3, 0xa and 0x8 for the packing.
  • image_get_lod: calculated LOD 1 and 3 on the two-mip texture. The clamped LOD stops at the last level, and at 0 under a sampler MAX_LOD of 0.25. On the one-level array: 2 and -3.

Harness changes:

  • vk_store_test gets a words mode: it fills the two r32 images and a small r32 uint volume and prints all three after the dispatch; check.py holds the expected words. It now also binds the uint image and the volume as r32ui storage images (bindings 4 and 7, where atomics address their image) and a 16x4 five-level image behind the T# that gfx10_descriptors.h writes for it. cs_imgstore, cs_imgload and cs_imgload_d16 run as before.
  • vk_compute_test, in its own commit: the bvh mode wrote its BVH past the end of its 256-byte heap buffer, so cs_bvh read outside the buffer on main (VUID-RuntimeSpirv-PhysicalStorageBuffer64-11819 under GPU-assisted validation). The heap is now large enough; the result words are unchanged.
  • docs/design.md: one contract row for these ops, with how they are confirmed and what is still unverified. The ray tracing row names cs_bvh32.

Not covered:

  • The order of u and v in image_get_lod: the tool's textures are square, where it makes no difference.
  • image_get_resinfo's depth word on hardware: 1 follows from the T#'s DEPTH field.
  • The atomics under --wave64-emulate: the fixtures are wave32, like cs_bvh and cs_imgstore, so LEONIDA_W64_EMULATE=1 translates them the same way.

Overlap with #1402

#1402 was opened for the same item while this branch was being tested; the coordinator's ruling on the claim is here. The two cannot both merge as they are: both add cs_imgatomic.asm, ps_get_lod.asm and cs_bvh32.asm, and both edit vk_store_test.cpp and the same registries.

Tested

Head 174cad2f: the branch's two commits (b9864d27, 05eb9ca9) with main c2967a5e merged in. Linux, Mesa 26.3.1, llvm-mc 23.1.5, LEONIDA_VK_VALIDATION=1.

GPU Driver native LEONIDA_W64_EMULATE=1 main (c2967a5e) before
Radeon RX 7900 XTX (RDNA3) RADV 141/141 141/141 not run
Ryzen 9 7950X3D integrated (RDNA2) RADV 141/141 141/141 135/135, 135/135
llvmpipe (LLVM 23.1.5) Mesa 92/141, 49 skipped 59/73, 14 skipped (--filter cs_, as CI) 86/135, 49 skipped; 55/69, 14 skipped
  • Translator: 145 shaders, 145 translated, 145 pass spirv-val (139, 139, 139 before).
  • The six new tests pass in every run that selects them. llvmpipe skips the same tests as on main.
  • Validation: the new fixtures and cs_bvh under the Khronos layer with GPU-assisted validation, on the integrated GPU and on llvmpipe: 0 errors.
  • Mutations: 22 result-only changes to a scratch copy of the translator, each run against its fixture: signed and unsigned min/max exchanged, add for sub, cmpswap operands swapped, the old value returned without glc, a wrong operand for inactive lanes, 3D coordinates swapped, resinfo width and height swapped, its level ignored, its depth, its dmask packing, LOD components swapped, the fallback sampler, BVH sorting off, t max from the wrong register. 21 fail the fixture. The u/v swap in image_get_lod does not (see above). These ran before main was merged in; the fixtures' SPIR-V is byte-identical after the merge.
  • CPU: compileall; all 151 standard-library test files; pytest tests --ignore=tests/semantic: 3517 passed, 37 skipped; unittest discover -s tests/semantic: 1194 tests OK.
  • Not tested here: MSVC (GCC 16.2, plus clang and mingw syntax checks) and llvm-mc 18, which CI's llvmpipe job uses (assembled with 23.1.5 and 21.1.8).

A host quirk the LOD test steps around: llvmpipe 26.3.1 does not apply a sampler's LOD range to OpImageQueryLod when its minimum and maximum are equal (0..0 gave level 1, RADV gives 0). The second draw uses 0..0.25, where both agree.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (No new rule: the row added documents the existing ones and how these tests confirm them.)

AI-assisted (Claude Code, Claude Fable 5.2).

🤖 Generated with Claude Code

aslan2142 and others added 3 commits November 22, 2026 05:43
The "bvh" mode writes its nodes at heap offsets 0x100 to 0x264, but with one
group the heap buffer is 64 words, 256 bytes. The host wrote past the mapped
range and the shader read the nodes through the buffer device address outside
the buffer. It worked because the memory allocation is larger than the buffer.

GPU-assisted validation reports it for cs_bvh on current main:
VUID-RuntimeSpirv-PhysicalStorageBuffer64-11819, "trying to read 4 bytes at
[..220, ..223) but this range does not belong to any buffer", the buffer being
256 bytes. The heap is now at least 0x280 bytes in this mode. The eight result
words are unchanged, and both BVH fixtures are clean under core and
GPU-assisted validation on RADV (RDNA2 integrated GPU) and llvmpipe.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The translator handles the image atomics, image_get_resinfo, image_get_lod
and the 32-bit image_bvh_intersect_ray, but no test ran them. Six hand-written
fixtures now do, with the expected words derived in each header from the
RDNA2 ISA definition of the instruction:

- cs_imgatomic: add, sub, and, or, xor, smin, smax, umin, umax and cmpswap on
  a 2D r32 uint image. 0xfffffff0 tells the signed min/max from the unsigned
  ones, each with a case that goes the other way; cmpswap hits and misses; one
  op runs without glc; 63 lanes are off; 64 threads add to one texel.
- cs_imgatomic3d: six cases on a 4x4x4 volume, the 3D path of the translator.
- cs_resinfo: a 16x4 image with five levels: levels 0, 1 and 3 in full, then
  dmask 0x3, 0xa and 0x8.
- ps_get_lod, ps_get_lod_array: calculated LOD 1 and 3 on the two-mip
  texture, the clamped LOD held by the last level and by the sampler's
  MAX_LOD; 2 and -3 on the one-level 2D array.
- cs_bvh32: the scene of cs_bvh through the 11-dword address form.

vk_store_test gets a "words" mode for the compute ones: it also binds the
uint image and a small volume as r32ui storage images (bindings 4 and 7) and
a 16x4 five-level image behind its real T#, fills the images and prints them;
check.py holds the expected words. The other two run on vk_texture_test and
vk_compute_test as they are.

All pass on an RX 7900 XTX and a Ryzen 9 7950X3D integrated GPU (RADV, Mesa
26.3.1) and on llvmpipe, natively and with LEONIDA_W64_EMULATE=1, and are
clean under the validation layer. No translator change was needed.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
main is at c2967a5, 120 commits past the branch's base. Two conflicts, both
sides kept:

- docs/design.md: main added a third "Typed image loads" row at the place
  where this branch adds its "Image atomics, size and LOD queries" row. Main's
  row first, then this branch's.
- tests/test_shader_checks.py: main counts one more check (cs_fmt_xy_xyz,
  TEST-185: 2 -> 3) on the line next to this branch's comment change. Main's
  count with this branch's comment; the STORE_WORDS and GET_LOD_TESTS terms
  stay.

Nothing from main overlaps the new fixtures: TEST-185 and cs_w64x_andn2_exec
run through vk_compute_test's dump mode, and vk_store_test, vk_texture_test
and vk_compute_test are unchanged on main.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 174cad2f046f61216e14832c6e0fbea563aadc62 on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

I built the Vulkan harnesses from this head and ran the five image-operation fixtures on Linux 7.0.0-43-generic with llvm-mc 21.1.8 and SPIRV-Tools 2026.1.

  • cs_imgatomic, cs_imgatomic3d and cs_resinfo matched all 64 words in each of the UINT, SINT and volume readbacks.
  • ps_get_lod passed for all 4,096 pixels in both draws. ps_get_lod_array passed for all 4,096 pixels in its draw. The clamped and calculated LOD values were within the fixture tolerance of 1/16.
  • The existing cs_imgstore, cs_imgload and cs_imgload_d16 controls also passed. The selected shader modules passed SPIR-V validation, and all 49 shader-check unit tests passed.

GPU coverage here is limited to those image fixtures and controls.

AI-assisted verification.

@crastinator

Copy link
Copy Markdown
Contributor

Tested 174cad2 merged into main c2967a5e (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.

  • The six new tests pass natively: cs_imgatomic, cs_imgatomic3d and cs_resinfo ("all 64 words of the uint image, the sint image and the volume exact"), ps_get_lod and ps_get_lod_array (the clamped and the calculated LOD within 1/16), and cs_bvh32.
  • Whole run_gpu_tests.py: 141/141 native, 141/141 with LEONIDA_W64_EMULATE=1. main alone has 135.
  • tests/test_shader_checks.py: 51 passed.

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

@kapitche

Copy link
Copy Markdown
Contributor

Tested on Windows 11 with two GPUs on one machine (runtime built from this PR's head, MSVC 14.51): pass. --filter img: 5/5 on both the RTX 4080 SUPER and the Intel UHD 770, including the new image atomics and image_get_resinfo fixtures.

@TieruYT

TieruYT commented Nov 22, 2026

Copy link
Copy Markdown

Independently tested ps_get_lod at 174cad2f046f61216e14832c6e0fbea563aadc62 on GeForce RTX 4070 Ti, NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300). Both draws passed.

Built the Vulkan test programs from this commit with MSVC 19.44.35222. Ran python -I scripts/run_gpu_tests.py --build <build-dir> --filter ps_get_lod.asm with LLVM 21.1.8 and SPIRV-Tools 2026.4. Both shader modules passed spirv-val.

I also repeated both draws directly with vk_texture_test --two-mip. The harness identified the RTX 4070 Ti on each run. All four components matched exactly across the full frame.

Sampler word 1 RGBA32F readback Exact pixels
0xc00000 (1, 1, 3, 1) 4096/4096
0x40000 (0, 1, 3, 0) 4096/4096

Scope was the 2D fixture only. AI-assisted verification.

@ayozetr

ayozetr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 174cad2 on NVIDIA GeForce RTX 3060 (Ampere), driver 620.70.06, Linux 7.3 (CachyOS), Vulkan 1.4.357, LLVM 23.1.5 llvm-mc: pass

  • scripts/run_gpu_tests.py --build runtime/build/linux: 112/141 passed, 29 skipped, 0 failed; 145/145 shaders translate and pass spirv-val.
  • The six new fixtures all pass: cs_imgatomic, cs_imgatomic3d, cs_resinfo (all 64 words exact), ps_get_lod (4096 pixels in each of 2 draws), ps_get_lod_array (4096 pixels), cs_bvh32.
  • The 29 skips are the wave64 tests (this GPU has 32-wide subgroups only), as on main (bb2e184: 109/139, 30 skipped, 0 failed).

main is at bb2e184. Three conflicts, both sides kept:

- runtime/test/vk_store_test.cpp: main added the "load-d16" mode (a row of
  16-bit boundary values in the fill, for the saturating d16 loads) and
  VK_KHR_shader_fma support; this branch added the "words" mode. Both modes
  and both includes stay; main's boundary row applies to "load-d16" only, so
  "words" keeps the plain fill its expected words are derived from.
- runtime/test/shaders/check.py: main lengthened CS_STORE on the line next to
  this branch's cs_bvh32 entry. Both lines.
- tests/test_shader_checks.py: main counts cs_fma_fused (8 -> 9) on the line
  after this branch's STORE_WORDS and GET_LOD_TESTS terms. Both.

The automatic merges were read as well: vk_compute_test.cpp keeps the larger
bvh heap next to main's shader_fma code, and check.py and run_gpu_tests.py
run cs_imgload_d16 in "load-d16" next to the "words" fixtures.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@UlteriorMotive00

Copy link
Copy Markdown
Contributor

Tested 5e91fb9 (0 behind main) on two GPUs: Windows 11 Home 10.0.26300, MSVC 14.44 (the PR's own scripts/build_runtime.ps1 build), Python 3.14.7, llvm-mc 21.1.8, Vulkan SDK 1.4.363.0, LEONIDA_VK_VALIDATION=1, VK_LOADER_LAYERS_DISABLE=~implicit~.

scripts/run_gpu_tests.py result
AMD Radeon RDNA2 iGPU (Ryzen 7 9800X3D, 32.0.21042.62), native wave64 145/145
RTX 5070 (617.42), LEONIDA_W64_EMULATE=1 145/145

All six new tests pass on both GPUs: cs_imgatomic, cs_imgatomic3d, cs_resinfo, ps_get_lod, ps_get_lod_array, cs_bvh32. No validation messages. pytest tests/test_shader_checks.py: 51 passed, 185 subtests.

A note for other testers: run it with the PR's own build. With main's vk_compute_test/vk_store_test (bb2e184), cs_resinfo fails on both GPUs: rgba8 unorm (float view): 64 bad, texel(5,3) = 0 0 0 0, 142/145. That's expected, since the PR changes those harnesses, but it looks like a translator failure if you reuse an existing build.

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

main is at 99f9989. One conflict, both sides kept:

- tests/test_shader_checks.py: main shortened the comment above TOTAL and
  counts a fourth vk_store_test shader (cs_sample_lz_int_d16: 3 -> 4) on the
  lines this branch's comment change touches. Main's comment with a clause
  for the "words" fixtures and the image_get_lod draws, main's count, and
  this branch's STORE_WORDS and GET_LOD_TESTS terms.

The automatic merges were read as well: check.py and run_gpu_tests.py run
cs_sample_lz_int_d16 through vk_store_test's "load-d16" mode next to the
"words" fixtures, and gfx10_descriptors.h still encodes the T# of the 16x4
image the same way.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@aslan2142

Copy link
Copy Markdown
Contributor Author

Merged main into the branch twice since this pull request was opened: bb2e1842 (head 5e91fb9a), then 99f99890 (new head 72b5b782). Both are merge commits, no rebase. The six new tests pass again on all three devices, next to the cases main added to the same tools.

Conflicts, both sides kept

Merge of bb2e1842:

  • runtime/test/vk_store_test.cpp: main added the load-d16 mode (a row of 16-bit boundary values in the fill) and VK_KHR_shader_fma support; this branch adds the words mode. Both modes and both includes stay.
  • The boundary row applies to load-d16 only, so words keeps the plain fill its expected words are derived from.
  • runtime/test/shaders/check.py: main lengthened CS_STORE on the line next to the cs_bvh32 entry. Both lines.
  • tests/test_shader_checks.py: main counts cs_fma_fused (8 → 9) on the line after this branch's two terms. Both.

Merge of 99f99890:

  • tests/test_shader_checks.py only: main shortened the comment above TOTAL and counts a fourth vk_store_test shader (cs_sample_lz_int_d16, 3 → 4) on the lines this branch's comment change touches. main's comment with a clause for this branch's fixtures, main's count, and this branch's two terms. The file's 49 tests pass.

Merged automatically, read as well

  • vk_compute_test.cpp: the larger bvh heap sits next to main's shader_fma code.
  • check.py and run_gpu_tests.py: cs_imgload_d16 and the new cs_sample_lz_int_d16 run in load-d16 next to the words fixtures.
  • vk_texture_test.cpp now puts the format into word 1 of its T#. The LOD fixtures read that T# from the heap as a key only, so nothing changes for them.
  • gfx10_descriptors.h changed in vulkan_view_format only, so the T# of the 16x4 image that cs_resinfo builds is still the one vk_store_test registers.
  • main's translator changes do not touch these ops: the SPIR-V of the six fixtures is byte-identical across both merges.

Counts on 72b5b782 (Mesa 26.3.1, llvm-mc 23.1.5, LEONIDA_VK_VALIDATION=1)

GPU native LEONIDA_W64_EMULATE=1
Radeon RX 7900 XTX (RADV) 147/147 147/147
Ryzen 9 7950X3D integrated, RDNA2 (RADV) 147/147 147/147
llvmpipe (LLVM 23.1.5) 98/147, 49 skipped 62/77, 15 skipped (--filter cs_, as CI)
  • Translator: 152 shaders, 152 translated, 152 pass spirv-val.
  • cs_imgstore, cs_imgload, cs_imgload_d16 and cs_sample_lz_int_d16 (both load-d16) pass with the extra r32ui bindings in the set.
  • Validation: the six fixtures, cs_bvh and the four older vk_store_test cases under the Khronos layer with GPU-assisted validation on the integrated GPU: 0 errors.
  • CPU: compileall; all 159 standard-library test files; pytest tests --ignore=tests/semantic: 3763 passed, 48 skipped; unittest discover -s tests/semantic: 1247 tests OK.
  • tests/test_mem_diff.py failed on main from b1b30d8d, the merge of Shader: fix the differential oracle for merged MTBUF load behavior #1396, until @Vonsek's fix f67aec27 landed, so it failed in the local run on 5e91fb9a. main 99f99890 contains the fix, and the test passes on 72b5b782 (15 tests).

How often the game uses these ops (my own count over the whole corpus: 26,503 shaders, mnemonics in the disassembly)

Op Shaders Uses Where
image_atomic_umax 995 2,485 3D 1,505 (pixel shaders only), 2D 980
image_atomic_or 714 725 2D 721, 3D 4
image_atomic_umin 707 713 2D
image_atomic_add 11 11 2D 6, 3D 5
image_atomic_cmpswap 1 1 3D
image_get_lod 653 718 2D 715, 2D array 3
image_get_resinfo 407 1,148 2D
image_bvh_intersect_ray (32-bit) 40 638
image_bvh64_intersect_ray 24 78
  • sub, and, xor, smin and smax do not occur. Neither do swap, inc and dec, which the translator has no case for.
  • The 32-bit BVH form, untested until now, is the more common of the two.
  • Not covered here: 1,018 of the 1,038 shaders with an image atomic are pixel shaders (20 are compute shaders), and the most common form, umax on a 3D image, occurs in pixel shaders only. These fixtures run the atomics in compute shaders, and the 3D one uses add, umin, smax, cmpswap and xor. That is a follow-up, not part of this PR; it is posted as a finding in the coordination issue.

Not re-run

  • The baseline of main itself on the GPUs (measured last at c2967a5e).
  • The mutation runs against a scratch copy of the translator (done before main was first merged in).
  • GPU-assisted validation on llvmpipe (clean at 174cad2f; only the integrated GPU was repeated since).
  • MSVC and llvm-mc 18: CI and the testers on this pull request cover those.

AI-assisted (Claude Code, Claude Fable 5.2).

main is at 41f4482. Two conflicts, both sides kept:

- docs/design.md: both sides edited the one-line "Ray tracing" row. Main's
  row (the triangle node types and their vertex slots), with this branch's
  sentence about cs_bvh32 where it stood.
- tests/test_shader_checks.py: main counts ps_ssharp (9 -> 10) and patches
  sampler_test on the lines next to this branch's STORE_WORDS / GET_LOD_TESTS
  terms and its get_lod_test patch. All four lines.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@ItsNotRexed
ItsNotRexed merged commit 8bf46bd into ItsNotRexed:main Nov 22, 2026
3 of 4 checks passed
@aslan2142
aslan2142 deleted the test-184-image-ops branch November 22, 2026 13:12
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.

8 participants