简体   繁体   English

金属着色器中包含的内容

[英]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.带有metal_stdlib的着色器在我在 web 上找到的示例 Xcode 项目中编译。 But it does not compile if I include it in my existing project where I get the error message 'metal_stdlib' file not found .但是,如果我将它包含在我收到错误消息'metal_stdlib' file not found现有项目中,它不会编译。 (the one with simd/simd.h works fine). (带有simd/simd.h的那个可以正常工作)。

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.我一直试图找出两个项目(其中有数千个)之间的 Xcode 设置存在差异的地方,但还没有运气。 When does one include <simd/simd.h> , when <metal_stdlib> ?什么时候包含<simd/simd.h> ,什么时候包含<metal_stdlib>

-- Update: --更新:

The compilation fails in an Objective-C file where I included the shared header (which includes the #include <metal_stdlib> ). Objective-C 文件中的编译失败,其中我包含了共享的 header (其中包括#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.我也为此苦苦挣扎了一会儿,才意识到我实际上错误地将我的金属文件导入了 Obj-C 源代码文件。 No metal header files may be imported on any other header or source code files.没有金属 header 文件可以在任何其他 header 或源代码文件中导入。

Simd.h provides small vector (simd) and matrix types, as well as basic arithmetic and mathematical functions for them. Simd.h提供小向量 (simd) 和矩阵类型,以及它们的基本算术和数学函数。

On the other hand, metal_stdlib provides the foundation platform-dependent header libraries for the metal framework.另一方面, metal_stdlib为金属框架提供了依赖于基础平台的 header 库。

You can't #include <metal_stdlib> in the shared header because it relates only to the Metal Shading Language.您不能在共享 header 中#include <metal_stdlib>因为它仅与金属着色语言有关。 It should be moved to the shader implementation .metal file.应该将其移至着色器实现.metal文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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