diff options
author | Keith Whitwell <keith@tungstengraphics.com> | 2008-01-25 20:53:31 +0000 |
---|---|---|
committer | Keith Whitwell <keith@tungstengraphics.com> | 2008-01-25 20:53:31 +0000 |
commit | 1e0d30a515e4cac891b6c590f12a33e0e8a8e295 (patch) | |
tree | 72ffec9e89bd0bd9202fcfc39f5e7bdf881adcf2 /src/mesa/pipe/pipebuffer/pb_buffer_fenced.c | |
parent | 756d52ec12c41ee90ee9598dc9028cc134806bd2 (diff) |
gallium: rename pipe_buffer_handle to pipe_buffer, rework pipebuffer/ code
Provide an actual definition of the pipe_buffer struct, containing
the parameters used to create the buffer, and its refcount.
Shift refcounting buffers out of the winsys interface, similar to
surfaces & textures.
Rework pipebuffer/ to reflect the fact these changes, and also Michel's
reworking of the buffer interface.
Diffstat (limited to 'src/mesa/pipe/pipebuffer/pb_buffer_fenced.c')
-rw-r--r-- | src/mesa/pipe/pipebuffer/pb_buffer_fenced.c | 102 |
1 files changed, 38 insertions, 64 deletions
diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c b/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c index dfb80b1dcf..625120d714 100644 --- a/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c +++ b/src/mesa/pipe/pipebuffer/pb_buffer_fenced.c @@ -72,9 +72,9 @@ struct fenced_buffer_list */ struct fenced_buffer { - struct pipe_buffer base; + struct pb_buffer base; - struct pipe_buffer *buffer; + struct pb_buffer *buffer; unsigned refcount; struct pipe_fence_handle *fence; @@ -84,8 +84,8 @@ struct fenced_buffer }; -static inline struct fenced_buffer * -fenced_buffer(struct pipe_buffer *buf) +static INLINE struct fenced_buffer * +fenced_buffer(struct pb_buffer *buf) { assert(buf); assert(buf->vtbl == &fenced_buffer_vtbl); @@ -93,12 +93,6 @@ fenced_buffer(struct pipe_buffer *buf) } -static void -_fenced_buffer_destroy(struct fenced_buffer *fenced_buf) -{ - buffer_release(fenced_buf->buffer); - free(fenced_buf); -} static void @@ -143,97 +137,81 @@ _fenced_buffer_list_check_free(struct fenced_buffer_list *fenced_list, LIST_DEL(list); fenced_list->numDelayed--; - - _fenced_buffer_destroy(fenced_buf); - } -} - -static void -fenced_buffer_reference(struct pipe_buffer *buf) -{ - struct fenced_buffer *fenced_buf = fenced_buffer(buf); - struct fenced_buffer_list *fenced_list = fenced_buf->list; - - _glthread_LOCK_MUTEX(fenced_list->mutex); - fenced_buf->refcount++; - _glthread_UNLOCK_MUTEX(fenced_list->mutex); + /* Do the delayed destroy: + */ + pb_destroy(fenced_buf->buffer); + free(fenced_buf); + } } static void -fenced_buffer_release(struct pipe_buffer *buf) +fenced_buffer_destroy(struct pb_buffer *buf) { struct fenced_buffer *fenced_buf = fenced_buffer(buf); struct fenced_buffer_list *fenced_list = fenced_buf->list; - _glthread_LOCK_MUTEX(fenced_list->mutex); - - fenced_buf->refcount--; - if(!fenced_buf->refcount) { - if (fenced_buf->fence) { - LIST_ADDTAIL(&fenced_buf->head, &fenced_list->delayed); - fenced_list->numDelayed++; - } - else { - _fenced_buffer_destroy(fenced_buf); - } - - if ((fenced_list->numDelayed % fenced_list->checkDelayed) == 0) - _fenced_buffer_list_check_free(fenced_list, 0); + if (fenced_buf->fence) { + LIST_ADDTAIL(&fenced_buf->head, &fenced_list->delayed); + fenced_list->numDelayed++; + } + else { + pb_destroy(fenced_buf->buffer); + free(fenced_buf); } - _glthread_UNLOCK_MUTEX(fenced_list->mutex); + if ((fenced_list->numDelayed % fenced_list->checkDelayed) == 0) + _fenced_buffer_list_check_free(fenced_list, 0); } static void * -fenced_buffer_map(struct pipe_buffer *buf, +fenced_buffer_map(struct pb_buffer *buf, unsigned flags) { struct fenced_buffer *fenced_buf = fenced_buffer(buf); - return buffer_map(fenced_buf->buffer, flags); + return pb_map(fenced_buf->buffer, flags); } static void -fenced_buffer_unmap(struct pipe_buffer *buf) +fenced_buffer_unmap(struct pb_buffer *buf) { struct fenced_buffer *fenced_buf = fenced_buffer(buf); - buffer_unmap(fenced_buf->buffer); + pb_unmap(fenced_buf->buffer); } static void -fenced_buffer_get_base_buffer(struct pipe_buffer *buf, - struct pipe_buffer **base_buf, +fenced_buffer_get_base_buffer(struct pb_buffer *buf, + struct pb_buffer **base_buf, unsigned *offset) { struct fenced_buffer *fenced_buf = fenced_buffer(buf); - buffer_get_base_buffer(fenced_buf->buffer, base_buf, offset); + pb_get_base_buffer(fenced_buf->buffer, base_buf, offset); } -const struct pipe_buffer_vtbl +const struct pb_vtbl fenced_buffer_vtbl = { - fenced_buffer_reference, - fenced_buffer_release, + fenced_buffer_destroy, fenced_buffer_map, fenced_buffer_unmap, fenced_buffer_get_base_buffer }; -struct pipe_buffer * +struct pb_buffer * fenced_buffer_create(struct fenced_buffer_list *fenced_list, - struct pipe_buffer *buffer) + struct pb_buffer *buffer) { struct fenced_buffer *buf; if(!buffer) return NULL; - buf = (struct fenced_buffer *)calloc(1, sizeof(struct fenced_buffer)); + buf = CALLOC_STRUCT(fenced_buffer); if(!buf) return NULL; @@ -247,20 +225,16 @@ fenced_buffer_create(struct fenced_buffer_list *fenced_list, void -buffer_fence(struct pipe_buffer *buf, +buffer_fence(struct pb_buffer *buf, struct pipe_fence_handle *fence) { - if(buf->vtbl == &fenced_buffer_vtbl) { - struct fenced_buffer *fenced_buf = fenced_buffer(buf); - struct fenced_buffer_list *fenced_list = fenced_buf->list; - struct pipe_winsys *winsys = fenced_list->winsys; + struct fenced_buffer *fenced_buf = fenced_buffer(buf); + struct fenced_buffer_list *fenced_list = fenced_buf->list; + struct pipe_winsys *winsys = fenced_list->winsys; - _glthread_LOCK_MUTEX(fenced_list->mutex); - winsys->fence_reference(winsys, &fenced_buf->fence, fence); - _glthread_UNLOCK_MUTEX(fenced_list->mutex); - } - else - assert(0); + _glthread_LOCK_MUTEX(fenced_list->mutex); + winsys->fence_reference(winsys, &fenced_buf->fence, fence); + _glthread_UNLOCK_MUTEX(fenced_list->mutex); } |