aejsmith / vkdevicechooser

Vulkan layer to force a specific device to be used
MIT License
77 stars 18 forks source link

Same GPU index refers to different GPUs between vkdevicechooser & vulkaninfo? #19

Open genpfault opened 2 years ago

genpfault commented 2 years ago

I'm seeing the same GPU index refer to different GPUs in vkdevicechooser & vulkaninfo.

vulkaninfo's view (from Debian's vulkan-tools package, version: 1.2.162.0+dfsg1-1):

$ vulkaninfo --summary | grep -E "GPU.:|deviceName|driverInfo"
(output trimmed)
GPU0:
        deviceName         = AMD RADV NAVY_FLOUNDER (ACO)
        driverInfo         = Mesa 20.3.5 (ACO)
GPU1:
        deviceName         = llvmpipe (LLVM 11.0.1, 256 bits)
        driverInfo         = Mesa 20.3.5 (LLVM 11.0.1)
GPU2:
        deviceName         = NVIDIA GeForce GTX 1650
        driverInfo         = 470.103.01
GPU3:
        deviceName         = llvmpipe (LLVM 11.0.1, 256 bits)
        driverInfo         = Mesa 22.0.2 (git-f1d9e66a84) (LLVM 11.0.1)
GPU4:
        deviceName         = AMD RADV NAVY_FLOUNDER
        driverInfo         = Mesa 22.0.2 (git-f1d9e66a84)

vkdevicechooser's view (current master, df15b9d33a):

$ ENABLE_DEVICE_CHOOSER_LAYER=1 VULKAN_DEVICE_INDEX=list vulkaninfo --summary
(output trimmed)
GPU0:
        deviceName = llvmpipe (LLVM 11.0.1, 256 bits)
        driverInfo = Mesa 20.3.5 (LLVM 11.0.1)
GPU1:
        deviceName = NVIDIA GeForce GTX 1650
        driverInfo = 470.103.01
GPU2:
        deviceName = AMD RADV NAVY_FLOUNDER (ACO)
        driverInfo = Mesa 20.3.5 (ACO)
GPU3:
        deviceName = llvmpipe (LLVM 11.0.1, 256 bits)
        driverInfo = Mesa 22.0.2 (git-f1d9e66a84) (LLVM 11.0.1)
GPU4:
        deviceName = AMD RADV NAVY_FLOUNDER
        driverInfo = Mesa 22.0.2 (git-f1d9e66a84)

It's almost like vkdevicechooser's list got shifted up an item, but then the AMD RADV NAVY_FLOUNDER (ACO) / Mesa 20.3.5 device gets put in after the NVidia card. I wonder if the vulkaninfo enumeration logic changed between when the README was written and now, resulting in different orders?

OS: Debian 11/Bullseye

genpfault commented 2 years ago

Quick 'n dirty VULKAN_DEVICE_INDEX=list implementation:

diff --git a/layer.cpp b/layer.cpp
index 3863862..f7b6b4d 100644
--- a/layer.cpp
+++ b/layer.cpp
@@ -5,6 +5,7 @@
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
+#include <iostream>
 #include <map>
 #include <vector>

@@ -63,6 +64,28 @@ static VkResult ChooseDevice(VkInstance                          instance,
         return result;
     }

+    if (std::string(env) == "list")
+    {
+        for (size_t i = 0; i < devices.size(); ++i)
+        {
+            VkPhysicalDeviceProperties pdp;
+            dispatch.GetPhysicalDeviceProperties(devices[i], &pdp);
+
+            VkPhysicalDeviceDriverProperties pddp{};
+            pddp.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
+            VkPhysicalDeviceProperties2 pdp2{};
+            pdp2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
+            pdp2.pNext = &pddp;
+            dispatch.GetPhysicalDeviceProperties2(devices[i], &pdp2);
+
+            std::cerr << "GPU" << i << ":" << std::endl;
+            std::cerr << "        deviceName = " << pdp.deviceName << std::endl;
+            std::cerr << "        driverInfo = " << pddp.driverInfo << std::endl;
+        }
+
+        std::exit(0);
+    }
+
     int deviceIndex = atoi(env);

     if (deviceIndex >= count)
@@ -205,6 +228,8 @@ DeviceChooserLayer_CreateInstance(const VkInstanceCreateInfo*  pCreateInfo,
     GET(EnumeratePhysicalDevices);
     GET(EnumeratePhysicalDeviceGroups);
     GET(EnumeratePhysicalDeviceGroupsKHR);
+    GET(GetPhysicalDeviceProperties);
+    GET(GetPhysicalDeviceProperties2);

     #undef GET