[Mesa-dev] [PATCH] i965/gen7: Add support for GL_ARB_timer_query.

Jose Fonseca jfonseca at vmware.com
Mon Aug 13 03:43:10 PDT 2012



----- Original Message -----
> Needs updated libdrm.
> ---
> 
> My home hardware collection is a mess right now, and testing
> ARB_timer_query requires examining rollover behavior, so this is
> gen7-only for the moment.  I do eventually want to enable it all the
> way back to g45 (the earliest usable timer register).
> 
>  configure.ac                                  |    2 +-
>  src/mesa/drivers/dri/i965/brw_queryobj.c      |   44
>  +++++++++++++++++++++++++
>  src/mesa/drivers/dri/intel/intel_extensions.c |    8 +++++
>  src/mesa/drivers/dri/intel/intel_reg.h        |    2 ++
>  4 files changed, 55 insertions(+), 1 deletion(-)
> 
> diff --git a/configure.ac b/configure.ac
> index 2ecedaf..3e1ec8c 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -29,7 +29,7 @@ LT_INIT([disable-static])
>  dnl Versions for external dependencies
>  LIBDRM_REQUIRED=2.4.24
>  LIBDRM_RADEON_REQUIRED=2.4.31
> -LIBDRM_INTEL_REQUIRED=2.4.37
> +LIBDRM_INTEL_REQUIRED=2.4.38
>  LIBDRM_NVVIEUX_REQUIRED=2.4.33
>  LIBDRM_NOUVEAU_REQUIRED=2.4.33
>  DRI2PROTO_REQUIRED=2.6
> diff --git a/src/mesa/drivers/dri/i965/brw_queryobj.c
> b/src/mesa/drivers/dri/i965/brw_queryobj.c
> index 3f9e065..b725fed 100644
> --- a/src/mesa/drivers/dri/i965/brw_queryobj.c
> +++ b/src/mesa/drivers/dri/i965/brw_queryobj.c
> @@ -41,6 +41,7 @@
>  #include "main/imports.h"
>  
>  #include "brw_context.h"
> +#include "brw_defines.h"
>  #include "brw_state.h"
>  #include "intel_batchbuffer.h"
>  #include "intel_reg.h"
> @@ -155,6 +156,21 @@ brw_queryobj_get_results(struct gl_context *ctx,
>  	 query->Base.Result += 1000 * ((results[1] >> 32) - (results[0] >>
>  	 32));
>        break;
>  
> +   case GL_TIMESTAMP:
> +      if (intel->gen >= 6) {
> +         /* The timestamp register we can read for glGetTimestamp()
> masks out
> +          * the top 32 bits, so we do that here too to let the two
> counters be
> +          * compared against each other.
> +          *
> +          * The low 32 bits rolls over in ~343 seconds.
> +          */
> +	 query->Base.Result = 80 * (results[1] & 0xffffffff);

>From my understanding of ARB_timer_query spec, the driver should do a modulus here

  Result &= (1 << N) - 1;

here, and the N must match precisely what glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS) returns, otherwise the whenever the rollover happens the application will get bogus results as it won't be able to reconstruct the unrolled (monotonically increasing) timestamps.

Given that base counter is 32bits, and is multiplied by 80 (6bits), the final counter has at most N = 38 significant bits.


But unfortunately I couldn't find a good example of how to use glGetQueryiv(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS) effectively, so I'm not 100% sure my expectations are correct.


Another alternative would be for the driver to reconstruct the upper 32bits bits somehow, using a separate time source.


Jose 


More information about the mesa-dev mailing list