Packaging AMDVLK

Hello,

I would like to contribute packaging AMDVLK:

AMDVLK repo is here: GitHub - GPUOpen-Drivers/AMDVLK: AMD Open Source Driver For Vulkan
It uses CMake to build and depends on a bunch of different repos, they’re pulled in according to this definition https://github.com/GPUOpen-Drivers/AMDVLK/blob/ff4e60402dc4528fbb7a9aa9f7cde1fd867c724c/default.xml
The CMake files seem to depend on a certain directory structure
It’s also packaged in AUR: PKGBUILD - aur.git - AUR Package Repositories

I’d love to contribute the needed derivations, I do need some help figuring out:
Should it be possible to reuse existing derivations? ( spirv-headers , spirv-tools , glslang )
What about their fork of llvm-project? – E: this seems to be blocking me right now
I suppose I’ll figure it out today when trying to build
How am I meant to pull in multipe repos in a single derivation?
Installation instructions mention replacing existing icd.json files with the ones provided in the repo, I have a hard time figuring out how this would apply to NixOS – E: vulkan-loader searches through some XDG folders, that should be easy to configure.

Thanks

Here’s where I am so far:

The build fails due to one error, and I can’t really make sense of it, supposedly related to LLVM:

CMake Error: Could not open file for write in copy operation /build/xgl/build/llvm/lib/cmake/llvm/LLVMConfigVersion.cmake.tmp
CMake Error: : System Error: Permission denied
CMake Error at /build/llvm-project/llvm/cmake/modules/CMakeLists.txt:114 (configure_file):
  configure_file Problem configuring file


-- Failed to find LLVM FileCheck
-- Version: 0.0.0

Logs are included with the gist.

Hi, did you get any further with this?

I currently have the following derivation which does manage to build

{ stdenv, cmake, pkgconfig, wayland, python3, fetchRepoProject, libffi, perl, xorg, openssl }:

stdenv.mkDerivation rec {
  pname = "amdvlk";
  version = "v-2020.Q2.4";

  src = fetchRepoProject {
    name = "amdvlk-src";
    manifest = "https://github.com/GPUOpen-Drivers/AMDVLK.git";
    rev = "fc576d9b331e8b86c1881f4b2385af8a093baef0";
    sha256 = "0bbpbyxnnl3pxx8aycv59kgilw5m6ddrida1gqfjblhc30mr0ivg";
  };

  preConfigure = ''
    cd drivers/xgl
  '';

  cmakeFlags = [
    "-DBUILD_WAYLAND_SUPPORT=ON"
  ];

  buildInputs = [
    wayland
    libffi
    xorg.libX11
    xorg.libxshmfence
    openssl
  ];

  nativeBuildInputs = [
    cmake
    pkgconfig
    python3
    perl
  ];

}

However I’m struggling to work out how I would actually install the driver

Hello,

Great job, I’ll be trying it out on my machine shortly.

EDIT:
From what I gathered, vulkan-loader searches for vulkan/icd.d/*.json in $XDG_CONFIG_DIRS, $XDG_DATA_DIRS, $XDG_DATA_HOME and finally /etc, which seems like a fairly easy way to have some NixOS/home-manager module handle that. (possibly outdated source: vulkaninfo yields VK_ERROR_INCOMPATIBLE_DRIVER unless VK_ICD_FILENAMES is passed (on 1.1.73) · Issue #110 · KhronosGroup/Vulkan-Loader · GitHub)
That search can be bypassed by using $VK_ICD_FILENAMES and pointing it directly to an ICD .json file.

The default installation phase seems to put LLVM-related stuff in $out, which isn’t what we want.
I have built the derivation in a nix-shell to have access to everything built, drivers/xgl/build/icd/amdvlk64.so seems to be the only thing needed.

I made a copy of drivers/AMDVLK/json/Ubuntu/amd_icd64.json and fixed the path to amdvlk64.so, then set $VK_ICD_FILENAMES to it in order to try it out without a full setup.

With vulkan-tools installed, vulkaninfo returns 255 and prints

/build/source/vulkaninfo/vulkaninfo.h:373: failed with ERROR_OUT_OF_HOST_MEMORY

vkcube returns 1 and prints

vkCreateInstance failed.

Do you have a compatible Vulkan installable client driver (ICD) installed?
Please look at the Getting Started guide for additional information.

Trying with VK_LOADER_DEBUG=all doesn’t seem to show any errors, it even seems to succeed at completing DEBUG: Build ICD instance extension list, and then the crash happens.

It could just be my GPU/setup, I’m running a R9 390 with amdgpu drivers.

Bests

After doing this I realised that there is already an open PR for amdvlk amdvlk: init at 2020.Q2.5 by Flakebi · Pull Request #82305 · NixOS/nixpkgs · GitHub . This works perfectly for me on RX 5600xt