flatpak / flatpak

Linux application sandboxing and distribution framework
https://flatpak.org
GNU Lesser General Public License v2.1
4.17k stars 397 forks source link

[Bug]: Trying to create a Vulkan instance in a Node process always returns `VK_ERROR_INCOMPATIBLE_DRIVER` #5420

Open CommandMC opened 1 year ago

CommandMC commented 1 year ago

Checklist

Flatpak version

1.15.4

What Linux distribution are you using?

Arch Linux

Linux distribution version

No response

What architecture are you using?

x86_64

How to reproduce

  1. Clone https://github.com/CommandMC/electron-sample-app
  2. Install dependencies (npm i), try to start the app. Note the message Successfully created Vulkan instance! in the console
  3. Build & install a Flatpak version of the app (flatpak-builder ...), run the installed application
  4. See that instance creation fails with a VkResult of -9 (VK_ERROR_INCOMPATIBLE_DRIVER)

Expected Behavior

Instance creation should succeed

Actual Behavior

Instance creation does not succeed

Additional Information

Using other non-Node tools to verify Vulkan functionality (vulkaninfo / adding Python into a sandbox & trying to call the same function with its ctypes module) works, so this must be some specific interaction between NodeJS and Flatpak

CommandMC commented 1 year ago

I've now reproduced this issue with a napi-rs project as well, so this doesn't seem library-specific anymore

BigBoyBarney commented 2 months ago

@CommandMC Have you been able to figure out a solution or is this a flatpak moment?

CommandMC commented 2 months ago

Sadly no. We've ended up bundling a small Rust CLI app with our program, as we just needed some device information

bahaaTuffaha commented 2 months ago

@CommandMC Have you been able to figure out a solution or is this a flatpak moment?

Found any solution to this? I looked into flatpak list and it has mesa and some nvidia drivers could it be the problem? Note I'm using electron-vite and window works perfectly.

BigBoyBarney commented 2 months ago

Yeah flatpak has its own copy of mesa, which I thought was the issue, since it couldn't find the system vulkan drivers. I gave up after trying trying to redirect VK_ICD_FILENAMES, VK_DRIVER_FILES and NCNN_VULKAN_DRIVER to system ones with export VK_DRIVER_FILES=/usr/lib/$(uname -m)-linux-gnu/GL/vulkan/icd.d to no avail. :( If you ever find a solution I'd be very interested 🤣

bahaaTuffaha commented 2 months ago

Yeah flatpak has its own copy of mesa, which I thought was the issue, since it couldn't find the system vulkan drivers. I gave up after trying trying to redirect VK_ICD_FILENAMES, VK_DRIVER_FILES and NCNN_VULKAN_DRIVER to system ones with export VK_DRIVER_FILES=/usr/lib/$(uname -m)-linux-gnu/GL/vulkan/icd.d to no avail. :( If you ever find a solution I'd be very interested 🤣

Aha I will try to reinstall the drivers and give it couple more tries if this keeps happening we have to start learning Rust 😂😂

bahaaTuffaha commented 2 months ago

I think I've got half of the puzzle from here: https://stackoverflow.com/a/77916976/13734642

I installed the nvidia-container-toolkit then most of the issues disappeared except these 2: Warning: loader_scanned_icd_add: Could not get 'vkCreateInstance' via 'vk_icdGetInstanceProcAddr' for ICD libGLX_nvidia.so.0 Warning: terminator_CreateInstance: Failed to CreateInstance in ICD 3. Skipping ICD.