Search code examples
glslvulkan

UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout


I'm trying to use image in glsl using uimage2D.

layout (binding = 0,rgba32ui)uniform writeonly uimage2D image;

void main(){
imageSize(image);

}

for this code I get error

validation layer: Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x30a8448, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x4dae5635 | Submitted command buffer expects VkImage 0x7c45730000000006[] (subresource: aspectMask 0x1 array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_GENERAL--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED.

error is because of imageSize(image).

I have declared ImageLayout as VK_IMAGE_LAYOUT_GENERAL still I'm getting this error.

VkDescriptorImageInfo imageInfo{};
imageInfo.imageLayout =VK_IMAGE_LAYOUT_GENERAL;
imageInfo.imageView = textureImageView;
imageInfo.sampler = textureSampler;

What might cause this error?


Solution

  • VkDescriptorImageInfo does not "declare" anything. It just informs the driver which layout you are gonna use. The error is saying exactly that; you lied to the driver. You told it you will give it image in VK_IMAGE_LAYOUT_GENERAL layout, but then it actually found it in different layout when it is actually being sampled.

    You need to change the image layout by pipeline barriers.