Repository navigation
gfx/tools: pass subgroup inputs by value to out-of-line mesh helpers - #3169
Closed
AlexandreBeauduin wants to merge 1 commit into
Closed
AlexandreBeauduin wants to merge 1 commit into
AlexandreBeauduin wants to merge 1 commit into
Conversation
Apple's Metal compiler reads gl_SubgroupInvocationID as one value for the whole SIMD group when a noinline helper passes it by reference to another noinline helper (-O1 and up, minimums 26.6 and 27.0). Ocarina of Time's scan helpers then gave every lane the same prefix sum; its mesh groups wrote outside their ranges and the GPU hung or faulted after a save loaded. mesh_subgroup_noinline now passes the gl_Subgroup* parameters by value. They are SPIR-V Input builtins, never written. The helpers stay noinline to avoid the SIGBUS of issue seedds#2825. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
seedds
added a commit
that referenced
this pull request
Nov 22, 2026
Apple's Metal compiler can miscompile nested out-of-line subgroup helpers when one passes a subgroup input by reference to another. Ocarina of Time then writes outside its mesh output ranges and can hang the GPU after a save loads. Pass read-only subgroup inputs by value in final native mesh sources. Keep the helpers out of line to avoid the earlier mesh compiler crash. Cover the rewrite with synthetic helpers and keep the exact GPU reproducer with the local game files. Both chains built the 500 native mesh shaders and 1,000 companions. The 44 changed Metal sources match the rewrite and reflection matches apart from the chain stamp. The reported pipeline compiles offline on g13d, g14g and g14s at minimum macOS 26.6. Focused tests pass. Affected M1 and M2 Macs still need runtime retests. Refs #3152 Co-authored-by: Alexandre Beauduin <6662875+AlexandreBeauduin@users.noreply.github.com> Co-authored-by: coderipper <34905663+yripper@users.noreply.github.com>
Owner
|
Thanks, Alexandre, for tracing the Metal compiler failure and testing the by-value fix. The revised patch landed on main in 6dc2763. It keeps the mesh helpers out of line and passes their read-only subgroup inputs by value. The repository test now uses synthetic shader code, and the exact GPU reproducer is kept with the local game files. The focused tests passed. Both versions built all 500 Ocarina of Time mesh shaders and their 1,000 companion shaders. The 44 expected shader changes preserved reflection, and the previously failing pipeline compiled offline for the older GPU targets. The affected M1 and M2 Macs still need runtime retests. Issue #3152 stays open for those results. |
This was referenced Nov 22, 2026
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On an M4 Pro, Ocarina of Time hung (
kIOGPUCommandBufferCallbackErrorHang), page-faulted and lost GPU access (GPU access revoked) shortly after a save loaded.The noinline workaround for the mesh SIGBUS (issue #2825) keeps SPIRV-Cross's subgroup helpers out of line, and SPIRV-Cross hands them
thread uint& gl_SubgroupInvocationID. When one such helper passes that reference on to another (the game's exclusive scan and its shuffle step), Apple's Metal compiler reads the builtin as one value for the whole SIMD group (-O1and up, minimums 26.6 and 27.0). Every lane got the same exclusive prefix sum, so mesh groups wrote outside their output ranges.Fix
mesh_subgroup_noinlinenow also passes thegl_Subgroup*parameters of final mesh code by value. They are SPIR-VInputbuiltins and never written, so a copy has the same meaning. The helpers stay noinline, which still avoids the SIGBUS. This works around a defect in Apple's compiler, which remains open; it is documented as such indocs/reference/shaders.mdand in the game note.Validation
test_scan_on_gpuruns the game's real scan helpers (mesha76e46990e6799ba) on the GPU: 62 of 64 lanes wrong in the previous noinline-by-reference form, 0 of 64 inlined or by value.g13s,g13d,g14gandg14sat 26.6 and forg18gat 27.0.These were run on the chain before rebasing onto current
main(d51675c8a1eb); the rebase only regenerateddmsh_chain.h, andtest_dmsh_raw_noinline.py,test_docs.pyandtest_nsp_chain.pypass on the rebased branch.Regression report
The rewrite only changes final native mesh stages whose helpers take
gl_Subgroup*parameters. Of the local games, only Ocarina of Time and Mario Kart World ship native mesh shaders; none of Mario Kart World's mesh sources has such a helper (19 of its 26 mesh keys generated and checked). Donkey Kong Bananza, Mario Tennis and Star Fox have no native mesh stages. A fullscripts/regress.py check --gameswas not run: the machine lacked the disk space for its two chains per game.🤖 Generated with Claude Code