[Mesa-dev] [PATCH 04/25] glx/drisw: add support for DRI2rendererQueryExtension

Emil Velikov emil.l.velikov at gmail.com
Fri Feb 21 19:03:54 PST 2014


The extension is used by GLX_MESA_query_renderer, which
can be provided for by hardware and software drivers.

Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/glx/drisw_glx.c  | 58 +++++++++++++++++++++++++++++++++++++++++++++++-----
 src/glx/drisw_priv.h |  1 +
 2 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index f2db25d..d4a7883 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -483,6 +483,51 @@ drisw_create_context_attribs(struct glx_screen *base,
    return &pcp->base;
 }
 
+static int
+drisw_query_renderer_integer(struct glx_screen *base, int attribute,
+                             unsigned int *value)
+{
+   struct drisw_screen *const psc = (struct drisw_screen *) base;
+
+   /* Even though there are invalid values (and
+    * dri2_convert_glx_query_renderer_attribs may return -1), the higher level
+    * GLX code is required to perform the filtering.  Assume that we got a
+    * good value.
+    */
+   const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
+
+   if (psc->rendererQuery == NULL)
+      return -1;
+
+   return psc->rendererQuery->queryInteger(psc->driScreen, dri_attribute,
+                                           value);
+}
+
+static int
+drisw_query_renderer_string(struct glx_screen *base, int attribute,
+                            const char **value)
+{
+   struct drisw_screen *const psc = (struct drisw_screen *) base;
+
+   /* Even though queryString only accepts a subset of the possible GLX
+    * queries, the higher level GLX code is required to perform the filtering.
+    * Assume that we got a good value.
+    */
+   const int dri_attribute = dri2_convert_glx_query_renderer_attribs(attribute);
+
+   if (psc->rendererQuery == NULL)
+      return -1;
+
+   return psc->rendererQuery->queryString(psc->driScreen, dri_attribute, value);
+}
+
+static const struct glx_screen_vtable drisw_screen_vtable = {
+   drisw_create_context,
+   drisw_create_context_attribs,
+   drisw_query_renderer_integer,
+   drisw_query_renderer_string,
+};
+
 static void
 driswDestroyDrawable(__GLXDRIdrawable * pdraw)
 {
@@ -596,11 +641,6 @@ driOpenSwrast(void)
    return driver;
 }
 
-static const struct glx_screen_vtable drisw_screen_vtable = {
-   drisw_create_context,
-   drisw_create_context_attribs
-};
-
 static void
 driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions)
 {
@@ -627,6 +667,14 @@ driswBindExtensions(struct drisw_screen *psc, const __DRIextension **extensions)
 	 psc->texBuffer = (__DRItexBufferExtension *) extensions[i];
 	 __glXEnableDirectExtension(&psc->base, "GLX_EXT_texture_from_pixmap");
       }
+      /* DRISW version 3 is also required because GLX_MESA_query_renderer
+       * requires GLX_ARB_create_context_profile.
+       */
+      if (psc->swrast->base.version >= 3
+          && strcmp(extensions[i]->name, __DRI2_RENDERER_QUERY) == 0) {
+         psc->rendererQuery = (__DRI2rendererQueryExtension *) extensions[i];
+         __glXEnableDirectExtension(&psc->base, "GLX_MESA_query_renderer");
+      }
    }
 }
 
diff --git a/src/glx/drisw_priv.h b/src/glx/drisw_priv.h
index a1abedf..969cf1a 100644
--- a/src/glx/drisw_priv.h
+++ b/src/glx/drisw_priv.h
@@ -45,6 +45,7 @@ struct drisw_screen
    const __DRIswrastExtension *swrast;
    const __DRItexBufferExtension *texBuffer;
    const __DRIcopySubBufferExtension *copySubBuffer;
+   const __DRI2rendererQueryExtension *rendererQuery;
 
    const __DRIconfig **driver_configs;
 
-- 
1.9.0



More information about the mesa-dev mailing list