【问题标题】:Metal: unknown type name float4金属:未知类型名称 float4
【发布时间】:2016-08-03 07:58:42
【问题描述】:

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

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

【问题讨论】:

    标签: ios shader metal


    【解决方案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);
    }
    

    这对我来说很好。

    【讨论】:

    • 谢谢!我不需要在我的头文件中包含 metal_stdlib,但我没有意识到我需要在向量类型的头文件中使用 metal 命名空间......愚蠢!再次感谢:)
    • 这对我不起作用——最近有什么变化吗?它适用于常规标头,但不适用于 Swift 和 Metal 的桥接头。
    【解决方案2】:

    尝试使用

    vector_float4
    

    改为。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      • 2014-11-19
      • 2018-10-27
      • 2016-09-16
      • 2012-04-03
      相关资源
      最近更新 更多