aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/radeonsi
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2012-10-08 04:06:42 +0200
committerMarek Olšák <[email protected]>2012-10-11 21:12:16 +0200
commit369e46888904c6d379b8b477d9242cff1608e30e (patch)
tree528b10f900f23af3acd22a0edcf50fde0eeee86e /src/gallium/drivers/radeonsi
parentec4c74a9dc10039d97ad24c4f16bd2400517991d (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')
-rw-r--r--src/gallium/drivers/radeonsi/r600_buffer.c53
-rw-r--r--src/gallium/drivers/radeonsi/r600_resource.c2
-rw-r--r--src/gallium/drivers/radeonsi/r600_texture.c99
3 files changed, 63 insertions, 91 deletions
diff --git a/src/gallium/drivers/radeonsi/r600_buffer.c b/src/gallium/drivers/radeonsi/r600_buffer.c
index ec9d87e4866..7fae048d1f5 100644
--- a/src/gallium/drivers/radeonsi/r600_buffer.c
+++ b/src/gallium/drivers/radeonsi/r600_buffer.c
@@ -46,15 +46,24 @@ static void r600_buffer_destroy(struct pipe_screen *screen,
FREE(rbuffer);
}
-static struct pipe_transfer *r600_get_transfer(struct pipe_context *ctx,
- struct pipe_resource *resource,
- unsigned level,
- unsigned usage,
- const struct pipe_box *box)
+static void *r600_buffer_transfer_map(struct pipe_context *ctx,
+ struct pipe_resource *resource,
+ unsigned level,
+ unsigned usage,
+ const struct pipe_box *box,
+ struct pipe_transfer **ptransfer)
{
struct r600_context *rctx = (struct r600_context*)ctx;
- struct pipe_transfer *transfer = util_slab_alloc(&rctx->pool_transfers);
+ struct pipe_transfer *transfer;
+ struct si_resource *rbuffer = si_resource(resource);
+ uint8_t *data;
+ data = rctx->ws->buffer_map(rbuffer->cs_buf, rctx->cs, usage);
+ if (!data) {
+ return NULL;
+ }
+
+ transfer = util_slab_alloc(&rctx->pool_transfers);
transfer->resource = resource;
transfer->level = level;
transfer->usage = usage;
@@ -62,31 +71,16 @@ static struct pipe_transfer *r600_get_transfer(struct pipe_context *ctx,
transfer->stride = 0;
transfer->layer_stride = 0;
transfer->data = NULL;
-
- /* Note strides are zero, this is ok for buffers, but not for
- * textures 2d & higher at least.
- */
- return transfer;
-}
-
-static void *r600_buffer_transfer_map(struct pipe_context *pipe,
- struct pipe_transfer *transfer)
-{
- struct si_resource *rbuffer = si_resource(transfer->resource);
- struct r600_context *rctx = (struct r600_context*)pipe;
- uint8_t *data;
-
- data = rctx->ws->buffer_map(rbuffer->cs_buf, rctx->cs, transfer->usage);
- if (!data)
- return NULL;
+ *ptransfer = transfer;
return (uint8_t*)data + transfer->box.x;
}
-static void r600_buffer_transfer_unmap(struct pipe_context *pipe,
+static void r600_buffer_transfer_unmap(struct pipe_context *ctx,
struct pipe_transfer *transfer)
{
- /* no-op */
+ struct r600_context *rctx = (struct r600_context*)ctx;
+ util_slab_free(&rctx->pool_transfers, transfer);
}
static void r600_buffer_transfer_flush_region(struct pipe_context *pipe,
@@ -95,19 +89,10 @@ static void r600_buffer_transfer_flush_region(struct pipe_context *pipe,
{
}
-static void r600_transfer_destroy(struct pipe_context *ctx,
- struct pipe_transfer *transfer)
-{
- struct r600_context *rctx = (struct r600_context*)ctx;
- util_slab_free(&rctx->pool_transfers, transfer);
-}
-
static const struct u_resource_vtbl r600_buffer_vtbl =
{
u_default_resource_get_handle, /* get_handle */
r600_buffer_destroy, /* resource_destroy */
- r600_get_transfer, /* get_transfer */
- r600_transfer_destroy, /* transfer_destroy */
r600_buffer_transfer_map, /* transfer_map */
r600_buffer_transfer_flush_region, /* transfer_flush_region */
r600_buffer_transfer_unmap, /* transfer_unmap */
diff --git a/src/gallium/drivers/radeonsi/r600_resource.c b/src/gallium/drivers/radeonsi/r600_resource.c
index a4888a703b4..33ccd003090 100644
--- a/src/gallium/drivers/radeonsi/r600_resource.c
+++ b/src/gallium/drivers/radeonsi/r600_resource.c
@@ -54,10 +54,8 @@ void r600_init_screen_resource_functions(struct pipe_screen *screen)
void r600_init_context_resource_functions(struct r600_context *r600)
{
- r600->context.get_transfer = u_get_transfer_vtbl;
r600->context.transfer_map = u_transfer_map_vtbl;
r600->context.transfer_flush_region = u_transfer_flush_region_vtbl;
r600->context.transfer_unmap = u_transfer_unmap_vtbl;
- r600->context.transfer_destroy = u_transfer_destroy_vtbl;
r600->context.transfer_inline_write = u_default_transfer_inline_write;
}
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 */