fix(shader): restore the per-instance hull PrimitiveId on MoltenVK, whose tessellation control dispatch spans instances #20111
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20111"
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-14T16:21:03Z.
What
On MoltenVK,
agc_driver_tessellationfails in its instanced relative-patch cases:When a hull program uses its relative patch index as data,
TessellationLowering::groupedPatchbuilds it fromPrimitiveId. When instances share hull threadgroups, it addsinstance * instancePatchesfirst. Vulkan restartsPrimitiveIdat 0 for each instance. MoltenVK does not. It runs the tessellation control stage as one compute dispatch over every patch of every instance, and SPIRV-Cross derives the ID from the dispatch:So in instance 1, the hull sees
PrimitiveId3 for the first patch instead of 0:1*3 + 3 = 6,6 mod 4 = 2instead of 3. That is blue 96 instead of 128.BREAK_WAVE_AT_EOIcase gets 3 where the per-instance 0 belongs. That is blue 128 instead of 32.SpirvTarget::tessellationPrimitiveIdPerInstance(trueby default,falseonVK_DRIVER_ID_MOLTENVK) records that difference. For an instanced draw on such a device,TessellationPrimitiveIdInstancePatches(request)gives the draw's patches per instance (indexCount / inputControlPoints). The hull'sPrimitiveIdis taken modulo that before the existing grouping. That restores the per-instance value Vulkan specifies, so both the shared-group and the break-at-instance paths stay exactly as they were:RequestInputInfoputs the value inTessellationConfiguration::primitiveIdInstancePatches. It is derived per request, likeinstancePatchesanddrawParameters, and added at the end of the struct so positional initializers keep their meaning.CacheKeyappendsTessellationPrimitiveIdInstancePatches(request)next toTessellationInstancePatches(request), plus the target flag. The driver already skips its draw-level stage entries for instanced tessellation draws.RequestSerializermoves to version 58. Version 57 requests read with the flagtrue.RequestSerializerTestsandShaderMemorymove their version 57 expectations to 58 and cover reading version 57.Tested
Setup:
-DCMAKE_OSX_ARCHITECTURES=x86_64; tests run under RosettaANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1mainwith the open macOS build fixes appliedResults:
agc_driver_tessellationfails before this change and passes after it: all three instanced relative-patch draws (shared groups at 4/8 and 3/3, andBREAK_WAVE_AT_EOI) and every refusal case.ctest -R 'tessellation|hull|domain|request_serializer|agc_shader_memory'passes.ctest -R '^(agc|shader|job)'(1578 tests,-j 1) and compared it with the same run before this change.agc_driver_tessellationis fixed and nothing that passed before fails because of this change.agc_driver_msaa_dcc_clear_2failed once in that run, then passed 3 of 4 reruns; it has no tessellation stage.agc_driver_scratch_poolis intermittent on this machine with and without this change.Not run on lavapipe, AMD or NVIDIA. There the flag stays
true,primitiveIdInstancePatchesis 0, and the generated shaders are unchanged. #20030 also moves the serializer from 57 to 58; whichever lands second takes 59.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-14T17:09:54Z.
Review: COMMENTED
Reviewed — no blocking findings
The code read matches the stated MoltenVK per-instance PrimitiveId correction; the two excluded large files leave material integration and test details unverified, so a formal approval is not justified.
What I ran
Inspected the prepared diff and pinned source at head
7fe817ed6c0f275d1d0f32841d77c4b814d1b3cfusingrepo_read.pysearch and targeted reads. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppandcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppwas excluded from the review folder because each exceeded its size limit; targeted changed ranges in both were read through the pinned reader. Other changed files whose full text was included were not read in full; the relevant changed hunks and targeted context were inspected. The author-reported build and test results were not independently run. No negative control was run.To get this to a good state
Nothing is required. Optional: confirm the reported MoltenVK tessellation and serializer tests on the pinned head.
Continued review (pass 2)
The specified continuation lines add serialization version handling and coverage for the tessellation primitive ID per instance option; the inspected code shows consistent round-trip, legacy-default, and truncation checks.
What I ran
Read the requested line ranges at the pinned head using
repo_read.pyreader tools. No tests were run.Results
Findings
Blocking
None in the inspected continuation lines.
Non-blocking
None.
Not verified
This review covers only the specified continuation lines and their immediate context. The rest of the pull request and test execution were not verified.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-17T03:23:15Z.
Review: COMMENTED
Tested on an Apple M4 (macOS 27.2, MoltenVK 1.4.2 from the LunarG SDK 1.4.363.1, x86-64 build under Rosetta).
This PR doesn't merge cleanly into current
main(bb95654123).git merge-treereports conflicts in:core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/ControlFlow/src/RequestSerializer.cppcore/shader/recompiler/tests/RequestSerializerTests.cppI didn't resolve them. I tested the PR's merge-base
2bc1db7ca8against the PR head7fe817ed6c, with no changes to either side. Both built apart fromlibcurl.prx(#17425).The test set is the 29
agc_driver_*tests that fail on currentmainon this Mac (ds_permute,f32_denormal_flush,image_sample_lod_*,label_*,pixel_sample_*,provoking_vertex,queued_indirect_read_order,tessellation, and others); the 26 of them that exist at the merge-base ran. Environment:ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer, three runs per side. Every test process loggedInsert instance layer "VK_LAYER_KHRONOS_validation"(layer 1.4.363), and none logged the missing-layer message.agc_driver_tessellationVUID-lines per runAt the merge-base, the failure is
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). With this PR, it logsTessellation tests passed. The 10VUID-lines are the same on both sides: 4VUID-VkDeviceCreateInfo-sType-unique(fromRecorder.cpp, addressed by #21965) and 6VUID-VkSamplerCreateInfo-samplerMipLodBias-04467. No regressions.The conflicting serializer files are where request versions get bumped, so the version number will need to be rechecked after rebasing. #20153 and #21938 also move it to 63.
I didn't test this on Linux, Windows or another GPU vendor.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T18:36:42Z.
Review: COMMENTED
The workaround has two independent inputs worth preserving on rebase. The draw's patch count selects the hull
PrimitiveIdmodulo, and the target flag controls whether that modulo is emitted. The older request round trip in this branch correctly defaults to per-instance IDs. Currentmainexplicitly rejects request version 58 and the serializer now conflicts in the merge, so the new field needs the next available format version. It would be useful to keep the older-version assertion and check both lowering paths with the same instanced request on a non-MoltenVK CI host.Source review of
7fe817ed6c. The MoltenVK execution evidence is from the author's run.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.