bkaradzic / bgfx

Cross-platform, graphics API agnostic, "Bring Your Own Engine/Framework" style rendering library.
https://bkaradzic.github.io/bgfx/overview.html
BSD 2-Clause "Simplified" License
15.12k stars 1.95k forks source link

Insert vkDeviceWaitIdle to prevent VK_DEVICE_LOST. #3363

Closed mcourteaux closed 1 month ago

mcourteaux commented 1 month ago

Potentially fixes #3227. At least on my machine, aggressively resizing the window no longer causes a device lost. For my setup, this change is an improvement. The idea is taken from here: https://github.com/mpv-player/mpv/issues/8360#issuecomment-1486705836

mcourteaux commented 1 month ago

I haven't actually looked into it yet, but I suspect frames-in-flight to be dependent on that swapchain that gets destroyed.

jay3d commented 1 month ago

@mcourteaux I have long awaited for this, but unfortunately it is still crashing with my use case:

src\bgfx.cpp (1737): BGFX Reset back-buffer swap chain:
src\bgfx.cpp (1746): BGFX   1936x1222, format: RGBA8, numBackBuffers: 2, maxFrameLatency: 0
src\bgfx.cpp (1748): BGFX   [ ] MSAAx1
src\bgfx.cpp (1749): BGFX   [ ] Fullscreen
src\bgfx.cpp (1750): BGFX   [ ] V-sync
src\bgfx.cpp (1751): BGFX   [x] Max Anisotropy
src\bgfx.cpp (1752): BGFX   [ ] Capture
src\bgfx.cpp (1753): BGFX   [ ] Flush After Render
src\bgfx.cpp (1754): BGFX   [ ] Flip After Render
src\bgfx.cpp (1755): BGFX   [ ] sRGB Back Buffer
src\bgfx.cpp (1756): BGFX   [ ] Transparent Back Buffer
src\bgfx.cpp (1757): BGFX   [ ] HDR10
src\bgfx.cpp (1758): BGFX   [ ] Hi-DPI
src\bgfx.cpp (1759): BGFX   [ ] Depth Clamp
src\bgfx.cpp (1760): BGFX   [ ] Suspend
src\renderer_vk.cpp (718): BGFX ---E-             Unknown, Validation, 0: Validation Error: [ VUID-VkSwapchainCreateInfoKHR-preTransform-01279 ] | MessageID = 0x987713ee | vkCreateSwapchainKHR(): pCreateInfo->preTransform is not supported, support values are:
  VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR%s
. The Vulkan spec states: preTransform must be one of the bits present in the supportedTransforms member of the VkSurfaceCapabilitiesKHR structure returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkSwapchainCreateInfoKHR-preTransform-01279)
src\renderer_vk.cpp (7241): BGFX Create swapchain numSwapChainImages 2, minImageCount 2, BX_COUNTOF(m_backBufferColorImage) 10
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02852 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0x7c6fcb0000023302, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xdb2c5767 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (1937) is greater than framebuffer width (1936). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.x + renderArea.extent.width must be less than or equal to VkFramebufferCreateInfo::width the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02852)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02852 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0x7c6fcb0000023302, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xdb2c5767 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (1937) is greater than framebuffer width (1936). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.x + renderArea.extent.width must be less than or equal to VkFramebufferCreateInfo::width the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02852)
src\renderer_vk.cpp (7121): BGFX WARN Create swapchain error: vkDeviceWaitIdle() failed: -4: VK_ERROR_DEVICE_LOST
src\renderer_vk.cpp (718): BGFX ---E-             Unknown, Validation, 0: Validation Error: [ VUID-VkSwapchainCreateInfoKHR-preTransform-01279 ] | MessageID = 0x987713ee | vkCreateSwapchainKHR(): pCreateInfo->preTransform is not supported, support values are:
  VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR%s
. The Vulkan spec states: preTransform must be one of the bits present in the supportedTransforms member of the VkSurfaceCapabilitiesKHR structure returned by vkGetPhysicalDeviceSurfaceCapabilitiesKHR for the surface (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkSwapchainCreateInfoKHR-preTransform-01279)
src\renderer_vk.cpp (7241): BGFX Create swapchain numSwapChainImages 2, minImageCount 2, BX_COUNTOF(m_backBufferColorImage) 10
src\renderer_vk.cpp(8203): ASSERT VK_SUCCESS == vkresult -> vkQueueSubmit(m_queue, 1, &si, m_completedFence); VK error 0xfffffffc: VK_ERROR_DEVICE_LOST
src\renderer_vk.cpp (8203): BGFX FATAL 0x00000000: vkQueueSubmit(m_queue, 1, &si, m_completedFence); VK error 0xfffffffc: VK_ERROR_DEVICE_LOST

Looks like a missing VK capabilities bit?

jay3d commented 1 month ago

I have added this missing bit:

        m_sci.surface            = m_surface;
        m_sci.minImageCount      = swapBufferCount;
        m_sci.imageFormat        = surfaceFormat;
        m_sci.imageColorSpace    = surfaceColorSpace;
        m_sci.imageExtent.width  = width;
        m_sci.imageExtent.height = height;
        m_sci.imageUsage         = imageUsage;
        m_sci.preTransform       = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;  // <-- Here
        m_sci.compositeAlpha     = compositeAlpha;
        m_sci.presentMode        = s_presentMode[presentModeIdx].mode;
        m_sci.clipped            = VK_FALSE;

        result = vkCreateSwapchainKHR(device, &m_sci, allocatorCb, &m_swapChain);

But it's still crashing. Something is different though:

src\bgfx.cpp (1737): BGFX Reset back-buffer swap chain:
src\bgfx.cpp (1746): BGFX   2255x1217, format: RGBA8, numBackBuffers: 2, maxFrameLatency: 0
src\bgfx.cpp (1748): BGFX   [ ] MSAAx1
src\bgfx.cpp (1749): BGFX   [ ] Fullscreen
src\bgfx.cpp (1750): BGFX   [ ] V-sync
src\bgfx.cpp (1751): BGFX   [x] Max Anisotropy
src\bgfx.cpp (1752): BGFX   [ ] Capture
src\bgfx.cpp (1753): BGFX   [ ] Flush After Render
src\bgfx.cpp (1754): BGFX   [ ] Flip After Render
src\bgfx.cpp (1755): BGFX   [ ] sRGB Back Buffer
src\bgfx.cpp (1756): BGFX   [ ] Transparent Back Buffer
src\bgfx.cpp (1757): BGFX   [ ] HDR10
src\bgfx.cpp (1758): BGFX   [ ] Hi-DPI
src\bgfx.cpp (1759): BGFX   [ ] Depth Clamp
src\bgfx.cpp (1760): BGFX   [ ] Suspend
src\renderer_vk.cpp (7121): BGFX WARN Create swapchain error: vkDeviceWaitIdle() failed: -4: VK_ERROR_DEVICE_LOST
src\renderer_vk.cpp (7242): BGFX Create swapchain numSwapChainImages 2, minImageCount 2, BX_COUNTOF(m_backBufferColorImage) 10
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02852 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xdb2c5767 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (2256) is greater than framebuffer width (2254). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.x + renderArea.extent.width must be less than or equal to VkFramebufferCreateInfo::width the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02852)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02853 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0x1bd44466 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.y (0) + extent.height (1218) is greater than framebuffer height (1216). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.y + renderArea.extent.height must be less than or equal to VkFramebufferCreateInfo::height the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02853)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02852 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xdb2c5767 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (2256) is greater than framebuffer width (2254). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.x + renderArea.extent.width must be less than or equal to VkFramebufferCreateInfo::width the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02852)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02853 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0x1bd44466 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.y (0) + extent.height (1218) is greater than framebuffer height (1216). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.y + renderArea.extent.height must be less than or equal to VkFramebufferCreateInfo::height the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02853)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02852 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xdb2c5767 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (2255) is greater than framebuffer width (2254). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.x + renderArea.extent.width must be less than or equal to VkFramebufferCreateInfo::width the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02852)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02853 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0x1bd44466 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.y (0) + extent.height (1217) is greater than framebuffer height (1216). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.y + renderArea.extent.height must be less than or equal to VkFramebufferCreateInfo::height the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02853)
src\renderer_vk.cpp(8204): ASSERT VK_SUCCESS == vkresult -> vkQueueSubmit(m_queue, 1, &si, m_completedFence); VK error 0xfffffffc: VK_ERROR_DEVICE_LOST
src\renderer_vk.cpp (8204): BGFX FATAL 0x00000000: vkQueueSubmit(m_queue, 1, &si, m_completedFence); VK error 0xfffffffc: VK_ERROR_DEVICE_LOST

I'm on Windows BTW.

mcourteaux commented 1 month ago

This validation error:

src\renderer_vk.cpp (718): BGFX ---E- RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02852 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xdb2c5767 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (2256) is greater than framebuffer width (2254). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.x + renderArea.extent.width must be less than or equal to VkFramebufferCreateInfo::width the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02852)

Sounds like you didn't properly adjust bgfx::setViewRect() accordingly? Can you double check that?

jay3d commented 1 month ago

@mcourteaux I have double checked, and it is set properly.

mcourteaux commented 1 month ago

@bkaradzic This really sounds like the issue I mentioned: there are still frames in flight which were using frames from the swapchain that got destroyed. How would we need to properly fix this?

I'm gathering clues:

@pezcode What are your thoughts on the matter?

bkaradzic commented 1 month ago

Should we somehow flush the frames in flight, then switch out the swapchain, and spin back up?

Yes, wait for everything to finish, then do resizing/switching.

mcourteaux commented 1 month ago

Should we somehow flush the frames in flight, then switch out the swapchain, and spin back up?

Yes, wait for everything to finish, then do resizing/switching.

What I mean is not just "wait", but also do an extra flip() to allow the last frame-in-flight corresponding to the old swapchain to be presented before we recreate the swapchain. Or am I talking nonsense? I sort of think this is wrong, because the window already IS resized. But I'm trying to figure out what's the reason for the vkDeviceWaitIdle() to fail.

pezcode commented 1 month ago

I thought the code already force-waits on a fence here: https://github.com/bkaradzic/bgfx/blob/dd4199bcb37426326e0e31419e99c10701e96c58/src/renderer_vk.cpp#L6824

So I'm not 100% sure why your fix works compared to the existing code. But I don't have a way to reproduce this, so I can't really help here.

Bikeshedding opinion ahead: vkDeviceWaitIdle() is a massive hammer you shouldn't be using unless it's for shutting down the whole program or you don't care about performance. Fences are always the better option, although it means you need to spend a bit longer to understand the dependencies.

pezcode commented 1 month ago

This code is explicitly ignoring the needtoRefreshSwapchain flag. What if the reasoning is wrong/outdated?

Feel free to try, but back when I wrote this it would happen that the swapchain was invalidated, but the new window size from reset() only made it to the renderer 2 frames later. So if you immediately recreated the swapchain, it would be with the old window size.

Previously I was creating a new one and then destroying the old afterwards. Not sure if this was the issue though. Now, I reuse the old when recreating and then destroy the old and everything works as expected.

In general this should be done for smooth resizing. Basically set the old swapchain handle here: https://github.com/bkaradzic/bgfx/blob/dd4199bcb37426326e0e31419e99c10701e96c58/src/renderer_vk.cpp#L6739 Then create the new one, and only then destroy the old one.

I tried this but kind of gave up because it made the code flow terrible to follow, and it was a minor optimization for visuals while resizing. It could be that some drivers have a fit when creating too many swapchains without reusing the old one, but it's not required by the spec. May or may not solve this issue, not sure.

bkaradzic commented 1 month ago

Yeah I'm also unable to reproduce locally... Anyone who has this issue do you see it in examples, or only in your app?

jay3d commented 1 month ago

It does crash with examples when modifying them to allow smooth resizing (rendering thread is different from the event thread). I think I suggest adding a Resize enum to the command buffer, and implement that among others things, because it's hard to track dependencies using hacks alone.

mcourteaux commented 1 month ago

I was able to reproduce, but since the added vkDeviceWaitIdle() I can't anymore. Perhaps I should try to debug this, without having the wait for idle instruction.

bkaradzic commented 1 month ago

I was able to reproduce

In unmodified examples from repo?

bkaradzic commented 1 month ago

Lets continue here: https://discord.com/channels/712512073522872352/1294033853102424125

pgruenbacher commented 2 weeks ago

I have added this missing bit:

      m_sci.surface            = m_surface;
      m_sci.minImageCount      = swapBufferCount;
      m_sci.imageFormat        = surfaceFormat;
      m_sci.imageColorSpace    = surfaceColorSpace;
      m_sci.imageExtent.width  = width;
      m_sci.imageExtent.height = height;
      m_sci.imageUsage         = imageUsage;
      m_sci.preTransform       = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR;  // <-- Here
      m_sci.compositeAlpha     = compositeAlpha;
      m_sci.presentMode        = s_presentMode[presentModeIdx].mode;
      m_sci.clipped            = VK_FALSE;

      result = vkCreateSwapchainKHR(device, &m_sci, allocatorCb, &m_swapChain);

But it's still crashing. Something is different though:

src\bgfx.cpp (1737): BGFX Reset back-buffer swap chain:
src\bgfx.cpp (1746): BGFX     2255x1217, format: RGBA8, numBackBuffers: 2, maxFrameLatency: 0
src\bgfx.cpp (1748): BGFX     [ ] MSAAx1
src\bgfx.cpp (1749): BGFX     [ ] Fullscreen
src\bgfx.cpp (1750): BGFX     [ ] V-sync
src\bgfx.cpp (1751): BGFX     [x] Max Anisotropy
src\bgfx.cpp (1752): BGFX     [ ] Capture
src\bgfx.cpp (1753): BGFX     [ ] Flush After Render
src\bgfx.cpp (1754): BGFX     [ ] Flip After Render
src\bgfx.cpp (1755): BGFX     [ ] sRGB Back Buffer
src\bgfx.cpp (1756): BGFX     [ ] Transparent Back Buffer
src\bgfx.cpp (1757): BGFX     [ ] HDR10
src\bgfx.cpp (1758): BGFX     [ ] Hi-DPI
src\bgfx.cpp (1759): BGFX     [ ] Depth Clamp
src\bgfx.cpp (1760): BGFX     [ ] Suspend
src\renderer_vk.cpp (7121): BGFX WARN Create swapchain error: vkDeviceWaitIdle() failed: -4: VK_ERROR_DEVICE_LOST
src\renderer_vk.cpp (7242): BGFX Create swapchain numSwapChainImages 2, minImageCount 2, BX_COUNTOF(m_backBufferColorImage) 10
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02852 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xdb2c5767 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (2256) is greater than framebuffer width (2254). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.x + renderArea.extent.width must be less than or equal to VkFramebufferCreateInfo::width the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02852)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02853 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0x1bd44466 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.y (0) + extent.height (1218) is greater than framebuffer height (1216). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.y + renderArea.extent.height must be less than or equal to VkFramebufferCreateInfo::height the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02853)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02852 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xdb2c5767 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (2256) is greater than framebuffer width (2254). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.x + renderArea.extent.width must be less than or equal to VkFramebufferCreateInfo::width the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02852)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02853 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0x1bd44466 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.y (0) + extent.height (1218) is greater than framebuffer height (1216). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.y + renderArea.extent.height must be less than or equal to VkFramebufferCreateInfo::height the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02853)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02852 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0xdb2c5767 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.x (0) + extent.width (2255) is greater than framebuffer width (2254). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.x + renderArea.extent.width must be less than or equal to VkFramebufferCreateInfo::width the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02852)
src\renderer_vk.cpp (718): BGFX ---E-          RenderPass, Validation, 0: Validation Error: [ VUID-VkRenderPassBeginInfo-pNext-02853 ] Object 0: handle = 0x3a6cbb0000000025, type = VK_OBJECT_TYPE_RENDER_PASS; Object 1: handle = 0xbb229e000000c3ed, type = VK_OBJECT_TYPE_FRAMEBUFFER; | MessageID = 0x1bd44466 | vkCmdBeginRenderPass(): pRenderPassBegin->renderArea offset.y (0) + extent.height (1217) is greater than framebuffer height (1216). The Vulkan spec states: If the pNext chain does not contain VkDeviceGroupRenderPassBeginInfo or its deviceRenderAreaCount member is equal to 0, renderArea.offset.y + renderArea.extent.height must be less than or equal to VkFramebufferCreateInfo::height the framebuffer was created with (https://vulkan.lunarg.com/doc/view/1.3.290.0/windows/1.3-extensions/vkspec.html#VUID-VkRenderPassBeginInfo-pNext-02853)
src\renderer_vk.cpp(8204): ASSERT VK_SUCCESS == vkresult -> vkQueueSubmit(m_queue, 1, &si, m_completedFence); VK error 0xfffffffc: VK_ERROR_DEVICE_LOST
src\renderer_vk.cpp (8204): BGFX FATAL 0x00000000: vkQueueSubmit(m_queue, 1, &si, m_completedFence); VK error 0xfffffffc: VK_ERROR_DEVICE_LOST

I'm on Windows BTW.

Confirmed that adding m_sci.preTransform = VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR; // <-- Here makes the validation error go away for me too for vulkan with Radeon driver.

bkaradzic commented 2 weeks ago

@pgruenbacher You're stomping over data initialized here: https://github.com/bkaradzic/bgfx/blob/cc789e83a69fddfb13f6cbeb89f43aa56dcfff9d/src/renderer_vk.cpp#L6736-L6739

pgruenbacher commented 2 weeks ago

hm ok i'll look into what my root cause was then.

pgruenbacher commented 2 weeks ago

yea nvm I was just mistaken, testing with latest bgfx and this merged PR resolved it for me.