diff options
author | Michel Dänzer <[email protected]> | 2009-03-04 11:58:48 +0100 |
---|---|---|
committer | Michel Dänzer <[email protected]> | 2009-03-04 11:58:48 +0100 |
commit | 5e27cd46c04a9e7b5904cc014bffd0f4daae31fe (patch) | |
tree | a57289f14d69f1977dfaee592af908052d726b8c /src/gallium/drivers/trace | |
parent | 60041203d5847de8ab71842a6ce5d33d96cc4930 (diff) |
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().
Diffstat (limited to 'src/gallium/drivers/trace')
-rw-r--r-- | src/gallium/drivers/trace/tr_screen.c | 122 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_state.c | 12 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_texture.c | 4 | ||||
-rw-r--r-- | src/gallium/drivers/trace/tr_winsys.c | 8 |
4 files changed, 48 insertions, 98 deletions
diff --git a/src/gallium/drivers/trace/tr_screen.c b/src/gallium/drivers/trace/tr_screen.c index 164c6bbc4d6..1d868eff6bb 100644 --- a/src/gallium/drivers/trace/tr_screen.c +++ b/src/gallium/drivers/trace/tr_screen.c @@ -207,37 +207,18 @@ trace_screen_texture_blanket(struct pipe_screen *_screen, static void -trace_screen_texture_release(struct pipe_screen *_screen, - struct pipe_texture **ptexture) +trace_screen_texture_destroy(struct pipe_texture *texture) { - struct trace_screen *tr_scr = trace_screen(_screen); - struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct pipe_texture *texture; - - assert(ptexture); - if(*ptexture) { - tr_tex = trace_texture(tr_scr, *ptexture); - texture = tr_tex->texture; - assert(texture->screen == screen); - } - else - texture = NULL; - - if (*ptexture) { - if (!--(*ptexture)->refcount) { - trace_dump_call_begin("pipe_screen", "texture_destroy"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, texture); - - trace_texture_destroy(tr_scr, *ptexture); - - trace_dump_call_end(); - } + struct pipe_screen *screen = texture->screen; - *ptexture = NULL; - } + trace_dump_call_begin("pipe_screen", "texture_destroy"); + + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, texture); + + trace_texture_destroy(trace_screen(screen), texture); + + trace_dump_call_end(); } @@ -280,38 +261,19 @@ trace_screen_get_tex_surface(struct pipe_screen *_screen, static void -trace_screen_tex_surface_release(struct pipe_screen *_screen, - struct pipe_surface **psurface) +trace_screen_tex_surface_destroy(struct pipe_surface *surface) { - struct trace_screen *tr_scr = trace_screen(_screen); - struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct trace_surface *tr_surf; - struct pipe_surface *surface; - - assert(psurface); - if(*psurface) { - tr_tex = trace_texture(tr_scr, (*psurface)->texture); - tr_surf = trace_surface(tr_tex, *psurface); - surface = tr_surf->surface; - } - else - surface = NULL; + struct pipe_screen *screen = surface->texture->screen; - if (*psurface) { - if (!--(*psurface)->refcount) { - trace_dump_call_begin("pipe_screen", "tex_surface_destroy"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, surface); + trace_dump_call_begin("pipe_screen", "tex_surface_destroy"); - trace_surface_destroy(tr_tex, *psurface); + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, surface); - trace_dump_call_end(); - } - - *psurface = NULL; - } + trace_surface_destroy(trace_texture(trace_screen(screen), surface->texture), + surface); + + trace_dump_call_end(); } @@ -356,38 +318,20 @@ trace_screen_get_tex_transfer(struct pipe_screen *_screen, static void -trace_screen_tex_transfer_release(struct pipe_screen *_screen, - struct pipe_transfer **ptransfer) +trace_screen_tex_transfer_destroy(struct pipe_transfer *transfer) { - struct trace_screen *tr_scr = trace_screen(_screen); - struct pipe_screen *screen = tr_scr->screen; - struct trace_texture *tr_tex; - struct trace_transfer *tr_trans; - struct pipe_transfer *transfer; - - assert(ptransfer); - if(*ptransfer) { - tr_tex = trace_texture(tr_scr, (*ptransfer)->texture); - tr_trans = trace_transfer(tr_tex, *ptransfer); - transfer = tr_trans->transfer; - } - else - transfer = NULL; - - if (*ptransfer) { - if (!--(*ptransfer)->refcount) { - trace_dump_call_begin("pipe_screen", "tex_transfer_destroy"); - - trace_dump_arg(ptr, screen); - trace_dump_arg(ptr, transfer); + struct pipe_texture *texture = transfer->texture; + struct pipe_screen *screen = texture->screen; - trace_transfer_destroy(tr_tex, *ptransfer); + trace_dump_call_begin("pipe_screen", "tex_transfer_destroy"); - trace_dump_call_end(); - } - - *ptransfer = NULL; - } + trace_dump_arg(ptr, screen); + trace_dump_arg(ptr, transfer); + + trace_transfer_destroy(trace_texture(trace_screen(screen), texture), + transfer); + + trace_dump_call_end(); } @@ -509,11 +453,11 @@ trace_screen_create(struct pipe_screen *screen) tr_scr->base.is_format_supported = trace_screen_is_format_supported; tr_scr->base.texture_create = trace_screen_texture_create; tr_scr->base.texture_blanket = trace_screen_texture_blanket; - tr_scr->base.texture_release = trace_screen_texture_release; + tr_scr->base.texture_destroy = trace_screen_texture_destroy; tr_scr->base.get_tex_surface = trace_screen_get_tex_surface; - tr_scr->base.tex_surface_release = trace_screen_tex_surface_release; + tr_scr->base.tex_surface_destroy = trace_screen_tex_surface_destroy; tr_scr->base.get_tex_transfer = trace_screen_get_tex_transfer; - tr_scr->base.tex_transfer_release = trace_screen_tex_transfer_release; + tr_scr->base.tex_transfer_destroy = trace_screen_tex_transfer_destroy; tr_scr->base.transfer_map = trace_screen_transfer_map; tr_scr->base.transfer_unmap = trace_screen_transfer_unmap; diff --git a/src/gallium/drivers/trace/tr_state.c b/src/gallium/drivers/trace/tr_state.c index 81a9e2376e0..0f175cd31ce 100644 --- a/src/gallium/drivers/trace/tr_state.c +++ b/src/gallium/drivers/trace/tr_state.c @@ -50,6 +50,14 @@ void trace_dump_block(const struct pipe_format_block *block) } +static void trace_dump_reference(const struct pipe_reference *reference) +{ + trace_dump_struct_begin("pipe_reference"); + trace_dump_member(uint, reference, count); + trace_dump_struct_end(); +} + + void trace_dump_template(const struct pipe_texture *templat) { if(!templat) { @@ -397,6 +405,8 @@ void trace_dump_surface(const struct pipe_surface *state) trace_dump_struct_begin("pipe_surface"); + trace_dump_reference(&state->reference); + trace_dump_member(format, state, format); trace_dump_member(uint, state, status); trace_dump_member(uint, state, clear_value); @@ -405,7 +415,6 @@ void trace_dump_surface(const struct pipe_surface *state) trace_dump_member(uint, state, layout); trace_dump_member(uint, state, offset); - trace_dump_member(uint, state, refcount); trace_dump_member(uint, state, usage); trace_dump_member(ptr, state, texture); @@ -437,7 +446,6 @@ void trace_dump_transfer(const struct pipe_transfer *state) trace_dump_member(uint, state, nblocksx); trace_dump_member(uint, state, nblocksy); trace_dump_member(uint, state, stride); - trace_dump_member(uint, state, refcount); trace_dump_member(uint, state, usage); trace_dump_member(ptr, state, texture); diff --git a/src/gallium/drivers/trace/tr_texture.c b/src/gallium/drivers/trace/tr_texture.c index 120ba0dd317..dc45d3dcc19 100644 --- a/src/gallium/drivers/trace/tr_texture.c +++ b/src/gallium/drivers/trace/tr_texture.c @@ -134,7 +134,7 @@ trace_transfer_create(struct trace_texture *tr_tex, return &tr_trans->base; error: - pipe_transfer_reference(&transfer, NULL); + transfer->texture->screen->tex_transfer_destroy(transfer); return NULL; } @@ -145,7 +145,7 @@ trace_transfer_destroy(struct trace_texture *tr_tex, { struct trace_transfer *tr_trans = trace_transfer(tr_tex, transfer); pipe_texture_reference(&tr_trans->base.texture, NULL); - pipe_transfer_reference(&tr_trans->transfer, NULL); + transfer->texture->screen->tex_transfer_destroy(tr_trans->transfer); FREE(tr_trans); } diff --git a/src/gallium/drivers/trace/tr_winsys.c b/src/gallium/drivers/trace/tr_winsys.c index c4148fe8104..86420bbf22a 100644 --- a/src/gallium/drivers/trace/tr_winsys.c +++ b/src/gallium/drivers/trace/tr_winsys.c @@ -295,18 +295,16 @@ trace_winsys_buffer_unmap(struct pipe_winsys *_winsys, static void -trace_winsys_buffer_destroy(struct pipe_winsys *_winsys, - struct pipe_buffer *buffer) +trace_winsys_buffer_destroy(struct pipe_buffer *buffer) { - struct trace_winsys *tr_ws = trace_winsys(_winsys); - struct pipe_winsys *winsys = tr_ws->winsys; + struct pipe_winsys *winsys = buffer->screen->winsys; trace_dump_call_begin("pipe_winsys", "buffer_destroy"); trace_dump_arg(ptr, winsys); trace_dump_arg(ptr, buffer); - winsys->buffer_destroy(winsys, buffer); + winsys->buffer_destroy(buffer); trace_dump_call_end(); } |