![](/img/trans.png)
[英]CoreML initialization fails: MTLTextureDescriptor has width greater than the maximum allowed size
[英]How do I determine the maximum allowed size of an MTLTextureDescriptor
我正在使用UIGraphicsImageRenderer(size: size, format: format)
执行图像处理。 如果图像太大,它将因断言而失败:
failed assertion `MTLTextureDescriptor has width (15488) greater than the maximum allowed size of 8192.'
我想通过首先检查图像不超过允许的最大尺寸来防止这种情况。 我不确定 8192 是所有设备的常量,并且希望以编程方式获取它而不是硬编码它。
以编程方式无法获得设备支持的最大纹理大小。 但是,下面的代码将根据设备类型为您提供硬编码的大小。
int maxTexSize = 4096;
if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily4_v1] || [mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily3_v1]) {
maxTexSize = 16384;
else if ([mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily2_v2] || [mtldevice supportsFeatureSet:MTLFeatureSet_iOS_GPUFamily1_v2]) {
maxTexSize = 8192;
} else {
maxTexSize = 4096;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.