[Mesa-dev] [PATCH 2/3] mesa: Add support for the ARB_pipeline_statistics_query extension

Ian Romanick idr at freedesktop.org
Tue Feb 17 11:41:01 PST 2015


On 02/13/2015 11:02 PM, Ben Widawsky wrote:
> This was originally part of a single patch which added the extension, and
> implemented it for i965 classic. For information about the evolution of the
> patch, please see the subsequent commit.
> 
> One difference here as compared to the original mega patch is this does build
> support for the compute shader query. Since it cannot be tested on any platform,
> it will always return NULL for now. Jordan has already written a patch to
> address this, and when that patch lands, this logic can be modified. Tesselation
> shader support still won't build, so it's stubbed out.
> 
> v2: Fix typo in subject (Brian Paul)
> Add checks for desktop gl (Ilia)
> Fail for any callers for now (Ilia)
> Update QueryCounterBits for new tokens (Ilia)
> Jordan: Use _mesa_has_compute_shaders
> 
> Cc: Jordan Justen <jljusten at gmail.com>
> Cc: Ilia Mirkin <imirkin at alum.mit.edu>
> Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
> ---
>  .../glapi/gen/ARB_pipeline_statistics_query.xml    | 24 ++++++
>  src/mapi/glapi/gen/Makefile.am                     |  1 +
>  src/mapi/glapi/gen/gl_API.xml                      |  3 +
>  src/mesa/main/config.h                             |  3 +
>  src/mesa/main/extensions.c                         |  1 +
>  src/mesa/main/mtypes.h                             | 15 ++++
>  src/mesa/main/queryobj.c                           | 91 ++++++++++++++++++++++
>  7 files changed, 138 insertions(+)
>  create mode 100644 src/mapi/glapi/gen/ARB_pipeline_statistics_query.xml
> 
> diff --git a/src/mapi/glapi/gen/ARB_pipeline_statistics_query.xml b/src/mapi/glapi/gen/ARB_pipeline_statistics_query.xml
> new file mode 100644
> index 0000000..1c66533
> --- /dev/null
> +++ b/src/mapi/glapi/gen/ARB_pipeline_statistics_query.xml
> @@ -0,0 +1,24 @@
> +<?xml version="1.0"?>
> +<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd">
> +
> +<!-- Note: no GLX protocol info yet. -->
> +
> +<OpenGLAPI>
> +
> +<category name="GL_ARB_pipeline_statistics_query" number="171">
> +
> +  <enum name="VERTICES_SUBMITTED"                      value="0x82EE"/>
> +  <enum name="PRIMITIVES_SUBMITTED"                    value="0x82EF"/>
> +  <enum name="VERTEX_SHADER_INVOCATIONS"               value="0x82F0"/>
> +  <enum name="TESS_CONTROL_SHADER_PATCHES"             value="0x82F1"/>
> +  <enum name="TESS_EVALUATION_SHADER_INVOCATIONS"      value="0x82F2"/>
> +  <!-- <enum name="GEOMETRY_SHADER_INVOCATIONS"             value="0x887F"/> -->
> +  <enum name="GEOMETRY_SHADER_PRIMITIVES_EMITTED"      value="0x82F3"/>
> +  <enum name="FRAGMENT_SHADER_INVOCATIONS"             value="0x82F4"/>
> +  <enum name="COMPUTE_SHADER_INVOCATIONS"              value="0x82F5"/>
> +  <enum name="CLIPPING_INPUT_PRIMITIVES"               value="0x82F6"/>
> +  <enum name="CLIPPING_OUTPUT_PRIMITIVES"              value="0x82F7"/>

Aren't all of these supposed to have _ARB on the end?

> +
> +</category>
> +
> +</OpenGLAPI>
> diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am
> index 35d9d01..28973c4 100644
> --- a/src/mapi/glapi/gen/Makefile.am
> +++ b/src/mapi/glapi/gen/Makefile.am
> @@ -138,6 +138,7 @@ API_XML = \
>  	ARB_invalidate_subdata.xml \
>  	ARB_map_buffer_range.xml \
>  	ARB_multi_bind.xml \
> +	ARB_pipeline_statistics_query.xml \
>  	ARB_robustness.xml \
>  	ARB_sample_shading.xml \
>  	ARB_sampler_objects.xml \
> diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
> index 17bf62a..764bbb7 100644
> --- a/src/mapi/glapi/gen/gl_API.xml
> +++ b/src/mapi/glapi/gen/gl_API.xml
> @@ -8389,6 +8389,9 @@
>  
>  <xi:include href="KHR_context_flush_control.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
>  
> +<!-- ARB extension 171 -->
> +<xi:include href="ARB_pipeline_statistics_query.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
> +
>  <!-- Non-ARB extensions sorted by extension number. -->
>  
>  <category name="GL_EXT_blend_color" number="2">
> diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h
> index 08e1a14..5a66a4e 100644
> --- a/src/mesa/main/config.h
> +++ b/src/mesa/main/config.h
> @@ -300,6 +300,9 @@
>  #define MAX_COMPUTE_IMAGE_UNIFORMS          8
>  /*@}*/
>  
> +/** For GL_ARB_pipeline_statistics_query */
> +#define MAX_PIPELINE_STATISTICS             11
> +
>  /*
>   * Color channel component order
>   * 
> diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
> index 220b220..caa2cc9 100644
> --- a/src/mesa/main/extensions.c
> +++ b/src/mesa/main/extensions.c
> @@ -134,6 +134,7 @@ static const struct extension extension_table[] = {
>     { "GL_ARB_multitexture",                        o(dummy_true),                              GLL,            1998 },
>     { "GL_ARB_occlusion_query2",                    o(ARB_occlusion_query2),                    GL,             2003 },
>     { "GL_ARB_occlusion_query",                     o(ARB_occlusion_query),                     GLL,            2001 },
> +   { "GL_ARB_pipeline_statistics_query",           o(ARB_pipeline_statistics_query),           GL,             2014 },
>     { "GL_ARB_pixel_buffer_object",                 o(EXT_pixel_buffer_object),                 GL,             2004 },
>     { "GL_ARB_point_parameters",                    o(EXT_point_parameters),                    GLL,            1997 },
>     { "GL_ARB_point_sprite",                        o(ARB_point_sprite),                        GL,             2003 },
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 1c33ef4..0e3db23 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -3072,6 +3072,9 @@ struct gl_query_state
>     /** GL_ARB_timer_query */
>     struct gl_query_object *TimeElapsed;
>  
> +   /** GL_ARB_pipeline_statistics_query */
> +   struct gl_query_object *pipeline_stats[MAX_PIPELINE_STATISTICS];
> +
>     GLenum CondRenderMode;
>  };
>  
> @@ -3458,6 +3461,17 @@ struct gl_constants
>        GLuint Timestamp;
>        GLuint PrimitivesGenerated;
>        GLuint PrimitivesWritten;
> +      GLuint VerticesSubmitted;
> +      GLuint PrimitivesSubmitted;
> +      GLuint VsInvocations;
> +      GLuint TessPatches;
> +      GLuint TessInvocations;
> +      GLuint GsInvocations;
> +      GLuint GsPrimitives;
> +      GLuint FsInvocations;
> +      GLuint ComputeInvocations;
> +      GLuint ClInPrimitives;
> +      GLuint ClOutPrimitives;
>     } QueryCounterBits;
>  
>     GLuint MaxDrawBuffers;    /**< GL_ARB_draw_buffers */
> @@ -3754,6 +3768,7 @@ struct gl_extensions
>     GLboolean ARB_map_buffer_range;
>     GLboolean ARB_occlusion_query;
>     GLboolean ARB_occlusion_query2;
> +   GLboolean ARB_pipeline_statistics_query;
>     GLboolean ARB_point_sprite;
>     GLboolean ARB_sample_shading;
>     GLboolean ARB_seamless_cube_map;
> diff --git a/src/mesa/main/queryobj.c b/src/mesa/main/queryobj.c
> index 932359c..98b6b56 100644
> --- a/src/mesa/main/queryobj.c
> +++ b/src/mesa/main/queryobj.c
> @@ -142,6 +142,18 @@ _mesa_init_query_object_functions(struct dd_function_table *driver)
>     driver->CheckQuery = _mesa_check_query;
>  }
>  
> +static struct gl_query_object **
> +get_pipe_stats_binding_point(struct gl_context *ctx,
> +                             GLenum target)
> +{
> +   if (!_mesa_is_desktop_gl(ctx) ||
> +       !ctx->Extensions.ARB_pipeline_statistics_query)
> +      return NULL;
> +
> +   const int which = target - GL_VERTICES_SUBMITTED_ARB;
> +   assert(which < MAX_PIPELINE_STATISTICS);
> +   return &ctx->Query.pipeline_stats[which];
> +}
>  
>  /**
>   * Return pointer to the query object binding point for the given target and
> @@ -183,6 +195,40 @@ get_query_binding_point(struct gl_context *ctx, GLenum target, GLuint index)
>           return &ctx->Query.PrimitivesWritten[index];
>        else
>           return NULL;
> +
> +   case GL_VERTICES_SUBMITTED_ARB:
> +   case GL_PRIMITIVES_SUBMITTED_ARB:
> +   case GL_VERTEX_SHADER_INVOCATIONS_ARB:
> +   case GL_FRAGMENT_SHADER_INVOCATIONS_ARB:
> +   case GL_CLIPPING_INPUT_PRIMITIVES_ARB:
> +   case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB:
> +         return get_pipe_stats_binding_point(ctx, target);
> +
> +   case GL_GEOMETRY_SHADER_INVOCATIONS:
> +      /* GL_GEOMETRY_SHADER_INVOCATIONS is defined in a non-sequential order */
> +      target = GL_VERTICES_SUBMITTED_ARB + MAX_PIPELINE_STATISTICS - 1;
> +      /* fallthrough */
> +   case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB:
> +      if (_mesa_has_geometry_shaders(ctx))
> +         return get_pipe_stats_binding_point(ctx, target);
> +      else
> +         return NULL;
> +
> +#if 0 /* Not yet able to build or test */
> +   case GL_TESS_CONTROL_SHADER_PATCHES_ARB:
> +   case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB:
> +      if (ctx->Version >= 40 || ctx->Extensions.ARB_tessellation_shader)
> +         return get_pipe_stats_binding_point(ctx, target);
> +      else
> +         return NULL;
> +#endif
> +
> +   case GL_COMPUTE_SHADER_INVOCATIONS_ARB:
> +      if (_mesa_has_compute_shaders(ctx))
> +         return get_pipe_stats_binding_point(ctx, target);
> +      else
> +         return NULL;
> +
>     default:
>        return NULL;
>     }
> @@ -553,6 +599,39 @@ _mesa_GetQueryIndexediv(GLenum target, GLuint index, GLenum pname,
>           case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
>              *params = ctx->Const.QueryCounterBits.PrimitivesWritten;
>              break;
> +         case GL_VERTICES_SUBMITTED_ARB:
> +            *params = ctx->Const.QueryCounterBits.VerticesSubmitted;
> +            break;
> +         case GL_PRIMITIVES_SUBMITTED_ARB:
> +            *params = ctx->Const.QueryCounterBits.PrimitivesSubmitted;
> +            break;
> +         case GL_VERTEX_SHADER_INVOCATIONS_ARB:
> +            *params = ctx->Const.QueryCounterBits.VsInvocations;
> +            break;
> +         case GL_TESS_CONTROL_SHADER_PATCHES_ARB:
> +            *params = ctx->Const.QueryCounterBits.TessPatches;
> +            break;
> +         case GL_TESS_EVALUATION_SHADER_INVOCATIONS_ARB:
> +            *params = ctx->Const.QueryCounterBits.TessInvocations;
> +            break;
> +         case GL_GEOMETRY_SHADER_INVOCATIONS:
> +            *params = ctx->Const.QueryCounterBits.GsInvocations;
> +            break;
> +         case GL_GEOMETRY_SHADER_PRIMITIVES_EMITTED_ARB:
> +            *params = ctx->Const.QueryCounterBits.GsPrimitives;
> +            break;
> +         case GL_FRAGMENT_SHADER_INVOCATIONS_ARB:
> +            *params = ctx->Const.QueryCounterBits.FsInvocations;
> +            break;
> +         case GL_COMPUTE_SHADER_INVOCATIONS_ARB:
> +            *params = ctx->Const.QueryCounterBits.ComputeInvocations;
> +            break;
> +         case GL_CLIPPING_INPUT_PRIMITIVES_ARB:
> +            *params = ctx->Const.QueryCounterBits.ClInPrimitives;
> +            break;
> +         case GL_CLIPPING_OUTPUT_PRIMITIVES_ARB:
> +            *params = ctx->Const.QueryCounterBits.ClOutPrimitives;
> +            break;
>           default:
>              _mesa_problem(ctx,
>                            "Unknown target in glGetQueryIndexediv(target = %s)",
> @@ -771,6 +850,18 @@ _mesa_init_queryobj(struct gl_context *ctx)
>     ctx->Const.QueryCounterBits.Timestamp = 64;
>     ctx->Const.QueryCounterBits.PrimitivesGenerated = 64;
>     ctx->Const.QueryCounterBits.PrimitivesWritten = 64;
> +
> +   ctx->Const.QueryCounterBits.VerticesSubmitted = 64;
> +   ctx->Const.QueryCounterBits.PrimitivesSubmitted = 64;
> +   ctx->Const.QueryCounterBits.VsInvocations = 64;
> +   ctx->Const.QueryCounterBits.TessPatches = 64;
> +   ctx->Const.QueryCounterBits.TessInvocations = 64;
> +   ctx->Const.QueryCounterBits.GsInvocations = 64;
> +   ctx->Const.QueryCounterBits.GsPrimitives = 64;
> +   ctx->Const.QueryCounterBits.FsInvocations = 64;
> +   ctx->Const.QueryCounterBits.ComputeInvocations = 64;
> +   ctx->Const.QueryCounterBits.ClInPrimitives = 64;
> +   ctx->Const.QueryCounterBits.ClOutPrimitives = 64;
>  }
>  
>  
> 



More information about the mesa-dev mailing list