diff --git a/bin/system-info.c b/bin/system-info.c index fe89cbe387a462c84c788b4be47adeb4f57cc6b8..f96ab4ce1cdefdffab25c3a81d2aaa3ab2b04b41 100644 --- a/bin/system-info.c +++ b/bin/system-info.c @@ -1065,6 +1065,8 @@ main (int argc, { gboolean can_run_vdpau; gchar *vdpau_additional_info = NULL; + gboolean can_run_va_api; + gchar *va_api_additional_info = NULL; can_run_vdpau = srt_system_info_can_run_vdpau (info, multiarch_tuples[i]); vdpau_additional_info = srt_system_info_dup_vdpau_additional_info (info, multiarch_tuples[i]); @@ -1078,7 +1080,22 @@ main (int argc, json_builder_add_string_value (builder, vdpau_additional_info); } json_builder_end_object (builder); + + can_run_va_api = srt_system_info_can_run_va_api (info, multiarch_tuples[i]); + va_api_additional_info = srt_system_info_dup_va_api_additional_info (info, multiarch_tuples[i]); + json_builder_set_member_name (builder, "va-api"); + json_builder_begin_object (builder); + json_builder_set_member_name (builder, "can-run"); + json_builder_add_boolean_value (builder, can_run_va_api); + if (va_api_additional_info != NULL) + { + json_builder_set_member_name (builder, "additional-info"); + json_builder_add_string_value (builder, va_api_additional_info); + } + json_builder_end_object (builder); + g_free (vdpau_additional_info); + g_free (va_api_additional_info); } json_builder_end_object (builder); diff --git a/bin/system-info.md b/bin/system-info.md index 58ddd5d5db75d2e27616a4f7af7b6ea8d3819341..18e7860edfc924e8427f2a59c4c24cc216892057 100644 --- a/bin/system-info.md +++ b/bin/system-info.md @@ -518,7 +518,7 @@ keys: **graphics-verification** : An object describing the ability to use a specific graphics module. - At the moment the only available key is **vdpau**. + At the moment the available keys are **vdpau** and **va-api**. The values are objects with the following keys: **can-run** diff --git a/helpers/check-va-api.c b/helpers/check-va-api.c index 172e1c98a6f09951d6362cd9aa4ea54b123ca47e..9e635a9723488fbaa66d4536f9eaacba2e9dc3b0 100644 --- a/helpers/check-va-api.c +++ b/helpers/check-va-api.c @@ -40,12 +40,14 @@ enum { OPTION_HELP = 1, + OPTION_VERBOSE, OPTION_VERSION, }; struct option long_options[] = { { "help", no_argument, NULL, OPTION_HELP }, + { "verbose", no_argument, NULL, OPTION_VERBOSE }, { "version", no_argument, NULL, OPTION_VERSION }, { NULL, 0, NULL, 0 } }; @@ -89,6 +91,7 @@ main (int argc, #define do_vaapi_or_exit(expr) if (! _do_vaapi (#expr, expr)) goto out; + bool verbose = false; int opt; int surfaces_count = 2; int ret = 1; @@ -105,7 +108,7 @@ main (int argc, VASurfaceID *surfaces = NULL; VAImageFormat image_format; VAProfile *profiles = NULL; - VAConfigID config; + VAConfigID config = VA_INVALID_ID; VAContextID context = VA_INVALID_ID; VABufferID misc_buf_id = VA_INVALID_ID; VABufferID pipeline_param_buf_id = VA_INVALID_ID; @@ -123,6 +126,10 @@ main (int argc, usage (0); break; + case OPTION_VERBOSE: + verbose = true; + break; + case OPTION_VERSION: /* Output version number as YAML for machine-readability, * inspired by `ostree --version` and `docker version` */ @@ -180,6 +187,9 @@ main (int argc, do_vaapi_or_exit (vaInitialize (va_display, &major_version, &minor_version)); + if (verbose) + printf ("%s\n", vaQueryVendorString (va_display)); + /* Test the ability to get the supported profiles and that they are not more than * the maximum number from the implementation */ max_profiles = vaMaxNumProfiles (va_display); diff --git a/steam-runtime-tools/graphics.c b/steam-runtime-tools/graphics.c index 310106ee77c86c65d5f0fa6feea69ccc51335976..ab8c6a649c2626b8da20d51e7d7022623c9db985 100644 --- a/steam-runtime-tools/graphics.c +++ b/steam-runtime-tools/graphics.c @@ -3566,6 +3566,9 @@ _srt_graphics_can_run (const char *helpers_path, break; case SRT_GRAPHICS_VAAPI_MODULE: + helper = "check-va-api"; + break; + case SRT_GRAPHICS_DRI_MODULE: case SRT_GRAPHICS_GLX_MODULE: case NUM_SRT_GRAPHICS_MODULES: diff --git a/steam-runtime-tools/system-info.c b/steam-runtime-tools/system-info.c index bca0deb6c7025ba31a50a24ac0776d13d6279188..8477e67af230b4451a966b4443594e8badcf0b33 100644 --- a/steam-runtime-tools/system-info.c +++ b/steam-runtime-tools/system-info.c @@ -3102,8 +3102,9 @@ ensure_can_run_graphics_cached (SrtSystemInfo *self, { g_return_if_fail (SRT_IS_SYSTEM_INFO (self)); g_return_if_fail (abi != NULL); - /* We can do this check only for VDPAU */ - g_return_if_fail (which == SRT_GRAPHICS_VDPAU_MODULE); + /* We can do this check only for VDPAU and VA-API */ + g_return_if_fail (which == SRT_GRAPHICS_VDPAU_MODULE || + which == SRT_GRAPHICS_VAAPI_MODULE); if (abi->graphics_modules[which].can_run != TRI_MAYBE) return; @@ -3176,3 +3177,57 @@ srt_system_info_dup_vdpau_additional_info (SrtSystemInfo *self, return g_strdup (abi->graphics_modules[SRT_GRAPHICS_VDPAU_MODULE].additional_info); } + +/** + * srt_system_info_can_run_va_api: + * @self: A #SrtSystemInfo object + * @multiarch_tuple: A multiarch tuple like %SRT_ABI_I386, representing an ABI. + * + * Check whether VA-API for the given ABI can be run successfully. + * + * Returns: %TRUE if we are able to use VA-API for the provided @multiarch_tuple + */ +gboolean +srt_system_info_can_run_va_api (SrtSystemInfo *self, + const char *multiarch_tuple) +{ + Abi *abi = NULL; + + g_return_val_if_fail (SRT_IS_SYSTEM_INFO (self), FALSE); + g_return_val_if_fail (multiarch_tuple != NULL, FALSE); + + abi = ensure_abi (self, multiarch_tuple); + + ensure_can_run_graphics_cached (self, abi, SRT_GRAPHICS_VAAPI_MODULE); + + return (abi->graphics_modules[SRT_GRAPHICS_VAAPI_MODULE].can_run == TRI_YES); +} + +/** + * srt_system_info_dup_va_api_additional_info: + * @self: A #SrtSystemInfo object + * @multiarch_tuple: A multiarch tuple like %SRT_ABI_I386, representing an ABI. + * + * Return addtional information gathered from the VA-API graphics helper. + * Usually the returned string will contain either information about the graphics + * driver in use or any eventual error message encountered running the helper. + * + * Returns: (type utf8) (transfer full) (nullable): Any additional information + * gathered from the graphics helper for the provided @multiarch_tuple, or %NULL + * if no information is available. + */ +gchar * +srt_system_info_dup_va_api_additional_info (SrtSystemInfo *self, + const char *multiarch_tuple) +{ + Abi *abi = NULL; + + g_return_val_if_fail (SRT_IS_SYSTEM_INFO (self), FALSE); + g_return_val_if_fail (multiarch_tuple != NULL, FALSE); + + abi = ensure_abi (self, multiarch_tuple); + + ensure_can_run_graphics_cached (self, abi, SRT_GRAPHICS_VAAPI_MODULE); + + return g_strdup (abi->graphics_modules[SRT_GRAPHICS_VAAPI_MODULE].additional_info); +} diff --git a/steam-runtime-tools/system-info.h b/steam-runtime-tools/system-info.h index ccf1ca54111ecc6b96a740d1881e40acd2a0db68..ae1b3e91b44f0c19cfd57989d2cce5169118d442 100644 --- a/steam-runtime-tools/system-info.h +++ b/steam-runtime-tools/system-info.h @@ -204,6 +204,12 @@ gboolean srt_system_info_can_run_vdpau (SrtSystemInfo *self, const char *multiarch_tuple); gchar *srt_system_info_dup_vdpau_additional_info (SrtSystemInfo *self, const char *multiarch_tuple); + +gboolean srt_system_info_can_run_va_api (SrtSystemInfo *self, + const char *multiarch_tuple); +gchar *srt_system_info_dup_va_api_additional_info (SrtSystemInfo *self, + const char *multiarch_tuple); + #ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC G_DEFINE_AUTOPTR_CLEANUP_FUNC (SrtSystemInfo, g_object_unref) #endif diff --git a/tests/graphics.c b/tests/graphics.c index c97543fe1df983c09023e67d069dfc535179751d..9ea1d019066c25f7ec1ede288df547ea8947cad5 100644 --- a/tests/graphics.c +++ b/tests/graphics.c @@ -2524,6 +2524,37 @@ test_vdpau_can_run (Fixture *f, g_object_unref (info); } +static void +test_va_api_can_run (Fixture *f, + gconstpointer context) +{ + gboolean can_run; + gchar *additional_info; + + SrtSystemInfo *info = srt_system_info_new (NULL); + srt_system_info_set_helpers_path (info, f->builddir); + + can_run = srt_system_info_can_run_va_api (info, "mock-good"); + g_assert_true (can_run); + + additional_info = srt_system_info_dup_va_api_additional_info (info, "mock-good"); + g_assert_cmpstr (additional_info, ==, "Mesa Gallium driver 20.0.4 for AMD Radeon RX 5700 XT (NAVI10, DRM 3.36.0, 5.6.3-arch1-1, LLVM 9.0.1)\n"); + g_free (additional_info); + + const gchar *error_message = + "libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)\n" + "vaInitialize (va_display, &major_version, &minor_version) failed: unknown libva error (-1)\n"; + + can_run = srt_system_info_can_run_va_api (info, "mock-bad"); + g_assert_false (can_run); + + additional_info = srt_system_info_dup_va_api_additional_info (info, "mock-bad"); + g_assert_cmpstr (additional_info, ==, error_message); + g_free (additional_info); + + g_object_unref (info); +} + static gint glx_icd_compare (SrtGlxIcd *a, SrtGlxIcd *b) { @@ -2706,6 +2737,9 @@ main (int argc, g_test_add ("/graphics/vdpau/can-run", Fixture, NULL, setup, test_vdpau_can_run, teardown); + g_test_add ("/graphics/va-api/can-run", Fixture, NULL, + setup, test_va_api_can_run, teardown); + g_test_add ("/graphics/glx/debian", Fixture, NULL, setup, test_glx_debian, teardown); g_test_add ("/graphics/glx/container", Fixture, NULL, diff --git a/tests/meson.build b/tests/meson.build index 260adff8f1e7ff0a3078e1f419dd58a9d0c4c4e4..f45f8bee9d2a3a62ad2fe1f84f3a8c5528489395 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -179,9 +179,11 @@ executable( # Helpers with no dependencies and one source file of the same name # as the helper itself. foreach helper : [ + 'mock-bad-check-va-api', 'mock-bad-check-vdpau', 'mock-bad-check-vulkan', 'mock-bad-vulkaninfo', + 'mock-good-check-va-api', 'mock-good-check-vdpau', 'mock-good-vulkaninfo', 'mock-hanging-wflinfo', diff --git a/tests/mock-bad-check-va-api.c b/tests/mock-bad-check-va-api.c new file mode 100644 index 0000000000000000000000000000000000000000..cca06c1697878b469509a3180585bb67de1850f8 --- /dev/null +++ b/tests/mock-bad-check-va-api.c @@ -0,0 +1,37 @@ +/* + * Copyright © 2020 Collabora Ltd. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> + +int +main (int argc, + char **argv) +{ + // Give bad output + fprintf (stderr, "libva error: vaGetDriverNameByIndex() failed with unknown libva error, driver_name = (null)\n"); + fprintf (stderr, "vaInitialize (va_display, &major_version, &minor_version) failed: unknown libva error (-1)\n"); + return 1; +} + diff --git a/tests/mock-good-check-va-api.c b/tests/mock-good-check-va-api.c new file mode 100644 index 0000000000000000000000000000000000000000..fd73038c0427709631eaf6ebba9c86d847a4454f --- /dev/null +++ b/tests/mock-good-check-va-api.c @@ -0,0 +1,36 @@ +/* + * Copyright © 2020 Collabora Ltd. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include <stdio.h> + +int +main (int argc, + char **argv) +{ + // Give good output + printf ("Mesa Gallium driver 20.0.4 for AMD Radeon RX 5700 XT (NAVI10, DRM 3.36.0, 5.6.3-arch1-1, LLVM 9.0.1)\n"); + return 0; +} +