From 6655beebd70ebb2085cab42ec9ffc5b5e2b0c950 Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Tue, 12 Jul 2022 12:35:50 -0400 Subject: [PATCH] Enhancements to recent extensions. - Update to latest SPIRV-Cross to support `SPV_KHR_physical_storage_buffer` for `VK_KHR_buffer_device_address` and `VK_EXT_buffer_device_address` - Add support for `VK_EXT_buffer_device_address` extension. - Advertise support for `VK_KHR_buffer_device_address` and `VK_EXT_buffer_device_address` on macOS 12.5. - Add appropriate extension reporting and enablement for `VkPhysicalDeviceBufferDeviceAddressFeatures`, `VkPhysicalDeviceBufferDeviceAddressFeaturesEXT`, and `VkPhysicalDeviceFragmentShaderBarycentricFeaturesKHR`. - Support reading `VkMemoryAllocateFlagsInfo` to identify memory allocations that need to support buffer pointer access (in case needed in future on non-shared memory). - Update `Whats_New.md` and `MoltenVK_Runtime_UserGuide` documents. --- Docs/MoltenVK_Runtime_UserGuide.md | 2 + Docs/Whats_New.md | 2 + ExternalRevisions/SPIRV-Cross_repo_revision | 2 +- MoltenVK/MoltenVK/GPUObjects/MVKDevice.h | 3 + MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 56 +++++++++++++++++-- .../MoltenVK/GPUObjects/MVKDeviceMemory.h | 3 +- .../MoltenVK/GPUObjects/MVKDeviceMemory.mm | 14 +++-- MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm | 1 + MoltenVK/MoltenVK/Layers/MVKExtensions.def | 3 +- MoltenVK/MoltenVK/Vulkan/vulkan.mm | 6 ++ 10 files changed, 79 insertions(+), 13 deletions(-) diff --git a/Docs/MoltenVK_Runtime_UserGuide.md b/Docs/MoltenVK_Runtime_UserGuide.md index b7f572d71..b82aa34eb 100644 --- a/Docs/MoltenVK_Runtime_UserGuide.md +++ b/Docs/MoltenVK_Runtime_UserGuide.md @@ -263,6 +263,7 @@ In addition to core *Vulkan* functionality, **MoltenVK** also supports the foll - `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 @@ In addition to core *Vulkan* functionality, **MoltenVK** also supports the foll - `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 e3b968323..f432400e8 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -20,11 +20,13 @@ Released TBD - 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 6a4e7767d..33777a7b7 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 9989a698d..7de4a7989 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h @@ -794,6 +794,9 @@ class MVKDevice : public MVKDispatchableVulkanAPIObject { 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 f3c6a3c0c..48db2d043 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 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope _enabledPortabilityFeatures(), _enabledImagelessFramebufferFeatures(), _enabledDynamicRenderingFeatures(), - _enabledSeparateDepthStencilLayoutsFeatures() { + _enabledSeparateDepthStencilLayoutsFeatures(), + _enabledFragmentShaderBarycentricFeatures(), + _enabledBufferDeviceAddressFeatures(), + _enabledBufferDeviceAddressFeaturesEXT() { // If the physical device is lost, bail. if (physicalDevice->getConfigurationResult() != VK_SUCCESS) { @@ -4244,10 +4254,25 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope 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 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope &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 6906ea442..0966dd356 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h @@ -165,7 +165,8 @@ class MVKDeviceMemory : public MVKVulkanAPIDeviceObject { id _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 a397e3ced..154eb60ad 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 471859451..54a398919 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 51b08b1a7..604a8cfed 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_swapchain_mutable_format, KHR_SWAPCHAIN_MUTABLE_FORMAT, 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 3d6964f09..58b6c279e 100644 --- a/MoltenVK/MoltenVK/Vulkan/vulkan.mm +++ b/MoltenVK/MoltenVK/Vulkan/vulkan.mm @@ -2801,6 +2801,12 @@ MVK_PUBLIC_VULKAN_SYMBOL VkResult vkWaitSemaphoresKHR( } +#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