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

Robert Bragg robert at sixbynine.org
Tue Apr 3 09:59:35 PDT 2012


> +typedef struct _CoglGpuVersion CoglGpuVersion;
> +
> +struct _CoglGpuVersion
> +{
> +  int major;
> +  int minor;
> +  int micro;
> +};

Could this be just CoglVersion perhaps? The implication of the gpu
itself having a version seems a bit odd to read here when presumably
this is used to store a driver version. Gpu hardware can have version
info too which we might want to try tracking at some point but it's
likely we wouldn't use a major, minor, micro layout.

> +
> +typedef struct _CoglGpu CoglGpu;
> +
> +struct _CoglGpu
> +{
> +  CoglGpuVendor vendor;
> +
> +  CoglGpuDriverPackage driver_package;
> +
> +  CoglGpuDriverBug driver_bugs;
> +
> +  CoglGpuVersion driver_package_version;
> +};

I'm wondering if this should be named CoglGpuInfo since I can imagine
some of the corresponding function names seeming a bit confusing if
they read as if you are querying the gpu itself. That would mean a
more verbose cogl_gpu_info_ namespace though.

> +
> +/*
> + * _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);
> +

I wonder if this should be named something like
_cogl_gpu_check_driver_version() or _cogl_gpu_check_driver() (and it
could also check the driver enum.) The reason I mentioned about the
CoglGpuInfo name above was because when I read this, the name suggests
to me that it queries the version of the gpu which doesn't do.

> +/*
> + * _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

Besides the minor thoughts about naming, yeah I agree we should land
something like this in Cogl as a starting point for tracking more and
more gpu info.

I think going forward we will end up wanting to generalizing the ways
in which we teach Cogl about new gpu vendors, drivers  and chipsets
using some form of declarative style (perhaps using the X_MACRO style
we use for gl-prototypes, or a statically initialized array or
structs). I do wonder if we should look at starting something like
that now along with this patch or maybe we should just add that on top
later?

Some time ago I took a half stab at something similar to this to be
able to track whether we were running on an immediate mode or deferred
rendering gpu and I was looking at declaring the state something like
this:

+typedef enum _CoglArchitectureFlag
+{
+  COGL_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE,
+  COGL_ARCHITECTURE_FLAG_VERTEX_TILED,
+  COGL_ARCHITECTURE_FLAG_VERTEX_SOFTWARE,
+  COGL_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE,
+  COGL_ARCHITECTURE_FLAG_FRAGMENT_DEFERRED
+} CoglArchitectureFlag;
+
+typedef struct _CoglArchitectureDescription
+{
+  CoglArchitectureVendor vendor;
+  const char *architecture_name;
+  CoglArchitecture architecture;
+  CoglArchitectureFlag architecture_flags;
+  const char *gl_architecture_regexs[COGL_ARCHITECTURE_DESCRIPTION_MAX_REGEXPS];
+} CoglArchitectureDescription;
+
+typedef struct _CoglVendorDescription
+{
+  const char *vendor_name;
+  CoglArchitectureVendor vendor;
+  const char *gl_vendor_regexs[COGL_ARCHITECTURE_DESCRIPTION_MAX_REGEXPS];
+  const char *gl_renderer_regexs[COGL_ARCHITECTURE_DESCRIPTION_MAX_REGEXPS];
+  const CoglArchitectureDescription *architectures;
+} CoglVendorDescription;
+
+CoglArchitectureDescription intel_architectures[] =
+{
+  {
+    COGL_ARCHITECTURE_VENDOR_INTEL,
+    "Sandybridge Mobile",
+    COGL_ARCHITECTURE_SANDYBRIDGE,
+    COGL_ARCHITECTURE_FLAG_VERTEX_IMMEDIATE_MODE |
+      COGL_ARCHITECTURE_FLAG_FRAGMENT_IMMEDIATE_MODE,
+    {"Sandybridge Mobile"}
+  },
+};
+
+CoglVendorDescription vendors[] =
+{
+  {
+    "Intel",
+    COGL_ARCHITECTURE_VENDOR_INTEL,
+    { 0 },
+    { "Intel" },
+    intel_architectures
+  }
+};

I wonder if something like this could be used here, though instead of
depending on regexes have pointers to functions that can do the
matches manually for now?

kind regards,
- Robert


More information about the Cogl mailing list