From 44b361390a9f3b1a37fe80ae31310bee3e1a7d35 Mon Sep 17 00:00:00 2001 From: Chip Davis Date: Sun, 19 Nov 2023 18:58:15 -0800 Subject: [PATCH] MVKDevice: Clamp max per-set descriptor limit to minimum 1024. As required by the Vulkan spec. Fixes the CTS tests `dEQP-VK.api.info.vulkan1p2_limits_validation.khr_maintenance_3` and `dEQP-VK.api.maintenance3_check.maintenance3_properties`. --- MoltenVK/MoltenVK/GPUObjects/MVKDevice.h | 1 + MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h index be9c08fb4..f40201cc9 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.h @@ -403,6 +403,7 @@ class MVKPhysicalDevice : public MVKDispatchableVulkanAPIObject { uint64_t getRecommendedMaxWorkingSetSize(); uint64_t getCurrentAllocatedSize(); uint32_t getMaxSamplerCount(); + uint32_t getMaxPerSetDescriptorCount(); void initExternalMemoryProperties(); void initExtensions(); void initCounterSets(); diff --git a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm index 0dd865f23..fe9a9f6a1 100644 --- a/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm +++ b/MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm @@ -525,9 +525,7 @@ supportedProps11.maxMultiviewViewCount = 32; supportedProps11.maxMultiviewInstanceIndex = canUseInstancingForMultiview() ? uintMax / 32 : uintMax; supportedProps11.protectedNoFault = false; - supportedProps11.maxPerSetDescriptors = 4 * (_metalFeatures.maxPerStageBufferCount + - _metalFeatures.maxPerStageTextureCount + - _metalFeatures.maxPerStageSamplerCount); + supportedProps11.maxPerSetDescriptors = getMaxPerSetDescriptorCount(); supportedProps11.maxMemoryAllocationSize = _metalFeatures.maxMTLBufferSize; // Create a SSOT for these Vulkan 1.2 properties, which can be queried via two mechanisms here. @@ -3146,6 +3144,13 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope } } +// Vulkan imposes a minimum maximum of 1024 descriptors per set. +uint32_t MVKPhysicalDevice::getMaxPerSetDescriptorCount() { + return max(4 * (_metalFeatures.maxPerStageBufferCount + + _metalFeatures.maxPerStageTextureCount + + _metalFeatures.maxPerStageSamplerCount), 1024u); +} + void MVKPhysicalDevice::initExternalMemoryProperties() { // Common @@ -3499,7 +3504,7 @@ static uint32_t mvkGetEntryProperty(io_registry_entry_t entry, CFStringRef prope for (uint32_t i = 0; i < pCreateInfo->bindingCount; i++) { descriptorCount += pCreateInfo->pBindings[i].descriptorCount; } - pSupport->supported = (descriptorCount < ((_physicalDevice->_metalFeatures.maxPerStageBufferCount + _physicalDevice->_metalFeatures.maxPerStageTextureCount + _physicalDevice->_metalFeatures.maxPerStageSamplerCount) * 2)); + pSupport->supported = (descriptorCount < _physicalDevice->getMaxPerSetDescriptorCount()); // Check whether the layout has a variable-count descriptor, and if so, whether we can support it. for (auto* next = (VkBaseOutStructure*)pSupport->pNext; next; next = next->pNext) {