metal: load default.metallib by path when newDefaultLibrary returns nil#19166
Draft
vanreece wants to merge 1 commit into
Draft
metal: load default.metallib by path when newDefaultLibrary returns nil#19166vanreece wants to merge 1 commit into
vanreece wants to merge 1 commit into
Conversation
On macOS, -[MTLDevice newDefaultLibrary] only resolves default.metallib
from inside a .app bundle's resources. For a bare executable (CLI builds,
non-.app installs, a dev build run in place) it returns nil, leaving the
Metal driver with no shader library -- every -newFunctionWithName: then
returns nil.
That nil function is passed straight to
-newComputePipelineStateWithFunction:error: when building the pixel-format
conversion filters, which asserts ("computeFunction must not be nil") and
aborts the process. Depending on timing it can instead surface as a
half-initialized driver or a plain "Cannot open video driver".
Two fixes:
- When newDefaultLibrary returns nil, fall back to loading
default.metallib explicitly via -newLibraryWithURL:error: from the
executable's own directory (where `make install` places it). The normal
.app bundle path is unaffected.
- Guard -newFunctionWithName: in +[Filter newFilterWithFunctionName:...]:
a nil function now returns gracefully with an error log instead of
tripping the NSAssert inside newComputePipelineStateWithFunction.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Summary
On macOS,
-[MTLDevice newDefaultLibrary]only resolvesdefault.metallibfrom inside a
.appbundle's resources. For a bare executable — CLI builds,non-
.appinstalls, or a dev build run in place — it returns nil, leavingthe Metal driver with no shader library. Every
-newFunctionWithName:thenreturns nil.
That nil function is passed straight to
-newComputePipelineStateWithFunction:error:when building the pixel-formatconversion filters, which asserts (
computeFunction must not be nil) andaborts the process. Depending on timing it can instead surface as a
half-initialized driver or a plain "Cannot open video driver".
Fix
newDefaultLibraryreturns nil, fall back to loadingdefault.metallibexplicitly via
-newLibraryWithURL:error:from the executable's own directory(where
make installplaces it). The normal.appbundle path is unaffected.-newFunctionWithName:in+[Filter newFilterWithFunctionName:...]: anil function now returns gracefully with an error log instead of tripping the
NSAssert.
Testing
macOS (Apple Silicon, Metal), running the binary outside a
.appbundle:before, it aborts at init with the
computeFunction must not be nilassertion;after, it logs
loaded shader library from …/default.metalliband runsnormally. The
.appbuild path is unchanged — the fallback only runs whennewDefaultLibraryis nil.🤖 Generated with Claude Code