anv: implement VK_EXT_physical_device_drm
authorLionel Landwerlin <lionel.g.landwerlin@intel.com>
Fri, 22 Jan 2021 10:38:41 +0000 (12:38 +0200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 21 Jun 2021 19:18:07 +0000 (19:18 +0000)
v2: add docs
    update error messages (Sagar)

v3: Use fstat() (Jason)

v4: Do fstat() on demand (Jason)

v5: clear major/minor values if not present (Jason)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Sagar Ghuge <sagar.ghuge@intel.com>
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8649>

docs/features.txt
src/intel/vulkan/anv_device.c

index 933988b..b44cd6e 100644 (file)
@@ -533,6 +533,7 @@ Khronos extensions that are not part of any Vulkan version:
   VK_EXT_memory_budget                                  DONE (anv, radv, tu)
   VK_EXT_memory_priority                                DONE (radv)
   VK_EXT_pci_bus_info                                   DONE (anv, radv)
+  VK_EXT_physical_device_drm                            DONE (anv)
   VK_EXT_pipeline_creation_cache_control                DONE (anv, radv)
   VK_EXT_pipeline_creation_feedback                     DONE (anv, radv)
   VK_EXT_post_depth_coverage                            DONE (anv/gfx10+, lvp, radv)
index 7a66f62..e329e29 100644 (file)
@@ -24,7 +24,9 @@
 #include <assert.h>
 #include <stdbool.h>
 #include <string.h>
+#include <sys/sysmacros.h>
 #include <sys/mman.h>
+#include <sys/stat.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include "drm-uapi/drm_fourcc.h"
@@ -281,6 +283,7 @@ get_device_extensions(const struct anv_physical_device *device,
       .EXT_line_rasterization                = true,
       .EXT_memory_budget                     = device->has_mem_available,
       .EXT_pci_bus_info                      = true,
+      .EXT_physical_device_drm               = true,
       .EXT_pipeline_creation_cache_control   = true,
       .EXT_pipeline_creation_feedback        = true,
       .EXT_post_depth_coverage               = device->info.ver >= 9,
@@ -2248,6 +2251,31 @@ void anv_GetPhysicalDeviceProperties2(
          break;
       }
 
+      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT: {
+         VkPhysicalDeviceDrmPropertiesEXT *props =
+            (VkPhysicalDeviceDrmPropertiesEXT *)ext;
+         struct stat st;
+
+         props->hasPrimary = fstat(pdevice->master_fd, &st) == 0;
+         if (props->hasPrimary) {
+            props->primaryMajor = (int64_t) major(st.st_rdev);
+            props->primaryMinor = (int64_t) minor(st.st_rdev);
+         } else {
+            props->primaryMajor = 0;
+            props->primaryMinor = 0;
+         }
+
+         props->hasRender = fstat(pdevice->local_fd, &st) == 0;
+         if (props->hasRender) {
+            props->renderMajor = (int64_t) major(st.st_rdev);
+            props->renderMinor = (int64_t) minor(st.st_rdev);
+         } else {
+            props->renderMajor = 0;
+            props->renderMinor = 0;
+         }
+         break;
+      }
+
       case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_MEMORY_HOST_PROPERTIES_EXT: {
          VkPhysicalDeviceExternalMemoryHostPropertiesEXT *props =
             (VkPhysicalDeviceExternalMemoryHostPropertiesEXT *) ext;