Fix shaders failing to compile with Metal renderer#87
Merged
phandasm merged 1 commit intoJul 11, 2026
Conversation
MSL has no scalar overload of distance(), so PSGradient and PSRange
failed to compile ('call to distance is ambiguous') under the Metal
backend, which made gs_effect_create return NULL and left all
waveform sources invisible on macOS with the Metal renderer.
Replace scalar distance(a, b) with abs(a - b), which is semantically
identical and valid in HLSL, GLSL, and MSL.
Fixes phandasm#85
Owner
|
Thanks! |
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 #85.
Root cause
The Metal Shading Language has no scalar overload of
distance()— onlyfloat2/3/4(andhalfvariants). OBS's Metal backend (libobs-metal) transpiles effect-HLSL intrinsics verbatim, soPSGradientandPSRangefail to compile with:One failed shader makes
gs_effect_create_from_filereturn NULL for the whole effect, so every technique (including Solid) stops rendering — matching the "no visual in any mode" symptom. The OBS log only shows the genericMTLDevice failed to create shader library and function; I recovered the real MTLCompiler error by instrumentingMetalShader.swiftin a local libobs-metal build.Fix
Replace scalar
distance(a, b)withabs(a - b)inPSGradientandPSRange. Semantically identical for scalars and valid in HLSL, GLSL, and MSL, so D3D11/OpenGL behavior is unchanged.Verification
macOS 26.4, Apple Silicon, OBS 32.1.2 with
Renderer=Metal:device_vertexshader_create: Device error compiling shader,Pass (0) <> missing pixel shader!, per-frameeffect_setval_inline: invalid paramspam, source screenshot has 0 painted pixels.Everything else in
gradient.effecttranspiles cleanly on 32.1.2 (uniform default initializers,booluniform,mul(), scalarsaturate/lerp, all six techniques, GS_TRISTRIP/LINESTRIP/TRIS draws).