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/mesa | |
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/mesa')
-rw-r--r-- | src/mesa/state_tracker/st_atom_constbuf.c | 2 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_atom_pixeltransfer.c | 2 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_accum.c | 18 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_bitmap.c | 16 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_bufferobjects.c | 5 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_clear.c | 8 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_drawpixels.c | 12 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_fbo.c | 3 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_readpixels.c | 8 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_cb_texture.c | 16 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_context.c | 2 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_draw.c | 10 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_draw_feedback.c | 4 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_gen_mipmap.c | 4 | ||||
-rw-r--r-- | src/mesa/state_tracker/st_texture.c | 10 |
15 files changed, 58 insertions, 62 deletions
diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c index 2df6fef210e..fd81ac36d2c 100644 --- a/src/mesa/state_tracker/st_atom_constbuf.c +++ b/src/mesa/state_tracker/st_atom_constbuf.c @@ -73,7 +73,7 @@ void st_upload_constants( struct st_context *st, /* We always need to get a new buffer, to keep the drivers simple and * avoid gratuitous rendering synchronization. */ - pipe_buffer_reference(pipe->screen, &cbuf->buffer, NULL ); + pipe_buffer_reference(&cbuf->buffer, NULL ); cbuf->buffer = pipe_buffer_create(pipe->screen, 16, PIPE_BUFFER_USAGE_CONSTANT, paramBytes ); diff --git a/src/mesa/state_tracker/st_atom_pixeltransfer.c b/src/mesa/state_tracker/st_atom_pixeltransfer.c index 05b69c9d00a..347f2b60c38 100644 --- a/src/mesa/state_tracker/st_atom_pixeltransfer.c +++ b/src/mesa/state_tracker/st_atom_pixeltransfer.c @@ -171,7 +171,7 @@ load_color_map_texture(GLcontext *ctx, struct pipe_texture *pt) } screen->transfer_unmap(screen, transfer); - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); } diff --git a/src/mesa/state_tracker/st_cb_accum.c b/src/mesa/state_tracker/st_cb_accum.c index 15cc4cd95dc..3f9a825a153 100644 --- a/src/mesa/state_tracker/st_cb_accum.c +++ b/src/mesa/state_tracker/st_cb_accum.c @@ -149,7 +149,7 @@ st_clear_accum_buffer(GLcontext *ctx, struct gl_renderbuffer *rb) } screen->transfer_unmap(screen, acc_pt); - screen->tex_transfer_release(screen, &acc_pt); + screen->tex_transfer_destroy(acc_pt); } @@ -187,7 +187,7 @@ accum_mad(GLcontext *ctx, GLfloat scale, GLfloat bias, } screen->transfer_unmap(screen, acc_pt); - screen->tex_transfer_release(screen, &acc_pt); + screen->tex_transfer_destroy(acc_pt); } @@ -220,7 +220,7 @@ accum_accum(struct pipe_context *pipe, GLfloat value, accBuf[i] = accBuf[i] + colorBuf[i] * value; } - screen->tex_transfer_release(screen, &acc_trans); + screen->tex_transfer_destroy(acc_trans); acc_trans = screen->get_tex_transfer(screen, acc_strb->texture, 0, 0, 0, PIPE_TRANSFER_WRITE, xpos, ypos, width, height); @@ -229,8 +229,8 @@ accum_accum(struct pipe_context *pipe, GLfloat value, _mesa_free(colorBuf); _mesa_free(accBuf); - screen->tex_transfer_release(screen, &acc_trans); - screen->tex_transfer_release(screen, &color_trans); + screen->tex_transfer_destroy(acc_trans); + screen->tex_transfer_destroy(color_trans); } @@ -264,8 +264,8 @@ accum_load(struct pipe_context *pipe, GLfloat value, acc_put_tile_rgba(pipe, acc_trans, 0, 0, width, height, buf); _mesa_free(buf); - screen->tex_transfer_release(screen, &acc_trans); - screen->tex_transfer_release(screen, &color_trans); + screen->tex_transfer_destroy(acc_trans); + screen->tex_transfer_destroy(color_trans); } @@ -316,8 +316,8 @@ accum_return(GLcontext *ctx, GLfloat value, _mesa_free(abuf); if (cbuf) _mesa_free(cbuf); - screen->tex_transfer_release(screen, &acc_trans); - screen->tex_transfer_release(screen, &color_trans); + screen->tex_transfer_destroy(acc_trans); + screen->tex_transfer_destroy(color_trans); } diff --git a/src/mesa/state_tracker/st_cb_bitmap.c b/src/mesa/state_tracker/st_cb_bitmap.c index f55a5e713ff..f77ac14762f 100644 --- a/src/mesa/state_tracker/st_cb_bitmap.c +++ b/src/mesa/state_tracker/st_cb_bitmap.c @@ -351,7 +351,7 @@ make_bitmap_texture(GLcontext *ctx, GLsizei width, GLsizei height, /* Release transfer */ screen->transfer_unmap(screen, transfer); - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); return pt; } @@ -379,7 +379,7 @@ setup_bitmap_vertex_data(struct st_context *st, GLuint i; if (st->bitmap.vbuf_slot >= max_slots) { - pipe_buffer_reference(pipe->screen, &st->bitmap.vbuf, NULL); + pipe_buffer_reference(&st->bitmap.vbuf, NULL); st->bitmap.vbuf_slot = 0; } @@ -571,7 +571,7 @@ reset_cache(struct st_context *st) cache->ymax = -1000000; if (cache->trans) - screen->tex_transfer_release(screen, &cache->trans); + screen->tex_transfer_destroy(cache->trans); assert(!cache->texture); @@ -623,7 +623,7 @@ st_flush_bitmap_cache(struct st_context *st) screen->transfer_unmap(screen, cache->trans); cache->buffer = NULL; - screen->tex_transfer_release(screen, &cache->trans); + screen->tex_transfer_destroy(cache->trans); draw_bitmap_quad(st->ctx, cache->xpos, @@ -651,7 +651,7 @@ st_flush_bitmap( struct st_context *st ) /* Release vertex buffer to avoid synchronous rendering if we were * to map it in the next frame. */ - pipe_buffer_reference(st->pipe->screen, &st->bitmap.vbuf, NULL); + pipe_buffer_reference(&st->bitmap.vbuf, NULL); st->bitmap.vbuf_slot = 0; } @@ -819,7 +819,7 @@ st_destroy_bitmap(struct st_context *st) struct bitmap_cache *cache = st->bitmap.cache; screen->transfer_unmap(screen, cache->trans); - screen->tex_transfer_release(screen, &cache->trans); + screen->tex_transfer_destroy(cache->trans); if (st->bitmap.vs) { cso_delete_vertex_shader(st->cso_context, st->bitmap.vs); @@ -828,12 +828,12 @@ st_destroy_bitmap(struct st_context *st) util_free_shader(&st->bitmap.vert_shader); if (st->bitmap.vbuf) { - pipe_buffer_reference(pipe->screen, &st->bitmap.vbuf, NULL); + pipe_buffer_reference(&st->bitmap.vbuf, NULL); st->bitmap.vbuf = NULL; } if (st->bitmap.cache) { - pipe_texture_release(&st->bitmap.cache->texture); + pipe_texture_reference(&st->bitmap.cache->texture, NULL); _mesa_free(st->bitmap.cache); st->bitmap.cache = NULL; } diff --git a/src/mesa/state_tracker/st_cb_bufferobjects.c b/src/mesa/state_tracker/st_cb_bufferobjects.c index 28e387c399d..52099232ade 100644 --- a/src/mesa/state_tracker/st_cb_bufferobjects.c +++ b/src/mesa/state_tracker/st_cb_bufferobjects.c @@ -74,11 +74,10 @@ st_bufferobj_alloc(GLcontext *ctx, GLuint name, GLenum target) static void st_bufferobj_free(GLcontext *ctx, struct gl_buffer_object *obj) { - struct pipe_context *pipe = st_context(ctx)->pipe; struct st_buffer_object *st_obj = st_buffer_object(obj); if (st_obj->buffer) - pipe_buffer_reference(pipe->screen, &st_obj->buffer, NULL); + pipe_buffer_reference(&st_obj->buffer, NULL); _mesa_free(st_obj); } @@ -165,7 +164,7 @@ st_bufferobj_data(GLcontext *ctx, buffer_usage = 0; } - pipe_buffer_reference( pipe->screen, &st_obj->buffer, NULL ); + pipe_buffer_reference( &st_obj->buffer, NULL ); st_obj->buffer = pipe_buffer_create( pipe->screen, 32, buffer_usage, size ); diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index c6fc7cec27c..7d4948a64ea 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -95,8 +95,6 @@ st_init_clear(struct st_context *st) void st_destroy_clear(struct st_context *st) { - struct pipe_context *pipe = st->pipe; - if (st->clear.vert_shader.tokens) { util_free_shader(&st->clear.vert_shader); st->clear.vert_shader.tokens = NULL; @@ -116,7 +114,7 @@ st_destroy_clear(struct st_context *st) st->clear.vs = NULL; } if (st->clear.vbuf) { - pipe_buffer_reference(pipe->screen, &st->clear.vbuf, NULL); + pipe_buffer_reference(&st->clear.vbuf, NULL); st->clear.vbuf = NULL; } } @@ -152,7 +150,7 @@ draw_quad(GLcontext *ctx, GLuint i; if (st->clear.vbuf_slot >= max_slots) { - pipe_buffer_reference(pipe->screen, &st->clear.vbuf, NULL); + pipe_buffer_reference(&st->clear.vbuf, NULL); st->clear.vbuf_slot = 0; } @@ -524,7 +522,7 @@ void st_flush_clear( struct st_context *st ) /* Release vertex buffer to avoid synchronous rendering if we were * to map it in the next frame. */ - pipe_buffer_reference(st->pipe->screen, &st->clear.vbuf, NULL); + pipe_buffer_reference(&st->clear.vbuf, NULL); st->clear.vbuf_slot = 0; } diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index cc7a9e78907..0a09e7e6f19 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -392,7 +392,7 @@ make_texture(struct st_context *st, /* unmap */ screen->transfer_unmap(screen, transfer); - screen->tex_transfer_release(screen, &transfer); + screen->tex_transfer_destroy(transfer); assert(success); @@ -495,7 +495,7 @@ draw_quad(GLcontext *ctx, GLfloat x0, GLfloat y0, GLfloat z, PIPE_PRIM_QUADS, 4, /* verts */ 3); /* attribs/vert */ - pipe_buffer_reference(pipe->screen, &buf, NULL); + pipe_buffer_reference(&buf, NULL); } } @@ -808,7 +808,7 @@ draw_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ screen->transfer_unmap(screen, pt); - screen->tex_transfer_release(screen, &pt); + screen->tex_transfer_destroy(pt); } @@ -951,7 +951,7 @@ copy_stencil_pixels(GLcontext *ctx, GLint srcx, GLint srcy, /* unmap the stencil buffer */ screen->transfer_unmap(screen, ptDraw); - screen->tex_transfer_release(screen, &ptDraw); + screen->tex_transfer_destroy(ptDraw); } @@ -1070,8 +1070,8 @@ st_CopyPixels(GLcontext *ctx, GLint srcx, GLint srcy, _mesa_free(buf); } - screen->tex_transfer_release(screen, &ptRead); - screen->tex_transfer_release(screen, &ptTex); + screen->tex_transfer_destroy(ptRead); + screen->tex_transfer_destroy(ptTex); } /* draw textured quad */ diff --git a/src/mesa/state_tracker/st_cb_fbo.c b/src/mesa/state_tracker/st_cb_fbo.c index 4e669f113bf..121ca8c29a7 100644 --- a/src/mesa/state_tracker/st_cb_fbo.c +++ b/src/mesa/state_tracker/st_cb_fbo.c @@ -413,7 +413,6 @@ static void st_finish_render_texture(GLcontext *ctx, struct gl_renderbuffer_attachment *att) { - struct pipe_screen *screen = ctx->st->pipe->screen; struct st_renderbuffer *strb = st_renderbuffer(att->Renderbuffer); if (!strb) @@ -422,7 +421,7 @@ st_finish_render_texture(GLcontext *ctx, st_flush( ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL ); if (strb->surface) - screen->tex_surface_release( screen, &strb->surface ); + pipe_surface_reference( &strb->surface, NULL ); strb->rtt = NULL; diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c index 5a4a7f0a616..2a4beccd90e 100644 --- a/src/mesa/state_tracker/st_cb_readpixels.c +++ b/src/mesa/state_tracker/st_cb_readpixels.c @@ -134,7 +134,7 @@ st_read_stencil_pixels(GLcontext *ctx, GLint x, GLint y, /* unmap the stencil buffer */ screen->transfer_unmap(screen, pt); - screen->tex_transfer_release(screen, &pt); + screen->tex_transfer_destroy(pt); } @@ -224,7 +224,7 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb, map = screen->transfer_map(screen, trans); if (!map) { - screen->tex_transfer_release(screen, &trans); + screen->tex_transfer_destroy(trans); return GL_FALSE; } @@ -282,7 +282,7 @@ st_fast_readpixels(GLcontext *ctx, struct st_renderbuffer *strb, } screen->transfer_unmap(screen, trans); - screen->tex_transfer_release(screen, &trans); + screen->tex_transfer_destroy(trans); } return GL_TRUE; @@ -466,7 +466,7 @@ st_readpixels(GLcontext *ctx, GLint x, GLint y, GLsizei width, GLsizei height, } } - screen->tex_transfer_release(screen, &trans); + screen->tex_transfer_destroy(trans); _mesa_unmap_readpix_pbo(ctx, &clippedPacking); } diff --git a/src/mesa/state_tracker/st_cb_texture.c b/src/mesa/state_tracker/st_cb_texture.c index 3039eb2a877..a5044541459 100644 --- a/src/mesa/state_tracker/st_cb_texture.c +++ b/src/mesa/state_tracker/st_cb_texture.c @@ -938,12 +938,12 @@ fallback_copy_texsubimage(GLcontext *ctx, srcY = strb->Base.Height - srcY - height; } - src_trans = pipe->screen->get_tex_transfer( pipe->screen, - strb->texture, - 0, 0, 0, - PIPE_TRANSFER_READ, - srcX, srcY, - width, height); + src_trans = screen->get_tex_transfer( screen, + strb->texture, + 0, 0, 0, + PIPE_TRANSFER_READ, + srcX, srcY, + width, height); texDest = st_texture_image_map(ctx->st, stImage, 0, PIPE_TRANSFER_WRITE, destX, destY, width, height); @@ -1020,7 +1020,7 @@ fallback_copy_texsubimage(GLcontext *ctx, } st_texture_image_unmap(ctx->st, stImage); - screen->tex_transfer_release(screen, &src_trans); + screen->tex_transfer_destroy(src_trans); } @@ -1413,7 +1413,7 @@ st_finalize_texture(GLcontext *ctx, stObj->pt->depth[0] != firstImage->base.Depth2 || stObj->pt->block.size/stObj->pt->block.width != cpp || /* Nominal bytes per pixel */ stObj->pt->compressed != firstImage->base.IsCompressed) { - pipe_texture_release(&stObj->pt); + pipe_texture_reference(&stObj->pt, NULL); ctx->st->dirty.st |= ST_NEW_FRAMEBUFFER; } } diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c index 78a7956c90d..f31be690237 100644 --- a/src/mesa/state_tracker/st_context.c +++ b/src/mesa/state_tracker/st_context.c @@ -209,7 +209,7 @@ static void st_destroy_context_priv( struct st_context *st ) for (i = 0; i < Elements(st->state.constants); i++) { if (st->state.constants[i].buffer) { - pipe_buffer_reference(st->pipe->screen, &st->state.constants[i].buffer, NULL); + pipe_buffer_reference(&st->state.constants[i].buffer, NULL); } } diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index b52e4886128..be1d9a86281 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -378,7 +378,7 @@ setup_interleaved_attribs(GLcontext *ctx, } else { vbuffer->buffer = NULL; - pipe_buffer_reference(pipe->screen, &vbuffer->buffer, stobj->buffer); + pipe_buffer_reference(&vbuffer->buffer, stobj->buffer); vbuffer->buffer_offset = (unsigned) low; } vbuffer->stride = stride; /* in bytes */ @@ -433,7 +433,7 @@ setup_non_interleaved_attribs(GLcontext *ctx, /*printf("stobj %u = %p\n", attr, (void*) stobj);*/ vbuffer[attr].buffer = NULL; - pipe_buffer_reference(pipe->screen, &vbuffer[attr].buffer, stobj->buffer); + pipe_buffer_reference(&vbuffer[attr].buffer, stobj->buffer); vbuffer[attr].buffer_offset = (unsigned) arrays[mesaAttr]->Ptr; velements[attr].src_offset = 0; } @@ -617,7 +617,7 @@ st_draw_vbo(GLcontext *ctx, if (bufobj && bufobj->Name) { /* elements/indexes are in a real VBO */ struct st_buffer_object *stobj = st_buffer_object(bufobj); - pipe_buffer_reference(pipe->screen, &indexBuf, stobj->buffer); + pipe_buffer_reference(&indexBuf, stobj->buffer); indexOffset = (unsigned) ib->ptr / indexSize; } else { @@ -657,7 +657,7 @@ st_draw_vbo(GLcontext *ctx, } } - pipe_buffer_reference(pipe->screen, &indexBuf, NULL); + pipe_buffer_reference(&indexBuf, NULL); } else { /* non-indexed */ @@ -673,7 +673,7 @@ st_draw_vbo(GLcontext *ctx, /* unreference buffers (frees wrapped user-space buffer objects) */ for (attr = 0; attr < num_vbuffers; attr++) { - pipe_buffer_reference(pipe->screen, &vbuffer[attr].buffer, NULL); + pipe_buffer_reference(&vbuffer[attr].buffer, NULL); assert(!vbuffer[attr].buffer); } diff --git a/src/mesa/state_tracker/st_draw_feedback.c b/src/mesa/state_tracker/st_draw_feedback.c index 5c9c4506c22..d63d8cae28e 100644 --- a/src/mesa/state_tracker/st_draw_feedback.c +++ b/src/mesa/state_tracker/st_draw_feedback.c @@ -152,7 +152,7 @@ st_feedback_draw_vbo(GLcontext *ctx, assert(stobj->buffer); vbuffers[attr].buffer = NULL; - pipe_buffer_reference(pipe->screen, &vbuffers[attr].buffer, stobj->buffer); + pipe_buffer_reference(&vbuffers[attr].buffer, stobj->buffer); vbuffers[attr].buffer_offset = (unsigned) arrays[0]->Ptr;/* in bytes */ velements[attr].src_offset = arrays[mesaAttr]->Ptr - arrays[0]->Ptr; } @@ -248,7 +248,7 @@ st_feedback_draw_vbo(GLcontext *ctx, for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { if (draw->pt.vertex_buffer[i].buffer) { pipe_buffer_unmap(pipe->screen, draw->pt.vertex_buffer[i].buffer); - pipe_buffer_reference(pipe->screen, &draw->pt.vertex_buffer[i].buffer, NULL); + pipe_buffer_reference(&draw->pt.vertex_buffer[i].buffer, NULL); draw_set_mapped_vertex_buffer(draw, i, NULL); } } diff --git a/src/mesa/state_tracker/st_gen_mipmap.c b/src/mesa/state_tracker/st_gen_mipmap.c index 08e48030681..9cc2176d5e4 100644 --- a/src/mesa/state_tracker/st_gen_mipmap.c +++ b/src/mesa/state_tracker/st_gen_mipmap.c @@ -147,8 +147,8 @@ fallback_generate_mipmap(GLcontext *ctx, GLenum target, screen->transfer_unmap(screen, srcTrans); screen->transfer_unmap(screen, dstTrans); - screen->tex_transfer_release(screen, &srcTrans); - screen->tex_transfer_release(screen, &dstTrans); + screen->tex_transfer_destroy(srcTrans); + screen->tex_transfer_destroy(dstTrans); } } diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c index fcf76ef82e8..79a4bd84d01 100644 --- a/src/mesa/state_tracker/st_texture.c +++ b/src/mesa/state_tracker/st_texture.c @@ -108,7 +108,7 @@ st_texture_create(struct st_context *st, newtex = screen->texture_create(screen, &pt); - assert(!newtex || newtex->refcount == 1); + assert(!newtex || newtex->reference.count == 1); return newtex; } @@ -219,7 +219,7 @@ st_texture_image_unmap(struct st_context *st, screen->transfer_unmap(screen, stImage->transfer); - screen->tex_transfer_release(screen, &stImage->transfer); + screen->tex_transfer_destroy(stImage->transfer); } @@ -284,7 +284,7 @@ st_texture_image_data(struct pipe_context *pipe, 0, 0, /* source x, y */ dst->width[level], dst->height[level]); /* width, height */ - screen->tex_transfer_release(screen, &dst_transfer); + screen->tex_transfer_destroy(dst_transfer); srcUB += src_image_stride; } @@ -350,8 +350,8 @@ st_texture_image_copy(struct pipe_context *pipe, 0, 0, /* srcX, Y */ width, height); - screen->tex_surface_release(screen, &src_surface); - screen->tex_surface_release(screen, &dst_surface); + pipe_surface_reference(&src_surface, NULL); + pipe_surface_reference(&dst_surface, NULL); } } |