Metal Shading Language - multidimensional array

空扰寡人 提交于 2019-12-25 09:09:01

问题


How can I convert this:

const vec3 GDFVectors[19] = vec3[](
                                   normalize(vec3(1, 0, 0)),
                                   normalize(vec3(0, 1, 0)),
                                   normalize(vec3(0, 0, 1)),

                                   normalize(vec3(1, 1, 1 )),
                                   normalize(vec3(-1, 1, 1)),
                                   normalize(vec3(1, -1, 1)),
                                   normalize(vec3(1, 1, -1)),

                                   normalize(vec3(0, 1, PHI+1)),
                                   normalize(vec3(0, -1, PHI+1)),
                                   normalize(vec3(PHI+1, 0, 1)),
                                   normalize(vec3(-PHI-1, 0, 1)),
                                   normalize(vec3(1, PHI+1, 0)),
                                   normalize(vec3(-1, PHI+1, 0)),

                                   normalize(vec3(0, PHI, 1)),
                                   normalize(vec3(0, -PHI, 1)),
                                   normalize(vec3(1, 0, PHI)),
                                   normalize(vec3(-1, 0, PHI)),
                                   normalize(vec3(PHI, 1, 0)),
                                   normalize(vec3(-PHI, 1, 0))
                                   );

so that I can use it in Metal? I tried:

constant const float3 GDFVectors[19] = {
    normalize(float3(1, 0, 0)),
    normalize(float3(0, 1, 0)),
    normalize(float3(0, 0, 1)),

    normalize(float3(1, 1, 1 )),
    normalize(float3(-1, 1, 1)),
    normalize(float3(1, -1, 1)),
    normalize(float3(1, 1, -1)),

    normalize(float3(0, 1, PHI+1)),
    normalize(float3(0, -1, PHI+1)),
    normalize(float3(PHI+1, 0, 1)),
    normalize(float3(-PHI-1, 0, 1)),
    normalize(float3(1, PHI+1, 0)),
    normalize(float3(-1, PHI+1, 0)),

    normalize(float3(0, PHI, 1)),
    normalize(float3(0, -PHI, 1)),
    normalize(float3(1, 0, PHI)),
    normalize(float3(-1, 0, PHI)),
    normalize(float3(PHI, 1, 0)),
    normalize(float3(-PHI, 1, 0))
};

and did not get any error. However when I try to access it:

float3 a = GDFVectors[0];

I will get this error:

error: cannot have global constructors (llvm.global_ctors) in compute

I know is the way I initialize the float3 array that give me issue. But I am not sure how to resolve this.

来源:https://stackoverflow.com/questions/43509957/metal-shading-language-multidimensional-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!