feat(shader): emulate barycentrics through tessellation on devices without geometry shaders #7308
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7308"
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?
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-17T22:31:39Z.
What
On a device without geometry shaders, a pixel shader that needs exact barycentrics or raw vertex values (and so uses the barycentric emulation) stops the draw with
Barycentric geometry SPIR-V: geometry shaders are unavailable. MoltenVK on Apple GPUs has no geometry shaders, so on macOS this ends many catalog titles, most of them a few seconds after start-up. MoltenVK does have tessellation, which can do the same job:BuildBarycentricTessellationShaders, next to the geometry stage inBarycentricGeometryShader.cpp). Each triangle of a triangle list becomes one three-point patch at tessellation level 1, so it comes out as the same single triangle. At each corner the evaluation stage readsgl_TessCoordto pick its vertex, then writes that corner as the weights and passes every vertex's parameters for raw reads. This is the same data the geometry stage provides. A flat parameter takes the first vertex's value, as the geometry stage's strip gives it.gl_ClipDistance, which every position export has written since #3878, goes through both stages. Without it, MoltenVK laid out the control stage's input differently from the vertex output: it read every position from the wrong offset, and nothing was drawn. #7124 found the same for rect lists; this PR uses itsVertexClipDistanceCountand builds on it.geometryShader. The tessellation stages are used only when the device hastessellationShaderbut nogeometryShader, and only for a triangle list without primitive restart. Strips, fans and restart still throw, with a message saying so.ShaderValidationaccepts the generated stages and checks their execution modes and three-element interface arrays. A four-stage vertex pipeline whose pixel shader does not emulate barycentrics still fails with "incorrect graphics stage count".VertexOrderCw, which keeps the triangle's facing; the draw test checks this with face culling.shader.mddebt entries are updated.Commits: refactor, recompiler stages, driver wiring, tests, docs, then a merge of current
main. In the merge, #7251's new last-vertex rect-list control stage also gets #7124's clip-distance argument, without whichRectListShaders.cppdoesn't compile.Related: #7201 handles MoltenVK per-vertex inputs differently, by rebuilding them from barycentric coordinates and derivatives; #6941 covers the mesh path. Neither generates tessellation stages for the vertex path.
Tested
Apple M2, macOS 26.7.1, MoltenVK 1.4.2 (
geometryShaderfalse,tessellationShadertrue), x86-64 under Rosetta, on the community macOS stack (mugurc's port branches overmainfrom 15 Oct) with #7124 applied, Release build. The changed files of this branch, as merged with currentmain, also compile on this Mac with SPIR-V Tools on.main's own libc doesn't build on macOS, so the tests ran on the port stack.agc_driver_pixel_barycentric_emulation(extended). It now runs the geometry route where the device has geometry shaders and the tessellation route where it has tessellation; before, it skipped any device withoutgeometryShader.main's test reportsskipped, the device lacks geometryShader.v_interp_movP0/P10/P20) are exact, host interpolation is unchanged, and back- and front-face culling give the same result as the same draw without emulation.MVK_CONFIG_DEBUGshowed MoltenVK's control-stage input struct asuint4, uint, float4 gl_Positionagainst a vertex output ofout_param_0, gl_Position, gl_ClipDistance[1], i.e. a mismatched layout. Forwarding the clip distances fixed it.VertexOrderCcwthen failed the culling check andVertexOrderCwpassed.agc_driver_graphics_tests(new unit tests) passes. It covers:shaderClipDistance.agc_fragment_barycentric,agc_driver_interpolation_modes,agc_driver_draw_offset_indices,agc_rect_list_position_invariant,agc_driver_indirect_patched_stage;agc_driver_interpolation_f16(nofragmentShaderBarycentric).agc_driver_tessellation(hull relative patch index) andagc_driver_pixel_ancillary_word(its pixel shader needs the Geometry capability).Titles (homebrew catalog, checksum-checked, 60 s each, relinked for macOS):
All of these stopped with
Barycentric geometry SPIR-V: geometry shaders are unavailablebefore. For three of them I rebuilt the same tree without this change and re-ran them:From earlier runs of the same stack:
last provoking vertex requires VK_EXT_provoking_vertex with provokingVertexLast enabled, which the M2 also lacks; the generated stages could handle that too, as #7251 does for rect lists, so it's a follow-up.Device limits of the M2 that stop titles here, not tested past them: no
geometryShader,shaderFloat64,VK_EXT_provoking_vertexorVK_EXT_depth_range_unrestricted.Not tested yet: Windows and Linux. There the geometry route is unchanged and the tessellation route runs only from the extended test, which lavapipe and other drivers with tessellation will run in CI. vkQuake (PPSA99010) is not tested here; on this Mac it stops earlier, creating its Vulkan surface.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T22:55:12Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)docs/dev/debt/shader.mdL146docs/dev/debt/shader.mdL146-147core/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppL607, L638Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/shader/recompiler/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.hppdocs/dev/debt/shader.mdcore/shader/recompiler/Recompiler.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppdocs/dev/debt/shader.mddocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/execution/PixelBarycentricEmulation.cppcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/RectListShaders.cppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/CMakeLists.txtdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderValidation.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/shader/recompiler/CMakeLists.txtdocs/dev/debt/shader.mdcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/include/Pipeline.hppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/shader/recompiler/Recompiler.hppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Execution/include/VulkanDevice.hppcore/libs/prx/libSceAgcDriver/Execution/src/Driver/Draw/Draw.cppcore/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppcore/libs/prx/libSceAgcDriver/Graphics/src/Pipeline.cppcore/shader/recompiler/CMakeLists.txtcore/shader/recompiler/Recompiler.hppcore/shader/recompiler/SpirvBackend/src/RectListShaders.cppdocs/dev/debt/shader.md