fix(shader): read the sample mask input in the pixel entry point so MoltenVK compiles it #19986
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/19986"
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 XIIYAZ on 2026-11-14T10:15:58Z.
What
On MoltenVK, a pixel shader that reads the sample mask input fails to compile when its body is the separate
pixelGuestFunc(pixel shaders wherebdaStopsInvocationsis set and the shader is not ordered), as inagc_driver_pixel_sample_coverageandagc_driver_sample_order:The SPIR-V reads
SampleMaskcorrectly (OpAccessChain %ptr_Input_int %gl_SampleMaskIn %uint_0, thenOpLoad). SPIRV-Cross mapsSampleMaskto Metal's scalar[[sample_mask]]and drops the[0], but because the variable is used in a function other than the entry point it also passes it into that function asthread uint (&gl_SampleMaskIn)[1], so the body readsint(gl_SampleMaskIn)from an array andmain0passes a scalar to the array parameter. This reproduces outside AnyPS5 with the SDK's tools on the SPIR-V MoltenVK logs (spirv-cross --msl --msl-version 30100, vulkan-sdk-1.4.363.0, thenxcrun metal), with default options. Declaring the array asuintdoes not change it; reading the mask in the entry point does.When the pixel body is a separate function, each sample mask input the body reads now goes through a private
i32copy, which the entry point fills from element 0 of the built-in just before it calls the body:LoadSampleMaskserves both reads (theStageInputKind::SampleMaskinput and the quad sample mask read ofsampleMaskInputVariable); it creates the private copy on first use and records the pair insampleMaskCopies.EmitPixelEntryPointstores each copy beforeOpFunctionCall pixelGuestFunc.main(nopixelGuestFunc), the reads stay as they were.The value is the same
SampleMask[0]the body read before, read once at entry; the input does not change during the invocation.Tested
Apple M4, macOS 26.7.3, MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1), Apple clang 21.0.0, full Release build with
-DCMAKE_OSX_ARCHITECTURES=x86_64(tests under Rosetta),ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, onmain290ee1aa0fwith the open macOS build fixes (#17425, #11049, #11437, #19903, #19920) and #19966 applied; this change and #19966 apply together cleanly.agc_driver_pixel_sample_coverageandagc_driver_sample_order(10 swap round trips, 4 shader remap checks, 2 scene checks): fail before with the errors above, pass after.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer(layer from the same SDK): both pass, the loader inserts the layer, nowas not found but was requested, noVUID-messages.ctest -R '^(agc|shader|job)', 1578 tests,-j 2, compared with the same run before both changes: no test fails that passed before; 30 failures before, 25 after.Not run on lavapipe, AMD or NVIDIA. The remaining sample-related MoltenVK failures (
agc_driver_pixel_sample_iteration,agc_driver_sample_mask_multisample) fail the same way before and after and are not changed here.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 MarcZX10 on 2026-11-14T13:24:58Z.
Review: COMMENTED
Reviewed — no blocking findings
The inspected changes appear correct, but I could not run the reported checks, so a formal approval is not justified.
What I ran
Reviewed head
753d6e1b204bfa17a03528c3c66a9cd4062dfe8cusing the prepared review bundle andrepo_read.py. No build or tests were run. The author reports Apple M4/macOS 26.7.3 MoltenVK testing and 1,578ctestcases; these results were not independently verified.Results
Findings
Blocking
None identified in the inspected changes.
Non-blocking
None.
Sources
Not verified
Build and test results were not run independently. Both changed files listed in the manifest were read. The excluded-file list was not available in the review bundle listing, so excluded files were not verified.
To get this to a good state
Nothing is required. The reported MoltenVK and
ctestresults remain author-reported.Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-16T23:01:45Z.
Review: COMMENTED
Tested on macOS 27.2 / Apple M4 with MoltenVK 1.4.2 (LunarG Vulkan SDK 1.4.363.1, validation layer 1.4.363), x86-64 build under Rosetta. This is the only GPU I tested.
Head
753d6e1b20merged alone onto main3b17977ba6, compared with3b17977ba6itself. I ran the 29 AGC tests that fail on main on this Mac, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer, throughctest --test-dir build -R <those 29> -V, three runs per side. Every Vulkan test loggedInsert instance layer "VK_LAYER_KHRONOS_validation"and none loggedwas not found but was requested by env var VK_INSTANCE_LAYERS.agc_driver_pixel_sample_coverageagc_driver_sample_orderThe other 26 tests gave the same result on both sides.
agc_driver_label_after_import_copyis flaky on main as well: main Failed, Passed, Passed, this PR Failed, Failed, Failed. Every failure on either side is the same timing check ("round N: a CPU read after the label that followed the copy found K of 262144 destination bytes not yet copied"), and it varied the same way across the other PRs I tested in the same session, so I don't attribute it to this change.VUID-lines: identical per test on both sides (30 on main, 30 with this PR, over the three runs). TheVUID-lines on both sides are main's existingVUID-VkDeviceCreateInfo-sType-unique(a duplicatedVkPhysicalDevicePortabilitySubsetFeaturesKHRin the device pNext chain) andVUID-VkSamplerCreateInfo-samplerMipLodBias-04467; this PR adds none. Note that this also fixesagc_driver_sample_orderhere: on main it fails with the same MoltenVK fragment shader compile error (cast from pointer to smaller type 'int' loses information), which #19943 does not change on this Mac.