Mesa

From NixOS Wiki
Revision as of 03:24, 27 March 2022 by imported>Natto1784 (Created page with "[https://www.mesa3d.org/ Mesa] is an open source implementation of several graphics APIs including OpenGL and Vulkan. == Enabling Vulkan Layers == Vulkan Layers are not enabl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Mesa is an open source implementation of several graphics APIs including OpenGL and Vulkan.

Enabling Vulkan Layers

Vulkan Layers are not enabled by default in Nixpkgs. You can override the existing Mesa packages and specify them in config.hardware.opengl.

hardware = {
  opengl =
    let
      fn = oa: {
        nativeBuildInputs = oa.nativeBuildInputs ++ [ pkgs.glslang ];
        mesonFlags = oa.mesonFlags ++ [ "-Dvulkan-layers=device-select,overlay" ];
#       patches = oa.patches ++ [ ./mesa-vulkan-layer-nvidia.patch ]; See below 
        postInstall = oa.postInstall + ''
            mv $out/lib/libVkLayer* $drivers/lib

            #Device Select layer
            layer=VkLayer_MESA_device_select
            substituteInPlace $drivers/share/vulkan/implicit_layer.d/''${layer}.json \
              --replace "lib''${layer}" "$drivers/lib/lib''${layer}"

            #Overlay layer
            layer=VkLayer_MESA_overlay
            substituteInPlace $drivers/share/vulkan/explicit_layer.d/''${layer}.json \
              --replace "lib''${layer}" "$drivers/lib/lib''${layer}"
          '';
      };
    in
    with pkgs; {
      enable = true;
      driSupport32Bit = true;
      package = (mesa.overrideAttrs fn).drivers;
      package32 = (pkgsi686Linux.mesa.overrideAttrs fn).drivers;
    };

Nvidia users may need to apply this patch for the Device Select layer to work.

diff b/src/vulkan/device-select-layer/device_select_layer.c a/src/vulkan/device-select-layer/device_select_layer.c
--- b/src/vulkan/device-select-layer/device_select_layer.c
+++ a/src/vulkan/device-select-layer/device_select_layer.c
@@ -454,12 +454,8 @@
       exit(0);
    } else {
       unsigned selected_index = get_default_device(info, selection, physical_device_count, physical_devices);
-      selected_physical_device_count = physical_device_count;
+      selected_physical_device_count = 1;
       selected_physical_devices[0] = physical_devices[selected_index];
-      for (unsigned i = 0; i < physical_device_count - 1; ++i) {
-         unsigned  this_idx = i < selected_index ? i : i + 1;
-         selected_physical_devices[i + 1] = physical_devices[this_idx];
-      }
    }

    if (selected_physical_device_count == 0) {