00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
00066
00067
00068
00069 if(vl->used && vl->buffers[vl->used - 1] == buf) {
00070 return PIPE_OK;
00071 }
00072
00073
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
00106
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