Mesa (main): v3dv: implement VK_EXT_physical_device_drm
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Jul 19 06:18:32 UTC 2021
Module: Mesa
Branch: main
Commit: d6dd13a62ec5f21c58e4251e6d7d872b31a55c86
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=d6dd13a62ec5f21c58e4251e6d7d872b31a55c86
Author: Andreas Bergmeier <abergmeier at gmx.net>
Date: Sun Feb 28 18:52:36 2021 +0000
v3dv: implement VK_EXT_physical_device_drm
Reviewed-by: Simon Ser <contact at emersion.fr>
Reviewed-by: Iago Toral Quiroga <itoral at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9320>
---
docs/features.txt | 2 +-
src/broadcom/vulkan/v3dv_device.c | 60 ++++++++++++++++++++++++++++++++++++--
src/broadcom/vulkan/v3dv_private.h | 9 ++++++
3 files changed, 68 insertions(+), 3 deletions(-)
diff --git a/docs/features.txt b/docs/features.txt
index 5a54634d036..38a98ee08d6 100644
--- a/docs/features.txt
+++ b/docs/features.txt
@@ -535,7 +535,7 @@ Khronos extensions that are not part of any Vulkan version:
VK_EXT_memory_priority DONE (radv)
VK_EXT_multi_draw DONE (anv, lvp, radv)
VK_EXT_pci_bus_info DONE (anv, radv)
- VK_EXT_physical_device_drm DONE (anv, radv)
+ VK_EXT_physical_device_drm DONE (anv, radv, v3dv)
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/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c
index 3062bdd8de8..0b278ceb05c 100644
--- a/src/broadcom/vulkan/v3dv_device.c
+++ b/src/broadcom/vulkan/v3dv_device.c
@@ -30,6 +30,13 @@
#include <unistd.h>
#include <xf86drm.h>
+#ifdef MAJOR_IN_MKDEV
+#include <sys/mkdev.h>
+#endif
+#ifdef MAJOR_IN_SYSMACROS
+#include <sys/sysmacros.h>
+#endif
+
#include "v3dv_private.h"
#include "common/v3d_debug.h"
@@ -133,6 +140,7 @@ get_device_extensions(const struct v3dv_physical_device *device,
.KHR_variable_pointers = true,
.EXT_external_memory_dma_buf = true,
.EXT_index_type_uint8 = true,
+ .EXT_physical_device_drm = true,
.EXT_private_data = true,
};
}
@@ -697,17 +705,50 @@ physical_device_init(struct v3dv_physical_device *device,
* we postpone that until a swapchain is created.
*/
+ const char *primary_path;
+#if !using_v3d_simulator
+ if (drm_primary_device)
+ primary_path = drm_primary_device->nodes[DRM_NODE_PRIMARY];
+ else
+ primary_path = NULL;
+#else
+ primary_path = drm_render_device->nodes[DRM_NODE_PRIMARY];
+#endif
+
+ struct stat primary_stat = {0}, render_stat = {0};
+
+ device->has_primary = primary_path;
+ if (device->has_primary) {
+ if (stat(primary_path, &primary_stat) != 0) {
+ result = vk_errorf(instance,
+ VK_ERROR_INITIALIZATION_FAILED,
+ "failed to stat DRM primary node %s",
+ primary_path);
+ goto fail;
+ }
+
+ device->primary_devid = primary_stat.st_rdev;
+ }
+
+ if (fstat(render_fd, &render_stat) != 0) {
+ result = vk_errorf(instance,
+ VK_ERROR_INITIALIZATION_FAILED,
+ "failed to stat DRM render node %s",
+ path);
+ goto fail;
+ }
+ device->has_render = true;
+ device->render_devid = render_stat.st_rdev;
+
if (instance->vk.enabled_extensions.KHR_display) {
#if !using_v3d_simulator
/* Open the primary node on the vc4 display device */
assert(drm_primary_device);
- const char *primary_path = drm_primary_device->nodes[DRM_NODE_PRIMARY];
master_fd = open(primary_path, O_RDWR | O_CLOEXEC);
#else
/* There is only one device with primary and render nodes.
* Open its primary node.
*/
- const char *primary_path = drm_render_device->nodes[DRM_NODE_PRIMARY];
master_fd = open(primary_path, O_RDWR | O_CLOEXEC);
#endif
}
@@ -1353,6 +1394,21 @@ v3dv_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
id_props->deviceLUIDValid = false;
break;
}
+ case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT: {
+ VkPhysicalDeviceDrmPropertiesEXT *props =
+ (VkPhysicalDeviceDrmPropertiesEXT *)ext;
+ props->hasPrimary = pdevice->has_primary;
+ if (props->hasPrimary) {
+ props->primaryMajor = (int64_t) major(pdevice->primary_devid);
+ props->primaryMinor = (int64_t) minor(pdevice->primary_devid);
+ }
+ props->hasRender = pdevice->has_render;
+ if (props->hasRender) {
+ props->renderMajor = (int64_t) major(pdevice->render_devid);
+ props->renderMinor = (int64_t) minor(pdevice->render_devid);
+ }
+ break;
+ }
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES: {
VkPhysicalDeviceMaintenance3Properties *props =
(VkPhysicalDeviceMaintenance3Properties *)ext;
diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h
index b7bc7dc0c9b..f37602bf7cb 100644
--- a/src/broadcom/vulkan/v3dv_private.h
+++ b/src/broadcom/vulkan/v3dv_private.h
@@ -118,6 +118,15 @@ struct v3dv_physical_device {
int32_t display_fd;
int32_t master_fd;
+ /* We need these because it is not clear how to detect
+ * valid devids in a portable way
+ */
+ bool has_primary;
+ bool has_render;
+
+ dev_t primary_devid;
+ dev_t render_devid;
+
uint8_t driver_build_sha1[20];
uint8_t pipeline_cache_uuid[VK_UUID_SIZE];
uint8_t device_uuid[VK_UUID_SIZE];
More information about the mesa-commit
mailing list