"Invalid Library File" error when tries to load a metallib

Hi,

I am trying to experimenting download metallib on the fly.

I can load a metalib built into the project following this document: https://developer.apple.com/documentation/metal/gpu_functions_libraries/building_a_library_with_metal_s_command-line_tools?language=objc

While if I try to load the same metallib that's downloaded from internet and saved to document folder. I got "Invalid Library File" error.

Is Apple restricting using metallib that's downloaded or is there any option I should add when generating a metallib that's not shipped with the project?

Replies

Why would you download a .metallib from the internet? I'm guess it's not actually a metallib but a ranom file with the .metallib extension. Otherwise it's a corrupt .metallib.

I am trying to experiment if it's possible to alter shader code on the fly. The metallib is built by myself following the link, it can function properly when built onto the device with mainbundle, however if I put it into a network position and download it and load, I will hit the "Inavlid library path" error.

It cannot be done on iOS as there are strict rules for executing any code (including shaders) for security reason.


It might work on macOS. Are you embedding the URL path to get to it? There is no way to do that. Downloading and and passing a local path may work on macOS.

Yes, I am experimenting on iOS. And I am passing a local path (which points to the metallib in document folder) to the API.

If there is strict rule about restricting exectuting downloaded shaders, then it makes sense why the API doesn't work.

Thanks for reply.

Side question: If Apple is restricing executing downloaded shaders, is shader modifier program (SCNShadable) also considered restricted? Since the program is just simple text files that compiled in the runtime.

reubenzh,


I would expect it may be, but you should check with App Reviw to be sure.