-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Fix Vulkan validation error during window detach in multi-viewport mode (#8176) #8600
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 Vulkan validation error during window detach in multi-viewport mode (#8176) #8600
Conversation
…r stages while transitioning for dynamic rendering
Hello Chris, Thanks for the careful and detailed PR. Right now if I try to enable dynamic rendering using this patch + grab the whole [vulkan] Debug report from ObjectType: 4
Message: Validation Error: [ SYNC-HAZARD-WRITE-AFTER-READ ] Object 0: handle = 0x1a86a8cdc20, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0x376bc9df | vkQueueSubmit(): Hazard WRITE_AFTER_READ for entry 0, VkCommandBuffer 0x1a86d1d80b0[], Submitted access info (submitted_usage: SYNC_IMAGE_LAYOUT_TRANSITION, command: vkCmdPipelineBarrier, seq_no: 1, reset_no: 308). Access info (prior_usage: SYNC_PRESENT_ENGINE_SYNCVAL_PRESENT_ACQUIRE_READ_SYNCVAL, read_barriers: VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT|VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT, , batch_tag: 3672, vkAcquireNextImageKHR aquire_tag:3672: VkSwapchainKHR 0xf56c9b0000000004[], image_index: 0image: VkImage 0xe7f79a0000000005[]).
SYNC-HAZARD-WRITE-AFTER-READ(ERROR / SPEC): msgNum: 929810911 - Validation Error: [ SYNC-HAZARD-WRITE-AFTER-READ ] Object 0: handle = 0x1a86a8cdc20, type = VK_OBJECT_TYPE_QUEUE; | MessageID = 0x376bc9df | vkQueueSubmit(): Hazard WRITE_AFTER_READ for entry 0, VkCommandBuffer 0x1a86d1deb80[], Submitted access info (submitted_usage: SYNC_IMAGE_LAYOUT_TRANSITION, command: vkCmdPipelineBarrier, seq_no: 1, reset_no: 308). Access info (prior_usage: SYNC_PRESENT_ENGINE_SYNCVAL_PRESENT_ACQUIRE_READ_SYNCVAL, read_barriers: VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT|VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT, , batch_tag: 3684, vkAcquireNextImageKHR aquire_tag:3684: VkSwapchainKHR 0xf56c9b0000000004[], image_index: 1image: VkImage 0xf443490000000006[]).
Objects: 1
[0] 0x1a86a8cdc20, type: 4, name: NULL And they don't go away with your patch. So I am hardly even able to look at the primary issue #8176. This is generally so utterly confusing to me that, given the much appreciated meticulousness of your PR, I'm tempted to trust you and merge and see what other reports come next from users, but it would be great if I could repro something locally and on a known test bed. |
Hello Omar, I’ve created a patch (from my fork, branch fix/vulkan-validation-error-pipeline-barrier) where I updated both the glfw_vulkan and sdl3_vulkan examples to test the fix. While working on it, I encountered issues with dynamic rendering function loading. Specifically, dynamic rendering functions are currently loaded using vkGetInstanceProcAddr, but since functions like vkCmdXXXX are device-level commands, they must be loaded using vkGetDeviceProcAddr. Current (incorrect) line: Correct version: I also encountered a problem related to layout transitions i added. Since the examples use ImGui_ImplVulkanH_* methods (which aren’t typically used in end-users code), the ImGui_ImplVulkan_Data and InitInfo I relied on weren’t always available (this should never happen if end-users don't use these helpers' functions). So, to avoid any possible issue, I moved the transition logic into ImGui_ImplVulkanH_CreateOrResizeWindow, where we have access to a queue family and can get a queue for command submission. All these changes are included in the patch to test in the examples. |
Thank you Christian for the thoughful and useful amount of details! |
Happy to have contributed! |
* origin/docking-dev: (1059 commits) Backends: Vulkan: Fix failing assertion for platforms where viewports are not supported (ocornut#8734) Backends: GLFW: Fixed not installing WndProc hook in all GLFW version, so AddMouseSourceEvent() logic was missing for some viewports. Backends: GLFW: Fixed crash when using GLFW 3.3 (ocornut#8713, ocornut#8676, ocornut#8239, ocornut#8069) Backends: warning fixes (for docking branch). Backends: GLFW: amend for multi-context support with multi-viewport. (ocornut#8676, ocornut#8239, ocornut#8069) Backends: OSX: ImGui_ImplOSX_HandleEvent() only process event for window containing our viewports. Amend 7ac99a4 for docking. (ocornut#8644) Fixed duplicate symbols in some compile-time configurations. Fonts: Misc merge fixes. Examples: set ConfigDpiScaleFonts / ConfigDpiScaleViewports in all examples already setup for scaling. Backends: GLFW, SDL2, SDL3, update for docking to use helpers. (Breaking) renamed/moved ImGuiConfigFlags_DpiEnableScaleFonts -> ioConfigDpiScaleFonts, ImGuiConfigFlags_DpiEnableScaleViewports -> io.ConfigDpiScaleViewports Backends: Win32: Viewports: handle WM_DPICHANGED in backend when ImGuiConfigFlags_DpiEnableScaleViewports flag is enabled. Viewports: fixed handling of simultaneous move + resize (e.g. toggling maximized) when ImGuiConfigFlags_DpiEnableScaleViewports is enabled. Refactor: move SetCurrentFont(), PushFont(), PopFont() to a section. Platform IME: Fixed multi-viewports IME support, affecting SDL backends. (ocornut#8648, ocornut#8584, ocornut#7492, ocornut#6341) Viewports: added per-viewport FramebufferScale, Platform_GetWindowFramebufferScale() + Backends: GLFW, SDL2, SDL3, Apple: added support. (ocornut#1065, ocornut#1542, ocornut#1676, ocornut#1786, ocornut#2826, ocornut#3757, ocornut#5081, ocornut#5580, ocornut#5592, ocornut#6465, ocornut#7273, ocornut#7779 etc.) ) Backends: OSX: rename internal struct for consistency with other backends. Viewports: fallback DpiScale pulled from fallback Monitor for consistency. Backends: Vulkan: fixed build with VK_NO_PROTOTYPES. Backends: Vulkan: fixed validation errors during window detach in multi-viewport mode. [docking branch amend] (ocornut#8600, ocornut#8176) ...
Summary
This PR fixes the Vulkan validation error reported in issue #8176, which occurs when detaching a window from the main window in multi-viewport mode.
Changes Included
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
immediately after creation.VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
toVK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL
, using appropriate pipeline stages and access masks.These changes make the swapchain image layout transitions explicit and properly synchronized, resolving the Vulkan validation warnings/errors during window detach and resize events.
Reference
A minimal reproducible demo can be found here:
👉 ChrisTom-94/imgui_fix_8176
Notes
PRESENT_SRC_KHR
could also be applied even when not using dynamic rendering.