rdna2spirv: --explicit-lod-bias applies the S# LOD bias where MoltenVK drops the sampler's; ps_ssharp passes on Macs (SHADER-EXPLICIT-LOD-BIAS-MVK) #1774

Open
github-bot wants to merge 16 commits from github-bot/gh-1774 into main AGit
Owner

@⁠Tauwni on GitHub · 2026-11-25 11:50 UTC · original
Tauwni:fix/explicit-lod-bias-moltenvk → main · +1374 −60 · 26 files · 16 commits · open

Update 4 (5c702e2a7, docs only): the M3 on 27.0 and an Apple M5 have run this head

No code has changed since 743eda012. bcf199736 and 5c702e2a7 only update docs/design.md with these results:

Machine macOS Probe (--lod-bias) ps_ssharp* in auto mode Run by
Apple M3 26.5.1 true: "the sampler drops mipLodBias" 6/6 pass (MoltenVK, KosmicKrisp, llvmpipe) me
Apple M3 27.0 (26A5406e) true on MoltenVK, false on KosmicKrisp and llvmpipe 6/6 pass on all three EvgHaze (comment)
Apple M5 26.6.2 false: "the sampler applies mipLodBias" 6/6 pass, flag off cizerter on Discord (comment)

So the measured gate does what it should on real Apple hardware. Where MoltenVK drops the bias (the M3s), the shader applies it. Where MoltenVK applies it (the M5, KosmicKrisp, llvmpipe), the flag stays off, and nothing is counted twice.

Still open: the macOS CI job. Its workflows are awaiting approval, and ps_ssharp stays in EXPECTED_FAILURES until the runner's probe shows which way it goes. An M5 Pro run on 26.7.3 (@⁠GeorgiyDemo) would be one more false data point, but it is no longer needed for the gate.


Update 3 (743eda012): review fixes, and main merged again

From @⁠aslan2142's review:

  • Probe control: tools/vk_lod_bias.py also reads at explicit LOD 1 with no bias, and answers null unless that read is 1.0. Before, a level 1 that was never cleared also read 0.0, which looked like a dropped bias.
  • Clamp order: outside the PS, image_sample_cl / image_sample_c_cl add the S# bias before the clamp, max(0 + bias, minlod), as _b_cl does.
  • design.md: the 27.0 M3 checked the draw probe only, until it's rerun.
  • Dead code in make_game.py dropped, and the tools/vk_subgroup_info.py conflict resolved (3fc618429, b14565930).

After #2098, a tagged module reads its instruction's array only when the table entry's kind names it. vk_sampler_test --cube / --3d now tag the array the texture sits in. Without that, ps_ssharp_cube and ps_ssharp_3d read the fallback.

Still open at the time: the M5 Pro and 27.0 M3 reruns (both answered in Update 4), and the macOS CI job.


Update 2 (631a53832): the probe needs no test programs, every sample form is GPU-checked

The open points of the Update below are done, with @⁠EvgHaze's two suggestions:

  • Probe without test programs. tools/vk_subgroup_info.py --lod-bias measures it in Python (tools/vk_lod_bias.py): a two-level R32_SFLOAT image cleared to 0.0 / 1.0, sampled at explicit LOD 0 through samplers with mipLodBias 0 and +1 in one compute dispatch. true when +1 still reads level 0, false when it reads level 1, null otherwise. It needs no built test programs, llvm-mc or SPIR-V tools. tools/lod_bias_probe.py returns that answer and only falls back to the ps_ssharp draw when it has none. build.py and make_game.py now measure too, so check.py alone takes the flag and make_game.py no longer waits for the test programs. The option is off by default, so nothing else that runs vk_subgroup_info.py dispatches anything.
  • llvm-mc message. When the draw fallback can't start llvm-mc, it gives mc_command.install_hint() (the Homebrew LLVM_MC="$(brew --prefix llvm)/bin/llvm-mc" line) instead of a bare "could not be started".
  • Every form GPU-checked, each with the same 10 SAMPLER_CASES (check.py's SAMPLER_FIXTURES). vk_sampler_test gains --cube, --3d and --dref; its 2D default is unchanged.
Fixture Forms Texture
ps_ssharp image_sample_lz, image_sample 2D (as before)
ps_ssharp_ld (new) image_sample_l, image_sample_d (the Grad scale) 2D
ps_ssharp_b (new) image_sample_lz, image_sample_b 2D
ps_ssharp_cube (new) image_sample_lz, image_sample 6-layer cube, images_arr
ps_ssharp_3d (new) image_sample_lz, image_sample 128x128x2 volume, images_3d
ps_ssharp_c (new) image_sample_c_lz, image_sample_c D32, 0.25 / 0.75, LESS_EQUAL S#
ps_ssharp_o (new) image_sample_lz_o, image_sample_o 2D, under LEONIDA_TEXOFF_FALLBACK=1 (a SKIP without it)

Tested at 631a53832 on the Apple M3 (macOS 26.5.1):

All 7 fixtures flag off flag on auto
MoltenVK 1.4.2 FAIL (bias +1) on all 7 PASS 7/7 PASS 7/7 (probe true)
KosmicKrisp (Mesa 26.3.1) PASS 7/7 FAIL bias +0.3 (counted twice) on all 7 PASS 7/7 (probe false)
llvmpipe (Mesa 26.3.1) PASS 7/7 FAIL bias +0.3 on all 7 PASS 7/7 (probe false)
  • The Python probe answered the same 10 times out of 10 on MoltenVK and on KosmicKrisp.
  • ctest 88/88 on this branch. The translator suite (6294 tests) and the docs tests pass.
  • With the open fixes merged (#1444, #1518, #1724, #822, #1212, #1673, #1657, #1412, #1375; and the generated/ fix below, locally) on main db1a22d29, test programs rebuilt:
    • MoltenVK: no failure in run_gpu_tests.py (200/270 native, 233/270 emulated) or check.py (192/237, 45 skipped, flag measured by build.py itself).
    • llvmpipe: no failure.
    • KosmicKrisp: only what this PR doesn't touch (cs_fma_fused from #1724; ps_cndmask_sign_mods and ps_valu16_mad_sel, fixed by the KosmicKrisp branch below; cs_fmt_all, see below).
    • ctest 99/99; translator suite 6324 tests, 0 failed; pytest 1919 passed. The standard-library loop has 2 failures that main has too: test_tool_stdout_encoding (#1837, #1673 and the stage_timeline branch below) and test_calibrated_texture_extra, a Windows MoveFileExW test that fails on macOS on main alone.

Still open after Update 2

  • The macOS CI runner is a paravirtual device I can't test. ps_ssharp stays in its EXPECTED_FAILURES; the job prints a notice if it passes there, and it can be dropped then.
  • An M5 Pro run of this head. @⁠GeorgiyDemo: python -I tools/vk_subgroup_info.py --lod-bias should answer "explicit_lod_bias": false there, and --filter ps_ssharp should pass all 7 with the flag off.

Found while testing and split off, since they're not this PR's topic:

  • #2096: the generated/ directory for vk_null_descriptor_test (the macOS/Linux build fails on main).
  • Tauwni:fix/stage-timeline-stdout (pull request to follow): stage_timeline.py's stdout guard.
  • Tauwni:fix/kosmickrisp-nan-canonicalization (pull request to follow): KosmicKrisp's canonical NaN in exact-word pixel tests.
  • cs_fmt_all on KosmicKrisp isn't one fix. Word 293 is an f16 signalling NaN stored quiet (0x7c01 -> 0x7e00), and word 312, an 11/11/10 float, reads a different finite G and a NaN B (0xf83efde0 -> 0xfc1efde0). That looks like a driver bug, not the canonicalization, so it stays a finding (#1608) rather than a tolerance.

Update (66b27ac6e): the flag is now measured per device, not keyed on MoltenVK's driver ID

The reviews showed the driver-ID gate was wrong: the same MoltenVK 1.4.2 applies mipLodBias on an Apple M5 Pro, so the auto flag counted the bias twice there and turned a passing ps_ssharp red. It isn't an OS-version rule either:

Machine macOS MoltenVK 1.4.2 applies mipLodBias? Reported by
Apple M3 26.5.1 (25F80) no, ps_ssharp fails on main this PR
Apple M5 Pro 26.7.3 (25G342) yes, passes on main GeorgiyDemo
Apple M3 27.0 (26A5406e) no, fails on main EvgHaze

What changed:

  • New tools/lod_bias_probe.py: translates vs_ids and ps_ssharp without the flag, draws them with vk_sampler_test at LOD_BIAS 0, +1 and -1, and answers true only when +1 and -1 read the no-bias levels. It answers false when both move as check.py expects, and null otherwise (wrong no-bias draw, mixed answer, failed draw, no test programs). null never turns the flag on.
  • scripts/run_gpu_tests.py and make_game.py take the probe's answer. make_game.py runs it on the test programs in runtime/build/linux or runtime/build if present; otherwise it keeps a recorded flag, like the other fallbacks.
  • runtime/test/shaders/build.py only follows LEONIDA_EXPLICIT_LOD_BIAS: it also runs inside the CMake build, before the test programs exist, so it must not probe.
  • tools/vk_subgroup_info.py and its test are back as on main, with no explicit_lod_bias field.
  • tools/lod_bias_probe.py is in runtime.yml's path filters. New tests/test_lod_bias_probe.py (7 tests with fake draws: applied, dropped, mixed, wrong base, failed draw, no programs, translated without the flag).

Tested at 66b27ac6e on the Apple M3:

  • Probe: MoltenVK true, KosmicKrisp false, llvmpipe false, no test programs null.
  • ps_ssharp in auto mode: 10/10 on all three. KosmicKrisp plays the part of a driver that applies the bias, like the M5 Pro: the probe leaves the flag off there. Forced checks unchanged: MoltenVK off fails bias +1, KosmicKrisp on fails bias +0.3.
  • With the open fixes merged (#1444, #1518, #1724, #822, #1212, #1673, #1657, #1412, #1375) on main 71a769d7d, test programs rebuilt:
    • MoltenVK: no failure in run_gpu_tests.py (195/264 native, 228/264 emulated) or in check.py with LEONIDA_EXPLICIT_LOD_BIAS=1, as the probe answers (187/231, 44 skipped).
    • llvmpipe: no failure.
    • KosmicKrisp: the same failures as without this PR.
    • ctest 95/95; translator suite 6300 tests, 0 failed; pytest 1913 passed.

Still open

  • This PR:
    • check.py alone doesn't take the flag (done in Update 2): after build.py, a Mac that needs it has to set LEONIDA_EXPLICIT_LOD_BIAS=1, which python -I tools/lod_bias_probe.py --build <test programs> answers. A lead: let build.py probe when it is given the test programs' folder, but never inside the CMake build.
    • Not GPU-checked: _d, the _c* forms, cube and 3D samples, and the texel-offset gradients. (done in Update 2) A lead: a ps_ssharp-style fixture per form.
    • The macOS CI runner is a paravirtual device I can't test, so ps_ssharp stays in its EXPECTED_FAILURES; the job prints a notice if it passes there.
    • make_game.py can only probe once the test programs are built (done in Update 2); before that the flag stays off unless it was recorded.
    • Not rerun on an M5 Pro since the change: @⁠GeorgiyDemo, a --filter ps_ssharp run and python -I tools/lod_bias_probe.py --build <your build> would confirm the probe answers false there.
  • Found while testing, not caused by this PR:
    • On main since ba626820e, the macOS/Linux build of vk_null_descriptor_test fails: its add_custom_command writes generated/cs_null_descriptors.spv without creating generated/ ("Failed to open file"). Adding COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/generated before glslangValidator fixes it locally (ctest 95/95).
    • tests/test_tool_stdout_encoding.py fails on main for two new tools, tools/game_run_summary.py and tools/stage_timeline.py (no errors='replace' on stdout).
    • On KosmicKrisp, ps_cndmask_sign_mods, ps_valu16_mad_sel and cs_fmt_all (NaN canonicalization, finding in #1608) and cs_fma_fused with #1724 (comment there) still fail.

I'll try to fix the open points of this PR this evening, or as soon as I have time, and post the results here. Done: see Update 2.


Claimed in the coordination issue as: SHADER-EXPLICIT-LOD-BIAS-MVK (#1608)

What and why

ps_ssharp fails on every Mac some Macs (see Update) with MoltenVK 1.4.2 (point bias +1: (0,0): (1.0, 0.0, 0.502, 0.502) != (0.502, 0.502, 0.502, 0.502)) and sits in the macOS job's EXPECTED_FAILURES. Measured on an Apple M3: MoltenVK drops VkSamplerCreateInfo::mipLodBias from both explicit-LOD samples (image_sample_lz with +0.6 / +1 stays on level 0) and the derivative-LOD image_sample (-0.6 / -1 stays on level 1). The test stopped at its first failing case, so only the explicit half showed. KosmicKrisp and llvmpipe (Mesa 26.3.1) on the same machine apply the bias.

This adds a device fallback, rdna2spirv.py --explicit-lod-bias, in the same shape as --f16-interp-fallback: the shader applies the S#'s LOD_BIAS (word 2 [13:0], signed 5.8, read from the S# SGPRs; a literal S# folds to a constant, a zero bias adds nothing):

  • added to the Lod of _lz, _l, _c_lz, _c_l and of the implicit forms outside the PS;
  • added to the bias of _b / _c_b;
  • a Bias operand on implicit samples in the PS;
  • a 2^bias scale of Grad derivatives (the typed 2D implicit read, _d, and the --texel-offset-fallback gradients).

The sampler still clamps to MIN_LOD..MAX_LOD. It is chosen per device, since on a driver that applies the bias it would count twice: explicit_lod_bias in tools/vk_subgroup_info.py (MoltenVK's driver ID), read by scripts/run_gpu_tests.py, runtime/test/shaders/build.py and make_game.py (replaced, see Update) (recorded with the other fallback flags); LEONIDA_EXPLICIT_LOD_BIAS=1/0 forces it in the test runners.

check.py's SAMPLER_CASES gain point bias +0.3 and -0.3: with two levels, an integer bias can't tell a bias applied once from twice, these can (they fail on KosmicKrisp and llvmpipe when the flag is forced there).

Docs: a contract row in docs/design.md (with what is and isn't GPU-checked) and a Known problems row in docs/testing.md. ps_ssharp stays in the macOS job's EXPECTED_FAILURES for now: that runner is a paravirtual device I can't test here; if it passes there, the job prints its "drop it from the expected failures" notice and it can go in a follow-up.

Tested

Apple M3, macOS 26.5.1, test programs built from main:

ps_ssharp (10 cases) flag off flag on default (auto)
MoltenVK 1.4.2 FAIL (bias +1; also +-0.6, -1) PASS PASS (on)
KosmicKrisp (Mesa 26.3.1) PASS FAIL bias +0.3 (counted twice) PASS (off)
llvmpipe (Mesa 26.3.1) PASS FAIL bias +0.3 (counted twice) PASS (off)
  • tests/semantic/test_explicit_lod_bias.py (new, 7 tests: literal, negative, zero and run-time S#, Grad scaling, Bias operand, _b, compute); tests/test_vk_subgroup_info.py, tests/test_make_game_translator_flags.py (probe mocked, new case), tests/test_make_game_argparse.py (probe mocked), tests/test_shader_checks.py (the two new cases).
  • On this branch: translator suite 6294 tests, 0 failed; docs tests OK.
  • With the open fixes merged together (#1444, #1518, #1724, #822, #1212, #1673, #1657, #1412, #1375; #822 and #1444 conflict with each other in build.py, resolution in #822's thread, none with this branch), test programs rebuilt: MoltenVK has no failure left: run_gpu_tests.py 195/263, 68 skipped (228/263 with LEONIDA_W64_EMULATE=1), check.py 187/231, 44 skipped. KosmicKrisp keeps exactly the failures it had without this branch (cs_fma_fused from #1724, ps_cndmask_sign_mods, ps_valu16_mad_sel, cs_fmt_all; see #1608); llvmpipe none. ctest 88/88; translator suite 6299 tests, standard-library loop 499 files, pytest 1912 passed, all 0 failed.
  • Not GPU-checked: _d, the _c* forms, cube and 3D samples, and the texel-offset gradients (covered by the semantic test only).

GPUs tested: Apple M3 (10-core GPU), MoltenVK 1.4.2 and KosmicKrisp (Mesa 26.3.1), macOS 26.5.1 (25F80); llvmpipe (Mesa 26.3.1)

AI-assisted: yes (Claude Code)

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • No game data, keys or decryption.
  • The new translator rule is in the contract table of docs/design.md, with how it was confirmed.

🤖 Generated with Claude Code

**@⁠Tauwni** on GitHub · 2026-11-25 11:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774) `Tauwni:fix/explicit-lod-bias-moltenvk` → `main` · +1374 −60 · 26 files · 16 commits · open ## Update 4 (`5c702e2a7`, docs only): the M3 on 27.0 and an Apple M5 have run this head No code has changed since `743eda012`. `bcf199736` and `5c702e2a7` only update `docs/design.md` with these results: | Machine | macOS | Probe (`--lod-bias`) | `ps_ssharp*` in auto mode | Run by | |---|---|---|---|---| | Apple M3 | 26.5.1 | true: "the sampler drops mipLodBias" | 6/6 pass (MoltenVK, KosmicKrisp, llvmpipe) | me | | Apple M3 | 27.0 (26A5406e) | true on MoltenVK, false on KosmicKrisp and llvmpipe | 6/6 pass on all three | EvgHaze ([comment](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1774)) | | Apple M5 | 26.6.2 | false: "the sampler applies mipLodBias" | 6/6 pass, flag off | cizerter on Discord ([comment](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1774)) | So the measured gate does what it should on real Apple hardware. Where MoltenVK drops the bias (the M3s), the shader applies it. Where MoltenVK applies it (the M5, KosmicKrisp, llvmpipe), the flag stays off, and nothing is counted twice. Still open: the macOS CI job. Its workflows are awaiting approval, and `ps_ssharp` stays in `EXPECTED_FAILURES` until the runner's probe shows which way it goes. An M5 Pro run on 26.7.3 (@⁠GeorgiyDemo) would be one more false data point, but it is no longer needed for the gate. --- ## Update 3 (`743eda012`): review fixes, and `main` merged again From @⁠aslan2142's review: - **Probe control:** `tools/vk_lod_bias.py` also reads at explicit LOD 1 with no bias, and answers `null` unless that read is 1.0. Before, a level 1 that was never cleared also read 0.0, which looked like a dropped bias. - **Clamp order:** outside the PS, `image_sample_cl` / `image_sample_c_cl` add the S# bias before the clamp, `max(0 + bias, minlod)`, as `_b_cl` does. - **design.md:** the 27.0 M3 checked the draw probe only, until it's rerun. - Dead code in `make_game.py` dropped, and the `tools/vk_subgroup_info.py` conflict resolved (`3fc618429`, `b14565930`). After #2098, a tagged module reads its instruction's array only when the table entry's kind names it. `vk_sampler_test --cube` / `--3d` now tag the array the texture sits in. Without that, `ps_ssharp_cube` and `ps_ssharp_3d` read the fallback. Still open at the time: the M5 Pro and 27.0 M3 reruns (both answered in Update 4), and the macOS CI job. --- ## Update 2 (`631a53832`): the probe needs no test programs, every sample form is GPU-checked The open points of the Update below are done, with @⁠EvgHaze's two suggestions: - **Probe without test programs.** `tools/vk_subgroup_info.py --lod-bias` measures it in Python (`tools/vk_lod_bias.py`): a two-level R32_SFLOAT image cleared to 0.0 / 1.0, sampled at explicit LOD 0 through samplers with `mipLodBias` 0 and +1 in one compute dispatch. `true` when +1 still reads level 0, `false` when it reads level 1, `null` otherwise. It needs no built test programs, llvm-mc or SPIR-V tools. `tools/lod_bias_probe.py` returns that answer and only falls back to the `ps_ssharp` draw when it has none. `build.py` and `make_game.py` now measure too, so `check.py` alone takes the flag and `make_game.py` no longer waits for the test programs. The option is off by default, so nothing else that runs `vk_subgroup_info.py` dispatches anything. - **`llvm-mc` message.** When the draw fallback can't start `llvm-mc`, it gives `mc_command.install_hint()` (the Homebrew `LLVM_MC="$(brew --prefix llvm)/bin/llvm-mc"` line) instead of a bare "could not be started". - **Every form GPU-checked**, each with the same 10 `SAMPLER_CASES` (`check.py`'s `SAMPLER_FIXTURES`). `vk_sampler_test` gains `--cube`, `--3d` and `--dref`; its 2D default is unchanged. | Fixture | Forms | Texture | |---|---|---| | `ps_ssharp` | `image_sample_lz`, `image_sample` | 2D (as before) | | `ps_ssharp_ld` (new) | `image_sample_l`, `image_sample_d` (the `Grad` scale) | 2D | | `ps_ssharp_b` (new) | `image_sample_lz`, `image_sample_b` | 2D | | `ps_ssharp_cube` (new) | `image_sample_lz`, `image_sample` | 6-layer cube, `images_arr` | | `ps_ssharp_3d` (new) | `image_sample_lz`, `image_sample` | 128x128x2 volume, `images_3d` | | `ps_ssharp_c` (new) | `image_sample_c_lz`, `image_sample_c` | D32, 0.25 / 0.75, LESS_EQUAL S# | | `ps_ssharp_o` (new) | `image_sample_lz_o`, `image_sample_o` | 2D, under `LEONIDA_TEXOFF_FALLBACK=1` (a SKIP without it) | Tested at `631a53832` on the Apple M3 (macOS 26.5.1): | All 7 fixtures | flag off | flag on | auto | |---|---|---|---| | MoltenVK 1.4.2 | FAIL (`bias +1`) on all 7 | PASS 7/7 | PASS 7/7 (probe `true`) | | KosmicKrisp (Mesa 26.3.1) | PASS 7/7 | FAIL `bias +0.3` (counted twice) on all 7 | PASS 7/7 (probe `false`) | | llvmpipe (Mesa 26.3.1) | PASS 7/7 | FAIL `bias +0.3` on all 7 | PASS 7/7 (probe `false`) | - The Python probe answered the same 10 times out of 10 on MoltenVK and on KosmicKrisp. - ctest 88/88 on this branch. The translator suite (6294 tests) and the docs tests pass. - With the open fixes merged (#1444, #1518, #1724, #822, #1212, #1673, #1657, #1412, #1375; and the `generated/` fix below, locally) on `main` `db1a22d29`, test programs rebuilt: - **MoltenVK: no failure** in `run_gpu_tests.py` (200/270 native, 233/270 emulated) or `check.py` (192/237, 45 skipped, flag measured by `build.py` itself). - llvmpipe: no failure. - KosmicKrisp: only what this PR doesn't touch (`cs_fma_fused` from #1724; `ps_cndmask_sign_mods` and `ps_valu16_mad_sel`, fixed by the KosmicKrisp branch below; `cs_fmt_all`, see below). - ctest 99/99; translator suite 6324 tests, 0 failed; pytest 1919 passed. The standard-library loop has 2 failures that `main` has too: `test_tool_stdout_encoding` (#1837, #1673 and the `stage_timeline` branch below) and `test_calibrated_texture_extra`, a Windows `MoveFileExW` test that fails on macOS on `main` alone. ### Still open after Update 2 - The macOS CI runner is a paravirtual device I can't test. `ps_ssharp` stays in its `EXPECTED_FAILURES`; the job prints a notice if it passes there, and it can be dropped then. - An M5 Pro run of this head. @⁠GeorgiyDemo: `python -I tools/vk_subgroup_info.py --lod-bias` should answer `"explicit_lod_bias": false` there, and `--filter ps_ssharp` should pass all 7 with the flag off. Found while testing and split off, since they're not this PR's topic: - #2096: the `generated/` directory for `vk_null_descriptor_test` (the macOS/Linux build fails on `main`). - `Tauwni:fix/stage-timeline-stdout` (pull request to follow): `stage_timeline.py`'s stdout guard. - `Tauwni:fix/kosmickrisp-nan-canonicalization` (pull request to follow): KosmicKrisp's canonical NaN in exact-word pixel tests. - `cs_fmt_all` on KosmicKrisp isn't one fix. Word 293 is an f16 signalling NaN stored quiet (`0x7c01` -> `0x7e00`), and word 312, an 11/11/10 float, reads a different finite G and a NaN B (`0xf83efde0` -> `0xfc1efde0`). That looks like a driver bug, not the canonicalization, so it stays a finding (#1608) rather than a tolerance. --- ## Update (`66b27ac6e`): the flag is now measured per device, not keyed on MoltenVK's driver ID The reviews showed the driver-ID gate was wrong: the same MoltenVK 1.4.2 applies `mipLodBias` on an Apple M5 Pro, so the auto flag counted the bias twice there and turned a passing `ps_ssharp` red. It isn't an OS-version rule either: | Machine | macOS | MoltenVK 1.4.2 applies `mipLodBias`? | Reported by | |---|---|---|---| | Apple M3 | 26.5.1 (25F80) | no, `ps_ssharp` fails on `main` | this PR | | Apple M5 Pro | 26.7.3 (25G342) | yes, passes on `main` | GeorgiyDemo | | Apple M3 | 27.0 (26A5406e) | no, fails on `main` | EvgHaze | What changed: - New `tools/lod_bias_probe.py`: translates `vs_ids` and `ps_ssharp` **without** the flag, draws them with `vk_sampler_test` at LOD_BIAS 0, +1 and -1, and answers `true` only when +1 and -1 read the no-bias levels. It answers `false` when both move as `check.py` expects, and `null` otherwise (wrong no-bias draw, mixed answer, failed draw, no test programs). `null` never turns the flag on. - `scripts/run_gpu_tests.py` and `make_game.py` take the probe's answer. `make_game.py` runs it on the test programs in `runtime/build/linux` or `runtime/build` if present; otherwise it keeps a recorded flag, like the other fallbacks. - `runtime/test/shaders/build.py` only follows `LEONIDA_EXPLICIT_LOD_BIAS`: it also runs inside the CMake build, before the test programs exist, so it must not probe. - `tools/vk_subgroup_info.py` and its test are back as on `main`, with no `explicit_lod_bias` field. - `tools/lod_bias_probe.py` is in `runtime.yml`'s path filters. New `tests/test_lod_bias_probe.py` (7 tests with fake draws: applied, dropped, mixed, wrong base, failed draw, no programs, translated without the flag). Tested at `66b27ac6e` on the Apple M3: - Probe: MoltenVK `true`, KosmicKrisp `false`, llvmpipe `false`, no test programs `null`. - `ps_ssharp` in auto mode: 10/10 on all three. KosmicKrisp plays the part of a driver that applies the bias, like the M5 Pro: the probe leaves the flag off there. Forced checks unchanged: MoltenVK off fails `bias +1`, KosmicKrisp on fails `bias +0.3`. - With the open fixes merged (#1444, #1518, #1724, #822, #1212, #1673, #1657, #1412, #1375) on `main` `71a769d7d`, test programs rebuilt: - MoltenVK: no failure in `run_gpu_tests.py` (195/264 native, 228/264 emulated) or in `check.py` with `LEONIDA_EXPLICIT_LOD_BIAS=1`, as the probe answers (187/231, 44 skipped). - llvmpipe: no failure. - KosmicKrisp: the same failures as without this PR. - ctest 95/95; translator suite 6300 tests, 0 failed; pytest 1913 passed. ### Still open - **This PR:** - ~~`check.py` alone doesn't take the flag~~ (done in Update 2): after `build.py`, a Mac that needs it has to set `LEONIDA_EXPLICIT_LOD_BIAS=1`, which `python -I tools/lod_bias_probe.py --build <test programs>` answers. A lead: let `build.py` probe when it is given the test programs' folder, but never inside the CMake build. - ~~Not GPU-checked: `_d`, the `_c*` forms, cube and 3D samples, and the texel-offset gradients.~~ (done in Update 2) A lead: a `ps_ssharp`-style fixture per form. - The macOS CI runner is a paravirtual device I can't test, so `ps_ssharp` stays in its `EXPECTED_FAILURES`; the job prints a notice if it passes there. - ~~`make_game.py` can only probe once the test programs are built~~ (done in Update 2); before that the flag stays off unless it was recorded. - Not rerun on an M5 Pro since the change: @⁠GeorgiyDemo, a `--filter ps_ssharp` run and `python -I tools/lod_bias_probe.py --build <your build>` would confirm the probe answers `false` there. - **Found while testing, not caused by this PR:** - On `main` since `ba626820e`, the macOS/Linux build of `vk_null_descriptor_test` fails: its `add_custom_command` writes `generated/cs_null_descriptors.spv` without creating `generated/` ("Failed to open file"). Adding `COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/generated` before `glslangValidator` fixes it locally (ctest 95/95). - `tests/test_tool_stdout_encoding.py` fails on `main` for two new tools, `tools/game_run_summary.py` and `tools/stage_timeline.py` (no `errors='replace'` on stdout). - On KosmicKrisp, `ps_cndmask_sign_mods`, `ps_valu16_mad_sel` and `cs_fmt_all` (NaN canonicalization, finding in #1608) and `cs_fma_fused` with #1724 (comment there) still fail. ~~I'll try to fix the open points of this PR this evening, or as soon as I have time, and post the results here.~~ Done: see Update 2. --- Claimed in the coordination issue as: SHADER-EXPLICIT-LOD-BIAS-MVK (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### What and why `ps_ssharp` fails on ~~every Mac~~ some Macs (see Update) with MoltenVK 1.4.2 (`point bias +1: (0,0): (1.0, 0.0, 0.502, 0.502) != (0.502, 0.502, 0.502, 0.502)`) and sits in the macOS job's `EXPECTED_FAILURES`. Measured on an Apple M3: MoltenVK drops `VkSamplerCreateInfo::mipLodBias` from **both** explicit-LOD samples (`image_sample_lz` with +0.6 / +1 stays on level 0) and the derivative-LOD `image_sample` (-0.6 / -1 stays on level 1). The test stopped at its first failing case, so only the explicit half showed. KosmicKrisp and llvmpipe (Mesa 26.3.1) on the same machine apply the bias. This adds a device fallback, `rdna2spirv.py --explicit-lod-bias`, in the same shape as `--f16-interp-fallback`: the shader applies the S#'s `LOD_BIAS` (word 2 [13:0], signed 5.8, read from the S# SGPRs; a literal S# folds to a constant, a zero bias adds nothing): - added to the `Lod` of `_lz`, `_l`, `_c_lz`, `_c_l` and of the implicit forms outside the PS; - added to the bias of `_b` / `_c_b`; - a `Bias` operand on implicit samples in the PS; - a 2^bias scale of `Grad` derivatives (the typed 2D implicit read, `_d`, and the `--texel-offset-fallback` gradients). The sampler still clamps to `MIN_LOD`..`MAX_LOD`. It is chosen per device, since on a driver that applies the bias it would count twice: ~~`explicit_lod_bias` in `tools/vk_subgroup_info.py` (MoltenVK's driver ID), read by `scripts/run_gpu_tests.py`, `runtime/test/shaders/build.py` and `make_game.py`~~ (replaced, see Update) (recorded with the other fallback flags); `LEONIDA_EXPLICIT_LOD_BIAS=1`/`0` forces it in the test runners. `check.py`'s `SAMPLER_CASES` gain `point bias +0.3` and `-0.3`: with two levels, an integer bias can't tell a bias applied once from twice, these can (they fail on KosmicKrisp and llvmpipe when the flag is forced there). Docs: a contract row in `docs/design.md` (with what is and isn't GPU-checked) and a Known problems row in `docs/testing.md`. `ps_ssharp` stays in the macOS job's `EXPECTED_FAILURES` for now: that runner is a paravirtual device I can't test here; if it passes there, the job prints its "drop it from the expected failures" notice and it can go in a follow-up. ### Tested Apple M3, macOS 26.5.1, test programs built from `main`: | `ps_ssharp` (10 cases) | flag off | flag on | default (auto) | |---|---|---|---| | MoltenVK 1.4.2 | FAIL (`bias +1`; also +-0.6, -1) | PASS | PASS (on) | | KosmicKrisp (Mesa 26.3.1) | PASS | FAIL `bias +0.3` (counted twice) | PASS (off) | | llvmpipe (Mesa 26.3.1) | PASS | FAIL `bias +0.3` (counted twice) | PASS (off) | - `tests/semantic/test_explicit_lod_bias.py` (new, 7 tests: literal, negative, zero and run-time S#, Grad scaling, Bias operand, `_b`, compute); `tests/test_vk_subgroup_info.py`, `tests/test_make_game_translator_flags.py` (probe mocked, new case), `tests/test_make_game_argparse.py` (probe mocked), `tests/test_shader_checks.py` (the two new cases). - On this branch: translator suite 6294 tests, 0 failed; docs tests OK. - With the open fixes merged together (#1444, #1518, #1724, #822, #1212, #1673, #1657, #1412, #1375; #822 and #1444 conflict with each other in `build.py`, resolution in #822's thread, none with this branch), test programs rebuilt: **MoltenVK has no failure left**: `run_gpu_tests.py` 195/263, 68 skipped (228/263 with `LEONIDA_W64_EMULATE=1`), `check.py` 187/231, 44 skipped. KosmicKrisp keeps exactly the failures it had without this branch (`cs_fma_fused` from #1724, `ps_cndmask_sign_mods`, `ps_valu16_mad_sel`, `cs_fmt_all`; see #1608); llvmpipe none. ctest 88/88; translator suite 6299 tests, standard-library loop 499 files, pytest 1912 passed, all 0 failed. - Not GPU-checked: `_d`, the `_c*` forms, cube and 3D samples, and the texel-offset gradients (covered by the semantic test only). GPUs tested: Apple M3 (10-core GPU), MoltenVK 1.4.2 and KosmicKrisp (Mesa 26.3.1), macOS 26.5.1 (25F80); llvmpipe (Mesa 26.3.1) AI-assisted: yes (Claude Code) ### Checklist - [x] Based on current `main` and merges cleanly. - [x] One topic. - [x] No game data, keys or decryption. - [x] The new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MoltenVK 1.4.2 drops VkSamplerCreateInfo::mipLodBias from both explicit and
derivative-LOD samples, so ps_ssharp's S# LOD_BIAS cases fail on every Mac.
With the flag the translator adds the S# bias (word 2 [13:0], signed 5.8) to
explicit LODs and to _b biases, as a Bias operand on implicit samples, and as
a 2^bias scale of Grad derivatives. tools/vk_subgroup_info.py reports
explicit_lod_bias for MoltenVK's driver ID, and run_gpu_tests.py, build.py
and make_game.py turn the flag on from it. ps_ssharp gains +-0.3 cases, which
fail when the bias counts twice.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The same MoltenVK 1.4.2 drops the bias on an Apple M3 and applies it on an
Apple M5 Pro (#1774 review), so the driver-ID rule turned ps_ssharp red on
the M5 Pro. tools/lod_bias_probe.py translates vs_ids and ps_ssharp without
the flag and draws LOD_BIAS 0, +1 and -1 with vk_sampler_test; the flag is
on only when +1 and -1 read the no-bias levels. run_gpu_tests.py, build.py
and make_game.py take its answer; vk_subgroup_info.py is back as on main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
tools/vk_lod_bias.py clears a two-level R32_SFLOAT image to 0.0 / 1.0 and
samples it at explicit LOD 0 through samplers with mipLodBias 0 and +1, from
Python through ctypes. vk_subgroup_info.py --lod-bias reports the answer as
explicit_lod_bias; lod_bias_probe.py uses it first and draws ps_ssharp only as
a fallback, with the Homebrew llvm-mc hint when llvm-mc is missing (#1774
review). build.py and make_game.py can now measure too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GPU coverage for the --explicit-lod-bias paths ps_ssharp doesn't run: the Lod
of image_sample_l, the 2^bias Grad scale of image_sample_d and the bias of
image_sample_b. check.py's SAMPLER_FIXTURES runs all three with the same cases.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GPU coverage for the rest of --explicit-lod-bias's forms. vk_sampler_test gains
a mode for a 6-layer cube (images_arr), a 128x128x2 volume (images_3d) and a
D32 texture (0.25 / 0.75 per level) with the S#'s compare function; the 2D
default is unchanged. check.py's SAMPLER_FIXTURES names each shader's mode and
judges ps_ssharp_c as compare results.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The last --explicit-lod-bias path without GPU coverage: with
LEONIDA_TEXOFF_FALLBACK=1 the implicit offset sample is a Grad sample whose
derivatives the flag scales. A SKIP without the fallback, since vk_sampler_test
enables no VK_KHR_maintenance8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	tools/vk_subgroup_info.py
Left over from the earlier draw-based version: it followed a try that always
returns and named an undefined build.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A level 1 that was never cleared also gives a biased 0.0, which read as a dropped bias.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Vulkan clamps the biased LOD: max(bias, minlod), as _b_cl already does, not max(0, minlod) + bias.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since #2098 (merged in from main) a tagged module reads its instruction's array only when the entry's kind names
it; with the 2D bit alone, ps_ssharp_cube and ps_ssharp_3d read the magenta fallback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:04:30 +00:00
Author
Owner

@⁠Mby159 on GitHub · 2026-11-25 12:11 UTC · original

Checked 1d19671eb on AMD: Radeon 780M Graphics (RDNA3 iGPU, gfx1103), AMD proprietary 26.10.2 (32.0.32015.12012, LLPC), Vulkan 1.4.359, Windows 11 10.0.29712, subgroup 32..64. This branch changes no C++, so we ran the branch's translator, fixtures and checker against the C++ test programs built from main bcaa13dad (the merge-base); nothing was merged.

  • tools/vk_subgroup_info.py on this GPU answers "explicit_lod_bias": false (driver_id: 1), so the fallback stays off here, consistent with this driver applying the sampler's own bias.
  • --filter ps_ssharp with the flag unset: PASS, "10 S#/T# cases, 4096 pixels each exact" - the two new point bias +0.3 and point bias -0.3 cases included.
  • With LEONIDA_EXPLICIT_LOD_BIAS=1 forced on, the new case fails: "point bias +0.3: (0,0): (0.502, 0.502, 0.502, 0.502) != (1.0, 0.0, 0.502, 0.502)" - the bias counted twice, matching the PR's own description (design.md / testing.md) of forcing the flag on a driver that already applies the sampler bias.
  • With LEONIDA_EXPLICIT_LOD_BIAS=0 forced off: PASS, all ten cases.

So on this AMD Windows device the ±0.3 cases also tell a bias counted once from twice, and the per-device selection keeps this GPU on the sampler's bias.

The whole suite with this branch and the flag unset gives the same result as main on this GPU: 273/273 shaders translated and spirv-val clean, 243/263 passed, 18 skipped, and the same two failures (cs_imgatomic_ext, which open PR #1518 fixes, and cs_texture_uav, which needs the D3D12 test program this machine cannot build).

Still not GPU-checked here: the _d, _c*, cube and 3D forms and the texel-offset gradients.

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

**@⁠Mby159** on GitHub · 2026-11-25 12:11 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7162041590) Checked `1d19671eb` on AMD: Radeon 780M Graphics (RDNA3 iGPU, gfx1103), AMD proprietary 26.10.2 (32.0.32015.12012, LLPC), Vulkan 1.4.359, Windows 11 10.0.29712, subgroup 32..64. This branch changes no C++, so we ran the branch's translator, fixtures and checker against the C++ test programs built from `main` `bcaa13dad` (the merge-base); nothing was merged. - `tools/vk_subgroup_info.py` on this GPU answers `"explicit_lod_bias": false` (`driver_id: 1`), so the fallback stays off here, consistent with this driver applying the sampler's own bias. - `--filter ps_ssharp` with the flag unset: PASS, "10 S#/T# cases, 4096 pixels each exact" - the two new `point bias +0.3` and `point bias -0.3` cases included. - With `LEONIDA_EXPLICIT_LOD_BIAS=1` forced on, the new case fails: "point bias +0.3: (0,0): (0.502, 0.502, 0.502, 0.502) != (1.0, 0.0, 0.502, 0.502)" - the bias counted twice, matching the PR's own description (design.md / testing.md) of forcing the flag on a driver that already applies the sampler bias. - With `LEONIDA_EXPLICIT_LOD_BIAS=0` forced off: PASS, all ten cases. So on this AMD Windows device the ±0.3 cases also tell a bias counted once from twice, and the per-device selection keeps this GPU on the sampler's bias. The whole suite with this branch and the flag unset gives the same result as `main` on this GPU: 273/273 shaders translated and spirv-val clean, 243/263 passed, 18 skipped, and the same two failures (`cs_imgatomic_ext`, which open PR #1518 fixes, and `cs_texture_uav`, which needs the D3D12 test program this machine cannot build). Still not GPU-checked here: the `_d`, `_c*`, cube and 3D forms and the texel-offset gradients. AI-assisted (MiniMax Code). No game files.
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 12:13 UTC · original

Tested 1d19671eb on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main 0d80bc5df:

  • tests/semantic/test_explicit_lod_bias.py: OK at this head; on main 7 errors. The wiring tests (test_make_game_argparse, test_make_game_translator_flags, test_shader_checks, test_vk_subgroup_info): 219 passed, 1 skipped, 485 subtests.
  • But on this machine the premise does not reproduce, and the auto-enabled flag regresses ps_ssharp:
    • main (no flag): ps_ssharp 8 S#/T# cases PASS on MoltenVK 1.4.2 — the sampler applies mipLodBias to the explicit-LOD sample here.
    • this head (auto flag; vk_subgroup_info reports explicit_lod_bias: true for driver_id 14): FAIL point bias +0.3: (0,0): (0.502, 0.502, 0.502, 0.502) != (1.0, 0.0, 0.502, 0.502) — exactly the fixture's doubled-bias case: the translator's +0.3 on top of the sampler's +0.3 = +0.6 reads level 1. Reproduced 3/3.
    • LEONIDA_EXPLICIT_LOD_BIAS=0 at this head: PASS 10/10; KosmicKrisp (flag off by detection): PASS 10/10.
  • So on M5 Pro + MoltenVK 1.4.2 the M3 measurement ("MoltenVK drops mipLodBias") does not hold: a driver-id gate alone turns a passing fixture red. It needs a behavioural probe (or a narrower condition) before enabling --explicit-lod-bias automatically.
  • Not run: the Apple M3 the measurement came from.

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

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 12:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7162085824) Tested `1d19671eb` on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against `main` `0d80bc5df`: - `tests/semantic/test_explicit_lod_bias.py`: **OK** at this head; on `main` **7 errors**. The wiring tests (`test_make_game_argparse`, `test_make_game_translator_flags`, `test_shader_checks`, `test_vk_subgroup_info`): **219 passed, 1 skipped, 485 subtests**. - **But on this machine the premise does not reproduce, and the auto-enabled flag regresses `ps_ssharp`:** - `main` (no flag): `ps_ssharp` **8 S#/T# cases PASS** on MoltenVK 1.4.2 — the sampler applies `mipLodBias` to the explicit-LOD sample here. - this head (auto flag; `vk_subgroup_info` reports `explicit_lod_bias: true` for driver_id 14): **FAIL** `point bias +0.3: (0,0): (0.502, 0.502, 0.502, 0.502) != (1.0, 0.0, 0.502, 0.502)` — exactly the fixture's doubled-bias case: the translator's +0.3 on top of the sampler's +0.3 = +0.6 reads level 1. Reproduced 3/3. - `LEONIDA_EXPLICIT_LOD_BIAS=0` at this head: **PASS 10/10**; KosmicKrisp (flag off by detection): **PASS 10/10**. - So on M5 Pro + MoltenVK 1.4.2 the M3 measurement ("MoltenVK drops `mipLodBias`") does not hold: a driver-id gate alone turns a passing fixture red. It needs a behavioural probe (or a narrower condition) before enabling `--explicit-lod-bias` automatically. - Not run: the Apple M3 the measurement came from. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠EvgHaze on GitHub · 2026-11-25 12:45 UTC · original

Independent Apple check, including the per-device choice this PR introduces.

Machine:  Apple M3, 10-core (MacBook Air 13", Mac15,13), macOS 27.0 (26A5406e), arm64
Drivers:  MoltenVK 1.4.2 (Homebrew), ICD loaded directly, driver id 14, subgroup 4..32
          KosmicKrisp, Mesa 26.3.1 (Homebrew), through the Vulkan loader, driver id 28, subgroup 32..32
Base:     main `0d80bc5` + this diff applied cleanly
Tools:    Homebrew llvm-mc 23.1.4, SPIRV-Tools 1.4.363.0, AppleClang 21.0.0, CMake 4.4.4

The auto-selection reports what it should:

MoltenVK     {"device": "Apple M3", "driver_id": 14, "explicit_lod_bias": True,  "per_vertex_inputs": False}
KosmicKrisp  {"device": "Apple M3", "driver_id": 28, "explicit_lod_bias": False, "per_vertex_inputs": False}

ps_ssharp, with the choice made per device:

Driver --explicit-lod-bias Result
MoltenVK 1.4.2 on (auto) PASS, 10 S#/T# cases, 4096 pixels each exact
KosmicKrisp 26.3.1 off (auto) PASS, 10 S#/T# cases, 4096 pixels each exact

On main, MoltenVK fails this fixture on this machine (point bias +1: (0,0): (1.0, 0.0, 0.502, 0.502)), so the flag is what fixes it.

Negative control, the risk your design row names: forcing LEONIDA_EXPLICIT_LOD_BIAS=1 on KosmicKrisp fails exactly as documented —

FAIL  ps_ssharp  point bias +0.3: (0,0): (0.502, 0.502, 0.502, 0.502) != (1.0, 0.0, 0.502, 0.502)

so the per-device probe is load-bearing, not cosmetic: without it KosmicKrisp would count the bias twice and lose the ±0.3 cases.

Both drivers translate the two modules with spirv-val clean.

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

**@⁠EvgHaze** on GitHub · 2026-11-25 12:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7162804266) Independent Apple check, including the per-device choice this PR introduces. ```text Machine: Apple M3, 10-core (MacBook Air 13", Mac15,13), macOS 27.0 (26A5406e), arm64 Drivers: MoltenVK 1.4.2 (Homebrew), ICD loaded directly, driver id 14, subgroup 4..32 KosmicKrisp, Mesa 26.3.1 (Homebrew), through the Vulkan loader, driver id 28, subgroup 32..32 Base: main `0d80bc5` + this diff applied cleanly Tools: Homebrew llvm-mc 23.1.4, SPIRV-Tools 1.4.363.0, AppleClang 21.0.0, CMake 4.4.4 ``` **The auto-selection reports what it should:** ```text MoltenVK {"device": "Apple M3", "driver_id": 14, "explicit_lod_bias": True, "per_vertex_inputs": False} KosmicKrisp {"device": "Apple M3", "driver_id": 28, "explicit_lod_bias": False, "per_vertex_inputs": False} ``` **`ps_ssharp`, with the choice made per device:** | Driver | `--explicit-lod-bias` | Result | |---|---|---| | MoltenVK 1.4.2 | on (auto) | **PASS**, 10 S#/T# cases, 4096 pixels each exact | | KosmicKrisp 26.3.1 | off (auto) | **PASS**, 10 S#/T# cases, 4096 pixels each exact | On main, MoltenVK fails this fixture on this machine (`point bias +1: (0,0): (1.0, 0.0, 0.502, 0.502)`), so the flag is what fixes it. **Negative control, the risk your design row names:** forcing `LEONIDA_EXPLICIT_LOD_BIAS=1` on KosmicKrisp fails exactly as documented — ```text FAIL ps_ssharp point bias +0.3: (0,0): (0.502, 0.502, 0.502, 0.502) != (1.0, 0.0, 0.502, 0.502) ``` so the per-device probe is load-bearing, not cosmetic: without it KosmicKrisp would count the bias twice and lose the ±0.3 cases. Both drivers translate the two modules with `spirv-val` clean. AI-assisted. No game data: the fixture is hand-written and every number above is test output.
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 14:14 UTC · original

Adding a datapoint that makes the driver-id gate look OS-version-dependent: an Apple M5 Pro on macOS 26.7.3 (25G342) with the same MoltenVK 1.4.2 (driver id 14), base main 0d80bc5df, binaries from the build at 66d4f5aa3, Homebrew llvm-mc 23.1.4 / SPIRV-Tools 1.4.363:

  • vk_subgroup_info reports driver_id: 14, explicit_lod_bias: true — i.e. the auto path enables the flag.
  • main without the flag: ps_ssharp 8/8 PASS — on this macOS the sampler applies mipLodBias to the explicit-LOD sample, so the M3/macOS 27 premise does not hold here.
  • this head, auto flag on: FAIL point bias +0.3: (0,0): (0.502, 0.502, 0.502, 0.502) != (1.0, 0.0, 0.502, 0.502) — the same doubled-bias failure as the forced-on negative controls (KosmicKrisp here, and Mby159's forced-on AMD run). Reproduced 3/3.
  • LEONIDA_EXPLICIT_LOD_BIAS=0 at this head: PASS 10/10; KosmicKrisp, flag off by detection: PASS 10/10.

So "MoltenVK drops mipLodBias" is true on the macOS 27.0/M3 run above but false on macOS 26.7.3 with the identical MoltenVK version; driver_id == MOLTENVK alone turns a passing fixture red on 26.7.3. The auto choice needs a behavioural probe (or an OS/Metal-version condition) rather than the driver id.

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

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 14:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7164969713) Adding a datapoint that makes the driver-id gate look OS-version-dependent: an Apple M5 Pro on **macOS 26.7.3 (25G342)** with the same **MoltenVK 1.4.2** (driver id 14), base `main` `0d80bc5df`, binaries from the build at `66d4f5aa3`, Homebrew llvm-mc 23.1.4 / SPIRV-Tools 1.4.363: - `vk_subgroup_info` reports `driver_id: 14`, `explicit_lod_bias: true` — i.e. the auto path enables the flag. - `main` **without** the flag: `ps_ssharp` **8/8 PASS** — on this macOS the sampler applies `mipLodBias` to the explicit-LOD sample, so the M3/macOS 27 premise does not hold here. - this head, **auto flag on**: **FAIL** `point bias +0.3: (0,0): (0.502, 0.502, 0.502, 0.502) != (1.0, 0.0, 0.502, 0.502)` — the same doubled-bias failure as the forced-on negative controls (KosmicKrisp here, and Mby159's forced-on AMD run). Reproduced 3/3. - `LEONIDA_EXPLICIT_LOD_BIAS=0` at this head: **PASS 10/10**; KosmicKrisp, flag off by detection: **PASS 10/10**. So "MoltenVK drops `mipLodBias`" is true on the macOS 27.0/M3 run above but false on macOS 26.7.3 with the identical MoltenVK version; `driver_id == MOLTENVK` alone turns a passing fixture red on 26.7.3. The auto choice needs a behavioural probe (or an OS/Metal-version condition) rather than the driver id. AI-assisted; synthetic fixtures only, no game data.
Author
Owner

@⁠EvgHaze on GitHub · 2026-11-25 14:35 UTC · original

Confirming the other half of what @⁠GeorgiyDemo describes, from the macOS 27.0 side, and agreeing the gate has to be behavioural.

My run, which the comment above quotes as "the macOS 27.0/M3 run": Apple M3, macOS 27.0 (26A5406e), MoltenVK 1.4.2 (Homebrew), driver_id: 14, base 0d80bc5df:

Result
main without the flag FAIL ps_ssharp — point bias +1: (0,0): (1.0, 0.0, 0.502, 0.502)
this head, auto flag on PASS 10 S#/T# cases, 4096 pixels each exact
KosmicKrisp, flag off by detection PASS 10/10
KosmicKrisp, LEONIDA_EXPLICIT_LOD_BIAS=1 forced FAIL point bias +0.3, the doubled bias

So the same driver_id 14 gives opposite answers on 26.7.3 and 27.0, and both directions are reproducible. driver_id == MOLTENVK is necessary but not sufficient.

For the probe, the cheapest shape that cannot lie is to sample with a known bias and read the returned LOD, the way ps_ssharp does, with a 1×1 chain: build a 2-mip texture, sample with image_sample_lz at Lod = 0 and mipLodBias = +1, and compare the returned texel against level 1. That is one vk_compute_test-sized program, no game data, and it answers the question on whichever macOS/Metal combination the user actually has, instead of encoding a version table.

If you want, I can write that probe into tools/vk_subgroup_info.py and test it on both sides — 27.0 here, and I can ask for a 26.7.3 run from the comment above.

AI-assisted.

**@⁠EvgHaze** on GitHub · 2026-11-25 14:35 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7165514474) Confirming the other half of what @⁠GeorgiyDemo describes, from the macOS 27.0 side, and agreeing the gate has to be behavioural. My run, which the comment above quotes as "the macOS 27.0/M3 run": Apple M3, **macOS 27.0 (26A5406e)**, MoltenVK 1.4.2 (Homebrew), `driver_id: 14`, base `0d80bc5df`: | | Result | |---|---| | `main` without the flag | **FAIL** `ps_ssharp` — `point bias +1: (0,0): (1.0, 0.0, 0.502, 0.502)` | | this head, auto flag on | **PASS** 10 S#/T# cases, 4096 pixels each exact | | KosmicKrisp, flag off by detection | **PASS** 10/10 | | KosmicKrisp, `LEONIDA_EXPLICIT_LOD_BIAS=1` forced | **FAIL** `point bias +0.3`, the doubled bias | So the same `driver_id 14` gives opposite answers on 26.7.3 and 27.0, and both directions are reproducible. `driver_id == MOLTENVK` is necessary but not sufficient. For the probe, the cheapest shape that cannot lie is to sample with a known bias and read the returned LOD, the way `ps_ssharp` does, with a 1×1 chain: build a 2-mip texture, sample with `image_sample_lz` at `Lod = 0` and `mipLodBias = +1`, and compare the returned texel against level 1. That is one `vk_compute_test`-sized program, no game data, and it answers the question on whichever macOS/Metal combination the user actually has, instead of encoding a version table. If you want, I can write that probe into `tools/vk_subgroup_info.py` and test it on both sides — 27.0 here, and I can ask for a 26.7.3 run from the comment above. AI-assisted.
Author
Owner

@⁠Tauwni on GitHub · 2026-11-25 14:38 UTC · original

Thanks, this is the key datapoint, and you're right that the driver-ID gate is wrong.

It doesn't look like an OS-version condition either, though. My M3 is on an older macOS than your M5 Pro and still drops the bias:

Machine macOS MoltenVK 1.4.2 applies mipLodBias?
Apple M3 (this PR) 26.5.1 (25F80) no, ps_ssharp fails on main
Apple M5 Pro (yours) 26.7.3 (25G342) yes, passes on main
Apple M3 (EvgHaze) 27.0 (26A5406e) no, fails on main

So it follows the GPU (or its Metal family) more than the OS, and any static rule (driver ID, OS version, chip list) will be wrong somewhere. I'm working on replacing the gate with the behavioural probe you suggested: a small tool that translates vs_ids and ps_ssharp without the flag, draws them with vk_sampler_test at LOD_BIAS 0, +1 and -1, and turns the flag on only when +1 and -1 read the no-bias levels. An inconclusive probe leaves it off.

It's still being tested here. I'll push it and post the results in this thread when it's done, and it would help if you could rerun --filter ps_ssharp on your M5 Pro then. Until then, please don't merge this PR as it is: the current head turns ps_ssharp red on your machine.

AI-assisted (Claude Code).

**@⁠Tauwni** on GitHub · 2026-11-25 14:38 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7165591245) Thanks, this is the key datapoint, and you're right that the driver-ID gate is wrong. It doesn't look like an OS-version condition either, though. My M3 is on an *older* macOS than your M5 Pro and still drops the bias: | Machine | macOS | MoltenVK 1.4.2 applies `mipLodBias`? | |---|---|---| | Apple M3 (this PR) | 26.5.1 (25F80) | no, `ps_ssharp` fails on `main` | | Apple M5 Pro (yours) | 26.7.3 (25G342) | yes, passes on `main` | | Apple M3 (EvgHaze) | 27.0 (26A5406e) | no, fails on `main` | So it follows the GPU (or its Metal family) more than the OS, and any static rule (driver ID, OS version, chip list) will be wrong somewhere. I'm working on replacing the gate with the behavioural probe you suggested: a small tool that translates `vs_ids` and `ps_ssharp` without the flag, draws them with `vk_sampler_test` at LOD_BIAS 0, +1 and -1, and turns the flag on only when +1 and -1 read the no-bias levels. An inconclusive probe leaves it off. It's still being tested here. I'll push it and post the results in this thread when it's done, and it would help if you could rerun `--filter ps_ssharp` on your M5 Pro then. Until then, please don't merge this PR as it is: the current head turns `ps_ssharp` red on your machine. AI-assisted (Claude Code).
Author
Owner

@⁠Tauwni on GitHub · 2026-11-25 15:03 UTC · original

Thanks! The probe you describe is in the update I just pushed (66b27ac6e, see the Update section above): tools/lod_bias_probe.py draws ps_ssharp without the flag at LOD_BIAS 0, +1 and -1 on the two-level texture and turns the flag on only when +1 and -1 read the no-bias levels. On my M3 (26.5.1) it answers true on MoltenVK and false on KosmicKrisp and llvmpipe. A rerun on your 27.0 M3 would be very welcome.

Your idea of putting it in tools/vk_subgroup_info.py has a real advantage over mine: it wouldn't need the built test programs, so make_game.py and build.py could probe too (two of the "Still open" points). If you'd like to write that version, go ahead and I'll test it here; otherwise I'll look at it this evening. Either way, let's say who does it here so we don't both write it.

AI-assisted (Claude Code).

**@⁠Tauwni** on GitHub · 2026-11-25 15:03 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7166232432) Thanks! The probe you describe is in the update I just pushed (`66b27ac6e`, see the Update section above): `tools/lod_bias_probe.py` draws `ps_ssharp` without the flag at LOD_BIAS 0, +1 and -1 on the two-level texture and turns the flag on only when +1 and -1 read the no-bias levels. On my M3 (26.5.1) it answers `true` on MoltenVK and `false` on KosmicKrisp and llvmpipe. A rerun on your 27.0 M3 would be very welcome. Your idea of putting it in `tools/vk_subgroup_info.py` has a real advantage over mine: it wouldn't need the built test programs, so `make_game.py` and `build.py` could probe too (two of the "Still open" points). If you'd like to write that version, go ahead and I'll test it here; otherwise I'll look at it this evening. Either way, let's say who does it here so we don't both write it. AI-assisted (Claude Code).
Author
Owner

@⁠EvgHaze on GitHub · 2026-11-25 15:46 UTC · original

Rerun on the 27.0 M3, as asked.

Machine:  Apple M3, 10-core, macOS 27.0 (26A5406e), arm64
Tree:     `0d80bc5` + this head (`66b27ac6e`), runtime built at `runtime/build`
Tools:    Homebrew llvm-mc 23.1.4 on PATH, SPIRV-Tools 1.4.363.0, Python 3.13.7
MoltenVK 1.4.2   {"explicit_lod_bias": true,  "reason": "the sampler drops LOD_BIAS: +1 and -1 read the no-bias levels"}
KosmicKrisp      {"explicit_lod_bias": false, "reason": "the sampler applies LOD_BIAS +1 and -1"}

So the probe answers true on this 27.0 M3 too, which is what ps_ssharp needs here (main fails without the flag, 10/10 with it). Together with @⁠GeorgiyDemo's 26.7.3 run, that is the two sides the driver-id gate got wrong, and the behavioural probe now gets both right.

One thing to keep in mind if the probe ships: lod_bias_probe.py needs llvm-mc on PATH, and Homebrew's llvm is keg-only, so a Mac user hitting it first sees the raw 'llvm-mc' could not be started message. Cheap fix in the tool's error text (point at llvm/tools/mc_command.py's message, which already says LLVM_MC="$(brew --prefix llvm)/bin/llvm-mc"), and worth doing so the probe is not blamed for being broken.

On ownership: you take the vk_subgroup_info.py version this evening — I would rather not start it and have us both write it. I will test whatever you push on this 27.0 M3 and on KosmicKrisp, and I can ask the 26.7.3 machine in the comment above to run it too. If you would rather I write it, say so and I will start, but the split above is the safer one.

AI-assisted.

**@⁠EvgHaze** on GitHub · 2026-11-25 15:46 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7167304819) Rerun on the 27.0 M3, as asked. ```text Machine: Apple M3, 10-core, macOS 27.0 (26A5406e), arm64 Tree: `0d80bc5` + this head (`66b27ac6e`), runtime built at `runtime/build` Tools: Homebrew llvm-mc 23.1.4 on PATH, SPIRV-Tools 1.4.363.0, Python 3.13.7 ``` ```text MoltenVK 1.4.2 {"explicit_lod_bias": true, "reason": "the sampler drops LOD_BIAS: +1 and -1 read the no-bias levels"} KosmicKrisp {"explicit_lod_bias": false, "reason": "the sampler applies LOD_BIAS +1 and -1"} ``` So the probe answers `true` on this 27.0 M3 too, which is what `ps_ssharp` needs here (main fails without the flag, 10/10 with it). Together with @⁠GeorgiyDemo's 26.7.3 run, that is the two sides the driver-id gate got wrong, and the behavioural probe now gets both right. One thing to keep in mind if the probe ships: `lod_bias_probe.py` needs `llvm-mc` on `PATH`, and Homebrew's `llvm` is keg-only, so a Mac user hitting it first sees the raw `'llvm-mc' could not be started` message. Cheap fix in the tool's error text (point at `llvm/tools/mc_command.py`'s message, which already says `LLVM_MC="$(brew --prefix llvm)/bin/llvm-mc"`), and worth doing so the probe is not blamed for being broken. **On ownership:** you take the `vk_subgroup_info.py` version this evening — I would rather not start it and have us both write it. I will test whatever you push on this 27.0 M3 and on KosmicKrisp, and I can ask the 26.7.3 machine in the comment above to run it too. If you would rather I write it, say so and I will start, but the split above is the safer one. AI-assisted.
Author
Owner

@⁠Tauwni on GitHub · 2026-11-25 18:31 UTC · original

Thanks for the 27.0 rerun, and agreed on the split: I'll write the vk_subgroup_info.py version, so the probe no longer needs the built test programs, plus the clear llvm-mc message you suggest. I'll post here when it's pushed, with the M3 results, so you can run it on your 27.0 M3 and on KosmicKrisp.

AI-assisted (Claude Code).

**@⁠Tauwni** on GitHub · 2026-11-25 18:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7171015542) Thanks for the 27.0 rerun, and agreed on the split: I'll write the `vk_subgroup_info.py` version, so the probe no longer needs the built test programs, plus the clear `llvm-mc` message you suggest. I'll post here when it's pushed, with the M3 results, so you can run it on your 27.0 M3 and on KosmicKrisp. AI-assisted (Claude Code).
Author
Owner

@⁠Tauwni on GitHub · 2026-11-25 20:18 UTC · original

Update 2 is pushed (631a53832), see the top of the description. As discussed:

  • tools/vk_subgroup_info.py --lod-bias measures it in Python with one compute dispatch (tools/vk_lod_bias.py), with no built test programs, llvm-mc or SPIR-V tools. build.py and make_game.py use it too.
  • The draw fallback gives the Homebrew LLVM_MC hint when llvm-mc is missing.
  • Every sample form now has a GPU fixture (ps_ssharp_ld, _b, _cube, _3d, _c, _o), through new vk_sampler_test --cube/--3d/--dref modes.

On the M3 (26.5.1), all 7 ps_ssharp* pass on MoltenVK (probe true), KosmicKrisp and llvmpipe (probe false), and forcing the flag on the last two fails bias +0.3 as it should. With the open fixes merged, MoltenVK has no failure left.

@⁠EvgHaze: a run on your 27.0 M3 (MoltenVK and KosmicKrisp) would be great. @⁠GeorgiyDemo: on the M5 Pro, python -I tools/vk_subgroup_info.py --lod-bias should answer "explicit_lod_bias": false, and --filter ps_ssharp should pass all 7 with the flag off. Thanks both.

AI-assisted (Claude Code).

**@⁠Tauwni** on GitHub · 2026-11-25 20:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7173471928) Update 2 is pushed (`631a53832`), see the top of the description. As discussed: - `tools/vk_subgroup_info.py --lod-bias` measures it in Python with one compute dispatch (`tools/vk_lod_bias.py`), with no built test programs, llvm-mc or SPIR-V tools. `build.py` and `make_game.py` use it too. - The draw fallback gives the Homebrew `LLVM_MC` hint when `llvm-mc` is missing. - Every sample form now has a GPU fixture (`ps_ssharp_ld`, `_b`, `_cube`, `_3d`, `_c`, `_o`), through new `vk_sampler_test --cube/--3d/--dref` modes. On the M3 (26.5.1), all 7 `ps_ssharp*` pass on MoltenVK (probe `true`), KosmicKrisp and llvmpipe (probe `false`), and forcing the flag on the last two fails `bias +0.3` as it should. With the open fixes merged, MoltenVK has no failure left. @⁠EvgHaze: a run on your 27.0 M3 (MoltenVK and KosmicKrisp) would be great. @⁠GeorgiyDemo: on the M5 Pro, `python -I tools/vk_subgroup_info.py --lod-bias` should answer `"explicit_lod_bias": false`, and `--filter ps_ssharp` should pass all 7 with the flag off. Thanks both. AI-assisted (Claude Code).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-25 21:47 UTC · original

Thanks for Update 2! Three things before this can merge:

  • Conflict: it now conflicts with main in tools/vk_subgroup_info.py, after #624 landed. Please merge main in.
  • Dead code: in make_game.py, runtime_gpu_explicit_lod_bias() has a second try block after the first, which always returns. It's unreachable and uses an undefined build; please drop it.
  • Reruns: waiting for the M3 (27.0) and M5 Pro runs you asked for.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-25 21:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7175541475) Thanks for Update 2! Three things before this can merge: - **Conflict:** it now conflicts with `main` in `tools/vk_subgroup_info.py`, after #624 landed. Please merge `main` in. - **Dead code:** in `make_game.py`, `runtime_gpu_explicit_lod_bias()` has a second `try` block after the first, which always returns. It's unreachable and uses an undefined `build`; please drop it. - **Reruns:** waiting for the M3 (27.0) and M5 Pro runs you asked for. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠Tauwni on GitHub · 2026-11-25 23:22 UTC · original

@⁠aslan2142 thanks, both done, in your order:

  • Conflict: main is merged in (b14565930, up to 21d3662ad). #624 had added chosen_d / chosen_extensions for what my chosen_dev did, so I kept main's and the --lod-bias measurement now uses them. It looks the extensions up itself rather than through exts, which is only set when per_vertex is true.
  • Dead code: the unreachable second try in runtime_gpu_explicit_lod_bias() is removed (3fc618429), and nothing else in make_game.py changes.

Rerun at 3fc618429 on the Apple M3 (macOS 26.5.1):

  • The probe answers true on MoltenVK and false on KosmicKrisp and llvmpipe.
  • The ps_ssharp* fixtures pass in auto mode on all three, and forcing the flag off or on fails as documented.
  • ctest 101/101; translator suite 6325 tests, 0 failed; docs tests OK.
  • No failure that main doesn't also have. ctest needs #2096 today: without it, the build stops at vk_null_descriptor_test's missing generated/.

The 27.0 M3 and M5 Pro reruns are still pending.

AI-assisted (Claude Code).

**@⁠Tauwni** on GitHub · 2026-11-25 23:22 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7177470404) @⁠aslan2142 thanks, both done, in your order: - **Conflict:** `main` is merged in (`b14565930`, up to `21d3662ad`). #624 had added `chosen_d` / `chosen_extensions` for what my `chosen_dev` did, so I kept `main`'s and the `--lod-bias` measurement now uses them. It looks the extensions up itself rather than through `exts`, which is only set when `per_vertex` is true. - **Dead code:** the unreachable second `try` in `runtime_gpu_explicit_lod_bias()` is removed (`3fc618429`), and nothing else in `make_game.py` changes. Rerun at `3fc618429` on the Apple M3 (macOS 26.5.1): - The probe answers `true` on MoltenVK and `false` on KosmicKrisp and llvmpipe. - The `ps_ssharp*` fixtures pass in auto mode on all three, and forcing the flag off or on fails as documented. - ctest 101/101; translator suite 6325 tests, 0 failed; docs tests OK. - No failure that `main` doesn't also have. ctest needs #2096 today: without it, the build stops at `vk_null_descriptor_test`'s missing `generated/`. The 27.0 M3 and M5 Pro reruns are still pending. AI-assisted (Claude Code).
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-26 00:57 UTC · original

Thanks, the merge and the dead-code fix both look good: it merges cleanly and the translator suite passes.

Before merging:

  • Reruns: the M5 Pro (vk_subgroup_info.py --lod-bias should answer false) and the 27.0 M3 with the compute probe. The 27.0 result in the thread is from the draw probe.
  • macOS CI: EXPECTED_FAILURES in runtime.yml still lists ps_ssharp. Once the job runs, drop it if the runner's probe answers true, or add the new ps_ssharp_* fixtures if they fail there.
  • Probe control: vk_lod_bias.py answers true whenever the biased read is 0.0, which a level 1 that was never cleared also gives. Could you add a plain read at explicit LOD 1 that must return 1.0, and answer null otherwise?
  • Clamp order: outside the PS, image_sample_cl / image_sample_c_cl get max(0, minlod) + bias. Vulkan clamps after the bias, max(bias, minlod), as _b_cl already does.
  • design.md: "Confirmed on two Apple M3s" should say that 27.0 checked the draw probe, until it's rerun.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠aslan2142** on GitHub · 2026-11-26 00:57 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7179287145) Thanks, the merge and the dead-code fix both look good: it merges cleanly and the translator suite passes. Before merging: - **Reruns:** the M5 Pro (`vk_subgroup_info.py --lod-bias` should answer `false`) and the 27.0 M3 with the compute probe. The 27.0 result in the thread is from the draw probe. - **macOS CI:** `EXPECTED_FAILURES` in `runtime.yml` still lists `ps_ssharp`. Once the job runs, drop it if the runner's probe answers `true`, or add the new `ps_ssharp_*` fixtures if they fail there. - **Probe control:** `vk_lod_bias.py` answers `true` whenever the biased read is 0.0, which a level 1 that was never cleared also gives. Could you add a plain read at explicit LOD 1 that must return 1.0, and answer `null` otherwise? - **Clamp order:** outside the PS, `image_sample_cl` / `image_sample_c_cl` get `max(0, minlod) + bias`. Vulkan clamps after the bias, `max(bias, minlod)`, as `_b_cl` already does. - **design.md:** "Confirmed on two Apple M3s" should say that 27.0 checked the draw probe, until it's rerun. AI-assisted (Claude Code, Claude Opus 5.5).
Author
Owner

@⁠Tauwni on GitHub · 2026-11-26 01:45 UTC · original

@⁠aslan2142 thanks, done in your order:

  • Reruns: still pending: the M5 Pro (vk_subgroup_info.py --lod-bias should answer false) and the 27.0 M3 with the compute probe. @⁠GeorgiyDemo @⁠EvgHaze, when you have a moment, please rerun at the new head.
  • macOS CI: the macOS job hasn't run on this PR yet, because its workflows are awaiting a maintainer's approval. Once it runs, I'll drop ps_ssharp from EXPECTED_FAILURES if the runner's probe answers true, or add the ps_ssharp_* fixtures that fail there.
  • Probe control (1787a81c7): the shader also reads at explicit LOD 1 with no bias, and verdict() answers null unless that read is 1.0. On this M3, skipping the level 1 clear now gives null on all three drivers ("control read at LOD 1 gave 0.0"), where it used to give true on MoltenVK. New test: test_the_lod1_control_must_read_one.
  • Clamp order (85eac6b54): outside the PS, image_sample_cl / image_sample_c_cl now add the S# bias before the clamp, max(0 + bias, minlod), as _b_cl does. New semantic test: test_compute_cl_clamps_after_the_bias. It fails on the previous head.
  • design.md (eb464f2fc): it now says the 27.0 M3 checked the draw probe until it's rerun, and it describes the LOD 1 control and the clamp order.

I also merged main again (a88bb83e0, up to ad41fd517), because #2098 changed something this PR depends on: a tagged module now reads its instruction's array only when the table entry's kind names it. vk_sampler_test tagged the T# 2D only, so after the merge ps_ssharp_cube and ps_ssharp_3d read the magenta fallback. 743eda012 tags the array the texture sits in for --cube / --3d.

Rerun at 743eda012 on the Apple M3 (macOS 26.5.1):

  • The probe answers true on MoltenVK and false on KosmicKrisp and llvmpipe.
  • The ps_ssharp* fixtures pass in auto mode on all three, and forcing the flag off or on fails as documented.
  • ctest 106/106; translator suite 6341 tests, 0 failed; docs tests OK.
  • run_gpu_tests.py: no failure that main doesn't also have. ps_array_resinfo and ps_get_lod_array fail on main too since #2098, on every driver; #2169 fixes them.

AI-assisted (Claude Code).

**@⁠Tauwni** on GitHub · 2026-11-26 01:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7180092060) @⁠aslan2142 thanks, done in your order: - **Reruns:** still pending: the M5 Pro (`vk_subgroup_info.py --lod-bias` should answer `false`) and the 27.0 M3 with the compute probe. @⁠GeorgiyDemo @⁠EvgHaze, when you have a moment, please rerun at the new head. - **macOS CI:** the macOS job hasn't run on this PR yet, because its workflows are awaiting a maintainer's approval. Once it runs, I'll drop `ps_ssharp` from `EXPECTED_FAILURES` if the runner's probe answers `true`, or add the `ps_ssharp_*` fixtures that fail there. - **Probe control** (`1787a81c7`): the shader also reads at explicit LOD 1 with no bias, and `verdict()` answers `null` unless that read is 1.0. On this M3, skipping the level 1 clear now gives `null` on all three drivers ("control read at LOD 1 gave 0.0"), where it used to give `true` on MoltenVK. New test: `test_the_lod1_control_must_read_one`. - **Clamp order** (`85eac6b54`): outside the PS, `image_sample_cl` / `image_sample_c_cl` now add the S# bias before the clamp, `max(0 + bias, minlod)`, as `_b_cl` does. New semantic test: `test_compute_cl_clamps_after_the_bias`. It fails on the previous head. - **design.md** (`eb464f2fc`): it now says the 27.0 M3 checked the draw probe until it's rerun, and it describes the LOD 1 control and the clamp order. I also merged `main` again (`a88bb83e0`, up to `ad41fd517`), because #2098 changed something this PR depends on: a tagged module now reads its instruction's array only when the table entry's kind names it. `vk_sampler_test` tagged the T# 2D only, so after the merge `ps_ssharp_cube` and `ps_ssharp_3d` read the magenta fallback. `743eda012` tags the array the texture sits in for `--cube` / `--3d`. Rerun at `743eda012` on the Apple M3 (macOS 26.5.1): - The probe answers `true` on MoltenVK and `false` on KosmicKrisp and llvmpipe. - The `ps_ssharp*` fixtures pass in auto mode on all three, and forcing the flag off or on fails as documented. - ctest 106/106; translator suite 6341 tests, 0 failed; docs tests OK. - `run_gpu_tests.py`: no failure that `main` doesn't also have. `ps_array_resinfo` and `ps_get_lod_array` fail on `main` too since #2098, on every driver; #2169 fixes them. AI-assisted (Claude Code).
Author
Owner

@⁠EvgHaze on GitHub · 2026-11-26 04:28 UTC · original

Rerun at 743eda012, the head that merged main again, on the 27.0 M3 — so the "checked until it is rerun" note in design.md can go.

Machine:  Apple M3, 10-core, macOS 27.0 (26A5406e), arm64
Tree:     Tauwni/leonida `fix/explicit-lod-bias-moltenvk` @ 743eda012, clean clone, `runtime/build` (35 `vk_*` tools)
Tools:    Homebrew llvm-mc 23.1.6, SPIRV-Tools 1.4.363.0, AppleClang 21.0.0, CMake 4.4.4

vk_subgroup_info.py --lod-bias, MoltenVK 1.4.2 — the new flag answers and explains:

"driver_id": 14, "explicit_lod_bias": true,
"explicit_lod_bias_reason": "the sampler drops mipLodBias (+1 still reads level 0)"

tools/lod_bias_probe.py, three drivers on the same machine:

Driver Verdict Reason
MoltenVK 1.4.2 true the sampler drops mipLodBias (+1 still reads level 0)
KosmicKrisp 26.3.1 false the sampler applies mipLodBias (+1 reads level 1)
llvmpipe (Mesa 26.3.1) false the sampler applies mipLodBias (+1 reads level 1)

run_gpu_tests.py --filter ps_ssharp, auto mode, all three drivers: 6/6 PASS on each — ps_ssharp, _3d, _b, _c, _cube, _ld, 10 S#/T# cases each, 4096 pixels each exact.

So this head reproduces your 26.5.1 M3 result on 27.0, and the cube/3d tagging fix (743eda012) holds here — ps_ssharp_cube and ps_ssharp_3d read the real arrays rather than the magenta fallback.

That is the full set you asked for from this machine; I did not rerun the whole GPU suite or ctest, since your run already covers those and this head changes no C++ that the probe and the fixtures do not exercise.

@⁠GeorgiyDemo the 26.7.3 side is still the one missing — that is the pair that decides the gate, since 26.7.3 is where main passes without the flag.

AI-assisted. No game data.

**@⁠EvgHaze** on GitHub · 2026-11-26 04:28 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7182622191) Rerun at `743eda012`, the head that merged `main` again, on the 27.0 M3 — so the "checked until it is rerun" note in `design.md` can go. ```text Machine: Apple M3, 10-core, macOS 27.0 (26A5406e), arm64 Tree: Tauwni/leonida `fix/explicit-lod-bias-moltenvk` @ 743eda012, clean clone, `runtime/build` (35 `vk_*` tools) Tools: Homebrew llvm-mc 23.1.6, SPIRV-Tools 1.4.363.0, AppleClang 21.0.0, CMake 4.4.4 ``` **`vk_subgroup_info.py --lod-bias`**, MoltenVK 1.4.2 — the new flag answers and explains: ```text "driver_id": 14, "explicit_lod_bias": true, "explicit_lod_bias_reason": "the sampler drops mipLodBias (+1 still reads level 0)" ``` **`tools/lod_bias_probe.py`**, three drivers on the same machine: | Driver | Verdict | Reason | |---|---|---| | MoltenVK 1.4.2 | **true** | the sampler drops `mipLodBias` (+1 still reads level 0) | | KosmicKrisp 26.3.1 | **false** | the sampler applies `mipLodBias` (+1 reads level 1) | | llvmpipe (Mesa 26.3.1) | **false** | the sampler applies `mipLodBias` (+1 reads level 1) | **`run_gpu_tests.py --filter ps_ssharp`**, auto mode, all three drivers: **6/6 PASS on each** — `ps_ssharp`, `_3d`, `_b`, `_c`, `_cube`, `_ld`, 10 S#/T# cases each, 4096 pixels each exact. So this head reproduces your 26.5.1 M3 result on 27.0, and the cube/3d tagging fix (`743eda012`) holds here — `ps_ssharp_cube` and `ps_ssharp_3d` read the real arrays rather than the magenta fallback. That is the full set you asked for from this machine; I did not rerun the whole GPU suite or ctest, since your run already covers those and this head changes no C++ that the probe and the fixtures do not exercise. @⁠GeorgiyDemo the 26.7.3 side is still the one missing — that is the pair that decides the gate, since 26.7.3 is where `main` passes without the flag. AI-assisted. No game data.
Author
Owner

@⁠Tauwni on GitHub · 2026-11-26 05:47 UTC · original

@⁠EvgHaze thanks for the rerun. bcf199736 drops the "until it is rerun" note: design.md now says the compute probe answers true on both M3s (26.5.1 and 27.0, MoltenVK 1.4.2) and false on KosmicKrisp and llvmpipe, and that ps_ssharp and its five variants pass in auto mode on all three drivers on the 27.0 machine. Docs only, no code change.

What is still open is the M5 Pro on 26.7.3, as you said.

**@⁠Tauwni** on GitHub · 2026-11-26 05:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7183811428) @⁠EvgHaze thanks for the rerun. `bcf199736` drops the "until it is rerun" note: `design.md` now says the compute probe answers true on both M3s (26.5.1 and 27.0, MoltenVK 1.4.2) and false on KosmicKrisp and llvmpipe, and that `ps_ssharp` and its five variants pass in auto mode on all three drivers on the 27.0 machine. Docs only, no code change. What is still open is the M5 Pro on 26.7.3, as you said.
Author
Owner

@⁠Tauwni on GitHub · 2026-11-26 10:56 UTC · original

@⁠GeorgiyDemo When you have a moment on the M5 Pro (macOS 26.7.3), could you run this head (bcf199736)? It is the last result this PR is waiting for. Both M3s, on macOS 26.5.1 and 27.0, are done.

python3 -I tools/vk_subgroup_info.py --lod-bias
python3 -I scripts/run_gpu_tests.py --filter ps_ssharp

On your machine the probe should answer "explicit_lod_bias": false, since MoltenVK applies mipLodBias there. The six ps_ssharp* fixtures should pass in auto mode. If the probe answers true instead, its explicit_lod_bias_reason line is the useful part. Thanks!

AI-assisted (Claude Code).

**@⁠Tauwni** on GitHub · 2026-11-26 10:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7190043072) @⁠GeorgiyDemo When you have a moment on the M5 Pro (macOS 26.7.3), could you run this head (`bcf199736`)? It is the last result this PR is waiting for. Both M3s, on macOS 26.5.1 and 27.0, are done. ```bash python3 -I tools/vk_subgroup_info.py --lod-bias python3 -I scripts/run_gpu_tests.py --filter ps_ssharp ``` On your machine the probe should answer `"explicit_lod_bias": false`, since MoltenVK applies `mipLodBias` there. The six `ps_ssharp*` fixtures should pass in auto mode. If the probe answers true instead, its `explicit_lod_bias_reason` line is the useful part. Thanks! AI-assisted (Claude Code).
Author
Owner

@⁠Tauwni on GitHub · 2026-11-26 14:02 UTC · original · edited 2026-11-26 14:04 UTC

Apple M5 result for this head, run by cizerter (on Discord) on their machine. I'm relaying it, and thanks to cizerter for the run.

Machine:  Apple M5, macOS 26.6.2
Tree:     bcf199736 (this PR's head)
Driver:   the default one (MoltenVK, loaded directly)

tools/vk_subgroup_info.py --lod-bias

"explicit_lod_bias": false
"explicit_lod_bias_reason": "the sampler applies mipLodBias (+1 reads level 1)"

scripts/run_gpu_tests.py --filter ps_ssharp, auto mode

8 shaders: 8 translated, 8 pass spirv-val
  PASS  ps_ssharp             10 S#/T# cases, 4096 pixels each exact
  PASS  ps_ssharp_3d          10 S#/T# cases, 4096 pixels each exact
  PASS  ps_ssharp_b           10 S#/T# cases, 4096 pixels each exact
  PASS  ps_ssharp_c           10 S#/T# cases, 4096 pixels each exact
  PASS  ps_ssharp_cube        10 S#/T# cases, 4096 pixels each exact
  PASS  ps_ssharp_ld          10 S#/T# cases, 4096 pixels each exact
  SKIP  ps_ssharp_o           SKIP (needs LEONIDA_TEXOFF_FALLBACK=1: vk_sampler_test enables no VK_KHR_maintenance8)
6/7 passed, 1 skipped

So the measured answer is false on the M5, as on the M5 Pro without the flag: MoltenVK applies mipLodBias there. The fixtures pass without --explicit-lod-bias, and only the M3s, where the probe answers true, get the in-shader bias. That is the false half of the gate on real Apple hardware.

The M5 Pro on 26.7.3 (@⁠GeorgiyDemo) would still be a second false data point, but this one already covers the case that decides the gate.

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

**@⁠Tauwni** on GitHub · 2026-11-26 14:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7194185558) · edited 2026-11-26 14:04 UTC Apple M5 result for this head, run by cizerter (on Discord) on their machine. I'm relaying it, and thanks to cizerter for the run. ```text Machine: Apple M5, macOS 26.6.2 Tree: bcf199736 (this PR's head) Driver: the default one (MoltenVK, loaded directly) ``` **`tools/vk_subgroup_info.py --lod-bias`** ```text "explicit_lod_bias": false "explicit_lod_bias_reason": "the sampler applies mipLodBias (+1 reads level 1)" ``` **`scripts/run_gpu_tests.py --filter ps_ssharp`**, auto mode ```text 8 shaders: 8 translated, 8 pass spirv-val PASS ps_ssharp 10 S#/T# cases, 4096 pixels each exact PASS ps_ssharp_3d 10 S#/T# cases, 4096 pixels each exact PASS ps_ssharp_b 10 S#/T# cases, 4096 pixels each exact PASS ps_ssharp_c 10 S#/T# cases, 4096 pixels each exact PASS ps_ssharp_cube 10 S#/T# cases, 4096 pixels each exact PASS ps_ssharp_ld 10 S#/T# cases, 4096 pixels each exact SKIP ps_ssharp_o SKIP (needs LEONIDA_TEXOFF_FALLBACK=1: vk_sampler_test enables no VK_KHR_maintenance8) 6/7 passed, 1 skipped ``` So the measured answer is false on the M5, as on the M5 Pro without the flag: MoltenVK applies `mipLodBias` there. The fixtures pass without `--explicit-lod-bias`, and only the M3s, where the probe answers true, get the in-shader bias. That is the false half of the gate on real Apple hardware. The M5 Pro on 26.7.3 (@⁠GeorgiyDemo) would still be a second false data point, but this one already covers the case that decides the gate. AI-assisted (Claude Code). No game data.
Author
Owner

@⁠Tauwni on GitHub · 2026-11-26 23:51 UTC · original

Merged main (d1dff7949) for the needs rebase label: 0dcf650d1. The only conflict was the global line in rdna2spirv.py's main(), where main added ADDRESS_GUARD next to this PR's EXPLICIT_LOD_BIAS. Both are kept.

Retested at 0dcf650d1 on an Apple M3 (macOS 26.5.1), test programs rebuilt from this tree:

  • --lod-bias probe: true on MoltenVK 1.4.2, false on KosmicKrisp and llvmpipe (Mesa 26.3.1), as before.
  • run_gpu_tests.py --filter ps_ssharp: 6/6 pass on all three (ps_ssharp_o skips without LEONIDA_TEXOFF_FALLBACK=1).
  • The full MoltenVK suite: 202/275 passed, 71 skipped. The two failures are cs_fma_fused (#1724) and cs_imgatomic_ext (#1518).
  • Semantic suite: 501 files, 6382 tests, 0 failed. test_vk_lod_bias.py, test_vk_subgroup_info.py and test_make_game_translator_flags.py pass.

No change to the PR's own code.

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

**@⁠Tauwni** on GitHub · 2026-11-26 23:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7205921167) Merged `main` (`d1dff7949`) for the *needs rebase* label: `0dcf650d1`. The only conflict was the `global` line in `rdna2spirv.py`'s `main()`, where `main` added `ADDRESS_GUARD` next to this PR's `EXPLICIT_LOD_BIAS`. Both are kept. Retested at `0dcf650d1` on an Apple M3 (macOS 26.5.1), test programs rebuilt from this tree: - `--lod-bias` probe: true on MoltenVK 1.4.2, false on KosmicKrisp and llvmpipe (Mesa 26.3.1), as before. - `run_gpu_tests.py --filter ps_ssharp`: 6/6 pass on all three (`ps_ssharp_o` skips without `LEONIDA_TEXOFF_FALLBACK=1`). - The full MoltenVK suite: 202/275 passed, 71 skipped. The two failures are `cs_fma_fused` (#1724) and `cs_imgatomic_ext` (#1518). - Semantic suite: 501 files, 6382 tests, 0 failed. `test_vk_lod_bias.py`, `test_vk_subgroup_info.py` and `test_make_game_translator_flags.py` pass. No change to the PR's own code. AI-assisted (Claude Code). No game data.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1774/head:github-bot/gh-1774'
git switch 'github-bot/gh-1774'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1774'
git switch 'github-bot/gh-1774'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1774'
git switch 'github-bot/gh-1774'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1774'
git switch 'main'
git merge --squash 'github-bot/gh-1774'
git switch 'main'
git merge --ff-only 'github-bot/gh-1774'
git switch 'main'
git merge 'github-bot/gh-1774'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.