iOS code to identify metal support in runtime?

后端 未结 4 1422
迷失自我
迷失自我 2021-02-13 15:51

Usually, I use the below code to identify the iOS version of the device.

if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0)

In

4条回答
  •  北海茫月
    2021-02-13 16:34

    Ricster explained clearly about all the methods to identify the device which supports metal at runtime. If you cannot use MTLCreateSystemDefaultDevice() in your class by including metal libraries, use device informations(iOS version,gpu/cpu architecture),but you need to consider all the cases explained by Ricster when using device informations.

    void deviceConfigurations(){
            size_t size;
            cpu_type_t type;
            cpu_subtype_t subtype;
            size = sizeof(type);
            sysctlbyname("hw.cputype", &type, &size, NULL, 0);
    
            size = sizeof(subtype);
            sysctlbyname("hw.cpusubtype", &subtype, &size, NULL, 0);
    }
    

    Use Subtype and type variable to identify device and other informations.

提交回复
热议问题