Browse Source

vulkan: gather capability information from physical device

rdb 10 years ago
parent
commit
282fc13956

+ 113 - 1
panda/src/vulkandisplay/vulkanGraphicsPipe.cxx

@@ -14,6 +14,7 @@
 #include "vulkanGraphicsPipe.h"
 #include "vulkanGraphicsWindow.h"
 #include "pandaVersion.h"
+#include "displayInformation.h"
 
 /**
  * Callback called by the VK_EXT_debug_report extension whenever one of the
@@ -163,8 +164,79 @@ VulkanGraphicsPipe() {
   _queue_families.resize(num_families);
   vkGetPhysicalDeviceQueueFamilyProperties(_gpu, &num_families, &_queue_families[0]);
 
-  // Get a list of supported texture formats.
+  // Fill in DisplayInformation.
+  _display_information->_vendor_id = _gpu_properties.vendorID;
+  _display_information->_device_id = _gpu_properties.deviceID;
+
   if (vulkandisplay_cat.is_debug()) {
+    // Output some properties about this device.
+    vulkandisplay_cat.debug() << "apiVersion: "
+      << ((_gpu_properties.apiVersion >> 22) & 0x3ff) << '.'
+      << ((_gpu_properties.apiVersion >> 12) & 0x3ff) << '.'
+      << (_gpu_properties.apiVersion & 0xfff) << '\n';
+
+    if (_gpu_properties.vendorID == 0x10DE) {
+      // This is how NVIDIA encodes their driver version.
+      vulkandisplay_cat.debug()
+        << "driverVersion: " << _gpu_properties.driverVersion << " ("
+        << ((_gpu_properties.driverVersion >> 22) & 0x3ff) << '.'
+        << ((_gpu_properties.driverVersion >> 14) & 0x0ff);
+
+      if (_gpu_properties.driverVersion & 0x3fc0) {
+        vulkandisplay_cat.debug(false) << '.'
+          << ((_gpu_properties.driverVersion >>  6) & 0x0ff) << ")\n";
+      } else {
+        vulkandisplay_cat.debug(false) << ")\n";
+      }
+    } else {
+      vulkandisplay_cat.debug()
+        << "driverVersion: " << _gpu_properties.driverVersion << "\n";
+    }
+
+    char vendor_id[5], device_id[5];
+    sprintf(vendor_id, "%04X", _gpu_properties.vendorID);
+    sprintf(device_id, "%04X", _gpu_properties.deviceID);
+
+    // Display the vendor name, if the vendor ID is recognized.
+    const char *vendor_name = get_vendor_name();
+    if (vendor_name != NULL) {
+      vulkandisplay_cat.debug() << "vendorID: 0x" << vendor_id
+                                << " (" << vendor_name << ")\n";
+    } else {
+      vulkandisplay_cat.debug() << "vendorID: 0x" << vendor_id << "\n";
+    }
+    vulkandisplay_cat.debug() << "deviceID: 0x" << device_id << "\n";
+
+    static const char *const device_types[] = {
+      "OTHER", "INTEGRATED_GPU", "DISCRETE_GPU", "VIRTUAL_GPU", "CPU", ""
+    };
+    vulkandisplay_cat.debug()
+      << "deviceType: VK_PHYSICAL_DEVICE_TYPE_"
+      << device_types[_gpu_properties.deviceType] << "\n";
+
+    vulkandisplay_cat.debug() << "deviceName: " << _gpu_properties.deviceName << "\n";
+
+    // Enumerate supported extensions.
+    uint32_t num_inst_extensions = 0, num_dev_extensions = 0;
+    vkEnumerateInstanceExtensionProperties(NULL, &num_inst_extensions, NULL);
+    vkEnumerateDeviceExtensionProperties(_gpu, NULL, &num_dev_extensions, NULL);
+
+    VkExtensionProperties *extensions = (VkExtensionProperties *)
+      alloca(sizeof(VkExtensionProperties) * max(num_inst_extensions, num_dev_extensions));
+
+    vulkandisplay_cat.debug() << "Supported instance extensions:\n";
+    vkEnumerateInstanceExtensionProperties(NULL, &num_inst_extensions, extensions);
+    for (uint32_t i = 0; i < num_inst_extensions; ++i) {
+      vulkandisplay_cat.debug() << "  " << extensions[i].extensionName << "\n";
+    }
+
+    vulkandisplay_cat.debug() << "Supported device extensions:\n";
+    vkEnumerateDeviceExtensionProperties(_gpu, NULL, &num_dev_extensions, extensions);
+    for (uint32_t i = 0; i < num_dev_extensions; ++i) {
+      vulkandisplay_cat.debug() << "  " << extensions[i].extensionName << "\n";
+    }
+
+    // Get a list of supported texture formats.
     vulkandisplay_cat.debug() << "Supported texture formats:\n";
 
     static const char *const format_strings[] = {
@@ -364,6 +436,30 @@ VulkanGraphicsPipe() {
           << "  VK_FORMAT_" << format_strings[i] << "\n";
       }
     }
+
+    // Print some more limits.
+    vulkandisplay_cat.debug() << "maxImageDimension1D = "
+      << _gpu_properties.limits.maxImageDimension1D << "\n";
+    vulkandisplay_cat.debug() << "maxImageDimension2D = "
+      << _gpu_properties.limits.maxImageDimension2D << "\n";
+    vulkandisplay_cat.debug() << "maxImageDimension3D = "
+      << _gpu_properties.limits.maxImageDimension3D << "\n";
+    vulkandisplay_cat.debug() << "maxImageDimensionCube = "
+      << _gpu_properties.limits.maxImageDimensionCube << "\n";
+    vulkandisplay_cat.debug() << "maxImageArrayLayers = "
+      << _gpu_properties.limits.maxImageArrayLayers << "\n";
+    vulkandisplay_cat.debug() << "maxTexelBufferElements = "
+      << _gpu_properties.limits.maxTexelBufferElements << "\n";
+    vulkandisplay_cat.debug() << "maxPushConstantsSize = "
+      << _gpu_properties.limits.maxPushConstantsSize << "\n";
+    vulkandisplay_cat.debug() << "maxMemoryAllocationCount = "
+      << _gpu_properties.limits.maxMemoryAllocationCount << "\n";
+    vulkandisplay_cat.debug() << "maxSamplerAllocationCount = "
+      << _gpu_properties.limits.maxSamplerAllocationCount << "\n";
+    vulkandisplay_cat.debug() << "maxColorAttachments = "
+      << _gpu_properties.limits.maxColorAttachments << "\n";
+    vulkandisplay_cat.debug() << "maxDrawIndexedIndexValue = "
+      << _gpu_properties.limits.maxDrawIndexedIndexValue << "\n";
   }
 
   _is_valid = true;
@@ -418,6 +514,22 @@ find_queue_family_for_surface(uint32_t &queue_family_index, VkSurfaceKHR surface
   return false;
 }
 
+/**
+ * Returns the name of the vendor of the physical device.
+ */
+const char *VulkanGraphicsPipe::
+get_vendor_name() const {
+  // Match OpenGL vendor for consistency.
+  switch (_gpu_properties.vendorID) {
+  case 0x1002: return "ATI Technologies Inc.";
+  case 0x10DE: return "NVIDIA Corporation";
+  case 0x5143: return "Qualcomm";
+  case 0x8086: return "Intel";
+  default:
+    return NULL;
+  }
+}
+
 /**
  * Returns the name of the rendering interface associated with this
  * GraphicsPipe.  This is used to present to the user to allow him/her to

+ 2 - 0
panda/src/vulkandisplay/vulkanGraphicsPipe.h

@@ -40,6 +40,8 @@ public:
                                      VkSurfaceKHR surface,
                                      VkFlags required_flags) const;
 
+  const char *get_vendor_name() const;
+
   virtual string get_interface_name() const;
   static PT(GraphicsPipe) pipe_constructor();
 

+ 28 - 0
panda/src/vulkandisplay/vulkanGraphicsStateGuardian.cxx

@@ -241,6 +241,24 @@ VulkanGraphicsStateGuardian::
 ~VulkanGraphicsStateGuardian() {
 }
 
+/**
+ * Returns the vendor of the video card driver
+ */
+string VulkanGraphicsStateGuardian::
+get_driver_vendor() {
+  VulkanGraphicsPipe *vkpipe;
+  DCAST_INTO_R(vkpipe, get_pipe(), NULL);
+
+  const char *vendor = vkpipe->get_vendor_name();
+  if (vendor != NULL) {
+    return string(vendor);
+  } else {
+    char vendor[24];
+    sprintf(vendor, "Unknown vendor 0x%04X", vkpipe->_gpu_properties.vendorID);
+    return string(vendor);
+  }
+}
+
 /**
  * Returns GL_Renderer
  */
@@ -251,6 +269,16 @@ get_driver_renderer() {
   return string(vkpipe->_gpu_properties.deviceName);
 }
 
+/**
+ * Returns driver version This has an implementation-defined meaning, and may
+ * be "" if the particular graphics implementation does not provide a way to
+ * query this information.
+ */
+string VulkanGraphicsStateGuardian::
+get_driver_version() {
+  return string();
+}
+
 /**
  * Creates whatever structures the GSG requires to represent the texture
  * internally, and returns a newly-allocated TextureContext object with this

+ 2 - 0
panda/src/vulkandisplay/vulkanGraphicsStateGuardian.h

@@ -29,7 +29,9 @@ public:
                               uint32_t queue_family_index);
   virtual ~VulkanGraphicsStateGuardian();
 
+  virtual string get_driver_vendor();
   virtual string get_driver_renderer();
+  virtual string get_driver_version();
 
   virtual TextureContext *prepare_texture(Texture *tex, int view);
   virtual bool update_texture(TextureContext *tc, bool force);