mach icon indicating copy to clipboard operation
mach copied to clipboard

black window on nixos+nvidia+vulkan

Open ozkutuk opened this issue 2 years ago • 9 comments

I am trying to run the example as explained in the project's landing page. However, the triangle is not displayed: image

Corresponding terminal output:

$ zig build run-example
found Vulkan backend on Discrete GPU adapter: NVIDIA GeForce GTX 1060 with Max-Q Design, NVIDIA: 510.54

I am on NixOS, so I have prepared a Nix flake to satisfy the system dependencies (i.e. X11 and Vulkan). I think there may be an implicit dependency I didn't capture within the Nix flake that does not cause a failure but is necessary to display the triangle? Again, nothing else is reported through standard output except from the above, so I couldn't go any further. If it would help, I can provide the Nix flake I am trying to get this working with.

$ zig version
0.10.0-dev.1453+9f25c8140

ozkutuk avatar Mar 27 '22 23:03 ozkutuk

Hmm, sorry to hear that - it found the Vulkan driver, so I would've expected it to just work.

Could you try with GPU_BACKEND=opengl zig build run-example ?

I'd also be curious if you can install a vulkan-tools package and see if vkcube runs on your system or not.

emidoots avatar Mar 28 '22 00:03 emidoots

Interestingly enough, with GPU_BACKEND=opengl it stills picks up Vulkan backend but rather than displaying black window, it immediately segfaults.

$ GPU_BACKEND=opengl zig build run-example
found Vulkan backend on Discrete GPU adapter: NVIDIA GeForce GTX 1060 with Max-Q Design, NVIDIA: 510.54
Segmentation fault at address 0x2100000620
???:?:?: 0x7f73345bfbdb in ??? (???)

vkcube works without any issues.

ozkutuk avatar Mar 28 '22 16:03 ozkutuk

OK, I see, it looks like we've got a bug in the gpu/ example with the OpenGL backend detection - I can repro on my Linux machine and am working on a fix.

Could you see if this other example works for you?

cd mach/gpu-dawn/
GPU_BACKEND=opengl zig build run-dawn-example

emidoots avatar Mar 29 '22 08:03 emidoots

That still reports Vulkan being found, and the output is a black window as it was the case initially:

$ GPU_BACKEND=opengl zig build run-dawn-example
found Vulkan adapter: NVIDIA GeForce GTX 1060 with Max-Q Design, NVIDIA: 510.54
Warning: clearColor is deprecated, prefer using clearValue instead.

If I remove the Vulkan stuff from the running environment through Nix, it fails to find Vulkan and panics:

$ GPU_BACKEND=opengl zig build run-dawn-example
Error: Couldn't load Vulkan. Searched /home/ozkutuk/dev/mach/gpu-dawn/zig-out/bin/libvulkan.so.1, /home/ozkutuk/dev/mach/gpu-dawn/zig-out/bin/libvulkan.so.1, libvulkan.so.1.
    at operator() (/home/runner/work/mach-gpu-dawn/mach-gpu-dawn/libs/dawn/src/dawn/native/vulkan/BackendVk.cpp:198)
    at Initialize (/home/runner/work/mach-gpu-dawn/mach-gpu-dawn/libs/dawn/src/dawn/native/vulkan/BackendVk.cpp:203)
    at Create (/home/runner/work/mach-gpu-dawn/mach-gpu-dawn/libs/dawn/src/dawn/native/vulkan/BackendVk.cpp:165)
    at operator() (/home/runner/work/mach-gpu-dawn/mach-gpu-dawn/libs/dawn/src/dawn/native/vulkan/BackendVk.cpp:420)

thread 5452 panic: reached unreachable code
/nix/store/pimq56ywpwy8wargg8byj29yydd70gyw-zig-0.10.0-dev.1453+9f25c8140/lib/std/debug.zig:234:14: 0x477358 in std.debug.assert (dawn-example)
    if (!ok) unreachable; // assertion failure
             ^
/home/ozkutuk/dev/mach/gpu-dawn/src/dawn/sample_utils.zig:92:11: 0x479e5d in sample_utils.setup (dawn-example)
    assert(backend_adapter != null);
          ^
/home/ozkutuk/dev/mach/gpu-dawn/src/dawn/hello_triangle.zig:10:41: 0x478522 in main (dawn-example)
    const setup = try sample_utils.setup(allocator);
                                        ^
/nix/store/pimq56ywpwy8wargg8byj29yydd70gyw-zig-0.10.0-dev.1453+9f25c8140/lib/std/start.zig:575:37: 0x487017 in std.start.callMain (dawn-example)
            const result = root.main() catch |err| {
                                    ^
/nix/store/pimq56ywpwy8wargg8byj29yydd70gyw-zig-0.10.0-dev.1453+9f25c8140/lib/std/start.zig:509:12: 0x47b467 in std.start.callMainWithArgs (dawn-example)
    return @call(.{ .modifier = .always_inline }, callMain, .{});
           ^
/nix/store/pimq56ywpwy8wargg8byj29yydd70gyw-zig-0.10.0-dev.1453+9f25c8140/lib/std/start.zig:474:12: 0x47b212 in std.start.main (dawn-example)
    return @call(.{ .modifier = .always_inline }, callMainWithArgs, .{ @intCast(usize, c_argc), c_argv, envp });

ozkutuk avatar Mar 29 '22 10:03 ozkutuk

@ozkutuk I can't believe I messed this up, so sorry, the env var is WGPU_BACKEND not GPU_BACKEND when running from the gpu-dawn/ directory, my bad! The correct commands are:

cd mach/gpu-dawn/
WGPU_BACKEND=opengl zig build run-dawn-example

Would be very curious to know if that works on your system or not.


In case it helps, the following shell.nix is what Mitchell Hashimoto needed (putting X11/GL on the LD_LIBRARY_PATH):

with import <nixpkgs> {};

pkgs.mkShell {
  nativeBuildInputs = with pkgs; [
    xorg.libX11
    libGL

    vulkan-tools
    glxinfo
  ];

  LD_LIBRARY_PATH="${pkgs.vulkan-loader}/lib:${pkgs.libGL}/lib";
}

I'd be keen to know if that fixes the black window issue or not. If not, it's likely the black screen issue is a bug in Dawn upstream

emidoots avatar Mar 30 '22 19:03 emidoots

It works! I have a somewhat similar Nix config, though I have migrated to Nix flakes so here is my flake.nix in case anyone else needs (it also provides a 0.10.x version of the Zig compiler through zig-overlay):

{
  description = "Mach is a game engine & graphics toolkit for the future.";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    zig.url = "github:roarkanize/zig-overlay";
  };

  outputs = { self, zig, nixpkgs }:
    let
      pkgs = nixpkgs.legacyPackages.x86_64-linux;
      lib = pkgs.lib;
    in {
      devShell.x86_64-linux = pkgs.mkShell {
        packages = [
          # As of 2022-03-20, 0.10.x is only available in nightly builds.
          # Any build with 0.10.x is okay.
          zig.packages.x86_64-linux.master."2022-03-20"
          pkgs.xorg.libX11
          pkgs.libGL
        ];
        LD_LIBRARY_PATH = "${lib.makeLibraryPath [ pkgs.libGL ]}";
      };
    };
}

I initially had Vulkan related parts in the config, but later removed them as it didn't work for me (I'm still curious as to why it didn't though).

ozkutuk avatar Mar 30 '22 19:03 ozkutuk

Just to clarify, was it the OpenGL backend that worked? Or Vulkan also worked after that?

emidoots avatar Mar 30 '22 21:03 emidoots

OpenGL backend worked with the correct commands you have provided. Unfortunately, still no triangle with the Vulkan backend.

ozkutuk avatar Mar 30 '22 21:03 ozkutuk

Thanks! I fixed the issue where GPU_BACKEND in the standard gpu/ example was not working, so this should work now.

Regarding Vulkan, I see two possibilities here:

  1. This is a NixOS-specific issue. If so, it would have to be a configuration difference between vkcube (perhaps it's dynamically linking vulkan?) and our binary (which loads vulkan at runtime, not dynamically linked.) Perhaps ${pkgs.vulkan-loader}/lib missing from your LD_LIBRARY_PATH could make a difference?
  2. This is a bug in Dawn <-> your graphics driver. I would find this really surprising, because I have verified this all works on laptop NVIDIA GPU drivers very similar to yours (on Elementary OS.) - and your GPU is similarly capable to mine.

Unfortunately, short of installing NixOS on my laptop I'm not sure there's any other way to debug here. I may try that in the future but it'd be a few months.

emidoots avatar Mar 31 '22 17:03 emidoots

I have an updated nix flake:

{
  description = "Mach is a game engine & graphics toolkit for the future.";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    zig.url = "github:mitchellh/zig-overlay";
  };

  outputs = { self, zig, nixpkgs }:
    let
      pkgs = nixpkgs.legacyPackages.x86_64-linux;
      lib = pkgs.lib;
    in {
      devShell.x86_64-linux = pkgs.mkShell {
        packages = [
          zig.packages.x86_64-linux.master
          pkgs.xorg.libX11
          pkgs.libGL
          pkgs.libsoundio
          pkgs.alsa-lib
        ];
        LD_LIBRARY_PATH = "${lib.makeLibraryPath [ pkgs.libGL pkgs.vulkan-loader ]}";
      };
    };
}

desttinghim avatar Sep 08 '22 22:09 desttinghim