金属:未知类型名称float4

时间:2016-08-03 07:58:42

标签: ios shader metal

我正在尝试在金属着色器中包含头文件。 对于像这样的原型,

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? :(

2 个答案:

答案 0 :(得分: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);
}

这对我来说很好。

答案 1 :(得分:0)

尝试使用

vector_float4

相反。