LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.67k stars 631 forks source link

Is it possible to create multiple DescripotrSetLayouts? #783

Closed Vqlf closed 1 year ago

Vqlf commented 1 year ago

Question

Is it intended, that the VkDescriptorSetLayoutCreateInfo struct blocks sType entries after already having created one because I want to create a second DescripotrSetLayout but the validation layer give me this message: Validation Error: [ VUID-VkDescriptorSetLayoutCreateInfo-sType-sType ] Object 0: handle = 0x1b73c0eb320, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x3cc1e4ad | vkCreateDescriptorSetLayout: parameter pCreateInfo->sType must be VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO. The Vulkan spec states: sType must be VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO (https://vulkan.lunarg.com/doc/view/1.3.211.0/windows/1.3-extensions/vkspec.html#VUID-VkDescriptorSetLayoutCreateInfo-sType-sType). This is very weird because in C/C++ it's possible to create multiple DescripotrSetLayouts.

httpdigest commented 1 year ago

The VkDescriptorSetLayoutCreateInfo struct does not "block" anything and does not reset anything to any other value after the call to vkCreateDescriptorSetLayout. And neither does vkCreateDescriptorSetLayout mutate the memory/state of the supplied VkDescriptorSetLayoutCreateInfo instance.

If you did set the sType member for the second call correctly, then the issue is very likely a memory management issue, where you might have allocated the VkDescriptorSetLayoutCreateInfo via memory (such as from MemoryStack) that got reused/overwritten between the first and second call.

Vqlf commented 1 year ago

Then which method of allocation should be used to intialize the struct while also avoiding such reused/overwritten memory? Because .create doesn't fixes the issue either.

Vqlf commented 1 year ago

Ok, I tried to initialize the struct by using malloc and now there's an additional error: Validation Error: [ VUID-VkDescriptorSetLayoutCreateInfo-pNext-pNext ] Object 0: handle = 0x1bf4ef73460, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x2b747b43 | vkCreateDescriptorSetLayout: pCreateInfo->pNext chain includes a structure with unknown VkStructureType (1666187265); Allowed structures are [VkDescriptorSetLayoutBindingFlagsCreateInfo, VkMutableDescriptorTypeCreateInfoVALVE]. This error is based on the Valid Usage documentation for version 211 of the Vulkan header. It is possible that you are using a struct from a private extension or an extension that was added to a later version of the Vulkan header, in which case the use of pCreateInfo->pNext is undefined and may not work correctly with validation enabled The Vulkan spec states: Each pNext member of any structure (including this one) in the pNext chain must be either NULL or a pointer to a valid instance of VkDescriptorSetLayoutBindingFlagsCreateInfo or VkMutableDescriptorTypeCreateInfoVALVE (https://vulkan.lunarg.com/doc/view/1.3.211.0/windows/1.3-extensions/vkspec.html#VUID-VkDescriptorSetLayoutCreateInfo-pNext-pNext)

httpdigest commented 1 year ago

Without seeing your actual code to have a minimal, complete and verifiable example, it is quite impossible to tell you why your code shows that behaviour. You should create a minimal, complete and verifiable example (MCVE) that is minimal and exhibits the same erroneous behaviour. All I can say from here (without seeing your code) is that LWJGL is not at fault. I've been using the Vulkan bindings very extensively and haven't yet had any such problems. Your code is at fault here, but we cannot say exactly how, without your code.

Vqlf commented 1 year ago

Ok thank you for that information. Heres the code for creating the DescriptorSetLayout:

DescripotrSetLayout code

Do you need more core like the DescriptorPool creation code?

httpdigest commented 1 year ago

You are using malloc which does not zero-out the memory! Change that to calloc and you should be fine.

Vqlf commented 1 year ago

Changed that but it still does not work

httpdigest commented 1 year ago

Show you code. I cannot help you without seeing the now actual code...

httpdigest commented 1 year ago

And for the love of god... don't use screenshots of your IDE... Use code tags.

Vqlf commented 1 year ago

Ok. Heres the new code: `int[] descriptorTypes = {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER};

        VkDescriptorSetLayoutBinding.Buffer objectUboLayoutBinding = VkDescriptorSetLayoutBinding.calloc(DESCRIPTOR_COUNT);
        for (int i = 0; i < DESCRIPTOR_COUNT; i++) {
            objectUboLayoutBinding.get(i).binding(i);
            objectUboLayoutBinding.get(i).descriptorCount(1);
            objectUboLayoutBinding.get(i).descriptorType(descriptorTypes[i]);
            objectUboLayoutBinding.get(i).stageFlags(VK_SHADER_STAGE_FRAGMENT_BIT);
        }

        VkDescriptorSetLayoutCreateInfo objectLayoutCreatInfo = VkDescriptorSetLayoutCreateInfo.calloc ();
        globalLayoutInfo.sType(VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO);
        globalLayoutInfo.pBindings(objectUboLayoutBinding);

        LongBuffer pObjectDescriptorSetLayout = stack.mallocLong(1);

        vkCreateDescriptorSetLayout(VulkanContext.getInstance().getVulkanDevice().getLogicalDevice(), objectLayoutCreatInfo, null, pObjectDescriptorSetLayout);

        long objectDescriptorSetLayout = pObjectDescriptorSetLayout.get(0);`
httpdigest commented 1 year ago

And by "it still doesn't work." you mean exactly what?

Vqlf commented 1 year ago

I'm getting the same validation layer error: Validation Error: [ VUID-VkDescriptorSetLayoutCreateInfo-sType-sType ] Object 0: handle = 0x22a76ccd560, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0x3cc1e4ad | vkCreateDescriptorSetLayout: parameter pCreateInfo->sType must be VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO. The Vulkan spec states: sType must be VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO (https://vulkan.lunarg.com/doc/view/1.3.211.0/windows/1.3-extensions/vkspec.html#VUID-VkDescriptorSetLayoutCreateInfo-sType-sType)

httpdigest commented 1 year ago

Please seriously review your code. I see another issue right off the bat:

        VkDescriptorSetLayoutCreateInfo objectLayoutCreatInfo = VkDescriptorSetLayoutCreateInfo.calloc (); // <- you create objectLayoutCreatInfo 
        globalLayoutInfo.sType(VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO); // <- but for some reason you set values on """globalLayoutInfo"""
        globalLayoutInfo.pBindings(objectUboLayoutBinding);
Vqlf commented 1 year ago

Oh I'm a fucking idiot sorry

Vqlf commented 1 year ago

That's the fix. Than you so much :)