Repository navigation
Conversation
…der fallback A pixel shader that reads the raw barycentric pair (v0 = i, v1 = j outside v_interp, ~315 in the game) maps it to BaryCoordKHR. RDNA1 and older on RADV (and Intel Gen9) don't expose the extension, and RADV gets BaryCoordKHR wrong in wave64 pixel shaders on GFX10.1 (2x2 quads read .xy instead of .yz, ItsNotRexed#88). For each such shader the translator now also writes: - <name>.bary.spv: the same shader reading %bary from a smooth input at the first free Location; - <name>.bary_gs.spv: a pass-through geometry shader that copies Position and the varyings, and gives the three vertices the corners (1,0,0), (0,1,0), (0,0,1) at that Location. Interpolated, that is BaryCoordKHR. The vertex shader can't write it: indexed meshes share vertices between triangles. index.json records them as "bary_fallback": {"location", "ps", "gs"}. vk_harness draws the fallback (VKH_BARY_PS + VKH_BARY_GS) when the device lacks the extension; VKH_BARY=gs|builtin forces one path. check.py and run_gpu_tests.py pass it from index.json. RX 5700 XT (RADV, Mesa 26.0.8), pixel shader forced to each wave size: ps_bary GS: 0/4096 wrong at wave64 and wave32; BaryCoordKHR: 512/4096 wrong at wave64 ps_uniform_branch GS: passes at wave64 and wave32; BaryCoordKHR: fails at wave64 Flat integer varyings keep their bits through the GS (ps_flat). run_gpu_tests.py: 38/42 as before (the three ms_* need VK_EXT_mesh_shader). pytest: 832 passed (830 before, +2 new tests). Not carried by the GS: the vertex shader's ClipDistance, CullDistance, Layer and ViewportIndex. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Perspective interpolation readback on Windows for I built the PR's
Negative control: I added AI-assisted independent verification using source-built shaders. |
|
The fallback location allocator hits a device limit on both this head ( On RTX 5080 (616.92) and Radeon Graphics (26.10.1), Two controls on both adapters, using the previously measured 64×64 perspective triangle:
To reproduce, substitute AI-assisted independent verification. |
|
Thanks, @Vonsek. This covers what my runs couldn't: a GPU that has the extension, both paths side by side, and non-uniform w. The tests in this PR draw with w = 1 everywhere ( Would you mind if I add a small version of it to this PR (a vertex shader with per-vertex w and a check against the same CPU weights), so |
|
Yes, please add the small regression to this PR. With clip w = (1, 2, 4), compute the screen-space barycentric weights at each pixel center, divide each weight by its vertex w, and normalize by their sum. Our NoPerspective control on the raw weights changed all 1,158 covered pixels while leaving the ordinary interpolated attributes correct. Keeping that control alongside the CPU comparison should catch a regression even on devices where only the fallback runs. |
|
Thanks, @Vonsek, and sorry for the noise: I missed that SHADER-98 was claimed by @Jess-Doit in #374 two hours before my claim, and #804 implements it. Under #634's rules that claim comes first, so I'm closing this in favour of #804. I'll still add the regression you describe, as its own test PR on Two notes from this branch for #804:
|
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>
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>
New SHADER item, claimed in #634. Depends on: none. Related: #88, #146, #166 (known failures:
ps_bary,ps_uniform_branch,ps_scc_mask32without the extension).Pixel shaders that read the raw barycentric pair (
v0= i,v1= j outsidev_interp, ~315 in the game) aretranslated to
BaryCoordKHR. Devices withoutVK_KHR_fragment_shader_barycentriccan't run them: RDNA1 and older onRADV, Intel Gen9, llvmpipe. Since f348eb9 the GPU tests skip them there. RADV on GFX10.1 also gets
BaryCoordKHRwrongin wave64 pixel shaders (2x2 quads read
.xyinstead of.yz, #88/#146), so the extension path isn't enough thereeither.
This adds a fallback that needs only
geometryShader. For each such shader the translator also writes:<name>.bary.spv: the same shader, reading%baryfrom a smoothvec3input at the first free Location;<name>.bary_gs.spv: a pass-through geometry shader that copies Position and the varyings and gives the threevertices the corners (1,0,0), (0,1,0), (0,0,1) at that Location. Interpolated, that is
BaryCoordKHR. The vertexshader can't write it: in an indexed mesh one vertex can be corner 1 of one triangle and corner 2 of the next.
Vertex order is kept, so the provoking vertex (Flat inputs) and the winding don't change.
index.jsonrecords them as"bary_fallback": {"location", "ps", "gs"}.vk_harnessdraws the fallback(
VKH_BARY_PS+VKH_BARY_GS) when the device lacks the extension, before f348eb9's unsupported check;VKH_BARY=gs|builtinforces one path.check.pyandrun_gpu_tests.pypass it fromindex.json.Not carried by the geometry shader: the vertex shader's ClipDistance, CullDistance, Layer and ViewportIndex.
Results (main 8df277f vs this branch)
ps_bary,ps_uniform_branch,ps_scc_mask32on an RX 5700 XT (RADV)run_gpu_tests.py, RX 5700 XTrun_gpu_tests.py, llvmpipecheck.py, RX 5700 XT* main prints 89/97 there:
cs_wavemaskis reported twice (fixed separately, #793). The same three tests skip onthe AMD Windows driver on RDNA1 too, which doesn't expose the extension either (#166, TEST-58 entry). With the
llvmpipe CI job claimed in #634, they would run there as well.
With the pixel shader forced to wave64 and to wave32 (
VKH_SUBGROUP_SIZE), both tests pass through the fallback;through
BaryCoordKHRat wave64,ps_baryhad 512/4096 pixels wrong. Flat integer varyings keep their bits throughthe geometry shader (
ps_flatdrawn through it).Cost of the geometry shader on the same GPU, per 1M triangles: +0.00 ms with 1 varying, +0.17 ms with 8, +0.64 ms
with 16 (visible triangles at 1920x1080). Only pipelines whose pixel shader reads raw barycentrics pay it.
AI-assisted (Claude Code): code, tests and this description. The tests ran on my own RX 5700 XT.
Tested 00884f9 (on main 8df277f) 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
🤖 Generated with Claude Code