Skip to content

GPU tests: raw barycentrics under perspective (ps_persp_bary, vs_persp) - #837

Open
DaniSBR1 wants to merge 2 commits into
ItsNotRexed:mainfrom
DaniSBR1:pr-bary-perspective
Open

DaniSBR1 wants to merge 2 commits into
ItsNotRexed:mainfrom
DaniSBR1:pr-bary-perspective

Conversation

@DaniSBR1

@DaniSBR1 DaniSBR1 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

New TEST item, claimed in #634. Depends on: none. Suggested by @Vonsek in #794.

The raw-barycentric tests draw with vs_ids, where clip w = 1 at every vertex, so nothing checks that the raw i/j
(and the interpolated attributes) follow perspective-correct weights. This adds:

  • vs_persp.asm: one triangle at screen (5,8), (57,16), (21,55) of the 64x64 viewport with clip w = 1, 2, 4 and
    attr0 = (0.25,-0.5), (2.25,0.75), (-1,3).
  • ps_persp_bary.asm: ps_bary's code, drawn with it (an entry in PIXEL_VERTEX in check.py and in DRAWN_WITH in run_gpu_tests.py).
    Its name avoids the ps_bary prefix so --filter ps_bary keeps selecting one test.
  • check.py's bary_persp_problem, used by both runners: every pixel against CPU weights
    p_k = (l_k / w_k) / sum(l_m / w_m) from the screen-space weights l_k (tolerance 1e-5), pixels outside the triangle
    still clear. Coverage comes from edge functions at doubled pixel-centre coordinates, which are exact integers; no
    centre lies on an edge, so all 1158 covered pixels are judged whatever the rasterization rule. It also requires the
    affine weights to differ by more than 100x the tolerance on every covered pixel (they differ by at least 0.006
    here), so a NoPerspective regression can't pass by accident.

On main it runs the native BaryCoordKHR path and skips without VK_KHR_fragment_shader_barycentric, like
ps_bary. With LEONIDA_BARY_FALLBACK=1 it runs through #804's pass-through geometry shader instead.

Results

main ec8ec4c this branch
RX 5700 XT (RADV, no extension) — ps_persp_bary skips like ps_bary
Same, LEONIDA_BARY_FALLBACK=1 (#804's GS) — passes in run_gpu_tests.py and check.py; also at a forced wave64
That GS with NoPerspective on %bary — all 1158 covered pixels fail; the interpolated attributes still match
pytest 9361 passed, 90 skipped 9368 passed, 90 skipped (5 tests in the new tests/test_bary_persp_oracle.py, 2 new samples)

RDNA1 has no VK_KHR_fragment_shader_barycentric, so I can't run the native path here. @Vonsek verified it on an
RTX 5080 (below in this thread): pass, plus an independent check of all 4,096 pixels and a BaryCoordNoPerspKHR
control that fails. The second commit follows from that check: the first version left nine covered centres near an
edge unjudged.

AI-assisted (Claude Code): code, tests and this description. The tests ran on my own RX 5700 XT.

Tested 5a2645c (on main ec8ec4c) on AMD Radeon RX 5700 XT (RDNA1, Navi 10), RADV Mesa 26.0.8-1ubuntu0.3, Vulkan 1.4.335, Ubuntu 26.04.1 (kernel 7.0.0-42), LLVM 21: pass (the new test skips without the extension and passes with LEONIDA_BARY_FALLBACK=1)

🤖 Generated with Claude Code

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Native-extension verification on e7caae031ca7d0dc50b91def05e7f103b4884be4, Windows / RTX 5080 (NVIDIA 616.92), wave32. From an empty work directory, run_gpu_tests.py --filter ps_persp_bary built both checked-in shaders, both passed spirv-val, and the draw passed (1/1). The harness enabled VK_KHR_fragment_shader_barycentric. All four CPU oracle unit tests passed as well.

I also checked all 4,096 returned RGBA32F pixels independently using integer edge functions at doubled pixel-centre coordinates and reciprocal-W weights proportional to (4e0, 2e1, e2). All 1,158 covered centres matched both the interpolated attributes and raw i/j (maximum absolute channel error 5.26e-7); the other 2,938 retained the exact clear value. This includes nine interior centres in the checked-in oracle's edge tolerance band.

For the negative control I changed only the generated PS input decoration from BaryCoordKHR to BaryCoordNoPerspKHR, validated the module and drew it with the original VS. All 1,149 judged interior pixels failed the checked-in oracle. Independently, the raw i/j at all 1,158 covered centres changed to affine weights (max error against affine 1.24e-7), while both attribute channels and all clear pixels still matched. This measurement uses the native path on this head; the GS fallback is tracked separately in #804.

@DaniSBR1
DaniSBR1 force-pushed the pr-bary-perspective branch from e7caae0 to 3ef3ee4 Compare November 22, 2026 03:58
DaniSBR1 added a commit to DaniSBR1/Leonida that referenced this pull request Nov 22, 2026
Edge functions at doubled pixel-centre coordinates are exact integers, and no centre of vs_persp's triangle lies on
an edge, so the 1e-3 band that left nine covered centres unjudged is not needed. All 1158 covered pixels are now
checked; a centre exactly on an edge would be reported as a test-geometry problem. The smallest perspective/affine
gap over them is 6.4e-3, so the NoPerspective control still fails on every one. Suggested by Vonsek's independent
check in ItsNotRexed#837.

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

Copy link
Copy Markdown
Contributor Author

Thanks for the native run and the independent check. You're right about the nine centres: no pixel centre of this triangle lies on an edge (the edge functions at doubled coordinates are never 0), so the 1e-3 band wasn't needed. The second commit (3ef3ee4) computes coverage from those integer edge functions and judges all 1158 covered pixels. A centre exactly on an edge would now be reported as a test-geometry problem. The smallest perspective/affine gap over the 1158 is 6.4e-3, still far above the 1e-3 control threshold. There's a new unit test for a covered centre 6.5e-4 from an edge.

I also rebased onto main 4a36bb1 (a conflict in docs/design.md). On the RX 5700 XT the test still skips on main, the forced GS fallback passes at wave32 and wave64, and the NoPerspective control now fails on all 1158 pixels. The same holds through #804's generated GS. pytest: 2307 vs 2300 on main.

@Jess-Doit

Copy link
Copy Markdown
Contributor

Tested 3ef3ee4 merged with #804 (ffd0786, no conflicts) on a GTX 1060 6GB (Pascal: no
VK_KHR_fragment_shader_barycentric, so this is the fallback path), NVIDIA 560.94 / Vulkan 1.3.280, Windows 10
22H2, Vulkan SDK 1.4.363.0, llvm-mc 23.1.6, MSVC 19.44:

  • run_gpu_tests.py:
    • Without LEONIDA_BARY_FALLBACK: ps_persp_bary skips like ps_bary. 65/101 passed, 36 skipped, 0 failed.
    • With LEONIDA_BARY_FALLBACK=1: ps_persp_bary passes, "perspective-correct on every covered pixel". 69/101
      passed, 32 skipped, 0 failed. ps_bary, ps_uniform_branch and ps_scc_mask32 pass too.
  • build.py + check.py with LEONIDA_BARY_FALLBACK=1: ps_persp_bary ok, 63 of 92 pass, 29 skipped.
  • Khronos validation on the vs_persp + generated GS + ps_persp_bary draw: zero messages.
  • Control: forcing NoPerspective on Translator: --bary-fallback for raw barycentrics without VK_KHR_fragment_shader_barycentric (SHADER-98) #804's fallback input makes ps_persp_bary fail on all 1158 covered pixels,
    while ps_bary still passes (its w = 1). So this test catches what ps_bary can't.
  • tests/test_bary_persp_oracle.py passes.

Together with @Vonsek's native run on the RTX 5080, both the BaryCoordKHR path and the GS fallback are now checked
under perspective. Thanks for adding it.

(AI-assisted testing; repository test programs only.)

@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 3ef3ee4aac51bdda4d96a32bcf5f637828dc2ead on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

The revised ps_persp_bary oracle passed on the native barycentric path at 3ef3ee4aac51bdda4d96a32bcf5f637828dc2ead (Ubuntu 26.04.1, NVIDIA RTX 5090, driver 595.99.02). This checks the change after the earlier RTX 5080 run that identified nine covered pixel centres near an edge.

Both checked-in shaders translated and passed spirv-val. The filtered GPU runner reported “perspective-correct on every covered pixel” (1/1 passed). The revised oracle checks all 1,158 covered centres, and its five unit tests passed. This was a standalone PR-head run with the stock oracle. AI-assisted.

AI-assisted verification.

@DaniSBR1

Copy link
Copy Markdown
Contributor Author

Rebased onto ec8ec4c (it merges cleanly on 1628210 too). The conflicts were in check.py, run_gpu_tests.py and docs/design.md. Main now has PIXEL_VERTEX for pixel tests drawn with another vertex shader, so this PR uses that instead of its own PIXEL_VS: ps_persp_bary is one more entry. With #804 merged, the test also runs on the RX 5700 XT through LEONIDA_BARY_FALLBACK=1. It passes in both runners, and with NoPerspective on %bary all 1158 covered pixels fail. pytest: 9368 passed vs 9361 on main.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Measured with ps_oracle (#3061) on gfx1036 (AMD Radeon iGPU, Windows driver 26.10.1). I ran this PR's ps_persp_bary.asm body as the real pixel shader, drawn with the translated vs_persp, with s_mov_b32 m0, s3 added for the template's M0. On all 1158 covered pixels, attr0.xy and the raw I/J in v0/v1 match the perspective-correct reference from the header (screen (5,8), (57,16), (21,55); w = 1, 2, 4) within 1.25e-6. No interior pixel is left uncovered. AI-assisted.

DaniSBR1 and others added 2 commits November 22, 2026 16:37
The raw-barycentric tests draw with vs_ids, where clip w = 1 at every vertex, so nothing checked that the raw
i/j (and the attributes) follow perspective-correct weights. vs_persp draws one triangle at screen (5,8),
(57,16), (21,55) with clip w = 1, 2, 4 and per-vertex attr0; ps_persp_bary is ps_bary's code drawn with it.
check.py's bary_persp_problem compares every pixel with CPU weights p_k = (l_k / w_k) / sum(l_m / w_m) from the
screen-space weights l_k, checks that pixels outside stay clear, and requires the affine weights to differ by
more than 100x the tolerance on every judged pixel, so a NoPerspective regression can't pass. run_gpu_tests.py
uses the same reference (PIXEL_VS, DRAWN_WITH). Suggested by Vonsek in ItsNotRexed#794.

On main it runs the native BaryCoordKHR path (it skips without VK_KHR_fragment_shader_barycentric, like
ps_bary); any barycentric fallback that lands (ItsNotRexed#804) is exercised by it too. Checked on an RX 5700 XT (RADV)
through a GS fallback: passes at wave32 and wave64; with NoPerspective on the fallback's input, all 1149
covered pixels fail while the interpolated attributes still match. New tests/test_bary_persp_oracle.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Edge functions at doubled pixel-centre coordinates are exact integers, and no centre of vs_persp's triangle lies on
an edge, so the 1e-3 band that left nine covered centres unjudged is not needed. All 1158 covered pixels are now
checked; a centre exactly on an edge would be reported as a test-geometry problem. The smallest perspective/affine
gap over them is 6.4e-3, so the NoPerspective control still fails on every one. Suggested by Vonsek's independent
check in ItsNotRexed#837.

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

Copy link
Copy Markdown
Contributor Author

Rebased onto aa2988c (conflicts in check.py, run_gpu_tests.py and the docs). Main now runs a llvmpipe CI step that requires every shader with a barycentric-fallback geometry shader to pass. ps_persp_bary gets one, so I ran that step locally on llvmpipe: ps_bary, ps_persp_bary, ps_scc_mask32 and ps_uniform_branch all pass. docs/testing.md now lists it with the other three. On the RX 5700 XT it still skips natively and passes with LEONIDA_BARY_FALLBACK=1.

Thanks @Vonsek for the ps_oracle run on real hardware, and @Jess-Doit and @tylerstraub for the earlier runs.

@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 0917b203 (the rebased head) on NVIDIA GeForce RTX 3060 Ti (subgroup 32..32), driver 580.173.02, Linux (kernel 6.18), Python 3.14: pass, with native barycentrics and with the fallback.

scripts/run_gpu_tests.py suite ps_persp_bary
default 165/211 passed, 46 skipped, 0 failed PASS, perspective-correct on every covered pixel
LEONIDA_BARY_FALLBACK=1 162/211 passed, 49 skipped, 0 failed PASS, perspective-correct on every covered pixel (ps_persp_bary.bary_gs.spv built)
  • ps_bary still passes in both runs (4096/4096 pixels).
  • ctest: 47/47 passed. pytest tests/test_bary_persp_oracle.py: 5 passed.

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

@tunczzz

tunczzz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 0917b203 (merge base aa2988cc) on an NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), driver 616.56, Windows 11 10.0.26300. Translator and fixtures from this head; runtime test programs built from main aa2988cc (MSVC 19.44, Vulkan-Headers fetched by CMake, loader from the NVIDIA driver); spirv-as/spirv-val and llvm-mc 21 from WSL Ubuntu: pass.

  • scripts/run_gpu_tests.py: 165/211 passed, 46 skipped (wave64 programs on a 32-wide GPU), 0 failed.
  • Diffed test by test against main aa2988cc (164/210, 46 skipped): every main result is the same here.
  • New: ps_persp_bary PASS (perspective-correct on every covered pixel).

Not run: LEONIDA_W64_EMULATE=1, other vendors, Linux. No game files.

AI-assisted (Claude Code).

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