Home > Mobile >  vkCreateInstance() taking an unreasonable amount of time with validation layers and VSCode
vkCreateInstance() taking an unreasonable amount of time with validation layers and VSCode

Time:05-15

I noticed my Vulkan program takes almost 10 seconds before actually responding after window creation; after some testing, I got the cause down to vkCreateInstance().

Here's the interesting part: this issue only occurs when running through VSCode - debugging or no debugging - and if the program is making use of validation layers (VK_EXT_debug_utils). That is to say the following:

The program works under the following conditions:

  • It is being run stand-alone (no VSCode) with debug utils
  • It is being run stand-alone (no VSCode) without debug utils
  • It is being run in VSCode, without debug utils

But the program does not work when:

  • It is being run in VSCode with debug utils.

(By 'work' I mean run without any significant delays)

I am on Linux with a Radeon RX 480, using RADV (Mesa) drivers.

Update 1

Looks like I wasn't using a validation layer when creating the instance - now I have done that, and the following output is returned during vkCreateInstance() when launching via VSCode:

[vlk] Searching for layer manifest files
[vlk]    In following folders:
[vlk]       /home/jack/.config/vulkan/implicit_layer.d
[vlk]       /etc/xdg/vulkan/implicit_layer.d
[vlk]       /etc/vulkan/implicit_layer.d
[vlk]       /home/jack/.local/share/vulkan/implicit_layer.d
[vlk]       /usr/local/share/vulkan/implicit_layer.d
[vlk]       /usr/share/vulkan/implicit_layer.d
[vlk]    Found the following files:
[vlk]       /home/jack/.local/share/vulkan/implicit_layer.d/steamfossilize_i386.json
[vlk]       /home/jack/.local/share/vulkan/implicit_layer.d/steamoverlay_x86_64.json
[vlk]       /home/jack/.local/share/vulkan/implicit_layer.d/steamoverlay_i386.json
[vlk]       /home/jack/.local/share/vulkan/implicit_layer.d/steamfossilize_x86_64.json
[vlk]       /usr/share/vulkan/implicit_layer.d/amd_icd64.json
[vlk]       /usr/share/vulkan/implicit_layer.d/amd_icd32.json
[vlk] Found manifest file /home/jack/.local/share/vulkan/implicit_layer.d/steamfossilize_i386.json (file version "1.0.0")
[vlk] Found manifest file /home/jack/.local/share/vulkan/implicit_layer.d/steamoverlay_x86_64.json (file version "1.0.0")
[vlk] Found manifest file /home/jack/.local/share/vulkan/implicit_layer.d/steamoverlay_i386.json (file version "1.0.0")
[vlk] Found manifest file /home/jack/.local/share/vulkan/implicit_layer.d/steamfossilize_x86_64.json (file version "1.0.0")
[vlk] Found manifest file /usr/share/vulkan/implicit_layer.d/amd_icd64.json (file version "1.0.0")
[vlk] Found manifest file /usr/share/vulkan/implicit_layer.d/amd_icd32.json (file version "1.0.0")
[vlk] Searching for layer manifest files
[vlk]    In following folders:
[vlk]       /home/jack/.config/vulkan/explicit_layer.d
[vlk]       /etc/xdg/vulkan/explicit_layer.d
[vlk]       /etc/vulkan/explicit_layer.d
[vlk]       /home/jack/.local/share/vulkan/explicit_layer.d
[vlk]       /usr/local/share/vulkan/explicit_layer.d
[vlk]       /usr/share/vulkan/explicit_layer.d
[vlk]    Found the following files:
[vlk]       /etc/vulkan/explicit_layer.d/VkLayer_screenshot.json
[vlk]       /etc/vulkan/explicit_layer.d/VkLayer_monitor.json
[vlk]       /etc/vulkan/explicit_layer.d/VkLayer_api_dump.json
[vlk]       /etc/vulkan/explicit_layer.d/VkLayer_device_simulation.json
[vlk]       /usr/share/vulkan/explicit_layer.d/VkLayer_khronos_validation.json
[vlk] Found manifest file /etc/vulkan/explicit_layer.d/VkLayer_screenshot.json (file version "1.2.0")
[vlk] Found manifest file /etc/vulkan/explicit_layer.d/VkLayer_monitor.json (file version "1.0.0")
[vlk] Found manifest file /etc/vulkan/explicit_layer.d/VkLayer_api_dump.json (file version "1.2.0")
[vlk] Found manifest file /etc/vulkan/explicit_layer.d/VkLayer_device_simulation.json (file version "1.2.0")
[vlk] Found manifest file /usr/share/vulkan/explicit_layer.d/VkLayer_khronos_validation.json (file version "1.2.0")
[vlk] Searching for driver manifest files
[vlk]    In following folders:
[vlk]       /usr/share/vulkan/icd.d/radeon_icd.x86_64.json
[vlk]    Found the following files:
[vlk]       /usr/share/vulkan/icd.d/radeon_icd.x86_64.json
[vlk] Found ICD manifest file /usr/share/vulkan/icd.d/radeon_icd.x86_64.json, version "1.0.0"
[vlk] Searching for ICD drivers named /usr/lib/libvulkan_radeon.so
[vlk] Build ICD instance extension list
[vlk] Loading layer library libVkLayer_khronos_validation.so
[vlk] Insert instance layer VK_LAYER_KHRONOS_validation (libVkLayer_khronos_validation.so)
[vlk] /usr/lib32/amdvlk32.so: wrong ELF class: ELFCLASS32
[vlk] Loading layer library /usr/lib/amdvlk64.so
[vlk] Insert instance layer VK_LAYER_AMD_switchable_graphics_64 (/usr/lib/amdvlk64.so)
[vlk] Requested layer VK_LAYER_AMD_switchable_graphics_32 was wrong bit-type.
[vlk] Build ICD instance extension list

The output log is the same outside of Visual Studio Code.

CodePudding user response:

After looking more into the issue, I have found a workaround that, whilst it doesn't completely eliminate the delay, minimises it to almost instant. About ~8-9 seconds down to an average of about ~2-3. Not perfect, but leagues ahead of the previous time.

It turns out it was GDB that, for whatever reason, caused this delay. Maybe something that someone on either the GDB or Vulkan team should look into? I don't know. In any case, VSCode was using GDB to debug the program.

So to fix the problem: use LLDB instead. Luckily I'm not limited to using GDB for any reason and LLDB seems to be a perfectly good debugger as well. There might be others I don't know about that work even better... I'll look further into it at some point in the future.

In my case, since I use VSCode, this extension was useful for integrating LLDB into the launch.json system that Code has.

  • Related