pb_buffer_fenced.h File Reference

Buffer fencing. More...

Include dependency graph for pb_buffer_fenced.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct fenced_buffer_listfenced_buffer_list_create (struct pipe_winsys *winsys)
 Create a fenced buffer list.
void fenced_buffer_list_check_free (struct fenced_buffer_list *fenced_list, int wait)
 Walk the fenced buffer list to check and free signalled buffers.
void fenced_buffer_list_destroy (struct fenced_buffer_list *fenced_list)
struct pb_bufferfenced_buffer_create (struct fenced_buffer_list *fenced, struct pb_buffer *buffer)
 Wrap a buffer in a fenced buffer.
void buffer_fence (struct pb_buffer *buf, struct pipe_fence_handle *fence)
 Set a buffer's fence.

Variables

struct pb_vtbl fenced_buffer_vtbl
 The fenced buffer's virtual function table.


Detailed Description

Buffer fencing.

"Fenced buffers" is actually a misnomer. They should be referred as "fenceable buffers", i.e, buffers that can be fenced, but I couldn't find the word "fenceable" in the dictionary.

A "fenced buffer" is a decorator around a normal buffer, which adds two special properties:

Usually DMA buffers have a life-time that will extend the life-time of its handle. The end-of-life is dictated by the fence signalling.

Between the handle's destruction, and the fence signalling, the buffer is stored in a fenced buffer list.

Author:
José Fonseca <jrfonseca@tungstengraphics.com>

Definition in file pb_buffer_fenced.h.


Function Documentation

void buffer_fence ( struct pb_buffer buf,
struct pipe_fence_handle *  fence 
)

Set a buffer's fence.

NOTE: Although it takes a generic pb_buffer argument, it will fail on everything but buffers returned by fenced_buffer_create.

Definition at line 403 of file pb_buffer_fenced.c.

References _fenced_buffer_add(), _fenced_buffer_remove(), assert, fenced_buffer::fence, pipe_winsys::fence_reference, fenced_buffer(), fenced_buffer::flags, fenced_buffer::list, fenced_buffer_list::mutex, PIPE_BUFFER_USAGE_GPU_READ_WRITE, pipe_mutex_lock, pipe_mutex_unlock, pb_buffer::vtbl, and fenced_buffer_list::winsys.

00405 {
00406    struct fenced_buffer *fenced_buf;
00407    struct fenced_buffer_list *fenced_list;
00408    struct pipe_winsys *winsys;
00409    /* FIXME: receive this as a parameter */
00410    unsigned flags = fence ? PIPE_BUFFER_USAGE_GPU_READ_WRITE : 0;
00411 
00412    /* This is a public function, so be extra cautious with the buffer passed, 
00413     * as happens frequently to receive null buffers, or pointer to buffers 
00414     * other than fenced buffers. */
00415    assert(buf);
00416    if(!buf)
00417       return;
00418    assert(buf->vtbl == &fenced_buffer_vtbl);
00419    if(buf->vtbl != &fenced_buffer_vtbl)
00420       return;
00421    
00422    if(!fence)
00423       return;
00424 
00425    fenced_buf = fenced_buffer(buf);
00426    fenced_list = fenced_buf->list;
00427    winsys = fenced_list->winsys;
00428    
00429    if(fence == fenced_buf->fence) {
00430       fenced_buf->flags |= flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE;
00431       return;
00432    }
00433    
00434    pipe_mutex_lock(fenced_list->mutex);
00435    if (fenced_buf->fence)
00436       _fenced_buffer_remove(fenced_list, fenced_buf);
00437    winsys->fence_reference(winsys, &fenced_buf->fence, fence);
00438    fenced_buf->flags |= flags & PIPE_BUFFER_USAGE_GPU_READ_WRITE;
00439    _fenced_buffer_add(fenced_buf);
00440    pipe_mutex_unlock(fenced_list->mutex);
00441 }

struct pb_buffer* fenced_buffer_create ( struct fenced_buffer_list fenced,
struct pb_buffer buffer 
) [read]

Wrap a buffer in a fenced buffer.

NOTE: this will not increase the buffer reference count.

Definition at line 368 of file pb_buffer_fenced.c.

References pipe_buffer::alignment, pb_buffer::base, fenced_buffer::base, fenced_buffer::buffer, CALLOC_STRUCT, fenced_buffer::head, fenced_buffer::list, LIST_ADDTAIL, fenced_buffer_list::mutex, pb_reference(), pipe_mutex_lock, pipe_mutex_unlock, pipe_buffer::refcount, pipe_buffer::size, pipe_buffer::usage, and pb_buffer::vtbl.

00370 {
00371    struct fenced_buffer *buf;
00372    
00373    if(!buffer)
00374       return NULL;
00375    
00376    buf = CALLOC_STRUCT(fenced_buffer);
00377    if(!buf) {
00378       pb_reference(&buffer, NULL);
00379       return NULL;
00380    }
00381    
00382    buf->base.base.refcount = 1;
00383    buf->base.base.alignment = buffer->base.alignment;
00384    buf->base.base.usage = buffer->base.usage;
00385    buf->base.base.size = buffer->base.size;
00386    
00387    buf->base.vtbl = &fenced_buffer_vtbl;
00388    buf->buffer = buffer;
00389    buf->list = fenced_list;
00390    
00391 #ifdef DEBUG
00392    pipe_mutex_lock(fenced_list->mutex);
00393    LIST_ADDTAIL(&buf->head, &fenced_list->unfenced);
00394    ++fenced_list->numUnfenced;
00395    pipe_mutex_unlock(fenced_list->mutex);
00396 #endif
00397 
00398    return &buf->base;
00399 }

void fenced_buffer_list_check_free ( struct fenced_buffer_list fenced_list,
int  wait 
)

Walk the fenced buffer list to check and free signalled buffers.

Definition at line 470 of file pb_buffer_fenced.c.

References _fenced_buffer_list_check_free(), fenced_buffer_list::mutex, pipe_mutex_lock, and pipe_mutex_unlock.

00472 {
00473    pipe_mutex_lock(fenced_list->mutex);
00474    _fenced_buffer_list_check_free(fenced_list, wait);
00475    pipe_mutex_unlock(fenced_list->mutex);
00476 }

struct fenced_buffer_list* fenced_buffer_list_create ( struct pipe_winsys winsys  )  [read]

Create a fenced buffer list.

See also fenced_bufmgr_create for a more convenient way to use this.

Definition at line 445 of file pb_buffer_fenced.c.

References CALLOC_STRUCT, fenced_buffer_list::delayed, LIST_INITHEAD, fenced_buffer_list::mutex, fenced_buffer_list::numDelayed, pipe_mutex_init, and fenced_buffer_list::winsys.

00446 {
00447    struct fenced_buffer_list *fenced_list;
00448 
00449    fenced_list = CALLOC_STRUCT(fenced_buffer_list);
00450    if (!fenced_list)
00451       return NULL;
00452 
00453    fenced_list->winsys = winsys;
00454 
00455    LIST_INITHEAD(&fenced_list->delayed);
00456    fenced_list->numDelayed = 0;
00457    
00458 #ifdef DEBUG
00459    LIST_INITHEAD(&fenced_list->unfenced);
00460    fenced_list->numUnfenced = 0;
00461 #endif
00462 
00463    pipe_mutex_init(fenced_list->mutex);
00464 
00465    return fenced_list;
00466 }

void fenced_buffer_list_destroy ( struct fenced_buffer_list fenced_list  ) 

Definition at line 525 of file pb_buffer_fenced.c.

References _fenced_buffer_list_check_free(), FREE, fenced_buffer_list::mutex, fenced_buffer_list::numDelayed, pipe_mutex_lock, and pipe_mutex_unlock.

00526 {
00527    pipe_mutex_lock(fenced_list->mutex);
00528 
00529    /* Wait on outstanding fences */
00530    while (fenced_list->numDelayed) {
00531       pipe_mutex_unlock(fenced_list->mutex);
00532 #if defined(PIPE_OS_LINUX)
00533       sched_yield();
00534 #endif
00535       _fenced_buffer_list_check_free(fenced_list, 1);
00536       pipe_mutex_lock(fenced_list->mutex);
00537    }
00538 
00539 #ifdef DEBUG
00540    //assert(!fenced_list->numUnfenced);
00541 #endif
00542       
00543    pipe_mutex_unlock(fenced_list->mutex);
00544    
00545    FREE(fenced_list);
00546 }


Variable Documentation

struct pb_vtbl fenced_buffer_vtbl

The fenced buffer's virtual function table.

NOTE: Made public for debugging purposes.

Definition at line 359 of file pb_buffer_fenced.c.


Generated on Tue Sep 29 06:25:24 2009 for Gallium3D by  doxygen 1.5.4