Dav1dde / glad

Multi-Language Vulkan/GL/GLES/EGL/GLX/WGL Loader-Generator based on the official specs.
https://glad.dav1d.de/
Other
3.79k stars 448 forks source link

EnumeratePhysicalDevices returns 0 GPUs #375

Closed Sven-v-Beuningen closed 2 years ago

Sven-v-Beuningen commented 2 years ago

Hi guys,

I'm new to Vulkan, but used glad for OpenGL in the past. I'm trying to port a Vulkan tutorial to GLAD, but I'm stuck right in the beginning. I tried the following:

#define VK_USE_PLATFORM_WIN32_KHR
#define GLAD_VULKAN_IMPLEMENTATION
#include <glad/vulkan.h>

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_2;

std::vector<const char*> enabledInstanceExtensions = {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME};

VkInstanceCreateInfo createInfo    = {};
createInfo.sType                   = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo        = &appInfo;
createInfo.enabledExtensionCount   = (uint32_t)enabledInstanceExtensions.size();
createInfo.ppEnabledExtensionNames = enabledInstanceExtensions.data();

GladVulkanContext ctx;
const auto version = gladLoaderLoadVulkanContext(&ctx, nullptr, nullptr, nullptr);

VkInstance instance;
const auto error = ctx.CreateInstance(&createInfo, nullptr, &instance);

uint32_t deviceCount = 0;
ctx.EnumeratePhysicalDevices(instance, &deviceCount, nullptr);
if (deviceCount == 0)
{
  std::cout << "Where are the devices?";
}

The code does work up to "ctx.EnumeratePhysicalDevices". Here I just get 0 devices. I tried the same without glad and just pure Vulkan code and with this I get 1 GPU as result:

#include <vulkan/vulkan.h>

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_2;

std::vector<const char*> enabledInstanceExtensions = {VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME};

VkInstanceCreateInfo createInfo    = {};
createInfo.sType                   = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo        = &appInfo;
createInfo.enabledExtensionCount   = (uint32_t)enabledInstanceExtensions.size();
createInfo.ppEnabledExtensionNames = enabledInstanceExtensions.data();

 VkInstance instance;
const auto error = vkCreateInstance(&createInfo, nullptr, &instance);

uint32_t deviceCount = 0;
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
if (deviceCount == 0)
{
  std::cout << "Where are the devices?";
}

Does someone have an Idea what I might miss, to get a valid result?

Thank You

Sven

Dav1dde commented 2 years ago

Does the Vulkan example work for you and if it does, can you try using a loader without MX enabled (maybe it's a MX bug)?

Sven-v-Beuningen commented 2 years ago

I did not finish the example so far, but at least up to creating a swap chain everything is fine. The MX thing gave me the right hint. Without MX it's just behaving as expected. I just got 1 gpu from vkEnumeratePhysicalDevices.

Of course, I'm nuw using gladLoaderLoadVulkan(nullptr, nullptr, nullptr);

Dav1dde commented 2 years ago

Thanks, I'll have to see why it breaks for MX, I can't really see why it would.

Dav1dde commented 2 years ago

I can't reproduce this.