Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False DrawState-InvalidImageLayout error #8869

Open
knokko opened this issue Nov 17, 2024 · 1 comment
Open

False DrawState-InvalidImageLayout error #8869

knokko opened this issue Nov 17, 2024 · 1 comment
Labels
Bug Something isn't working

Comments

@knokko
Copy link

knokko commented Nov 17, 2024

Environment:

  • OS: Windows 10
  • GPU and driver version: NVIDIA GeForce RTX 3070 Ti 561.9.0.0
  • SDK or header version if building from repo: 1.3.296.0
  • Options enabled (synchronization, best practices, etc.): gpu-assisted, synchronization, and best practices

Describe the Issue

When my application draws an image, the validation layer reports a validation error that I believe is incorrect:

Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x2243b06c390, name = GameWindowBuffer0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x2e2cd000000002b, name = Bc1Image0, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x4dae5635 | vkCmdDraw():  command buffer VkCommandBuffer 0x2243b06c390[GameWindowBuffer0] expects VkImage 0x2e2cd000000002b[Bc1Image0] (subresource: aspectMask VK_IMAGE_ASPECT_COLOR_BIT array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED.

It states that my image Bc1Image0 has the current layout VK_IMAGE_LAYOUT_UNDEFINED, but I believe that it's layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL because the following commands have been executed and completed prior to the draw command submission:

the image layout transition commands
Thread 1, Frame 0:
vkCmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers) returns void:
    commandBuffer:                  VkCommandBuffer = 000002243B5C0C60 [UiStagingTransfer]
    srcStageMask:                   VkPipelineStageFlags = 1 (VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT)
    dstStageMask:                   VkPipelineStageFlags = 4096 (VK_PIPELINE_STAGE_TRANSFER_BIT)
    dependencyFlags:                VkDependencyFlags = 0
    memoryBarrierCount:             uint32_t = 0
    pMemoryBarriers:                const VkMemoryBarrier* = NULL
    bufferMemoryBarrierCount:       uint32_t = 0
    pBufferMemoryBarriers:          const VkBufferMemoryBarrier* = NULL
    imageMemoryBarrierCount:        uint32_t = 1
    pImageMemoryBarriers:           const VkImageMemoryBarrier* = 000002243B086928
        pImageMemoryBarriers[0]:        const VkImageMemoryBarrier = 000002243B086928:
            sType:                          VkStructureType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER (45)
            pNext:                          const void* = NULL
            srcAccessMask:                  VkAccessFlags = 0 (VK_ACCESS_NONE)
            dstAccessMask:                  VkAccessFlags = 4096 (VK_ACCESS_TRANSFER_WRITE_BIT)
            oldLayout:                      VkImageLayout = VK_IMAGE_LAYOUT_UNDEFINED (0)
            newLayout:                      VkImageLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL (7)
            srcQueueFamilyIndex:            uint32_t = 4294967295
            dstQueueFamilyIndex:            uint32_t = 4294967295
            image:                          VkImage = 02E2CD000000002B [Bc1Image0]
            subresourceRange:               VkImageSubresourceRange = 000002243B086958:
                aspectMask:                     VkImageAspectFlags = 1 (VK_IMAGE_ASPECT_COLOR_BIT)
                baseMipLevel:                   uint32_t = 0
                levelCount:                     uint32_t = 1
                baseArrayLayer:                 uint32_t = 0
                layerCount:                     uint32_t = 1

Thread 1, Frame 0:
vkCmdCopyBufferToImage(commandBuffer, srcBuffer, dstImage, dstImageLayout, regionCount, pRegions) returns void:
    commandBuffer:                  VkCommandBuffer = 000002243B5C0C60 [UiStagingTransfer]
    srcBuffer:                      VkBuffer = 0980B0000000002E [UiStagingBuffer]
    dstImage:                       VkImage = 02E2CD000000002B [Bc1Image0]
    dstImageLayout:                 VkImageLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL (7)
    regionCount:                    uint32_t = 1
    pRegions:                       const VkBufferImageCopy* = 000002243B0868F0
        pRegions[0]:                    const VkBufferImageCopy = 000002243B0868F0:
            bufferOffset:                   VkDeviceSize = 0
            bufferRowLength:                uint32_t = 720
            bufferImageHeight:              uint32_t = 528
            imageSubresource:               VkImageSubresourceLayers = 000002243B086900:
                aspectMask:                     VkImageAspectFlags = 1 (VK_IMAGE_ASPECT_COLOR_BIT)
                mipLevel:                       uint32_t = 0
                baseArrayLayer:                 uint32_t = 0
                layerCount:                     uint32_t = 1
            imageOffset:                    VkOffset3D = 000002243B086910:
                x:                              int32_t = 0
                y:                              int32_t = 0
                z:                              int32_t = 0
            imageExtent:                    VkExtent3D = 000002243B08691C:
                width:                          uint32_t = 720
                height:                         uint32_t = 528
                depth:                          uint32_t = 1

Thread 1, Frame 0:
vkCmdPipelineBarrier(commandBuffer, srcStageMask, dstStageMask, dependencyFlags, memoryBarrierCount, pMemoryBarriers, bufferMemoryBarrierCount, pBufferMemoryBarriers, imageMemoryBarrierCount, pImageMemoryBarriers) returns void:
    commandBuffer:                  VkCommandBuffer = 000002243B5C0C60 [UiStagingTransfer]
    srcStageMask:                   VkPipelineStageFlags = 4096 (VK_PIPELINE_STAGE_TRANSFER_BIT)
    dstStageMask:                   VkPipelineStageFlags = 128 (VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT)
    dependencyFlags:                VkDependencyFlags = 0
    memoryBarrierCount:             uint32_t = 0
    pMemoryBarriers:                const VkMemoryBarrier* = NULL
    bufferMemoryBarrierCount:       uint32_t = 0
    pBufferMemoryBarriers:          const VkBufferMemoryBarrier* = NULL
    imageMemoryBarrierCount:        uint32_t = 1
    pImageMemoryBarriers:           const VkImageMemoryBarrier* = 000002243B0868A8
        pImageMemoryBarriers[0]:        const VkImageMemoryBarrier = 000002243B0868A8:
            sType:                          VkStructureType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER (45)
            pNext:                          const void* = NULL
            srcAccessMask:                  VkAccessFlags = 4096 (VK_ACCESS_TRANSFER_WRITE_BIT)
            dstAccessMask:                  VkAccessFlags = 32 (VK_ACCESS_SHADER_READ_BIT)
            oldLayout:                      VkImageLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL (7)
            newLayout:                      VkImageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL (5)
            srcQueueFamilyIndex:            uint32_t = 4294967295
            dstQueueFamilyIndex:            uint32_t = 4294967295
            image:                          VkImage = 02E2CD000000002B [Bc1Image0]
            subresourceRange:               VkImageSubresourceRange = 000002243B0868D8:
                aspectMask:                     VkImageAspectFlags = 1 (VK_IMAGE_ASPECT_COLOR_BIT)
                baseMipLevel:                   uint32_t = 0
                levelCount:                     uint32_t = 1
                baseArrayLayer:                 uint32_t = 0
                layerCount:                     uint32_t = 1

I have executed vkWaitForFences after the submission to await its completion. This happens before the drawing commands are recorded. I have included the full api dump in the attachment. dump.txt

lines 1440 - 1525: allocate render command buffers
lines 2333 - 2700: create the problematic image, performs the copy & barriers, and awaits the fence
lines 2564 - 2645: the layout transitions of the problematic image
lines 3025 - 3340: samples the problematic image during a draw call
lines 3639 - 3680: another problematic draw call for the same image

line 3935: validation error about the first draw call
line 3939: validation error about the second draw call

(Since the validation error is reported asynchronously by vvl, it doesn't appear immediately.)

To reproduce this error, I published the executable at https://github.com/knokko/mardek/releases/tag/vvl-bug1 . Building from source should also be possible, but requires Java.

Expected behavior

No validation error is reported.

Valid Usage ID
If applicable, please include the validation messages encountered leading up to the issue

Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ] Object 0: handle = 0x2243b06c390, name = GameWindowBuffer0, type = VK_OBJECT_TYPE_COMMAND_BUFFER; Object 1: handle = 0x2e2cd000000002b, name = Bc1Image0, type = VK_OBJECT_TYPE_IMAGE; | MessageID = 0x4dae5635 | vkCmdDraw():  command buffer VkCommandBuffer 0x2243b06c390[GameWindowBuffer0] expects VkImage 0x2e2cd000000002b[Bc1Image0] (subresource: aspectMask VK_IMAGE_ASPECT_COLOR_BIT array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED.
@spencer-lunarg spencer-lunarg added the Bug Something isn't working label Nov 17, 2024
@spencer-lunarg
Copy link
Contributor

thanks for reporting, we have a soon TODO to clean up the UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout error as it has many issues and needs clarification in the Vulkan Spec what is actually legal or not on all Hardware that support Vulkan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants