I encountered an image layout transition problem. My whole commands are basically:
- Create VkImage things with initial layout Undefined
- CommandBuffer0: image layout transition undefined → shader_read_only_optimal
- CommandBuffer1:
3.1 image layout transition shader_read_only_optimal->general
3.2 access by a Compute Shader as a storage image
3.3 image layout transition general->shader_read_only_optimal
3.4 access by another Compute Shader as a sampled image - CommandBuffer2, do exactly what commandbuffer1 did
- CommandBuffer1, …
- CommandBuffer2, …
Whenever I handle a window resize, I will repeat the whole process, and it seems that it works fine for most time, but sometimes the validation layer will report error as follows:
Command buffer expects VkImage (subresource: aspectMask 0x1 array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL–instead, current layout is VK_IMAGE_LAYOUT_GENERAL.
In visual studio debug mode, the error will not happen until the first submit of CommandBuffer2, so I guess the image is successfully changed from undefined to shader_read_only_optimal and then to general, but never be able to change back to shader_read_only_optimal?
However, in Nsight Graphics, the error will also exist when I capture the frame and find the barrier is submitted correctly.
I have no idea why, if the general->shader_read_only_optimal transition is not successful, why there is no error for 3.4 where it is actually accessed as a sampled image? Please help me, thanks~