I encountered a problem; I can’t appear to attach a dynamic library to the mission.
What I’m doing: first, I’m making an attempt to create the dynamic library on this approach.
xcrun metallic -c dynShaders.metallic -o dynShaders.air
xcrun metallib dynShaders.air -o dynShaders.metallib
The contents of dynShaders.metallic.
#embody <metal_stdlib>
utilizing namespace metallic;
#import <simd/simd.h>
[[visible]]
float4 dynamicTestFunction() {
return float4(0.0,1.0,1.0,1.0);
}
Subsequent, I load the metallib on this approach.
let libraryURL = Bundle(for: kind(of: self)).url(forResource: "dynShaders", withExtension: "metallib")!
do {
self.dynLibrary = strive machine.makeDynamicLibrary(url: libraryURL)
print("Library efficiently loaded!")
} catch {
print("Did not load library: (error)")
self.dynLibrary = nil
}
With this method, I constantly get an EXC_BAD error with none extra clarification. The trail exists, the file is there, however the error happens with no data offered.
Subsequent, I attempted in search of different choices to compile the library and located this line within the official Apple documentation.
xcrun metallic -dynamiclib dynShaders.metallic -o dynShaders.metallib
Such a library hundreds efficiently and doesn’t produce any errors.
Subsequent, I compile the shader from the textual content the place I attempt to use a perform from the dynamic library on this approach.
let compileOptions = MTLCompileOptions()
if let dynLibrary {
compileOptions.libraries = [dynLibrary]
}
let library = strive machine.makeLibrary(supply: supply, choices: compileOptions)
return library.makeFunction(identify: "dynamicShader")
Here’s what the ultimate shader seems to be like, the one I’m making an attempt to compile.
#embody <metal_stdlib>
utilizing namespace metallic;
#import <simd/simd.h>
extern float4 dynamicTestFunction();
fragment float4 dynamicShader(VertexIn vertexIn [[stage_in]]) {
float4 colour = float4(1.0,1.0,1.0,1.0);
colour = dynamicTestFunction();
return colour;
}
And I at all times get an error.
Shader compilation error: Error Area=MTLLibraryErrorDomain Code=3 "Undefined image(s) for structure 'air64':
'_Z23dynamicApplyMainTexturev', referenced from:
dynamicShader in program_object_0
error: image(s) not discovered for goal 'air64-apple-ios18.0.0'
" UserInfo={NSLocalizedDescription=Undefined image(s) for structure 'air64':
'_Z23dynamicApplyMainTexturev', referenced from:
dynamicShader in program_object_0
error: image(s) not discovered for goal 'air64-apple-ios18.0.0'
I attempted compiling with the desired structure, nevertheless it didn’t assist, like this.
xcrun metallic -dynamiclib dynShaders.metallic -arch air64 -o dynShaders.metallib
I additionally tried including the structure when creating the .air.
xcrun metallic dynShaders.metallic -arch air64 -c -o dynShaders.air
What am I doing unsuitable, and the way do I appropriately use a dynamic library?