Skip to content

Commit

Permalink
Merge pull request #2073 from cdavis5e/min-max-descriptor-count
Browse files Browse the repository at this point in the history
MVKDevice: Clamp max per-set descriptor limit to minimum 1024.
  • Loading branch information
billhollings committed Nov 23, 2023
2 parents 88c9176 + 44b3613 commit 645aaa4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 9 additions & 4 deletions MoltenVK/MoltenVK/GPUObjects/MVKDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -3150,6 +3148,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
Expand Down Expand Up @@ -3507,7 +3512,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) {
Expand Down

0 comments on commit 645aaa4

Please sign in to comment.