AGC: merged hull programs draw nothing on MoltenVK, because the pipeline cache reuses a domain shader converted for another hull #10045
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 jotitadev on 2026-10-23T06:08:24Z.
What fails: on Apple silicon with MoltenVK,
agc_driver_tessellationfails at its first merged hull case:merged hull program storing its local part's registersfails the same way. The earlierRequirePatchescases use separate local and hull programs, and all of them pass. #8861 was a different bug on AMD's Windows driver (fixed by #8884, which is in the tree I tested).Setup:
BUILD_TESTING=ON.feat/macos-port) @4e0468722f, sincemaindoes not build on macOS yet.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.mainwith SPIRV-Cross #2704.Cause: MoltenVK reuses a domain shader that it converted for a different hull, through the shader cache inside the
VkPipelineCache.MoltenVK runs the hull stage as a compute kernel that writes its per-vertex outputs to a buffer, and the domain stage reads that buffer as an array of structs. To keep both strides equal, SPIRV-Cross pads the domain stage's input struct with every per-vertex output of the hull it is linked with (
raw_buffer_tese_input).The merged hull has one more per-vertex output than the other hulls in the test: the
ControlSharedrecord that stands in for the local part's LDS, at location 2. So its control points are 48 bytes apart, and the other hulls' are 16 bytes apart. All of them use the sameDomainCode.Pipeline.cppcreates every graphics pipeline withcontext.pipelineCache. MoltenVK's pipeline cache keeps the converted shaders per SPIR-V module, andSPIRVToMSLConversionConfiguration::matches()(SPIRVToMSLConverter.cpp#L191-L197, the same in v1.4.2) only checks that the inputs the cached conversion used are present in the new configuration. The extra inputs that would change the padding do not prevent a match. So the domain shader converted for the first 16-byte hull is reused for the merged hull, and it reads the merged hull's control points 16 bytes apart:Evidence: I wrapped each case of
main()in a try/catch, and ran the test in three ways. Both drivers gave the same results:RequirePatchescasesVK_NULL_HANDLEas the pipeline cacheWith the merged hull first, the MSL dump (
MVK_CONFIG_DEBUG=1) shows the domain shader converted with the padding, and the next 16-byte pipeline gets a new conversion without it:This fits
matches()only checking one direction: the padded conversion was not reused for the 16-byte hull that came after it, but the 16-byte conversion is reused for the merged hull when it comes first.Fix: I have a branch that creates tessellation pipelines without the pipeline cache when the driver is MoltenVK (
TessellationPipelineCacheUsable(VkDriverId), likeFragmentShaderBarycentricUsable). With it on #8658, both merged hull cases pass, and the rest of^agcis unchanged with both drivers (870 tests: the same 18 failures with MoltenVK 1.4.2 and the same 17 with MoltenVK main before and after;agc_driver_tessellationstays in both lists because it now stops at the case below). I will open it as a PR that references this issue. The proper fix belongs in MoltenVK'smatches(), and I can report it there too.Also hidden behind it: with every case run, the only other case that fails on Apple is
RequireInstancedRelativePatches, with both drivers and with the fix:I have not looked into it. It may be KhronosGroup/MoltenVK#2886 (the hull's
PrimitiveIdis not reset between instances), but I have not confirmed that.GPUs tested: Apple M2 Max (MoltenVK 1.4.2 from Vulkan SDK 1.4.363.0, and MoltenVK main + SPIRV-Cross #2704), macOS 27.2.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.