Search code examples
iosswifttexturesmetalmetalkit

How to get programmatically the maximum texture size (width and height)


How to get programmatically the maximum texture size (width and height) with metal? with openGL i can do: glGetIntegerv(GL_MAX_TEXTURE_SIZE, ...) but how to do it with Metal ?


Solution

  • As @warrenm has mentioned, 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;
    }