我正在使用 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;
}
关于ios - 如何确定 MTLTextureDescriptor 的最大允许大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63515452/