turnip: Implement VK_EXT_physical_device_drm

Copied from ANV and V3DV.

v1. Fix a build error for clang "unannotated fall-through between switch labels"
( Hyunjun Ko <zzoon.ko@igalia.com> )

Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/6011

Signed-off-by: Danylo Piliaiev <dpiliaiev@igalia.com>
Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14971>
This commit is contained in:
Danylo Piliaiev 2022-02-10 15:35:59 +02:00 committed by Marge Bot
parent bb6ba8f21f
commit 549e861dc1
4 changed files with 53 additions and 3 deletions

View File

@ -555,7 +555,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, v3dv)
VK_EXT_physical_device_drm DONE (anv, radv, tu, v3dv)
VK_EXT_post_depth_coverage DONE (anv/gfx10+, lvp, radv/gfx10+)
VK_EXT_primitive_topology_list_restart DONE (anv, lvp, radv, tu)
VK_EXT_provoking_vertex DONE (anv, lvp, radv, tu, v3dv)

View File

@ -203,6 +203,9 @@ get_device_extensions(const struct tu_physical_device *device,
.EXT_line_rasterization = true,
.EXT_subgroup_size_control = true,
.EXT_image_robustness = true,
#ifndef TU_USE_KGSL
.EXT_physical_device_drm = true,
#endif
/* For Graphics Flight Recorder (GFR) */
.AMD_buffer_marker = true,
.ARM_rasterization_order_attachment_access = true,
@ -1252,6 +1255,18 @@ tu_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice,
props->lineSubPixelPrecisionBits = 8;
break;
}
case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRM_PROPERTIES_EXT: {
VkPhysicalDeviceDrmPropertiesEXT *props =
(VkPhysicalDeviceDrmPropertiesEXT *)ext;
props->hasPrimary = pdevice->has_master;
props->primaryMajor = pdevice->master_major;
props->primaryMinor = pdevice->master_minor;
props->hasRender = pdevice->has_local;
props->renderMajor = pdevice->local_major;
props->renderMinor = pdevice->local_minor;
break;
}
default:
break;

View File

@ -29,6 +29,13 @@
#include <sys/mman.h>
#include <xf86drm.h>
#ifdef MAJOR_IN_MKDEV
#include <sys/mkdev.h>
#endif
#ifdef MAJOR_IN_SYSMACROS
#include <sys/sysmacros.h>
#endif
#include "vk_util.h"
#include "drm-uapi/msm_drm.h"
@ -609,6 +616,7 @@ tu_drm_device_init(struct tu_physical_device *device,
struct tu_instance *instance,
drmDevicePtr drm_device)
{
const char *primary_path = drm_device->nodes[DRM_NODE_PRIMARY];
const char *path = drm_device->nodes[DRM_NODE_RENDER];
VkResult result = VK_SUCCESS;
drmVersionPtr version;
@ -665,8 +673,7 @@ tu_drm_device_init(struct tu_physical_device *device,
device->instance = instance;
if (instance->vk.enabled_extensions.KHR_display) {
master_fd =
open(drm_device->nodes[DRM_NODE_PRIMARY], O_RDWR | O_CLOEXEC);
master_fd = open(primary_path, O_RDWR | O_CLOEXEC);
if (master_fd >= 0) {
/* TODO: free master_fd is accel is not working? */
}
@ -700,6 +707,28 @@ tu_drm_device_init(struct tu_physical_device *device,
goto fail;
}
struct stat st;
if (stat(primary_path, &st) == 0) {
device->has_master = true;
device->master_major = major(st.st_rdev);
device->master_minor = minor(st.st_rdev);
} else {
device->has_master = false;
device->master_major = 0;
device->master_minor = 0;
}
if (stat(path, &st) == 0) {
device->has_local = true;
device->local_major = major(st.st_rdev);
device->local_minor = minor(st.st_rdev);
} else {
result = vk_errorf(instance, VK_ERROR_INITIALIZATION_FAILED,
"failed to stat DRM render node %s", path);
goto fail;
}
device->syncobj_type = vk_drm_syncobj_get_type(fd);
device->timeline_type = vk_sync_timeline_get_type(&tu_timeline_sync_type);

View File

@ -215,7 +215,13 @@ struct tu_physical_device
struct wsi_device wsi_device;
int local_fd;
bool has_local;
int64_t local_major;
int64_t local_minor;
int master_fd;
bool has_master;
int64_t master_major;
int64_t master_minor;
uint32_t gmem_size;
uint64_t gmem_base;