如何在Metal中绑定二维数组纹理

3

我正在尝试使用二维数组纹理在Metal中,通过查阅网络上的资料,我已经成功初始化了我的纹理数组。但是现在,在将纹理与myEncoder.setFragmentTexture(myTextureArray, index: myIndex)绑定后,出现了一个错误,我无法继续。

Failed assertion `Fragment Function(basicFragment): incorrect type of
texture (MTLTextureType2DArray) bound at texture binding at index 0
(expect MTLTextureType2D) for texture[0].

我不知道在这里做错了什么,不幸的是谷歌也不知道。我想我需要调用一个特定的函数来绑定一个数组纹理,而不是用于绑定普通纹理的那个函数(setFragmentTexture),或者我可能会神秘地将我的纹理类型设置为单个2D纹理,而不允许设置纹理数组?所以我的问题是:

如何适当地在Metal中绑定我的纹理数组?

编辑:

我的片段着色器:

fragment float4 basicFragment(VertexOut vertexOut [[ stage_in ]],
                              texture2d<float> texture [[ texture(0) ]],
                              sampler sampler2D [[ sampler(0) ]])
{
    return texture.sample(sampler2D, vertexOut.texCoord, vertexOut.slice);
}

1
显示片段着色器声明。 - Ken Thomases
1个回答

1
根据金属着色语言规范第26页的内容:
下面的示例使用访问限定符和纹理对象参数。
void foo (texture2d<float> imgA [[texture(0)]],
         texture2d<float, access::read> imgB [[texture(1)]],
         texture2d<float, access::write> imgC [[texture(2)]])

在上一页中,他们展示了使用texture2d_array<type, access>替代texture2d<type, access>来创建2D纹理数组。因此,我认为代码应该是这样的:
void basicFragment(texture2d_array<float> imgA [[texture(0)]],...

例如。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接