ios - 在哪些情况下“MTLDevice newTextureWithDescriptor”会在 iOS 中失败?
问题描述
在我的 iOS 项目Metal
中被广泛使用。有时MTLDevice newTextureWithDescriptor
无法创建纹理。纹理格式有效,它是一个小的 RGBA 512x512 纹理,一切设置正确。
当我打印MTLDevice.currentAllocatedSize >> 20
它1396 MB
时iPhone XR
(A12
处理器)。
我已经使用了很多这个线程来估计最大运行时 RAM:https
://stackoverflow.com/a/15200855/2567725
所以我相信 iPhone XR 的最大允许 RAM 是1792 MB
。
我猜纹理没有被创建,因为 RAM 已经耗尽。
所以客人的意见是:
在 A12 上,Metal 是否
currentAllocatedSize
与CPU
内存相关,并且GPU
内存与 CPU 之一“共享”,所以1792 MB = GPU+CPU
对于 iPhone XR?有没有办法得到金属错误的描述?(现在它只是返回
nil
)newTextureWithDescriptor
。是否有可能知道金属分配策略是如何工作的,例如返回的可用空间
RAM
应该有多小?MTLDevice newTextureWithDescriptor
nil
更新:
然而,在某些情况下,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
解决方案
推荐阅读
- javascript - 使用 React 的 RSS 解析器在页面刷新时失败
- python-3.x - 如何在 Windows 10 命令提示符下运行 python 程序
- reactjs - 如何在 React 中使用外部脚本而不将其添加到 html 文件中
- rider - JetBrains Rider:如何附加到本地运行的提升权限进程?
- python - 您可以将就地运算符与 Python 3.8 “海象”运算符一起使用吗?
- javascript - ajax jquery 表单停止发送电子邮件
- java - 从 Java 中的 .txt 文件导入字符串时跳过隔行
- javascript - JavaScript RegExp:为什么 `\$` 不匹配 `$` 而 `\\$` 匹配?
- python - 打印输出它不显示任何东西
- javascript - WordPress 自定义插件开发中的 AJAX 请求发布/返回