Skip to content

SHADER-925: use barycentric fallback automatically on Mesa ANV - #5568

Closed
iksZ2 wants to merge 0 commit into
ItsNotRexed:mainfrom
iksZ2:shader-925
Closed

iksZ2 wants to merge 0 commit into
ItsNotRexed:mainfrom
iksZ2:shader-925

Conversation

@iksZ2

@iksZ2 iksZ2 commented Nov 23, 2026

Copy link
Copy Markdown

Summary

  • Detect Intel Mesa ANV in tools/vk_subgroup_info.py.
  • Automatically select --bary-fallback in make_game.py and scripts/run_gpu_tests.py.
  • Preserve explicit LEONIDA_BARY_FALLBACK=0/1 overrides.
  • Document the Arc B580/Mesa ANV result and add synthetic probe/runner tests.

Hardware verification

Intel Arc B580, Mesa ANV 26.2.5:

  • Native ps_uniform_branch: FAIL (i=0.0, all 4096 pixels).
  • Native ps_scc_mask32: FAIL (i=0.0, all 4096 pixels).
  • Automatic fallback ps_uniform_branch: PASS (2048 s5=8, 2048 s5=7).
  • Automatic fallback ps_scc_mask32: PASS (2048 s5=8, 2048 s5=7).
  • Native ps_bary: PASS (4096/4096).

Testing

  • python -I tests/test_vk_subgroup_info.py
  • python -I tests/test_make_game_translator_flags.py
  • python -I tests/test_make_game_argparse.py
  • python -I tests/test_run_gpu_tests.py

AI-assisted (Copilot). No game data.

Depends on: none
SHADER-925

@Kev-Ball

Copy link
Copy Markdown

The automatic probe correctly returned false on my RTX 3080 Ti (CachyOS, NVIDIA 620.73.04). I found a discrepancy in the documented override on b8d79bc1: a fixture run and a game build can select opposite barycentric paths in the same environment.

Using the PR's MainWiringTest.run_main with the ANV probe result injected, I checked the flags delivered to both preflight and the shader stage, then checked run_gpu_tests.bary_fallback() with the same probe result and environment.

Probe result LEONIDA_BARY_FALLBACK Game build GPU test runner
ANV 0 fallback native
non-ANV 1 native fallback

In particular, the documented =0 workaround for forcing native mode on ANV works for the test runner, but a game rebuild still emits fallback shaders. If the override is intended for both entry points, the builder needs the same explicit-value handling before automatic selection, with these two cases in the wiring tests. If it is runner-only, scoping the override to the runner in the contract row and PR summary would clarify what someone can reproduce. This was a flag-selection test, CPU only after the live device probe. AI-assisted.

@iksZ2

iksZ2 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Fixed the override mismatch. make_game.py now handles LEONIDA_BARY_FALLBACK=1/0 the same as scripts/run_gpu_tests.py: 1 forces --bary-fallback, 0 forces native barycentrics, and an unset value remains probe-driven. Explicit --bary-fallback remains a positive game-build override.

Added builder wiring tests for both override directions and runner override tests. Verified on the Arc B580: forced fallback passes ps_uniform_branch, and forced native passes ps_bary. Focused builder, probe, and runner suites pass.

Updated commit: bb90d0c.

@Kev-Ball

Copy link
Copy Markdown

Retested my original four cases at bb90d0c5. With ANV injected and LEONIDA_BARY_FALLBACK=0, both preflight and the shader stage now receive no fallback flag and the GPU runner selects native. With non-ANV injected and =1, both receive --bary-fallback and the runner selects fallback. The other two combinations still agree, and the live RTX 3080 Ti probe still returns false. This resolves the discrepancy I reported. CachyOS, flag-selection retest, AI-assisted.

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head bb90d0c.

  • python -I -m pytest tests/test_make_game_argparse.py tests/test_make_game_translator_flags.py tests/test_run_gpu_tests.py tests/test_vk_subgroup_info.py -q -> 160 passed, 160 subtests.
  • Live probe, RTX 5070 Ti (barycentrics supported, per_vertex_inputs: true, driver 4): tools/vk_subgroup_info.py -> "barycentric_fallback": false; make_game.runtime_gpu_barycentric_fallback() -> False.
  • git diff --check clean.

Selection answer: it does not pick the fallback on non-ANV hardware that supports barycentrics (RADV and Intel Windows are covered by tests, NVIDIA verified live). It does pick it on every Mesa ANV device, whatever the Mesa version and whether or not the B580 bug is present. That is deliberate per docs/design.md/testing.md and logs a line, and the fallback output is correct, but the gate is wider than the measured bug; only ANV loses the per-vertex tests (ps_ij_computed, ps_interp_f16_high skip) and the corpus's computed-I/J class is documented as empty. Non-blocking if ANV-wide is intended; a Mesa-version gate would narrow it.

@iksZ2

iksZ2 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Resolved the conflicts by rebasing SHADER-925 onto the latest main. The branch now reports MERGEABLE (MERGE_STATE_STATUS=UNSTABLE, with no conflict).

Rebased commit: e30cb1b

Focused tests after rebase:

  • test_vk_subgroup_info.py: 50/50
  • test_make_game_translator_flags.py: 30/30
  • test_make_game_argparse.py: 36/36 (1 skipped)
  • test_run_gpu_tests.py: 50/50

No game data.

@memorypressure

Copy link
Copy Markdown

Verified against main 561b65a: only docs/design.md conflicts (round-44 rewrote the same bary-fallback contract row) — the code side merges fully and the whole wiring set passes on the merged tree: test_vk_subgroup_info 50/50, make_game_translator_flags 30/30, run_gpu_tests 50/50, make_game_argparse 36/36, semantic test_bary_fallback 12/12 (re-run). Please re-merge that one row by hand. VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA=6 matches the header, the LEONIDA_BARY_FALLBACK=0 force-off is cleanly documented as a behavior change, and the probe-failure path keeps the per_vertex keep_recorded_fallback convention. The branch reports no CI checks — worth a push now that round-44 moved main under you. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested e30cb1b on Intel UHD Graphics 630 (CFL GT2), Mesa ANV: test_vk_subgroup_info.py (50 tests), test_make_game_translator_flags.py (30), test_make_game_argparse.py (36, 1 skipped) and test_run_gpu_tests.py (50) pass. tools/vk_subgroup_info.py prints "barycentric_fallback": true for this device. With LEONIDA_BARY_FALLBACK unset, run_gpu_tests.py --filter ps_uniform_branch and --filter ps_scc_mask32 each pass 1/1 ("s5==8: 2048 (192 of them with bit 0), s5==7: 2048 (4096 px)") through the automatic fallback ("bary fallback GS: ps_uniform_branch.bary_gs.spv"). I did not run them with the fallback off, so the native failure in the description is not reproduced on this GPU.

AI-assisted.

@junaydirfan

Copy link
Copy Markdown

Tested e30cb1b4 (the PR head; its merge into main conflicts in docs/design.md) on Linux (CachyOS), on Gfx12 between the UHD 630 and the B580 above: pass. Full run_gpu_tests.py, LEONIDA_W64_EMULATE=1, test programs built from main 561b65a8.

GPU, driver probe barycentric_fallback LEONIDA_BARY_FALLBACK unset =0
Intel Raptor Lake-S iGPU (Xe-LP), Mesa ANV 26.3.1 (driver_id 6) true 203/232 passed, 29 skipped, 0 failed 199/232 passed, 33 skipped, 0 failed
RTX 4080 Laptop, NVIDIA 620.73.04 (driver_id 4) false 214/232, 17 skipped, 1 failed identical

@sovljanskii

Copy link
Copy Markdown
Contributor

Tested e30cb1b merged onto main 561b65a (the branch already contains it) on Apple M4, macOS 27.2.1, MoltenVK 1.4.2, Python 3.15.2 and 3.12.16: needs changes

  • The rebase damaged docs/design.md. Line 370 is a leftover conflict-marker fragment, >>>>>> bb90d0c50 (SHADER-925: fall back to barycentric interpolation on Mesa ANV). The diff also deletes three contract rows that are on main and have nothing to do with this PR: "Workgroup memory limit (SHADER-309)", "Wave64 leading-bit scans" and "Wave64 emulation: scalar exits from a folded EXECZ region". The design.md change shows as +2/−4 when it should be +1/−1 on the Barycentric fallback row. Fix: restore those three rows from main and delete line 370. No docs test catches either problem (test_design_contract_rows and test_docs_design_rows pass).
  • The variable beats an explicit command-line flag. make_game.py:2201-2208 checks LEONIDA_BARY_FALLBACK before a.bary_fallback, so LEONIDA_BARY_FALLBACK=0 make_game.py --bary-fallback drops the flag. On this M4, main passes --bary-fallback to preflight and shaders, and the PR passes neither. The design.md row says "explicit --bary-fallback also forces the fallback in make_game.py". Either check the flag first (command line, then variable, then probe) or document that =0 wins. Then add that case to test_barycentric_environment_override_matches_gpu_runner: today, changing a.bary_fallback = False (:2208) to pass doesn't fail any test.
  • Detection: it keys only on the driver ID, VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA = 6, which matches vulkan_core.h. It does not use vendor 0x8086 or the driver name. So Intel's Windows driver (5), MoltenVK (14, including Intel Macs), NVIDIA (4) and AMD (1/3) stay false. A Pascal game build still needs the explicit --bary-fallback, same as before.
  • M4 probe (tools/vk_subgroup_info.py): "barycentric_fallback": false, driver_id 14. I ran make_game.main() with the real probes (only game access and the stages stubbed) to see the flags it hands to preflight and shaders:
    • variable unset or =0: ('--f16-interp-fallback',), the same as main;
    • =1: the PR adds --bary-fallback; main ignores the variable for game builds. This is the documented behaviour change.
  • Full scripts/run_gpu_tests.py on the M4, main runner vs PR runner on the same build: 165/232 pass and 59 skip on both. All rows are identical, and the PR run prints no bary fallback GS line.
  • Tests: on both Pythons, test_vk_subgroup_info 50, test_make_game_translator_flags 30, test_make_game_argparse 36 (1 skipped) and test_run_gpu_tests 50 pass. So do test_shader_build_fallbacks (4) and semantic test_bary_fallback (12). compileall and git diff --check are clean. I also ran the rest of test_run_gpu_tests with the probe cache forced to True and then to False: 47/47 both ways, so those tests don't depend on the host GPU.
  • Mutations, 9 of 13 caught:
    • Caught: ANV detection always False; always True; driver 5 instead of 6; the key dropped from query(); the make_game auto branch ignored; the variable ignored; probe None turned into the fallback; the runner ignoring the probe; the runner treating None as the fallback.
    • Survived (a): VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA = 7, because test_barycentric_fallback uses the module constant. Pin the literal 6.
    • Survived (b): or vendor == 0x8086, because the intel_windows FakeDevice (tests/test_vk_subgroup_info.py:826) has vendor 0. Give it vendor_id=0x8086.
    • Survived (c): runner =0 no longer forcing native. test_env_override (tests/test_run_gpu_tests.py:26) doesn't stub the probe, so it passes only because this host says false. Patch subprocess.run to return {"barycentric_fallback": true} there.
    • Survived (d): the =0 plus command-line case above.
  • Gap, non-blocking: runtime/test/shaders/build.py:169/206/245 and check.py:345 still read only LEONIDA_BARY_FALLBACK == "1". On ANV with the variable unset, the build.py + check.py path still draws ps_uniform_branch / ps_scc_mask32 natively. The new docs/testing.md paragraph should say that path still needs =1, or the probe should be wired in there too.
  • Nit: bary_fallback = override at make_game.py:2202 is dead code. The next use is the walrus.

AI-assisted.

@iksZ2

iksZ2 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Fixed the reviewer findings:

  • restored the upstream contract rows and removed the rebase conflict fragment in docs/design.md;
  • made an explicit --bary-fallback CLI flag win over LEONIDA_BARY_FALLBACK=0 in make_game.py;
  • wired build.py/check.py to the same environment/probe override behavior;
  • strengthened ANV/vendor/runner mutation tests.

Affected suites pass: make_game translator 31/31, VK probe 51/51, GPU runner 50/50, standalone shader build 5/5, docs design/table 6/6.

Amended head: 264870b.

@iksZ2

iksZ2 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Final verification of amended head 264870b:

  • no merge conflict against current main;
  • docs/design.md has no conflict markers and the upstream contract rows are intact;
  • explicit --bary-fallback wins over LEONIDA_BARY_FALLBACK=0;
  • build.py/check.py follow the same environment/probe override behavior;
  • test_make_game_translator_flags.py 31/31, test_vk_subgroup_info.py 53/53, test_run_gpu_tests.py 51/51, test_shader_build_fallbacks.py 5/5, docs design/table suites 6/6.

No remaining sovljanskii finding is unresolved in this head.

@iksZ2

iksZ2 commented Nov 23, 2026

Copy link
Copy Markdown
Author

Final amended head: b4c0ec4. The duplicate barycentric contract row and rebase conflict fragment are removed; the upstream contract rows remain intact.

Validation: maker translator 31/31, VK probe 51/51, GPU runner 61/61, standalone shader build 5/5, docs design/table 6/6. Local merge-tree check against current main reports no conflict. GitHub mergeability is currently recalculating (MERGEABLE status had UNKNOWN during the check).

Sovljanskii’s blocking findings are resolved in this head.

vicennpacheco added a commit to vicennpacheco/Leonida that referenced this pull request Nov 23, 2026
…tsNotRexed#5933)

tools/vk_subgroup_info.py reports barycentric_fallback for gfx90c iGPUs
(Renoir, Lucienne, Cezanne, Barcelo: amdgpu's CHIP_RENOIR PCI IDs) under
VK_DRIVER_ID_AMD_PROPRIETARY, so make_game.py and run_gpu_tests.py select
--bary-fallback there through ItsNotRexed#5568's wiring. LEONIDA_BARY_FALLBACK=0/1
still overrides it.

On a Vega 8 (1002:15E7, driver 31.0.21921.13001) native BaryCoordKHR
returns a wrong third component in ps_bary and ps_persp_bary; through the
fallback both pass, and RADV on RDNA 3.5 passes natively. Other GCN 5
parts and RADV are not measured, so they are left out.

Depends on: ItsNotRexed#5568

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@iksZ2 iksZ2 closed this Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants