device-select: fix build errors on some stricter build configurations

After commit 45eb3bfd32 (device-select: only try wayland/x11 if the
required vars are set, 2024-10-18), building `device_select_layer.c` can
results in compiler errors on some stricter build configurations
(-Werror,-Wunused-variable):

-----------------------------------------------------------------------
../src/vulkan/device-select-layer/device_select_layer.c:149:9: error: unused variable 'has_wayland' [-Werror,-Wunused-variable]
  149 |    bool has_wayland = getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET");
      |         ^~~~~~~~~~~
../src/vulkan/device-select-layer/device_select_layer.c:150:9: error: unused variable 'has_xcb' [-Werror,-Wunused-variable]
  150 |    bool has_xcb = !!getenv("DISPLAY");
      |         ^~~~~~~
2 errors generated.
-----------------------------------------------------------------------

So guard the declarations of the `has_wayland` and `has_xcb` variables
behind `VK_USE_PLATFORM_WAYLAND_KHR` and `VK_USE_PLATFORM_XCB_KHR`
respectively, just like the user code.

Note: the declarations are still kept outside of the loop body, in order
to assign the variables once and for all.

Reviewed-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37571>
This commit is contained in:
Antonio Ospite 2025-05-27 18:51:12 +02:00 committed by Marge Bot
parent d4f44edbff
commit 613bfe0b8b

View file

@ -127,8 +127,12 @@ device_select_CreateInstance(const VkInstanceCreateInfo *pCreateInfo,
info->xwayland = !strcmp(applicationName, "Xwayland");
info->xserver = !strcmp(applicationName, "Xorg") || !strcmp(applicationName, "Xephyr");
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
bool has_wayland = getenv("WAYLAND_DISPLAY") || getenv("WAYLAND_SOCKET");
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
bool has_xcb = !!getenv("DISPLAY");
#endif
for (unsigned i = 0; i < pCreateInfo->enabledExtensionCount; i++) {
#ifdef VK_USE_PLATFORM_WAYLAND_KHR