Permalink
Browse files

shim: Add initial support for Vulkan under snapd

This will require modifications to snapd, but at the moment we'll attempt
to look for vulkan icd (`10*.json`) passed from the hostfs from their
proprietary NVIDIA driver within the GL shared directory.

If we find these files, we'll insert the `VK_ICD_FILENAMES` variable into
the environment, taking care to preserve the original glob order by doing
this part in reverse.

Signed-off-by: Ikey Doherty <ikey@solus-project.com>
  • Loading branch information...
1 parent 02cccea commit 393d335af4fa275b5e87c570e64562eb019ddf6c @ikeydoherty ikeydoherty committed Nov 11, 2017
Showing with 34 additions and 0 deletions.
  1. +34 −0 src/shim/shim.c
View
@@ -12,6 +12,7 @@
#define _GNU_SOURCE
#include <errno.h>
+#include <glob.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
@@ -55,6 +56,11 @@
"glx-provider/default"
#define SNAPD_DRIVERS_PATH "/usr/lib/dri:/usr/lib32/dri"
+/**
+ * Bi-arch location for the host Vulkan ICD files
+ */
+#define VK_GLOB_BIARCH "/var/lib/snapd/lib/gl/10_*.json"
+
/**
* Used to update a value in the environment, and perform a prepend if the variable
* is already set.
@@ -151,6 +157,31 @@ static void shim_init_user(const char *userdir)
setenv(vars[i], tgt, 1);
}
}
+
+/**
+ * Attempt to set up Vulkan in the environment by looking for the ICD files
+ * passed from the hostfs
+ */
+static bool shim_init_vulkan(const char *glob_path)
+{
+ glob_t glo = { 0 };
+
+ glob(glob_path, GLOB_DOOFFS, NULL, &glo);
+
+ if (glo.gl_pathc < 1) {
+ globfree(&glo);
+ return false;
+ }
+
+ /* Preserve glob order and insert environment in reverse */
+ for (int i = glo.gl_pathc - 1; i >= 0; i--) {
+ shim_export_merge_vars("VK_ICD_FILENAMES", NULL, glo.gl_pathv[i]);
+ }
+
+ globfree(&glo);
+
+ return true;
+}
#endif
/**
@@ -172,6 +203,9 @@ static void shim_export_extra(const char *prefix)
shim_export_merge_vars("PATH", prefix, "/usr/bin");
shim_export_merge_vars("PATH", prefix, "/bin");
+ /* TODO: If this fails, try setting from multiarch */
+ shim_init_vulkan(VK_GLOB_BIARCH);
+
/* XDG */
shim_export_merge_vars("XDG_CONFIG_DIRS", NULL, "/etc/xdg");
shim_export_merge_vars("XDG_CONFIG_DIRS", NULL, "/usr/share/xdg");

0 comments on commit 393d335

Please sign in to comment.