Linux | vkCreateInstance apparently breaks libraries using LibGL

Hello,

I’m having a few issues getting Vulkan to work with the new 364.12 driver, which were not present in the 355.00.29 beta driver.

First, Valgrind complains about vkCreateInstance not initializing something (tested with my own code and with these samples):

==31161== Conditional jump or move depends on uninitialised value(s)
==31161==    at 0x8BB4C99: ??? (in /usr/lib/libnvidia-glcore.so.364.12)
==31161==    by 0x8D0D54E: ??? (in /usr/lib/libnvidia-glcore.so.364.12)
==31161==    by 0x8BB13A4: ??? (in /usr/lib/libnvidia-glcore.so.364.12)
==31161==    by 0x8B2D9E2: ??? (in /usr/lib/libnvidia-glcore.so.364.12)
==31161==    by 0x766BA15: ??? (in /usr/lib/libGLX_nvidia.so.364.12)
==31161==    by 0x76BDDE2: ??? (in /usr/lib/libGLX_nvidia.so.364.12)
==31161==    by 0x506069F: ??? (in /usr/lib/libvulkan.so.1.0.5)
==31161==    by 0x5066D84: ??? (in /usr/lib/libvulkan.so.1.0.5)
==31161==    by 0x50699AF: vkCreateInstance (in /usr/lib/libvulkan.so.1.0.5)
==31161==    by 0x43261C: VulkanExampleBase::createInstance(bool) (in /home/xxx/Vulkan/build/bin/triangle)
==31161==    by 0x433DA8: VulkanExampleBase::initVulkan(bool) (in /home/xxx/Vulkan/build/bin/triangle)
==31161==    by 0x433967: VulkanExampleBase::VulkanExampleBase(bool) (in /home/xxx/Vulkan/build/bin/triangle)

Second, and that is the reason I used Valgrind at all, is that it kind of seems to break some internal state in the driver, which leads to segfaults when trying to use a library such as SDL or GLFW. I’ve put together a minimal sample program to demonstrate this (this one is using SDL2, but it’s exactly the same with GLFW3):

#include <iostream>
#include <SDL2/SDL.h>
#include <vulkan/vulkan.h>

int main(int argc, char** argv) {
  
  VkApplicationInfo applicationInfo;
  applicationInfo.sType               = VK_STRUCTURE_TYPE_APPLICATION_INFO;
  applicationInfo.pNext               = nullptr;
  applicationInfo.pApplicationName    = nullptr;
  applicationInfo.applicationVersion  = 0;
  applicationInfo.pEngineName         = nullptr;
  applicationInfo.engineVersion       = VK_MAKE_VERSION(1, 0, 0);
  applicationInfo.apiVersion          = VK_MAKE_VERSION(1, 0, 5);

  VkInstanceCreateInfo instanceCreateInfo;
  instanceCreateInfo.sType                    = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
  instanceCreateInfo.pNext                    = nullptr;
  instanceCreateInfo.flags                    = 0;
  instanceCreateInfo.pApplicationInfo         = &applicationInfo;
  instanceCreateInfo.enabledLayerCount        = 0;
  instanceCreateInfo.ppEnabledLayerNames      = nullptr;
  instanceCreateInfo.enabledExtensionCount    = 0;
  instanceCreateInfo.ppEnabledExtensionNames  = nullptr;
  
  VkInstance instance;
  VkResult   instanceCreationResult = vkCreateInstance(
    &instanceCreateInfo, nullptr, &instance);
  
  if (instanceCreationResult != VK_SUCCESS) {
    std::cout << "Failed to create Vulkan instance: Error "
              << instanceCreationResult
              << std::endl;
    return 1;
  }
  
  // SDL_Init crashes here. When the order is
  // reversed, i.e. if SDL is initialized before
  // the Vulkan instance, SDL_Quit will crash.
  if (SDL_Init(SDL_INIT_VIDEO) != 0) {
    std::cout << "Failed to initialize SDL: "
              << SDL_GetError()
              << std::endl;
    return 1;
  }
  
  SDL_Quit();
  vkDestroyInstance(instance, nullptr);
  return 0;
}

This segfaults with the following stack trace:

#0  0x00007ffff6ced71c in _wordcopy_fwd_aligned () from /usr/lib/libc.so.6
#1  0x00007ffff6ce7f25 in __memmove_sse2 () from /usr/lib/libc.so.6
#2  0x00007ffff56f6c89 in ?? () from /usr/lib/libnvidia-glcore.so.364.12
#3  0x00007ffff56f6dba in ?? () from /usr/lib/libnvidia-glcore.so.364.12
#4  0x00007ffff1602eae in ?? () from /usr/lib/libGL.so.1
#5  0x00007ffff7de837a in call_init.part () from /lib64/ld-linux-x86-64.so.2
#6  0x00007ffff7de84cb in _dl_init () from /lib64/ld-linux-x86-64.so.2
#7  0x00007ffff7deca50 in dl_open_worker () from /lib64/ld-linux-x86-64.so.2
#8  0x00007ffff7de8264 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#9  0x00007ffff7dec1e7 in _dl_open () from /lib64/ld-linux-x86-64.so.2
#10 0x00007ffff6a62f09 in ?? () from /usr/lib/libdl.so.2
#11 0x00007ffff7de8264 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
#12 0x00007ffff6a63521 in ?? () from /usr/lib/libdl.so.2
#13 0x00007ffff6a62fa1 in dlopen () from /usr/lib/libdl.so.2
#14 0x00007ffff795fe66 in ?? () from /usr/lib/libSDL2-2.0.so.0
#15 0x00007ffff7951bff in ?? () from /usr/lib/libSDL2-2.0.so.0
#16 0x00007ffff7953b0c in ?? () from /usr/lib/libSDL2-2.0.so.0
#17 0x00007ffff79537b5 in ?? () from /usr/lib/libSDL2-2.0.so.0
#18 0x00007ffff78b7f47 in ?? () from /usr/lib/libSDL2-2.0.so.0
#19 0x0000000000400cd6 in main (argc=1, argv=0x7fffffffdc98) at /home/xxx/vktest/main.cpp:40

If you need more information, please ask.

Hi,

Thank you for reporting this.

I was able to reproduce the first issue, which will be fixed shortly.

I am, however, unable to reproduce the segfault with your sample program. I am using Ubuntu 15.10 amd64 and built your example code with:

g++ vksdl2.cpp -std=gnu++0x -lSDL2 -lvulkan -g

Can you provide more details about how the segfault occurs?