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

Author: Lionel Landwerlin <lionel.g.landwer...@intel.com>
Date:   Thu Aug 31 09:23:38 2023 +0300

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 <lionel.g.landwer...@intel.com>
Acked-by: Rob Clark <robdcl...@chromium.org>
Reviewed-by: Chia-I Wu <olva...@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25051>

---

 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<DrmDevice> 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;

Reply via email to