From 270c5d67c2b261c15f12a0db9db40ae6cccc65d6 Mon Sep 17 00:00:00 2001 From: Ludovico de Nittis <ludovico.denittis@collabora.com> Date: Wed, 3 Mar 2021 17:16:13 +0100 Subject: [PATCH] check-vulkan: Bundle the required shaders using GResource Bundling the shaders makes it easier to ship the relocatable version of the Vulkan helper. It also fixes the issue reported in #62. Fixes: #62 Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com> --- helpers/check-vulkan.c | 19 +++++++--------- helpers/meson.build | 44 ++++++++++++++++++++---------------- helpers/shader.gresource.xml | 7 ++++++ 3 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 helpers/shader.gresource.xml diff --git a/helpers/check-vulkan.c b/helpers/check-vulkan.c index 598148abb..77ea9e6c0 100644 --- a/helpers/check-vulkan.c +++ b/helpers/check-vulkan.c @@ -664,15 +664,19 @@ create_shader_module (VkDevice device, VkShaderModule *shader_module, GError **error) { - g_autofree gchar *shader_data = NULL; + const gchar *shader_data = NULL; + g_autoptr(GBytes) bytes = NULL; gsize size; g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (shader_module != NULL, FALSE); - if (!g_file_get_contents (filename, &shader_data, &size, error)) + bytes = g_resources_lookup_data (filename, G_RESOURCE_LOOKUP_FLAGS_NONE, error); + if (bytes == NULL) return FALSE; + shader_data = g_bytes_get_data (bytes, &size); + VkShaderModuleCreateInfo create_info = { .sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO, @@ -692,16 +696,9 @@ create_graphics_pipeline (VulkanPhysicalDeviceProperties *dev_props, { g_autofree gchar *vert_path = NULL; g_autofree gchar *frag_path = NULL; - g_autofree gchar *base_path = NULL; - - g_return_val_if_fail (dev_props != NULL, FALSE); - - base_path = g_strdup (getenv ("SRT_DATA_PATH")); - if (base_path == NULL) - base_path = g_path_get_dirname (argv0); - vert_path = g_build_filename (base_path, "shaders", "/vert.spv", NULL); - frag_path = g_build_filename (base_path, "shaders", "/frag.spv", NULL); + vert_path = g_build_filename ("/com", "valvesoftware", "steam-runtime-tools", "shader", "vert.spv", NULL); + frag_path = g_build_filename ("/com", "valvesoftware", "steam-runtime-tools", "shader", "frag.spv", NULL); VkShaderModule vert_shader_module; VkShaderModule frag_shader_module; diff --git a/helpers/meson.build b/helpers/meson.build index 0034412f4..34c3a87f5 100644 --- a/helpers/meson.build +++ b/helpers/meson.build @@ -76,21 +76,10 @@ executable( # a game with no special linking would be able to use VDPAU. ) -executable( - multiarch + '-check-vulkan', - 'check-vulkan.c', - dependencies : [glib, gio_unix, libglnx_dep, libsteamrt_dep, json_glib, vulkan, xcb], - include_directories : project_include_dirs, - install : true, - install_dir : pkglibexecdir, - # Use the adjacent libsteam-runtime-tools and json-glib, ignoring - # LD_LIBRARY_PATH even if set - build_rpath : pkglibexec_rpath, - install_rpath : pkglibexec_rpath, -) +shaders = [] foreach shader : ['frag', 'vert'] - custom_target( + shaders += custom_target( shader + '.spv', build_by_default : true, command : [ @@ -101,16 +90,31 @@ foreach shader : ['frag', 'vert'] ], input : 'shader.' + shader, output : shader + '.spv', - install : true, - install_dir : join_paths( - get_option('prefix'), - get_option('libexecdir'), - 'steam-runtime-tools-' + api_major, - 'shaders', - ) ) endforeach +shader_resources = gnome.compile_resources( + 'shader-resources', + 'shader.gresource.xml', + source_dir: meson.current_build_dir(), + dependencies: shaders, + c_name: 'shader', +) + +executable( + multiarch + '-check-vulkan', + 'check-vulkan.c', + shader_resources, + dependencies : [glib, gio_unix, libglnx_dep, libsteamrt_dep, json_glib, vulkan, xcb], + include_directories : project_include_dirs, + install : true, + install_dir : pkglibexecdir, + # Use the adjacent libsteam-runtime-tools and json-glib, ignoring + # LD_LIBRARY_PATH even if set + build_rpath : pkglibexec_rpath, + install_rpath : pkglibexec_rpath, +) + executable( multiarch + '-check-gl', 'check-gl.cpp', diff --git a/helpers/shader.gresource.xml b/helpers/shader.gresource.xml new file mode 100644 index 000000000..8b94db304 --- /dev/null +++ b/helpers/shader.gresource.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<gresources> + <gresource prefix="/com/valvesoftware/steam-runtime-tools/shader"> + <file>frag.spv</file> + <file>vert.spv</file> + </gresource> +</gresources> -- GitLab