Hello, while writing a Vulkan descriptor pool class, during some testing I realized I was able to allocate from pools which I explicitly told to not have those resources.
Example:
- Create a pool with 1 uniform buffer descriptor
- Allocate a sampler descriptor with this pool
- It works (while it shouldn’t)
bool DescriptorPoolVulkan::Create(const vk::Device aDevice,
uint32_t iMaxSets,
uint32_t iCombinedImgSamplerCount,
uint32_t iSamplerCount,
uint32_t iUniformBufferCount,
uint32_t iSampledImgCount)
{
if (hasInitialized)
{
LOG(ERROR) << "DescriptorPoolVulkan::Create User attempted to create pool, pool already has been created";
return false;
}
std::array<vk::DescriptorPoolSize, 4> type_count;
// Initialize our pool with these values
type_count[0].type = vk::DescriptorType::eCombinedImageSampler;
type_count[0].descriptorCount = iCombinedImgSamplerCount;
type_count[1].type = vk::DescriptorType::eSampler;
type_count[1].descriptorCount = iSamplerCount;
type_count[2].type = vk::DescriptorType::eUniformBuffer;
type_count[2].descriptorCount = iUniformBufferCount;
type_count[3].type = vk::DescriptorType::eSampledImage;
type_count[3].descriptorCount = iSampledImgCount;
vk::DescriptorPoolCreateInfo createInfo = vk::DescriptorPoolCreateInfo()
.setPNext(nullptr)
.setMaxSets(iMaxSets)
.setPoolSizeCount(1)
.setPPoolSizes(type_count.data());
pool = aDevice.createDescriptorPool(createInfo);
return true;
}
vk::DescriptorSetAllocateInfo alloc_info = {};
alloc_info.pNext = NULL;
alloc_info.setDescriptorPool(pool);
alloc_info.setDescriptorSetCount(iNumToAllocate);
alloc_info.setPSetLayouts(&iDescriptorLayouts);
std::vector<vk::DescriptorSet> tDescriptors;
tDescriptors.resize(iNumToAllocate);
// Allocate descriptors if all is well
if (iDevice.allocateDescriptorSets(&alloc_info, tDescriptors.data()) == vk::Result::eSuccess)
{
LOG(INFO) << "DescriptorPoolVulkan::AllocateDescriptorSet Allocated set!";
}