AGC: merged hull programs draw nothing on MoltenVK, because the pipeline cache reuses a domain shader converted for another hull #10045

Closed
opened 2026-10-23 06:08:24 +00:00 by jotitadev · 0 comments
jotitadev commented 2026-10-23 06:08:24 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T06:08:24Z.


What fails: on Apple silicon with MoltenVK, agc_driver_tessellation fails at its first merged hull case:

AGC graphics: merged hull program, unculled: the level-1 patch was not drawn as one flat triangle, centre (16, 24, 40, 255)

merged hull program storing its local part's registers fails the same way. The earlier RequirePatches cases 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:

  • Apple M2 Max (32 GB), macOS 27.2.
  • x86_64 build under Rosetta, Release, BUILD_TESTING=ON.
  • #8658 (feat/macos-port) @ 4e0468722f, since main does not build on macOS yet.
  • ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.
  • Same results with two drivers: MoltenVK 1.4.2 from Vulkan SDK 1.4.363.0, and MoltenVK main with 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 ControlShared record 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 same DomainCode.

Pipeline.cpp creates every graphics pipeline with context.pipelineCache. MoltenVK's pipeline cache keeps the converted shaders per SPIR-V module, and SPIRVToMSLConversionConfiguration::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:

// DomainCode as reused for the merged hull pipeline
struct main0_in
{
    spvUnsafeArray<uint4, 1> tess_attributes;
};

Evidence: I wrapped each case of main() in a try/catch, and ran the test in three ways. Both drivers gave the same results:

Variant merged hull cases other RequirePatches cases
as in the test fail pass
tessellation pipelines created with VK_NULL_HANDLE as the pipeline cache pass pass
pipeline cache kept, but the two merged hull cases run first pass pass

With 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:

// DomainCode converted next to the merged hull
struct main0_in
{
    spvUnsafeArray<uint4, 1> tess_attributes;
    uint4 m_278;
    uint4 m_283;
};

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), like FragmentShaderBarycentricUsable). With it on #8658, both merged hull cases pass, and the rest of ^agc is 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_tessellation stays 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's matches(), 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:

AGC graphics: the patch in column 0 of an instanced draw with 4 patches per group and 8 primitives per group did not take its blue channel from the hull's relative patch index across instances, (255, 0, 96, 255)

I have not looked into it. It may be KhronosGroup/MoltenVK#2886 (the hull's PrimitiveId is 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5992860983 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/10045). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-23T06:08:24Z. --- **What fails:** on Apple silicon with MoltenVK, `agc_driver_tessellation` fails at its first merged hull case: ``` AGC graphics: merged hull program, unculled: the level-1 patch was not drawn as one flat triangle, centre (16, 24, 40, 255) ``` `merged hull program storing its local part's registers` fails the same way. The earlier `RequirePatches` cases 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:** - Apple M2 Max (32 GB), macOS 27.2. - x86_64 build under Rosetta, Release, `BUILD_TESTING=ON`. - #8658 (`feat/macos-port`) @ `4e0468722f`, since `main` does not build on macOS yet. - `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`. - Same results with two drivers: MoltenVK 1.4.2 from Vulkan SDK 1.4.363.0, and MoltenVK `main` with 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 `ControlShared` record 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 same `DomainCode`. `Pipeline.cpp` creates every graphics pipeline with `context.pipelineCache`. MoltenVK's pipeline cache keeps the converted shaders per SPIR-V module, and `SPIRVToMSLConversionConfiguration::matches()` ([SPIRVToMSLConverter.cpp#L191-L197](https://github.com/KhronosGroup/MoltenVK/blob/5189f8de86ec365860f63bf1da736815cfaea5cd/MoltenVKShaderConverter/MoltenVKShaderConverter/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: ```metal // DomainCode as reused for the merged hull pipeline struct main0_in { spvUnsafeArray<uint4, 1> tess_attributes; }; ``` **Evidence:** I wrapped each case of `main()` in a try/catch, and ran the test in three ways. Both drivers gave the same results: | Variant | merged hull cases | other `RequirePatches` cases | |---|---|---| | as in the test | fail | pass | | tessellation pipelines created with `VK_NULL_HANDLE` as the pipeline cache | pass | pass | | pipeline cache kept, but the two merged hull cases run first | pass | pass | With 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: ```metal // DomainCode converted next to the merged hull struct main0_in { spvUnsafeArray<uint4, 1> tess_attributes; uint4 m_278; uint4 m_283; }; ``` 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)`, like `FragmentShaderBarycentricUsable`). With it on #8658, both merged hull cases pass, and the rest of `^agc` is 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_tessellation` stays 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's `matches()`, 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: ``` AGC graphics: the patch in column 0 of an instanced draw with 4 patches per group and 8 primitives per group did not take its blue channel from the hull's relative patch index across instances, (255, 0, 96, 255) ``` I have not looked into it. It may be KhronosGroup/MoltenVK#2886 (the hull's `PrimitiveId` is 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.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#10045
No description provided.