fix(agc): check host imports outside the pending storage image mutex when storing drawn linear targets #26273
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26273"
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 Gonic0 on 2026-11-23T15:44:27Z.
What
On macOS,
StorageTexture::StoreDrawnLinearholdsGpuMutexand the pending storage image mutex while it callsHostImportCoversfor each drawn linear target it may read-trap at a label, andHostImportCoverstakes the host imports mutex.ImportMappedRangesholds the host imports mutex and then takes the pending mutex throughStorageTexture::AnyPendingOverlaps. Two threads can each hold the lock the other waits for. Asampleof Grand Theft Auto V (PPSA04264) caught it once:The pending mutex is already a
MapImportGate::LeafMutex, andStoreSmallPendingalready asksHostImportCoversafter releasing it.StoreDrawnLinearcollects the dirty drawn targets it may trap, asshared_ptrs, under the pending mutex and releases it. It then asksHostImportCoversfor each, and takes the pending mutex again to set traps (trapReadsAtLabel, which reads the pending set) on the covered ones that are still drawn and dirty. Uncovered ones, and any whoseweak_from_thishas expired, are stored as before.ImportsMutex::locknow aborts when lock order is checked and the thread holds a leaf lock (MapImportGate::LeafLockHeld).APS5_ASSERT_LOCK_ORDERturns on that leaf and imports lock-order checking without theGpuMutexassertions ofAPS5_ASSERT_GPU_LOCK, which abort earlier in test fixtures that drive the device withoutGpuMutex(for example the f32 flush probe at device creation). It is documented indocs/dev/ENVIRONMENT.md.agc_driver_linear_target_completion_stores_lock_orderruns the existing linear target completion store test withAPS5_ASSERT_LOCK_ORDER=1. That test reachesStoreDrawnLinearat a label with a covered drawn linear target.Tested
Apple M5 Pro, macOS 27.3, MoltenVK (Vulkan SDK 1.4.363), x86_64 Release under Rosetta 2,
main26508fa3f9. The same build directory formainand this change.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.agc_driver_linear_target_completion_stores_lock_order: 3 of 3 pass. With this change's assertion and without itsStoreDrawnLinearchange, 3 of 3 abort with[lock] ASSERT: the host imports mutex is taken while this thread holds the live or pending storage image mutex.linear_target|label|map_gate|flush_exclusion|unwatch_hook_lock_order|host_import|drawn|read_trap|small_pending|alpha_to_coverage, one run each side withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer(Khronos validation layer 1.4.363). Each side's log shows 75Insert instance layerlines, nowas not found, and noVUID-.mainand with this change:agc_driver_label_ordered_flush,_unimported,agc_driver_unimported_label_orderand its_draw_pipelineand_plan_verifyvariants.APS5_ASSERT_LOCK_ORDER=1and this change: no[lock] ASSERT.agc_driver_label_after_import_copyfailed once under-j4and passed 4 of 4 alone, with and without the variable.APS5_ASSERT_LOCK_ORDER=1, 2 of 2 runs without theStoreDrawnLinearchange abort on the assertion within 10 s.tools/check_conventions.py --base upstream/mainandtools/env_reference.py --checkpass.Not run on Linux or Windows. There, the trap path in
StoreDrawnLinearis compiled out, and the new check fires only when lock order is checked.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)🤖 Generated with Claude Code