mach icon indicating copy to clipboard operation
mach copied to clipboard

examples segfault on Ubuntu 22.04 (need to set VK_ICD_FILENAMES)

Open shakesoda opened this issue 2 years ago • 8 comments

compiled latest (88558b7d522dc9f6b41edf1ee33eb38b3fc59cda as of this moment) with the linked zig revision in readme, tried both cross build and native on windows 10 (developer mode, not wsl) and ubuntu 22.04, zig build run-example-boids produces a segfault that looks to be somewhere in dawn. aarch64 mac build runs fine, though.

edit: on windows it works with -Drelease-fast, but not linux, so i suspect it's accounted for by issues #456 / #464 on there. vulkan driver is definitely working on linux, judging by vkcube

shakesoda avatar Aug 24 '22 23:08 shakesoda

Thanks for the report! Things have become a bit bumpy lately, sorry it's not working :)

The windows issue is known and can be worked around with release-fast, as you noted.

I haven't heard of any Linux segfaults yet, though. I'll test on my Linux machine again soon. If you don't mind, perhaps you could capture a stack trace of the Linux crash for me? e.g. by running the binary with lldb -- /path/to/mach/zig-out/bin/example-boids, type run, and then bt once it crashes

emidoots avatar Aug 25 '22 03:08 emidoots

sure thing. here's everything above start.zig from gdb:

Thread 1 "example-boids" received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) bt
#0  0x0000000000000000 in ?? ()
#1  0x00007fffed74bf38 in ?? ()
   from /lib/x86_64-linux-gnu/libVkLayer_MESA_device_select.so
#2  0x00007fffed74c617 in ?? ()
   from /lib/x86_64-linux-gnu/libVkLayer_MESA_device_select.so
#3  0x00007ffff7010765 in ?? () from /usr/lib/x86_64-linux-gnu/libvulkan.so.1
#4  0x00007ffff7021592 in vkEnumeratePhysicalDevices ()
   from /usr/lib/x86_64-linux-gnu/libvulkan.so.1
#5  0x000000000530b511 in dawn::native::vulkan::GatherPhysicalDevices(VkInstance_T*, dawn::native::vulkan::VulkanFunctions const&) ()
    at libs/dawn/src/dawn/native/vulkan/VulkanInfo.cpp:129
#6  0x00000000052e01cf in dawn::native::vulkan::VulkanInstance::Initialize(dawn::native::InstanceBase const*, dawn::native::vulkan::ICD) ()
    at libs/dawn/src/dawn/native/vulkan/BackendVk.cpp:282
#7  0x00000000052dece6 in dawn::native::vulkan::VulkanInstance::Create(dawn::native::InstanceBase const*, dawn::native::vulkan::ICD) ()
    at libs/dawn/src/dawn/native/vulkan/BackendVk.cpp:203
#8  0x00000000052e3bf9 in dawn::native::vulkan::Backend::DiscoverAdapters(dawn::native::AdapterDiscoveryOptionsBase const*)::$_2::operator()() const ()
    at libs/dawn/src/dawn/native/vulkan/BackendVk.cpp:462
#9  0x00000000052e3463 in dawn::native::vulkan::Backend::DiscoverAdapters(dawn::native::AdapterDiscoveryOptionsBase const*) ()
    at libs/dawn/src/dawn/native/vulkan/BackendVk.cpp:461
#10 0x00000000052e2ed3 in dawn::native::vulkan::Backend::DiscoverDefaultAdapters() () at libs/dawn/src/dawn/native/vulkan/BackendVk.cpp:433
#11 0x00000000037a0d95 in dawn::native::InstanceBase::DiscoverDefaultAdapters()
    () at libs/dawn/src/dawn/native/Instance.cpp:272
#12 0x000000000379f2f0 in dawn::native::InstanceBase::RequestAdapterInternal(dawn::native::RequestAdapterOptions const*) ()
    at libs/dawn/src/dawn/native/Instance.cpp:196
#13 0x000000000379ec5c in dawn::native::InstanceBase::APIRequestAdapter(dawn::native::RequestAdapterOptions const*, void (*)(WGPURequestAdapterStatus, WGPUAdapterImpl*, char const*, void*), void*) ()
    at libs/dawn/src/dawn/native/Instance.cpp:162
#14 0x0000000003709873 in dawn::native::NativeInstanceRequestAdapter(WGPUInstanceImpl*, WGPURequestAdapterOptions const*, void (*)(WGPURequestAdapterStatus, WGPUAdapterImpl*, char const*, void*), void*) ()
    at libs/dawn/out/Debug/gen/src/dawn/native/ProcTable.cpp:826
#15 0x0000000005b5034d in .app.gpu.dawn_impl.Interface.instanceRequestAdapter (
    instance=0x5ee6800, options=0x7fffffffc4d8, 
    callback=0x5b56200 <.app.gpu.instance.Helper.cCallback>, 
    userdata=0x7fffffffc4f0) at /media/src/mach/gpu/src/dawn_impl.zig:677
#16 .app.gpu.instance.Instance.requestAdapter (instance=0x5ee6800, 
    options=0x7fffffffc4d8, context=0x7fffffffc4f0)
    at /media/src/mach/gpu/src/instance.zig:51
#17 Platform.init (allocator=..., core=0x7ffff7ffa000)
    at /media/src/mach/src/platform/native.zig:92
#18 0x0000000005b4da36 in .app.mach.Core.init (allocator=..., 
    core=0x7ffff7ffa000) at Core.zig:41
#19 0x0000000005b4afb5 in coreInit (allocator=...)
    at /media/src/mach/src/platform/native.zig:622
#20 0x0000000005b4ab49 in main ()
    at /media/src/mach/src/platform/native.zig:601
#21 0x0000000005b4bd40 in std.start.callMain ()

looks like vkEnumeratePhysicalDevices is failing in dawn. if nothing else i know my vulkan driver is fine since vkcube runs (as do some other vulkan tests/apps) and vulkaninfo reports everything looking fine, shows gpu 0 as intel hd 620 (kaby lake gt2).

shakesoda avatar Aug 25 '22 23:08 shakesoda

Oh no, that's not great, this being in vkEnumeratePhysicalDevices means I likely won't be able to reproduce it on any of my systems :(

After some googling, it looks like this is a rather common issue to run into with Vulkan on Linux actually. this thread suggests that we might be seeing it pick up 32-bit Vulkan drivers by accident. I am curious if you have any such drivers on your system?

find /usr/lib/i386-linux-gnu/ | grep libvulkan

emidoots avatar Aug 26 '22 22:08 emidoots

i do, yes:

$ find /usr/lib/i386-linux-gnu/ | grep libvulkan
/usr/lib/i386-linux-gnu/libvulkan_radeon.so
/usr/lib/i386-linux-gnu/libvulkan.so.1.3.204
/usr/lib/i386-linux-gnu/libvulkan.so.1
/usr/lib/i386-linux-gnu/libvulkan_intel.so
/usr/lib/i386-linux-gnu/libvulkan_lvp.so

shakesoda avatar Aug 26 '22 23:08 shakesoda

Looks like it might be a regression/bug in vulkan-loader that has perhaps been fixed already but hasn't made its way into a release/Dawn, https://github.com/lutris/lutris/issues/4158 - this would explain why vkcube works on your system while Mach doesn't.

Try the following: run ls /usr/share/vulkan/icd.d/ to see which driver ICD json files you have, there should be one here that indicates it's an intel (or mesa) driver in the filename. Then export this (replacing nvidia_icd.json with your ICD filename) to force selection of that graphics driver / ICD:

export VK_ICD_FILENAMES="/usr/share/vulkan/icd.d/nvidia_icd.json"

Then run with vulkan-loader debug logging:

export VK_LOADER_DEBUG=all
zig build run-example-boids

Does that work? If not, let me know what debug logs look like.

emidoots avatar Aug 27 '22 00:08 emidoots

looks like that's the culprit, it worked (using export VK_ICD_FILENAMES=/usr/share/vulkan/icd.d/intel_icd.x86_64.json on this system):

image

shakesoda avatar Aug 27 '22 01:08 shakesoda

OK that's great to hear, this will probably auto-resolve itself once we update Dawn again in the near future.

I'd suggest you set that in your bash profile generally, there are a lot of other Vulkan games that have this issue too (there's no harm in doing so.)

Do you mind if I ping you in the future to try it again to see if we did in fact fix it?

emidoots avatar Aug 27 '22 02:08 emidoots

I don't mind at all :+1:

shakesoda avatar Aug 27 '22 03:08 shakesoda