Vulkan create VK_KHR_surface error: VK_ERROR_EXTENSION_NOT_PRESENT

Vulkan create VK_KHR_surface error: VK_ERROR_EXTENSION_NOT_PRESENT

我正在通过 this 教程学习 Vulkan。 我已经使用 GLFW 创建了 window 并且没有错误地初始化了 Vulkan 实例。但是 Vulkan 无法创建 VKSurfaceKHR.

bool CreateRenderContext(RenderContext* contextOut)
{
  glfwInit();
  glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
  glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
  contextOut->window = glfwCreateWindow(contextOut->width, contextOut->height, "Vulkan", NULL, NULL);

  if(!CreateVulkanInstance(contextOut->instance))
  {
    printf("failed creating vulkan instance\n");
  }

  if(!glfwVulkanSupported())
  {
    return false;
  }

  VkResult err = glfwCreateWindowSurface(contextOut->instance, contextOut->window,nullptr, &contextOut->surface);
  if (err != VK_SUCCESS)
  {
    // Window surface creation failed
    printf("failed to create surface");
    return false;
  }
  return true;
}

CreateVulkanInstance() 看起来像这样:

bool CreateVulkanInstance(VkInstance  instanceOut)

{

  VkApplicationInfo appInfo = {};
  appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
  appInfo.pApplicationName = "Hello Triangle";
  appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
  appInfo.pEngineName = "No Engine";
  appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
  appInfo.apiVersion = VK_API_VERSION_1_0;

  VkInstanceCreateInfo createInfo = {};
  createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
  createInfo.pApplicationInfo = &appInfo;

  uint32_t glfwExtensionCount = 0;
  const char** glfwExtensions = nullptr;
  glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);

  createInfo.enabledExtensionCount = glfwExtensionCount;
  createInfo.ppEnabledExtensionNames = glfwExtensions;
  createInfo.enabledLayerCount = 0;

  if (vkCreateInstance(&createInfo, nullptr, &instanceOut) != VK_SUCCESS)
  { 
    return false;
  }

  return true;
}

GLFW returns 需要以下扩展:

VK_KHR_surface

VK_KHR_xcb_surface

但是 VkResult err = glfwCreateWindowSurface(contextOut->instance, contextOut->window,nullptr, &contextOut->surface);

Returns VK_ERROR_EXTENSION_NOT_PRESENT

为什么表面创建失败?

我的系统: Ubuntu 18.04 64 位,NVIDIA RTX3000,GPU 驱动程序 NVIDIA 430

您正在将实例创建到局部变量中:

bool CreateVulkanInstance(VkInstance  instanceOut) {
   vkCreateInstance(&createInfo, nullptr, &instanceOut)
}

可能应该是 VkInstance&