mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:50:52 +01:00
[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
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1788
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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+)
1d19671rdna2spirv: --explicit-lod-bias applies the S# LOD bias in the shader where MoltenVK drops the sampler's (SHADER-EXPLICIT-LOD-BIAS-MVK)66b27aclod_bias_probe: measure whether the sampler applies mipLodBias instead of keying --explicit-lod-bias on MoltenVK's driver ID (SHADER-EXPLICIT-LOD-BIAS-MVK)a03715cvk_subgroup_info --lod-bias: measure mipLodBias with one compute dispatch, no test programs needed (SHADER-EXPLICIT-LOD-BIAS-MVK)98b22aeps_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)ff2e459vk_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)631a538ps_ssharp_o: the S# mip fields on image_sample_lz_o / image_sample_o under the texel-offset fallback (SHADER-EXPLICIT-LOD-BIAS-MVK)b145659Merge remote-tracking branch 'origin/main' into fix/explicit-lod-bias-moltenvk3fc6184make_game: drop the unreachable second try in runtime_gpu_explicit_lod_bias (#1774 review)1787a81vk_lod_bias: control read at explicit LOD 1 must return 1.0, else null (#1774 review)85eac6brdna2spirv: --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 headNo code has changed since
743eda012.bcf199736and5c702e2a7only updatedocs/design.mdwith these results:--lod-bias)ps_ssharp*in auto modeSo 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_ssharpstays inEXPECTED_FAILURESuntil 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, andmainmerged againFrom @aslan2142's review:
tools/vk_lod_bias.pyalso reads at explicit LOD 1 with no bias, and answersnullunless that read is 1.0. Before, a level 1 that was never cleared also read 0.0, which looked like a dropped bias.image_sample_cl/image_sample_c_cladd the S# bias before the clamp,max(0 + bias, minlod), as_b_cldoes.make_game.pydropped, and thetools/vk_subgroup_info.pyconflict 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/--3dnow tag the array the texture sits in. Without that,ps_ssharp_cubeandps_ssharp_3dread 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-checkedThe open points of the Update below are done, with @EvgHaze's two suggestions:
tools/vk_subgroup_info.py --lod-biasmeasures 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 withmipLodBias0 and +1 in one compute dispatch.truewhen +1 still reads level 0,falsewhen it reads level 1,nullotherwise. It needs no built test programs, llvm-mc or SPIR-V tools.tools/lod_bias_probe.pyreturns that answer and only falls back to theps_ssharpdraw when it has none.build.pyandmake_game.pynow measure too, socheck.pyalone takes the flag andmake_game.pyno longer waits for the test programs. The option is off by default, so nothing else that runsvk_subgroup_info.pydispatches anything.llvm-mcmessage. When the draw fallback can't startllvm-mc, it givesmc_command.install_hint()(the HomebrewLLVM_MC="$(brew --prefix llvm)/bin/llvm-mc"line) instead of a bare "could not be started".SAMPLER_CASES(check.py'sSAMPLER_FIXTURES).vk_sampler_testgains--cube,--3dand--dref; its 2D default is unchanged.ps_ssharpimage_sample_lz,image_sampleps_ssharp_ld(new)image_sample_l,image_sample_d(theGradscale)ps_ssharp_b(new)image_sample_lz,image_sample_bps_ssharp_cube(new)image_sample_lz,image_sampleimages_arrps_ssharp_3d(new)image_sample_lz,image_sampleimages_3dps_ssharp_c(new)image_sample_c_lz,image_sample_cps_ssharp_o(new)image_sample_lz_o,image_sample_oLEONIDA_TEXOFF_FALLBACK=1(a SKIP without it)Tested at
631a53832on the Apple M3 (macOS 26.5.1):bias +1) on all 7true)bias +0.3(counted twice) on all 7false)bias +0.3on all 7false)generated/fix below, locally) onmaindb1a22d29, test programs rebuilt:run_gpu_tests.py(200/270 native, 233/270 emulated) orcheck.py(192/237, 45 skipped, flag measured bybuild.pyitself).cs_fma_fusedfrom #1724;ps_cndmask_sign_modsandps_valu16_mad_sel, fixed by the KosmicKrisp branch below;cs_fmt_all, see below).mainhas too:test_tool_stdout_encoding(#1837, #1673 and thestage_timelinebranch below) andtest_calibrated_texture_extra, a WindowsMoveFileExWtest that fails on macOS onmainalone.Still open after Update 2
ps_ssharpstays in itsEXPECTED_FAILURES; the job prints a notice if it passes there, and it can be dropped then.python -I tools/vk_subgroup_info.py --lod-biasshould answer"explicit_lod_bias": falsethere, and--filter ps_ssharpshould pass all 7 with the flag off.Found while testing and split off, since they're not this PR's topic:
generated/directory forvk_null_descriptor_test(the macOS/Linux build fails onmain).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_allon 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 IDThe reviews showed the driver-ID gate was wrong: the same MoltenVK 1.4.2 applies
mipLodBiason an Apple M5 Pro, so the auto flag counted the bias twice there and turned a passingps_ssharpred. It isn't an OS-version rule either:mipLodBias?ps_ssharpfails onmainmainmainWhat changed:
tools/lod_bias_probe.py: translatesvs_idsandps_ssharpwithout the flag, draws them withvk_sampler_testat LOD_BIAS 0, +1 and -1, and answerstrueonly when +1 and -1 read the no-bias levels. It answersfalsewhen both move ascheck.pyexpects, andnullotherwise (wrong no-bias draw, mixed answer, failed draw, no test programs).nullnever turns the flag on.scripts/run_gpu_tests.pyandmake_game.pytake the probe's answer.make_game.pyruns it on the test programs inruntime/build/linuxorruntime/buildif present; otherwise it keeps a recorded flag, like the other fallbacks.runtime/test/shaders/build.pyonly followsLEONIDA_EXPLICIT_LOD_BIAS: it also runs inside the CMake build, before the test programs exist, so it must not probe.tools/vk_subgroup_info.pyand its test are back as onmain, with noexplicit_lod_biasfield.tools/lod_bias_probe.pyis inruntime.yml's path filters. Newtests/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
66b27ac6eon the Apple M3:true, KosmicKrispfalse, llvmpipefalse, no test programsnull.ps_ssharpin 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 failsbias +1, KosmicKrisp on failsbias +0.3.main71a769d7d, test programs rebuilt:run_gpu_tests.py(195/264 native, 228/264 emulated) or incheck.pywithLEONIDA_EXPLICIT_LOD_BIAS=1, as the probe answers (187/231, 44 skipped).Still open
(done in Update 2): aftercheck.pyalone doesn't take the flagbuild.py, a Mac that needs it has to setLEONIDA_EXPLICIT_LOD_BIAS=1, whichpython -I tools/lod_bias_probe.py --build <test programs>answers. A lead: letbuild.pyprobe when it is given the test programs' folder, but never inside the CMake build.Not GPU-checked:(done in Update 2) A lead: a_d, the_c*forms, cube and 3D samples, and the texel-offset gradients.ps_ssharp-style fixture per form.ps_ssharpstays in itsEXPECTED_FAILURES; the job prints a notice if it passes there.(done in Update 2); before that the flag stays off unless it was recorded.make_game.pycan only probe once the test programs are built--filter ps_ssharprun andpython -I tools/lod_bias_probe.py --build <your build>would confirm the probe answersfalsethere.mainsinceba626820e, the macOS/Linux build ofvk_null_descriptor_testfails: itsadd_custom_commandwritesgenerated/cs_null_descriptors.spvwithout creatinggenerated/("Failed to open file"). AddingCOMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/generatedbeforeglslangValidatorfixes it locally (ctest 95/95).tests/test_tool_stdout_encoding.pyfails onmainfor two new tools,tools/game_run_summary.pyandtools/stage_timeline.py(noerrors='replace'on stdout).ps_cndmask_sign_mods,ps_valu16_mad_selandcs_fmt_all(NaN canonicalization, finding in #1608) andcs_fma_fusedwith #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_ssharpfails onevery Macsome 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'sEXPECTED_FAILURES. Measured on an Apple M3: MoltenVK dropsVkSamplerCreateInfo::mipLodBiasfrom both explicit-LOD samples (image_sample_lzwith +0.6 / +1 stays on level 0) and the derivative-LODimage_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#'sLOD_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):Lodof_lz,_l,_c_lz,_c_land of the implicit forms outside the PS;_b/_c_b;Biasoperand on implicit samples in the PS;Gradderivatives (the typed 2D implicit read,_d, and the--texel-offset-fallbackgradients).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:(replaced, see Update) (recorded with the other fallback flags);explicit_lod_biasintools/vk_subgroup_info.py(MoltenVK's driver ID), read byscripts/run_gpu_tests.py,runtime/test/shaders/build.pyandmake_game.pyLEONIDA_EXPLICIT_LOD_BIAS=1/0forces it in the test runners.check.py'sSAMPLER_CASESgainpoint bias +0.3and-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 indocs/testing.md.ps_ssharpstays in the macOS job'sEXPECTED_FAILURESfor 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)bias +1; also +-0.6, -1)bias +0.3(counted twice)bias +0.3(counted twice)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).build.py, resolution in #822's thread, none with this branch), test programs rebuilt: MoltenVK has no failure left:run_gpu_tests.py195/263, 68 skipped (228/263 withLEONIDA_W64_EMULATE=1),check.py187/231, 44 skipped. KosmicKrisp keeps exactly the failures it had without this branch (cs_fma_fusedfrom #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._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
mainand merges cleanly.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.