Vulkan issue with creating descriptor sets

Started by darkyellow, June 21, 2019, 13:31:14

Previous topic - Next topic

darkyellow

Hi

I am having an issue when creating descriptor sets, it could be due to the way I use the buffers in lwjgl

In my example, I have 3 swap chains

Method 1 (This doesn't work)

        VkDescriptorSetAllocateInfo createInfoDescriptorSetAllocate = VkDescriptorSetAllocateInfo.calloc();
        createInfoDescriptorSetAllocate.sType(VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO);
        createInfoDescriptorSetAllocate.descriptorPool(descriptorPool.getDescriptorPool());
        createInfoDescriptorSetAllocate.pSetLayouts(uniformDescriptorSetLayout);

        uniformDescriptorSet = memAllocLong((int) swapChain.getSize());

        errorCheck("Error allocating descriptor sets for uniform buffers.", vkAllocateDescriptorSets(logicalDevice.getLogicalDevice(), createInfoDescriptorSetAllocate, uniformDescriptorSet));


Using this method I get the below validation error when trying to write to the 2nd and 3rd descriptor set

21/06/2019 02:24:53.667 [DEBUG] [org.myapp.application.lwjgl.vulkan.VulkanDebug$1.invoke()] [VULKAN DEBUG CALLBACK][ERROR][VALIDATION] Invalid DescriptorSet Object 0x7fc2d40000d0. The Vulkan spec states: dstSet must be a valid VkDescriptorSet handle (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkWriteDescriptorSet-dstSet-00320)
21/06/2019 02:24:53.667 [DEBUG] [org.myapp.application.lwjgl.vulkan.VulkanDebug$1.invoke()] [VULKAN DEBUG CALLBACK][ERROR][VALIDATION] Invalid DescriptorSet Object 0x7fc231582b50. The Vulkan spec states: dstSet must be a valid VkDescriptorSet handle (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkWriteDescriptorSet-dstSet-00320)

        for (Buffer uniformBuffer : getUniformBindings())
        {
            for (int i = 0; i < swapChain.getSize(); i++)
            {
                createInfoDescriptorBuffer.get(0)
                        .buffer(uniformBuffer.getId(i))
                        .offset(0)
                        .range(uniformBuffer.getSize());
                shaderWriteDescriptorSet.get(overallCounter++)
                        .sType(VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET)
                        .dstSet(uniformDescriptorSet.get(i))
                        .dstBinding(uniformBuffer.getBinding())
                        .dstArrayElement(0)
                        .descriptorType(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER)
                        .pBufferInfo(createInfoDescriptorBuffer)
                        .pImageInfo(null)
                        .pTexelBufferView(null);
            }
        }

        vkUpdateDescriptorSets(logicalDevice, shaderWriteDescriptorSet, null);


Method 2 (This works)

This time create the descriptor sets one at a time

        uniformDescriptorSet = memAllocLong((int) swapChain.getSize());

        LongBuffer tempUiformDescriptorSet = memAllocLong(1);

        for (int i = 0; i < swapChain.getSize(); i++)
        {
            VkDescriptorSetAllocateInfo createInfoDescriptorSetAllocate = VkDescriptorSetAllocateInfo.calloc();
            createInfoDescriptorSetAllocate.sType(VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO);
            createInfoDescriptorSetAllocate.descriptorPool(descriptorPool.getDescriptorPool());
            createInfoDescriptorSetAllocate.pSetLayouts(uniformDescriptorSetLayout);

            errorCheck("Error allocating descriptor sets for uniform buffers.", vkAllocateDescriptorSets(logicalDevice.getLogicalDevice(), createInfoDescriptorSetAllocate, tempUiformDescriptorSet));
            uniformDescriptorSet.put(i,tempUiformDescriptorSet.get(0));
        }


Using the same code to write to the descriptor this setup works with no validation errors on the dstset issue


Do you know if this is a bug or if I have missed somerthing obvious?

KaiHH

The number of descriptor sets allocated by `vkAllocateDescriptorSets()` is determined by the remaining buffer count of the `LongBuffer` set as the `pSetLayouts` member in the `VkDescriptorSetAllocateInfo` struct given to the `vkAllocateDescriptorSets()` call as the second argument. That means you need to repeat the pipeline descriptor set layout `N` times in a LongBuffer given to `pSetLayouts` if you want `vkAllocateDescriptorSets()` to allocate `N` sets for this same pipeline descriptor set layout.

darkyellow

Thanks Kai. That makes sense with the way you have described it.