12

x86_64 ターゲット (iOS シミュレーター) への金属シェーダーを含むプロジェクトをビルドするたびに、依存関係分析の警告が表示されます。

warning: no rule to process file '[File Path]/Shaders.metal' of type sourcecode.metal for architecture x86_64

これが大きな問題ではないことはわかっていますが、実際に問題が発生したときに実際に黄色の三角形の警告が表示されるように、ビルド時にプロジェクトに警告が表示されないようにしたいと考えています。

Xcode にシミュレータ ターゲットのメタル ファイルを無視させる簡単な方法はありますか?

4

2 に答える 2

4

You can resolve this by precompiling your .metal file into a Metal library during the build step, and removing the .metal source code from your app target.

Remove .metal file from target

Select your .metal file in the project navigator, and uncheck the target that is giving you the warning.

Metal library compile script

Create a bash script called CompileMetalLib.sh in your project, alongside your .metal file, with contents like this:

xcrun -sdk iphoneos metal -c MyShader.metal -o MyShader.air
xcrun -sdk iphoneos metallib MyShader.air -o MyShader.metallib
rm MyShader.air

Make sure to give it executable permissions by running chmod +x CompileMetalLib.sh.

MyShader.air is the intermediate compile step, and MyShader.metallib is the fully compiled metal library. Read all about compiling a Metal file here

If you're compiling for OS X, change iphoneos to macosx.

Run compile script during build

Now you'll want to trigger this script in your Build Phases.

Add a New Run Script Phase to your target. The contents should look like this:

cd ${SRCROOT}/path/to/folder/containing/yourshader
./CompileMetalLib.sh

It's important to drag this step so that it happens before the Copy Bundle Resources step.

Change your code to use your compiled Metal library

You'll now load the compiled Metal library from your app bundle.

Here's some pseudo-Swift:

let metalLibPath = Bundle.main.path(forResource: "MyShader", ofType: "metallib")
let myLibrary = try metalDevice.makeLibrary(filepath: metalLibPath)

Result

You are manually compiling your .metal file with an external script, and copying the compiled library into your bundle resources. Your code loads this library. Now that you don't have any .metal files in your target, the simulator will no longer throw a warning about not being able to compile for x86_64.

于 2018-10-17T19:23:22.110 に答える