首页 > 解决方案 > 在哪些情况下“MTLDevice newTextureWithDescriptor”会在 iOS 中失败?

问题描述

在我的 iOS 项目Metal中被广泛使用。有时MTLDevice newTextureWithDescriptor无法创建纹理。纹理格式有效,它是一个小的 RGBA 512x512 纹理,一切设置正确。

当我打印MTLDevice.currentAllocatedSize >> 201396 MBiPhone XRA12处理器)。

我已经使用了很多这个线程来估计最大运行时 RAMhttps
://stackoverflow.com/a/15200855/2567725 所以我相信 iPhone XR 的最大允许 RAM 是1792 MB

我猜纹理没有被创建,因为 RAM 已经耗尽。

所以客人的意见是:

  1. 在 A12 上,Metal 是否currentAllocatedSizeCPU内存相关,并且GPU内存与 CPU 之一“共享”,所以1792 MB = GPU+CPU对于 iPhone XR?

  2. 有没有办法得到金属错误的描述?(现在它只是返回nilnewTextureWithDescriptor

  3. 是否有可能知道金属分配策略是如何工作的,例如返回的可用空间RAM应该有多小?MTLDevice newTextureWithDescriptornil

更新
然而,在某些情况下,MTLDevice.currentAllocatedSize >> 20要少得多,例如14 MB,所以我怀疑Metal有一些状态腐败。但是如何检查错误的原因是什么?

纹理描述符的调试描述:

textureDescriptor.pixelFormat = 70
textureDescriptor.width = 512
textureDescriptor.height = 512
textureDescriptor.textureType = 3
textureDescriptor.usage = 23
textureDescriptor.arrayLength = 1000
textureDescriptor.sampleCount = 1
textureDescriptor.mipmapLevelCount = 1
device.currentAllocatedSize >> 20 = 14

标签: iosmemory-managementgpumetal

解决方案


推荐阅读