From 42823e5dc1f1fbf8ec734065a50e8d8790ce013f Mon Sep 17 00:00:00 2001 From: Karen Webb Date: Wed, 15 Jan 2025 13:07:41 +0000 Subject: [PATCH] layers: Add warning if allocated descriptors exceeds pool max --- layers/best_practices/bp_descriptor.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/layers/best_practices/bp_descriptor.cpp b/layers/best_practices/bp_descriptor.cpp index b87475da9e3..c829a0ca1a2 100644 --- a/layers/best_practices/bp_descriptor.cpp +++ b/layers/best_practices/bp_descriptor.cpp @@ -50,6 +50,22 @@ bool BestPractices::PreCallValidateAllocateDescriptorSets(VkDevice device, const ". This pool only has %" PRIu32 " descriptorSets remaining.", pAllocateInfo->descriptorSetCount, FormatHandle(*pool_state).c_str(), pool_state->GetAvailableSets()); } + auto ads_pool_state = Get(pAllocateInfo->descriptorPool); + for (auto it = ads_state_data.required_descriptors_by_type.begin(); it != ads_state_data.required_descriptors_by_type.end(); + ++it) { + auto available_count = ads_pool_state->GetAvailableCount(it->first); + + if (ads_state_data.required_descriptors_by_type.at(it->first) > available_count) { + skip |= LogWarning("BestPractices-VkDescriptorSetAllocateInfo-EmptyDescriptorPoolType", ads_pool_state->Handle(), + error_obj.location, + "Unable to allocate %" PRIu32 + " descriptors of type %s from %s" + ". This pool only has %" PRIu32 " descriptors of this type remaining.", + ads_state_data.required_descriptors_by_type.at(it->first), + string_VkDescriptorType(VkDescriptorType(it->first)), FormatHandle(*ads_pool_state).c_str(), + available_count); + } + } } return skip; @@ -74,8 +90,7 @@ void BestPractices::ManualPostCallRecordAllocateDescriptorSets(VkDevice device, void BestPractices::PostCallRecordFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, uint32_t descriptorSetCount, const VkDescriptorSet* pDescriptorSets, const RecordObject& record_obj) { - BaseClass::PostCallRecordFreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets, - record_obj); + BaseClass::PostCallRecordFreeDescriptorSets(device, descriptorPool, descriptorSetCount, pDescriptorSets, record_obj); if (record_obj.result == VK_SUCCESS) { // we want to track frees because we're interested in suggesting re-use if (auto pool_state = Get(descriptorPool)) {