Descriptor layout and multithreading

Hello,

I’m trying to allocate descriptor sets in my application with the method “vkAllocateDescriptorSets”.
However this method crashes, and the validation layer indicate that I must use valid descriptorSetLayout.

I created descriptorSetLayout by using “vkCreateDescriptorSetLayout”, and this method returned a VK_SUCCESS, and I have no warning at all in the validation layer.

After a lot of investigation about this issue, I noticed that the issue seems to come because of multithreading.
vkCreateDescriptorSetLayout” is called in main thread, and “vkAllocateDescriptorSets” in another one.
The second thread start only after the “vkCreateDescriptorSetLayout”, so I’m sure that the descriptorSetLayout is ready. To be really sure, I delayed the second thread by 10 seconds, with the same issue.
If I put the two methods in the same thread, I don’t have any issue.

So my question is: Is it mandatory to have the two methods in the same thread? If yes, how should I know it? The documentation doesn’t speak about it.
I could have done an error in my code, but days of research didn’t lead to anything, so I’m stuck with the impress that i face a limitation of Vulkan about that.

Thank you for your help.

That’s not how threading works. If you want to “be sure” about the order of two threaded operations, then you should use a mutex or similar construct, not a time delay.

Now to be fair, the start of a thread does “happen after” all of the things in the initializing thread that have already taken place at the moment of thread initialization. So if you truly start the thread after the call to vkCreateDescriptorSetLayout, then you ought to be fine as far as synchronization is concerned.

Odds are good that the problem is how you’re sending the actual descriptor set layout object to the other thread. Have you confirmed (via breakpoints in the code) that the layout object’s value “returned” by vkCreateDescriptorSetLayout is the exact value being passed to vkAllocateDescriptorSets?

Thank you for your answer.

I know that 10 seconds is not the good way to do, but a ‘one-line’ test that should be ok I think.
Effectively, I forgot to mention that the descriptor layout set is given by reference to the second thread and point on the same adress, checked with debugger.

As this issue is really stucking me, I recreated a fresh project and tried to create layout and descriptor in different thread with an example code from documentation. And… it works.
So it seems that we can effectively do this in two different threads and so it should be my code that is wrong. I’ll haveto check what is wrong in my code.

I keep this thread open until I find the issue to be sure it is not vulkan related.

Ok, as I suspected, the error is not vulkan related. The setlayout was destroyed because of a copy of the variable.
I can close the thread