maierfelix / webgpu

WebGPU for Node [Deprecated, Unmaintained]
MIT License
244 stars 17 forks source link

LD_LIBRARY_PATH on linux #14

Closed pjoe closed 4 years ago

pjoe commented 4 years ago

Trying to run the samples, it fails to load the libdawn_native.so. Setting LD_LIBRARY_PATH manually fixes this.

Debugging with LD_DEBUG=libs gives me:

(node:18056) ExperimentalWarning: The ESM module loader is experimental.
     18056:     find library=libdawn_native.so [0]; searching
     18056:      search path=/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/tls/haswell/x86_64:/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/tls/haswell:/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/tls/x86_64:/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/tls:/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/haswell/x86_64:/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/haswell:/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/x86_64:/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release             (RUNPATH from file /home/pelle/test/webgpu/node_modules/webgpu/generated/0.0.1/linux/build/Release/addon-linux.node)
     18056:       trying file=/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/tls/haswell/x86_64/libdawn_native.so
     18056:       trying file=/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/tls/haswell/libdawn_native.so
     18056:       trying file=/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/tls/x86_64/libdawn_native.so
     18056:       trying file=/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/tls/libdawn_native.so
     18056:       trying file=/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/haswell/x86_64/libdawn_native.so
     18056:       trying file=/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/haswell/libdawn_native.so
     18056:       trying file=/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/x86_64/libdawn_native.so
     18056:       trying file=/mnt/c/Users/maier/Desktop/LXSS_SHARED/webgpu/generated/0.0.1/linux/build/Release/libdawn_native.so
     18056:      search cache=/etc/ld.so.cache
     18056:      search path=/lib/x86_64-linux-gnu/tls/haswell/x86_64:/lib/x86_64-linux-gnu/tls/haswell:/lib/x86_64-linux-gnu/tls/x86_64:/lib/x86_64-linux-gnu/tls:/lib/x86_64-linux-gnu/haswell/x86_64:/lib/x86_64-linux-gnu/haswell:/lib/x86_64-linux-gnu/x86_64:/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu/tls/haswell/x86_64:/usr/lib/x86_64-linux-gnu/tls/haswell:/usr/lib/x86_64-linux-gnu/tls/x86_64:/usr/lib/x86_64-linux-gnu/tls:/usr/lib/x86_64-linux-gnu/haswell/x86_64:/usr/lib/x86_64-linux-gnu/haswell:/usr/lib/x86_64-linux-gnu/x86_64:/usr/lib/x86_64-linux-gnu:/lib/tls/haswell/x86_64:/lib/tls/haswell:/lib/tls/x86_64:/lib/tls:/lib/haswell/x86_64:/lib/haswell:/lib/x86_64:/lib:/usr/lib/tls/haswell/x86_64:/usr/lib/tls/haswell:/usr/lib/tls/x86_64:/usr/lib/tls:/usr/lib/haswell/x86_64:/usr/lib/haswell:/usr/lib/x86_64:/usr/lib          (system search path)
     18056:       trying file=/lib/x86_64-linux-gnu/tls/haswell/x86_64/libdawn_native.so
     18056:       trying file=/lib/x86_64-linux-gnu/tls/haswell/libdawn_native.so
     18056:       trying file=/lib/x86_64-linux-gnu/tls/x86_64/libdawn_native.so
     18056:       trying file=/lib/x86_64-linux-gnu/tls/libdawn_native.so
     18056:       trying file=/lib/x86_64-linux-gnu/haswell/x86_64/libdawn_native.so
     18056:       trying file=/lib/x86_64-linux-gnu/haswell/libdawn_native.so
     18056:       trying file=/lib/x86_64-linux-gnu/x86_64/libdawn_native.so
     18056:       trying file=/lib/x86_64-linux-gnu/libdawn_native.so
     18056:       trying file=/usr/lib/x86_64-linux-gnu/tls/haswell/x86_64/libdawn_native.so
     18056:       trying file=/usr/lib/x86_64-linux-gnu/tls/haswell/libdawn_native.so
     18056:       trying file=/usr/lib/x86_64-linux-gnu/tls/x86_64/libdawn_native.so
     18056:       trying file=/usr/lib/x86_64-linux-gnu/tls/libdawn_native.so
     18056:       trying file=/usr/lib/x86_64-linux-gnu/haswell/x86_64/libdawn_native.so
     18056:       trying file=/usr/lib/x86_64-linux-gnu/haswell/libdawn_native.so
     18056:       trying file=/usr/lib/x86_64-linux-gnu/x86_64/libdawn_native.so
     18056:       trying file=/usr/lib/x86_64-linux-gnu/libdawn_native.so
     18056:       trying file=/lib/tls/haswell/x86_64/libdawn_native.so
     18056:       trying file=/lib/tls/haswell/libdawn_native.so
     18056:       trying file=/lib/tls/x86_64/libdawn_native.so
     18056:       trying file=/lib/tls/libdawn_native.so
     18056:       trying file=/lib/haswell/x86_64/libdawn_native.so
     18056:       trying file=/lib/haswell/libdawn_native.so
     18056:       trying file=/lib/x86_64/libdawn_native.so
     18056:       trying file=/lib/libdawn_native.so
     18056:       trying file=/usr/lib/tls/haswell/x86_64/libdawn_native.so
     18056:       trying file=/usr/lib/tls/haswell/libdawn_native.so
     18056:       trying file=/usr/lib/tls/x86_64/libdawn_native.so
     18056:       trying file=/usr/lib/tls/libdawn_native.so
     18056:       trying file=/usr/lib/haswell/x86_64/libdawn_native.so
     18056:       trying file=/usr/lib/haswell/libdawn_native.so
     18056:       trying file=/usr/lib/x86_64/libdawn_native.so
     18056:       trying file=/usr/lib/libdawn_native.so
     18056:
internal/modules/cjs/loader.js:1197
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: libdawn_native.so: cannot open shared object file: No such file or directory
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1197:18)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
    at Module.require (internal/modules/cjs/loader.js:1036:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at Object.<anonymous> (/home/pelle/test/webgpu/node_modules/webgpu/index.js:13:18)
    at Module._compile (internal/modules/cjs/loader.js:1147:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10)
    at Module.load (internal/modules/cjs/loader.js:996:32)
    at Function.Module._load (internal/modules/cjs/loader.js:896:14)
pjoe commented 4 years ago

Unfortunately even with LD_LIBRARY_PATH set manually I get a segfault when tryig the raytracing sample :cry:

pjoe commented 4 years ago

Trying hello-triangle.mjs:

$ LD_LIBRARY_PATH=`pwd`/node_modules/webgpu/generated/0.0.1/linux/build/Release node hello-triangle.mjs 
(node:18425) ExperimentalWarning: The ESM module loader is experimental.
X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  149 ()
  Minor opcode of failed request:  4
  Resource id in failed request:  0x300000d
  Serial number of failed request:  197
  Current serial number in output stream:  203

FYI: on ubuntu 19.10, laptop with RTX-2070, driver nvidia-435

maierfelix commented 4 years ago

Thanks for reporting, I'll try to resolve this ASAP

dcerisano commented 4 years ago

The README has directions for setting the LD_LIBRARY_PATH, and installing libvulkan. Please report your version of libvulkan.

pjoe commented 4 years ago

This is what dpkg tells me:

ii  libvulkan1:amd64 1.1.114.0-1  amd64        Vulkan loader library

I upgraded to webgpu 0.1.4, but still getting error on hello-triangle, running like this:

$ LD_LIBRARY_PATH=`pwd`/node_modules/webgpu/generated/0.0.1/linux/build/Release node hello-triangle.mjs 
(node:6008) ExperimentalWarning: The ESM module loader is experimental.
X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  149 ()
  Minor opcode of failed request:  4
  Resource id in failed request:  0x3c0000d
  Serial number of failed request:  197
  Current serial number in output stream:  203

Using node v13.11.0 if that matters.

vulkaninfo seems to return ok info, but vkcube just show a black window (no crash though. I am using an optimus laptop (both nVIDA and Intel GPU) - dunno if that may be related.

pjoe commented 4 years ago

Found this related to optimus: https://forums.developer.nvidia.com/t/on-optimus-system-vulkan-tries-to-use-integrated-intel-graphics-and-fails-with-a-blank-black-window/79257.

After disabling the Intel icd, then hello-triangle seems to work, showing a nice red triangle.

Trying to run the ray-tracing sample almost crashed the whole system :S

The ubuntu crash reporter show: node crashed with SIGSEGV in dawn_native::vulkan::Buffer::TransitionUsageNow()

Guessing this may be related to drivers. The nVidia control panel show driver version to be 435.21

maierfelix commented 4 years ago

The latest npm package should fix this now.

@pjoe The RT example is broken on linux and I'm currently investigating into this. Can this issue be closed now?

pjoe commented 4 years ago

I really don't think it should be necessary to set library path when just consuming the npm module. I've never had to deal with library path before with other npm modules.

Maybe it's a matter of the right rpath, dunno if it helps but found this: https://github.com/nodejs/node-v0.x-archive/issues/25627#issuecomment-172804743

pjoe commented 4 years ago

@dcerisano I already had libvulkan installed.

pjoe commented 4 years ago

Also if you look at the LD_DEBUG output, it is not libvulkan, but libdawn_native it is failing to find. And it is searching for paths that looks local to Felix's machine, which doesn't seem ideal to me :)

What then worked for me was to point LD_LIBRARY_PATH like this:

LD_LIBRARY_PATH=`pwd`/node_modules/webgpu/generated/0.0.1/linux/build/Release

i.e. pointing to a folder inside the installed node module. This I really don't think should be necessary.

pjoe commented 4 years ago

I think this can be fixed with the right rpath setting (probably here: https://github.com/maierfelix/webgpu/blob/master/generated/0.0.1/linux/binding.gyp#L102).

maierfelix commented 4 years ago

I had this issue with past projects too, .gyp files are horrible to work with. I'm not sure what's the best fix for this, but eventually by setting the environment variable manually in the index.js file in this project?

Something like this:

if (process.platform === "linux") {
  if (!process.env.hasOwnProperty("LD_LIBRARY_PATH ")) {
    process.env.LD_LIBRARY_PATH = require("path").join(__dirname, `${generatedPath}/build/Release/`);
  }
}
pjoe commented 4 years ago

Unfortunately I don't think it works to set LD_LIBRARY_PATH like that - at least I was unable to get that working in this case, when I originally tried. Anyway I will try to see if this can't be handled by tweaking rpath. Will do a PR if i get it working, but suggest we keep this issue open for now.

maierfelix commented 4 years ago

Should be fixed in 0.1.6, can you approve @pjoe ?

pjoe commented 4 years ago

Unfortunately still not working with 0.1.7.

Relevant output from LD_DEBUG:

(node:7148) ExperimentalWarning: The ESM module loader is experimental.                    
      7148:     find library=libdawn_native.so [0]; searching                              
      7148:      search path=/home/user/Documents/GitHub/webgpu/generated/0.0.1/linux/build
/Release/tls/haswell/x86_64:/home/user/Documents/GitHub/webgpu/generated/0.0.1/linux/build/
Release/tls/haswell:/home/user/Documents/GitHub/webgpu/generated/0.0.1/linux/build/Release/
tls/x86_64:/home/user/Documents/GitHub/webgpu/generated/0.0.1/linux/build/Release/tls:/home
/user/Documents/GitHub/webgpu/generated/0.0.1/linux/build/Release/haswell/x86_64:/home/user
/Documents/GitHub/webgpu/generated/0.0.1/linux/build/Release/haswell:/home/user/Documents/G
itHub/webgpu/generated/0.0.1/linux/build/Release/x86_64:/home/user/Documents/GitHub/webgpu/
generated/0.0.1/linux/build/Release             (RPATH from file /home/pelle/test/webgpu/no
de_modules/webgpu/generated/0.0.1/linux/build/Release/addon-linux.node)

Please re-open