pb_validate.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  *
00003  * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  *
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  *
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  *
00026  **************************************************************************/
00027 
00036 #include "pipe/p_compiler.h"
00037 #include "pipe/p_error.h"
00038 #include "util/u_memory.h"
00039 #include "pipe/p_debug.h"
00040 
00041 #include "pb_buffer.h"
00042 #include "pb_buffer_fenced.h"
00043 #include "pb_validate.h"
00044 
00045 
00046 #define PB_VALIDATE_INITIAL_SIZE 1 /* 512 */ 
00047 
00048 
00049 struct pb_validate
00050 {
00051    struct pb_buffer **buffers;
00052    unsigned used;
00053    unsigned size;
00054 };
00055 
00056 
00057 enum pipe_error
00058 pb_validate_add_buffer(struct pb_validate *vl,
00059                        struct pb_buffer *buf)
00060 {
00061    assert(buf);
00062    if(!buf)
00063       return PIPE_ERROR;
00064 
00065    /* We only need to store one reference for each buffer, so avoid storing
00066     * consecutive references for the same buffer. It might not be the more 
00067     * common pasttern, but it is easy to implement.
00068     */
00069    if(vl->used && vl->buffers[vl->used - 1] == buf) {
00070       return PIPE_OK;
00071    }
00072    
00073    /* Grow the table */
00074    if(vl->used == vl->size) {
00075       unsigned new_size;
00076       struct pb_buffer **new_buffers;
00077       
00078       new_size = vl->size * 2;
00079       if(!new_size)
00080          return PIPE_ERROR_OUT_OF_MEMORY;
00081 
00082       new_buffers = (struct pb_buffer **)REALLOC(vl->buffers,
00083                                                  vl->size*sizeof(struct pb_buffer *),
00084                                                  new_size*sizeof(struct pb_buffer *));
00085       if(!new_buffers)
00086          return PIPE_ERROR_OUT_OF_MEMORY;
00087       
00088       memset(new_buffers + vl->size, 0, (new_size - vl->size)*sizeof(struct pb_buffer *));
00089       
00090       vl->size = new_size;
00091       vl->buffers = new_buffers;
00092    }
00093    
00094    assert(!vl->buffers[vl->used]);
00095    pb_reference(&vl->buffers[vl->used], buf);
00096    ++vl->used;
00097    
00098    return PIPE_OK;
00099 }
00100 
00101 
00102 enum pipe_error
00103 pb_validate_validate(struct pb_validate *vl) 
00104 {
00105    /* FIXME: go through each buffer, ensure its not mapped, its address is 
00106     * available -- requires a new pb_buffer interface */
00107    return PIPE_OK;
00108 }
00109 
00110 
00111 void
00112 pb_validate_fence(struct pb_validate *vl,
00113                   struct pipe_fence_handle *fence)
00114 {
00115    unsigned i;
00116    for(i = 0; i < vl->used; ++i) {
00117       buffer_fence(vl->buffers[i], fence);
00118       pb_reference(&vl->buffers[i], NULL);
00119    }
00120    vl->used = 0;
00121 }
00122 
00123 
00124 void
00125 pb_validate_destroy(struct pb_validate *vl)
00126 {
00127    unsigned i;
00128    for(i = 0; i < vl->used; ++i)
00129       pb_reference(&vl->buffers[i], NULL);
00130    FREE(vl->buffers);
00131    FREE(vl);
00132 }
00133 
00134 
00135 struct pb_validate *
00136 pb_validate_create()
00137 {
00138    struct pb_validate *vl;
00139    
00140    vl = CALLOC_STRUCT(pb_validate);
00141    if(!vl)
00142       return NULL;
00143    
00144    vl->size = PB_VALIDATE_INITIAL_SIZE;
00145    vl->buffers = (struct pb_buffer **)CALLOC(vl->size, sizeof(struct pb_buffer *));
00146    if(!vl->buffers) {
00147       FREE(vl);
00148       return NULL;
00149    }
00150 
00151    return vl;
00152 }
00153 

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