diff options
author | Marek Olšák <[email protected]> | 2012-10-08 04:06:42 +0200 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2012-10-11 21:12:16 +0200 |
commit | 369e46888904c6d379b8b477d9242cff1608e30e (patch) | |
tree | 528b10f900f23af3acd22a0edcf50fde0eeee86e /src/gallium/drivers/llvmpipe | |
parent | ec4c74a9dc10039d97ad24c4f16bd2400517991d (diff) |
gallium: unify transfer functions
"get_transfer + transfer_map" becomes "transfer_map".
"transfer_unmap + transfer_destroy" becomes "transfer_unmap".
transfer_map must create and return the transfer object and transfer_unmap
must destroy it.
transfer_map is successful if the returned buffer pointer is not NULL.
If transfer_map fails, the pointer to the transfer object remains unchanged
(i.e. doesn't have to be NULL).
Acked-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium/drivers/llvmpipe')
-rw-r--r-- | src/gallium/drivers/llvmpipe/lp_texture.c | 104 |
1 files changed, 42 insertions, 62 deletions
diff --git a/src/gallium/drivers/llvmpipe/lp_texture.c b/src/gallium/drivers/llvmpipe/lp_texture.c index 841df004d14..b4ea94ca1ae 100644 --- a/src/gallium/drivers/llvmpipe/lp_texture.c +++ b/src/gallium/drivers/llvmpipe/lp_texture.c @@ -622,16 +622,23 @@ llvmpipe_surface_destroy(struct pipe_context *pipe, } -static struct pipe_transfer * -llvmpipe_get_transfer(struct pipe_context *pipe, - struct pipe_resource *resource, - unsigned level, - unsigned usage, - const struct pipe_box *box) +static void * +llvmpipe_transfer_map( struct pipe_context *pipe, + struct pipe_resource *resource, + unsigned level, + unsigned usage, + const struct pipe_box *box, + struct pipe_transfer **transfer ) { struct llvmpipe_context *llvmpipe = llvmpipe_context(pipe); - struct llvmpipe_resource *lprex = llvmpipe_resource(resource); - struct llvmpipe_transfer *lpr; + struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen); + struct llvmpipe_resource *lpr = llvmpipe_resource(resource); + struct llvmpipe_transfer *lpt; + struct pipe_transfer *pt; + ubyte *map; + enum pipe_format format; + enum lp_texture_usage tex_usage; + const char *mode; assert(resource); assert(level <= resource->last_level); @@ -661,48 +668,19 @@ llvmpipe_get_transfer(struct pipe_context *pipe, if (resource == llvmpipe->constants[PIPE_SHADER_FRAGMENT][0]) llvmpipe->dirty |= LP_NEW_CONSTANTS; - lpr = CALLOC_STRUCT(llvmpipe_transfer); - if (lpr) { - struct pipe_transfer *pt = &lpr->base; - pipe_resource_reference(&pt->resource, resource); - pt->box = *box; - pt->level = level; - pt->stride = lprex->row_stride[level]; - pt->layer_stride = lprex->img_stride[level]; - pt->usage = usage; - - return pt; - } - return NULL; -} - - -static void -llvmpipe_transfer_destroy(struct pipe_context *pipe, - struct pipe_transfer *transfer) -{ - /* Effectively do the texture_update work here - if texture images - * needed post-processing to put them into hardware layout, this is - * where it would happen. For llvmpipe, nothing to do. - */ - assert (transfer->resource); - pipe_resource_reference(&transfer->resource, NULL); - FREE(transfer); -} - - -static void * -llvmpipe_transfer_map( struct pipe_context *pipe, - struct pipe_transfer *transfer ) -{ - struct llvmpipe_screen *screen = llvmpipe_screen(pipe->screen); - ubyte *map; - struct llvmpipe_resource *lpr; - enum pipe_format format; - enum lp_texture_usage tex_usage; - const char *mode; + lpt = CALLOC_STRUCT(llvmpipe_transfer); + if (!lpt) + return NULL; + pt = &lpt->base; + pipe_resource_reference(&pt->resource, resource); + pt->box = *box; + pt->level = level; + pt->stride = lpr->row_stride[level]; + pt->layer_stride = lpr->img_stride[level]; + pt->usage = usage; + *transfer = pt; - assert(transfer->level < LP_MAX_TEXTURE_LEVELS); + assert(level < LP_MAX_TEXTURE_LEVELS); /* printf("tex_transfer_map(%d, %d %d x %d of %d x %d, usage %d )\n", @@ -712,7 +690,7 @@ llvmpipe_transfer_map( struct pipe_context *pipe, transfer->usage); */ - if (transfer->usage == PIPE_TRANSFER_READ) { + if (usage == PIPE_TRANSFER_READ) { tex_usage = LP_TEX_USAGE_READ; mode = "read"; } @@ -722,33 +700,29 @@ llvmpipe_transfer_map( struct pipe_context *pipe, } if (0) { - struct llvmpipe_resource *lpr = llvmpipe_resource(transfer->resource); printf("transfer map tex %u mode %s\n", lpr->id, mode); } - - assert(transfer->resource); - lpr = llvmpipe_resource(transfer->resource); format = lpr->base.format; - map = llvmpipe_resource_map(transfer->resource, - transfer->level, - transfer->box.z, + map = llvmpipe_resource_map(resource, + level, + box->z, tex_usage, LP_TEX_LAYOUT_LINEAR); /* May want to do different things here depending on read/write nature * of the map: */ - if (transfer->usage & PIPE_TRANSFER_WRITE) { + if (usage & PIPE_TRANSFER_WRITE) { /* Do something to notify sharing contexts of a texture change. */ screen->timestamp++; } map += - transfer->box.y / util_format_get_blockheight(format) * transfer->stride + - transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + box->y / util_format_get_blockheight(format) * pt->stride + + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); return map; } @@ -763,6 +737,14 @@ llvmpipe_transfer_unmap(struct pipe_context *pipe, llvmpipe_resource_unmap(transfer->resource, transfer->level, transfer->box.z); + + /* Effectively do the texture_update work here - if texture images + * needed post-processing to put them into hardware layout, this is + * where it would happen. For llvmpipe, nothing to do. + */ + assert (transfer->resource); + pipe_resource_reference(&transfer->resource, NULL); + FREE(transfer); } unsigned int @@ -1474,8 +1456,6 @@ llvmpipe_init_screen_resource_funcs(struct pipe_screen *screen) void llvmpipe_init_context_resource_funcs(struct pipe_context *pipe) { - pipe->get_transfer = llvmpipe_get_transfer; - pipe->transfer_destroy = llvmpipe_transfer_destroy; pipe->transfer_map = llvmpipe_transfer_map; pipe->transfer_unmap = llvmpipe_transfer_unmap; |