[Mesa-dev] [PATCH 2/3] gallium/auxiliary/indices: add u_primconvert

Brian Paul brianp at vmware.com
Tue Oct 29 21:22:58 CET 2013


On 10/29/2013 02:10 PM, Rob Clark wrote:
> From: Rob Clark <robclark at freedesktop.org>
>
> A convenient front end to indices generate/translate code, for emulating
> primitives which are not supported natively by the driver.
>
> This handles saving/restoring index buffer state, etc.
>
> Signed-off-by: Rob Clark <robclark at freedesktop.org>
> Reviewed-by: Brian Paul <brianp at vmware.com>
> ---
> v1: original
> v2: re-indent, fix initializers for MSVC, use util_draw_init_info()
>
>   src/gallium/auxiliary/Makefile.sources        |   1 +
>   src/gallium/auxiliary/indices/u_primconvert.c | 181 ++++++++++++++++++++++++++
>   src/gallium/auxiliary/indices/u_primconvert.h |  45 +++++++
>   3 files changed, 227 insertions(+)
>   create mode 100644 src/gallium/auxiliary/indices/u_primconvert.c
>   create mode 100644 src/gallium/auxiliary/indices/u_primconvert.h
>
> diff --git a/src/gallium/auxiliary/Makefile.sources b/src/gallium/auxiliary/Makefile.sources
> index acbcef7..c89cbdd 100644
> --- a/src/gallium/auxiliary/Makefile.sources
> +++ b/src/gallium/auxiliary/Makefile.sources
> @@ -43,6 +43,7 @@ C_SOURCES := \
>   	hud/hud_cpu.c \
>   	hud/hud_fps.c \
>           hud/hud_driver_query.c \
> +	indices/u_primconvert.c \
>   	os/os_misc.c \
>   	os/os_process.c \
>   	os/os_time.c \
> diff --git a/src/gallium/auxiliary/indices/u_primconvert.c b/src/gallium/auxiliary/indices/u_primconvert.c
> new file mode 100644
> index 0000000..14da7a6
> --- /dev/null
> +++ b/src/gallium/auxiliary/indices/u_primconvert.c
> @@ -0,0 +1,181 @@
> +/*
> + * Copyright (C) 2013 Rob Clark <robclark at freedesktop.org>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + *
> + * Authors:
> + *    Rob Clark <robclark at freedesktop.org>
> + */
> +
> +/**
> + * This module converts provides a more convenient front-end to u_indices,
> + * etc, utils to convert primitive types supported not supported by the
> + * hardware.  It handles binding new index buffer state, and restoring
> + * previous state after.  To use, put something like this at the front of
> + * drivers pipe->draw_vbo():
> + *
> + *    // emulate unsupported primitives:
> + *    if (info->mode needs emulating) {
> + *       util_primconvert_save_index_buffer(ctx->primconvert, &ctx->indexbuf);
> + *       util_primconvert_save_rasterizer_state(ctx->primconvert, ctx->rasterizer);
> + *       util_primconvert_draw_vbo(ctx->primconvert, info);
> + *       return;
> + *    }
> + *
> + */
> +
> +#include "pipe/p_state.h"
> +#include "util/u_draw.h"
> +#include "util/u_inlines.h"
> +#include "util/u_memory.h"
> +
> +#include "indices/u_indices.h"
> +#include "indices/u_primconvert.h"
> +
> +struct primconvert_context
> +{
> +   struct pipe_context *pipe;
> +   struct pipe_index_buffer saved_ib;
> +   uint32_t primtypes_mask;
> +   unsigned api_pv;
> +   // TODO we could cache/recycle the indexbuf created to translate prims..
> +};
> +
> +
> +struct primconvert_context *
> +util_primconvert_create(struct pipe_context *pipe, uint32_t primtypes_mask)
> +{
> +   struct primconvert_context *pc = CALLOC_STRUCT(primconvert_context);
> +   if (!pc)
> +      return NULL;
> +   pc->pipe = pipe;
> +   pc->primtypes_mask = primtypes_mask;
> +   return pc;
> +}
> +
> +void
> +util_primconvert_destroy(struct primconvert_context *pc)
> +{
> +   util_primconvert_save_index_buffer(pc, NULL);
> +   free(pc);
> +}
> +
> +void
> +util_primconvert_save_index_buffer(struct primconvert_context *pc,
> +                                   const struct pipe_index_buffer *ib)
> +{
> +   if (ib) {
> +      pipe_resource_reference(&pc->saved_ib.buffer, ib->buffer);
> +      pc->saved_ib.index_size = ib->index_size;
> +      pc->saved_ib.offset = ib->offset;
> +      pc->saved_ib.user_buffer = ib->user_buffer;
> +   }
> +   else {
> +      pipe_resource_reference(&pc->saved_ib.buffer, NULL);
> +   }

I think we have similar code duplicated in a few places.  We should 
probably have a util_copy_index_buffer(dst, src) function that copies 
pipe_index_buffer objects.  We could do that in a follow-on patch though.


For patches 1-2: Reviewed-by: Brian Paul <brianp at vmware.com>
For patch 3: Acked-by: Brian Paul <brianp at vmware.com>




More information about the mesa-dev mailing list