Skip to content

Commit

Permalink
Enhancements to recent extensions.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
billhollings committed Jul 12, 2022
1 parent ba183b4 commit 6655bee
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 13 deletions.
2 changes: 2 additions & 0 deletions Docs/MoltenVK_Runtime_UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions Docs/Whats_New.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------------

Expand Down
2 changes: 1 addition & 1 deletion ExternalRevisions/SPIRV-Cross_repo_revision
Original file line number Diff line number Diff line change
@@ -1 +1 @@
50b4d5389b6a06f86fb63a2848e1a7da6d9755ca
d8d051381f65b9606fb8016c79b7c3bab872eec3
3 changes: 3 additions & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
56 changes: 51 additions & 5 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);

This comment has been minimized.

Copy link
@spnda

spnda Jul 13, 2022

Collaborator

@billhollings This is NOT the correct way to do this. Devices ranging from the A11 to the A12 are able to upgrade to iOS 16, yet do not support Metal 3 and therefore can't support bufferDeviceAddress. This was the issue regarding my comment in the original PR for KHR_buffer_device_address. We should instead check for [mtlDevice supportsFamily:MTLGPUFamilyMetal3] to enable these extensions and their features.

This comment has been minimized.

Copy link
@billhollings

billhollings Jul 14, 2022

Author Contributor

Metal 3 is a broad marker, and I'm concerned that testing for it may be too restrictive in this case.

Pointers have existed in MSL for a while now. From what I can tell, the missing ingredient was [MTLBuffer gpuAddress], which is an API capability, independent of MSL, and it is possible that it might be supported on a broader range of SoC's than those that support the full Metal 3 feature set.

What components of Metal 3 are in play for this feature that you are concerned won't be working? And is there documentation to indicate that they won't be supported? I haven't seen any applicable documentation for gpuAddress yet. During beta phase, it might be worth waiting to see results from different SoC's the wild.

This comment has been minimized.

Copy link
@billhollings

billhollings Jul 14, 2022

Author Contributor

Metal 3 is a broad marker, and I'm concerned that testing for it may be too restrictive in this case.

Pointers have existed in MSL for a while now. From what I can tell, the missing ingredient was [MTLBuffer gpuAddress], which is an API capability, independent of MSL, and it is possible that it might be supported on a broader range of SoC's than those that support the full Metal 3 feature set.

What components of Metal 3 are in play for this feature that you are concerned won't be working? And is there documentation to indicate that they won't be supported? I haven't seen any applicable documentation for gpuAddress yet. During beta phase, it might be worth waiting to see results from different SoC's the wild.

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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ class MVKDeviceMemory : public MVKVulkanAPIDeviceObject {
id<MTLHeap> _mtlHeap = nil;
void* _pMemory = nullptr;
void* _pHostMemory = nullptr;
VkMemoryPropertyFlags _vkMemProps;
VkMemoryPropertyFlags _vkMemPropFlags;
VkMemoryAllocateFlags _vkMemAllocFlags;
MTLStorageMode _mtlStorageMode;
MTLCPUCacheMode _mtlCPUCacheMode;
bool _isDedicated = false;
Expand Down
14 changes: 9 additions & 5 deletions MoltenVK/MoltenVK/GPUObjects/MVKDeviceMemory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKInstance.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion MoltenVK/MoltenVK/Layers/MVKExtensions.def
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions MoltenVK/MoltenVK/Vulkan/vulkan.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6655bee

Please sign in to comment.