简体   繁体   中英

What to include in Metal shader

I'm new to Metal. In some example shaders, I see

#include <simd/simd.h>

In others, I see

#include <metal_stdlib>

The shader with metal_stdlib compiles in an example Xcode project which I found on the web. But it does not compile if I include it in my existing project where I get the error message 'metal_stdlib' file not found . (the one with simd/simd.h works fine).

I'm confused as to what is going on. Maybe this is due to a different Metal version? I've been trying to find where there is a difference in the Xcode settings between the two projects (of which there are thousands), but no luck yet. When does one include <simd/simd.h> , when <metal_stdlib> ?

-- Update:

The compilation fails in an Objective-C file where I included the shared header (which includes the #include <metal_stdlib> ). Still very confused.

I was struggling with this for a bit as well, all to realize I actually had mistakenly imported my metal file in an Obj-C source code file. No metal header files may be imported on any other header or source code files.

Simd.h provides small vector (simd) and matrix types, as well as basic arithmetic and mathematical functions for them.

On the other hand, metal_stdlib provides the foundation platform-dependent header libraries for the metal framework.

You can't #include <metal_stdlib> in the shared header because it relates only to the Metal Shading Language. It should be moved to the shader implementation .metal file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM