Vulkan per frame resources

So I’m trying to avoid stall between frames, when CPU waits for GPU to finish rendering the first frame and then CPU starts preparing for the second frame.

Work progress : 
TotalNumberOfSwapChainImages : 3
MaxNumOfFramesInFlight : 2
CommandBuffers: 3
RenderSemaphores: MaxNumOfFramesInFlight
PresentationSemaphore : MaxNumOfFramesInFlight
FenceCount: MaxNumOfFramesInFlight

With this setup the clearing and basic rendering loop is running without any issues.
Now the Question arises while setting up the shader resources.

PipelineLayout and descriptorsetlayout are not per frame, i believe they are not required to be unique for each frame or each frame in flight ( Please correct me if i’m wrong).

The confusion is with descriptorSets and associated buffers and memories. Which of the below config is a solution ? Or is there any other config which is better ? The below mentioned buffers are getting update in every frame. Is it allowed to update a buffer/memory at an offset when its in use at another offset ?

DescriptorSet : MaxNumOfFramesInFlight
Buffer : MaxNumOfFramesInFlight
Memory : MaxNumOfFramesInFlight

or

DescriptorSet : MaxNumOfFramesInFlight
Buffer : 1 , with sizeOf(TransformationStruct) * MaxNumOfFramesInFlight, use offseting mechanism
Memory : 1, with sizeOf(TransformationStruct) * MaxNumOfFramesInFlight, use offseting mechanism

Thanks

PipelineLayout and descriptorsetlayout are not per frame, i believe they are not required to be unique for each frame or each frame in flight.

Yes you don’t have to have per frame PipelineLayouts and DescriptorSetLayouts. It’ll be a waste of performance if you try to create them once per frame. But you’ll have to do that if the Pipeline itself is changed drastically (meaning if the shader bindings and all are changed).

The confusion is with descriptorSets and associated buffers and memories. Which of the below config is a solution ? Or is there any other config which is better ? The below mentioned buffers are getting update in every frame. Is it allowed to update a buffer/memory at an offset when its in use at another offset ?

The Vulkan tutorial I followed showed me to use one DescriptorSet, Buffer and BufferMemory for each SwapChain image. But I tried using only one DescriptorSet, Buffer and BufferMemory and it worked fine. I’m not sure if I’m doing something wrong by doing that but it worked perfectly fine (and the memory usage was good too).

My logic behind doing that was, after submitting the CommandBuffer, my program stayed until the frame was rendered. Which means that updating the resources would be okay, there wont be any data corruption happening. And I’m not sure if there’s a way to skip the CPU waiting time until the frame is rendered.

The query is to find out better ways to reduce number of allocations. Vulkan spec had the answer but still need to test with implementation. For vkBindBufferMemory :

memoryOffset is the start offset of the region of memory which is to be bound to the buffer. The
number of bytes returned in the VkMemoryRequirements::size member in memory, starting from
memoryOffset bytes, will be bound to the specified buffer.

Will try with below config ( with offsets ), for a single uniform struct :

DescriptorSet : MaxNumOfFramesInFlight or TotalNumberOfSwapChainImages
Buffer : 1
Memory : 1

CONCURRENT_FRAMES or MaxNumOfFramesInFlight is the number of frames getting calculated in parallel.

Config 1:
descriptorSets : CONCURRENT_FRAMES or MaxNumOfFramesInFlight
uniformBuffer : 1
uniformBufferMemory : 1

Config 2:
descriptorSets : CONCURRENT_FRAMES or MaxNumOfFramesInFlight
uniformBuffer : CONCURRENT_FRAMES or MaxNumOfFramesInFlight
uniformBufferMemory : 1

The above two configs work without any issues. Using a single count of all 3 entities will overwrite values.