Home | History | Annotate | Download | only in util

Lines Matching refs:allocator

29 /* A simple allocator that suballocates memory from a large buffer. */
64 struct u_suballocator *allocator = CALLOC_STRUCT(u_suballocator);
65 if (!allocator)
68 allocator->pipe = pipe;
69 allocator->size = size;
70 allocator->bind = bind;
71 allocator->usage = usage;
72 allocator->zero_buffer_memory = zero_buffer_memory;
73 return allocator;
77 u_suballocator_destroy(struct u_suballocator *allocator)
79 pipe_resource_reference(&allocator->buffer, NULL);
80 FREE(allocator);
84 u_suballocator_alloc(struct u_suballocator *allocator, unsigned size,
88 allocator->offset = align(allocator->offset, alignment);
91 if (size > allocator->size)
95 if (!allocator->buffer ||
96 allocator->offset + size > allocator->size) {
98 pipe_resource_reference(&allocator->buffer, NULL);
99 allocator->offset = 0;
100 allocator->buffer =
101 pipe_buffer_create(allocator->pipe->screen, allocator->bind,
102 allocator->usage, allocator->size);
103 if (!allocator->buffer)
107 if (allocator->zero_buffer_memory) {
111 ptr = pipe_buffer_map(allocator->pipe, allocator->buffer,
113 memset(ptr, 0, allocator->size);
114 pipe_buffer_unmap(allocator->pipe, transfer);
118 assert(allocator->offset % alignment == 0);
119 assert(allocator->offset < allocator->buffer->width0);
120 assert(allocator->offset + size <= allocator->buffer->width0);
123 *out_offset = allocator->offset;
124 pipe_resource_reference(outbuf, allocator->buffer);
126 allocator->offset += size;