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

Minimal example does not work on NixOS #4792

Open
VirgileHenry opened this issue Nov 28, 2023 · 8 comments
Open

Minimal example does not work on NixOS #4792

VirgileHenry opened this issue Nov 28, 2023 · 8 comments
Labels
area: documentation Documentation for crate items, public or private help required We need community help to make this happen. type: enhancement New feature or request

Comments

@VirgileHenry
Copy link

Description

I tried running a minimal WGPU example, as well as the hello_triangle example under NixOS. both fails.
I have an Nvidia gtx 3050 (driver version 535.113.01) as well as an integrated intel GPU.
I tried on my own NixOS setup, as well as on a NixOS fresh install using the gnome / wayland ISO.

Repro steps

Expected vs observed behavior

Expected was the hello_triangle (or my minimal app setup), observed is the following error

Extra materials

The error is the following :

thread 'main' panicked at <my home folder>/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.18.1/src/gles/egl.rs:751:18:
called `Result::unwrap()` on an `Err` value: BadAlloc
stack backtrace:
   0: rust_begin_unwind
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
   1: core::panicking::panic_fmt
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/result.rs:1652:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/result.rs:1077:23
   4: <wgpu_hal::gles::egl::Instance as wgpu_hal::Instance<wgpu_hal::gles::Api>>::init
             at /home/eclipse/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-hal-0.18.1/src/gles/egl.rs:744:31
   5: wgpu_core::instance::Instance::new::init
             at /home/eclipse/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-core-0.18.1/src/instance.rs:83:32
   6: wgpu_core::instance::Instance::new
             at /home/eclipse/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-core-0.18.1/src/instance.rs:114:17
   7: wgpu_core::global::Global<G>::new
             at /home/eclipse/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-core-0.18.1/src/global.rs:36:23
   8: <wgpu::backend::direct::Context as wgpu::context::Context>::init
             at /home/eclipse/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.18.0/src/backend/direct.rs:584:14
   9: wgpu::Instance::new
             at /home/eclipse/.cargo/registry/src/index.crates.io-6f17d22bba15001f/wgpu-0.18.0/src/lib.rs:1772:32
  10: morpheus::main
             at ./src/main.rs:12:20
  11: core::ops::function::FnOnce::call_once
             at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/ops/function.rs:250:5

Platform
I'm running NixOS unstable, but the same have been experienced on NixOS 23.05 wayland / gnome ditribution. This was done with the latest version of wgpu.

@cwfitzgerald
Copy link
Member

I'm not really sure how to debug this, I know NixOS is generally pretty hard to get graphical stuff working.

Make sure you have the EGL available, the appropriate mesa drivers, etc.

This is probably EGL looking for something it can't find.

@VirgileHenry
Copy link
Author

I managed to make a shell that expose the libs used by WGPU, it woks so far.
I'm putting it here in case anyone needs it in the future :

{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    libxkbcommon
    libGL
    # WINIT_UNIX_BACKEND=wayland
    wayland
  ];
  LD_LIBRARY_PATH = "${pkgs.libxkbcommon}/lib:${pkgs.libGL}/lib:${pkgs.wayland}/lib";
  RUST_BACKTRACE=1;
}

I'll keep learning WGPU, and I'll update it if there are other needs. Cheers!

@teoxoy
Copy link
Member

teoxoy commented Nov 29, 2023

It would be worth documenting this in the wiki or on the readme. @cwfitzgerald thoughts?

@VirgileHenry
Copy link
Author

This works on my current setup, but I thing I'll need to try it again on a plain NixOS install to check it is a sound solution. I can't do it right now, but I can take the time to do proper testing and creating the minimal nix shell for this.

However, I'm still learning NixOS, so I'm trying my best but I'm unsure I am the best person to do this.

@cwfitzgerald
Copy link
Member

Yeah this would be good to document in the wiki once we figure it out!

@zh4ngx
Copy link

zh4ngx commented Dec 25, 2023

Struggling with NixOS + wgpu as well. Do you have a good understanding as to why LD_LIBRARY_PATH needs manual intervention?

Also, were you able to get a larger flake.nix that you can share? I'm still working on mine. Seems like this would be a great template for wgpu-based projects.

@kaimast
Copy link

kaimast commented Jan 31, 2024

Can you try forcing X11? There are still plenty of issues with NVIDIA and Wayland, e.g., #4775.

@techieAgnostic
Copy link

Tangentially related but on an Intel Integrated GPU on NixOS, my problem was not having VK_ICD_FILENAMES set properly, I set it to /run/opengl-driver/share/vulkan/icd.d/intel_icd.x86_64.json which worked.

I tried each of the files in that folder to find the one I needed

@teoxoy teoxoy added type: enhancement New feature or request area: documentation Documentation for crate items, public or private help required We need community help to make this happen. labels Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: documentation Documentation for crate items, public or private help required We need community help to make this happen. type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants