diff options
author | Marek Olšák <[email protected]> | 2016-07-16 21:19:48 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2016-07-23 13:33:42 +0200 |
commit | 1ffe77e7bb2486ea74cda077ed2a9622b758395c (patch) | |
tree | 4a04818614fc8c4e086e9dcd32dbadecbac4b6fb /src/gallium/auxiliary | |
parent | 0ba7288376dc66f932336862c8a6abb629b47686 (diff) |
gallium: split transfer_inline_write into buffer and texture callbacks
to reduce the call indirections with u_resource_vtbl.
The worst call tree you could get was:
- u_transfer_inline_write_vtbl
- u_default_transfer_inline_write
- u_transfer_map_vtbl
- driver_transfer_map
- u_transfer_unmap_vtbl
- driver_transfer_unmap
That's 6 indirect calls. Some drivers only had 5. The goal is to have
1 indirect call for drivers that care. The resource type can be determined
statically at most call sites.
The new interface is:
pipe_context::buffer_subdata(ctx, resource, usage, offset, size, data)
pipe_context::texture_subdata(ctx, resource, level, usage, box, data,
stride, layer_stride)
v2: fix whitespace, correct ilo's behavior
Reviewed-by: Nicolai Hähnle <[email protected]>
Acked-by: Roland Scheidegger <[email protected]>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r-- | src/gallium/auxiliary/postprocess/pp_mlaa.c | 14 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_inlines.h | 28 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_transfer.c | 112 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_transfer.h | 39 |
4 files changed, 74 insertions, 119 deletions
diff --git a/src/gallium/auxiliary/postprocess/pp_mlaa.c b/src/gallium/auxiliary/postprocess/pp_mlaa.c index a3f58b52f48..502fcf169a6 100644 --- a/src/gallium/auxiliary/postprocess/pp_mlaa.c +++ b/src/gallium/auxiliary/postprocess/pp_mlaa.c @@ -62,13 +62,9 @@ static void up_consts(struct pp_queue_t *ppq) { struct pipe_context *pipe = ppq->p->pipe; - struct pipe_box box; - - u_box_2d(0, 0, sizeof(constants), 1, &box); - pipe->transfer_inline_write(pipe, ppq->constbuf, 0, PIPE_TRANSFER_WRITE, - &box, constants, sizeof(constants), - sizeof(constants)); + pipe->buffer_subdata(pipe, ppq->constbuf, PIPE_TRANSFER_WRITE, + 0, sizeof(constants), constants); } /** Run function of the MLAA filter. */ @@ -280,9 +276,9 @@ pp_jimenezmlaa_init_run(struct pp_queue_t *ppq, unsigned int n, u_box_2d(0, 0, 165, 165, &box); - ppq->p->pipe->transfer_inline_write(ppq->p->pipe, ppq->areamaptex, 0, - PIPE_TRANSFER_WRITE, &box, - areamap, 165 * 2, sizeof(areamap)); + ppq->p->pipe->texture_subdata(ppq->p->pipe, ppq->areamaptex, 0, + PIPE_TRANSFER_WRITE, &box, + areamap, 165 * 2, sizeof(areamap)); ppq->shaders[n][1] = pp_tgsi_to_state(ppq->p->pipe, offsetvs, true, "offsetvs"); diff --git a/src/gallium/auxiliary/util/u_inlines.h b/src/gallium/auxiliary/util/u_inlines.h index 207e2aa838f..07f73546ad7 100644 --- a/src/gallium/auxiliary/util/u_inlines.h +++ b/src/gallium/auxiliary/util/u_inlines.h @@ -339,7 +339,6 @@ pipe_buffer_write(struct pipe_context *pipe, unsigned size, const void *data) { - struct pipe_box box; unsigned access = PIPE_TRANSFER_WRITE; if (offset == 0 && size == buf->width0) { @@ -348,16 +347,7 @@ pipe_buffer_write(struct pipe_context *pipe, access |= PIPE_TRANSFER_DISCARD_RANGE; } - u_box_1d(offset, size, &box); - - pipe->transfer_inline_write( pipe, - buf, - 0, - access, - &box, - data, - size, - 0); + pipe->buffer_subdata(pipe, buf, access, offset, size, data); } /** @@ -372,18 +362,10 @@ pipe_buffer_write_nooverlap(struct pipe_context *pipe, unsigned offset, unsigned size, const void *data) { - struct pipe_box box; - - u_box_1d(offset, size, &box); - - pipe->transfer_inline_write(pipe, - buf, - 0, - (PIPE_TRANSFER_WRITE | - PIPE_TRANSFER_UNSYNCHRONIZED), - &box, - data, - 0, 0); + pipe->buffer_subdata(pipe, buf, + (PIPE_TRANSFER_WRITE | + PIPE_TRANSFER_UNSYNCHRONIZED), + offset, size, data); } diff --git a/src/gallium/auxiliary/util/u_transfer.c b/src/gallium/auxiliary/util/u_transfer.c index 0610535cd2c..82cf68db958 100644 --- a/src/gallium/auxiliary/util/u_transfer.c +++ b/src/gallium/auxiliary/util/u_transfer.c @@ -4,34 +4,58 @@ #include "util/u_transfer.h" #include "util/u_memory.h" -/* One-shot transfer operation with data supplied in a user - * pointer. XXX: strides?? - */ -void u_default_transfer_inline_write( struct pipe_context *pipe, - struct pipe_resource *resource, - unsigned level, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned layer_stride) +void u_default_buffer_subdata(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned usage, unsigned offset, + unsigned size, const void *data) { struct pipe_transfer *transfer = NULL; + struct pipe_box box; uint8_t *map = NULL; assert(!(usage & PIPE_TRANSFER_READ)); - /* the write flag is implicit by the nature of transfer_inline_write */ + /* the write flag is implicit by the nature of buffer_subdata */ usage |= PIPE_TRANSFER_WRITE; - /* transfer_inline_write implicitly discards the rewritten buffer range */ - if (resource->target == PIPE_BUFFER && - box->x == 0 && box->width == resource->width0) { + /* buffer_subdata implicitly discards the rewritten buffer range */ + if (offset == 0 && size == resource->width0) { usage |= PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE; } else { usage |= PIPE_TRANSFER_DISCARD_RANGE; } + u_box_1d(offset, size, &box); + + map = pipe->transfer_map(pipe, resource, 0, usage, &box, &transfer); + if (!map) + return; + + memcpy(map, data, size); + pipe_transfer_unmap(pipe, transfer); +} + +void u_default_texture_subdata(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride) +{ + struct pipe_transfer *transfer = NULL; + const uint8_t *src_data = data; + uint8_t *map = NULL; + + assert(!(usage & PIPE_TRANSFER_READ)); + + /* the write flag is implicit by the nature of texture_subdata */ + usage |= PIPE_TRANSFER_WRITE; + + /* texture_subdata implicitly discards the rewritten buffer range */ + usage |= PIPE_TRANSFER_DISCARD_RANGE; + map = pipe->transfer_map(pipe, resource, level, @@ -40,28 +64,18 @@ void u_default_transfer_inline_write( struct pipe_context *pipe, if (!map) return; - if (resource->target == PIPE_BUFFER) { - assert(box->height == 1); - assert(box->depth == 1); - - memcpy(map, data, box->width); - } - else { - const uint8_t *src_data = data; - - util_copy_box(map, - resource->format, - transfer->stride, /* bytes */ - transfer->layer_stride, /* bytes */ - 0, 0, 0, - box->width, - box->height, - box->depth, - src_data, - stride, /* bytes */ - layer_stride, /* bytes */ - 0, 0, 0); - } + util_copy_box(map, + resource->format, + transfer->stride, /* bytes */ + transfer->layer_stride, /* bytes */ + 0, 0, 0, + box->width, + box->height, + box->depth, + src_data, + stride, /* bytes */ + layer_stride, /* bytes */ + 0, 0, 0); pipe_transfer_unmap(pipe, transfer); } @@ -138,27 +152,3 @@ void u_transfer_unmap_vtbl( struct pipe_context *pipe, struct u_resource *ur = u_resource(transfer->resource); ur->vtbl->transfer_unmap(pipe, transfer); } - -void u_transfer_inline_write_vtbl( struct pipe_context *pipe, - struct pipe_resource *resource, - unsigned level, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned layer_stride) -{ - struct u_resource *ur = u_resource(resource); - ur->vtbl->transfer_inline_write(pipe, - resource, - level, - usage, - box, - data, - stride, - layer_stride); -} - - - - diff --git a/src/gallium/auxiliary/util/u_transfer.h b/src/gallium/auxiliary/util/u_transfer.h index 660dc161d33..7f680bc6582 100644 --- a/src/gallium/auxiliary/util/u_transfer.h +++ b/src/gallium/auxiliary/util/u_transfer.h @@ -14,14 +14,19 @@ boolean u_default_resource_get_handle(struct pipe_screen *screen, struct pipe_resource *resource, struct winsys_handle *handle); -void u_default_transfer_inline_write( struct pipe_context *pipe, - struct pipe_resource *resource, - unsigned level, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned layer_stride); +void u_default_buffer_subdata(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned usage, unsigned offset, + unsigned size, const void *data); + +void u_default_texture_subdata(struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + const void *data, + unsigned stride, + unsigned layer_stride); void u_default_transfer_flush_region( struct pipe_context *pipe, struct pipe_transfer *transfer, @@ -58,15 +63,6 @@ struct u_resource_vtbl { void (*transfer_unmap)( struct pipe_context *, struct pipe_transfer *transfer ); - - void (*transfer_inline_write)( struct pipe_context *pipe, - struct pipe_resource *resource, - unsigned level, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned layer_stride); }; @@ -98,13 +94,4 @@ void u_transfer_flush_region_vtbl( struct pipe_context *pipe, void u_transfer_unmap_vtbl( struct pipe_context *rm_ctx, struct pipe_transfer *transfer ); -void u_transfer_inline_write_vtbl( struct pipe_context *rm_ctx, - struct pipe_resource *resource, - unsigned level, - unsigned usage, - const struct pipe_box *box, - const void *data, - unsigned stride, - unsigned layer_stride); - #endif |