Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Vulkan validation layers

Discussion in 'General Graphics' started by okluskyond, Mar 18, 2020.

  1. okluskyond

    okluskyond

    Joined:
    Dec 6, 2017
    Posts:
    34
    Hi,

    is it possible to incorporate Vulkan validation layers into Unity build somehow? Or how do you deal with bugs that freeze Unity only on some specific outdated devices?

    Thanks for answer
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,864
    Hi!
    Debug builds should have them enabled by default.
     
  3. okluskyond

    okluskyond

    Joined:
    Dec 6, 2017
    Posts:
    34
    Hi,

    Oh, what a terrible mistake I've made.

    Thanks for answer :). Saved my day
     
  4. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    Sounds like you already solved your problem, so this is just for the record:

    Have a look at https://developer.android.com/ndk/guides/graphics/validation-layer about how to get and enable Vulkan validation layers on Android.

    Unity implements parts of this internally. You can force the Unity runtime to try to load validation layers using the command line switch "-force-vulkan-layers". A way to pass command line switches to Unity on Android is described here https://docs.unity3d.com/Manual/AndroidUnityPlayerActivity.html.
    You can add the Vulkan validation layer libraries to your Unity project similar to any other native plugin, but you have to make sure that you don't ship them with release builds.
    Unity should then print all validation warnings and errors to logcat. Please also check the logcat output of a Development Build to make sure that the validation layers are actually enabled.
     
  5. okluskyond

    okluskyond

    Joined:
    Dec 6, 2017
    Posts:
    34
    Thanks for more indepth answer.

    I have figured out that when you pack Validation Layers from NDK (https://developer.android.com/ndk/guides/graphics/validation-layer) using gradle, or just throught Unity Plugins folder leads some result. Unity on start prints to logcat, that those validation layers were added. So I was convinced, that everything works as expected (even if no further errors appeared).

    Is "-force-vulkan-layers" mandatory then?
     
  6. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479
    You still need to enable the layer somehow.
    So if you just see "vulkan : added global layer 'VK_LAYER_KHRONOS_validation' from library ..." in logcat that's not enough. With "-force-vulkan-layers" you should see something like "Unity : [Vulkan init] layer enabled: VK_LAYER_KHRONOS_validation" and "[Vulkan init] extensions: name=VK_EXT_debug_report, enabled=1".

    Please note that older Unity versions need the legacy validation layers (VK_LAYER_LUNARG_core_validation etc).
     
  7. okluskyond

    okluskyond

    Joined:
    Dec 6, 2017
    Posts:
    34
    Ah great :) this is probably the piece of puzzle I was missing :) I'll give it a try and if some problems occurs, will try to get more info. You have been really helpfull and this may help others in the same situation :)
     
  8. okluskyond

    okluskyond

    Joined:
    Dec 6, 2017
    Posts:
    34
    Finally got it working

    Thanks
     
    florianpenzkofer likes this.
  9. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    @florianpenzkofer @aleksandrk

    thanks for the useful info in this thread, literally the only place about -force-vulkan-layers

    I get a crash when trying to use validation on 2021.2.8 posting here in case other's are encountering similar problems.

    I am using the libVkLayer_khronos_validation.so files copied to the project's plugins folder, from the NDK that gets installed by Unity Hub, located in C:\Program Files\Unity\Hub\Editor\2021.2.8f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK\sources\third_party\vulkan\src\build-android\jniLibs\

    to activate validation I launch using adb:
    adb shell am start -n com.DefaultCompany.VulkanVRSRP/com.unity3d.player.UnityPlayerActivity -e unity -force-vulkan-layers

    I can see that the validation layer is enabled, but immediately when the first frame renders it crashes. (It does not crash when validation is inactive)

    Code (CSharp):
    1. Debug Unity Vulkan validation error./Runtime/GfxDevice/vulkan/VKDebug.cpp:34
    2. Debug Unity  #00 0xc67394a4 0xc67394a4 (libunity.so) vk::DebugKHRDefaultCallback(unsigned int, VkDebugReportObjectTypeEXT, unsigned long long, unsigned int, int, char const*, char const*, void*) 0x144
    3. Debug Unity  #01 0xb7bc7b3b 0xb7bc7b3b (libVkLayer_khronos_validation.so) ? 0x0
    4. Debug Unity  #02 0xb7bc1121 0xb7bc1121 (libVkLayer_khronos_validation.so) ? 0x0
    5. Debug Unity  #03 0xb7bc2087 0xb7bc2087 (libVkLayer_khronos_validation.so) ? 0x0
    6. Debug Unity  #04 0xb7b33cf3 0xb7b33cf3 (libVkLayer_khronos_validation.so) ? 0x0
    7. Debug Unity  #05 0xc675b804 0xc675b804 (libunity.so) vk::TaskExecutor::HandleCommandStream(GrowableBuffer*, VkCommandBuffer_T*) 0x14b0
    8. Debug Unity  #06 0xc675a244 0xc675a244 (libunity.so) vk::TaskExecutor::ExecuteCommandbuffers(vk::CommandBuffer**, int) 0x180
    9. Debug Unity  #07 0xc6758838 0xc6758838 (libunity.so) vk::TaskExecutor::DoFlush(unsigned long long, unsigned long long, unsigned long long) 0x38
    10. Debug Unity  #08 0xc6756fd8 0xc6756fd8 (libunity.so) vk::TaskExecutor::HandleTaskStream() 0x408
    11. Debug Unity  #09 0xc6756aac 0xc6756aac (libunity.so) vk::TaskExecutor::ThreadEntry(void*) 0x2c
    12. Debug Unity  #10 0xc5f8ffc3 0xc5f8ffc3 (libunity.so) Thread::RunThreadWrapper(void*) 0x206
    13. Debug Unity  #11 0xee21e6d5 0xee21e6d5 (libc.so) __init_static_tls(void*) 0x48
    14. Debug Unity  #12 0xb6bcdffe 0xb6bcdffe (kgsl-3d0) ? 0x0
    15. Info Unity VULKAN DEBUG: ERROR:  [Validation, 0]:  [ VUID-VkRenderPassBeginInfo-framebuffer-parameter ] Object: 0x2a (Type = 24) | Invalid VkFramebuffer Object 0x2a. The Vulkan spec states: framebuffer must be a valid VkFramebuffer handle (https://www.khronos.org/registry/vulkan/specs/1.1-extensions/html/vkspec.html#VUID-VkRenderPassBeginInfo-framebuffer-parameter)
    16. Error CRASH *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
    17. Error CRASH Version '2021.2.8f1 (d0e5f0a7b06a)', Build type 'Development', Scripting Backend 'mono', CPU 'armeabi-v7a'
    18. Error CRASH Revision: '0'
    19. Error CRASH ABI: 'arm'
    20. Error CRASH Timestamp: 2022-03-24 17:27:56-0700
    21. Error CRASH pid: 7430, tid: 7531, name: Vulkan Submissi  >>> com.DefaultCompany.VulkanVRSRP <<<
    22. Error CRASH uid: 10103
    23. Error CRASH signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x40
    24. Error CRASH Cause: null pointer dereference
    25. Error CRASH     r0  00000000  r1  00000001  r2  00000000  r3  91dded4a
    26. Error CRASH     r4  c2b6d180  r5  bbfe7000  r6  00000000  r7  b6ccae78
    27. Error CRASH     r8  00000000  r9  00000001  r10 c2b6d180  r11 00000000
    28. Error CRASH     ip  b6ccadf8  sp  b6ccae20  lr  b7a8146f  pc  b7a676ac
    29. Error CRASH
    30. Error CRASH backtrace:
    31. Error CRASH       #00 pc 0019a6ac  /data/app/com.DefaultCompany.VulkanVRSRP-7F3aba1VFTwwBGZHhuwF8Q==/lib/arm/libVkLayer_khronos_validation.so (BuildId: 512eeb7e849eeaa63f97bed51a8ec332be7620ff)
    32. Error CRASH       #01 pc 0019b48b  /data/app/com.DefaultCompany.VulkanVRSRP-7F3aba1VFTwwBGZHhuwF8Q==/lib/arm/libVkLayer_khronos_validation.so (BuildId: 512eeb7e849eeaa63f97bed51a8ec332be7620ff)
    33. Error CRASH       #02 pc 00266cf3  /data/app/com.DefaultCompany.VulkanVRSRP-7F3aba1VFTwwBGZHhuwF8Q==/lib/arm/libVkLayer_khronos_validation.so (BuildId: 512eeb7e849eeaa63f97bed51a8ec332be7620ff)
    34. Error CRASH       #03 pc 01068804  /data/app/com.DefaultCompany.VulkanVRSRP-7F3aba1VFTwwBGZHhuwF8Q==/lib/arm/libunity.so (vk::TaskExecutor::HandleCommandStream(GrowableBuffer*, VkCommandBuffer_T*)+5296) (BuildId: 7686810daf0a1f74bd65bab634f96fd92c520192)
    35. Error CRASH       #04 pc 01067244  /data/app/com.DefaultCompany.VulkanVRSRP-7F3aba1VFTwwBGZHhuwF8Q==/lib/arm/libunity.so (vk::TaskExecutor::ExecuteCommandbuffers(vk::CommandBuffer**, int)+384) (BuildId: 7686810daf0a1f74bd65bab634f96fd92c520192)
    36. Error CRASH       #05 pc 01065838  /data/app/com.DefaultCompany.VulkanVRSRP-7F3aba1VFTwwBGZHhuwF8Q==/lib/arm/libunity.so (vk::TaskExecutor::DoFlush(unsigned long long, unsigned long long, unsigned long long)+56) (BuildId: 7686810daf0a1f74bd65bab634f96fd92c520192)
    37. Error CRASH       #06 pc 01063fd8  /data/app/com.DefaultCompany.VulkanVRSRP-7F3aba1VFTwwBGZHhuwF8Q==/lib/arm/libunity.so (vk::TaskExecutor::HandleTaskStream()+1032) (BuildId: 7686810daf0a1f74bd65bab634f96fd92c520192)
    38. Error CRASH       #07 pc 01063aac  /data/app/com.DefaultCompany.VulkanVRSRP-7F3aba1VFTwwBGZHhuwF8Q==/lib/arm/libunity.so (vk::TaskExecutor::ThreadEntry(void*)+44) (BuildId: 7686810daf0a1f74bd65bab634f96fd92c520192)
    39. Error CRASH       #08 pc 0089cfc3  /data/app/com.DefaultCompany.VulkanVRSRP-7F3aba1VFTwwBGZHhuwF8Q==/lib/arm/libunity.so (Thread::RunThreadWrapper(void*)+518) (BuildId: 7686810daf0a1f74bd65bab634f96fd92c520192)
    40. Error CRASH       #09 pc 000996d5  /apex/com.android.runtime/lib/bionic/libc.so (__init_static_tls(void*)+72) (BuildId: d1568497ed5b358f7b37d4db225ec799)
    41. Error CRASH       #10 pc fffffffe  <anonymous:b6bce000>
     
  10. florianpenzkofer

    florianpenzkofer

    Unity Technologies

    Joined:
    Sep 2, 2014
    Posts:
    479