[Cogl] [PATCH 4/5] Add a mechanism for determining GPU driver details

Neil Roberts neil at linux.intel.com
Tue Mar 27 09:56:24 PDT 2012


This adds a CoglGpu struct to the CoglContext which contains some
enums describing the GL driver in use. This currently includes the
driver package (ie, is it Mesa) the version number of the package and
the vendor of the GPU (ie, is it by Intel). There is also a bitmask
which will contain the workarounds that we should do for that
particular driver configuration. The struct is initialised on context
creation by using some regular expressions to examine the strings
returned from glGetString.
---
 cogl/Makefile.am            |    2 +
 cogl/cogl-context-private.h |    5 ++
 cogl/cogl-context.c         |    3 +
 cogl/cogl-gpu-private.h     |   97 +++++++++++++++++++++++++++++++++++++
 cogl/cogl-gpu.c             |  111 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 218 insertions(+), 0 deletions(-)
 create mode 100644 cogl/cogl-gpu-private.h
 create mode 100644 cogl/cogl-gpu.c

diff --git a/cogl/Makefile.am b/cogl/Makefile.am
index b9968a7..a984164 100644
--- a/cogl/Makefile.am
+++ b/cogl/Makefile.am
@@ -180,6 +180,8 @@ cogl_sources_c = \
 	$(srcdir)/cogl-private.h			\
 	$(srcdir)/cogl-debug.h 				\
 	$(srcdir)/cogl-debug-options.h			\
+	$(srcdir)/cogl-gpu.c				\
+	$(srcdir)/cogl-gpu-private.h			\
 	$(srcdir)/cogl-handle.h 			\
 	$(srcdir)/cogl-context-private.h		\
 	$(srcdir)/cogl-context.c			\
diff --git a/cogl/cogl-context-private.h b/cogl/cogl-context-private.h
index a79672f..f12d0f2 100644
--- a/cogl/cogl-context-private.h
+++ b/cogl/cogl-context-private.h
@@ -47,6 +47,7 @@
 #include "cogl-texture-2d.h"
 #include "cogl-texture-3d.h"
 #include "cogl-texture-rectangle.h"
+#include "cogl-gpu-private.h"
 
 typedef struct
 {
@@ -63,6 +64,10 @@ struct _CoglContext
 
   CoglDriver driver;
 
+  /* Information about the GPU and driver which we can use to
+     determine certain workarounds */
+  CoglGpu gpu;
+
   /* vtables for the driver functions */
   const CoglDriverVtable *driver_vtable;
   const CoglTextureDriver *texture_driver;
diff --git a/cogl/cogl-context.c b/cogl/cogl-context.c
index 8ed3103..fdb97e3 100644
--- a/cogl/cogl-context.c
+++ b/cogl/cogl-context.c
@@ -47,6 +47,7 @@
 #include "cogl2-path.h"
 #include "cogl-attribute-private.h"
 #include "cogl1-context.h"
+#include "cogl-gpu-private.h"
 
 #include <string.h>
 
@@ -234,6 +235,8 @@ cogl_context_new (CoglDisplay *display,
       return NULL;
     }
 
+  _cogl_gpu_init (context, &context->gpu);
+
   context->attribute_name_states_hash =
     g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
   context->attribute_name_index_map = NULL;
diff --git a/cogl/cogl-gpu-private.h b/cogl/cogl-gpu-private.h
new file mode 100644
index 0000000..a32de0a
--- /dev/null
+++ b/cogl/cogl-gpu-private.h
@@ -0,0 +1,97 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ */
+
+#ifndef __COGL_GPU_PRIVATE_H
+#define __COGL_GPU_PRIVATE_H
+
+#include "cogl-context.h"
+
+typedef enum
+{
+  COGL_GPU_VENDOR_UNKNOWN,
+  COGL_GPU_VENDOR_INTEL
+} CoglGpuVendor;
+
+typedef enum
+{
+  COGL_GPU_DRIVER_PACKAGE_UNKNOWN,
+  COGL_GPU_DRIVER_PACKAGE_MESA
+} CoglGpuDriverPackage;
+
+typedef enum
+{
+  COGL_GPU_DRIVER_STUB
+} CoglGpuDriverBug;
+
+typedef struct _CoglGpuVersion CoglGpuVersion;
+
+struct _CoglGpuVersion
+{
+  int major;
+  int minor;
+  int micro;
+};
+
+typedef struct _CoglGpu CoglGpu;
+
+struct _CoglGpu
+{
+  CoglGpuVendor vendor;
+
+  CoglGpuDriverPackage driver_package;
+
+  CoglGpuDriverBug driver_bugs;
+
+  CoglGpuVersion driver_package_version;
+};
+
+/*
+ * _cogl_gpu_version_check:
+ * @version: A package version number to check against
+ * @major: The major part of the minimum required version
+ * @minor: The minor part of the minimum required version
+ * @micro: The micro part of the minimum required version
+ *
+ * Return value: %TRUE if the version number in @version is greater
+ *   than or equal to the version number described by @major, @minor and
+ * @micro.
+ */
+gboolean
+_cogl_gpu_version_check (const CoglGpuVersion *version,
+                         int major,
+                         int minor,
+                         int micro);
+
+/*
+ * _cogl_gpu_init:
+ * @ctx: A #CoglContext
+ * @gpu: A return location for the GPU information
+ *
+ * Determines information about the GPU and driver from the given
+ * context.
+ */
+void
+_cogl_gpu_init (CoglContext *ctx,
+                CoglGpu *gpu);
+
+#endif /* __COGL_GPU_PRIVATE_H */
diff --git a/cogl/cogl-gpu.c b/cogl/cogl-gpu.c
new file mode 100644
index 0000000..2ca38db
--- /dev/null
+++ b/cogl/cogl-gpu.c
@@ -0,0 +1,111 @@
+/*
+ * Cogl
+ *
+ * An object oriented GL/GLES Abstraction/Utility Layer
+ *
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <string.h>
+#include <errno.h>
+
+#include "cogl-gpu-private.h"
+#include "cogl-mini-re-private.h"
+#include "cogl-context-private.h"
+
+static void
+_cogl_gpu_parse_version_string (const char *version_string,
+                                CoglGpuVersion *version)
+{
+  int i;
+
+  memset (version, 0, sizeof (CoglGpuVersion));
+
+  for (i = 0; i < 3; i++)
+    {
+      int *part = ((int *) version) + i;
+
+      *part = g_ascii_strtoull (version_string,
+                                (char **) &version_string,
+                                10);
+      if (*version_string != '.')
+        break;
+
+      version_string++;
+    }
+}
+
+gboolean
+_cogl_gpu_version_check (const CoglGpuVersion *version,
+                         int major,
+                         int minor,
+                         int micro)
+{
+  if (version->major > major)
+    return TRUE;
+
+  if (version->major == major)
+    {
+      if (version->minor > minor)
+        return TRUE;
+
+      if (version->minor == minor)
+        return version->micro >= micro;
+    }
+
+  return FALSE;
+}
+
+void
+_cogl_gpu_init (CoglContext *ctx,
+                CoglGpu *gpu)
+{
+  const char *renderer_string = (const char *) ctx->glGetString (GL_RENDERER);
+  const char *version_string = (const char *) ctx->glGetString (GL_VERSION);
+
+  /* Determine the driver package */
+  if (_cogl_mini_re_match ("^(\\d\\.)+\\d+ Mesa \\d+\\.\\d+"
+                           "(\\.\\d+$|-devel)",
+                           version_string))
+    {
+      const char *package_version;
+
+      gpu->driver_package = COGL_GPU_DRIVER_PACKAGE_MESA;
+
+      /* Find the package version string */
+      package_version = strchr (version_string, 'M') + 5;
+      _cogl_gpu_parse_version_string (package_version,
+                                      &gpu->driver_package_version);
+    }
+  else
+    gpu->driver_package = COGL_GPU_DRIVER_PACKAGE_UNKNOWN;
+
+  /* Determine the GPU vendor */
+  if (_cogl_mini_re_match ("\\bIntel\\(R\\)( |$)",
+                           renderer_string))
+    gpu->vendor = COGL_GPU_VENDOR_INTEL;
+  else
+    gpu->vendor = COGL_GPU_VENDOR_UNKNOWN;
+
+  /* Determine the driver bugs */
+  gpu->driver_bugs = 0;
+}
-- 
1.7.3.16.g9464b



More information about the Cogl mailing list