From 18642002ce68fa3071885afbaf4fa42e6ea17ded Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Wed, 1 Dec 2021 18:14:07 -0500 Subject: [PATCH 1/3] Updates to better support Rosetta2 runtimes, and MSL 2.4 and 2.3 versions. Do not use MTLEvent for VkSemaphore under Rosetta2. Remove compile test for MVK_MACOS_APPLE_SILICON and MVK_APPLE_SILICON when testing for Apple GPU families, to allow x86 builds to test for Apple GPU under Rosetta2. Simplify identifying M1 GPU. All M1 SoCs currently support the A14 (Apple7) GPU. Support compiling MSL 2.4 in runtime pipelines and MoltenVKShaderConverterTool. Fix issue where MSL 2.3 only available on Apple Silicon, even on macOS. Update to latest SPIRV-Cross (unrelated to Rosetta2). --- Docs/Whats_New.md | 8 ++- ExternalRevisions/SPIRV-Cross_repo_revision | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 49 ++++++++++--------- .../MoltenVKShaderConverterTool/OSSupport.mm | 5 ++ 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index cfefbb17..47a6ff26 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -18,7 +18,13 @@ MoltenVK 1.1.7 Released TBD -- Support building MoltenVK with static Vulkan linkage symbols hidden. +- Support building MoltenVK with static Vulkan linkage symbols hidden. +- Do not use `MTLEvent` for `VkSemaphore` under *Rosetta2*. +- Support compiling *MSL 2.4* in runtime pipelines and `MoltenVKShaderConverterTool`. +- Fix issue where *MSL 2.3* only available on *Apple Silicon*, even on *macOS*. +- Update to latest SPIRV-Cross: + - MSL: Add 64 bit support for `OpSwitch`. + - MSL: Don't output depth and stencil values with explicit early fragment tests. diff --git a/ExternalRevisions/SPIRV-Cross_repo_revision b/ExternalRevisions/SPIRV-Cross_repo_revision index 25967c3b..11d4f3bd 100644 --- a/ExternalRevisions/SPIRV-Cross_repo_revision +++ b/ExternalRevisions/SPIRV-Cross_repo_revision @@ -1 +1 @@ -7c3cb0b12c9965497b08403c82ac1b82846fa7be +e9cc6403341baf0edd430a4027b074d0a06b782f diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index a4e69ff8..87758534 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -1273,6 +1273,11 @@ void MVKPhysicalDevice::initMetalFeatures() { _metalFeatures.mslVersionEnum = MTLLanguageVersion2_3; } #endif +#if MVK_XCODE_13 + if ( mvkOSVersionIsAtLeast(15.0) ) { + _metalFeatures.mslVersionEnum = MTLLanguageVersion2_4; + } +#endif #endif @@ -1377,6 +1382,11 @@ void MVKPhysicalDevice::initMetalFeatures() { } } #endif +#if MVK_XCODE_13 + if ( mvkOSVersionIsAtLeast(15.0) ) { + _metalFeatures.mslVersionEnum = MTLLanguageVersion2_4; + } +#endif #endif @@ -1447,7 +1457,7 @@ void MVKPhysicalDevice::initMetalFeatures() { } } -#if MVK_MACOS_APPLE_SILICON +#if MVK_XCODE_12 if ( mvkOSVersionIsAtLeast(10.16) ) { _metalFeatures.mslVersionEnum = MTLLanguageVersion2_3; if (supportsMTLGPUFamily(Apple5)) { @@ -1475,6 +1485,11 @@ void MVKPhysicalDevice::initMetalFeatures() { _metalFeatures.textureBarriers = true; } +#if MVK_XCODE_13 + if ( mvkOSVersionIsAtLeast(12.0) ) { + _metalFeatures.mslVersionEnum = MTLLanguageVersion2_4; + } +#endif #endif // Note the selector name, which is different from the property name. @@ -2200,21 +2215,10 @@ 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. + if (supportsMTLGPUFamily(Apple7)) { + // This is an Apple GPU. It won't have a 'device-id' property, so fill it in like on iOS/tvOS. _properties.vendorID = kAppleVendorId; -#if MVK_MACOS_APPLE_SILICON - if (supportsMTLGPUFamily(Apple7)) { - _properties.deviceID = 0xa140; - } else if (supportsMTLGPUFamily(Apple6)) { - _properties.deviceID = 0xa130; - } else { - _properties.deviceID = 0xa120; - } -#else - _properties.deviceID = 0xa120; -#endif + _properties.deviceID = 0xa140; return; } @@ -2480,10 +2484,8 @@ 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 (supportsMTLGPUFamily(Apple7)) { mtlFam = MTLGPUFamilyApple7; } -#endif // Not explicitly guaranteed to be unique...but close enough without spilling over uint32_t mtlFS = (mtlVer << 8) + (uint32_t)mtlFam; @@ -2622,7 +2624,7 @@ void MVKPhysicalDevice::initMemoryProperties() { // Memoryless storage uint32_t memlessBit = 0; -#if MVK_MACOS_APPLE_SILICON +#if MVK_MACOS if (supportsMTLGPUFamily(Apple5)) { memlessBit = 1 << typeIdx; setMemoryType(typeIdx, mainHeapIdx, MVK_VK_MEMORY_TYPE_METAL_MEMORYLESS); @@ -2808,10 +2810,8 @@ 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 (supportsMTLGPUFamily(Apple7)) { logMsg += "\n\t\tGPU Family Apple 7"; } 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"; } @@ -3966,9 +3966,12 @@ void MVKDevice::initPhysicalDevice(MVKPhysicalDevice* physicalDevice, const VkDe // Decide whether Vulkan semaphores should use a MTLEvent or MTLFence if they are available. // Prefer MTLEvent, because MTLEvent handles sync across MTLCommandBuffers and MTLCommandQueues. - // However, do not allow use of MTLEvents on NVIDIA GPUs, which have demonstrated trouble with MTLEvents. - // Since MTLFence config is disabled by default, emulation will be used on NVIDIA unless MTLFence is enabled. - bool canUseMTLEventForSem4 = _pMetalFeatures->events && mvkConfig().semaphoreUseMTLEvent && (_pProperties->vendorID != kNVVendorId); + // However, do not allow use of MTLEvents on Rosetta2 (x86 build on M1 runtime) or NVIDIA GPUs, + // which have demonstrated trouble with MTLEvents. In that case, since MTLFence use is disabled + // by default, unless MTLFence is deliberately enabled, CPU emulation will be used. + bool isNVIDIA = _pProperties->vendorID == kNVVendorId; + bool isRosetta2 = _pProperties->vendorID == kAppleVendorId && !MVK_APPLE_SILICON; + bool canUseMTLEventForSem4 = _pMetalFeatures->events && mvkConfig().semaphoreUseMTLEvent && !(isRosetta2 || isNVIDIA); bool canUseMTLFenceForSem4 = _pMetalFeatures->fences && mvkConfig().semaphoreUseMTLFence; _vkSemaphoreStyle = canUseMTLEventForSem4 ? VkSemaphoreStyleUseMTLEvent : (canUseMTLFenceForSem4 ? VkSemaphoreStyleUseMTLFence : VkSemaphoreStyleUseEmulation); switch (_vkSemaphoreStyle) { diff --git a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/OSSupport.mm b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/OSSupport.mm index 2af65a8a..f0f8cb9f 100644 --- a/MoltenVKShaderConverter/MoltenVKShaderConverterTool/OSSupport.mm +++ b/MoltenVKShaderConverter/MoltenVKShaderConverterTool/OSSupport.mm @@ -71,6 +71,11 @@ bool mvk::compile(const string& mslSourceCode, #define mslVer(MJ, MN, PT) mslVersionMajor == MJ && mslVersionMinor == MN && mslVersionPoint == PT MTLLanguageVersion mslVerEnum = (MTLLanguageVersion)0; +#if MVK_XCODE_13 + if (mslVer(2, 4, 0)) { + mslVerEnum = MTLLanguageVersion2_4; + } else +#endif #if MVK_XCODE_12 if (mslVer(2, 3, 0)) { mslVerEnum = MTLLanguageVersion2_3; From 479d55f2aa2bebdedf87db0132ddd41f5b35341b Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Wed, 1 Dec 2021 19:13:29 -0500 Subject: [PATCH 2/3] Wrap MTLGPUFamilyApple6 and MTLGPUFamilyApple7 in build macros for Xcode 11.7. --- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 87758534..84c53753 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -2215,10 +2215,20 @@ 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(Apple7)) { + if (supportsMTLGPUFamily(Apple5)) { // This is an Apple GPU. It won't have a 'device-id' property, so fill it in like on iOS/tvOS. + // Test for Apple5 first instead of Apple7 to support Xcode 11.7 builds. _properties.vendorID = kAppleVendorId; - _properties.deviceID = 0xa140; +#if MVK_XCODE_12 + if (supportsMTLGPUFamily(Apple7)) { + _properties.deviceID = 0xa140; + } else if (supportsMTLGPUFamily(Apple6)) { + _properties.deviceID = 0xa130; + } else +#endif + { + _properties.deviceID = 0xa120; + } return; } @@ -2484,8 +2494,10 @@ uint32_t MVKPhysicalDevice::getHighestMTLFeatureSet() { if (supportsMTLGPUFamily(Apple3)) { mtlFam = MTLGPUFamilyApple3; } if (supportsMTLGPUFamily(Apple4)) { mtlFam = MTLGPUFamilyApple4; } if (supportsMTLGPUFamily(Apple5)) { mtlFam = MTLGPUFamilyApple5; } +#if MVK_XCODE_12 if (supportsMTLGPUFamily(Apple6)) { mtlFam = MTLGPUFamilyApple6; } if (supportsMTLGPUFamily(Apple7)) { mtlFam = MTLGPUFamilyApple7; } +#endif // Not explicitly guaranteed to be unique...but close enough without spilling over uint32_t mtlFS = (mtlVer << 8) + (uint32_t)mtlFam; @@ -2810,8 +2822,10 @@ void MVKPhysicalDevice::logGPUInfo() { logMsg += "\n\tsupports the following Metal Versions, GPU's and Feature Sets:"; logMsg += "\n\t\tMetal Shading Language %s"; +#if MVK_XCODE_12 if (supportsMTLGPUFamily(Apple7)) { logMsg += "\n\t\tGPU Family Apple 7"; } 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"; } From e74cf2f094c42280b635eb8d79296a099358e301 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Thu, 2 Dec 2021 09:47:56 -0500 Subject: [PATCH 3/3] Fix build macros for tvOS, plus support MTLGPUFamilyApple8. Don't use tests for MTLGPUFamilyApple6 and MTLGPUFamilyApple7 in tvOS build. Advertise MTLGPUFamilyApple8 GPU and A15 SoC device if present. --- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 84c53753..49aea68b 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -2282,6 +2282,11 @@ void MVKPhysicalDevice::initGPUInfoProperties() { void MVKPhysicalDevice::initGPUInfoProperties() { NSUInteger coreCnt = NSProcessInfo.processInfo.processorCount; uint32_t devID = 0xa070; +#if MVK_XCODE_13 + if (supportsMTLGPUFamily(Apple8)) { + devID = 0xa150; + } else +#endif #if MVK_XCODE_12 if (supportsMTLGPUFamily(Apple7)) { devID = 0xa140; @@ -2494,10 +2499,15 @@ uint32_t MVKPhysicalDevice::getHighestMTLFeatureSet() { if (supportsMTLGPUFamily(Apple3)) { mtlFam = MTLGPUFamilyApple3; } if (supportsMTLGPUFamily(Apple4)) { mtlFam = MTLGPUFamilyApple4; } if (supportsMTLGPUFamily(Apple5)) { mtlFam = MTLGPUFamilyApple5; } -#if MVK_XCODE_12 +#if MVK_IOS || (MVK_MACOS && MVK_XCODE_12) if (supportsMTLGPUFamily(Apple6)) { mtlFam = MTLGPUFamilyApple6; } +#endif +#if (MVK_IOS || MVK_MACOS) && MVK_XCODE_12 if (supportsMTLGPUFamily(Apple7)) { mtlFam = MTLGPUFamilyApple7; } #endif +#if MVK_IOS && MVK_XCODE_13 + if (supportsMTLGPUFamily(Apple8)) { mtlFam = MTLGPUFamilyApple8; } +#endif // Not explicitly guaranteed to be unique...but close enough without spilling over uint32_t mtlFS = (mtlVer << 8) + (uint32_t)mtlFam; @@ -2822,8 +2832,13 @@ void MVKPhysicalDevice::logGPUInfo() { logMsg += "\n\tsupports the following Metal Versions, GPU's and Feature Sets:"; logMsg += "\n\t\tMetal Shading Language %s"; -#if MVK_XCODE_12 +#if MVK_IOS && MVK_XCODE_13 + if (supportsMTLGPUFamily(Apple8)) { logMsg += "\n\t\tGPU Family Apple 8"; } +#endif +#if (MVK_IOS || MVK_MACOS) && MVK_XCODE_12 if (supportsMTLGPUFamily(Apple7)) { logMsg += "\n\t\tGPU Family Apple 7"; } +#endif +#if MVK_IOS || (MVK_MACOS && MVK_XCODE_12) if (supportsMTLGPUFamily(Apple6)) { logMsg += "\n\t\tGPU Family Apple 6"; } #endif if (supportsMTLGPUFamily(Apple5)) { logMsg += "\n\t\tGPU Family Apple 5"; }