Lines Matching defs:allocator
29 /* A simple allocator that suballocates memory from a large buffer. */
48 u_suballocator_init(struct u_suballocator *allocator,
54 memset(allocator, 0, sizeof(*allocator));
56 allocator->pipe = pipe;
57 allocator->size = size;
58 allocator->bind = bind;
59 allocator->usage = usage;
60 allocator->flags = flags;
61 allocator->zero_buffer_memory = zero_buffer_memory;
65 u_suballocator_destroy(struct u_suballocator *allocator)
67 pipe_resource_reference(&allocator->buffer, NULL);
71 u_suballocator_alloc(struct u_suballocator *allocator, unsigned size,
75 allocator->offset = align(allocator->offset, alignment);
78 if (size > allocator->size)
82 if (!allocator->buffer ||
83 allocator->offset + size > allocator->size) {
85 pipe_resource_reference(&allocator->buffer, NULL);
86 allocator->offset = 0;
92 templ.bind = allocator->bind;
93 templ.usage = allocator->usage;
94 templ.flags = allocator->flags;
95 templ.width0 = allocator->size;
100 struct pipe_screen *screen = allocator->pipe->screen;
101 allocator->buffer = screen->resource_create(screen, &templ);
102 if (!allocator->buffer)
106 if (allocator->zero_buffer_memory) {
107 struct pipe_context *pipe = allocator->pipe;
112 pipe->clear_buffer(pipe, allocator->buffer, 0, allocator->size,
116 void *ptr = pipe_buffer_map(pipe, allocator->buffer,
118 memset(ptr, 0, allocator->size);
124 assert(allocator->offset % alignment == 0);
125 assert(allocator->offset < allocator->buffer->width0);
126 assert(allocator->offset + size <= allocator->buffer->width0);
129 *out_offset = allocator->offset;
130 pipe_resource_reference(outbuf, allocator->buffer);
132 allocator->offset += size;