Repository navigation
fix(shader): fence the scratch pool slot release on MoltenVK - #24201
oneandonlydean merged 1 commit into
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The changed fence is emitted before scratch slot release only when the MoltenVK-specific ldsLockFences option is enabled; no blocking defect was verified.
What I ran
Reviewed head 47e6c7c87cdf6cda91bf9363d94edec28504bacf. Inspected the prepared diff and source context using repo_read.py reader tools. No tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed code | passed | One changed line reviewed |
| Target option wiring | passed | MoltenVK flag reaches emitter |
| Tests | not run | No local test execution |
Findings
Blocking
None.
Non-blocking
None.
Not verified
Author-reported device test results were not independently verified. No build, test, or physical-console run was performed. The review bundle excluded no changed files; the changed file's full text and relevant option wiring were read.
To get this to a good state
Nothing is required.
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Head No new failures and no new validation messages on either GPU.
Layer runs used AI-assisted: yes |
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
|
Independent check on another Apple GPU: Apple M5 Pro, macOS 27.3, MoltenVK from Vulkan SDK 1.4.363.0, x86_64 Release under Rosetta 2,
With The dumped SPIR-V cross-compiled with the SDK's |
What
On MoltenVK,
agc_driver_scratch_poolfails most runs, as XIIYAZ listed in #1 (comment):A workgroup gives its scratch pool slot back with an
OpAtomicIDecrement(AcquireRelease, Uniform). The last invocation then stores 0 to the slot's lock word. SPIRV-Cross turns these atomics intomemory_order_relaxedwith no fence. So a workgroup can release its slot before its own scratch loads and stores complete, and the next workgroup that takes the slot overwrites them.This change emits an
OpMemoryBarrier(Device, AcquireRelease | UniformMemory) before the decrement. It does so only whenldsLockFencesis set, which is MoltenVK only. That is the flag the LDS lock fences already use for the same reason. With MSL 3.2 and later, SPIRV-Cross emits it asatomic_thread_fence(mem_flags::mem_device, memory_order_seq_cst, thread_scope_device). Other drivers get the same SPIR-V as before, so the AMD fix in #16274 is untouched.Tested
Apple M4, macOS 27.0.1, MoltenVK 1.4.2, x86_64 Release build under Rosetta 2,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, each run beingctest -R '^agc_driver_scratch_pool$' -j1. The tree wasmainwith #17425 and #11049, which the macOS build needs. Neither touches the shader recompiler.agc_driver_scratch_poolagc_flat_scratch,agc_guarded_memory_loads,agc_spirv_lds_atomic_lockandagc_shader_disk_cachepass with the change.Not run on Windows, Linux or a non-Apple GPU. There
ldsLockFencesis false, so the SPIR-V does not change. Not run with MSL older than 3.2, where SPIRV-Cross emits the barrier asthreadgroup_barrier(mem_flags::mem_device).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)