From 1bad27cf26a37cf10cb9eedcf40747007dc61a4d Mon Sep 17 00:00:00 2001 From: Bill Hollings Date: Thu, 5 May 2022 15:55:26 -0400 Subject: [PATCH] Add support for VK_KHR_separate_depth_stencil_layouts extension. Add VK_KHR_separate_depth_stencil_layouts and enable its features. Metal generally ignores image layouts, so nothing further needed. Update Whats_New.md and MoltenVK_Runtime_UserGuide.md documents with recently-added extensions. Passes almost all supported separate_layouts CTS tests, with the few remaining tests failing due to issues with unrelated capabilities. Unrelated cleanup: - MVKDevice enable extensions before features. - MVKDevice reorder ivar declarations to reduce memory layout gaps, and define default values. - Rename VkSemaphoreStyle to MVKSemaphoreStyle to remove potential conflicts with Vulkan Vk name space. --- Docs/MoltenVK_Runtime_UserGuide.md | 3 ++ Docs/Whats_New.md | 1 + MoltenVK/MoltenVK/GPUObjects/MVKDevice.h | 37 ++++++++++--------- MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 43 +++++++++++++++------- MoltenVK/MoltenVK/Layers/MVKExtensions.def | 1 + 5 files changed, 54 insertions(+), 31 deletions(-) diff --git a/Docs/MoltenVK_Runtime_UserGuide.md b/Docs/MoltenVK_Runtime_UserGuide.md index 2f87262b..ca1c4364 100644 --- a/Docs/MoltenVK_Runtime_UserGuide.md +++ b/Docs/MoltenVK_Runtime_UserGuide.md @@ -270,6 +270,7 @@ In addition to core *Vulkan* functionality, **MoltenVK** also supports the foll - `VK_KHR_device_group` - `VK_KHR_device_group_creation` - `VK_KHR_driver_properties` +- `VK_KHR_dynamic_rendering` - `VK_KHR_get_memory_requirements2` - `VK_KHR_get_physical_device_properties2` - `VK_KHR_get_surface_capabilities2` @@ -284,6 +285,7 @@ In addition to core *Vulkan* functionality, **MoltenVK** also supports the foll - `VK_KHR_relaxed_block_layout` - `VK_KHR_sampler_mirror_clamp_to_edge` *(requires a Mac GPU or Apple family 7 GPU)* - `VK_KHR_sampler_ycbcr_conversion` +- `VK_KHR_separate_depth_stencil_layouts` - `VK_KHR_shader_draw_parameters` - `VK_KHR_shader_float16_int8` - `VK_KHR_shader_subgroup_extended_types` *(requires Metal 2.1 on Mac or Metal 2.2 and Apple family 4 on iOS)* @@ -309,6 +311,7 @@ In addition to core *Vulkan* functionality, **MoltenVK** also supports the foll - `VK_EXT_robustness2` - `VK_EXT_sample_locations` - `VK_EXT_scalar_block_layout` +- `VK_EXT_separate_stencil_usage` - `VK_EXT_shader_stencil_export` *(requires Mac GPU family 2 or iOS GPU family 5)* - `VK_EXT_shader_viewport_index_layer` - `VK_EXT_subgroup_size_control` *(requires Metal 2.1 on Mac or Metal 2.2 and Apple family 4 on iOS)* diff --git a/Docs/Whats_New.md b/Docs/Whats_New.md index 2718328d..3e118946 100644 --- a/Docs/Whats_New.md +++ b/Docs/Whats_New.md @@ -23,6 +23,7 @@ Released TBD updated to indicate the impact of the `VK_KHR_portability_enumeration` extension during runtime loading on *macOS* via the *Vulkan Loader*. - `VK_KHR_dynamic_rendering` + - `VK_KHR_separate_depth_stencil_layouts` - `VK_EXT_separate_stencil_usage` - Fix error where previously bound push constants can override a descriptor buffer binding used by a subsequent pipeline that does not use push constants. diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h index 42804ed0..63b6e189 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h @@ -429,6 +429,12 @@ typedef struct MVKMTLBlitEncoder { id mtlCmdBuffer = nil; } MVKMTLBlitEncoder; +typedef enum { + MVKSemaphoreStyleUseMTLEvent, + MVKSemaphoreStyleUseMTLFence, + MVKSemaphoreStyleUseEmulation +} MVKSemaphoreStyle; + /** Represents a Vulkan logical GPU device, associated with a physical device. */ class MVKDevice : public MVKDispatchableVulkanAPIObject { @@ -762,6 +768,9 @@ public: #pragma mark Properties directly accessible + /** The list of Vulkan extensions, indicating whether each has been enabled by the app for this device. */ + const MVKExtensionList _enabledExtensions; + /** Device features available and enabled. */ const VkPhysicalDeviceFeatures _enabledFeatures; const VkPhysicalDevice16BitStorageFeatures _enabledStorage16Features; @@ -781,9 +790,7 @@ public: const VkPhysicalDevicePortabilitySubsetFeaturesKHR _enabledPortabilityFeatures; const VkPhysicalDeviceImagelessFramebufferFeaturesKHR _enabledImagelessFramebufferFeatures; const VkPhysicalDeviceDynamicRenderingFeatures _enabledDynamicRenderingFeatures; - - /** The list of Vulkan extensions, indicating whether each has been enabled by the app for this device. */ - const MVKExtensionList _enabledExtensions; + const VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures _enabledSeparateDepthStencilLayoutsFeatures; /** Pointer to the Metal-specific features of the underlying physical device. */ const MVKPhysicalDeviceMetalFeatures* _pMetalFeatures; @@ -858,21 +865,15 @@ protected: std::mutex _rezLock; std::mutex _sem4Lock; std::mutex _perfLock; - id _globalVisibilityResultMTLBuffer; - id _defaultMTLSamplerState; - id _dummyBlitMTLBuffer; - uint32_t _globalVisibilityQueryCount; - std::mutex _vizLock; - bool _logActivityPerformanceInline; - bool _isPerformanceTracking; - bool _isCurrentlyAutoGPUCapturing; - - typedef enum { - VkSemaphoreStyleUseMTLEvent, - VkSemaphoreStyleUseMTLFence, - VkSemaphoreStyleUseEmulation - } VkSemaphoreStyle; - VkSemaphoreStyle _vkSemaphoreStyle; + std::mutex _vizLock; + id _globalVisibilityResultMTLBuffer = nil; + id _defaultMTLSamplerState = nil; + id _dummyBlitMTLBuffer = nil; + MVKSemaphoreStyle _vkSemaphoreStyle = MVKSemaphoreStyleUseEmulation; + uint32_t _globalVisibilityQueryCount = 0; + bool _logActivityPerformanceInline = false; + bool _isPerformanceTracking = false; + bool _isCurrentlyAutoGPUCapturing = false; }; diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 520a4644..88ef958e 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -282,6 +282,11 @@ void MVKPhysicalDevice::getFeatures(VkPhysicalDeviceFeatures2* features) { dynamicRenderingFeatures->dynamicRendering = true; break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES: { + auto* separateDepthStencilLayoutsFeatures = (VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures*)next; + separateDepthStencilLayoutsFeatures->separateDepthStencilLayouts = true; + break; + } default: break; } @@ -3327,9 +3332,9 @@ MVKSemaphore* MVKDevice::createSemaphore(const VkSemaphoreCreateInfo* pCreateInf } } else { switch (_vkSemaphoreStyle) { - case VkSemaphoreStyleUseMTLEvent: return new MVKSemaphoreMTLEvent(this, pCreateInfo); - case VkSemaphoreStyleUseMTLFence: return new MVKSemaphoreMTLFence(this, pCreateInfo); - case VkSemaphoreStyleUseEmulation: return new MVKSemaphoreEmulated(this, pCreateInfo); + case MVKSemaphoreStyleUseMTLEvent: return new MVKSemaphoreMTLEvent(this, pCreateInfo); + case MVKSemaphoreStyleUseMTLFence: return new MVKSemaphoreMTLFence(this, pCreateInfo); + case MVKSemaphoreStyleUseEmulation: return new MVKSemaphoreEmulated(this, pCreateInfo); } } } @@ -3981,10 +3986,10 @@ MVKDevice::MVKDevice(MVKPhysicalDevice* physicalDevice, const VkDeviceCreateInfo _enabledPortabilityFeatures(), _enabledImagelessFramebufferFeatures(), _enabledDynamicRenderingFeatures(), - _enabledExtensions(this), - _isCurrentlyAutoGPUCapturing(false) -{ - // If the physical device is lost, bail. + _enabledSeparateDepthStencilLayoutsFeatures(), + _enabledExtensions(this) { + + // If the physical device is lost, bail. if (physicalDevice->getConfigurationResult() != VK_SUCCESS) { setConfigurationResult(physicalDevice->getConfigurationResult()); return; @@ -3992,8 +3997,8 @@ MVKDevice::MVKDevice(MVKPhysicalDevice* physicalDevice, const VkDeviceCreateInfo initPerformanceTracking(); initPhysicalDevice(physicalDevice, pCreateInfo); - enableFeatures(pCreateInfo); enableExtensions(pCreateInfo); + enableFeatures(pCreateInfo); initQueues(pCreateInfo); reservePrivateData(pCreateInfo); @@ -4075,15 +4080,15 @@ void MVKDevice::initPhysicalDevice(MVKPhysicalDevice* physicalDevice, const VkDe 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); + _vkSemaphoreStyle = canUseMTLEventForSem4 ? MVKSemaphoreStyleUseMTLEvent : (canUseMTLFenceForSem4 ? MVKSemaphoreStyleUseMTLFence : MVKSemaphoreStyleUseEmulation); switch (_vkSemaphoreStyle) { - case VkSemaphoreStyleUseMTLEvent: + case MVKSemaphoreStyleUseMTLEvent: MVKLogInfo("Using MTLEvent for Vulkan semaphores."); break; - case VkSemaphoreStyleUseMTLFence: + case MVKSemaphoreStyleUseMTLFence: MVKLogInfo("Using MTLFence for Vulkan semaphores."); break; - case VkSemaphoreStyleUseEmulation: + case MVKSemaphoreStyleUseEmulation: MVKLogInfo("Using emulation for Vulkan semaphores."); break; } @@ -4110,10 +4115,15 @@ void MVKDevice::enableFeatures(const VkDeviceCreateInfo* pCreateInfo) { mvkClear(&_enabledPortabilityFeatures); mvkClear(&_enabledImagelessFramebufferFeatures); mvkClear(&_enabledDynamicRenderingFeatures); + mvkClear(&_enabledSeparateDepthStencilLayoutsFeatures); + + VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures pdSeparateDepthStencilLayoutsFeatures; + pdSeparateDepthStencilLayoutsFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES; + pdSeparateDepthStencilLayoutsFeatures.pNext = nullptr; VkPhysicalDeviceDynamicRenderingFeatures pdDynamicRenderingFeatures; pdDynamicRenderingFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_FEATURES; - pdDynamicRenderingFeatures.pNext = NULL; + pdDynamicRenderingFeatures.pNext = &pdSeparateDepthStencilLayoutsFeatures; VkPhysicalDeviceImagelessFramebufferFeaturesKHR pdImagelessFramebufferFeatures; pdImagelessFramebufferFeatures.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_IMAGELESS_FRAMEBUFFER_FEATURES; @@ -4321,6 +4331,13 @@ void MVKDevice::enableFeatures(const VkDeviceCreateInfo* pCreateInfo) { &pdDynamicRenderingFeatures.dynamicRendering, 1); break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SEPARATE_DEPTH_STENCIL_LAYOUTS_FEATURES: { + auto* requestedFeatures = (VkPhysicalDeviceSeparateDepthStencilLayoutsFeatures*)next; + enableFeatures(&_enabledSeparateDepthStencilLayoutsFeatures.separateDepthStencilLayouts, + &requestedFeatures->separateDepthStencilLayouts, + &pdSeparateDepthStencilLayoutsFeatures.separateDepthStencilLayouts, 1); + break; + } default: break; } diff --git a/MoltenVK/MoltenVK/Layers/MVKExtensions.def b/MoltenVK/MoltenVK/Layers/MVKExtensions.def index b0ae8306..019b23b4 100644 --- a/MoltenVK/MoltenVK/Layers/MVKExtensions.def +++ b/MoltenVK/MoltenVK/Layers/MVKExtensions.def @@ -72,6 +72,7 @@ MVK_EXTENSION(KHR_push_descriptor, KHR_PUSH_DESCRIPTOR, MVK_EXTENSION(KHR_relaxed_block_layout, KHR_RELAXED_BLOCK_LAYOUT, DEVICE, 10.11, 8.0) MVK_EXTENSION(KHR_sampler_mirror_clamp_to_edge, KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE, DEVICE, 10.11, 14.0) MVK_EXTENSION(KHR_sampler_ycbcr_conversion, KHR_SAMPLER_YCBCR_CONVERSION, DEVICE, 10.11, 8.0) +MVK_EXTENSION(KHR_separate_depth_stencil_layouts, KHR_SEPARATE_DEPTH_STENCIL_LAYOUTS, DEVICE, 10.11, 8.0) MVK_EXTENSION(KHR_shader_draw_parameters, KHR_SHADER_DRAW_PARAMETERS, DEVICE, 10.11, 8.0) MVK_EXTENSION(KHR_shader_float16_int8, KHR_SHADER_FLOAT16_INT8, DEVICE, 10.11, 8.0) MVK_EXTENSION(KHR_shader_subgroup_extended_types, KHR_SHADER_SUBGROUP_EXTENDED_TYPES, DEVICE, 10.14, 13.0)