Warpspeed SCP
Warpspeed SCP

Reputation: 174

What could cause vkCreateDevice() to fail without giving a reason for failure?

I'm learning vulkan with the vulkan cookbook, and I now find myself at an impasse:

If I try to pass extensions, namely, VK_KHR_SURFACE_EXTENSION_NAME and VK_KHR_WIN32_SURFACE_EXTENSION_NAME in the list of extensions in the VkDeviceCreateInfo structure that I send to vkCreateDevice, the function fails without any error (It doeesn't return VK_SUCCESS)

I've checked, and I know that my graphics card supports all the extensions that I'm trying to pass. I tried reading the output from validation layers, but they don't seem to catch the reason for failure (I enabled the VK_LAYER_LUNARG_api_dump and standard validation layers).

My function to create a logical device looks like this-

bool create_logical_device(VkPhysicalDevice &physDev, VkDevice &device,
                           std::vector<char const *> &desExts,
                           std::vector<queueInfo> &qInfos,
                           VkPhysicalDeviceFeatures &physDevFtrs) 
{
  std::vector<VkDeviceQueueCreateInfo> qCreateInfo;
  std::vector<VkExtensionProperties> physDevExtProps;

  if (!get_avl_phys_dev_exts(physDev, physDevExtProps))
    return false;

  for (auto &ext : desExts) 
  {
    if (!is_ext_available(physDevExtProps, ext))
      return false;
  }

  for (auto &i : qInfos) 
  {
    qCreateInfo.push_back(
        {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO, 
            nullptr, 
            0, 
            i.FamilyIndex,
            (uint32_t)i.Priorities.size(),
            i.Priorities.size() > 0 ? i.Priorities.data() : nullptr
        });
  }

  VkDeviceCreateInfo devCreateInfo = 
  {
      VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
      nullptr,
      0,
      (uint32_t)qCreateInfo.size(),
      qCreateInfo.size() > 0 ? qCreateInfo.data() : nullptr,
      0,
      nullptr,
      (uint32_t)desExts.size(),
      desExts.size() > 0 ? desExts.data() : nullptr,
      &physDevFtrs

  };



#ifdef ENABLE_VALIDATION
  devCreateInfo.enabledLayerCount = (uint32_t)valLayers.size();
  devCreateInfo.ppEnabledLayerNames = valLayers.data();
#endif

  if (vkCreateDevice(physDev, &devCreateInfo, nullptr, &device) != VK_SUCCESS) 
  {
    std::cout << "Could not create logical device!" << std::endl;
    return false;
  }

  std::cout << "Succesfully created logical device" << std::endl;

  return true;
}

valLayers is a constant vector in the global scope.

This failure occurs on both windows and linux, so it can only be something on my side. Running the code through the debugger didn't reveal anything to me. What could I be doing wrong?

Upvotes: 1

Views: 1852

Answers (1)

Ekzuzy
Ekzuzy

Reputation: 3457

Are You sure You are providing valid extension names? VK_KHR_SURFACE_EXTENSION_NAME is an instance extension, so it shouldn't be provided during device creation.

And thanks for using/reading/learning from the Vulkan Cookbook ;-).

Upvotes: 4

Related Questions