From 5e27cd46c04a9e7b5904cc014bffd0f4daae31fe Mon Sep 17 00:00:00 2001 From: Michel Dänzer Date: Wed, 4 Mar 2009 11:58:48 +0100 Subject: gallium: Unify reference counting. The core reference counting code is centralized in p_refcnt.h. This has some consequences related to struct pipe_buffer: * The screen member of struct pipe_buffer must be initialized, or pipe_buffer_reference() will crash trying to destroy a buffer with reference count 0. u_simple_screen takes care of this, but I may have missed some of the drivers not using it. * Except for rare exceptions deep in winsys code, buffers must always be allocated via pipe_buffer_create() or via screen->*buffer_create() rather than via winsys->*buffer_create(). --- src/gallium/drivers/softpipe/sp_context.c | 3 +- src/gallium/drivers/softpipe/sp_state_fs.c | 4 +- src/gallium/drivers/softpipe/sp_texture.c | 76 ++++++++++------------------ src/gallium/drivers/softpipe/sp_tile_cache.c | 14 ++--- 4 files changed, 37 insertions(+), 60 deletions(-) (limited to 'src/gallium/drivers/softpipe') diff --git a/src/gallium/drivers/softpipe/sp_context.c b/src/gallium/drivers/softpipe/sp_context.c index ff5d1b54a4c..cc552c4915b 100644 --- a/src/gallium/drivers/softpipe/sp_context.c +++ b/src/gallium/drivers/softpipe/sp_context.c @@ -87,7 +87,6 @@ softpipe_unmap_transfers(struct softpipe_context *sp) static void softpipe_destroy( struct pipe_context *pipe ) { struct softpipe_context *softpipe = softpipe_context( pipe ); - struct pipe_screen *screen = pipe->screen; uint i; if (softpipe->draw) @@ -116,7 +115,7 @@ static void softpipe_destroy( struct pipe_context *pipe ) for (i = 0; i < Elements(softpipe->constants); i++) { if (softpipe->constants[i].buffer) { - pipe_buffer_reference(screen, &softpipe->constants[i].buffer, NULL); + pipe_buffer_reference(&softpipe->constants[i].buffer, NULL); } } diff --git a/src/gallium/drivers/softpipe/sp_state_fs.c b/src/gallium/drivers/softpipe/sp_state_fs.c index 4d01a9dbe15..957c8b72e48 100644 --- a/src/gallium/drivers/softpipe/sp_state_fs.c +++ b/src/gallium/drivers/softpipe/sp_state_fs.c @@ -146,14 +146,12 @@ softpipe_set_constant_buffer(struct pipe_context *pipe, const struct pipe_constant_buffer *buf) { struct softpipe_context *softpipe = softpipe_context(pipe); - struct pipe_screen *screen = pipe->screen; assert(shader < PIPE_SHADER_TYPES); assert(index == 0); /* note: reference counting */ - pipe_buffer_reference(screen, - &softpipe->constants[shader].buffer, + pipe_buffer_reference(&softpipe->constants[shader].buffer, buf ? buf->buffer : NULL); softpipe->dirty |= SP_NEW_CONSTANTS; diff --git a/src/gallium/drivers/softpipe/sp_texture.c b/src/gallium/drivers/softpipe/sp_texture.c index 142ce230fc0..4919ec826e9 100644 --- a/src/gallium/drivers/softpipe/sp_texture.c +++ b/src/gallium/drivers/softpipe/sp_texture.c @@ -59,7 +59,6 @@ static boolean softpipe_texture_layout(struct pipe_screen *screen, struct softpipe_texture * spt) { - struct pipe_winsys *ws = screen->winsys; struct pipe_texture *pt = &spt->base; unsigned level; unsigned width = pt->width[0]; @@ -87,9 +86,9 @@ softpipe_texture_layout(struct pipe_screen *screen, depth = minify(depth); } - spt->buffer = ws->buffer_create(ws, 32, - PIPE_BUFFER_USAGE_PIXEL, - buffer_size); + spt->buffer = screen->buffer_create(screen, 32, + PIPE_BUFFER_USAGE_PIXEL, + buffer_size); return spt->buffer != NULL; } @@ -98,19 +97,18 @@ static boolean softpipe_displaytarget_layout(struct pipe_screen *screen, struct softpipe_texture * spt) { - struct pipe_winsys *ws = screen->winsys; unsigned usage = (PIPE_BUFFER_USAGE_CPU_READ_WRITE | PIPE_BUFFER_USAGE_GPU_READ_WRITE); spt->base.nblocksx[0] = pf_get_nblocksx(&spt->base.block, spt->base.width[0]); spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]); - spt->buffer = ws->surface_buffer_create( ws, - spt->base.width[0], - spt->base.height[0], - spt->base.format, - usage, - &spt->stride[0]); + spt->buffer = screen->surface_buffer_create( screen, + spt->base.width[0], + spt->base.height[0], + spt->base.format, + usage, + &spt->stride[0]); return spt->buffer != NULL; } @@ -128,7 +126,7 @@ softpipe_texture_create(struct pipe_screen *screen, return NULL; spt->base = *templat; - spt->base.refcount = 1; + pipe_reference_init(&spt->base.reference, 1); spt->base.screen = screen; if (spt->base.tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) { @@ -140,7 +138,7 @@ softpipe_texture_create(struct pipe_screen *screen, goto fail; } - assert(spt->base.refcount == 1); + assert(spt->base.reference.count == 1); return &spt->base; fail: @@ -170,32 +168,25 @@ softpipe_texture_blanket(struct pipe_screen * screen, return NULL; spt->base = *base; - spt->base.refcount = 1; + pipe_reference_init(&spt->base.reference, 1); spt->base.screen = screen; spt->base.nblocksx[0] = pf_get_nblocksx(&spt->base.block, spt->base.width[0]); spt->base.nblocksy[0] = pf_get_nblocksy(&spt->base.block, spt->base.height[0]); spt->stride[0] = stride[0]; - pipe_buffer_reference(screen, &spt->buffer, buffer); + pipe_buffer_reference(&spt->buffer, buffer); return &spt->base; } static void -softpipe_texture_release(struct pipe_screen *screen, - struct pipe_texture **pt) +softpipe_texture_destroy(struct pipe_texture *pt) { - if (!*pt) - return; - - if (--(*pt)->refcount <= 0) { - struct softpipe_texture *spt = softpipe_texture(*pt); + struct softpipe_texture *spt = softpipe_texture(pt); - pipe_buffer_reference(screen, &spt->buffer, NULL); - FREE(spt); - } - *pt = NULL; + pipe_buffer_reference(&spt->buffer, NULL); + FREE(spt); } @@ -212,7 +203,7 @@ softpipe_get_tex_surface(struct pipe_screen *screen, ps = CALLOC_STRUCT(pipe_surface); if (ps) { - ps->refcount = 1; + pipe_reference_init(&ps->reference, 1); pipe_texture_reference(&ps->texture, pt); ps->format = pt->format; ps->width = pt->width[level]; @@ -259,20 +250,15 @@ softpipe_get_tex_surface(struct pipe_screen *screen, static void -softpipe_tex_surface_release(struct pipe_screen *screen, - struct pipe_surface **s) +softpipe_tex_surface_destroy(struct pipe_surface *surf) { - struct pipe_surface *surf = *s; /* 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 softpipe, nothing to do. */ assert(surf->texture); - if (--surf->refcount == 0) { - pipe_texture_reference(&surf->texture, NULL); - FREE(surf); - } - *s = NULL; + pipe_texture_reference(&surf->texture, NULL); + FREE(surf); } @@ -292,7 +278,6 @@ softpipe_get_tex_transfer(struct pipe_screen *screen, spt = CALLOC_STRUCT(softpipe_transfer); if (spt) { struct pipe_transfer *pt = &spt->base; - pt->refcount = 1; pipe_texture_reference(&pt->texture, texture); pt->format = texture->format; pt->block = texture->block; @@ -327,20 +312,15 @@ softpipe_get_tex_transfer(struct pipe_screen *screen, static void -softpipe_tex_transfer_release(struct pipe_screen *screen, - struct pipe_transfer **t) +softpipe_tex_transfer_destroy(struct pipe_transfer *transfer) { - struct softpipe_transfer *transfer = softpipe_transfer(*t); /* 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 softpipe, nothing to do. */ - assert (transfer->base.texture); - if (--transfer->base.refcount == 0) { - pipe_texture_reference(&transfer->base.texture, NULL); - FREE(transfer); - } - *t = NULL; + assert (transfer->texture); + pipe_texture_reference(&transfer->texture, NULL); + FREE(transfer); } @@ -408,13 +388,13 @@ softpipe_init_screen_texture_funcs(struct pipe_screen *screen) { screen->texture_create = softpipe_texture_create; screen->texture_blanket = softpipe_texture_blanket; - screen->texture_release = softpipe_texture_release; + screen->texture_destroy = softpipe_texture_destroy; screen->get_tex_surface = softpipe_get_tex_surface; - screen->tex_surface_release = softpipe_tex_surface_release; + screen->tex_surface_destroy = softpipe_tex_surface_destroy; screen->get_tex_transfer = softpipe_get_tex_transfer; - screen->tex_transfer_release = softpipe_tex_transfer_release; + screen->tex_transfer_destroy = softpipe_tex_transfer_destroy; screen->transfer_map = softpipe_transfer_map; screen->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 593360aab03..51e34d0d621 100644 --- a/src/gallium/drivers/softpipe/sp_tile_cache.c +++ b/src/gallium/drivers/softpipe/sp_tile_cache.c @@ -140,11 +140,11 @@ sp_destroy_tile_cache(struct softpipe_tile_cache *tc) } if (tc->transfer) { screen = tc->transfer->texture->screen; - screen->tex_transfer_release(screen, &tc->transfer); + screen->tex_transfer_destroy(tc->transfer); } if (tc->tex_trans) { screen = tc->tex_trans->texture->screen; - screen->tex_transfer_release(screen, &tc->tex_trans); + screen->tex_transfer_destroy(tc->tex_trans); } FREE( tc ); @@ -167,11 +167,11 @@ sp_tile_cache_set_surface(struct softpipe_tile_cache *tc, return; if (tc->transfer_map) { - tc->screen->transfer_unmap(tc->screen, tc->transfer); + screen->transfer_unmap(screen, tc->transfer); tc->transfer_map = NULL; } - screen->tex_transfer_release(screen, &tc->transfer); + screen->tex_transfer_destroy(tc->transfer); } tc->surface = ps; @@ -249,11 +249,11 @@ sp_tile_cache_set_texture(struct pipe_context *pipe, struct pipe_screen *screen = tc->transfer->texture->screen; if (tc->tex_trans_map) { - tc->screen->transfer_unmap(tc->screen, tc->tex_trans); + screen->transfer_unmap(screen, tc->tex_trans); tc->tex_trans_map = NULL; } - screen->tex_transfer_release(screen, &tc->tex_trans); + screen->tex_transfer_destroy(tc->tex_trans); } /* mark as entries as invalid/empty */ @@ -559,7 +559,7 @@ sp_get_cached_tile_tex(struct softpipe_context *sp, if (tc->tex_trans_map) tc->screen->transfer_unmap(tc->screen, tc->tex_trans); - screen->tex_transfer_release(screen, &tc->tex_trans); + screen->tex_transfer_destroy(tc->tex_trans); } tc->tex_trans = screen->get_tex_transfer(screen, tc->texture, face, level, z, -- cgit v1.2.3