From 34813e13db586456edd40314690da07aadaca09e Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Thu, 31 Aug 2023 09:23:38 +0300 Subject: [PATCH] pps-producer: add ability to select device with DRI_PRIME When running with multiple Intel cards in a system, having the ability to select the device recording performance data is useful. Signed-off-by: Lionel Landwerlin Acked-by: Rob Clark Reviewed-by: Chia-I Wu Part-of: --- src/tool/pps/pps_device.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/tool/pps/pps_device.cc b/src/tool/pps/pps_device.cc index 908aabfc15b..400339fea24 100644 --- a/src/tool/pps/pps_device.cc +++ b/src/tool/pps/pps_device.cc @@ -55,6 +55,21 @@ std::optional create_drm_device(int fd, int32_t gpu_num) return std::nullopt; } + const char *dri_prime = getenv("DRI_PRIME"); + if (dri_prime != NULL) { + drmDevicePtr drm_device; + uint16_t vendor_id, device_id; + bool prime_is_vid_did = + sscanf(dri_prime, "%hx:%hx", &vendor_id, &device_id) == 2; + + if (prime_is_vid_did && drmGetDevice2(fd, 0, &drm_device) == 0) { + if (drm_device->bustype == DRM_BUS_PCI && + (drm_device->deviceinfo.pci->vendor_id != vendor_id || + drm_device->deviceinfo.pci->device_id != device_id)) + return std::nullopt; + } + } + auto ret = DrmDevice(); ret.fd = fd; ret.gpu_num = gpu_num;