Michael IV
Michael IV

Reputation: 11424

Vulkan create VK_KHR_surface error: VK_ERROR_EXTENSION_NOT_PRESENT

I am learning Vulkan via this tutorial. I have created window with GLFW and initialized Vulkan instance without errors. But Vulkan fails to create 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() looks like this:

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 the following required extensions:

VK_KHR_surface

VK_KHR_xcb_surface

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

Returns VK_ERROR_EXTENSION_NOT_PRESENT

Why the surface creation fails?

My system: Ubuntu 18.04 64bit, NVIDIA RTX3000, GPU Driver NVIDIA 430

Upvotes: 1

Views: 3721

Answers (1)

krOoze
krOoze

Reputation: 13246

You are creating instance into a local variable:

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

Probably supposed to be VkInstance&.

Upvotes: 2

Related Questions