flightlessmango / MangoHud

A Vulkan and OpenGL overlay for monitoring FPS, temperatures, CPU/GPU load and more. Discord: https://discordapp.com/invite/Gj5YmBb
MIT License
6.47k stars 287 forks source link

MangoHud Causing synchronization read-after-write validation error and segfault on exit #1214

Open Tacodiva opened 9 months ago

Tacodiva commented 9 months ago

Describe the bug When I try to use MangoHud with my game engine, it causes a validation warning and error message every frame:

[Warn][Vk][Validation] Validation Warning: [ UNASSIGNED-BestPractices-ImageBarrierAccessLayout ] | MessageID = 0x849fcec7 | vkCmdPipelineBarrier(): pImageMemoryBarriers[0] image is VkImage 0x564fdd0000000069[] and accessMask is VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT, but for layout VK_IMAGE_LAYOUT_PRESENT_SRC_KHR expected accessMask are VkAccessFlags2(0).
   at Vulkan.VulkanDeviceCommands.vkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInfo)
   [ rest of stack trace...]

[Err][Vk][Validation] Validation Error: [ SYNC-HAZARD-READ-AFTER-WRITE ] Object 0: handle = 0x4256c1000000005d, type = VK_OBJECT_TYPE_RENDER_PASS; | MessageID = 0xe4d96472 | vkCmdBeginRenderPass: Hazard READ_AFTER_WRITE in subpass 0 for attachment 0 aspect color during load with loadOp VK_ATTACHMENT_LOAD_OP_LOAD. Access info (usage: SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_READ, prior_usage: SYNC_IMAGE_LAYOUT_TRANSITION, write_barriers: SYNC_COLOR_ATTACHMENT_OUTPUT_COLOR_ATTACHMENT_WRITE, command: vkCmdPipelineBarrier, seq_no: 4, reset_no: 2).
   at Vulkan.VulkanDeviceCommands.vkQueuePresentKHR(VkQueue queue, VkPresentInfoKHR* pPresentInfo)
   [ rest of stack trace...]

It still seems to work fine on my drivers despite the validation error. When I close the window in my engine, I get a segfault only when using mangohud. GDB reported the following (probably not very helpful) stacktrace:

#0  0x00007ffff7a72051 in __GI__IO_getline_info (fp=fp@entry=0x7fbdec000b70, 
    buf=buf@entry=0x7fbe804bd2a0 <error: Cannot access memory at address 0x7fbe804bd2a0>, n=1022, n@entry=1023, 
    delim=delim@entry=10, extract_delim=extract_delim@entry=1, eof=eof@entry=0x0) at iogetline.c:77
#1  0x00007ffff7a7213c in __GI__IO_getline (fp=fp@entry=0x7fbdec000b70, 
    buf=buf@entry=0x7fbe804bd2a0 <error: Cannot access memory at address 0x7fbe804bd2a0>, n=n@entry=1023, 
    delim=delim@entry=10, extract_delim=extract_delim@entry=1) at iogetline.c:34
#2  0x00007ffff7a70de0 in _IO_fgets (buf=0x7fbe804bd2a0 <error: Cannot access memory at address 0x7fbe804bd2a0>, n=1024, 
    fp=0x7fbdec000b70) at iofgets.c:53
#3  0x00007fbe8029060a in ?? ()
#4  0x0000000000000000 in ?? ()

I was not able to determine what Vulkan command was causing the segfault, but it happens when I close the window and the engine tries to exit so probably one of the vkDestroy... commands. I'm also not sure if the segfault is happening in the driver due to incorrect usage of the API or if it's MangoHud itself.

List relevant hardware/software information

To Reproduce

I assume this is something strange I'm doing within my engine, but I'm not sure what that could be. Without MangoHud, it works fine without validation issues. I would prefer not to release my engine at this time, though I'm happy to answer any questions if need be.