fix(agc): drop the vertex gl_Layer output from rect-list pipelines #16923
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16923"
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 frankea on 2026-11-07T22:38:58Z.
What
This is the rect-list counterpart of #16891 and is stacked on it: it reuses
DemoteVertexLayerOutputfromGraphics/include/PatchVertexLayer.hpp, which #16891 adds, so this branch starts at the #16891 head673188baf4(its three commits and a merge of main). Only the last three commits are new: a test and two one-line changes inGraphics/src/Pipeline.cpp.A rect-list draw runs the guest vertex shader in front of a generated tessellation control shader (
BuildRectListShaders). That control shader reads gl_Position, gl_ClipDistance and the parameters the pixel shader uses, and checks that the three corners form an axis-aligned rectangle. When the vertex shader also writes gl_Layer, MoltenVK reads the corners at the wrong offset, and on this route the check then fails: "rect-list requires finite nondegenerate axis-aligned positions with equal positive W". This PR creates the vertex module of a rect-list pipeline with gl_Layer demoted to a private variable, as #16891 does for barycentric patch pipelines. It also creates rect-list pipelines without the VkPipelineCache on MoltenVK, as guest tessellation and barycentric patch pipelines already are.Why
The mechanism is the one #16891 describes. MoltenVK runs the vertex shader as a compute kernel that captures its outputs to a buffer. The control shader cannot read gl_Layer, so SPIRV-Cross pads the control input struct with a member for it, and that member is sorted among the user locations, before gl_Position. The vertex kernel's own struct keeps gl_Layer as a built-in after gl_ClipDistance.
MSL that the local MoltenVK generated (MVK_CONFIG_DEBUG=1) for a rect-list pipeline whose vertex shader writes one parameter, three clip distances and a layer:
out_param_0,gl_Position,gl_ClipDistance[3],uint gl_Layer;m_32,uint m_326,gl_Position,gl_ClipDistance[3].The control shader therefore reads gl_Position 16 bytes late and at the wrong stride. This happens with a fresh pipeline cache as well, so no cache reuse is needed to hit it.
Dropping the layer changes nothing that is rendered. In Vulkan the layer comes from the last pre-rasterization stage. The generated rect-list evaluation shader writes no layer, so these draws already render to the first layer on every driver. Forwarding the layer through the rect-list stages is a separate change and is not part of this PR.
The pipeline cache change is needed for the same reason as in #16891. MoltenVK reuses a cached shader conversion when the new pipeline has every interface entry that the cached conversion marked as used, and padding members are not marked as used. The rect-list control shader is the same for every vertex shader that feeds the same parameters. Measured: a pipeline cache persisted by the build without this change, then loaded by a build with only the demotion commit, still fails the one-parameter layer cases of the new test (6 failed checks). With the cache bypass as well, the same stale cache file passes all 8 cases. The new test itself does not exercise this, because it starts without a persisted cache. Rect-list pipelines never use pipeline libraries, so no un-demoted library module can be linked in. The cost is that on MoltenVK every rect-list pipeline now converts its shaders to MSL once per session instead of loading the conversion from the persisted cache; rect-list draws are common, and this first-use cost was not measured in a title.
Quad-list draws do not take this route. They are expanded to triangle lists on the host and go through no generated control shader.
Tested
macOS 27.0.1 on an Apple M5 Max (Rosetta x86-64 build), with MoltenVK 1.4.2 from Vulkan SDK 1.4.363.0 and with a local MoltenVK 1.4.2 build. All runs used
ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1, on both ICDs. "Before" is the #16891 head673188baf4with the new test added.agc_driver_rect_list_vertex_layer. It draws a rectangle through the rect-list stages, reading per-vertex values with v_interp_mov, for vertex shaders with and without gl_Layer, next to clip distances and up to four parameters. Each draw runs once with a fresh pipeline cache and once after the other vertex shader's pipeline seeded the cache. Every pixel's coverage and values are checked.agc_driver_pixel_barycentric_emulation,agc_driver_rect_list_corner,agc_driver_barycentric_patch_vertex_layer,agc_driver_pipeline_journal,agc_driver_layered_array_color_draw,agc_driver_layered_volume_draw,agc_driver_zero_position_vertex,agc_driver_vertex_clip_cull_draw,agc_tessellation_pipeline_cache,agc_fragment_barycentric;APS5_NO_GPL=1:agc_driver_draw_cache_reuse,agc_driver_draw_cache_relocation,agc_driver_draw_data_hit_user_words;agc_driver_mesh_barycentric_emulationandagc_driver_tessellation_geometry(no mesh or geometry shaders).agc_driver_tessellation: the hull's relative patch index across instances;agc_driver_rect_list_indirect: the same rect-list position refusal, but its vertex shaders write no layer, so it is not this bug. It aborts on its first refused draw, so it covers neither result;agc_driver_provoking_vertex: provokingVertexLast is unsupported.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(local ICD) the layer loaded in every run, and the new test,rect_list_corner,pixel_barycentric_emulationandbarycentric_patch_vertex_layerpass with noVUID-reported.main302864d48c, Windows 11 on an NVIDIA Turing laptop GPU (driver 610) and an Intel iGPU (driver 101.70xx), with the validation layer: the newagc_driver_rect_list_vertex_layer,agc_driver_barycentric_patch_vertex_layer,agc_driver_rect_list_corner,agc_driver_rect_list_indirectandagc_driver_pixel_barycentric_emulationall pass in two runs on each GPU, with noVUID-on either side. The two layer tests also pass there without thePipeline.cppchanges, as expected for a padding layout that only SPIRV-Cross produces, so they do not fail falsely on native drivers.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 gabichuuuuu on 2026-11-08T01:39:41Z.
Review: COMMENTED
Ran
d117ed22d4(so #16891 as well) merged onmain302864d48con Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 610) and an Intel iGPU (driver 101.70xx), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos validation layer 1.4.368),ctest -R '^agc_driver_(rect_list|barycentric_patch_vertex_layer|pixel_barycentric_emulation)' -V.This only checks that native drivers are unaffected; the failure itself is MoltenVK's.
mainmain+ the two new test files onlyagc_driver_rect_list_vertex_layerandagc_driver_barycentric_patch_vertex_layerpass even without thePipeline.cppchanges, so here nothing reads gl_Position at the wrong offset, as expected for a padding layout only SPIRV-Cross produces. The tests also don't fail falsely on native drivers.agc_driver_rect_list_corner,agc_driver_rect_list_indirectandagc_driver_pixel_barycentric_emulationpass on both sides.was not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has aVUID-, so dropping the vertex gl_Layer output doesn't trip an interface-matching check on these drivers. To be sure validation messages reach these logs, the same layer with best practices on printed 28BestPractices-warnings into anagc_driver_recorderlog on each GPU.AI-assisted: yes.