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/radeonsi/r600_texture.c | |
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/radeonsi/r600_texture.c')
-rw-r--r-- | src/gallium/drivers/radeonsi/r600_texture.c | 99 |
1 files changed, 44 insertions, 55 deletions
diff --git a/src/gallium/drivers/radeonsi/r600_texture.c b/src/gallium/drivers/radeonsi/r600_texture.c index e6f72c88b05..8fae79200b6 100644 --- a/src/gallium/drivers/radeonsi/r600_texture.c +++ b/src/gallium/drivers/radeonsi/r600_texture.c @@ -254,17 +254,23 @@ static void r600_texture_destroy(struct pipe_screen *screen, FREE(rtex); } -static struct pipe_transfer* si_texture_get_transfer(struct pipe_context *ctx, - struct pipe_resource *texture, - unsigned level, - unsigned usage, - const struct pipe_box *box) +static void *si_texture_transfer_map(struct pipe_context *ctx, + struct pipe_resource *texture, + unsigned level, + unsigned usage, + const struct pipe_box *box, + struct pipe_transfer **ptransfer) { + struct r600_context *rctx = (struct r600_context *)ctx; struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; struct pipe_resource resource; struct r600_transfer *trans; int r; boolean use_staging_texture = FALSE; + struct radeon_winsys_cs_handle *buf; + enum pipe_format format = texture->format; + unsigned offset = 0; + char *map; /* We cannot map a tiled texture directly because the data is * in a different order, therefore we do detiling using a blit. @@ -316,7 +322,6 @@ static struct pipe_transfer* si_texture_get_transfer(struct pipe_context *ctx, } trans->transfer.stride = rtex->flushed_depth_texture->surface.level[level].pitch_bytes; trans->offset = r600_texture_get_offset(rtex->flushed_depth_texture, level, box->z); - return &trans->transfer; } else if (use_staging_texture) { resource.target = PIPE_TEXTURE_2D; resource.format = texture->format; @@ -355,66 +360,35 @@ static struct pipe_transfer* si_texture_get_transfer(struct pipe_context *ctx, /* Always referenced in the blit. */ radeonsi_flush(ctx, NULL, 0); } - return &trans->transfer; - } - trans->transfer.stride = rtex->surface.level[level].pitch_bytes; - trans->transfer.layer_stride = rtex->surface.level[level].slice_size; - trans->offset = r600_texture_get_offset(rtex, level, box->z); - return &trans->transfer; -} - -static void si_texture_transfer_destroy(struct pipe_context *ctx, - struct pipe_transfer *transfer) -{ - struct r600_transfer *rtransfer = (struct r600_transfer*)transfer; - struct pipe_resource *texture = transfer->resource; - struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; - - if (rtransfer->staging_texture) { - if (transfer->usage & PIPE_TRANSFER_WRITE) { - r600_copy_from_staging_texture(ctx, rtransfer); - } - pipe_resource_reference(&rtransfer->staging_texture, NULL); - } - - if (rtex->depth && !rtex->is_flushing_texture) { - if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtex->flushed_depth_texture) - r600_blit_push_depth(ctx, rtex); + } else { + trans->transfer.stride = rtex->surface.level[level].pitch_bytes; + trans->transfer.layer_stride = rtex->surface.level[level].slice_size; + trans->offset = r600_texture_get_offset(rtex, level, box->z); } - pipe_resource_reference(&transfer->resource, NULL); - FREE(transfer); -} - -static void* si_texture_transfer_map(struct pipe_context *ctx, - struct pipe_transfer* transfer) -{ - struct r600_context *rctx = (struct r600_context *)ctx; - struct r600_transfer *rtransfer = (struct r600_transfer*)transfer; - struct radeon_winsys_cs_handle *buf; - enum pipe_format format = transfer->resource->format; - unsigned offset = 0; - char *map; - - if (rtransfer->staging_texture) { - buf = si_resource(rtransfer->staging_texture)->cs_buf; + if (trans->staging_texture) { + buf = si_resource(trans->staging_texture)->cs_buf; } else { - struct r600_resource_texture *rtex = (struct r600_resource_texture*)transfer->resource; + struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; if (rtex->flushed_depth_texture) buf = rtex->flushed_depth_texture->resource.cs_buf; else - buf = si_resource(transfer->resource)->cs_buf; + buf = si_resource(texture)->cs_buf; - offset = rtransfer->offset + - transfer->box.y / util_format_get_blockheight(format) * transfer->stride + - transfer->box.x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + offset = trans->offset + + box->y / util_format_get_blockheight(format) * trans->transfer.stride + + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); } - if (!(map = rctx->ws->buffer_map(buf, rctx->cs, transfer->usage))) { + if (!(map = rctx->ws->buffer_map(buf, rctx->cs, usage))) { + pipe_resource_reference(&trans->staging_texture, NULL); + pipe_resource_reference(&trans->transfer.resource, NULL); + FREE(trans); return NULL; } + *ptransfer = &trans->transfer; return map + offset; } @@ -424,6 +398,8 @@ static void si_texture_transfer_unmap(struct pipe_context *ctx, struct r600_transfer *rtransfer = (struct r600_transfer*)transfer; struct r600_context *rctx = (struct r600_context*)ctx; struct radeon_winsys_cs_handle *buf; + struct pipe_resource *texture = transfer->resource; + struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture; if (rtransfer->staging_texture) { buf = si_resource(rtransfer->staging_texture)->cs_buf; @@ -437,14 +413,27 @@ static void si_texture_transfer_unmap(struct pipe_context *ctx, } } rctx->ws->buffer_unmap(buf); + + if (rtransfer->staging_texture) { + if (transfer->usage & PIPE_TRANSFER_WRITE) { + r600_copy_from_staging_texture(ctx, rtransfer); + } + pipe_resource_reference(&rtransfer->staging_texture, NULL); + } + + if (rtex->depth && !rtex->is_flushing_texture) { + if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtex->flushed_depth_texture) + r600_blit_push_depth(ctx, rtex); + } + + pipe_resource_reference(&transfer->resource, NULL); + FREE(transfer); } static const struct u_resource_vtbl r600_texture_vtbl = { r600_texture_get_handle, /* get_handle */ r600_texture_destroy, /* resource_destroy */ - si_texture_get_transfer, /* get_transfer */ - si_texture_transfer_destroy, /* transfer_destroy */ si_texture_transfer_map, /* transfer_map */ u_default_transfer_flush_region,/* transfer_flush_region */ si_texture_transfer_unmap, /* transfer_unmap */ |