0
votes

I always thought that on android platform we were supposed to load the pointer to Vulkan library using dlopen() and dlsym() (something like that:

libVulkan = dlopen("libvulkan.so", RTLD_NOW | RTLD_LOCAL);
vkEnumerateInstanceExtensionProperties = reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties(dlsym(libVulkan,"vkEnumerateInstanceExtensionProperties"));

(source: https://github.com/SaschaWillems/Vulkan/blob/master/base/VulkanAndroid.cpp)

)

or by using the "vulkan_wrapper.h" dynamic loader (like in the Vulkan Android Samples by google https://github.com/googlesamples/android-vulkan-tutorials)

I was able to build and run the hello_xr sample on the oculus quest thanks to the blog of Gayan Ediriweera (https://gayanediriweera.github.io/code/2021/04/06/how-to-run-helloxr-on-oculus-quest.html)

However when I look at the code for the hello_xr sample for vulkan I haven't seen call to dlopen() or dlsym(). For example at line 1287 (https://github.com/KhronosGroup/OpenXR-SDK-Source/blob/master/src/tests/hello_xr/graphicsplugin_vulkan.cpp), the sample call vkEnumerateInstanceLayerProperties but I don't see where the pointer for this base function is loaded which is confusing me.

What is the kind of black magic that is going on here ? Does the OpenXR runtime load these under the hood or am I missing something in the code?

Thanks in advance for any help on this

1
Do you know what dlopen does? Do you know why you don't need to use dlopen to call printf?user253751
@user253751 Isn't it for dynamically loading a shared library ? is the answer of the second question linked to the answer of this question ? stackoverflow.com/questions/63306734/…LauVB

1 Answers

0
votes

When you want to call a function from some library, there are two ways to do it:

  1. Tell the compiler you want to use the library. Then, just use the function.
  2. Don't tell the compiler you want to use the library. Instead, call dlopen to load the library and then call dlsym to look up the functions in the library, and call them.

The first way is the normal way to use a library. The second way is something you only do with a good reason - for example if you're not sure that the library is installed.

I would guess that Android has some good reason to use dlopen (perhaps old versions of Android don't have Vulkan installed?) and OpenXR does not.