Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-82600

Vulkan under QML example causes std::system_error:: mutex lock failed with MoltenVK

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.14.0
    • Fix Version/s: 5.15.0 Beta2
    • Component/s: GUI: Vulkan, Qt RHI
    • Labels:
      None
    • Environment:
      macOS Catalina 10.15.3 on MacBook Pro with Intel Iris Plus Graphics 655 1536 MB

      MoltenVK 1.1.130 and MoltenVK 1.2.131 (from the corresponding LunarG Vulkan SDKs).
    • Platform/s:
      macOS

      Description

      (Cross-posted on stackexchange.)

      The Vulkan under QML example runs for at most a couple of seconds before crashing with the following error:

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

      While the animation looks correct during operation, the QML label is not displayed correctly (see attached image).

      I'm running macOS Catalina with MoltenVK 1.1.130 (LunarG Vulkan SDK) and Qt 5.14.0. I've also tried MoltenVK 1.2.131, with the same result. When using MoltenVK with MVK_LOG_LEVEL_INFO enabled, the following message is printed twice every frame:

      [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.
      

      The MVK error message makes it appear a though the Vulkan integration is broken: Not only is vkCreateMacOSSurfaceMVK called twice every frame, but it also seems to be called from the render thread (not the GUI thread/main thread).

      In order to even use Qt with Vulkan, you must compile Qt from source and provide the Vulkan headers. The configuration call I used to compile Qt is:

      ../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
      

      My environment variables are set according to the LunarG documentation:

      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"
      

      Backtrace:

      [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
      

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            lagocs Laszlo Agocs
            Reporter:
            maltekliemann Malte Kliemann
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes