Qt-5.14.0:QML 下的 Vulkan 导致 std::system_error:: 互斥锁失败

Posted

技术标签:

【中文标题】Qt-5.14.0:QML 下的 Vulkan 导致 std::system_error:: 互斥锁失败【英文标题】:Qt-5.14.0: Vulkan under QML causes std::system_error:: mutex lock failed 【发布时间】:2020-02-29 14:55:00 【问题描述】:

Vulkan under QML 示例在崩溃之前最多运行几秒钟并出现以下错误:

libc++abi.dylib: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument

虽然动画在运行过程中看起来正确,但 QML 标签显示不正确:

我正在使用 MoltenVK 1.1.130 (LunarG Vulkan SDK) 和 Qt 5.14.0 运行 macOS Catalina。我也尝试过 MoltenVK 1.2.131,结果相同。在启用 MVK_LOG_LEVEL_INFO 的情况下使用 MoltenVK 时,每帧打印两次以下消息:

[mvk-info] vkCreateMacOSSurfaceMVK(): You are not calling this function from the main thread. NSView should only be accessed from the main thread. When using this function outside the main thread, consider passing the CAMetalLayer itself in VkMacOSSurfaceCreateInfoMVK::pView, instead of the NSView.

问题

有人知道是什么原因造成的吗?这是一个错误吗?有人成功运行过这个例子吗?

虽然 Qt 的 Vulkan 集成已损坏,但 MVK 错误消息使它看起来像:vkCreateMacOSSurfaceMVK 不仅每帧调用两次,而且似乎也是从渲染线程调用的 (不是 GUI 线程/主线程)。

详情

为了将 Qt 与 Vulkan 一起使用,您必须从源代码编译 Qt 并提供 Vulkan 头文件。我用来编译Qt的配置调用是:

../qt5/configure -developer-build -skip qtquick3d -skip qtwebengine -opensource -nomake examples -nomake tests -confirm-license -vulkan -I $VULKAN_SDK/../MoltenVK/include -L $VULKAN_SDK/lib

我的环境变量是根据 LunarG 文档设置的:

export VULKAN_SDK="$HOME/SDK/vulkansdk-macos-1.1.130.0/macOS"
export PATH="$VULKAN_SDK/bin:$PATH"
export DYLD_LIBRARY_PATH="$VULKAN_SDK/lib:$DYLD_LIBRARY_PATH"
export VK_ICD_FILENAMES="$VULKAN_SDK/etc/vulkan/icd.d/MoltenVK_icd.json"
export VK_LAYER_PATH="$VULKAN_SDK/etc/vulkan/explicit_layer.d"
export VK_INSTANCE_LAYERS="VK_LAYER_KHRONOS_validation"

export QT_VULKAN_LIB="$VULKAN_SDK/lib/libMoltenVK.dylib"

(Qt 需要 QT_VULKAN_LIBdlopen 的库。)

lldb 回溯:

[mvk-info] vkCreateMacOSSurfaceMVK(): You are not calling this function from the main thread. NSView should only be accessed from the main thread. When using this function outside the main thread, consider passing the CAMetalLayer itself in VkMacOSSurfaceCreateInfoMVK::pView, instead of the NSView.
[mvk-info] vkCreateMacOSSurfaceMVK(): You are not calling this function from the main thread. NSView should only be accessed from the main thread. When using this function outside the main thread, consider passing the CAMetalLayer itself in VkMacOSSurfaceCreateInfoMVK::pView, instead of the NSView.
libc++abi.dylib: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument
Process 83453 stopped
* thread #10, name = 'QSGRenderThread', stop reason = signal SIGABRT
    frame #0: 0x00007fff648c57fa libsystem_kernel.dylib`__pthread_kill + 10
libsystem_kernel.dylib`__pthread_kill:
->  0x7fff648c57fa <+10>: jae    0x7fff648c5804            ; <+20>
    0x7fff648c57fc <+12>: movq   %rax, %rdi
    0x7fff648c57ff <+15>: jmp    0x7fff648bfa89            ; cerror_nocancel
    0x7fff648c5804 <+20>: retq   
Target 0: (main) stopped.
(lldb) frame info
frame #0: 0x00007fff648c57fa libsystem_kernel.dylib`__pthread_kill + 10
(lldb) frame variable
(lldb) bt
* thread #10, name = 'QSGRenderThread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff648c57fa libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff64982bc1 libsystem_pthread.dylib`pthread_kill + 432
    frame #2: 0x00007fff6484ca1c libsystem_c.dylib`abort + 120
    frame #3: 0x00007fff618e6be8 libc++abi.dylib`abort_message + 231
    frame #4: 0x00007fff618e6d84 libc++abi.dylib`demangling_terminate_handler() + 238
    frame #5: 0x00007fff63412792 libobjc.A.dylib`_objc_terminate() + 104
    frame #6: 0x00007fff618f3dc7 libc++abi.dylib`std::__terminate(void (*)()) + 8
    frame #7: 0x00007fff618f3d79 libc++abi.dylib`std::terminate() + 41
    frame #8: 0x0000000103942439 libQt5Core_debug.5.dylib`qTerminate() at qglobal.cpp:3333:5
    frame #9: 0x000000010341f5f8 libQt5Core_debug.5.dylib`QThreadPrivate::start(arg=0x000000011721cfb0) at qthread_unix.cpp:354:9
    frame #10: 0x00007fff64982e65 libsystem_pthread.dylib`_pthread_start + 148
    frame #11: 0x00007fff6497e83b libsystem_pthread.dylib`thread_start + 15

【问题讨论】:

听起来你可能想报告一个 Qt 错误.. @JesperJuhl 可能不是 Qt。崩溃后我刚刚收到完全相同的错误消息。 LWJGL、GLFW、Vulkan、MoltenVK、金属。在辅助线程上渲染。调整窗口大小时发生。这可能不是 Qt 中的错误,而是 Metal 或 MoltenVK 中的错误。 @Andreas-he-her- 这很有趣。您是在辅助线程上调用vkCreateMacOSSurfaceMVK 吗? @mkl 不,我无权访问该函数,但 GLFW 可能从 glfwCreateWindowSurface 中调用它,我确实在辅助线程上调用它。它的文档指出:This function may be called from any thread. For synchronization details of Vulkan objects, see the Vulkan specification. 我从不多次调用它,这在设置代码中。在这次突然的崩溃之前从未有过任何问题。 @Andreas-he-her- 崩溃是否可重现? 【参考方案1】:

我已报告该问题:QTBUG-82600

该修复已合并到 Qt 5.15.0 beta2 中。尽管不再发生崩溃,但文本仍然被破坏。对此的修复被推迟到 Qt6:QTBUG-83072

【讨论】:

“我已经报告了这个问题” - ?

以上是关于Qt-5.14.0:QML 下的 Vulkan 导致 std::system_error:: 互斥锁失败的主要内容,如果未能解决你的问题,请参考以下文章

Vulkan Tutorial 01 开发环境搭建之Windows

Vulkan Tutorial 01 开发环境搭建之Windows

Quick QML 一个QML调用另一个文件夹下的QML方法

QML下的OpenGL

OpenGL Core Profile 下的 QML 标签崩溃 App

QML 中的 5 大布局