iOS Metal "纹理像素格式与数据类型"不兼容



我在我的一个金属内核函数中添加了另一个纹理,并得到以下错误。我搜索了一下,看到很多关于这个错误的困惑。

如何解决Metal错误"纹理的像素格式与数据类型不兼容"?

validateComputeFunctionArguments:841: failed assertion `Compute Function(screenSampleWithScreenshot): 
The pixel format (MTLPixelFormatBGRA8Unorm) of the texture (name:CAMetalLayer Display Drawable)
bound at index 4 is incompatible with the data type (MTLDataTypeUInt) of the texture parameter
(myTexture [[texture(0)]]). MTLPixelFormatBGRA8Unorm is compatible with the data type(s) (
float,
half
).'

解决方案很简单:金属验证检测到函数签名不正确。它发现unsigned int(或其他意想不到的)数据类型,而你正在传递一个纹理与float颜色格式。

kernel void myComputeFunction(
texture2d<unsigned int, access::read> integerTexture [[texture(0)]],
texture2d<unsigned int, access::read> myTexture [[texture(1)]],
//change unsigned int to float if your texture MTLPixelFormatBGRA8Unorm:
texture2d<unsigned int, access::read> integerTexture [[texture(0)]],
texture2d<float, access::read> myTexture [[texture(1)]],
)

相关内容

  • 没有找到相关文章

最新更新