2016-08-03 96 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