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

Fix barrier setting in async compute sample #1213

Merged

Conversation

yknishidate
Copy link
Contributor

@yknishidate yknishidate commented Nov 2, 2024

Description

In the async compute sample, when "Enable async queue" is checked in the GUI, the following validation error is output.

image

Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ]
Object 0: handle = 0x18b310c3570, type = VK_OBJECT_TYPE_COMMAND_BUFFER;
Object 1: handle = 0x1ff0c40000000a81, type = > VK_OBJECT_TYPE_IMAGE; |
MessageID = 0x4dae5635 |
vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x18b310c3570[] expects VkImage 0x1ff0c40000000a81[] (subresource: aspectMask 0x1 array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL.

Note

If you get output different from the one below when you check the checkbox, the error may not be reproducible in your environment.

[info] Device has 2 or more graphics queues.
[info] Device has async compute queue.

Since the sample contains multiple images and command buffers, I added set_debug_name() to make the error more understandable, as shown below.

Validation Error: [ UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout ]
Object 0: handle = 0x24dda4ae730, name = compute_post, type = VK_OBJECT_TYPE_COMMAND_BUFFER;
Object 1: handle = 0xdd5f6f0000000a82, name = color_targets[0], type = VK_OBJECT_TYPE_IMAGE; |
MessageID = 0x4dae5635 |
vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] command buffer VkCommandBuffer 0x24dda4ae730[compute_post] expects VkImage 0xdd5f6f0000000a82[color_targets[0]] (subresource: aspectMask 0x1 array layer 0, mip level 0) to be in layout VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL--instead, current layout is VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL.

This shows that the barrier setting for color_targets[0] in compute_post is incorrect. The code is as follows:

memory_barrier.old_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
memory_barrier.new_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;

In the previous forward_offscreen_pass, the layout already transitioned to SHADER_READ_ONLY_OPTIMAL after drawing. This means that the current code is performing the same image layout transition twice (However, both barriers are required for queue transitions.).

memory_barrier.old_layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
memory_barrier.new_layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;

So I fixed the old_layout setting on the compute_post barrier, and the validation errors disappeared. Also, because this sample is complex and hard to debug, I'm leaving set_debug_name() for future.

  • Tested on Windows
  • No related issues

General Checklist:

Please ensure the following points are checked:

  • My code follows the coding style
  • I have reviewed file licenses
  • I have commented any added functions (in line with Doxygen)
  • I have commented any code that could be hard to understand
  • My changes do not add any new compiler warnings
  • My changes do not add any new validation layer errors or warnings
  • I have used existing framework/helper functions where possible
  • My changes do not add any regressions
  • I have tested every sample to ensure everything runs correctly
  • This PR describes the scope and expected impact of the changes I am making

Note: The Samples CI runs a number of checks including:

  • I have updated the header Copyright to reflect the current year (CI build will fail if Copyright is out of date)
  • My changes build on Windows, Linux, macOS and Android. Otherwise I have documented any exceptions

@yknishidate yknishidate changed the title Fix barrier setting Fix barrier setting in async compute sample Nov 2, 2024
Copy link
Contributor

@asuessenbach asuessenbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch!

And even better fix description!

@marty-johnson59 marty-johnson59 merged commit 0fb8bf5 into KhronosGroup:main Nov 4, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants