Skip to content

--bary-fallback: read 16-bit interpolants from the producer's decoded halves - #2086

Open
undeadhuman37 wants to merge 3 commits into
ItsNotRexed:mainfrom
undeadhuman37:bary-fallback-f16-halves
Open

undeadhuman37 wants to merge 3 commits into
ItsNotRexed:mainfrom
undeadhuman37:bary-fallback-f16-halves

Conversation

@undeadhuman37

Copy link
Copy Markdown
Contributor

Fixes @XFlawless1's finding: #1902 (comment)
Claimed: #1902 (comment)

What and why

A device without VK_KHR_fragment_shader_barycentric runs the translation with --bary-fallback. That flag has no PerVertexKHR inputs, so a v_interp_*_f16 read took the plain smooth-f32 interpolation of the whole 32-bit channel. Low and high then read the same value, which is neither half: ps_interp_f16_high was off by 0.984.

--f16-interp-fallback (the MoltenVK path) already solves the same problem without PerVertexKHR: the VS exports each param's two f16 halves decoded to f32 at locations 28 − 2N / 29 − 2N, and the PS reads its half as an ordinary smooth input. This PR makes --bary-fallback take that path too (f16_halves_on() in tools/rdna2spirv.py, used at the VS/mesh exports, the PS reads and the index metadata). Without --bary-fallback nothing changes.

  • A PS that reads raw barycentrics too: its %bary input goes to the lowest location the PS doesn't use, and the pass-through GS from tools/bary_fallback_gs.py copies the PS's inputs, which now list the half locations it reads.
  • An f16 read of an attribute with no half location (attr30, as under --f16-interp-fallback) is now Unsupported, not a wrong value.
  • The GPU runners (check.py, run_gpu_tests.py) no longer skip ps_interp_f16_high under LEONIDA_BARY_FALLBACK=1.

Tests

  • GPU, RTX 4070 SUPER, driver 621.01, Windows 11, LEONIDA_BARY_FALLBACK=1 python -I scripts/run_gpu_tests.py --filter ps_interp_f16_high: PASS (f16 low/high halves and f32 control within 2e-3). The same run with main's tools/rdna2spirv.py: FAIL, off by 0.984. ps_bary under the same setting still passes, 4096/4096 exact.
    • My GPU has the barycentric extension; the flag only changes the translation, so this is the module a Pascal card would get. A run on a GTX 10xx would still be welcome.
  • Semantic, tests/semantic/test_interp_p1lv_f16.py: the bary-fallback tests asserted the old behaviour (same channel for low and high). They now check the decoded-half inputs and metadata, distinct low/high values, the raw-barycentric case and the attr30 refusal. 3 of them fail on main.
  • python -m unittest discover -s tests/semantic: 1672 OK
  • python -I tests/test_run_gpu_tests.py OK; compileall and make_game.py --help OK
  • docs/design.md: the two 16-bit interpolation rows now describe --bary-fallback.

AI-assisted (Claude Code). No game files used.

🤖 Generated with Claude Code

@AvantBras

AvantBras commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested d60ab80fb671fa49439830a286ab81ee95f76269 on RTX 3060 12 GB, NVIDIA 580.178.04, Pop!_OS 22.04, using the Vulkan harnesses built at #2048’s head with the UBO tail off.

With LEONIDA_BARY_FALLBACK=1 LEONIDA_F16_INTERP_FALLBACK=0, ran python -I scripts/run_gpu_tests.py --build <build> --filter <fixture> separately for ps_interp_f16_high, ps_bary, and ms_f16_pack. The first passed (both halves and f32 control within 2e-3); the second passed 4,096/4,096 pixels through the generated fallback GS. The mesh fixture translated and validated, but still reports SKIP (per-vertex f16 interpolants need barycentrics) under this combination, so I did not count it as a GPU pass. This is forced fallback on a GPU with native barycentrics.

No game files. AI-assisted verification.

Follow-up: the skip is still unconditional in the ms_f16_pack branch of scripts/run_gpu_tests.py. Using the same two SPIR-V modules produced by that skipped run, I invoked VKH_MESH=1 vk_harness ms_f16_pack.spv ps_interp_f16_high.spv <out> directly. It drew 4096 pixels and the runner’s interp_f16_high_problem checker returned no error. So the mesh fallback works on this configuration; the runner skip hides it.

@Flyander Flyander 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.

The pixel-shader path consumes decoded f16 locations whenever the fallback is active, but decoded outputs and their metadata are only generated for VS/MS. A real geometry-shader producer therefore does not write the locations this PS reads, so interpolation can come from unrelated or undefined values. Please either emit the decoded halves through GS as well or reject this stage combination explicitly; coverage should include a PS fed by a real GS.

@gkissel

gkissel commented Nov 22, 2026

Copy link
Copy Markdown

Tested d60ab80f (merged onto main 4eb6155, a fast-forward) on an NVIDIA GeForce GTX 1650 Mobile (Turing TU117, 4 GiB), NVIDIA 620.70.06, Vulkan 1.4.357, CachyOS Linux: pass.

Full suite, not only the f16 fixture: LEONIDA_BARY_FALLBACK=1 LEONIDA_F16_INTERP_FALLBACK=0 LEONIDA_VK_DEVICE=1650 python -I scripts/run_gpu_tests.py --build runtime/build/linux (test programs built from 4eb6155; the PR changes no C++), once on main and once with this PR:

main 4eb6155 this PR
translated / pass spirv-val 184 of 185 184 of 185
run_gpu_tests.py 133/180 passed, 47 skipped, 0 failed 134/180 passed, 46 skipped, 0 failed
ps_interp_f16_high SKIP (per-vertex f16 interpolants need barycentrics) PASS (f16 low/high halves and f32 control within 2e-3)
ps_bary (through the fallback GS) PASS, 4096/4096 exact PASS, 4096/4096 exact
ms_f16_pack SKIP SKIP (same reason)
  • The one shader not translated in both runs is ps_ij_computed, refused with computed I/J pair under --bary-fallback: no PerVertexKHR inputs, the same on main.
  • No other test changed between the two runs.
  • With this PR: python -m unittest discover -s tests/semantic OK, python -I tests/test_run_gpu_tests.py OK.
  • My GPU has VK_KHR_fragment_shader_barycentric, so, as in your run, this is the module a Pascal card would get, not a run on one.

AI-assisted (Claude Code). No game files used.

undeadhuman37 added a commit to undeadhuman37/Leonida that referenced this pull request Nov 22, 2026
…xed#2086)

Under --bary-fallback (and --f16-interp-fallback) a PS reads 16-bit
interpolants from decoded-half locations that only VS and mesh producers
wrote, so a PS behind a translated GS read nothing. The GS now writes each
non-position output's decoded halves at every emit (Gen.gs_half_regs) and
lists them in f16_halves, so the PS's entries are among its producer's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
undeadhuman37 added a commit to undeadhuman37/Leonida that referenced this pull request Nov 22, 2026
…otRexed#2086)

After the rebase onto main (ItsNotRexed#2049 skipped the f16 tests only under the bary
fallback without the f16 fallback), the mesh producer's skip remained; the
bary fallback now reads decoded halves, so both tests run there.
tests/test_run_gpu_tests.py expects them drawn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@undeadhuman37
undeadhuman37 force-pushed the bary-fallback-f16-halves branch from d60ab80 to d569a31 Compare November 22, 2026 19:44
@undeadhuman37

Copy link
Copy Markdown
Contributor Author

@Flyander thanks, good catch. Fixed by emitting the halves through the GS, in e158282 (rebased onto main, so it no longer conflicts).

  • GS: a translated geometry shader now writes each non-position output's decoded f16 halves at every OpEmitVertex, at the same locations VS and mesh params use (Gen.gs_half_regs). They are left out when they would land on one of the GS's own outputs, as for VS. They're listed in the GS's f16_halves, so a PS's entries are among its GS producer's. This applies under --bary-fallback and under --f16-interp-fallback; without either, the GS translation is unchanged.
  • Coverage with a real GS (GeometryShaderF16HalvesTests in tests/semantic/test_interp_p1lv_f16.py, using runtime/test/shaders/gs_tri.asm with the ISG1/OSG1 run_gpu_tests.py gives it):
    • The GS declares %gs_out_f16h1_0/1 at locations 26/27, stores them at each of its three emits, and lists {"1": [26, 27]}.
    • A PS reading attr1's low and high halves lists the same entry, and every input location it declares is a GS output location.
    • Without the fallbacks, the GS is unchanged.
    • The new tests fail on the previous head (2 failures, 2 errors).
  • Rebase: main's GPU runners: run the f16 interpolation tests under the bary fallback when the f16 fallback is on (new TEST item, claim in #1902) #2049 skipped ps_interp_f16_high and ms_f16_pack under the bary fallback unless the f16 fallback was on too. With this PR the bary fallback reads decoded halves itself, so both skips are gone and tests/test_run_gpu_tests.py now expects both drawn.

Tests on RTX 4070 SUPER, driver 621.01, Windows 11:

  • LEONIDA_BARY_FALLBACK=1 LEONIDA_F16_INTERP_FALLBACK=0: ps_interp_f16_high, ms_f16_pack and gs_tri all pass.
  • gs_tri also passes with neither fallback and with LEONIDA_F16_INTERP_FALLBACK=1, 4096/4096 exact each time.
  • tests/semantic: OK. tests/test_translate.py: 541 passed, 4 skipped. tests/test_run_gpu_tests.py: OK. compileall and make_game.py --help: OK.
  • Not covered on the GPU: a draw of an f16-reading PS behind a translated GS. The harness has no fixture that packs f16 into a GS output yet, so that link is checked at the metadata and location level only.

AI-assisted (Claude Code).

undeadhuman37 added a commit to undeadhuman37/Leonida that referenced this pull request Nov 22, 2026
…xed#2086)

Under --bary-fallback (and --f16-interp-fallback) a PS reads 16-bit
interpolants from decoded-half locations that only VS and mesh producers
wrote, so a PS behind a translated GS read nothing. The GS now writes each
non-position output's decoded halves at every emit (Gen.gs_half_regs) and
lists them in f16_halves, so the PS's entries are among its producer's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@undeadhuman37

Copy link
Copy Markdown
Contributor Author

@Flyander thanks, good catch. Fixed by emitting the halves through the GS, in a3680aa (rebased onto main, so it no longer conflicts).

  • GS: a translated geometry shader now writes each non-position output's decoded f16 halves at every OpEmitVertex, at the same locations VS and mesh params use (Gen.gs_half_regs). They are left out when they would land on one of the GS's own outputs, as for VS. They're listed in the GS's f16_halves, so a PS's entries are among its GS producer's. This applies under --bary-fallback and under --f16-interp-fallback; without either, the GS translation is unchanged.
  • Coverage with a real GS (GeometryShaderF16HalvesTests in tests/semantic/test_interp_p1lv_f16.py, using runtime/test/shaders/gs_tri.asm with the ISG1/OSG1 run_gpu_tests.py gives it):
    • The GS declares %gs_out_f16h1_0/1 at locations 26/27, stores them at each of its three emits, and lists {"1": [26, 27]}.
    • A PS reading attr1's low and high halves lists the same entry, and every input location it declares is a GS output location.
    • Without the fallbacks, the GS is unchanged.
    • The new tests fail on the previous head (2 failures, 2 errors).
  • Rebase: main's GPU runners: run the f16 interpolation tests under the bary fallback when the f16 fallback is on (new TEST item, claim in #1902) #2049 skipped ps_interp_f16_high and ms_f16_pack under the bary fallback unless the f16 fallback was on too. With this PR the bary fallback reads decoded halves itself, so both skips are gone and tests/test_run_gpu_tests.py now expects both drawn.

Tests on RTX 4070 SUPER, driver 621.01, Windows 11:

  • LEONIDA_BARY_FALLBACK=1 LEONIDA_F16_INTERP_FALLBACK=0: ps_interp_f16_high, ms_f16_pack and gs_tri all pass.
  • gs_tri also passes with neither fallback and with LEONIDA_F16_INTERP_FALLBACK=1, 4096/4096 exact each time.
  • tests/semantic: OK. tests/test_translate.py: 562 passed, 4 skipped. tests/test_run_gpu_tests.py: OK. compileall and make_game.py --help: OK.
  • Not covered on the GPU: a draw of an f16-reading PS behind a translated GS. The harness has no fixture that packs f16 into a GS output yet, so that link is checked at the metadata and location level only.

AI-assisted (Claude Code).

undeadhuman37 added a commit to undeadhuman37/Leonida that referenced this pull request Nov 22, 2026
…otRexed#2086)

After the rebase onto main (ItsNotRexed#2049 skipped the f16 tests only under the bary
fallback without the f16 fallback), the mesh producer's skip remained; the
bary fallback now reads decoded halves, so both tests run there.
tests/test_run_gpu_tests.py expects them drawn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@undeadhuman37
undeadhuman37 force-pushed the bary-fallback-f16-halves branch from d569a31 to a3680aa Compare November 22, 2026 20:43
@zneel

zneel commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Tested a3680aae on AMD Radeon RX 9070 XT (RDNA4, subgroup 32..64), AMD 26.11.2, Windows 11 Pro 10.0.26300, AMD Ryzen 7 9800X3D CPU (64 GB RAM), Python 3.12.10: pass.

Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows llvm-mc 21.1.8, Vulkan SDK 1.4.363.0. No game files.

run result
run_gpu_tests.py (whole suite, native wave64) 185/199, 14 skipped, 0 failed (main 49475796: 170/185)
same with LEONIDA_W64_EMULATE=1 185/199, 14 skipped, 0 failed
pytest tests/test_run_gpu_tests.py tests/test_translate.py tests/test_shader_checks.py 674 passed, 4 skipped, 266 subtests passed in 174.30s (0:02:54)
unittest discover -s tests/semantic -p test_interp_p1lv_f16.py 40 OK

I also ran the path this PR changes: LEONIDA_BARY_FALLBACK=1 run_gpu_tests.py at this head, with the scratch build's test programs from another recent head (this PR changes no C++). The driver has VK_KHR_fragment_shader_barycentric, so the fallback is forced here rather than needed.

run result
LEONIDA_BARY_FALLBACK=1 run_gpu_tests.py 184/199, 15 skipped, 0 failed
ps_interp_f16_high (no longer skipped under the fallback) PASS: f16 low/high halves and the f32 control within 2e-3
ps_bary (with its pass-through GS ps_bary.bary_gs.spv) 4096/4096 pixels exact

The one extra skip is ps_ij_computed (computed I/J pairs need PerVertexKHR), as intended. GitHub now reports this branch as conflicting with main, so I tested the head as it is.

AI-assisted (Claude Code); I checked the results.

@undeadhuman37

Copy link
Copy Markdown
Contributor Author

Rebased onto main again in 1fdaf2a (it conflicted with gs_emit(end_primitive=...); kept main's signature, the GS halves are unchanged). RTX 4070 SUPER, driver 621.01: with LEONIDA_BARY_FALLBACK=1 LEONIDA_F16_INTERP_FALLBACK=0, ps_interp_f16_high, ms_f16_pack and gs_tri pass; gs_tri also passes with neither fallback. tests/test_translate.py 581 passed / 4 skipped, tests/test_run_gpu_tests.py OK. tests/semantic shows 7 failures and 2 errors (test_loop_ballot_barrier, test_cmp_class_f64, test_mutations), and main itself gives the same 7 + 2 here, so they're not from this PR. AI-assisted (Claude Code).

@undeadhuman37
undeadhuman37 force-pushed the bary-fallback-f16-halves branch from a3680aa to 1fdaf2a Compare November 22, 2026 22:47
undeadhuman37 added a commit to undeadhuman37/Leonida that referenced this pull request Nov 22, 2026
…xed#2086)

Under --bary-fallback (and --f16-interp-fallback) a PS reads 16-bit
interpolants from decoded-half locations that only VS and mesh producers
wrote, so a PS behind a translated GS read nothing. The GS now writes each
non-position output's decoded halves at every emit (Gen.gs_half_regs) and
lists them in f16_halves, so the PS's entries are among its producer's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
undeadhuman37 added a commit to undeadhuman37/Leonida that referenced this pull request Nov 22, 2026
…otRexed#2086)

After the rebase onto main (ItsNotRexed#2049 skipped the f16 tests only under the bary
fallback without the f16 fallback), the mesh producer's skip remained; the
bary fallback now reads decoded halves, so both tests run there.
tests/test_run_gpu_tests.py expects them drawn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
undeadhuman37 and others added 3 commits November 23, 2026 07:19
… halves

Under --bary-fallback there are no PerVertexKHR inputs, so v_interp_*_f16
read the plain 32-bit channel and ignored `high` (off by 0.984 in
ps_interp_f16_high). It now takes the --f16-interp-fallback path: the VS
exports the decoded halves and the PS reads its half. The GPU runners no
longer skip ps_interp_f16_high under LEONIDA_BARY_FALLBACK=1.

Finding by XFlawless1 in the coordination issue.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…xed#2086)

Under --bary-fallback (and --f16-interp-fallback) a PS reads 16-bit
interpolants from decoded-half locations that only VS and mesh producers
wrote, so a PS behind a translated GS read nothing. The GS now writes each
non-position output's decoded halves at every emit (Gen.gs_half_regs) and
lists them in f16_halves, so the PS's entries are among its producer's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…otRexed#2086)

After the rebase onto main (ItsNotRexed#2049 skipped the f16 tests only under the bary
fallback without the f16 fallback), the mesh producer's skip remained; the
bary fallback now reads decoded halves, so both tests run there.
tests/test_run_gpu_tests.py expects them drawn.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@undeadhuman37
undeadhuman37 force-pushed the bary-fallback-f16-halves branch from 1fdaf2a to 8e19116 Compare November 23, 2026 04:31
@undeadhuman37

Copy link
Copy Markdown
Contributor Author

Rebased onto main (8e19116). Kept main's mov_delta per-vertex set for the non-fallback path; under --bary-fallback the decoded halves are used, so the ps_interp_f16_high / ms_f16_pack skips stay removed.

Tested (RTX 4070 SUPER, driver 621.01):

  • compileall, make_game.py --help, tests/test_run_gpu_tests.py (41 OK)
  • semantic suite: 3 failures + 2 errors, all outside this change (main itself has 7 + 2 here); every *bary*, *f16*, *interp* test passes
  • GPU, LEONIDA_BARY_FALLBACK=1 LEONIDA_F16_INTERP_FALLBACK=0: ps_interp_f16_high, ms_f16_pack, gs_tri PASS

@junaydirfan

Copy link
Copy Markdown

Tested 8e191160 merged into main 98fa503f on Linux (CachyOS, kernel 7.3.5), llvm-mc 23.1.5, LEONIDA_W64_EMULATE=1, test programs built from main (this PR changes no C++): pass.

GPU driver run_gpu_tests.py main
Intel Raptor Lake-S iGPU (Xe-LP), subgroup 8..32 Mesa ANV 26.3.1 186/217 passed, 31 skipped, 0 failed 186/217
RTX 4080 Laptop GPU (Ada), subgroup 32 NVIDIA 620.73.04 201/217 passed, 16 skipped, 0 failed 201/217

Every other test has the same result as on main on both GPUs.

This PR changes the --bary-fallback path, so I also ran both GPUs with LEONIDA_BARY_FALLBACK=1:

GPU main this PR
Intel (no fragment barycentrics) 189/217, 0 failed 189/217, 0 failed; same results
RTX 4080 (fallback forced) 198/217, 0 failed 200/217, 0 failed

On the RTX 4080, ps_interp_f16_high and ms_f16_pack go from SKIP ("per-vertex f16 interpolants need barycentrics") to PASS ("f16 low/high halves and f32 control within 2e-3"), and nothing else changes. On Intel, ps_interp_f16_high already passes on main within 2e-3, and still does.

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.

6 participants