Skip to content

Commit

Permalink
make support iOS 11+ and macOS 14+
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo committed Jan 14, 2025
1 parent cc2ff78 commit 24fcb77
Showing 1 changed file with 8 additions and 108 deletions.
116 changes: 8 additions & 108 deletions native/cocos/renderer/gfx-metal/MTLUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,40 +98,6 @@ EShLanguage getShaderStage(ShaderStageFlagBit type) {

#if CC_PLATFORM == CC_PLATFORM_IOS
ccstd::string getIOSFeatureSetToString(MTLFeatureSet featureSet) {
if (@available(iOS 8.0, *)) {
switch (featureSet) {
case MTLFeatureSet_iOS_GPUFamily1_v1:
return "MTLFeatureSet_iOS_GPUFamily1_v1";
case MTLFeatureSet_iOS_GPUFamily2_v1:
return "MTLFeatureSet_iOS_GPUFamily2_v1";
default:
break;
}
}
if (@available(iOS 9.0, *)) {
switch (featureSet) {
case MTLFeatureSet_iOS_GPUFamily1_v2:
return "MTLFeatureSet_iOS_GPUFamily1_v2";
case MTLFeatureSet_iOS_GPUFamily2_v2:
return "MTLFeatureSet_iOS_GPUFamily2_v2";
case MTLFeatureSet_iOS_GPUFamily3_v1:
return "MTLFeatureSet_iOS_GPUFamily3_v1";
default:
break;
}
}
if (@available(iOS 10.0, *)) {
switch (featureSet) {
case MTLFeatureSet_iOS_GPUFamily1_v3:
return "MTLFeatureSet_iOS_GPUFamily1_v3";
case MTLFeatureSet_iOS_GPUFamily2_v3:
return "MTLFeatureSet_iOS_GPUFamily2_v3";
case MTLFeatureSet_iOS_GPUFamily3_v2:
return "MTLFeatureSet_iOS_GPUFamily3_v2";
default:
break;
}
}
if (@available(iOS 11.0, *)) {
switch (featureSet) {
case MTLFeatureSet_iOS_GPUFamily1_v4:
Expand Down Expand Up @@ -192,68 +158,10 @@ GPUFamily getIOSGPUFamily(MTLFeatureSet featureSet) {
break;
}
}
if (@available(iOS 10.0, *)) {
switch (featureSet) {
case MTLFeatureSet_iOS_GPUFamily1_v3:
return GPUFamily::Apple1;
case MTLFeatureSet_iOS_GPUFamily2_v3:
return GPUFamily::Apple2;
case MTLFeatureSet_iOS_GPUFamily3_v2:
return GPUFamily::Apple3;
default:
break;
}
}
if (@available(iOS 9.0, *)) {
switch (featureSet) {
case MTLFeatureSet_iOS_GPUFamily1_v2:
return GPUFamily::Apple1;
case MTLFeatureSet_iOS_GPUFamily2_v2:
return GPUFamily::Apple2;
case MTLFeatureSet_iOS_GPUFamily3_v1:
return GPUFamily::Apple3;
default:
break;
}
}
if (@available(iOS 8.0, *)) {
switch (featureSet) {
case MTLFeatureSet_iOS_GPUFamily1_v1:
return GPUFamily::Apple1;
case MTLFeatureSet_iOS_GPUFamily2_v1:
return GPUFamily::Apple2;
default:
break;
}
}
return GPUFamily::Apple1;
}
#else
ccstd::string getMacFeatureSetToString(MTLFeatureSet featureSet) {
if (@available(macOS 10.11, *)) {
switch (featureSet) {
case MTLFeatureSet_macOS_GPUFamily1_v1:
return "MTLFeatureSet_macOS_GPUFamily1_v1";
default:
break;
}
}
if (@available(macOS 10.12, *)) {
switch (featureSet) {
case MTLFeatureSet_macOS_GPUFamily1_v2:
return "MTLFeatureSet_macOS_GPUFamily1_v2";
default:
break;
}
}
if (@available(macOS 10.13, *)) {
switch (featureSet) {
case MTLFeatureSet_macOS_GPUFamily1_v3:
return "MTLFeatureSet_macOS_GPUFamily1_v3";
default:
break;
}
}
if (@available(macOS 10.14, *)) {
switch (featureSet) {
case MTLFeatureSet_macOS_GPUFamily1_v4:
Expand Down Expand Up @@ -525,7 +433,7 @@ void main() {
}
}
#else
if (@available(macOS 10.13, *)) {
if (@available(macOS 10.14, *)) {
if (isNormalized) {
return MTLVertexFormatUChar4Normalized_BGRA;
} else {
Expand Down Expand Up @@ -1149,38 +1057,30 @@ void main() {

NSUInteger mu::highestSupportedFeatureSet(id<MTLDevice> device) {
NSUInteger maxKnownFeatureSet;
NSUInteger defaultFeatureSet;
#if CC_PLATFORM == CC_PLATFORM_IOS
defaultFeatureSet = MTLFeatureSet_iOS_GPUFamily1_v1;
if (@available(iOS 12.0, *)) {
maxKnownFeatureSet = MTLFeatureSet_iOS_GPUFamily4_v2;
maxKnownFeatureSet = MTLFeatureSet_iOS_GPUFamily5_v1;
} else if (@available(iOS 11.0, *)) {
maxKnownFeatureSet = MTLFeatureSet_iOS_GPUFamily4_v1;
} else if (@available(iOS 10.0, *)) {
maxKnownFeatureSet = MTLFeatureSet_iOS_GPUFamily3_v2;
} else if (@available(iOS 9.0, *)) {
maxKnownFeatureSet = MTLFeatureSet_iOS_GPUFamily3_v1;
} else {
maxKnownFeatureSet = MTLFeatureSet_iOS_GPUFamily2_v1;
CC_ASSERT(false);
maxKnownFeatureSet MTLFeatureSet_iOS_GPUFamily1_v4;
}
#else
defaultFeatureSet = MTLFeatureSet_macOS_GPUFamily1_v1;
if (@available(macOS 10.14, *)) {
maxKnownFeatureSet = MTLFeatureSet_macOS_GPUFamily2_v1;
} else if (@available(macOS 10.13, *)) {
maxKnownFeatureSet = MTLFeatureSet_macOS_GPUFamily1_v3;
} else if (@available(macOS 10.12, *)) {
maxKnownFeatureSet = MTLFeatureSet_macOS_GPUFamily1_v2;
} else {
CC_ASSERT(false);
maxKnownFeatureSet = MTLFeatureSet_macOS_GPUFamily1_v1;
}
#endif
for (int featureSet = static_cast<int>(maxKnownFeatureSet); featureSet >= 0; --featureSet) {
if ([device supportsFeatureSet:MTLFeatureSet(featureSet)]) {
return static_cast<NSUInteger>(featureSet);
maxKnownFeatureSet = static_cast<NSUInteger>(featureSet);
break;
}
}
return defaultFeatureSet;
return maxKnownFeatureSet;
}

uint32_t mu::getGPUFamily(MTLFeatureSet featureSet) {
Expand Down

0 comments on commit 24fcb77

Please sign in to comment.