简体   繁体   中英

How do I determine the maximum allowed size of an MTLTextureDescriptor

I am performing image manipulation using 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.

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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