Skip to content
Snippets Groups Projects
Commit 1538449b authored by Ludovico de Nittis's avatar Ludovico de Nittis
Browse files

Merge branch 'wip/unify-icds' into 'master'

runtime: Share more code between Vulkan and EGL

See merge request !197
parents 8bf7d1d3 5f98f714
No related branches found
No related tags found
1 merge request!197runtime: Share more code between Vulkan and EGL
Pipeline #5995 passed
...@@ -2400,33 +2400,34 @@ pv_runtime_search_in_path_and_bin (PvRuntime *self, ...@@ -2400,33 +2400,34 @@ pv_runtime_search_in_path_and_bin (PvRuntime *self,
} }
/* /*
* setup_vulkan_loadable_json: * setup_json_manifest:
* @self: The runtime * @self: The runtime
* @bwrap: Append arguments to this bubblewrap invocation to make files * @bwrap: Append arguments to this bubblewrap invocation to make files
* available in the container * available in the container
* @sub_dir: `icd.d`, `explicit_layer.d` or `implicit_layer.d` * @sub_dir: `vulkan/icd.d`, `glvnd/egl_vendor.d` or similar
* @write_to_dir: Path to `/overrides/share/vulkan/${sub_dir}` in the * @write_to_dir: Path to `/overrides/share/${sub_dir}` in the
* current execution environment * current execution environment
* @details: An #IcdDetails holding a #SrtVulkanLayer or #SrtVulkanIcd, * @details: An #IcdDetails holding a #SrtVulkanLayer or #SrtVulkanIcd,
* whichever is appropriate for @sub_dir * whichever is appropriate for @sub_dir
* @seq: Sequence number of @details, used to make unique filenames * @seq: Sequence number of @details, used to make unique filenames
* @vulkan_path: Used to build `$VK_ICD_FILENAMES` or a similar search path * @search_path: Used to build `$VK_ICD_FILENAMES` or a similar search path
* @error: Used to raise an error on failure * @error: Used to raise an error on failure
* *
* Make a single Vulkan layer or ICD available in the container. * Make a single Vulkan layer or ICD available in the container.
*/ */
static gboolean static gboolean
setup_vulkan_loadable_json (PvRuntime *self, setup_json_manifest (PvRuntime *self,
FlatpakBwrap *bwrap, FlatpakBwrap *bwrap,
const gchar *sub_dir, const gchar *sub_dir,
const gchar *write_to_dir, const gchar *write_to_dir,
IcdDetails *details, IcdDetails *details,
gsize seq, gsize seq,
GString *vulkan_path, GString *search_path,
GError **error) GError **error)
{ {
SrtVulkanLayer *layer = NULL; SrtVulkanLayer *layer = NULL;
SrtVulkanIcd *icd = NULL; SrtVulkanIcd *icd = NULL;
SrtEglIcd *egl = NULL;
gboolean need_provider_json = FALSE; gboolean need_provider_json = FALSE;
gsize i; gsize i;
...@@ -2434,6 +2435,8 @@ setup_vulkan_loadable_json (PvRuntime *self, ...@@ -2434,6 +2435,8 @@ setup_vulkan_loadable_json (PvRuntime *self,
layer = SRT_VULKAN_LAYER (details->icd); layer = SRT_VULKAN_LAYER (details->icd);
else if (SRT_IS_VULKAN_ICD (details->icd)) else if (SRT_IS_VULKAN_ICD (details->icd))
icd = SRT_VULKAN_ICD (details->icd); icd = SRT_VULKAN_ICD (details->icd);
else if (SRT_IS_EGL_ICD (details->icd))
egl = SRT_EGL_ICD (details->icd);
else else
g_return_val_if_reached (FALSE); g_return_val_if_reached (FALSE);
...@@ -2443,6 +2446,11 @@ setup_vulkan_loadable_json (PvRuntime *self, ...@@ -2443,6 +2446,11 @@ setup_vulkan_loadable_json (PvRuntime *self,
if (!srt_vulkan_layer_check_error (layer, NULL)) if (!srt_vulkan_layer_check_error (layer, NULL))
return TRUE; return TRUE;
} }
else if (egl != NULL)
{
if (!srt_egl_icd_check_error (egl, NULL))
return TRUE;
}
else else
{ {
if (!srt_vulkan_icd_check_error (icd, NULL)) if (!srt_vulkan_icd_check_error (icd, NULL))
...@@ -2466,7 +2474,7 @@ setup_vulkan_loadable_json (PvRuntime *self, ...@@ -2466,7 +2474,7 @@ setup_vulkan_loadable_json (PvRuntime *self,
seq, multiarch_tuples[i]); seq, multiarch_tuples[i]);
write_to_file = g_build_filename (write_to_dir, json_base, NULL); write_to_file = g_build_filename (write_to_dir, json_base, NULL);
json_in_container = g_build_filename (self->overrides_in_container, json_in_container = g_build_filename (self->overrides_in_container,
"share", "vulkan", sub_dir, "share", sub_dir,
json_base, NULL); json_base, NULL);
if (layer != NULL) if (layer != NULL)
...@@ -2478,6 +2486,17 @@ setup_vulkan_loadable_json (PvRuntime *self, ...@@ -2478,6 +2486,17 @@ setup_vulkan_loadable_json (PvRuntime *self,
if (!srt_vulkan_layer_write_to_file (replacement, write_to_file, error)) if (!srt_vulkan_layer_write_to_file (replacement, write_to_file, error))
return FALSE; return FALSE;
} }
else if (egl != NULL)
{
g_autoptr(SrtEglIcd) replacement = NULL;
replacement = srt_egl_icd_new_replace_library_path (egl,
details->paths_in_container[i]);
if (!srt_egl_icd_write_to_file (replacement, write_to_file,
error))
return FALSE;
}
else else
{ {
g_autoptr(SrtVulkanIcd) replacement = NULL; g_autoptr(SrtVulkanIcd) replacement = NULL;
...@@ -2488,7 +2507,7 @@ setup_vulkan_loadable_json (PvRuntime *self, ...@@ -2488,7 +2507,7 @@ setup_vulkan_loadable_json (PvRuntime *self,
return FALSE; return FALSE;
} }
pv_search_path_append (vulkan_path, json_in_container); pv_search_path_append (search_path, json_in_container);
} }
else if (details->kinds[i] == ICD_KIND_SONAME else if (details->kinds[i] == ICD_KIND_SONAME
|| details->kinds[i] == ICD_KIND_META_LAYER) || details->kinds[i] == ICD_KIND_META_LAYER)
...@@ -2504,12 +2523,14 @@ setup_vulkan_loadable_json (PvRuntime *self, ...@@ -2504,12 +2523,14 @@ setup_vulkan_loadable_json (PvRuntime *self,
const char *json_in_provider = NULL; const char *json_in_provider = NULL;
if (layer != NULL) if (layer != NULL)
json_in_provider = srt_vulkan_layer_get_json_path (layer); json_in_provider = srt_vulkan_layer_get_json_path (layer);
else if (egl != NULL)
json_in_provider = srt_egl_icd_get_json_path (egl);
else else
json_in_provider = srt_vulkan_icd_get_json_path (icd); json_in_provider = srt_vulkan_icd_get_json_path (icd);
json_base = g_strdup_printf ("%" G_GSIZE_FORMAT ".json", seq); json_base = g_strdup_printf ("%" G_GSIZE_FORMAT ".json", seq);
json_in_container = g_build_filename (self->overrides_in_container, json_in_container = g_build_filename (self->overrides_in_container,
"share", "vulkan", sub_dir, "share", sub_dir,
json_base, NULL); json_base, NULL);
if (!pv_runtime_take_from_provider (self, bwrap, if (!pv_runtime_take_from_provider (self, bwrap,
...@@ -2519,40 +2540,41 @@ setup_vulkan_loadable_json (PvRuntime *self, ...@@ -2519,40 +2540,41 @@ setup_vulkan_loadable_json (PvRuntime *self,
error)) error))
return FALSE; return FALSE;
pv_search_path_append (vulkan_path, json_in_container); pv_search_path_append (search_path, json_in_container);
} }
return TRUE; return TRUE;
} }
/* /*
* setup_vulkan_loadable_json: * setup_each_json_manifest:
* @self: The runtime * @self: The runtime
* @bwrap: Append arguments to this bubblewrap invocation to make files * @bwrap: Append arguments to this bubblewrap invocation to make files
* available in the container * available in the container
* @sub_dir: `icd.d`, `explicit_layer.d` or `implicit_layer.d` * @sub_dir: `vulkan/icd.d` or similar
* @write_to_dir: Path to `/overrides/share/vulkan/${sub_dir}` in the * @write_to_dir: Path to `/overrides/share/${sub_dir}` in the
* current execution environment * current execution environment
* @vulkan_details: (element-type IcdDetails): A list of #IcdDetails * @details: (element-type IcdDetails): A list of #IcdDetails
* holding #SrtVulkanLayer or #SrtVulkanIcd, as appropriate for @sub_dir * holding #SrtVulkanLayer, #SrtVulkanIcd or #SrtEglIcd, as appropriate
* @vulkan_path: Used to build `$VK_ICD_FILENAMES` or a similar search path * for @sub_dir
* @search_path: Used to build `$VK_ICD_FILENAMES` or a similar search path
* @error: Used to raise an error on failure * @error: Used to raise an error on failure
* *
* Make a list of Vulkan layers or ICDs available in the container. * Make a list of Vulkan layers or ICDs available in the container.
*/ */
static gboolean static gboolean
setup_each_vulkan_loadable_json (PvRuntime *self, setup_each_json_manifest (PvRuntime *self,
FlatpakBwrap *bwrap, FlatpakBwrap *bwrap,
const gchar *sub_dir, const gchar *sub_dir,
GPtrArray *vulkan_details, GPtrArray *details,
GString *vulkan_path, GString *search_path,
GError **error) GError **error)
{ {
gsize j; gsize j;
g_autofree gchar *write_to_dir = NULL; g_autofree gchar *write_to_dir = NULL;
write_to_dir = g_build_filename (self->overrides, write_to_dir = g_build_filename (self->overrides,
"share", "vulkan", sub_dir, NULL); "share", sub_dir, NULL);
if (g_mkdir_with_parents (write_to_dir, 0700) != 0) if (g_mkdir_with_parents (write_to_dir, 0700) != 0)
{ {
...@@ -2560,11 +2582,11 @@ setup_each_vulkan_loadable_json (PvRuntime *self, ...@@ -2560,11 +2582,11 @@ setup_each_vulkan_loadable_json (PvRuntime *self,
return FALSE; return FALSE;
} }
for (j = 0; j < vulkan_details->len; j++) for (j = 0; j < details->len; j++)
{ {
if (!setup_vulkan_loadable_json (self, bwrap, sub_dir, write_to_dir, if (!setup_json_manifest (self, bwrap, sub_dir, write_to_dir,
g_ptr_array_index (vulkan_details, j), g_ptr_array_index (details, j),
j, vulkan_path, error)) j, search_path, error))
return FALSE; return FALSE;
} }
...@@ -2673,7 +2695,6 @@ pv_runtime_use_provider_graphics_stack (PvRuntime *self, ...@@ -2673,7 +2695,6 @@ pv_runtime_use_provider_graphics_stack (PvRuntime *self,
g_autofree gchar *localedef = NULL; g_autofree gchar *localedef = NULL;
g_autofree gchar *ldconfig = NULL; g_autofree gchar *ldconfig = NULL;
g_autofree gchar *locale = NULL; g_autofree gchar *locale = NULL;
g_autofree gchar *dir_on_host = NULL;
g_autoptr(SrtSystemInfo) system_info = srt_system_info_new (NULL); g_autoptr(SrtSystemInfo) system_info = srt_system_info_new (NULL);
g_autoptr(SrtObjectList) egl_icds = NULL; g_autoptr(SrtObjectList) egl_icds = NULL;
g_autoptr(SrtObjectList) vulkan_icds = NULL; g_autoptr(SrtObjectList) vulkan_icds = NULL;
...@@ -3483,102 +3504,27 @@ pv_runtime_use_provider_graphics_stack (PvRuntime *self, ...@@ -3483,102 +3504,27 @@ pv_runtime_use_provider_graphics_stack (PvRuntime *self,
g_debug ("Setting up EGL ICD JSON..."); g_debug ("Setting up EGL ICD JSON...");
dir_on_host = g_build_filename (self->overrides, if (!setup_each_json_manifest (self, bwrap, "glvnd/egl_vendor.d",
"share", "glvnd", "egl_vendor.d", NULL); egl_icd_details, egl_path, error))
return FALSE;
if (g_mkdir_with_parents (dir_on_host, 0700) != 0)
{
glnx_throw_errno_prefix (error, "Unable to create %s", dir_on_host);
return FALSE;
}
for (j = 0; j < egl_icd_details->len; j++)
{
IcdDetails *details = g_ptr_array_index (egl_icd_details, j);
SrtEglIcd *icd = SRT_EGL_ICD (details->icd);
gboolean need_provider_json = FALSE;
if (!srt_egl_icd_check_error (icd, NULL))
continue;
for (i = 0; i < G_N_ELEMENTS (multiarch_tuples) - 1; i++)
{
g_assert (i < G_N_ELEMENTS (details->kinds));
g_assert (i < G_N_ELEMENTS (details->paths_in_container));
if (details->kinds[i] == ICD_KIND_ABSOLUTE)
{
g_autoptr(SrtEglIcd) replacement = NULL;
g_autofree gchar *json_on_host = NULL;
g_autofree gchar *json_in_container = NULL;
g_autofree gchar *json_base = NULL;
g_assert (details->paths_in_container[i] != NULL);
json_base = g_strdup_printf ("%" G_GSIZE_FORMAT "-%s.json",
j, multiarch_tuples[i]);
json_on_host = g_build_filename (dir_on_host, json_base, NULL);
json_in_container = g_build_filename (self->overrides_in_container,
"share", "glvnd",
"egl_vendor.d",
json_base, NULL);
replacement = srt_egl_icd_new_replace_library_path (icd,
details->paths_in_container[i]);
if (!srt_egl_icd_write_to_file (replacement, json_on_host,
error))
return FALSE;
pv_search_path_append (egl_path, json_in_container);
}
else if (details->kinds[i] == ICD_KIND_SONAME)
{
need_provider_json = TRUE;
}
}
if (need_provider_json)
{
g_autofree gchar *json_in_container = NULL;
g_autofree gchar *json_base = NULL;
const char *json_on_host = srt_egl_icd_get_json_path (icd);
json_base = g_strdup_printf ("%" G_GSIZE_FORMAT ".json", j);
json_in_container = g_build_filename (self->overrides_in_container,
"share", "glvnd",
"egl_vendor.d",
json_base, NULL);
if (!pv_runtime_take_from_provider (self, bwrap,
json_on_host,
json_in_container,
TAKE_FROM_PROVIDER_FLAGS_COPY_FALLBACK,
error))
return FALSE;
pv_search_path_append (egl_path, json_in_container);
}
}
g_debug ("Setting up Vulkan ICD JSON..."); g_debug ("Setting up Vulkan ICD JSON...");
if (!setup_each_vulkan_loadable_json (self, bwrap, "icd.d", if (!setup_each_json_manifest (self, bwrap, "vulkan/icd.d",
vulkan_icd_details, vulkan_icd_details, vulkan_path, error))
vulkan_path, error))
return FALSE; return FALSE;
if (self->flags & PV_RUNTIME_FLAGS_IMPORT_VULKAN_LAYERS) if (self->flags & PV_RUNTIME_FLAGS_IMPORT_VULKAN_LAYERS)
{ {
g_debug ("Setting up Vulkan explicit layer JSON..."); g_debug ("Setting up Vulkan explicit layer JSON...");
if (!setup_each_vulkan_loadable_json (self, bwrap, "explicit_layer.d", if (!setup_each_json_manifest (self, bwrap, "vulkan/explicit_layer.d",
vulkan_exp_layer_details, vulkan_exp_layer_details,
vulkan_exp_layer_path, error)) vulkan_exp_layer_path, error))
return FALSE; return FALSE;
g_debug ("Setting up Vulkan implicit layer JSON..."); g_debug ("Setting up Vulkan implicit layer JSON...");
if (!setup_each_vulkan_loadable_json (self, bwrap, "implicit_layer.d", if (!setup_each_json_manifest (self, bwrap, "vulkan/implicit_layer.d",
vulkan_imp_layer_details, vulkan_imp_layer_details,
vulkan_imp_layer_path, error)) vulkan_imp_layer_path, error))
return FALSE; return FALSE;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment