summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/util/u_transfer.c
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2016-07-16 21:19:48 +0200
committerMarek Olšák <[email protected]>2016-07-23 13:33:42 +0200
commit1ffe77e7bb2486ea74cda077ed2a9622b758395c (patch)
tree4a04818614fc8c4e086e9dcd32dbadecbac4b6fb /src/gallium/auxiliary/util/u_transfer.c
parent0ba7288376dc66f932336862c8a6abb629b47686 (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/util/u_transfer.c')
-rw-r--r--src/gallium/auxiliary/util/u_transfer.c112
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);
-}
-
-
-
-