// Copyright 2019-2021 The Khronos Group Inc.
//
// SPDX-License-Identifier: CC-BY-4.0

// Common Valid Usage
// Common to VkImageMemoryBarrier* structs
  * [[VUID-{refpage}-subresourceRange-01486]]
    pname:subresourceRange.baseMipLevel must: be less than the
    pname:mipLevels specified in slink:VkImageCreateInfo when pname:image
    was created
  * [[VUID-{refpage}-subresourceRange-01724]]
    If pname:subresourceRange.levelCount is not
    ename:VK_REMAINING_MIP_LEVELS, [eq]#pname:subresourceRange.baseMipLevel
    {plus} pname:subresourceRange.levelCount# must: be less than or equal to
    the pname:mipLevels specified in slink:VkImageCreateInfo when
    pname:image was created
  * [[VUID-{refpage}-subresourceRange-01488]]
    pname:subresourceRange.baseArrayLayer must: be less than the
    pname:arrayLayers specified in slink:VkImageCreateInfo when pname:image
    was created
  * [[VUID-{refpage}-subresourceRange-01725]]
    If pname:subresourceRange.layerCount is not
    ename:VK_REMAINING_ARRAY_LAYERS,
    [eq]#pname:subresourceRange.baseArrayLayer {plus}
    pname:subresourceRange.layerCount# must: be less than or equal to the
    pname:arrayLayers specified in slink:VkImageCreateInfo when pname:image
    was created
  * [[VUID-{refpage}-image-01932]]
    If pname:image is non-sparse then it must: be bound completely and
    contiguously to a single sname:VkDeviceMemory object
  * [[VUID-{refpage}-oldLayout-01208]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL then pname:image must:
    have been created with ename:VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT
  * [[VUID-{refpage}-oldLayout-01209]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL then pname:image
    must: have been created with
    ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
  * [[VUID-{refpage}-oldLayout-01210]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL then pname:image
    must: have been created with
    ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
  * [[VUID-{refpage}-oldLayout-01211]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL then pname:image must:
    have been created with ename:VK_IMAGE_USAGE_SAMPLED_BIT or
    ename:VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
  * [[VUID-{refpage}-oldLayout-01212]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL then pname:image must: have
    been created with ename:VK_IMAGE_USAGE_TRANSFER_SRC_BIT
  * [[VUID-{refpage}-oldLayout-01213]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL then pname:image must: have
    been created with ename:VK_IMAGE_USAGE_TRANSFER_DST_BIT
  * [[VUID-{refpage}-oldLayout-01197]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    pname:oldLayout must: be ename:VK_IMAGE_LAYOUT_UNDEFINED or the current
    layout of the image subresources affected by the barrier
  * [[VUID-{refpage}-newLayout-01198]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    pname:newLayout must: not be ename:VK_IMAGE_LAYOUT_UNDEFINED or
    ename:VK_IMAGE_LAYOUT_PREINITIALIZED
ifdef::VK_VERSION_1_1,VK_KHR_maintenance2[]
  * [[VUID-{refpage}-oldLayout-01658]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_STENCIL_ATTACHMENT_OPTIMAL then
    pname:image must: have been created with
    ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
  * [[VUID-{refpage}-oldLayout-01659]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_STENCIL_READ_ONLY_OPTIMAL then
    pname:image must: have been created with
    ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
endif::VK_VERSION_1_1,VK_KHR_maintenance2[]
ifdef::VK_VERSION_1_2,VK_EXT_separate_depth_stencil_layouts[]
  * [[VUID-{refpage}-srcQueueFamilyIndex-04065]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_DEPTH_READ_ONLY_OPTIMAL then pname:image must:
    have been created with at least one of
    ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
    ename:VK_IMAGE_USAGE_SAMPLED_BIT, or
    ename:VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
  * [[VUID-{refpage}-srcQueueFamilyIndex-04066]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL then pname:image must:
    have been created with ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
    set
  * [[VUID-{refpage}-srcQueueFamilyIndex-04067]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_STENCIL_READ_ONLY_OPTIMAL then pname:image must:
    have been created with at least one of
    ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
    ename:VK_IMAGE_USAGE_SAMPLED_BIT, or
    ename:VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
  * [[VUID-{refpage}-srcQueueFamilyIndex-04068]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_STENCIL_ATTACHMENT_OPTIMAL then pname:image must:
    have been created with ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
    set
endif::VK_VERSION_1_2,VK_EXT_separate_depth_stencil_layouts[]
ifdef::VK_KHR_synchronization2[]
  * [[VUID-{refpage}-srcQueueFamilyIndex-03938]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_ATTACHMENT_OPTIMAL_KHR, pname:image must: have
    been created with ename:VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT or
    ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT
  * [[VUID-{refpage}-srcQueueFamilyIndex-03939]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_READ_ONLY_OPTIMAL_KHR, pname:image must: have been
    created with at least one of
    ename:VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
    ename:VK_IMAGE_USAGE_SAMPLED_BIT, or
    ename:VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
endif::VK_KHR_synchronization2[]
ifdef::VK_KHR_fragment_shading_rate,VK_NV_shading_rate_image[]
  * [[VUID-{refpage}-oldLayout-02088]]
    If pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex define a
    <<synchronization-queue-transfers, queue family ownership transfer>> or
    pname:oldLayout and pname:newLayout define an
    <<synchronization-image-layout-transitions, image layout transition>>,
    and pname:oldLayout or pname:newLayout is
    ename:VK_IMAGE_LAYOUT_FRAGMENT_SHADING_RATE_ATTACHMENT_OPTIMAL_KHR then
    pname:image must: have been created with
    ename:VK_IMAGE_USAGE_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR set
endif::VK_KHR_fragment_shading_rate,VK_NV_shading_rate_image[]
ifndef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
  * [[VUID-{refpage}-image-02902]]
    If pname:image has a color format, then the pname:aspectMask member of
    pname:subresourceRange must: be ename:VK_IMAGE_ASPECT_COLOR_BIT
endif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
ifdef::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
  * [[VUID-{refpage}-image-01671]]
    If pname:image has a single-plane color format or is not _disjoint_,
    then the pname:aspectMask member of pname:subresourceRange must: be
    ename:VK_IMAGE_ASPECT_COLOR_BIT
  * [[VUID-{refpage}-image-01672]]
    If pname:image has a multi-planar format and the image is _disjoint_,
    then the pname:aspectMask member of pname:subresourceRange must: include
    either at least one of ename:VK_IMAGE_ASPECT_PLANE_0_BIT,
    ename:VK_IMAGE_ASPECT_PLANE_1_BIT, and
    ename:VK_IMAGE_ASPECT_PLANE_2_BIT; or must: include
    ename:VK_IMAGE_ASPECT_COLOR_BIT
  * [[VUID-{refpage}-image-01673]]
    If pname:image has a multi-planar format with only two planes, then the
    pname:aspectMask member of pname:subresourceRange must: not include
    ename:VK_IMAGE_ASPECT_PLANE_2_BIT
endif::VK_VERSION_1_1,VK_KHR_sampler_ycbcr_conversion[]
ifndef::VK_VERSION_1_2,VK_KHR_separate_depth_stencil_layouts[]
  * [[VUID-{refpage}-image-01207]]
    If pname:image has a depth/stencil format with both depth and stencil
    components, then the pname:aspectMask member of pname:subresourceRange
    must: include both ename:VK_IMAGE_ASPECT_DEPTH_BIT and
    ename:VK_IMAGE_ASPECT_STENCIL_BIT
endif::VK_VERSION_1_2,VK_KHR_separate_depth_stencil_layouts[]
ifdef::VK_VERSION_1_2,VK_KHR_separate_depth_stencil_layouts[]
  * [[VUID-{refpage}-image-03319]]
    If pname:image has a depth/stencil format with both depth and stencil
    and the <<features-separateDepthStencilLayouts,
    separateDepthStencilLayouts>> feature is enabled, then the
    pname:aspectMask member of pname:subresourceRange must: include either
    or both ename:VK_IMAGE_ASPECT_DEPTH_BIT and
    ename:VK_IMAGE_ASPECT_STENCIL_BIT
  * [[VUID-{refpage}-image-03320]]
    If pname:image has a depth/stencil format with both depth and stencil
    and the <<features-separateDepthStencilLayouts,
    separateDepthStencilLayouts>> feature is not enabled, then the
    pname:aspectMask member of pname:subresourceRange must: include both
    ename:VK_IMAGE_ASPECT_DEPTH_BIT and ename:VK_IMAGE_ASPECT_STENCIL_BIT
endif::VK_VERSION_1_2,VK_KHR_separate_depth_stencil_layouts[]
ifndef::VK_VERSION_1_1,VK_KHR_external_memory[]
  * [[VUID-{refpage}-image-04069]]
    If pname:image was created with a sharing mode of
    ename:VK_SHARING_MODE_EXCLUSIVE, and pname:srcQueueFamilyIndex and
    pname:dstQueueFamilyIndex are not equal, pname:srcQueueFamilyIndex and
    pname:dstQueueFamilyIndex must: be valid queue families
endif::VK_VERSION_1_1,VK_KHR_external_memory[]
ifdef::VK_VERSION_1_1,VK_KHR_external_memory[]
  * [[VUID-{refpage}-srcQueueFamilyIndex-04070]]
    If pname:srcQueueFamilyIndex is not equal to pname:dstQueueFamilyIndex,
    at least one must: not be a special queue family reserved for external
    memory ownership transfers, as described in
    <<synchronization-queue-transfers>>
  * [[VUID-{refpage}-image-04071]]
    If pname:image was created with a sharing mode of
    ename:VK_SHARING_MODE_CONCURRENT, pname:srcQueueFamilyIndex and
    pname:dstQueueFamilyIndex are not equal, and one of
    pname:srcQueueFamilyIndex and pname:dstQueueFamilyIndex is one of the
    special queue family values reserved for external memory transfers, the
    other must: be ename:VK_QUEUE_FAMILY_IGNORED
  * [[VUID-{refpage}-image-04072]]
    If pname:image was created with a sharing mode of
    ename:VK_SHARING_MODE_EXCLUSIVE, and pname:srcQueueFamilyIndex and
    pname:dstQueueFamilyIndex are not equal, pname:srcQueueFamilyIndex and
    pname:dstQueueFamilyIndex must: both be valid queue families, or one of
    the special queue family values reserved for external memory transfers,
    as described in <<synchronization-queue-transfers>>
endif::VK_VERSION_1_1,VK_KHR_external_memory[]
// Common Valid Usage
