有没有办法只使用像素数据指针而不使用 CVPixelBuffer 来制作 MTLTexture?

Is there a way to make MTLTexture using only pixel data pointer without using CVPixelBuffer?

目前,我将像素数据复制到CVPixelBuffer的y,u,v平面,使用CVMetalTextureCache创建CVMetalTexture,导入使用MTLTexture。

有没有办法在不将像素数据复制到CVPixelBuffer的y,u,v平面的情况下制作CVMetalTexture? 或者,有没有办法只使用像素数据指针而不使用 CVPixelBuffer 来创建 MTLTexture?

创建 MTLTexture 的惯用方法是:

创建一个 MTLTextureDescriptor 来描述您想要的纹理 — 它的大小、像素格式、mip 贴图的数量等。

使用您的纹理描述符通过 makeTexture(descriptor:) 从您的 MTLDevice 请求新纹理。

在纹理上使用 replace(region:mipmapLevel:slice:withBytes:bytesPerRow:bytesPerImage:) 用数据填充纹理。

CVMetalTexture 的存在主要是为了将 CoreVideo 数据桥接到 Metal——例如如果您想解码视频并将其显示在 3d 场景中。如果您还没有进入 CV 世界,它就不会有用。