[Mesa-dev] [PATCH 06/10] gallium/util: add util_copy_index_buffer() helper
Nicolai Hähnle
nhaehnle at gmail.com
Tue Jun 14 16:32:17 UTC 2016
On 14.06.2016 17:57, Rob Clark wrote:
> From: Rob Clark <robclark at freedesktop.org>
>
> Note there was previously a util_set_index_buffer() which was only used
> by svga. Replace this.
>
> (The util_copy_* naming is more consistent with other u_inlines/
> u_framebuffer helpers)
Looks like you're changing semantics in a few places: memcpy is replaced
by util_copy_index_buffer, which does reference counting.
Nicolai
>
> Signed-off-by: Rob Clark <robclark at freedesktop.org>
> ---
> src/gallium/auxiliary/util/u_helpers.c | 15 ---------------
> src/gallium/auxiliary/util/u_helpers.h | 3 ---
> src/gallium/auxiliary/util/u_inlines.h | 17 +++++++++++++++++
> src/gallium/drivers/freedreno/freedreno_state.c | 11 +----------
> src/gallium/drivers/i915/i915_state.c | 6 +-----
> src/gallium/drivers/ilo/ilo_state.c | 10 +---------
> src/gallium/drivers/llvmpipe/lp_state_vertex.c | 6 +-----
> src/gallium/drivers/nouveau/nv30/nv30_state.c | 11 +----------
> src/gallium/drivers/r300/r300_state.c | 8 +-------
> src/gallium/drivers/r600/r600_state_common.c | 5 +----
> src/gallium/drivers/radeonsi/si_state.c | 6 +-----
> src/gallium/drivers/softpipe/sp_state_vertex.c | 6 +-----
> src/gallium/drivers/svga/svga_pipe_vertex.c | 2 +-
> src/gallium/drivers/swr/swr_state.cpp | 7 +------
> src/gallium/drivers/vc4/vc4_state.c | 11 +----------
> src/gallium/drivers/virgl/virgl_context.c | 8 +-------
> 16 files changed, 30 insertions(+), 102 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_helpers.c b/src/gallium/auxiliary/util/u_helpers.c
> index 09020b0..117a51b 100644
> --- a/src/gallium/auxiliary/util/u_helpers.c
> +++ b/src/gallium/auxiliary/util/u_helpers.c
> @@ -94,18 +94,3 @@ void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst,
>
> *dst_count = util_last_bit(enabled_buffers);
> }
> -
> -
> -void
> -util_set_index_buffer(struct pipe_index_buffer *dst,
> - const struct pipe_index_buffer *src)
> -{
> - if (src) {
> - pipe_resource_reference(&dst->buffer, src->buffer);
> - memcpy(dst, src, sizeof(*dst));
> - }
> - else {
> - pipe_resource_reference(&dst->buffer, NULL);
> - memset(dst, 0, sizeof(*dst));
> - }
> -}
> diff --git a/src/gallium/auxiliary/util/u_helpers.h b/src/gallium/auxiliary/util/u_helpers.h
> index a9a53e4..9804163 100644
> --- a/src/gallium/auxiliary/util/u_helpers.h
> +++ b/src/gallium/auxiliary/util/u_helpers.h
> @@ -44,9 +44,6 @@ void util_set_vertex_buffers_count(struct pipe_vertex_buffer *dst,
> const struct pipe_vertex_buffer *src,
> unsigned start_slot, unsigned count);
>
> -void util_set_index_buffer(struct pipe_index_buffer *dst,
> - const struct pipe_index_buffer *src);
> -
> #ifdef __cplusplus
> }
> #endif
> diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h
> index 207e2aa..78125c8 100644
> --- a/src/gallium/auxiliary/util/u_inlines.h
> +++ b/src/gallium/auxiliary/util/u_inlines.h
> @@ -623,6 +623,23 @@ util_copy_constant_buffer(struct pipe_constant_buffer *dst,
> }
>
> static inline void
> +util_copy_index_buffer(struct pipe_index_buffer *dst,
> + const struct pipe_index_buffer *src)
> +{
> + if (src) {
> + dst->index_size = src->index_size;
> + dst->offset = src->offset;
> + pipe_resource_reference(&dst->buffer, src->buffer);
> + dst->user_buffer = src->user_buffer;
> + } else {
> + dst->index_size = 0;
> + dst->offset = 0;
> + pipe_resource_reference(&dst->buffer, NULL);
> + dst->user_buffer = NULL;
> + }
> +}
> +
> +static inline void
> util_copy_image_view(struct pipe_image_view *dst,
> const struct pipe_image_view *src)
> {
> diff --git a/src/gallium/drivers/freedreno/freedreno_state.c b/src/gallium/drivers/freedreno/freedreno_state.c
> index 53ea39b..688975f 100644
> --- a/src/gallium/drivers/freedreno/freedreno_state.c
> +++ b/src/gallium/drivers/freedreno/freedreno_state.c
> @@ -207,16 +207,7 @@ fd_set_index_buffer(struct pipe_context *pctx,
> const struct pipe_index_buffer *ib)
> {
> struct fd_context *ctx = fd_context(pctx);
> -
> - if (ib) {
> - pipe_resource_reference(&ctx->indexbuf.buffer, ib->buffer);
> - ctx->indexbuf.index_size = ib->index_size;
> - ctx->indexbuf.offset = ib->offset;
> - ctx->indexbuf.user_buffer = ib->user_buffer;
> - } else {
> - pipe_resource_reference(&ctx->indexbuf.buffer, NULL);
> - }
> -
> + util_copy_index_buffer(&ctx->indexbuf, ib);
> ctx->dirty |= FD_DIRTY_INDEXBUF;
> }
>
> diff --git a/src/gallium/drivers/i915/i915_state.c b/src/gallium/drivers/i915/i915_state.c
> index 2efa14e..dbd711f 100644
> --- a/src/gallium/drivers/i915/i915_state.c
> +++ b/src/gallium/drivers/i915/i915_state.c
> @@ -1063,11 +1063,7 @@ static void i915_set_index_buffer(struct pipe_context *pipe,
> const struct pipe_index_buffer *ib)
> {
> struct i915_context *i915 = i915_context(pipe);
> -
> - if (ib)
> - memcpy(&i915->index_buffer, ib, sizeof(i915->index_buffer));
> - else
> - memset(&i915->index_buffer, 0, sizeof(i915->index_buffer));
> + util_copy_index_buffer(&i915->index_buffer, ib);
> }
>
> static void
> diff --git a/src/gallium/drivers/ilo/ilo_state.c b/src/gallium/drivers/ilo/ilo_state.c
> index 4f1002e..feb50ad 100644
> --- a/src/gallium/drivers/ilo/ilo_state.c
> +++ b/src/gallium/drivers/ilo/ilo_state.c
> @@ -1910,15 +1910,7 @@ ilo_set_index_buffer(struct pipe_context *pipe,
> const struct pipe_index_buffer *state)
> {
> struct ilo_state_vector *vec = &ilo_context(pipe)->state_vector;
> -
> - if (state) {
> - pipe_resource_reference(&vec->ib.state.buffer, state->buffer);
> - vec->ib.state = *state;
> - } else {
> - pipe_resource_reference(&vec->ib.state.buffer, NULL);
> - memset(&vec->ib.state, 0, sizeof(vec->ib.state));
> - }
> -
> + util_copy_index_buffer(&vec->ib.state, state);
> vec->dirty |= ILO_DIRTY_IB;
> }
>
> diff --git a/src/gallium/drivers/llvmpipe/lp_state_vertex.c b/src/gallium/drivers/llvmpipe/lp_state_vertex.c
> index 1e93fd8..2e9669c 100644
> --- a/src/gallium/drivers/llvmpipe/lp_state_vertex.c
> +++ b/src/gallium/drivers/llvmpipe/lp_state_vertex.c
> @@ -98,11 +98,7 @@ llvmpipe_set_index_buffer(struct pipe_context *pipe,
> const struct pipe_index_buffer *ib)
> {
> struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe);
> -
> - if (ib)
> - memcpy(&llvmpipe->index_buffer, ib, sizeof(llvmpipe->index_buffer));
> - else
> - memset(&llvmpipe->index_buffer, 0, sizeof(llvmpipe->index_buffer));
> + util_copy_index_buffer(&llvmpipe->index_buffer, ib);
> }
>
> void
> diff --git a/src/gallium/drivers/nouveau/nv30/nv30_state.c b/src/gallium/drivers/nouveau/nv30/nv30_state.c
> index 3655e0c..f22a809 100644
> --- a/src/gallium/drivers/nouveau/nv30/nv30_state.c
> +++ b/src/gallium/drivers/nouveau/nv30/nv30_state.c
> @@ -441,16 +441,7 @@ nv30_set_index_buffer(struct pipe_context *pipe,
> const struct pipe_index_buffer *ib)
> {
> struct nv30_context *nv30 = nv30_context(pipe);
> -
> - if (ib) {
> - pipe_resource_reference(&nv30->idxbuf.buffer, ib->buffer);
> - nv30->idxbuf.index_size = ib->index_size;
> - nv30->idxbuf.offset = ib->offset;
> - nv30->idxbuf.user_buffer = ib->user_buffer;
> - } else {
> - pipe_resource_reference(&nv30->idxbuf.buffer, NULL);
> - nv30->idxbuf.user_buffer = NULL;
> - }
> + util_copy_index_buffer(&nv30->idxbuf, ib);
> }
>
> void
> diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
> index 01ccd46..b324d34 100644
> --- a/src/gallium/drivers/r300/r300_state.c
> +++ b/src/gallium/drivers/r300/r300_state.c
> @@ -1786,13 +1786,7 @@ static void r300_set_index_buffer_hwtcl(struct pipe_context* pipe,
> const struct pipe_index_buffer *ib)
> {
> struct r300_context* r300 = r300_context(pipe);
> -
> - if (ib) {
> - pipe_resource_reference(&r300->index_buffer.buffer, ib->buffer);
> - memcpy(&r300->index_buffer, ib, sizeof(*ib));
> - } else {
> - pipe_resource_reference(&r300->index_buffer.buffer, NULL);
> - }
> + util_copy_index_buffer(&r300->index_buffer, ib);
> }
>
> static void r300_set_index_buffer_swtcl(struct pipe_context* pipe,
> diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
> index 1ca583c..b9cfea5 100644
> --- a/src/gallium/drivers/r600/r600_state_common.c
> +++ b/src/gallium/drivers/r600/r600_state_common.c
> @@ -520,13 +520,10 @@ static void r600_set_index_buffer(struct pipe_context *ctx,
> const struct pipe_index_buffer *ib)
> {
> struct r600_context *rctx = (struct r600_context *)ctx;
> + util_copy_index_buffer(&rctx->index_buffer, ib);
>
> if (ib) {
> - pipe_resource_reference(&rctx->index_buffer.buffer, ib->buffer);
> - memcpy(&rctx->index_buffer, ib, sizeof(*ib));
> r600_context_add_resource_size(ctx, ib->buffer);
> - } else {
> - pipe_resource_reference(&rctx->index_buffer.buffer, NULL);
> }
> }
>
> diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c
> index 6ef3fe5..20cbbad 100644
> --- a/src/gallium/drivers/radeonsi/si_state.c
> +++ b/src/gallium/drivers/radeonsi/si_state.c
> @@ -3223,13 +3223,9 @@ static void si_set_index_buffer(struct pipe_context *ctx,
> const struct pipe_index_buffer *ib)
> {
> struct si_context *sctx = (struct si_context *)ctx;
> -
> + util_copy_index_buffer(&sctx->index_buffer, ib);
> if (ib) {
> - pipe_resource_reference(&sctx->index_buffer.buffer, ib->buffer);
> - memcpy(&sctx->index_buffer, ib, sizeof(*ib));
> r600_context_add_resource_size(ctx, ib->buffer);
> - } else {
> - pipe_resource_reference(&sctx->index_buffer.buffer, NULL);
> }
> }
>
> diff --git a/src/gallium/drivers/softpipe/sp_state_vertex.c b/src/gallium/drivers/softpipe/sp_state_vertex.c
> index 48c8d2c..afbedbe 100644
> --- a/src/gallium/drivers/softpipe/sp_state_vertex.c
> +++ b/src/gallium/drivers/softpipe/sp_state_vertex.c
> @@ -102,11 +102,7 @@ softpipe_set_index_buffer(struct pipe_context *pipe,
> const struct pipe_index_buffer *ib)
> {
> struct softpipe_context *softpipe = softpipe_context(pipe);
> -
> - if (ib)
> - memcpy(&softpipe->index_buffer, ib, sizeof(softpipe->index_buffer));
> - else
> - memset(&softpipe->index_buffer, 0, sizeof(softpipe->index_buffer));
> + util_copy_index_buffer(&softpipe->index_buffer, ib);
> }
>
>
> diff --git a/src/gallium/drivers/svga/svga_pipe_vertex.c b/src/gallium/drivers/svga/svga_pipe_vertex.c
> index 99757e4..5e03f10 100644
> --- a/src/gallium/drivers/svga/svga_pipe_vertex.c
> +++ b/src/gallium/drivers/svga/svga_pipe_vertex.c
> @@ -59,7 +59,7 @@ static void svga_set_index_buffer(struct pipe_context *pipe,
> {
> struct svga_context *svga = svga_context(pipe);
>
> - util_set_index_buffer(&svga->curr.ib, ib);
> + util_copy_index_buffer(&svga->curr.ib, ib);
> }
>
>
> diff --git a/src/gallium/drivers/swr/swr_state.cpp b/src/gallium/drivers/swr/swr_state.cpp
> index c4b5f77..cd18c96 100644
> --- a/src/gallium/drivers/swr/swr_state.cpp
> +++ b/src/gallium/drivers/swr/swr_state.cpp
> @@ -529,12 +529,7 @@ swr_set_index_buffer(struct pipe_context *pipe,
> const struct pipe_index_buffer *ib)
> {
> struct swr_context *ctx = swr_context(pipe);
> -
> - if (ib)
> - memcpy(&ctx->index_buffer, ib, sizeof(ctx->index_buffer));
> - else
> - memset(&ctx->index_buffer, 0, sizeof(ctx->index_buffer));
> -
> + util_copy_index_buffer(&ctx->index_buffer, ib);
> ctx->dirty |= SWR_NEW_VERTEX;
> }
>
> diff --git a/src/gallium/drivers/vc4/vc4_state.c b/src/gallium/drivers/vc4/vc4_state.c
> index 7aa3931..694d8a0 100644
> --- a/src/gallium/drivers/vc4/vc4_state.c
> +++ b/src/gallium/drivers/vc4/vc4_state.c
> @@ -306,16 +306,7 @@ vc4_set_index_buffer(struct pipe_context *pctx,
> const struct pipe_index_buffer *ib)
> {
> struct vc4_context *vc4 = vc4_context(pctx);
> -
> - if (ib) {
> - pipe_resource_reference(&vc4->indexbuf.buffer, ib->buffer);
> - vc4->indexbuf.index_size = ib->index_size;
> - vc4->indexbuf.offset = ib->offset;
> - vc4->indexbuf.user_buffer = ib->user_buffer;
> - } else {
> - pipe_resource_reference(&vc4->indexbuf.buffer, NULL);
> - }
> -
> + util_copy_index_buffer(&vc4->indexbuf, ib);
> vc4->dirty |= VC4_DIRTY_INDEXBUF;
> }
>
> diff --git a/src/gallium/drivers/virgl/virgl_context.c b/src/gallium/drivers/virgl/virgl_context.c
> index 27e85a8..865c144 100644
> --- a/src/gallium/drivers/virgl/virgl_context.c
> +++ b/src/gallium/drivers/virgl/virgl_context.c
> @@ -407,13 +407,7 @@ static void virgl_set_index_buffer(struct pipe_context *ctx,
> const struct pipe_index_buffer *ib)
> {
> struct virgl_context *vctx = virgl_context(ctx);
> -
> - if (ib) {
> - pipe_resource_reference(&vctx->index_buffer.buffer, ib->buffer);
> - memcpy(&vctx->index_buffer, ib, sizeof(*ib));
> - } else {
> - pipe_resource_reference(&vctx->index_buffer.buffer, NULL);
> - }
> + util_copy_index_buffer(&vctx->index_buffer, ib);
> }
>
> static void virgl_hw_set_index_buffer(struct pipe_context *ctx,
>
More information about the mesa-dev
mailing list