From 693fac8ae2e5812265222b1335695bd33b90bd8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fonseca?= Date: Tue, 24 Feb 2009 11:30:25 +0000 Subject: gallium: Add pipe_buffer_write/read inlines. Saves code, and will simplify future interface changes. --- src/gallium/auxiliary/util/u_blit.c | 18 ++++----------- src/gallium/auxiliary/util/u_gen_mipmap.c | 9 ++------ src/gallium/include/pipe/p_inlines.h | 38 +++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 21 deletions(-) (limited to 'src/gallium') diff --git a/src/gallium/auxiliary/util/u_blit.c b/src/gallium/auxiliary/util/u_blit.c index efc3a874cc..4cc720269d 100644 --- a/src/gallium/auxiliary/util/u_blit.c +++ b/src/gallium/auxiliary/util/u_blit.c @@ -199,7 +199,6 @@ static unsigned setup_vertex_data(struct blit_state *ctx, float x0, float y0, float x1, float y1, float z) { - void *buf; unsigned offset; ctx->vertices[0][0][0] = x0; @@ -228,12 +227,8 @@ setup_vertex_data(struct blit_state *ctx, offset = get_next_slot( ctx ); - buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf, - PIPE_BUFFER_USAGE_CPU_WRITE); - - memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices)); - - pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf); + pipe_buffer_write(ctx->pipe->screen, ctx->vbuf, + offset, sizeof(ctx->vertices), ctx->vertices); return offset; } @@ -249,7 +244,6 @@ setup_vertex_data_tex(struct blit_state *ctx, float s0, float t0, float s1, float t1, float z) { - void *buf; unsigned offset; ctx->vertices[0][0][0] = x0; @@ -278,12 +272,8 @@ setup_vertex_data_tex(struct blit_state *ctx, offset = get_next_slot( ctx ); - buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf, - PIPE_BUFFER_USAGE_CPU_WRITE); - - memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices)); - - pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf); + pipe_buffer_write(ctx->pipe->screen, ctx->vbuf, + offset, sizeof(ctx->vertices), ctx->vertices); return offset; } diff --git a/src/gallium/auxiliary/util/u_gen_mipmap.c b/src/gallium/auxiliary/util/u_gen_mipmap.c index 90483fcb21..1857a71dd8 100644 --- a/src/gallium/auxiliary/util/u_gen_mipmap.c +++ b/src/gallium/auxiliary/util/u_gen_mipmap.c @@ -1368,7 +1368,6 @@ get_next_slot(struct gen_mipmap_state *ctx) static unsigned set_vertex_data(struct gen_mipmap_state *ctx, float width, float height) { - void *buf; unsigned offset; ctx->vertices[0][0][0] = 0.0f; /*x*/ @@ -1393,12 +1392,8 @@ set_vertex_data(struct gen_mipmap_state *ctx, float width, float height) offset = get_next_slot( ctx ); - buf = pipe_buffer_map(ctx->pipe->screen, ctx->vbuf, - PIPE_BUFFER_USAGE_CPU_WRITE); - - memcpy((char *)buf + offset, ctx->vertices, sizeof(ctx->vertices)); - - pipe_buffer_unmap(ctx->pipe->screen, ctx->vbuf); + pipe_buffer_write(ctx->pipe->screen, ctx->vbuf, + offset, sizeof(ctx->vertices), ctx->vertices); return offset; } diff --git a/src/gallium/include/pipe/p_inlines.h b/src/gallium/include/pipe/p_inlines.h index ffbe2d7612..4eb928d882 100644 --- a/src/gallium/include/pipe/p_inlines.h +++ b/src/gallium/include/pipe/p_inlines.h @@ -161,6 +161,44 @@ pipe_buffer_unmap(struct pipe_screen *screen, screen->buffer_unmap(screen, buf); } +static INLINE void +pipe_buffer_write(struct pipe_screen *screen, + struct pipe_buffer *buf, + unsigned offset, unsigned size, + const void *data) +{ + uint8_t *map; + + assert(offset < buf->size); + assert(offset + size <= buf->size); + + map = pipe_buffer_map(screen, buf, PIPE_BUFFER_USAGE_CPU_WRITE); + assert(map); + if(map) { + memcpy(map + offset, data, size); + pipe_buffer_unmap(screen, buf); + } +} + +static INLINE void +pipe_buffer_read(struct pipe_screen *screen, + struct pipe_buffer *buf, + unsigned offset, unsigned size, + void *data) +{ + uint8_t *map; + + assert(offset < buf->size); + assert(offset + size <= buf->size); + + map = pipe_buffer_map(screen, buf, PIPE_BUFFER_USAGE_CPU_READ); + assert(map); + if(map) { + memcpy(data, map + offset, size); + pipe_buffer_unmap(screen, buf); + } +} + /* XXX: thread safety issues! */ static INLINE void -- cgit v1.2.3