From 6bf27c2caeb621472151c63fc33c4951ce0188d1 Mon Sep 17 00:00:00 2001 From: David McFarland Date: Tue, 11 Oct 2016 13:50:52 -0300 Subject: [PATCH] vulkan-loader: allow validation layers to be enabled The loader now uses XDK_DATA_DIRS to find drivers and layers. --- nixos/modules/config/system-path.nix | 1 + nixos/modules/hardware/video/amdgpu-pro.nix | 2 - .../libraries/vulkan-loader/default.nix | 8 +- .../vulkan-loader/use-xdg-paths.patch | 142 ++++++++++++++++++ pkgs/os-specific/linux/amdgpu-pro/default.nix | 5 +- 5 files changed, 151 insertions(+), 7 deletions(-) create mode 100644 pkgs/development/libraries/vulkan-loader/use-xdg-paths.patch diff --git a/nixos/modules/config/system-path.nix b/nixos/modules/config/system-path.nix index 775d0c39c4fa..3ac5f634c7a6 100644 --- a/nixos/modules/config/system-path.nix +++ b/nixos/modules/config/system-path.nix @@ -118,6 +118,7 @@ in "/share/terminfo" "/share/themes" "/share/vim-plugins" + "/share/vulkan" ]; system.path = pkgs.buildEnv { diff --git a/nixos/modules/hardware/video/amdgpu-pro.nix b/nixos/modules/hardware/video/amdgpu-pro.nix index 3723d7690dc6..979810abf90a 100644 --- a/nixos/modules/hardware/video/amdgpu-pro.nix +++ b/nixos/modules/hardware/video/amdgpu-pro.nix @@ -45,10 +45,8 @@ in "amd/amdapfxx.blb".source = package + "/etc/amd/amdapfxx.blb"; "gbm/gbm.conf".source = package + "/etc/gbm/gbm.conf"; "OpenCL/vendors/amdocl64.icd".source = package + "/etc/OpenCL/vendors/amdocl64.icd"; - "vulkan/icd.d/amd_icd64.json".source = package + "/etc/vulkan/icd.d/amd_icd64.json"; } // optionalAttrs opengl.driSupport32Bit { "OpenCL/vendors/amdocl32.icd".source = package32 + "/etc/OpenCL/vendors/amdocl32.icd"; - "vulkan/icd.d/amd_icd32.json".source = package32 + "/etc/vulkan/icd.d/amd_icd32.json"; }; }; diff --git a/pkgs/development/libraries/vulkan-loader/default.nix b/pkgs/development/libraries/vulkan-loader/default.nix index 612ba2381137..622d027c60bc 100644 --- a/pkgs/development/libraries/vulkan-loader/default.nix +++ b/pkgs/development/libraries/vulkan-loader/default.nix @@ -34,6 +34,8 @@ stdenv.mkDerivation rec { "-DBUILD_WSI_WAYLAND_SUPPORT=ON" # XLIB/XCB supported by default ]; + patches = [ ./use-xdg-paths.patch ]; + outputs = [ "out" "dev" "demos" ]; preConfigure = '' @@ -49,10 +51,10 @@ stdenv.mkDerivation rec { mkdir -p $out/lib $out/bin cp -d loader/libvulkan.so* $out/lib cp demos/vulkaninfo $out/bin - mkdir -p $out/lib $out/etc/explicit_layer.d + mkdir -p $out/lib $out/share/vulkan/explicit_layer.d cp -d layers/*.so $out/lib/ - cp -d layers/*.json $out/etc/explicit_layer.d/ - sed -i "s:\\./lib:$out/lib/lib:g" "$out/etc/"**/*.json + cp -d layers/*.json $out/share/vulkan/explicit_layer.d/ + sed -i "s:\\./lib:$out/lib/lib:g" "$out/share/vulkan/"*/*.json mkdir -p $dev/include cp -rv ../include $dev/ mkdir -p $demos/bin diff --git a/pkgs/development/libraries/vulkan-loader/use-xdg-paths.patch b/pkgs/development/libraries/vulkan-loader/use-xdg-paths.patch new file mode 100644 index 000000000000..1ae0f20889fc --- /dev/null +++ b/pkgs/development/libraries/vulkan-loader/use-xdg-paths.patch @@ -0,0 +1,142 @@ +diff --git a/loader/loader.c b/loader/loader.c +index a950ea1..9462d05 100644 +--- a/loader/loader.c ++++ b/loader/loader.c +@@ -2671,6 +2671,94 @@ static VkResult loader_get_manifest_files( + } + } + ++#if !defined(_WIN32) ++ if (home_location && override == NULL) { ++ char *xdgconfdirs = secure_getenv("XDG_CONFIG_DIRS"); ++ char *xdgdatadirs = secure_getenv("XDG_DATA_DIRS"); ++ char *cur, *src = loc; ++ size_t src_size = strlen(src), rel_size = strlen(home_location); ++ size_t size = 0; ++ ++ if (src_size > 0) ++ size += src_size + 1; ++ ++ if (xdgconfdirs == NULL) ++ xdgconfdirs = "/etc/xdg"; ++ if (xdgdatadirs == NULL) ++ xdgdatadirs = "/usr/local/share:/usr/share"; ++ ++ for (char *x = xdgconfdirs; *x; ++x) ++ if (*x == PATH_SEPERATOR) size += rel_size; ++ size += strlen(xdgconfdirs) + rel_size + 1; ++ for (char *x = xdgdatadirs; *x; ++x) ++ if (*x == PATH_SEPERATOR) size += rel_size; ++ size += strlen(xdgdatadirs) + rel_size + 1; ++ ++#if defined(LOCALPREFIX) ++ size += strlen(LOCALPREFIX "/" SYSCONFDIR) + rel_size + 1; ++ size += strlen(LOCALPREFIX "/" DATADIR) + rel_size + 1; ++#endif ++ ++ loc = cur = loader_stack_alloc(size); ++ if (cur == NULL) { ++ loader_log(inst, VK_DEBUG_REPORT_ERROR_BIT_EXT, 0, ++ "Out of memory can't get manifest files"); ++ res = VK_ERROR_OUT_OF_HOST_MEMORY; ++ goto out; ++ } ++ ++ if (src_size > 0) { ++ memcpy(cur, src, src_size); ++ cur += src_size; ++ *cur++ = PATH_SEPERATOR; ++ } ++ ++ src = xdgconfdirs; ++ for (char *x = src;; ++x) { ++ if (*x == PATH_SEPERATOR || *x == 0) { ++ size_t s = x - src; ++ memcpy(cur, src, s); cur += s; ++ memcpy(cur, home_location, rel_size); cur += rel_size; ++ *cur++ = PATH_SEPERATOR; ++ if (*x == 0) ++ break; ++ src = ++x; ++ } ++ } ++ ++#if defined(LOCALPREFIX) ++ strcpy(cur, LOCALPREFIX "/" SYSCONFDIR); ++ cur += strlen(cur); ++ memcpy(cur, home_location, rel_size); cur += rel_size; ++ *cur++ = PATH_SEPERATOR; ++#endif ++ ++ src = xdgdatadirs; ++ for (char *x = src;; ++x) { ++ if (*x == PATH_SEPERATOR || *x == 0) { ++ size_t s = x - src; ++ memcpy(cur, src, s); cur += s; ++ memcpy(cur, home_location, rel_size); cur += rel_size; ++ *cur++ = PATH_SEPERATOR; ++ if (*x == 0) ++ break; ++ src = ++x; ++ } ++ } ++ ++#if defined(LOCALPREFIX) ++ strcpy(cur, LOCALPREFIX "/" DATADIR); ++ cur += strlen(cur); ++ memcpy(cur, home_location, rel_size); cur += rel_size; ++ *cur++ = PATH_SEPERATOR; ++#endif ++ ++ loc[size - 1] = 0; ++ assert(cur == loc + size); ++ list_is_dirs = true; ++ } ++#endif ++ + // Print out the paths being searched if debugging is enabled + loader_log(inst, VK_DEBUG_REPORT_DEBUG_BIT_EXT, 0, + "Searching the following paths for manifest files: %s\n", loc); +diff --git a/loader/vk_loader_platform.h b/loader/vk_loader_platform.h +index 3a02640..70a2652 100644 +--- a/loader/vk_loader_platform.h ++++ b/loader/vk_loader_platform.h +@@ -57,35 +57,10 @@ + #define VULKAN_ILAYERCONF_DIR "implicit_layer.d" + #define VULKAN_LAYER_DIR "layer" + +-#if defined(LOCALPREFIX) +-#define LOCAL_DRIVERS_INFO \ +- LOCALPREFIX "/" SYSCONFDIR VULKAN_DIR VULKAN_ICDCONF_DIR ":" \ +- LOCALPREFIX "/" DATADIR VULKAN_DIR VULKAN_ICDCONF_DIR ":" +-#define LOCAL_ELAYERS_INFO \ +- LOCALPREFIX "/" SYSCONFDIR VULKAN_DIR VULKAN_ELAYERCONF_DIR ":" \ +- LOCALPREFIX "/" DATADIR VULKAN_DIR VULKAN_ELAYERCONF_DIR ":" +-#define LOCAL_ILAYERS_INFO \ +- LOCALPREFIX "/" SYSCONFDIR VULKAN_DIR VULKAN_ILAYERCONF_DIR ":" \ +- LOCALPREFIX "/" DATADIR VULKAN_DIR VULKAN_ILAYERCONF_DIR ":" +-#else +-#define LOCAL_DRIVERS_INFO +-#define LOCAL_ELAYERS_INFO +-#define LOCAL_ILAYERS_INFO +-#endif +- +-#define DEFAULT_VK_DRIVERS_INFO \ +- LOCAL_DRIVERS_INFO \ +- "/" SYSCONFDIR VULKAN_DIR VULKAN_ICDCONF_DIR ":" \ +- "/usr/" DATADIR VULKAN_DIR VULKAN_ICDCONF_DIR ++#define DEFAULT_VK_DRIVERS_INFO "" + #define DEFAULT_VK_DRIVERS_PATH "" +-#define DEFAULT_VK_ELAYERS_INFO \ +- LOCAL_ELAYERS_INFO \ +- "/" SYSCONFDIR VULKAN_DIR VULKAN_ELAYERCONF_DIR ":" \ +- "/usr/" DATADIR VULKAN_DIR VULKAN_ELAYERCONF_DIR +-#define DEFAULT_VK_ILAYERS_INFO \ +- LOCAL_ILAYERS_INFO \ +- "/" SYSCONFDIR VULKAN_DIR VULKAN_ILAYERCONF_DIR ":" \ +- "/usr/" DATADIR VULKAN_DIR VULKAN_ILAYERCONF_DIR ++#define DEFAULT_VK_ELAYERS_INFO "" ++#define DEFAULT_VK_ILAYERS_INFO "" + #define DEFAULT_VK_LAYERS_PATH "" + #if !defined(LAYERS_SOURCE_PATH) + #define LAYERS_SOURCE_PATH NULL diff --git a/pkgs/os-specific/linux/amdgpu-pro/default.nix b/pkgs/os-specific/linux/amdgpu-pro/default.nix index 17a066640410..856989381ef1 100644 --- a/pkgs/os-specific/linux/amdgpu-pro/default.nix +++ b/pkgs/os-specific/linux/amdgpu-pro/default.nix @@ -92,12 +92,13 @@ in stdenv.mkDerivation rec { installPhase = '' mkdir -p $out cp -r usr/bin $out/bin + cp -r usr/share $out/share cp -r etc $out/etc + mv $out/etc/vulkan $out/share cp -r usr/include $out/include cp -r usr/lib/${libArch} $out/lib mv $out/lib/amdgpu-pro/* $out/lib/ rmdir $out/lib/amdgpu-pro - cp -r usr/share $out/share '' + optionalString (!libsOnly) '' if [ -d $out/lib/xorg ]; then rm $out/lib/xorg @@ -133,7 +134,7 @@ in stdenv.mkDerivation rec { perl -pi -e 's:${libReplaceDir}:${libCompatDir}:g' "$out/lib/$lib" fi done - substituteInPlace "$out/etc/vulkan/icd.d/amd_icd${bitness}.json" --replace "/usr/lib/${libArch}" "$out/lib" + substituteInPlace "$out/share/vulkan/icd.d/amd_icd${bitness}.json" --replace "/usr/lib/${libArch}" "$out/lib" ''; buildInputs = [