From bbb4a1a0b5de35551706b954a23ed9c333a33fc7 Mon Sep 17 00:00:00 2001
From: philippegorley <philippe.gorley@savoirfairelinux.com>
Date: Tue, 27 Jun 2017 15:41:42 -0400
Subject: [PATCH] vaapi: prefer render nodes over card devices

Prefer renderD* nodes over card* devices, as they provide several
advantages:
- No kernel mode-setting (ie display resolution and depth)
- No insecure gem-flink (the names are global)
- No DRM-auth
- No legacy pre-KMS DRM-API

In other words, userspace can use GPUs without a privileged
graphics-server.

Change-Id: I2e6207ba2fc6e0b17f6cf0cb294c0a5188bc022e
Reviewed-by: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
---
 src/media/video/v4l2/vaapi.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/media/video/v4l2/vaapi.cpp b/src/media/video/v4l2/vaapi.cpp
index 414da2342e..b222e8959a 100644
--- a/src/media/video/v4l2/vaapi.cpp
+++ b/src/media/video/v4l2/vaapi.cpp
@@ -79,9 +79,11 @@ VaapiAccel::checkAvailability()
 {
     AVBufferRef* hardwareDeviceCtx = nullptr;
 #ifdef HAVE_VAAPI_ACCEL_DRM
-    // try all possible devices, use first one that works
     const std::string path = "/dev/dri/";
-    for (auto& entry : ring::fileutils::readDirectory(path)) {
+    auto files = ring::fileutils::readDirectory(path);
+    // renderD* is preferred over card*
+    std::sort(files.rbegin(), files.rend());
+    for (auto& entry : files) {
         std::string deviceName = path + entry;
         if (av_hwdevice_ctx_create(&hardwareDeviceCtx, AV_HWDEVICE_TYPE_VAAPI, deviceName.c_str(), nullptr, 0) >= 0) {
             deviceName_ = deviceName;
-- 
GitLab