[Mesa-dev] [PATCH 4/4] i965: use cut index to handle primitive restart when possible
Ian Romanick
idr at freedesktop.org
Mon May 14 16:29:28 PDT 2012
On 05/13/2012 07:06 AM, Jordan Justen wrote:
> If the primitive restart index and the primitive type can
> be handled by the cut index feature, then use the hardware
> to handle the primitive restart feature.
>
> The VBO module's software handling of primitive restart is
> used as a fall back.
>
> Signed-off-by: Jordan Justen<jordan.l.justen at intel.com>
> ---
> src/mesa/drivers/dri/i965/brw_primitive_restart.c | 68 ++++++++++++++++++++-
> 1 file changed, 67 insertions(+), 1 deletion(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_primitive_restart.c b/src/mesa/drivers/dri/i965/brw_primitive_restart.c
> index 20a9226..f4c8f4e 100644
> --- a/src/mesa/drivers/dri/i965/brw_primitive_restart.c
> +++ b/src/mesa/drivers/dri/i965/brw_primitive_restart.c
> @@ -31,6 +31,56 @@
> #include "brw_context.h"
> #include "brw_draw.h"
>
> +static bool can_cut_index_handle_restart_index(struct gl_context *ctx,
> + const struct _mesa_index_buffer *ib)
> +{
> + bool cut_index_will_work;
> +
> + switch (ib->type) {
> + case GL_UNSIGNED_BYTE:
> + cut_index_will_work = (ctx->Array.RestartIndex& 0xff) == 0xff;
> + break;
> + case GL_UNSIGNED_SHORT:
> + cut_index_will_work = (ctx->Array.RestartIndex& 0xffff) == 0xffff;
> + break;
> + case GL_UNSIGNED_INT:
> + cut_index_will_work = ctx->Array.RestartIndex == 0xffffffff;
> + break;
> + default:
> + cut_index_will_work = false;
> + assert(0);
> + }
> +
> + return cut_index_will_work;
> +}
> +
> +static bool can_cut_index_handle_prims(struct gl_context *ctx,
> + const struct _mesa_prim *prim,
> + GLuint nr_prims)
> +{
> + for ( ; nr_prims> 0; nr_prims--) {
> + switch(prim->mode) {
> + case GL_POINTS:
> + case GL_LINES:
> + case GL_LINE_STRIP:
> + case GL_TRIANGLES:
> + case GL_TRIANGLE_STRIP:
> + /* Cut index supports these primitive types */
> + break;
> + default:
> + /* Cut index does not support these primitive types */
> + //case GL_LINE_LOOP:
> + //case GL_TRIANGLE_FAN:
> + //case GL_QUADS:
> + //case GL_QUAD_STRIP:
> + //case GL_POLYGON:
> + return false;
> + }
> + }
> +
> + return true;
> +}
> +
> bool brw_handle_primitive_restart(struct gl_context *ctx,
> const struct _mesa_prim *prim,
> GLuint nr_prims,
> @@ -70,7 +120,23 @@ bool brw_handle_primitive_restart(struct gl_context *ctx,
> */
> brw->prim_restart.in_progress = true;
>
> - vbo_sw_primitive_restart(ctx, prim, nr_prims, ib);
> + if (!can_cut_index_handle_restart_index(ctx, ib)) {
> + /* The primitive restart index can't be handled, so take
> + * the software path
> + */
> + vbo_sw_primitive_restart(ctx, prim, nr_prims, ib);
> + } else if (can_cut_index_handle_prims(ctx, prim, nr_prims)) {
> + /* Cut index should work for primitive restart, so use it
> + */
> + brw->prim_restart.enable_cut_index = true;
> + brw_draw_prims(ctx, prim, nr_prims, ib, GL_FALSE, -1, -1, NULL);
> + brw->prim_restart.enable_cut_index = false;
> + } else {
> + /* Not all the primitive draw modes are supported by the cut index,
> + * so take the software path
> + */
> + vbo_sw_primitive_restart(ctx, prim, nr_prims, ib);
> + }
I think this is better as
if (can_cut_index_handle_restart_index(ctx, ib)
&& can_cut_index_handle_prims(ctx, prim, nr_prims)) {
...
} else {
...
}
> brw->prim_restart.in_progress = false;
More information about the mesa-dev
mailing list