fix(troika-three-utils): avoid inout params in vertex transform so text renders in Safari/ANGLE Metal - #392
Merged
Conversation
createDerivedMaterial emitted `troikaVertexTransform` as a function taking `inout vec3/vec2` params, called with the hoisted shader globals. Safari's ANGLE Metal backend cannot bind a __metal_generic global to a `thread T&` reference, so every derived material fails to link (Shader Error 1282, VALIDATE_STATUS false) and no text renders. This is the ANGLE translator defect tracked in WebKit bug 250169 / 319958. Rewrite the transform as a parameterless function with explicit copy-in/copy-out locals. This is semantically identical to the inout version, avoids passing globals by reference, and compiles cleanly under ANGLE Metal. Verified identical output in Chrome/Firefox. Fixes protectwise#390 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Collaborator
|
Thank you! |
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.
Fixes #390.
Problem
createDerivedMaterialemits the vertex transform as a function takinginoutparameters, called with the hoisted shader globals:On Safari (macOS, ANGLE Metal backend), ANGLE hoists those globals into a
__metal_generic-address-space struct, then wraps eachinoutargument in anANGLE_InOut<T>helper whose conversion operator returnsthread T&. The MSL compiler rejects binding the__metal_genericglobal to athreadreference, so every derived material fails to link:followed by an endless stream of
WebGL: INVALID_OPERATION: useProgram: program not valid. The result is that notroika-three-textrenders in Safari. Chrome/Firefox are unaffected because their ANGLE builds use different backends. This is the ANGLE translator defect tracked upstream in WebKit bug 250169 (see also 319958) — the underlying bug is Safari's, but troika can sidestep it entirely.Fix
Emit the transform as a parameterless function with explicit copy-in / copy-out locals instead of
inoutparameters. It's semantically identical to the previous version (same local names, same read-then-write-back semantics), but never passes a global by reference, so it compiles cleanly under ANGLE Metal.Verification
Running this as a
patch-packagepatch against0.52.4in production: text renders correctly again in Safari, with visually identical output in Chrome and Firefox.Reported and fixed while debugging this in our app; PR opened at maintainer's request (per #390) so the fix is attributed correctly.