[Beignet] [PATCH] Try to use drm render nodes.

Abrahm Scully abrahm.scully at gmail.com
Wed Jun 18 19:28:42 PDT 2014


Allows non-root user to run without X.
Works on Fedora 20 with render nodes enabled.

Signed-off-by: Abrahm Scully <abrahm.scully at gmail.com>
---
 src/intel/intel_driver.c | 33 +++++++++++++++++++++++++++++++++
 src/intel/intel_driver.h |  3 +++
 2 files changed, 36 insertions(+)

diff --git a/src/intel/intel_driver.c b/src/intel/intel_driver.c
index f0e860c..2d74ff3 100644
--- a/src/intel/intel_driver.c
+++ b/src/intel/intel_driver.c
@@ -222,6 +222,18 @@ intel_driver_open(intel_driver_t *intel, cl_context_prop props)
   }
 
   if(!intel_driver_is_active(intel)) {
+    printf("Trying to open render node...\n");
+    char card_name[20];
+    for(cardi = 0; cardi < 16; cardi++) {
+      sprintf(card_name, "/dev/dri/renderD%d", 128+cardi);
+      if(intel_driver_init_render(intel, card_name)) {
+        printf("Success at %s.\n", card_name);
+        break;
+      }
+    }
+  }
+
+  if(!intel_driver_is_active(intel)) {
     printf("Trying to open directly...\n");
     char card_name[20];
     for(cardi = 0; cardi < 16; cardi++) {
@@ -232,6 +244,7 @@ intel_driver_open(intel_driver_t *intel, cl_context_prop props)
       }
     }
   }
+
   if(!intel_driver_is_active(intel)) {
     printf("Device open failed\n");
     exit(-1);
@@ -324,6 +337,26 @@ intel_driver_init_master(intel_driver_t *driver, const char* dev_name)
   return 1;
 }
 
+LOCAL int
+intel_driver_init_render(intel_driver_t *driver, const char* dev_name)
+{
+  int dev_fd;
+
+  drm_client_t client;
+
+  // usually dev_name = "/dev/dri/renderD%d"
+  dev_fd = open(dev_name, O_RDWR);
+  if (dev_fd == -1) {
+    printf("open(\"%s\", O_RDWR) failed: %s\n", dev_name, strerror(errno));
+    return 0;
+  }
+
+  intel_driver_init(driver, dev_fd);
+  driver->master = 1;
+
+  return 1;
+}
+
 LOCAL int 
 intel_driver_terminate(intel_driver_t *driver)
 {
diff --git a/src/intel/intel_driver.h b/src/intel/intel_driver.h
index 34efbbb..1ad0500 100644
--- a/src/intel/intel_driver.h
+++ b/src/intel/intel_driver.h
@@ -106,6 +106,9 @@ extern int intel_driver_init_shared(intel_driver_t*, struct dri_state*);
  */
 extern int intel_driver_init_master(intel_driver_t*, const char* dev_name);
 
+/* init driver for render node */
+extern int intel_driver_init_render(intel_driver_t*, const char* dev_name);
+
 /* terminate driver and all underlying structures */
 extern int intel_driver_terminate(intel_driver_t*);
 
-- 
1.9.3



More information about the Beignet mailing list