2016-08-03 94 views
1

我试图在金属着色器中包含一个头文件。 对于原型就是这样,金属:未知的类型名称float4

float4 someFunction(float4 v); 

我收到此错误信息,

Unknown type name 'float4'; did you mean 'float'? 

似乎并不知道这是一个着色器程序头......虽然其他错误提示它。举例来说,如果我没有在这里指定的地址空间,

static float someK = 2.0; 

我得到这个错误,

Global variables must have a constant address space qualifier 

可固定如果我添加

constant static float someK = 2.0; 

如果我使用参考文献,我也得到这些类型的错误,

Reference type must include device, threadgroup, constant, or thread address space qualifier 

所以它看起来好像编译器知道它是着色器。为什么它不知道float4? :(

回答

1

确保你在你的着色器中的前两行就像这个例子:

#include <metal_stdlib> 

using namespace metal; 

float4 someFunction(float4 v); 

kernel void compute(texture2d<float, access::write> output [[texture(0)]], 
        uint2 gid [[thread_position_in_grid]]) 
{ 
    float4 color = float4(0, 0.5, 0.5, 1); 
    output.write(color, gid); 
} 

这对我工作得很好

+0

感谢我并不需要包括在metal_stdlib!我的头文件,但我没有意识到我需要在矢量类型头的金属名称空间...愚蠢的!再次感谢:) – endavid

+0

这不适合我 - 最近有什么变化?它工作在一个普通的头部,但不是在Swift和Metal中使用的桥头。 – bsabiston