I am building a 3d renderer in C++ using Vulkan. I am currently running into some issues with transitioning an image view as an output from one render pass to an input into another render pass. Right now I have disabled the first render pass to ensure the second is working properly. So the image view in question is blank and unmodified from it's initialisation. I want to transition the image view using the subpass dependency functionality within the render pass, as I have successfully done this elsewhere for managing shadows. I have tried to implement a dependency, but I am still getting an error. Can you help me fix the code so it will work properly?

Here is the error message:

VUID-VkDescriptorImageInfo-imageLayout-00344(ERROR / SPEC): msgNum: -564812795 - Validation Error: [ VUID-VkDescriptorImageInfo-imageLayout-00344 ] Object 0: handle = 0x234ab4fda10, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0xde55a405 | vkCmdDraw: Cannot use VkImage 0xb991fa0000000024[] (layer=0 mip=0) with specific layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL that doesn't match the previous known layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL. The Vulkan spec states: imageLayout must match the actual VkImageLayout of each subresource accessible from imageView at the time this descriptor is accessed as defined by the image layout matching rules (https://vulkan.lunarg.com/doc/view/1.3.239.0/windows/1.3-extensions/vkspec.html#VUID-VkDescriptorImageInfo-imageLayout-00344)
    Objects: 1
        [0] 0x234ab4fda10, type: 6, name: NULL

Here is the current dependency:

    vk::SubpassDependency externalToGeometryDependency{};
    externalToGeometryDependency.srcSubpass = VK_SUBPASS_EXTERNAL;
    externalToGeometryDependency.dstSubpass = 0;
    externalToGeometryDependency.srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput;
    externalToGeometryDependency.dstStageMask = vk::PipelineStageFlagBits::eFragmentShader;
    externalToGeometryDependency.srcAccessMask = vk::AccessFlagBits::eColorAttachmentWrite;
    externalToGeometryDependency.dstAccessMask = vk::AccessFlagBits::eShaderRead;

Here is the imageInfo setting for the input image:

        imageInfo.imageType = vk::ImageType::e2D;
        imageInfo.format = format;
        imageInfo.extent = vk::Extent3D(swapChainExtent.width, swapChainExtent.height, 1);
        imageInfo.mipLevels = 1;
        imageInfo.arrayLayers = 1;
        imageInfo.samples = msaaSamples;
        imageInfo.tiling = vk::ImageTiling::eOptimal;
        imageInfo.usage = vk::ImageUsageFlagBits::eColorAttachment | vk::ImageUsageFlagBits::eInputAttachment;
        imageInfo.sharingMode = vk::SharingMode::eExclusive;

Here is the attachment description settings for the relevant render pass attachment:

    vk::AttachmentDescription sceneAttachment{};
    sceneAttachment.format = swapChainImageFormat;
    sceneAttachment.samples = msaaSamples;
    sceneAttachment.loadOp = vk::AttachmentLoadOp::eDontCare;
    sceneAttachment.storeOp = vk::AttachmentStoreOp::eStore;
    sceneAttachment.stencilLoadOp = vk::AttachmentLoadOp::eDontCare;
    sceneAttachment.stencilStoreOp = vk::AttachmentStoreOp::eDontCare;
    sceneAttachment.initialLayout = vk::ImageLayout::eUndefined;
    sceneAttachment.finalLayout = vk::ImageLayout::eShaderReadOnlyOptimal;