Merge pull request #1635 from bangnoise/pr/maxTotalThreadsPerThreadgroup-crash-macOS_10_13

Fix crash creating compute pipelines on macOS versions < 10.14
diff --git a/Docs/MoltenVK_Runtime_UserGuide.md b/Docs/MoltenVK_Runtime_UserGuide.md
index b7f572d..b82aa34 100644
--- a/Docs/MoltenVK_Runtime_UserGuide.md
+++ b/Docs/MoltenVK_Runtime_UserGuide.md
@@ -263,6 +263,7 @@
 - `VK_KHR_16bit_storage`
 - `VK_KHR_8bit_storage`
 - `VK_KHR_bind_memory2`
+- `VK_KHR_buffer_device_address` *(requires Metal 3.0)*
 - `VK_KHR_create_renderpass2`
 - `VK_KHR_dedicated_allocation`
 - `VK_KHR_depth_stencil_resolve`
@@ -297,6 +298,7 @@
 - `VK_KHR_timeline_semaphore`
 - `VK_KHR_uniform_buffer_standard_layout`
 - `VK_KHR_variable_pointers`
+- `VK_EXT_buffer_device_address` *(requires Metal 3.0)*
 - `VK_EXT_debug_marker`
 - `VK_EXT_debug_report`
 - `VK_EXT_debug_utils`
diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md
index e3b9683..f432400 100644
--- a/Docs/Whats_New.md
+++ b/Docs/Whats_New.md
@@ -20,11 +20,13 @@
 
 - Add support for extensions:
 	- `VK_EXT_metal_objects`
+	- `VK_KHR_buffer_device_address` and `VK_EXT_buffer_device_address`.
 - Reducing redundant state changes to improve command encoding performance.
 - Update minimum Xcode deployment targets to macOS 10.13, iOS 11, and tvOS 11,
   to avoid Xcode build warnings in Xcode 14.
 
 
+
 MoltenVK 1.1.10
 --------------
 
diff --git a/ExternalRevisions/SPIRV-Cross_repo_revision b/ExternalRevisions/SPIRV-Cross_repo_revision
index 6a4e776..33777a7 100644
--- a/ExternalRevisions/SPIRV-Cross_repo_revision
+++ b/ExternalRevisions/SPIRV-Cross_repo_revision
@@ -1 +1 @@
-50b4d5389b6a06f86fb63a2848e1a7da6d9755ca
+d8d051381f65b9606fb8016c79b7c3bab872eec3
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
index 9989a69..7de4a79 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
@@ -794,6 +794,9 @@
 	const VkPhysicalDeviceImagelessFramebufferFeaturesKHR _enabledImagelessFramebufferFeatures;
 	const VkPhysicalDeviceDynamicRenderingFeatures _enabledDynamicRenderingFeatures;
 	const VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures _enabledSeparateDepthStencilLayoutsFeatures;
+	const VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR _enabledFragmentShaderBarycentricFeatures;
+	const VkPhysicalDeviceBufferDeviceAddressFeatures _enabledBufferDeviceAddressFeatures;
+	const VkPhysicalDeviceBufferDeviceAddressFeaturesEXT _enabledBufferDeviceAddressFeaturesEXT;
 
 	/** Pointer to the Metal-specific features of the underlying physical device. */
 	const MVKPhysicalDeviceMetalFeatures* _pMetalFeatures;
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
index f3c6a3c..48db2d0 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
@@ -288,16 +288,23 @@
 				break;
 			}
             case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_BARYCENTRIC_FEATURES_KHR: {
-                auto* barycentricProperties = (VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR*)next;
-                barycentricProperties->fragmentShaderBarycentric = true;
+                auto* barycentricFeatures = (VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR*)next;
+				barycentricFeatures->fragmentShaderBarycentric = true;
                 break;
             }
             case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES: {
                 auto* bufferDeviceAddressFeatures = (VkPhysicalDeviceBufferDeviceAddressFeatures*)next;
-                bufferDeviceAddressFeatures->bufferDeviceAddress = true;
+                bufferDeviceAddressFeatures->bufferDeviceAddress = mvkOSVersionIsAtLeast(12.05, 16.0);
                 bufferDeviceAddressFeatures->bufferDeviceAddressCaptureReplay = false;
                 bufferDeviceAddressFeatures->bufferDeviceAddressMultiDevice = false;
             }
+			case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT: {
+				auto* bufferDeviceAddressFeatures = (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT*)next;
+				bufferDeviceAddressFeatures->bufferDeviceAddress = mvkOSVersionIsAtLeast(12.05, 16.0);
+				bufferDeviceAddressFeatures->bufferDeviceAddressCaptureReplay = false;
+				bufferDeviceAddressFeatures->bufferDeviceAddressMultiDevice = false;
+				break;
+			}
 			default:
 				break;
 		}
@@ -4115,7 +4122,10 @@
 	_enabledPortabilityFeatures(),
 	_enabledImagelessFramebufferFeatures(),
 	_enabledDynamicRenderingFeatures(),
-	_enabledSeparateDepthStencilLayoutsFeatures() {
+	_enabledSeparateDepthStencilLayoutsFeatures(),
+	_enabledFragmentShaderBarycentricFeatures(),
+	_enabledBufferDeviceAddressFeatures(),
+	_enabledBufferDeviceAddressFeaturesEXT() {
 
 		// If the physical device is lost, bail.
 	if (physicalDevice->getConfigurationResult() != VK_SUCCESS) {
@@ -4244,10 +4254,25 @@
 	mvkClear(&_enabledImagelessFramebufferFeatures);
 	mvkClear(&_enabledDynamicRenderingFeatures);
 	mvkClear(&_enabledSeparateDepthStencilLayoutsFeatures);
+	mvkClear(&_enabledFragmentShaderBarycentricFeatures);
+	mvkClear(&_enabledBufferDeviceAddressFeatures);
+	mvkClear(&_enabledBufferDeviceAddressFeaturesEXT);
+
+	VkPhysicalDeviceBufferDeviceAddressFeaturesEXT pdBufferDeviceAddressFeaturesEXT;
+	pdBufferDeviceAddressFeaturesEXT.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT;
+	pdBufferDeviceAddressFeaturesEXT.pNext = nullptr;
+
+	VkPhysicalDeviceBufferDeviceAddressFeatures pdBufferDeviceAddressFeatures;
+	pdBufferDeviceAddressFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES;
+	pdBufferDeviceAddressFeatures.pNext = &pdBufferDeviceAddressFeaturesEXT;
+
+	VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR pdFragmentShaderBarycentricFeatures;
+	pdFragmentShaderBarycentricFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_BARYCENTRIC_FEATURES_KHR;
+	pdFragmentShaderBarycentricFeatures.pNext = &pdBufferDeviceAddressFeatures;
 
 	VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures pdSeparateDepthStencilLayoutsFeatures;
 	pdSeparateDepthStencilLayoutsFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES;
-	pdSeparateDepthStencilLayoutsFeatures.pNext = nullptr;
+	pdSeparateDepthStencilLayoutsFeatures.pNext = &pdFragmentShaderBarycentricFeatures;
 
 	VkPhysicalDeviceDynamicRenderingFeatures pdDynamicRenderingFeatures;
 	pdDynamicRenderingFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES;
@@ -4466,6 +4491,27 @@
 							   &pdSeparateDepthStencilLayoutsFeatures.separateDepthStencilLayouts, 1);
 				break;
 			}
+			case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADER_BARYCENTRIC_FEATURES_KHR: {
+				auto* requestedFeatures = (VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR*)next;
+				enableFeatures(&_enabledFragmentShaderBarycentricFeatures.fragmentShaderBarycentric,
+							   &requestedFeatures->fragmentShaderBarycentric,
+							   &pdFragmentShaderBarycentricFeatures.fragmentShaderBarycentric, 1);
+				break;
+			}
+			case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES: {
+				auto* requestedFeatures = (VkPhysicalDeviceBufferDeviceAddressFeatures*)next;
+				enableFeatures(&_enabledBufferDeviceAddressFeatures.bufferDeviceAddress,
+							   &requestedFeatures->bufferDeviceAddress,
+							   &pdBufferDeviceAddressFeatures.bufferDeviceAddress, 3);
+				break;
+			}
+			case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_DEVICE_ADDRESS_FEATURES_EXT: {
+				auto* requestedFeatures = (VkPhysicalDeviceBufferDeviceAddressFeaturesEXT*)next;
+				enableFeatures(&_enabledBufferDeviceAddressFeaturesEXT.bufferDeviceAddress,
+							   &requestedFeatures->bufferDeviceAddress,
+							   &pdBufferDeviceAddressFeaturesEXT.bufferDeviceAddress, 3);
+				break;
+			}
 			default:
 				break;
 		}
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h b/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h
index 6906ea4..0966dd3 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h
@@ -165,7 +165,8 @@
 	id<MTLHeap> _mtlHeap = nil;
 	void* _pMemory = nullptr;
 	void* _pHostMemory = nullptr;
-	VkMemoryPropertyFlags _vkMemProps;
+	VkMemoryPropertyFlags _vkMemPropFlags;
+	VkMemoryAllocateFlags _vkMemAllocFlags;
 	MTLStorageMode _mtlStorageMode;
 	MTLCPUCacheMode _mtlCPUCacheMode;
 	bool _isDedicated = false;
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.mm
index a397e3c..154eb60 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.mm
@@ -57,7 +57,7 @@
 
 	// Coherent memory does not require flushing by app, so we must flush now
 	// to support Metal textures that actually reside in non-coherent memory.
-	if (mvkIsAnyFlagEnabled(_vkMemProps, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
+	if (mvkIsAnyFlagEnabled(_vkMemPropFlags, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
 		pullFromDevice(offset, size);
 	}
 
@@ -73,7 +73,7 @@
 
 	// Coherent memory does not require flushing by app, so we must flush now
 	// to support Metal textures that actually reside in non-coherent memory.
-	if (mvkIsAnyFlagEnabled(_vkMemProps, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
+	if (mvkIsAnyFlagEnabled(_vkMemPropFlags, VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) {
 		flushToDevice(_mappedRange.offset, _mappedRange.size);
 	}
 
@@ -277,9 +277,9 @@
 								 const VkMemoryAllocateInfo* pAllocateInfo,
 								 const VkAllocationCallbacks* pAllocator) : MVKVulkanAPIDeviceObject(device) {
 	// Set Metal memory parameters
-	_vkMemProps = _device->_pMemoryProperties->memoryTypes[pAllocateInfo->memoryTypeIndex].propertyFlags;
-	_mtlStorageMode = mvkMTLStorageModeFromVkMemoryPropertyFlags(_vkMemProps);
-	_mtlCPUCacheMode = mvkMTLCPUCacheModeFromVkMemoryPropertyFlags(_vkMemProps);
+	_vkMemPropFlags = _device->_pMemoryProperties->memoryTypes[pAllocateInfo->memoryTypeIndex].propertyFlags;
+	_mtlStorageMode = mvkMTLStorageModeFromVkMemoryPropertyFlags(_vkMemPropFlags);
+	_mtlCPUCacheMode = mvkMTLCPUCacheModeFromVkMemoryPropertyFlags(_vkMemPropFlags);
 
 	_allocationSize = pAllocateInfo->allocationSize;
 
@@ -315,6 +315,10 @@
 			case VK_STRUCTURE_TYPE_EXPORT_METAL_OBJECT_CREATE_INFO_EXT: {
 				const auto* pExportInfo = (VkExportMetalObjectCreateInfoEXT*)next;
 				willExportMTLBuffer = pExportInfo->exportObjectType == VK_EXPORT_METAL_OBJECT_TYPE_METAL_BUFFER_BIT_EXT;
+			}
+			case VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO: {
+				auto* pMemAllocFlagsInfo = (VkMemoryAllocateFlagsInfo*)next;
+				_vkMemAllocFlags = pMemAllocFlagsInfo->flags;
 				break;
 			}
 			default:
diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
index 4718594..54a3989 100644
--- a/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
+++ b/MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
@@ -649,6 +649,7 @@
 	ADD_DVC_EXT_ENTRY_POINT(vkGetSemaphoreCounterValueKHR, KHR_TIMELINE_SEMAPHORE);
 	ADD_DVC_EXT_ENTRY_POINT(vkSignalSemaphoreKHR, KHR_TIMELINE_SEMAPHORE);
 	ADD_DVC_EXT_ENTRY_POINT(vkWaitSemaphoresKHR, KHR_TIMELINE_SEMAPHORE);
+	ADD_DVC_EXT_ENTRY_POINT(vkGetBufferDeviceAddressEXT, EXT_BUFFER_DEVICE_ADDRESS);
 	ADD_DVC_EXT_ENTRY_POINT(vkDebugMarkerSetObjectTagEXT, EXT_DEBUG_MARKER);
 	ADD_DVC_EXT_ENTRY_POINT(vkDebugMarkerSetObjectNameEXT, EXT_DEBUG_MARKER);
 	ADD_DVC_EXT_ENTRY_POINT(vkCmdDebugMarkerBeginEXT, EXT_DEBUG_MARKER);
diff --git a/MoltenVK/MoltenVK/Layers/MVKExtensions.def b/MoltenVK/MoltenVK/Layers/MVKExtensions.def
index 51b08b1..604a8cf 100644
--- a/MoltenVK/MoltenVK/Layers/MVKExtensions.def
+++ b/MoltenVK/MoltenVK/Layers/MVKExtensions.def
@@ -44,7 +44,7 @@
 MVK_EXTENSION(KHR_16bit_storage,                   KHR_16BIT_STORAGE,                    DEVICE,   10.11,  8.0)
 MVK_EXTENSION(KHR_8bit_storage,                    KHR_8BIT_STORAGE,                     DEVICE,   10.11,  8.0)
 MVK_EXTENSION(KHR_bind_memory2,                    KHR_BIND_MEMORY_2,                    DEVICE,   10.11,  8.0)
-MVK_EXTENSION(KHR_buffer_device_address,           KHR_BUFFER_DEVICE_ADDRESS,            DEVICE,    13.0, 16.0)
+MVK_EXTENSION(KHR_buffer_device_address,           KHR_BUFFER_DEVICE_ADDRESS,            DEVICE,   12.05,  16.0)
 MVK_EXTENSION(KHR_create_renderpass2,              KHR_CREATE_RENDERPASS_2,              DEVICE,   10.11,  8.0)
 MVK_EXTENSION(KHR_dedicated_allocation,            KHR_DEDICATED_ALLOCATION,             DEVICE,   10.11,  8.0)
 MVK_EXTENSION(KHR_depth_stencil_resolve,           KHR_DEPTH_STENCIL_RESOLVE,            DEVICE,   10.11,  8.0)
@@ -85,6 +85,7 @@
 MVK_EXTENSION(KHR_timeline_semaphore,              KHR_TIMELINE_SEMAPHORE,               DEVICE,   10.11,  8.0)
 MVK_EXTENSION(KHR_uniform_buffer_standard_layout,  KHR_UNIFORM_BUFFER_STANDARD_LAYOUT,   DEVICE,   10.11,  8.0)
 MVK_EXTENSION(KHR_variable_pointers,               KHR_VARIABLE_POINTERS,                DEVICE,   10.11,  8.0)
+MVK_EXTENSION(EXT_buffer_device_address,           EXT_BUFFER_DEVICE_ADDRESS,            DEVICE,   12.05,  16.0)
 MVK_EXTENSION(EXT_debug_marker,                    EXT_DEBUG_MARKER,                     DEVICE,   10.11,  8.0)
 MVK_EXTENSION(EXT_debug_report,                    EXT_DEBUG_REPORT,                     INSTANCE, 10.11,  8.0)
 MVK_EXTENSION(EXT_debug_utils,                     EXT_DEBUG_UTILS,                      INSTANCE, 10.11,  8.0)
diff --git a/MoltenVK/MoltenVK/Vulkan/vulkan.mm b/MoltenVK/MoltenVK/Vulkan/vulkan.mm
index 3d6964f..58b6c27 100644
--- a/MoltenVK/MoltenVK/Vulkan/vulkan.mm
+++ b/MoltenVK/MoltenVK/Vulkan/vulkan.mm
@@ -2802,6 +2802,12 @@
 
 
 #pragma mark -
+#pragma mark VK_EXT_buffer_device_address extension
+
+MVK_PUBLIC_VULKAN_ALIAS(vkGetBufferDeviceAddressEXT, vkGetBufferDeviceAddressKHR);
+
+
+#pragma mark -
 #pragma mark VK_EXT_debug_report extension
 
 MVK_PUBLIC_VULKAN_SYMBOL VkResult vkCreateDebugReportCallbackEXT(