[PR #1774] 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) #1788

Open
opened 2026-11-26 21:18:57 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1774
Author: @Tauwni
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/explicit-lod-bias-moltenvk


📝 Commits (10+)

  • 1d19671 rdna2spirv: --explicit-lod-bias applies the S# LOD bias in the shader where MoltenVK drops the sampler's (SHADER-EXPLICIT-LOD-BIAS-MVK)
  • 66b27ac lod_bias_probe: measure whether the sampler applies mipLodBias instead of keying --explicit-lod-bias on MoltenVK's driver ID (SHADER-EXPLICIT-LOD-BIAS-MVK)
  • a03715c vk_subgroup_info --lod-bias: measure mipLodBias with one compute dispatch, no test programs needed (SHADER-EXPLICIT-LOD-BIAS-MVK)
  • 98b22ae ps_ssharp_ld, ps_ssharp_b: the S# mip fields on image_sample_l, _d and _b, judged by SAMPLER_CASES (SHADER-EXPLICIT-LOD-BIAS-MVK)
  • ff2e459 vk_sampler_test --cube/--3d/--dref; ps_ssharp_cube, ps_ssharp_3d, ps_ssharp_c: the S# mip fields on cube, 3D and depth-compare samples (SHADER-EXPLICIT-LOD-BIAS-MVK)
  • 631a538 ps_ssharp_o: the S# mip fields on image_sample_lz_o / image_sample_o under the texel-offset fallback (SHADER-EXPLICIT-LOD-BIAS-MVK)
  • b145659 Merge remote-tracking branch 'origin/main' into fix/explicit-lod-bias-moltenvk
  • 3fc6184 make_game: drop the unreachable second try in runtime_gpu_explicit_lod_bias (#1774 review)
  • 1787a81 vk_lod_bias: control read at explicit LOD 1 must return 1.0, else null (#1774 review)
  • 85eac6b rdna2spirv: --explicit-lod-bias clamps image_sample_cl / _c_cl outside the PS after the bias (#1774 review)

📊 Changes

26 files changed (+1374 additions, -60 deletions)

View changed files

📝 .github/workflows/runtime.yml (+4 -0)
📝 docs/design.md (+1 -0)
📝 docs/testing.md (+1 -0)
📝 make_game.py (+25 -1)
📝 runtime/cmake/translator_deps.cmake (+5 -3)
📝 runtime/test/shaders/build.py (+19 -0)
📝 runtime/test/shaders/check.py (+43 -7)
➕ runtime/test/shaders/ps_ssharp_3d.asm (+21 -0)
➕ runtime/test/shaders/ps_ssharp_b.asm (+23 -0)
➕ runtime/test/shaders/ps_ssharp_c.asm (+22 -0)
➕ runtime/test/shaders/ps_ssharp_cube.asm (+22 -0)
➕ runtime/test/shaders/ps_ssharp_ld.asm (+30 -0)
➕ runtime/test/shaders/ps_ssharp_o.asm (+24 -0)
📝 runtime/test/vk_sampler_test.cpp (+131 -32)
📝 scripts/run_gpu_tests.py (+34 -4)
➕ tests/semantic/test_explicit_lod_bias.py (+159 -0)
➕ tests/test_lod_bias_probe.py (+128 -0)
📝 tests/test_make_game_argparse.py (+1 -0)
📝 tests/test_make_game_translator_flags.py (+9 -1)
📝 tests/test_shader_checks.py (+4 -3)

...and 6 more files

📄 Description

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 (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161563852)

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1774 **Author:** [@Tauwni](https://github.com/Tauwni) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/explicit-lod-bias-moltenvk` --- ### 📝 Commits (10+) - [`1d19671`](https://github.com/ubiquitarianism/leonida/commit/1d19671ebd7965371e89a467ddf932f4244ec394) rdna2spirv: --explicit-lod-bias applies the S# LOD bias in the shader where MoltenVK drops the sampler's (SHADER-EXPLICIT-LOD-BIAS-MVK) - [`66b27ac`](https://github.com/ubiquitarianism/leonida/commit/66b27ac6e20debe6bf22290e4dddaf2fb7a91503) lod_bias_probe: measure whether the sampler applies mipLodBias instead of keying --explicit-lod-bias on MoltenVK's driver ID (SHADER-EXPLICIT-LOD-BIAS-MVK) - [`a03715c`](https://github.com/ubiquitarianism/leonida/commit/a03715c46af0f674722075d40cd9827b3d5cfc98) vk_subgroup_info --lod-bias: measure mipLodBias with one compute dispatch, no test programs needed (SHADER-EXPLICIT-LOD-BIAS-MVK) - [`98b22ae`](https://github.com/ubiquitarianism/leonida/commit/98b22aee0bb2a1994a25dd977e949ba2305cb0db) ps_ssharp_ld, ps_ssharp_b: the S# mip fields on image_sample_l, _d and _b, judged by SAMPLER_CASES (SHADER-EXPLICIT-LOD-BIAS-MVK) - [`ff2e459`](https://github.com/ubiquitarianism/leonida/commit/ff2e459123809a83c9f767e76707219d34194dee) vk_sampler_test --cube/--3d/--dref; ps_ssharp_cube, ps_ssharp_3d, ps_ssharp_c: the S# mip fields on cube, 3D and depth-compare samples (SHADER-EXPLICIT-LOD-BIAS-MVK) - [`631a538`](https://github.com/ubiquitarianism/leonida/commit/631a5383207ef01d0b96fdd0010c9898222b791a) ps_ssharp_o: the S# mip fields on image_sample_lz_o / image_sample_o under the texel-offset fallback (SHADER-EXPLICIT-LOD-BIAS-MVK) - [`b145659`](https://github.com/ubiquitarianism/leonida/commit/b145659304353a2da1809b49a2d0666c9cff4ffa) Merge remote-tracking branch 'origin/main' into fix/explicit-lod-bias-moltenvk - [`3fc6184`](https://github.com/ubiquitarianism/leonida/commit/3fc6184290e404b08abc0c131ebcb714a654c609) make_game: drop the unreachable second try in runtime_gpu_explicit_lod_bias (#1774 review) - [`1787a81`](https://github.com/ubiquitarianism/leonida/commit/1787a81c74097b2558f2e1bbc8da7a90a349447c) vk_lod_bias: control read at explicit LOD 1 must return 1.0, else null (#1774 review) - [`85eac6b`](https://github.com/ubiquitarianism/leonida/commit/85eac6b54d27b9e134b118934501c24f4f0bdc65) rdna2spirv: --explicit-lod-bias clamps image_sample_cl / _c_cl outside the PS after the bias (#1774 review) ### 📊 Changes **26 files changed** (+1374 additions, -60 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/runtime.yml` (+4 -0) 📝 `docs/design.md` (+1 -0) 📝 `docs/testing.md` (+1 -0) 📝 `make_game.py` (+25 -1) 📝 `runtime/cmake/translator_deps.cmake` (+5 -3) 📝 `runtime/test/shaders/build.py` (+19 -0) 📝 `runtime/test/shaders/check.py` (+43 -7) ➕ `runtime/test/shaders/ps_ssharp_3d.asm` (+21 -0) ➕ `runtime/test/shaders/ps_ssharp_b.asm` (+23 -0) ➕ `runtime/test/shaders/ps_ssharp_c.asm` (+22 -0) ➕ `runtime/test/shaders/ps_ssharp_cube.asm` (+22 -0) ➕ `runtime/test/shaders/ps_ssharp_ld.asm` (+30 -0) ➕ `runtime/test/shaders/ps_ssharp_o.asm` (+24 -0) 📝 `runtime/test/vk_sampler_test.cpp` (+131 -32) 📝 `scripts/run_gpu_tests.py` (+34 -4) ➕ `tests/semantic/test_explicit_lod_bias.py` (+159 -0) ➕ `tests/test_lod_bias_probe.py` (+128 -0) 📝 `tests/test_make_game_argparse.py` (+1 -0) 📝 `tests/test_make_game_translator_flags.py` (+9 -1) 📝 `tests/test_shader_checks.py` (+4 -3) _...and 6 more files_ </details> ### 📄 Description ## 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://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7183811428)) | | Apple M5 | 26.6.2 | false: "the sampler applies mipLodBias" | 6/6 pass, flag off | cizerter on Discord ([comment](https://github.com/ubiquitarianism/leonida/pull/1774#issuecomment-7194185558)) | 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://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7161563852) ### 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#1788
No description provided.