black window on nixos+nvidia+vulkan #192

Closed
opened 2022-03-27 23:13:31 +00:00 by ozkutuk · 10 comments
ozkutuk commented 2022-03-27 23:13:31 +00:00 (Migrated from github.com)

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
I am trying to run the example as explained in the project's landing page. However, the triangle is not displayed: ![image](https://user-images.githubusercontent.com/5948762/160304982-bc194028-1dd1-4145-add5-c7542f8b7da8.png) Corresponding terminal output: ```bash $ 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. ```bash $ zig version 0.10.0-dev.1453+9f25c8140 ```
emidoots commented 2022-03-28 00:50:52 +00:00 (Migrated from github.com)

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.

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.
ozkutuk commented 2022-03-28 16:46:33 +00:00 (Migrated from github.com)

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.

Interestingly enough, with `GPU_BACKEND=opengl` it stills picks up Vulkan backend but rather than displaying black window, it immediately segfaults. ```bash $ 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.
emidoots commented 2022-03-29 08:46:00 +00:00 (Migrated from github.com)

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
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 ```
ozkutuk commented 2022-03-29 10:03:27 +00:00 (Migrated from github.com)

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 });
That still reports _Vulkan_ being found, and the output is a black window as it was the case initially: ```bash $ 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: ```bash $ 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 }); ```
emidoots commented 2022-03-30 19:04:55 +00:00 (Migrated from github.com)

@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

@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
ozkutuk commented 2022-03-30 19:29:02 +00:00 (Migrated from github.com)

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

It works! I have a somewhat similar Nix config, though I have migrated to [Nix flakes](https://nixos.wiki/wiki/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](https://github.com/roarkanize/zig-overlay)): ```nix { 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).
emidoots commented 2022-03-30 21:45:40 +00:00 (Migrated from github.com)

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

Just to clarify, was it the OpenGL backend that worked? Or Vulkan also worked after that?
ozkutuk commented 2022-03-30 21:54:20 +00:00 (Migrated from github.com)

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

OpenGL backend worked with the correct commands you have provided. Unfortunately, still no triangle with the Vulkan backend.
emidoots commented 2022-03-31 17:09:27 +00:00 (Migrated from github.com)

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.

Thanks! I fixed the issue where `GPU_BACKEND` in the standard `gpu/` example was not working, so [this](https://github.com/hexops/mach/issues/192#issuecomment-1080066314) 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.
desttinghim commented 2022-09-08 22:06:30 +00:00 (Migrated from github.com)

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 ]}";
      };
    };
}
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 ]}"; }; }; } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
hexops/mach#192
No description provided.