[Mesa-dev] [PATCH 8/9] i965: Implement glDrawTransformFeedback().

Eric Anholt eric at anholt.net
Tue Oct 22 03:09:43 CEST 2013


Kenneth Graunke <kenneth at whitecape.org> writes:

> Implementing the GetTransformFeedbackVertexCount() driver hook allows
> the VBO module to call us with the right number of vertices.
>
> The hardware doesn't directly count the number of vertices written by
> SOL, so we instead use the SO_NUM_PRIMS_WRITTEN(n) counters and multiply
> by the number of vertices per primitive.
>
> Unfortunately, counting the number of primitives generated is tricky:
> a program might pause a transform feedback operation, start a second one
> with a different object, then switch back and resume.  Both transform
> feedback operations share the SO_NUM_PRIMS_WRITTEN counters.
>
> To work around this, we save the counter values at Begin, Pause, Resume,
> and End.  This "bookends" each section where transform feedback is
> active for the current object.  Adding up differences of pairs gives
> us the number of primitives generated.  (This is similar to what we
> do for occlusion queries on platforms without hardware contexts.)
>
> Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
> ---
>  src/mesa/drivers/dri/i965/brw_context.c    |   2 +
>  src/mesa/drivers/dri/i965/brw_context.h    |  26 ++++
>  src/mesa/drivers/dri/i965/gen6_sol.c       |   1 +
>  src/mesa/drivers/dri/i965/gen7_sol_state.c | 190 ++++++++++++++++++++++++++++-
>  4 files changed, 218 insertions(+), 1 deletion(-)

> +/**
> + * Tally the number of primitives generated so far.
> + *
> + * The buffer contains a series of pairs:
> + * (<start0, start1, start2, start3>, <end0, end1, end2, end3>) ;
> + * (<start0, start1, start2, start3>, <end0, end1, end2, end3>) ;
> + *
> + * For each stream, we subtract the pair of values (end - start) to get the
> + * number of primitives generated during one section.  We accumulate these
> + * values, adding them up to get the total number of primitives generated.
> + */
> +static void
> +gen7_tally_prims_generated(struct brw_context *brw,
> +                           struct brw_transform_feedback_object *obj)
> +{
> +   /* If the current batch is still contributing to the number of primitives
> +    * generated, flush it now so the results will be present when mapped.
> +    */
> +   if (drm_intel_bo_references(brw->batch.bo, obj->prim_count_bo))
> +      intel_batchbuffer_flush(brw);
> +
> +   if (unlikely(brw->perf_debug && drm_intel_bo_busy(obj->prim_count_bo)))
> +      perf_debug("Stalling for # of transform feedback primitives written.\n");
> +
> +   drm_intel_bo_map(obj->prim_count_bo, false);
> +   uint64_t *prim_counts = obj->prim_count_bo->virtual;
> +
> +   assert(obj->prim_count_buffer_index % 2 * BRW_MAX_XFB_STREAMS == 0);

I think you want parens around "2 * BRW_MAX_XFB_STREAMS" here.

I was really impressed with how legible I found this patch.  Thanks!

All but patches 4, 9 are:

Reviewed-by: Eric Anholt <eric at anholt.net>

and 9 gets r-b with the obvious change.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20131021/836e05a4/attachment.pgp>


More information about the mesa-dev mailing list