diff options
Diffstat (limited to 'src/gallium/auxiliary/util/u_transfer.c')
-rw-r--r-- | src/gallium/auxiliary/util/u_transfer.c | 112 |
1 files changed, 51 insertions, 61 deletions
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); -} - - - - |