Use lower alignments where possible. Also pad out allocated blocks to

a multiple of alignment to avoid accumulating unusable free blocks.
This commit is contained in:
Keith Whitwell
2006-09-07 16:23:22 +00:00
parent 133f141680
commit 1456a0fff6
7 changed files with 20 additions and 12 deletions
+1 -1
View File
@@ -95,7 +95,7 @@ static void brw_init_pool( struct brw_context *brw,
pool->size = size;
pool->brw = brw;
bmGenBuffers(&brw->intel, "pool", 1, &pool->buffer);
bmGenBuffers(&brw->intel, "pool", 1, &pool->buffer, 0);
/* Also want to say not to wait on fences when data is presented
*/
+1 -1
View File
@@ -79,7 +79,7 @@ static void upload_wm_unit(struct brw_context *brw )
*/
if (!brw->wm.scratch_buffer) {
bmGenBuffers(intel, "wm scratch", 1, &brw->wm.scratch_buffer);
bmGenBuffers(intel, "wm scratch", 1, &brw->wm.scratch_buffer, 12);
bmBufferSetInvalidateCB(intel,
brw->wm.scratch_buffer,
invalidate_scratch_cb,
+2 -1
View File
@@ -84,7 +84,8 @@ int bmInitPool( struct intel_context *,
* understood, and drivers can just pass the calls through without too
* much thunking.
*/
void bmGenBuffers(struct intel_context *, const char *, unsigned n, struct buffer **buffers);
void bmGenBuffers(struct intel_context *, const char *, unsigned n, struct buffer **buffers,
int align );
void bmDeleteBuffers(struct intel_context *, unsigned n, struct buffer **buffers);
+13 -6
View File
@@ -163,10 +163,16 @@ static GLboolean alloc_from_pool( struct intel_context *intel,
struct bufmgr *bm = intel->bm;
struct pool *pool = &bm->pool[pool_nr];
struct block *block = (struct block *)calloc(sizeof *block, 1);
GLuint sz, align = (1<<buf->alignment);
if (!block)
return GL_FALSE;
block->mem = mmAllocMem(pool->heap, buf->size, buf->alignment, 0);
sz = (buf->size + align-1) & ~(align-1);
block->mem = mmAllocMem(pool->heap,
sz,
buf->alignment, 0);
if (!block->mem) {
free(block);
return GL_FALSE;
@@ -621,14 +627,14 @@ int bmInitPool( struct intel_context *intel,
return retval;
}
static struct buffer *do_GenBuffer(struct intel_context *intel, const char *name)
static struct buffer *do_GenBuffer(struct intel_context *intel, const char *name, int align)
{
struct bufmgr *bm = intel->bm;
struct buffer *buf = calloc(sizeof(*buf), 1);
buf->id = ++bm->buf_nr;
buf->name = name;
buf->alignment = 12; /* page-alignment to fit in with AGP swapping */
buf->alignment = align ? align : 6;
buf->flags = BM_MEM_AGP|BM_MEM_VRAM|BM_MEM_LOCAL;
return buf;
@@ -638,7 +644,8 @@ static struct buffer *do_GenBuffer(struct intel_context *intel, const char *name
void bmGenBuffers(struct intel_context *intel,
const char *name, unsigned n,
struct buffer **buffers)
struct buffer **buffers,
int align )
{
struct bufmgr *bm = intel->bm;
LOCK(bm);
@@ -646,7 +653,7 @@ void bmGenBuffers(struct intel_context *intel,
int i;
for (i = 0; i < n; i++)
buffers[i] = do_GenBuffer(intel, name);
buffers[i] = do_GenBuffer(intel, name, align);
}
UNLOCK(bm);
}
@@ -694,7 +701,7 @@ struct buffer *bmGenBufferStatic(struct intel_context *intel,
if (bm->pool[pool].static_buffer)
buf = bm->pool[pool].static_buffer;
else {
buf = do_GenBuffer(intel, "static");
buf = do_GenBuffer(intel, "static", 12);
bm->pool[pool].static_buffer = buf;
assert(!buf->block);
@@ -92,7 +92,7 @@ struct intel_batchbuffer *intel_batchbuffer_alloc( struct intel_context *intel )
batch->intel = intel;
bmGenBuffers(intel, "batch", 1, &batch->buffer);
bmGenBuffers(intel, "batch", 1, &batch->buffer, 12);
bmBufferSetInvalidateCB(intel, batch->buffer,
intel_batchbuffer_reset_cb,
@@ -52,7 +52,7 @@ static struct gl_buffer_object *intel_bufferobj_alloc( GLcontext *ctx,
/* XXX: We generate our own handle, which is different to 'name' above.
*/
bmGenBuffers(intel, "bufferobj", 1, &obj->buffer);
bmGenBuffers(intel, "bufferobj", 1, &obj->buffer, 6);
assert(obj->buffer);
return &obj->Base;
+1 -1
View File
@@ -82,7 +82,7 @@ struct intel_region *intel_region_alloc( struct intel_context *intel,
region->height = height; /* needed? */
region->refcount = 1;
bmGenBuffers(intel, "tex", 1, &region->buffer);
bmGenBuffers(intel, "tex", 1, &region->buffer, 6);
bmBufferData(intel, region->buffer, pitch * cpp * height, NULL, 0);
return region;