public unsafe DescriptorSets(Api api, DescriptorPool descriptorPool, DescriptorSetLayout layout, Dictionary <uint, DescriptorType> bindingTypes, ulong size)
        {
            (_api, _descriptorPool, _bindingTypes) = (api, descriptorPool, bindingTypes);

            Span <VkDescriptorSetLayout> layouts = stackalloc VkDescriptorSetLayout[(int)size];

            for (int i = 0; i < layouts.Length; i++)
            {
                layouts[i] = layout.VkDescriptorSetLayout;
            }

            var allocInfo = new DescriptorSetAllocateInfo();

            allocInfo.SType              = StructureType.DescriptorSetAllocateInfo;
            allocInfo.DescriptorPool     = descriptorPool.VkDescriptorPool;
            allocInfo.DescriptorSetCount = (uint)size;
            allocInfo.PSetLayouts        = (VkDescriptorSetLayout *)Unsafe.AsPointer(ref layouts[0]);

            _vkDescriptorSets = new DescriptorSet[(int)size];

            fixed(DescriptorSet *pDescriptorSets = &_vkDescriptorSets[0])
            {
                Util.Verify(
                    _api.Vk.AllocateDescriptorSets(_api.Device.VkDevice, allocInfo, pDescriptorSets),
                    $"{nameof(descriptorPool)}: Cannot allocate descriptor sets");
            }
        }
        public DescriptorSetManager(Api api, DescriptorBinding[] descriptorBindings, ulong maxSets)
        {
            // Sanity check to avoid binding different resources to the same binding point.
            Dictionary <uint, DescriptorType> bindingTypes = new Dictionary <uint, DescriptorType>(descriptorBindings.Length);

            foreach (var binding in descriptorBindings)
            {
                if (bindingTypes.TryAdd(binding.Binding, binding.Type) == false)
                {
                    throw new Exception($"{nameof(DescriptorSetManager)}: Binding collision");
                }
            }

            _descriptorPool      = new DescriptorPool(api, descriptorBindings, maxSets);
            _descriptorSetLayout = new DescriptorSetLayout(api, descriptorBindings);
            _descriptorSets      = new DescriptorSets(api, _descriptorPool, _descriptorSetLayout, bindingTypes, maxSets);
        }