diff --git a/Common/MVKCommonEnvironment.h b/Common/MVKCommonEnvironment.h index d1531261..8087c9fe 100644 --- a/Common/MVKCommonEnvironment.h +++ b/Common/MVKCommonEnvironment.h @@ -72,6 +72,17 @@ extern "C" { # define MVK_OS_SIMULATOR TARGET_OS_SIMULATOR #endif +/** Building for macOS with support for Apple Silicon. */ +#ifndef MVK_MACOS_APPLE_SILICON +# define MVK_MACOS_APPLE_SILICON (__MAC_OS_X_VERSION_MAX_ALLOWED >= 101600) +#endif + +/** Building with Xcode 12. */ +#ifndef MVK_XCODE_12 +# define MVK_XCODE_12 (MVK_MACOS_APPLE_SILICON || \ + (__IPHONE_OS_VERSION_MAX_ALLOWED >= 140000)) // Also covers tvOS +#endif + /** Directive to identify public symbols. */ #define MVK_PUBLIC_SYMBOL __attribute__((visibility("default"))) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 411348cd..5a07b446 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -727,6 +727,14 @@ VkResult MVKPhysicalDevice::getSurfaceFormats(MVKSurface* surface, #if MVK_MACOS addSurfFmt(MTLPixelFormatRGB10A2Unorm); addSurfFmt(MTLPixelFormatBGR10A2Unorm); +#if MVK_MACOS_APPLE_SILICON + if (supportsMTLGPUFamily(Apple5)) { + addSurfFmt(MTLPixelFormatBGRA10_XR); + addSurfFmt(MTLPixelFormatBGRA10_XR_sRGB); + addSurfFmt(MTLPixelFormatBGR10_XR); + addSurfFmt(MTLPixelFormatBGR10_XR_sRGB); + } +#endif #endif #if MVK_IOS_OR_TVOS addSurfFmt(MTLPixelFormatBGRA10_XR); @@ -1117,6 +1125,13 @@ void MVKPhysicalDevice::initMetalFeatures() { _metalFeatures.nativeTextureSwizzle = true; } } + +#if MVK_XCODE_12 + if ( mvkOSVersionIsAtLeast(14.0) ) { + _metalFeatures.mslVersionEnum = MTLLanguageVersion2_3; + } +#endif + #endif #if MVK_IOS @@ -1191,6 +1206,12 @@ void MVKPhysicalDevice::initMetalFeatures() { } } +#if MVK_XCODE_12 + if ( mvkOSVersionIsAtLeast(14.0) ) { + _metalFeatures.mslVersionEnum = MTLLanguageVersion2_3; + } +#endif + #endif #if MVK_MACOS @@ -1255,6 +1276,18 @@ void MVKPhysicalDevice::initMetalFeatures() { } } +#if MVK_MACOS_APPLE_SILICON + if ( mvkOSVersionIsAtLeast(10.16) ) { + _metalFeatures.mslVersionEnum = MTLLanguageVersion2_3; + if (supportsMTLGPUFamily(Apple5)) { + // This is an Apple GPU--treat it accordingly. + _metalFeatures.mtlCopyBufferAlignment = 1; + _metalFeatures.mtlBufferAlignment = 16; + _metalFeatures.maxPerStageDynamicMTLBufferCount = _metalFeatures.maxPerStageBufferCount; + } + } +#endif + #endif // Note the selector name, which is different from the property name. @@ -1283,8 +1316,7 @@ void MVKPhysicalDevice::initMetalFeatures() { _metalFeatures.mslVersion = SPIRV_CROSS_NAMESPACE::CompilerMSL::Options::make_msl_version(maj, min); switch (_metalFeatures.mslVersionEnum) { -#if (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101600) || \ - (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000) // also covers tvOS +#if MVK_XCODE_12 case MTLLanguageVersion2_3: setMSLVersion(2, 3); break; @@ -1559,6 +1591,9 @@ void MVKPhysicalDevice::initLimits() { _properties.limits.maxTexelBufferElements = _properties.limits.maxImageDimension2D * (4 * KIBI); #if MVK_MACOS _properties.limits.maxUniformBufferRange = (64 * KIBI); + if (supportsMTLGPUFamily(Apple5)) { + _properties.limits.maxUniformBufferRange = (uint32_t)_metalFeatures.maxMTLBufferSize; + } #endif #if MVK_IOS_OR_TVOS _properties.limits.maxUniformBufferRange = (uint32_t)_metalFeatures.maxMTLBufferSize; @@ -1645,6 +1680,9 @@ void MVKPhysicalDevice::initLimits() { #endif #if MVK_MACOS _properties.limits.minTexelBufferOffsetAlignment = 256; + if (supportsMTLGPUFamily(Apple5)) { + _properties.limits.minTexelBufferOffsetAlignment = 16; + } #endif _texelBuffAlignProperties.storageTexelBufferOffsetAlignmentBytes = _properties.limits.minTexelBufferOffsetAlignment; _texelBuffAlignProperties.storageTexelBufferOffsetSingleTexelAlignment = VK_FALSE; @@ -1695,6 +1733,9 @@ void MVKPhysicalDevice::initLimits() { #if MVK_MACOS _properties.limits.maxFragmentInputComponents = 124; _properties.limits.optimalBufferCopyOffsetAlignment = 256; + if (supportsMTLGPUFamily(Apple5)) { + _properties.limits.optimalBufferCopyOffsetAlignment = 16; + } if (supportsMTLFeatureSet(macOS_GPUFamily1_v2)) { _properties.limits.maxTessellationGenerationLevel = 64; @@ -1851,6 +1892,22 @@ void MVKPhysicalDevice::initGPUInfoProperties() { _properties.deviceType = isIntegrated ? VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU : VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU; strlcpy(_properties.deviceName, _mtlDevice.name.UTF8String, VK_MAX_PHYSICAL_DEVICE_NAME_SIZE); + if (supportsMTLGPUFamily(Apple5)) { + // This is an Apple GPU. It won't have a 'device-id' property, so fill it in + // like on iOS/tvOS. + _properties.vendorID = 0x106b; // Apple's PCI ID +#if MVK_MACOS_APPLE_SILICON + if (supportsMTLGPUFamily(Apple6)) { + _properties.deviceID = 0xa130; + } else { + _properties.deviceID = 0xa120; + } +#else + _properties.deviceID = 0xa120; +#endif + return; + } + // If the device has an associated registry ID, we can use that to get the associated IOKit node. // The match dictionary is consumed by IOServiceGetMatchingServices and does not need to be released. io_registry_entry_t entry; @@ -1901,7 +1958,14 @@ void MVKPhysicalDevice::initGPUInfoProperties() { void MVKPhysicalDevice::initGPUInfoProperties() { NSUInteger coreCnt = NSProcessInfo.processInfo.processorCount; uint32_t devID = 0xa070; - if (supportsMTLFeatureSet(iOS_GPUFamily5_v1)) { +#if MVK_XCODE_12 + if (supportsMTLGPUFamily(Apple7)) { + devID = 0xa140; + } else +#endif + if (supportsMTLGPUFamily(Apple6)) { + devID = 0xa130; + } else if (supportsMTLFeatureSet(iOS_GPUFamily5_v1)) { devID = 0xa120; } else if (supportsMTLFeatureSet(iOS_GPUFamily4_v1)) { devID = 0xa110; @@ -2086,9 +2150,11 @@ uint32_t MVKPhysicalDevice::getHighestMTLFeatureSet() { uint32_t mtlVer = 0; #if MVK_IOS_OR_TVOS if (mvkOSVersionIsAtLeast(13.0)) { mtlVer = 0x30000; } + if (mvkOSVersionIsAtLeast(14.0)) { mtlVer = 0x40000; } #endif #if MVK_MACOS if (mvkOSVersionIsAtLeast(10.15)) { mtlVer = 0x30000; } + if (mvkOSVersionIsAtLeast(10.16)) { mtlVer = 0x40000; } #endif MTLGPUFamily mtlFam = MTLGPUFamily(0); @@ -2100,6 +2166,12 @@ uint32_t MVKPhysicalDevice::getHighestMTLFeatureSet() { if (supportsMTLGPUFamily(Apple3)) { mtlFam = MTLGPUFamilyApple3; } if (supportsMTLGPUFamily(Apple4)) { mtlFam = MTLGPUFamilyApple4; } if (supportsMTLGPUFamily(Apple5)) { mtlFam = MTLGPUFamilyApple5; } +#if MVK_IOS || MVK_MACOS_APPLE_SILICON + if (supportsMTLGPUFamily(Apple6)) { mtlFam = MTLGPUFamilyApple6; } +#if !MVK_MACOS + if (supportsMTLGPUFamily(Apple7)) { mtlFam = MTLGPUFamilyApple7; } +#endif +#endif // Not explicitly guaranteed to be unique...but close enough without spilling over uint32_t mtlFS = (mtlVer << 8) + (uint32_t)mtlFam; @@ -2375,6 +2447,12 @@ void MVKPhysicalDevice::logGPUInfo() { logMsg += "\n\tsupports the following Metal Versions, GPU's and Feature Sets:"; logMsg += "\n\t\tMetal Shading Language %s"; +#if MVK_IOS || MVK_MACOS_APPLE_SILICON +#if !MVK_MACOS + if (supportsMTLGPUFamily(Apple7)) { logMsg += "\n\t\tGPU Family Apple 7"; } +#endif + if (supportsMTLGPUFamily(Apple6)) { logMsg += "\n\t\tGPU Family Apple 6"; } +#endif if (supportsMTLGPUFamily(Apple5)) { logMsg += "\n\t\tGPU Family Apple 5"; } if (supportsMTLGPUFamily(Apple4)) { logMsg += "\n\t\tGPU Family Apple 4"; } if (supportsMTLGPUFamily(Apple3)) { logMsg += "\n\t\tGPU Family Apple 3"; }