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

Insert vkDeviceWaitIdle to prevent VK_DEVICE_LOST. #3363

Merged
merged 1 commit into from
Oct 8, 2024

Conversation

mcourteaux
Copy link
Contributor

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: mpv-player/mpv#8360 (comment)

@mcourteaux
Copy link
Contributor Author

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

@bkaradzic bkaradzic merged commit fdb09ca into bkaradzic:master Oct 8, 2024
11 checks passed
@jay3d
Copy link
Contributor

jay3d commented Oct 8, 2024

@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
Copy link
Contributor

jay3d commented Oct 9, 2024

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
Copy link
Contributor Author

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
Copy link
Contributor

jay3d commented Oct 10, 2024

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

@mcourteaux
Copy link
Contributor Author

mcourteaux commented Oct 10, 2024

@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?

  • Should there be a brief instance where there are two swapchains?
  • Should we somehow flush the frames in flight, then switch out the swapchain, and spin back up?

I'm gathering clues:

  • https://vulkan-tutorial.com/Drawing_a_triangle/Swap_chain_recreation

    However, the disadvantage of this approach is that we need to stop all rendering before creating the new swap chain. It is possible to create a new swap chain while drawing commands on an image from the old swap chain are still in-flight. You need to pass the previous swap chain to the oldSwapChain field in the VkSwapchainCreateInfoKHR struct and destroy the old swap chain as soon as you've finished using it.

  • https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VkSwapchainCreateInfoKHR.html has oldSwapchain stating:

    Providing a valid oldSwapchain may aid in the resource reuse, and also allows the application to still present any images that are already acquired from it.

  • https://vulkan-tutorial.com/Drawing_a_triangle/Swap_chain_recreation#comment-5042868630

    Posting in case someone is getting DEVICE_LOST on WaitIdle when recreating swapchains.

    I noticed later on in the tutorial that vkDeviceWaitIdle() would sometimes fail with DEVICE_LOST before recreating the swapchain when I resized (glfw/rust with ash/ubuntu/nvidia) but work most of the time.

    When I dragged the edge of the window, I would get swapchain out-of-date results every frame (even if I didn't release the mouse) and the swapchain would be recreated every frame with small incremental changes in size and then suddenly it would fail. I tried reproducing it on my windows machine (also nvidia but newer gpu) where resize failed directly (but only when releasing the mouse button). On windows, I would also get a "vkCreateSwapchainKHR: internal drawable creation failed" from the validation layers.
    I fixed both of the issues by reusing the old swapchain!

    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.

    Note that I was always calling WaitIdle before creating/destroying swapchains so I'm assuming the wait idle somehow did not wait properly? I also tried to wait on all outstanding fences before calling WaitIdle, but it did not help. Anyhow, reusing the old swapchain fixes it!

    This comment seems relevant, but unfortunately, I don't really understand what the explained solution is.

  • bgfx/src/renderer_vk.cpp

    Lines 2808 to 2823 in dd4199b

    // Note: m_needToRefreshSwapchain is deliberately ignored when deciding whether to
    // recreate the swapchain because it can happen several frames before submit is called
    // with the new resolution.
    //
    // Instead, vkAcquireNextImageKHR and all draws to the backbuffer are skipped until
    // the window size is updated. That also fixes a related issue where VK_ERROR_OUT_OF_DATE_KHR
    // is returned from vkQueuePresentKHR when the window doesn't exist anymore, and
    // vkGetPhysicalDeviceSurfaceCapabilitiesKHR fails with VK_ERROR_SURFACE_LOST_KHR.
    if (false
    || m_resolution.format != _resolution.format
    || m_resolution.width != _resolution.width
    || m_resolution.height != _resolution.height
    || m_resolution.reset != flags
    || m_backBuffer.m_swapChain.m_needToRecreateSurface)
    {

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

@pezcode What are your thoughts on the matter?

@bkaradzic
Copy link
Owner

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
Copy link
Contributor Author

mcourteaux commented Oct 10, 2024

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
Copy link
Contributor

pezcode commented Oct 10, 2024

I thought the code already force-waits on a fence here:

// can't delay-delete the surface, since there can only be one swapchain per surface

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
Copy link
Contributor

pezcode commented Oct 10, 2024

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:

m_sci.oldSwapchain = VK_NULL_HANDLE;

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
Copy link
Owner

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
Copy link
Contributor

jay3d commented Oct 10, 2024

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
Copy link
Contributor Author

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
Copy link
Owner

I was able to reproduce

In unmodified examples from repo?

@bkaradzic
Copy link
Owner

@pgruenbacher
Copy link
Contributor

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
Copy link
Owner

@pgruenbacher You're stomping over data initialized here:

bgfx/src/renderer_vk.cpp

Lines 6736 to 6739 in cc789e8

m_sci.preTransform = BX_ENABLED(BX_PLATFORM_NX)
? VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR
: VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR
;

@pgruenbacher
Copy link
Contributor

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

@pgruenbacher
Copy link
Contributor

pgruenbacher commented Nov 9, 2024

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

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.

Crash on resize: Nvidia RTX 4090 + Vulkan + Linux
5 participants