|
43 | 43 | asyncQueue = [device newCommandQueue]; |
44 | 44 | mtlCHECK(asyncQueue != nil, "Failed to create Metal async command queue"); |
45 | 45 |
|
46 | | - // Load the compiled shader library |
47 | | -#ifdef SPRUX_METAL_LIBRARY_PATH |
| 46 | + // Load the compiled shader library. |
| 47 | + // Priority: SPRUX_METALLIB_PATH env var > compiled-in path > default library. |
48 | 48 | NSError* error = nil; |
49 | | - NSString* libraryPath = @SPRUX_METAL_LIBRARY_PATH; |
50 | | - NSURL* libraryURL = [NSURL fileURLWithPath:libraryPath]; |
51 | | - library = [device newLibraryWithURL:libraryURL error:&error]; |
52 | | - if (error != nil) { |
53 | | - NSLog(@"Failed to load Metal library from %@: %@", libraryPath, error); |
54 | | - // Try loading default library as fallback |
55 | | - library = [device newDefaultLibrary]; |
| 49 | + const char* envPath = getenv("SPRUX_METALLIB_PATH"); |
| 50 | + if (envPath) { |
| 51 | + NSString* libraryPath = [NSString stringWithUTF8String:envPath]; |
| 52 | + NSURL* libraryURL = [NSURL fileURLWithPath:libraryPath]; |
| 53 | + library = [device newLibraryWithURL:libraryURL error:&error]; |
| 54 | + if (error != nil) { |
| 55 | + NSLog(@"Failed to load Metal library from env SPRUX_METALLIB_PATH=%@: %@", |
| 56 | + libraryPath, error); |
| 57 | + } |
| 58 | + } |
| 59 | +#ifdef SPRUX_METAL_LIBRARY_PATH |
| 60 | + if (library == nil) { |
| 61 | + error = nil; |
| 62 | + NSString* libraryPath = @SPRUX_METAL_LIBRARY_PATH; |
| 63 | + NSURL* libraryURL = [NSURL fileURLWithPath:libraryPath]; |
| 64 | + library = [device newLibraryWithURL:libraryURL error:&error]; |
| 65 | + if (error != nil) { |
| 66 | + NSLog(@"Failed to load Metal library from %@: %@", libraryPath, error); |
| 67 | + } |
56 | 68 | } |
57 | | -#else |
58 | | - library = [device newDefaultLibrary]; |
59 | 69 | #endif |
| 70 | + if (library == nil) { |
| 71 | + library = [device newDefaultLibrary]; |
| 72 | + } |
60 | 73 | mtlCHECK(library != nil, "Failed to load Metal shader library"); |
61 | 74 |
|
62 | 75 | NSLog(@"Metal initialized: %@", device.name); |
|
0 commit comments