简体   繁体   English

如何确定 MTLTextureDescriptor 的最大允许大小

[英]How do I determine the maximum allowed size of an MTLTextureDescriptor

I am performing image manipulation using UIGraphicsImageRenderer(size: size, format: format) .我正在使用UIGraphicsImageRenderer(size: size, format: format)执行图像处理。 If the image is too large, it will fail with an assertion:如果图像太大,它将因断言而失败:

failed assertion `MTLTextureDescriptor has width (15488) greater than the maximum allowed size of 8192.'

I'd like to prevent this by first checking the image does not exceed the maximum allowed size.我想通过首先检查图像不超过允许的最大尺寸来防止这种情况。 I'm not sure that 8192 is a constant for all devices, and would like to obtain this programmatically instead of hard coding it.我不确定 8192 是所有设备的常量,并且希望以编程方式获取它而不是硬编码它。

It is programmatically not possible to get the maximum texture size supported by the device.以编程方式无法获得设备支持的最大纹理大小。 However, the below code will give you the hardcoded size based on the device type.但是,下面的代码将根据设备类型为您提供硬编码的大小。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM