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/softpipe | |
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/softpipe')
-rw-r--r-- | src/gallium/drivers/softpipe/sp_context.c | 32 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_draw_arrays.c | 2 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_flush.c | 8 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_state.h | 6 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_tex_tile_cache.c | 41 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_texture.c | 88 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_tile_cache.c | 74 | ||||
-rw-r--r-- | src/gallium/drivers/softpipe/sp_tile_cache.h | 6 |
8 files changed, 74 insertions, 183 deletions
diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index 891bb261d8a..e2cc1e17dae 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -53,38 +53,6 @@ #include "sp_screen.h" -/** - * Map any drawing surfaces which aren't already mapped - */ -void -softpipe_map_transfers(struct softpipe_context *sp) -{ - unsigned i; - - for (i = 0; i < sp->framebuffer.nr_cbufs; i++) { - sp_tile_cache_map_transfers(sp->cbuf_cache[i]); - } - - sp_tile_cache_map_transfers(sp->zsbuf_cache); -} - - -/** - * Unmap any mapped drawing surfaces - */ -void -softpipe_unmap_transfers(struct softpipe_context *sp) -{ - uint i; - - for (i = 0; i < sp->framebuffer.nr_cbufs; i++) { - sp_tile_cache_unmap_transfers(sp->cbuf_cache[i]); - } - - sp_tile_cache_unmap_transfers(sp->zsbuf_cache); -} - - static void softpipe_destroy( struct pipe_context *pipe ) { diff --git a/src/gallium/drivers/softpipe/sp_draw_arrays.c b/src/gallium/drivers/softpipe/sp_draw_arrays.c index f9fc923a184..59226fb9c15 100644 --- a/src/gallium/drivers/softpipe/sp_draw_arrays.c +++ b/src/gallium/drivers/softpipe/sp_draw_arrays.c @@ -73,8 +73,6 @@ softpipe_draw_vbo(struct pipe_context *pipe, softpipe_update_derived(sp, sp->reduced_api_prim); } - softpipe_map_transfers(sp); - /* Map vertex buffers */ for (i = 0; i < sp->num_vertex_buffers; i++) { const void *buf = sp->vertex_buffer[i].user_buffer; diff --git a/src/gallium/drivers/softpipe/sp_flush.c b/src/gallium/drivers/softpipe/sp_flush.c index 28660850d29..e28236afc50 100644 --- a/src/gallium/drivers/softpipe/sp_flush.c +++ b/src/gallium/drivers/softpipe/sp_flush.c @@ -75,14 +75,6 @@ softpipe_flush( struct pipe_context *pipe, softpipe->dirty_render_cache = FALSE; - /* Need this call for hardware buffers before swapbuffers. - * - * there should probably be another/different flush-type function - * that's called before swapbuffers because we don't always want - * to unmap surfaces when flushing. - */ - softpipe_unmap_transfers(softpipe); - /* Enable to dump BMPs of the color/depth buffers each frame */ #if 0 if(flags & PIPE_FLUSH_FRAME) { diff --git a/src/gallium/drivers/softpipe/sp_state.h b/src/gallium/drivers/softpipe/sp_state.h index 6df40c66394..eb85b0689ea 100644 --- a/src/gallium/drivers/softpipe/sp_state.h +++ b/src/gallium/drivers/softpipe/sp_state.h @@ -159,12 +159,6 @@ softpipe_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info); void -softpipe_map_transfers(struct softpipe_context *sp); - -void -softpipe_unmap_transfers(struct softpipe_context *sp); - -void softpipe_map_texture_surfaces(struct softpipe_context *sp); void diff --git a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c index 7e1ac6c88fd..b6a848bc5a7 100644 --- a/src/gallium/drivers/softpipe/sp_tex_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tex_tile_cache.c @@ -74,10 +74,10 @@ sp_destroy_tex_tile_cache(struct softpipe_tex_tile_cache *tc) /*assert(tc->entries[pos].x < 0);*/ } if (tc->transfer) { - tc->pipe->transfer_destroy(tc->pipe, tc->transfer); + tc->pipe->transfer_unmap(tc->pipe, tc->transfer); } if (tc->tex_trans) { - tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans); + tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans); } FREE( tc ); @@ -131,14 +131,10 @@ sp_tex_tile_cache_set_sampler_view(struct softpipe_tex_tile_cache *tc, if (!sp_tex_tile_is_compat_view(tc, view)) { pipe_resource_reference(&tc->texture, texture); - if (tc->tex_trans) { - if (tc->tex_trans_map) { - tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans); - tc->tex_trans_map = NULL; - } - - tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans); + if (tc->tex_trans_map) { + tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans); tc->tex_trans = NULL; + tc->tex_trans_map = NULL; } if (view) { @@ -236,14 +232,10 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, /* get new transfer (view into texture) */ unsigned width, height, layer; - if (tc->tex_trans) { - if (tc->tex_trans_map) { - tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans); - tc->tex_trans_map = NULL; - } - - tc->pipe->transfer_destroy(tc->pipe, tc->tex_trans); + if (tc->tex_trans_map) { + tc->pipe->transfer_unmap(tc->pipe, tc->tex_trans); tc->tex_trans = NULL; + tc->tex_trans_map = NULL; } width = u_minify(tc->texture->width0, addr.bits.level); @@ -256,14 +248,12 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, layer = addr.bits.face + addr.bits.z; } - tc->tex_trans = - pipe_get_transfer(tc->pipe, tc->texture, + tc->tex_trans_map = + pipe_transfer_map(tc->pipe, tc->texture, addr.bits.level, layer, PIPE_TRANSFER_READ | PIPE_TRANSFER_UNSYNCHRONIZED, - 0, 0, width, height); - - tc->tex_trans_map = tc->pipe->transfer_map(tc->pipe, tc->tex_trans); + 0, 0, width, height, &tc->tex_trans); tc->tex_face = addr.bits.face; tc->tex_level = addr.bits.level; @@ -274,8 +264,7 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, * the image format. */ if (!zs && util_format_is_pure_uint(tc->format)) { - pipe_get_tile_ui_format(tc->pipe, - tc->tex_trans, + pipe_get_tile_ui_format(tc->tex_trans, tc->tex_trans_map, addr.bits.x * TILE_SIZE, addr.bits.y * TILE_SIZE, TILE_SIZE, @@ -283,8 +272,7 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, tc->format, (unsigned *) tile->data.colorui); } else if (!zs && util_format_is_pure_sint(tc->format)) { - pipe_get_tile_i_format(tc->pipe, - tc->tex_trans, + pipe_get_tile_i_format(tc->tex_trans, tc->tex_trans_map, addr.bits.x * TILE_SIZE, addr.bits.y * TILE_SIZE, TILE_SIZE, @@ -292,8 +280,7 @@ sp_find_cached_tile_tex(struct softpipe_tex_tile_cache *tc, tc->format, (int *) tile->data.colori); } else { - pipe_get_tile_rgba_format(tc->pipe, - tc->tex_trans, + pipe_get_tile_rgba_format(tc->tex_trans, tc->tex_trans_map, addr.bits.x * TILE_SIZE, addr.bits.y * TILE_SIZE, TILE_SIZE, diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 50137fe6227..b4bca076bda 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -331,15 +331,22 @@ softpipe_surface_destroy(struct pipe_context *pipe, * \param usage bitmask of PIPE_TRANSFER_x flags * \param box the 1D/2D/3D region of interest */ -static struct pipe_transfer * -softpipe_get_transfer(struct pipe_context *pipe, +static void * +softpipe_transfer_map(struct pipe_context *pipe, struct pipe_resource *resource, unsigned level, unsigned usage, - const struct pipe_box *box) + const struct pipe_box *box, + struct pipe_transfer **transfer) { + struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys; struct softpipe_resource *spr = softpipe_resource(resource); struct softpipe_transfer *spt; + struct pipe_transfer *pt; + enum pipe_format format = resource->format; + const unsigned hgt = u_minify(spr->base.height0, level); + const unsigned nblocksy = util_format_get_nblocksy(format, hgt); + uint8_t *map; assert(resource); assert(level <= resource->last_level); @@ -384,69 +391,41 @@ softpipe_get_transfer(struct pipe_context *pipe, } spt = CALLOC_STRUCT(softpipe_transfer); - if (spt) { - struct pipe_transfer *pt = &spt->base; - enum pipe_format format = resource->format; - const unsigned hgt = u_minify(spr->base.height0, level); - const unsigned nblocksy = util_format_get_nblocksy(format, hgt); - - pipe_resource_reference(&pt->resource, resource); - pt->level = level; - pt->usage = usage; - pt->box = *box; - pt->stride = spr->stride[level]; - pt->layer_stride = pt->stride * nblocksy; - - spt->offset = sp_get_tex_image_offset(spr, level, box->z); - - spt->offset += - box->y / util_format_get_blockheight(format) * spt->base.stride + - box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); + if (!spt) + return NULL; - return pt; - } - return NULL; -} + pt = &spt->base; + pipe_resource_reference(&pt->resource, resource); + pt->level = level; + pt->usage = usage; + pt->box = *box; + pt->stride = spr->stride[level]; + pt->layer_stride = pt->stride * nblocksy; -/** - * Free a pipe_transfer object which was created with - * softpipe_get_transfer(). - */ -static void -softpipe_transfer_destroy(struct pipe_context *pipe, - struct pipe_transfer *transfer) -{ - pipe_resource_reference(&transfer->resource, NULL); - FREE(transfer); -} + spt->offset = sp_get_tex_image_offset(spr, level, box->z); + spt->offset += + box->y / util_format_get_blockheight(format) * spt->base.stride + + box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format); -/** - * Create memory mapping for given pipe_transfer object. - */ -static void * -softpipe_transfer_map(struct pipe_context *pipe, - struct pipe_transfer *transfer) -{ - struct softpipe_transfer *spt = softpipe_transfer(transfer); - struct softpipe_resource *spr = softpipe_resource(transfer->resource); - struct sw_winsys *winsys = softpipe_screen(pipe->screen)->winsys; - uint8_t *map; - /* resources backed by display target treated specially: */ if (spr->dt) { - map = winsys->displaytarget_map(winsys, spr->dt, transfer->usage); + map = winsys->displaytarget_map(winsys, spr->dt, usage); } else { map = spr->data; } - if (map == NULL) + if (map == NULL) { + pipe_resource_reference(&pt->resource, NULL); + FREE(spt); return NULL; - else - return map + spt->offset; + } + + *transfer = pt; + return map + spt->offset; } @@ -472,6 +451,9 @@ softpipe_transfer_unmap(struct pipe_context *pipe, /* Mark the texture as dirty to expire the tile caches. */ spr->timestamp++; } + + pipe_resource_reference(&transfer->resource, NULL); + FREE(transfer); } /** @@ -509,8 +491,6 @@ softpipe_user_buffer_create(struct pipe_screen *screen, void softpipe_init_texture_funcs(struct pipe_context *pipe) { - pipe->get_transfer = softpipe_get_transfer; - pipe->transfer_destroy = softpipe_transfer_destroy; pipe->transfer_map = softpipe_transfer_map; pipe->transfer_unmap = softpipe_transfer_unmap; diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.c b/src/gallium/drivers/softpipe/sp_tile_cache.c index 659ac58e5b0..8d581112fcd 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c @@ -141,7 +141,7 @@ sp_destroy_tile_cache(struct softpipe_tile_cache *tc) FREE( tc->tile ); if (tc->transfer) { - tc->pipe->transfer_destroy(tc->pipe, tc->transfer); + tc->pipe->transfer_unmap(tc->pipe, tc->transfer); } FREE( tc ); @@ -158,27 +158,24 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, { struct pipe_context *pipe = tc->pipe; - if (tc->transfer) { + if (tc->transfer_map) { if (ps == tc->surface) return; - if (tc->transfer_map) { - pipe->transfer_unmap(pipe, tc->transfer); - tc->transfer_map = NULL; - } - - pipe->transfer_destroy(pipe, tc->transfer); + pipe->transfer_unmap(pipe, tc->transfer); tc->transfer = NULL; + tc->transfer_map = NULL; } tc->surface = ps; if (ps) { - tc->transfer = pipe_get_transfer(pipe, ps->texture, - ps->u.tex.level, ps->u.tex.first_layer, - PIPE_TRANSFER_READ_WRITE | - PIPE_TRANSFER_UNSYNCHRONIZED, - 0, 0, ps->width, ps->height); + tc->transfer_map = pipe_transfer_map(pipe, ps->texture, + ps->u.tex.level, ps->u.tex.first_layer, + PIPE_TRANSFER_READ_WRITE | + PIPE_TRANSFER_UNSYNCHRONIZED, + 0, 0, ps->width, ps->height, + &tc->transfer); tc->depth_stencil = util_format_is_depth_or_stencil(ps->format); } @@ -195,24 +192,6 @@ sp_tile_cache_get_surface(struct softpipe_tile_cache *tc) } -void -sp_tile_cache_map_transfers(struct softpipe_tile_cache *tc) -{ - if (tc->transfer && !tc->transfer_map) - tc->transfer_map = tc->pipe->transfer_map(tc->pipe, tc->transfer); -} - - -void -sp_tile_cache_unmap_transfers(struct softpipe_tile_cache *tc) -{ - if (tc->transfer_map) { - tc->pipe->transfer_unmap(tc->pipe, tc->transfer); - tc->transfer_map = NULL; - } -} - - /** * Set pixels in a tile to the given clear color/value, float. */ @@ -349,24 +328,23 @@ sp_tile_cache_flush_clear(struct softpipe_tile_cache *tc) if (is_clear_flag_set(tc->clear_flags, addr)) { /* write the scratch tile to the surface */ if (tc->depth_stencil) { - pipe_put_tile_raw(tc->pipe, - pt, + pipe_put_tile_raw(pt, tc->transfer_map, x, y, TILE_SIZE, TILE_SIZE, tc->tile->data.any, 0/*STRIDE*/); } else { if (util_format_is_pure_uint(tc->surface->format)) { - pipe_put_tile_ui_format(tc->pipe, pt, + pipe_put_tile_ui_format(pt, tc->transfer_map, x, y, TILE_SIZE, TILE_SIZE, pt->resource->format, (unsigned *) tc->tile->data.colorui128); } else if (util_format_is_pure_sint(tc->surface->format)) { - pipe_put_tile_i_format(tc->pipe, pt, + pipe_put_tile_i_format(pt, tc->transfer_map, x, y, TILE_SIZE, TILE_SIZE, pt->resource->format, (int *) tc->tile->data.colori128); } else { - pipe_put_tile_rgba(tc->pipe, pt, + pipe_put_tile_rgba(pt, tc->transfer_map, x, y, TILE_SIZE, TILE_SIZE, (float *) tc->tile->data.color); } @@ -389,7 +367,7 @@ sp_flush_tile(struct softpipe_tile_cache* tc, unsigned pos) { if (!tc->tile_addrs[pos].bits.invalid) { if (tc->depth_stencil) { - pipe_put_tile_raw(tc->pipe, tc->transfer, + pipe_put_tile_raw(tc->transfer, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, @@ -397,21 +375,21 @@ sp_flush_tile(struct softpipe_tile_cache* tc, unsigned pos) } else { if (util_format_is_pure_uint(tc->surface->format)) { - pipe_put_tile_ui_format(tc->pipe, tc->transfer, + pipe_put_tile_ui_format(tc->transfer, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, tc->surface->format, (unsigned *) tc->entries[pos]->data.colorui128); } else if (util_format_is_pure_sint(tc->surface->format)) { - pipe_put_tile_i_format(tc->pipe, tc->transfer, + pipe_put_tile_i_format(tc->transfer, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, tc->surface->format, (int *) tc->entries[pos]->data.colori128); } else { - pipe_put_tile_rgba_format(tc->pipe, tc->transfer, + pipe_put_tile_rgba_format(tc->transfer, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, @@ -516,7 +494,7 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc, if (tc->tile_addrs[pos].bits.invalid == 0) { /* put dirty tile back in framebuffer */ if (tc->depth_stencil) { - pipe_put_tile_raw(tc->pipe, pt, + pipe_put_tile_raw(pt, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, @@ -524,21 +502,21 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc, } else { if (util_format_is_pure_uint(tc->surface->format)) { - pipe_put_tile_ui_format(tc->pipe, pt, + pipe_put_tile_ui_format(pt, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, tc->surface->format, (unsigned *) tile->data.colorui128); } else if (util_format_is_pure_sint(tc->surface->format)) { - pipe_put_tile_i_format(tc->pipe, pt, + pipe_put_tile_i_format(pt, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, tc->surface->format, (int *) tile->data.colori128); } else { - pipe_put_tile_rgba_format(tc->pipe, pt, + pipe_put_tile_rgba_format(pt, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, @@ -563,7 +541,7 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc, else { /* get new tile data from transfer */ if (tc->depth_stencil) { - pipe_get_tile_raw(tc->pipe, pt, + pipe_get_tile_raw(pt, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, @@ -571,21 +549,21 @@ sp_find_cached_tile(struct softpipe_tile_cache *tc, } else { if (util_format_is_pure_uint(tc->surface->format)) { - pipe_get_tile_ui_format(tc->pipe, pt, + pipe_get_tile_ui_format(pt, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, tc->surface->format, (unsigned *) tile->data.colorui128); } else if (util_format_is_pure_sint(tc->surface->format)) { - pipe_get_tile_i_format(tc->pipe, pt, + pipe_get_tile_i_format(pt, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, tc->surface->format, (int *) tile->data.colori128); } else { - pipe_get_tile_rgba_format(tc->pipe, pt, + pipe_get_tile_rgba_format(pt, tc->transfer_map, tc->tile_addrs[pos].bits.x * TILE_SIZE, tc->tile_addrs[pos].bits.y * TILE_SIZE, TILE_SIZE, TILE_SIZE, diff --git a/src/gallium/drivers/softpipe/sp_tile_cache.h b/src/gallium/drivers/softpipe/sp_tile_cache.h index 775676b4bf5..8d0466b8191 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.h +++ b/src/gallium/drivers/softpipe/sp_tile_cache.h @@ -113,12 +113,6 @@ extern struct pipe_surface * sp_tile_cache_get_surface(struct softpipe_tile_cache *tc); extern void -sp_tile_cache_map_transfers(struct softpipe_tile_cache *tc); - -extern void -sp_tile_cache_unmap_transfers(struct softpipe_tile_cache *tc); - -extern void sp_flush_tile_cache(struct softpipe_tile_cache *tc); extern void |