[GH-ISSUE #543] GPU test: ps_imgatomic loses atomic updates intermittently on MoltenVK 1.4.2 (Apple M5 Pro); KosmicKrisp passes #13

Closed
opened 2026-11-26 20:13:59 +01:00 by 4ld0 · 3 comments
Owner

Originally created by @GeorgiyDemo on GitHub (Nov 24, 2026).
Original GitHub issue: https://github.com/ubiquitarianism/leonida/issues/543

Re-filed from the old #9786 (listed in #18): that repository went private. Re-verified on this repository's main d42773d07; runtime/test/vk_bindless_test.cpp and runtime/test/shaders/ps_imgatomic.asm are identical to the old tree, so the measurements carry over.

What happens. runtime/test/vk_bindless_test in its ps_imgatomic mode fails intermittently on MoltenVK 1.4.2 on an Apple M5 Pro: 1 to 5 of the 256 checked texels come back wrong, always with fewer updates than expected (lost atomics), while the render-target check stays exact (0 of 4096 pixels). The same SPIR-V and the same binary pass every time through KosmicKrisp (Mesa).

GPU:        Apple M5 Pro (16-core GPU, Metal 4)
Driver:     MoltenVK 1.4.2 (Homebrew bottle), Vulkan 1.4.357
            KosmicKrisp (Mesa 26.3.1, Homebrew), Vulkan 1.4.363, through vulkan-loader 1.4.363
Subgroup:   4..32 (MoltenVK), 32..32 (KosmicKrisp)
OS:         macOS 26.7.3 (25G342), arm64
Commit:     main d42773d07
Tools:      llvm-mc 23.1.6 (Homebrew), SPIRV-Tools v2026.4, Apple clang 21.0.0, CMake 4.5.1

Reproduce:

python3 -I runtime/test/shaders/build.py <out> vs_ids ps_imgatomic
# MoltenVK, loaded directly by the test program (the default):
for i in $(seq 1 20); do runtime/build/linux/vk_bindless_test <out>/spirv/vs_ids.spv <out>/spirv/ps_imgatomic.spv; done
# KosmicKrisp:
LEONIDA_VULKAN_LOADER=$(brew --prefix)/lib/libvulkan.1.dylib \
VK_DRIVER_FILES=$(brew --prefix)/share/vulkan/icd.d/kosmickrisp_mesa_icd.aarch64.json \
  runtime/build/linux/vk_bindless_test <out>/spirv/vs_ids.spv <out>/spirv/ps_imgatomic.spv
  • MoltenVK: 9 pass, 11 fail in 20 runs at d42773d07. At the old main it was 11 pass / 9 fail in 20 runs at two commits (152 commits apart), and earlier sessions on the same machine gave 1/5, 3/10, 4/8, 6/10 and 9/12 failures, so roughly half.
  • KosmicKrisp: 10/10 pass, 0 texels wrong, at both the old and the current tree.

Examples printed by the test on a failing run, all consistent with one or a few atomic updates not landing:

2D umax texel 15: got 0x000002ff, want 0x000003ff
2D or   texel  7: got 0x00000000, want 0xff000000
2D umin texel  5: got 0x00000128, want 0x00000028
3D umax texel 12: got 0x00000fc4, want 0x00000fcc

What I ruled out:

  • The module is atomic, not a read-modify-write: spirv-dis shows four OpImageTexelPointer with OpAtomicUMax, OpAtomicUMin and OpAtomicOr.
  • The test's synchronization: the same binary passes 10/10 on KosmicKrisp, and the render-target readback is exact in every failing run.
  • The MoltenVK install: the formula was re-poured from the Homebrew bottle (brew reinstall molten-vk) and the runs repeated; the picture is unchanged.
  • Metal API validation: MTL_DEBUG_LAYER=1 reports no validation errors or hazards, and the intermittent wrong texels remain.

In the full suite on the old tree: run_gpu_tests.py 182/244 passed, 60 skipped, 2 failed (cs_fma_fused, the known MoltenVK 1.4.2 row, and ps_imgatomic); with LEONIDA_W64_EMULATE=1, 213/244 passed, 30 skipped, 1 failed (cs_fma_fused only), so ps_imgatomic is a flake and not a translation difference.

Question: does ps_imgatomic reproduce on other Apple GPUs or on MoltenVK main? If it is MoltenVK-side, the macOS CI job's EXPECTED_FAILURES (today ps_ssharp and cs_fma_fused) would need this one too, because a suite run reaches it about half the time.

AI-assisted run; synthetic fixtures only, no game data.

Originally created by @GeorgiyDemo on GitHub (Nov 24, 2026). Original GitHub issue: https://github.com/ubiquitarianism/leonida/issues/543 Re-filed from the old `#9786` (listed in #18): that repository went private. Re-verified on this repository's `main` `d42773d07`; `runtime/test/vk_bindless_test.cpp` and `runtime/test/shaders/ps_imgatomic.asm` are identical to the old tree, so the measurements carry over. **What happens.** `runtime/test/vk_bindless_test` in its `ps_imgatomic` mode fails intermittently on MoltenVK 1.4.2 on an Apple M5 Pro: 1 to 5 of the 256 checked texels come back wrong, always with fewer updates than expected (lost atomics), while the render-target check stays exact (0 of 4096 pixels). The same SPIR-V and the same binary pass every time through KosmicKrisp (Mesa). ``` GPU: Apple M5 Pro (16-core GPU, Metal 4) Driver: MoltenVK 1.4.2 (Homebrew bottle), Vulkan 1.4.357 KosmicKrisp (Mesa 26.3.1, Homebrew), Vulkan 1.4.363, through vulkan-loader 1.4.363 Subgroup: 4..32 (MoltenVK), 32..32 (KosmicKrisp) OS: macOS 26.7.3 (25G342), arm64 Commit: main d42773d07 Tools: llvm-mc 23.1.6 (Homebrew), SPIRV-Tools v2026.4, Apple clang 21.0.0, CMake 4.5.1 ``` Reproduce: ```sh python3 -I runtime/test/shaders/build.py <out> vs_ids ps_imgatomic # MoltenVK, loaded directly by the test program (the default): for i in $(seq 1 20); do runtime/build/linux/vk_bindless_test <out>/spirv/vs_ids.spv <out>/spirv/ps_imgatomic.spv; done # KosmicKrisp: LEONIDA_VULKAN_LOADER=$(brew --prefix)/lib/libvulkan.1.dylib \ VK_DRIVER_FILES=$(brew --prefix)/share/vulkan/icd.d/kosmickrisp_mesa_icd.aarch64.json \ runtime/build/linux/vk_bindless_test <out>/spirv/vs_ids.spv <out>/spirv/ps_imgatomic.spv ``` * MoltenVK: 9 pass, 11 fail in 20 runs at `d42773d07`. At the old `main` it was 11 pass / 9 fail in 20 runs at two commits (152 commits apart), and earlier sessions on the same machine gave 1/5, 3/10, 4/8, 6/10 and 9/12 failures, so roughly half. * KosmicKrisp: 10/10 pass, 0 texels wrong, at both the old and the current tree. Examples printed by the test on a failing run, all consistent with one or a few atomic updates not landing: ``` 2D umax texel 15: got 0x000002ff, want 0x000003ff 2D or texel 7: got 0x00000000, want 0xff000000 2D umin texel 5: got 0x00000128, want 0x00000028 3D umax texel 12: got 0x00000fc4, want 0x00000fcc ``` What I ruled out: * The module is atomic, not a read-modify-write: `spirv-dis` shows four `OpImageTexelPointer` with `OpAtomicUMax`, `OpAtomicUMin` and `OpAtomicOr`. * The test's synchronization: the same binary passes 10/10 on KosmicKrisp, and the render-target readback is exact in every failing run. * The MoltenVK install: the formula was re-poured from the Homebrew bottle (`brew reinstall molten-vk`) and the runs repeated; the picture is unchanged. * Metal API validation: `MTL_DEBUG_LAYER=1` reports no validation errors or hazards, and the intermittent wrong texels remain. In the full suite on the old tree: `run_gpu_tests.py` 182/244 passed, 60 skipped, 2 failed (`cs_fma_fused`, the known MoltenVK 1.4.2 row, and `ps_imgatomic`); with `LEONIDA_W64_EMULATE=1`, 213/244 passed, 30 skipped, 1 failed (`cs_fma_fused` only), so `ps_imgatomic` is a flake and not a translation difference. Question: does `ps_imgatomic` reproduce on other Apple GPUs or on MoltenVK `main`? If it is MoltenVK-side, the macOS CI job's `EXPECTED_FAILURES` (today `ps_ssharp` and `cs_fma_fused`) would need this one too, because a suite run reaches it about half the time. AI-assisted run; synthetic fixtures only, no game data.
4ld0 closed this issue 2026-11-26 20:13:59 +01:00
Author
Owner

@GeorgiyDemo commented on GitHub (Nov 24, 2026):

Two extra series on the same machine (main d42773d07, MoltenVK 1.4.2, 20 runs each, same binary and SPIR-V):

Run Pass Fail
baseline 9 11
MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS=1 7 13
MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=1 8 12

So it is not the submission path or the descriptor path: serializing submissions and switching to Metal argument buffers leave the rate where it is. Together with MTL_DEBUG_LAYER=1 reporting nothing and the same module passing 10/10 on KosmicKrisp, that points at the shader-level atomic path in MoltenVK rather than at the test's synchronization.

AI-assisted; synthetic fixtures only, no game data.

<!-- gh-comment-id:7130507578 --> @GeorgiyDemo commented on GitHub (Nov 24, 2026): Two extra series on the same machine (`main` `d42773d07`, MoltenVK 1.4.2, 20 runs each, same binary and SPIR-V): | Run | Pass | Fail | |---|---|---| | baseline | 9 | 11 | | `MVK_CONFIG_SYNCHRONOUS_QUEUE_SUBMITS=1` | 7 | 13 | | `MVK_CONFIG_USE_METAL_ARGUMENT_BUFFERS=1` | 8 | 12 | So it is not the submission path or the descriptor path: serializing submissions and switching to Metal argument buffers leave the rate where it is. Together with `MTL_DEBUG_LAYER=1` reporting nothing and the same module passing 10/10 on KosmicKrisp, that points at the shader-level atomic path in MoltenVK rather than at the test's synchronization. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@hugo0024 commented on GitHub (Nov 24, 2026):

It reproduces on a second Apple chip: Apple M5 (8-core GPU), MoltenVK 1.4.2, macOS 27.2.1, main d0da7dade, 101 of 150 single runs fail. What that run narrowed down, with the numbers in #860: MoltenVK lowers the four atomics to Metal's texture atomics; it fails as often with the descriptor index used directly instead of the first-lane broadcast (54 of 60) and with the image copies in a submission of their own after the draw (42 of 60); and a wrong umax or umin texel always holds the max or min of only some of its own 64 pixels. AI-assisted; synthetic fixtures only.

<!-- gh-comment-id:7134952860 --> @hugo0024 commented on GitHub (Nov 24, 2026): It reproduces on a second Apple chip: Apple M5 (8-core GPU), MoltenVK 1.4.2, macOS 27.2.1, `main` `d0da7dade`, 101 of 150 single runs fail. What that run narrowed down, with the numbers in #860: MoltenVK lowers the four atomics to Metal's texture atomics; it fails as often with the descriptor index used directly instead of the first-lane broadcast (54 of 60) and with the image copies in a submission of their own after the draw (42 of 60); and a wrong `umax` or `umin` texel always holds the max or min of only some of its own 64 pixels. AI-assisted; synthetic fixtures only.
Author
Owner

@EvgHaze commented on GitHub (Nov 25, 2026):

A third Apple chip says this one is not MoltenVK-wide — it does not reproduce on an M3 at all.

Machine:  Apple M3, 10-core GPU (MacBook Air 13", Mac15,13), macOS 27.0 (26A5406e), arm64
Driver:   MoltenVK 1.4.2 (Homebrew bottle), ICD loaded directly, subgroup 4..32
          KosmicKrisp, Mesa 26.3.1 (Homebrew), through vulkan-loader 1.4.363
Tree:     main `0d80bc5df`, `cmake -S runtime -B runtime/build -G Ninja`, binaries and SPIR-V from that tree
Run:      `vk_bindless_test <vs_ids.spv> <ps_imgatomic.spv>`
Driver Runs Result
MoltenVK 1.4.2 30 30 pass, 0 fail — 0 of 256 texels wrong and 0 of 4096 render-target pixels wrong in every run
KosmicKrisp 26.3.1 10 10 pass, 0 fail

So the numbers now are: M5 Pro 11 of 20 fail, M5 101 of 150 fail (from the comments above), M3 0 of 30. That is not a random flake that a different machine sometimes shows — it looks bounded by the GPU generation, and if so the useful next step is a boundary rather than another reproduction:

  • an M4 run would say whether the split is "M3 versus M4/M5" or "M5 only";
  • on the failing machines, the Metal side is worth recording: the device's supported GPU family (supportsFamily: for MTLGPUFamilyApple*) and whether Metal 4's texture atomics are in use at all, because the lowering named in #860 is the one path that changes between these generations.

I can run an M4 check too if one is reachable; on this hardware there is nothing to reproduce, so what I can offer is the negative datapoint, which is what rules out "MoltenVK 1.4.2 loses atomics on every Apple GPU".

AI-assisted. No game data: the fixtures are hand-written and every number above is test output.

<!-- gh-comment-id:7167350598 --> @EvgHaze commented on GitHub (Nov 25, 2026): A third Apple chip says this one is not MoltenVK-wide — it does not reproduce on an M3 at all. ```text Machine: Apple M3, 10-core GPU (MacBook Air 13", Mac15,13), macOS 27.0 (26A5406e), arm64 Driver: MoltenVK 1.4.2 (Homebrew bottle), ICD loaded directly, subgroup 4..32 KosmicKrisp, Mesa 26.3.1 (Homebrew), through vulkan-loader 1.4.363 Tree: main `0d80bc5df`, `cmake -S runtime -B runtime/build -G Ninja`, binaries and SPIR-V from that tree Run: `vk_bindless_test <vs_ids.spv> <ps_imgatomic.spv>` ``` | Driver | Runs | Result | |---|---|---| | MoltenVK 1.4.2 | 30 | **30 pass, 0 fail** — `0 of 256 texels wrong` and `0 of 4096 render-target pixels wrong` in every run | | KosmicKrisp 26.3.1 | 10 | 10 pass, 0 fail | So the numbers now are: M5 Pro 11 of 20 fail, M5 101 of 150 fail (from the comments above), **M3 0 of 30**. That is not a random flake that a different machine sometimes shows — it looks bounded by the GPU generation, and if so the useful next step is a boundary rather than another reproduction: - an M4 run would say whether the split is "M3 versus M4/M5" or "M5 only"; - on the failing machines, the Metal side is worth recording: the device's supported GPU family (`supportsFamily:` for `MTLGPUFamilyApple*`) and whether Metal 4's texture atomics are in use at all, because the lowering named in #860 is the one path that changes between these generations. I can run an M4 check too if one is reachable; on this hardware there is nothing to reproduce, so what I can offer is the negative datapoint, which is what rules out "MoltenVK 1.4.2 loses atomics on every Apple GPU". AI-assisted. No game data: the fixtures are hand-written and every number above is test output.
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#13
No description provided.