#1578

GPU test: image atomics in a pixel shader (ps_imgatomic)

OpenDom-inwants to merge intofrom

Claimed in the coordination issue as: https://github.com/ItsNotRexed/Leonida/issues/1380#issuecomment-7078894940 (@aslan2142's finding 7078879525)

What and why

1,018 of the corpus's 1,038 image-atomic shaders are pixel shaders. Yet every GPU test of image atomics runs in a compute shader: cs_imgatomic* (#1419) go through vk_store_test, and vk_texture_test binds no storage image. So the fragment-stage storage bindings, and an atomic from a pixel that is discarded afterwards, were untested.

runtime/test/shaders/ps_imgatomic.asm uses the corpus's forms. Every one of the 64×64 pixels computes its id px + 64·py and texel (px >> 3, py >> 3), so 64 pixels contend for each texel. It then:

  • runs image_atomic_umax, umin and or on three 8×8 2D r32ui images;
  • runs umax on a 4×4×4 3D image, the corpus's most common form (1,505 uses, never in compute);
  • finds each image through its own T# in the descriptor table, via set 0's r32ui storage arrays (binding 4 for 2D, 7 for 3D);
  • discards odd pixels after their atomics. Those atomics must still count, as on hardware.

vk_bindless_test runs it when given ps_imgatomic.spv:

  • it enables fragmentStoresAndAtomics, and exits 77 with unsupported: ... without it;
  • it creates and clears the four images (umin to all ones), registers them in the bindless set and draws once;
  • it checks all 256 texels against a model of the 4096 pixels, and checks that the render target has the odd columns discarded.

run_gpu_tests.py (drawn with vs_ids) and check.py run it next to ps_tex. tests/test_shader_checks.py's TOTAL counts it.

Tested

GPUnativeLEONIDA_W64_EMULATE=1
AMD Radeon RX 9070 (RDNA4), AMD 26.11.2, Windows 110 of 256 texels wrong ...; 0 of 4096 render-target pixels wrong, also with LEONIDA_VK_VALIDATION=1 (0 validation errors)—
NVIDIA RTX 2080 SUPER (Turing), 595.99.02, Ubuntu 26.04PASS, 0 wrongPASS, 0 wrong
  • Negative control: with the fixture's umin changed to umax, the test reports all 64 umin texels wrong (got 0xffffffff, want 0x00000020...).
  • run_gpu_tests.py full suite on the RX 9070: 142/142. check.py: 131 of 134 pass, 3 skipped.
  • tests/test_shader_checks.py, tests/test_run_gpu_tests.py: OK. pytest tests/test_translate.py tests/test_cube_sample.py: 435 passed.

So the translated atomics behave in the fragment stage as in compute, on both vendors. That's not proof the game's shaders are right, but the binding path and discard ordering they rely on are now covered.

AI-assisted (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. (Hand-written fixture; the corpus counts are from the finding.)
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: test only)

🤖 Generated with Claude Code

Activity

132
AvantBras1h ago

Tested 876b90533124f3704c1ef2a646429040d4cb7a8c on RTX 3060 12 GB (Ampere), NVIDIA 580.178.04, Pop!_OS 22.04 LTS: pass. Rebuilt the Vulkan harnesses including vk_bindless_test at this head, then ran python -I scripts/run_gpu_tests.py --build <build> --filter ps_imgatomic natively and with LEONIDA_W64_EMULATE=1. Both runs reported 0/256 wrong storage texels and 0/4096 wrong render-target pixels; both modules passed spirv-val on each run. No skips. No game files or Vulkan validation-layer run. AI-assisted verification.

Yourrespawn1h ago

Tested 876b9053 on NVIDIA GeForce RTX 4080 (Ada), driver 617.14, Vulkan API 1.4.351, Windows 11 Pro 10.0.26200: pass.

  • run_gpu_tests.py: ps_imgatomic PASS — "0 of 256 texels wrong (2D umax/umin/or 8x8 each, 3D umax 4x4x4); 0 of 4096 render-target pixels wrong (odd columns discarded)"; suite 116/146 passed, 30 skipped (native wave64, expected on this 32-lane GPU)
  • vk_bindless_test vs_ids.spv ps_imgatomic.spv with LEONIDA_VK_VALIDATION=1 (Core + Synchronization): same exact counts, 0 validation errors
  • fragmentStoresAndAtomics path exercised (no exit 77), descriptor-table lookup through set 0's r32ui arrays works on this driver

AI-assisted (ZCode agent): builds and runs executed by a coding agent on this machine.