Mesa (main): radv: implement VK_EXT_physical_device_drm

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Tue Jun 22 13:37:38 UTC 2021


Module: Mesa
Branch: main
Commit: 7aaa54feb53a9d0cf3277bef31547312ee56b277
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7aaa54feb53a9d0cf3277bef31547312ee56b277

Author: Simon Ser <contact at emersion.fr>
Date:   Fri Jan  8 16:06:51 2021 +0100

radv: implement VK_EXT_physical_device_drm

This adds support for the Vulkan extension introduced in [1]. The
extension allows to get a VkPhysicalDevice's DRM node device IDs.

[1]: https://github.com/KhronosGroup/Vulkan-Docs/pull/1356

Signed-off-by: Simon Ser <contact at emersion.fr>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8390>

---

 docs/features.txt              |  2 +-
 docs/relnotes/new_features.txt |  1 +
 src/amd/vulkan/radv_device.c   | 53 +++++++++++++++++++++++++++++++++++++++++-
 src/amd/vulkan/radv_private.h  |  4 ++++
 4 files changed, 58 insertions(+), 2 deletions(-)

diff --git a/docs/features.txt b/docs/features.txt
index b44cd6e1a76..e70fdb85119 100644
--- a/docs/features.txt
+++ b/docs/features.txt
@@ -533,7 +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_physical_device_drm                            DONE (anv, radv)
   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)
diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt
index 00c0e47cbc6..15c04e13aaa 100644
--- a/docs/relnotes/new_features.txt
+++ b/docs/relnotes/new_features.txt
@@ -2,5 +2,6 @@ zink supports GL_ARB_texture_filter_minmax, GL_ARB_shader_clock
 VK_EXT_provoking_vertex on RADV.
 VK_EXT_extended_dynamic_state2 on RADV.
 VK_EXT_global_priority_query on RADV.
+VK_EXT_physical_device_drm on RADV.
 32-bit x86 builds now default disable x87 math and use sse2.
 GL ES 3.1 on GT21x hardware.
diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c
index 4b8eab2ed75..9e18348a328 100644
--- a/src/amd/vulkan/radv_device.c
+++ b/src/amd/vulkan/radv_device.c
@@ -29,6 +29,12 @@
 #include <stdbool.h>
 #include <string.h>
 
+#ifdef __FreeBSD__
+#include <sys/types.h>
+#elif !defined(_WIN32)
+#include <sys/sysmacros.h>
+#endif
+
 #include "util/debug.h"
 #include "util/disk_cache.h"
 #include "radv_cs.h"
@@ -469,6 +475,9 @@ radv_physical_device_get_supported_extensions(const struct radv_physical_device
       .EXT_memory_budget = true,
       .EXT_memory_priority = true,
       .EXT_pci_bus_info = true,
+#ifndef _WIN32
+      .EXT_physical_device_drm = true,
+#endif
       .EXT_pipeline_creation_cache_control = true,
       .EXT_pipeline_creation_feedback = true,
       .EXT_post_depth_coverage = device->rad_info.chip_class >= GFX10,
@@ -698,8 +707,30 @@ radv_physical_device_try_create(struct radv_instance *instance, drmDevicePtr drm
    radv_physical_device_get_supported_extensions(device, &device->vk.supported_extensions);
 
 #ifndef _WIN32
-   if (drm_device)
+   if (drm_device) {
+      struct stat primary_stat = {0}, render_stat = {0};
+
+      device->available_nodes = drm_device->available_nodes;
       device->bus_info = *drm_device->businfo.pci;
+
+      if ((drm_device->available_nodes & (1 << DRM_NODE_PRIMARY)) &&
+          stat(drm_device->nodes[DRM_NODE_PRIMARY], &primary_stat) != 0) {
+         result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
+                            "failed to stat DRM primary node %s",
+                            drm_device->nodes[DRM_NODE_PRIMARY]);
+         goto fail_disk_cache;
+      }
+      device->primary_devid = primary_stat.st_rdev;
+
+      if ((drm_device->available_nodes & (1 << DRM_NODE_RENDER)) &&
+          stat(drm_device->nodes[DRM_NODE_RENDER], &render_stat) != 0) {
+         result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
+                            "failed to stat DRM render node %s",
+                            drm_device->nodes[DRM_NODE_RENDER]);
+         goto fail_disk_cache;
+      }
+      device->render_devid = render_stat.st_rdev;
+   }
 #endif
 
    if ((device->instance->debug_flags & RADV_DEBUG_INFO))
@@ -2308,6 +2339,26 @@ radv_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
          props->minAccelerationStructureScratchOffsetAlignment = 128;
          break;
       }
+#ifndef _WIN32
+      case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT: {
+         VkPhysicalDeviceDrmPropertiesEXT *props = (VkPhysicalDeviceDrmPropertiesEXT *)ext;
+         if (pdevice->available_nodes & (1 << DRM_NODE_PRIMARY)) {
+            props->hasPrimary = true;
+            props->primaryMajor = (int64_t)major(pdevice->primary_devid);
+            props->primaryMinor = (int64_t)minor(pdevice->primary_devid);
+         } else {
+            props->hasPrimary = false;
+         }
+         if (pdevice->available_nodes & (1 << DRM_NODE_RENDER)) {
+            props->hasRender = true;
+            props->renderMajor = (int64_t)major(pdevice->render_devid);
+            props->renderMinor = (int64_t)minor(pdevice->render_devid);
+         } else {
+            props->hasRender = false;
+         }
+         break;
+      }
+#endif
       default:
          break;
       }
diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h
index bf99e928b9f..d9dd39ff3ff 100644
--- a/src/amd/vulkan/radv_private.h
+++ b/src/amd/vulkan/radv_private.h
@@ -304,7 +304,11 @@ struct radv_physical_device {
    unsigned heaps;
 
 #ifndef _WIN32
+   int available_nodes;
    drmPciBusInfo bus_info;
+
+   dev_t primary_devid;
+   dev_t render_devid;
 #endif
 };
 



More information about the mesa-commit mailing list