2.9 C
New York
Tuesday, January 28, 2025

swift – iOS steel dynamic library


I encountered a problem; I can’t appear to attach a dynamic library to the venture.

What I’m doing: first, I’m attempting to create the dynamic library on this manner.

xcrun steel -c dynShaders.steel -o dynShaders.air
xcrun metallib dynShaders.air -o dynShaders.metallib

The contents of dynShaders.steel.

#embrace 
utilizing namespace steel;
#import 
 
[[visible]]
float4 dynamicTestFunction() {
   return float4(0.0,1.0,1.0,1.0);
}

Subsequent, I load the metallib on this manner.

 let libraryURL = Bundle(for: sort(of: self)).url(forResource: "dynShaders", withExtension: "metallib")!
 do {
    self.dynLibrary = strive system.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 further clarification. The trail exists, the file is there, however the error happens with no info offered.

Subsequent, I attempted searching for different choices to compile the library and located this line within the official Apple documentation.

xcrun steel -dynamiclib dynShaders.steel -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 manner.

let compileOptions = MTLCompileOptions()
if let dynLibrary {
    compileOptions.libraries = [dynLibrary]
}
let library = strive system.makeLibrary(supply: supply, choices: compileOptions)
return library.makeFunction(identify: "dynamicShader")

Here’s what the ultimate shader appears to be like like, the one I’m attempting to compile.

#embrace 
utilizing namespace steel;
#import 

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, however it didn’t assist, like this.

xcrun steel -dynamiclib dynShaders.steel -arch air64 -o dynShaders.metallib

I additionally tried including the structure when creating the .air.

xcrun steel dynShaders.steel -arch air64 -c -o dynShaders.air

What am I doing fallacious, and the way do I accurately use a dynamic library?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles