summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Fonseca <jrfonseca@tungstengraphics.com>2008-01-17 17:06:16 +0900
committerJosé Fonseca <jrfonseca@tungstengraphics.com>2008-01-26 11:46:49 +0900
commit65df0241465b2dae4979d71cad17b83cfd1fda11 (patch)
tree90d29be8a76f140765738dae9e13b2521e57254c
parentca01ed45e8dee7970c6eefb528b7576ce6717459 (diff)
gallium: Aggregate all buffer allocation info into a single struct. Obey requested alignment.
-rw-r--r--src/mesa/pipe/pipebuffer/pb_buffer.h18
-rw-r--r--src/mesa/pipe/pipebuffer/pb_buffer_malloc.c13
-rw-r--r--src/mesa/pipe/pipebuffer/pb_bufmgr.h7
-rw-r--r--src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c8
-rw-r--r--src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c15
-rw-r--r--src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c12
6 files changed, 52 insertions, 21 deletions
diff --git a/src/mesa/pipe/pipebuffer/pb_buffer.h b/src/mesa/pipe/pipebuffer/pb_buffer.h
index 570986314a..2f570ef9de 100644
--- a/src/mesa/pipe/pipebuffer/pb_buffer.h
+++ b/src/mesa/pipe/pipebuffer/pb_buffer.h
@@ -54,6 +54,18 @@
struct pb_vtbl;
/**
+ * Buffer description.
+ *
+ * Used when allocating the buffer.
+ */
+struct pb_desc
+{
+ unsigned alignment;
+ unsigned usage;
+};
+
+
+/**
* Base class for all pb_* buffers.
*/
struct pb_buffer
@@ -159,10 +171,8 @@ pb_user_buffer_create(void *data, unsigned bytes);
* hardware.
*/
struct pb_buffer *
-pb_malloc_buffer_create( unsigned alignment,
- unsigned usage,
- unsigned size );
-
+pb_malloc_buffer_create(size_t size,
+ const struct pb_desc *desc);
static INLINE struct pipe_buffer *
diff --git a/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c b/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c
index b80ee8dda3..f0ff1d347e 100644
--- a/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c
+++ b/src/mesa/pipe/pipebuffer/pb_buffer_malloc.c
@@ -62,7 +62,7 @@ malloc_buffer(struct pb_buffer *buf)
static void
malloc_buffer_destroy(struct pb_buffer *buf)
{
- FREE(malloc_buffer(buf)->data);
+ align_free(malloc_buffer(buf)->data);
FREE(buf);
}
@@ -102,9 +102,8 @@ malloc_buffer_vtbl = {
struct pb_buffer *
-pb_malloc_buffer_create( unsigned alignment,
- unsigned usage,
- unsigned size )
+pb_malloc_buffer_create(size_t size,
+ const struct pb_desc *desc)
{
struct malloc_buffer *buf;
@@ -116,11 +115,11 @@ pb_malloc_buffer_create( unsigned alignment,
return NULL;
buf->base.vtbl = &malloc_buffer_vtbl;
- buf->base.base.alignment = alignment;
- buf->base.base.usage = usage;
+ buf->base.base.alignment = desc->alignment;
+ buf->base.base.usage = desc->usage;
buf->base.base.size = size;
- buf->data = MALLOC(size);
+ buf->data = align_malloc(size, desc->alignment < sizeof(void*) ? sizeof(void*) : desc->alignment);
if(!buf->data) {
FREE(buf);
return NULL;
diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr.h b/src/mesa/pipe/pipebuffer/pb_bufmgr.h
index 13d4ea7545..1ddf784c97 100644
--- a/src/mesa/pipe/pipebuffer/pb_bufmgr.h
+++ b/src/mesa/pipe/pipebuffer/pb_bufmgr.h
@@ -53,6 +53,7 @@
#include <stddef.h>
+struct pb_desc;
struct pipe_buffer;
struct pipe_winsys;
@@ -65,7 +66,8 @@ struct pb_manager
/* XXX: we will likely need more allocation flags */
struct pb_buffer *
(*create_buffer)( struct pb_manager *mgr,
- size_t size );
+ size_t size,
+ const struct pb_desc *desc);
void
(*destroy)( struct pb_manager *mgr );
@@ -82,7 +84,8 @@ struct pb_manager
*/
struct pb_manager *
pool_bufmgr_create(struct pb_manager *provider,
- size_t n, size_t size);
+ size_t n, size_t size,
+ const struct pb_desc *desc);
/**
diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c
index 734d5bdceb..6a81cbdae0 100644
--- a/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c
+++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_fenced.c
@@ -63,7 +63,9 @@ fenced_pb_manager(struct pb_manager *mgr)
static struct pb_buffer *
-fenced_bufmgr_create_buffer(struct pb_manager *mgr, size_t size)
+fenced_bufmgr_create_buffer(struct pb_manager *mgr,
+ size_t size,
+ const struct pb_desc *desc)
{
struct fenced_pb_manager *fenced_mgr = fenced_pb_manager(mgr);
struct pb_buffer *buf;
@@ -72,12 +74,12 @@ fenced_bufmgr_create_buffer(struct pb_manager *mgr, size_t size)
/* check for free buffers before allocating new ones */
fenced_buffer_list_check_free(fenced_mgr->fenced_list, 0);
- buf = fenced_mgr->provider->create_buffer(fenced_mgr->provider, size);
+ buf = fenced_mgr->provider->create_buffer(fenced_mgr->provider, size, desc);
if(!buf) {
/* try harder to get a buffer */
fenced_buffer_list_check_free(fenced_mgr->fenced_list, 1);
- buf = fenced_mgr->provider->create_buffer(fenced_mgr->provider, size);
+ buf = fenced_mgr->provider->create_buffer(fenced_mgr->provider, size, desc);
if(!buf) {
/* give up */
return NULL;
diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c
index 038406e953..2a62702c36 100644
--- a/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c
+++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_mm.c
@@ -447,11 +447,17 @@ mm_buffer_vtbl = {
static struct pb_buffer *
mm_bufmgr_create_buffer(struct pb_manager *mgr,
- size_t size)
+ size_t size,
+ const struct pb_desc *desc)
{
struct mm_pb_manager *mm = mm_pb_manager(mgr);
struct mm_buffer *mm_buf;
+ /* We don't handle alignments larger then the one initially setup */
+ assert(desc->alignment % (1 << mm->align2) == 0);
+ if(desc->alignment % (1 << mm->align2))
+ return NULL;
+
_glthread_LOCK_MUTEX(mm->mutex);
mm_buf = CALLOC_STRUCT(mm_buffer);
@@ -559,10 +565,15 @@ mm_bufmgr_create(struct pb_manager *provider,
{
struct pb_buffer *buffer;
struct pb_manager *mgr;
+ struct pb_desc desc;
assert(provider);
assert(provider->create_buffer);
- buffer = provider->create_buffer(provider, size);
+
+ memset(&desc, 0, sizeof(desc));
+ desc.alignment = 1 << align2;
+
+ buffer = provider->create_buffer(provider, size, &desc);
if (!buffer)
return NULL;
diff --git a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c
index 33b2f628dd..61c06ec824 100644
--- a/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c
+++ b/src/mesa/pipe/pipebuffer/pb_bufmgr_pool.c
@@ -62,6 +62,7 @@ struct pool_pb_manager
_glthread_Mutex mutex;
size_t bufSize;
+ size_t bufAlign;
size_t numFree;
size_t numTot;
@@ -160,13 +161,16 @@ pool_buffer_vtbl = {
static struct pb_buffer *
-pool_bufmgr_create_buffer(struct pb_manager *mgr, size_t size)
+pool_bufmgr_create_buffer(struct pb_manager *mgr,
+ size_t size,
+ const struct pb_desc *desc)
{
struct pool_pb_manager *pool = pool_pb_manager(mgr);
struct pool_buffer *pool_buf;
struct list_head *item;
assert(size == pool->bufSize);
+ assert(desc->alignment % pool->bufAlign == 0);
_glthread_LOCK_MUTEX(pool->mutex);
@@ -213,7 +217,8 @@ pool_bufmgr_destroy(struct pb_manager *mgr)
struct pb_manager *
pool_bufmgr_create(struct pb_manager *provider,
size_t numBufs,
- size_t bufSize)
+ size_t bufSize,
+ const struct pb_desc *desc)
{
struct pool_pb_manager *pool;
struct pool_buffer *pool_buf;
@@ -231,10 +236,11 @@ pool_bufmgr_create(struct pb_manager *provider,
pool->numTot = numBufs;
pool->numFree = numBufs;
pool->bufSize = bufSize;
+ pool->bufAlign = desc->alignment;
_glthread_INIT_MUTEX(pool->mutex);
- pool->buffer = provider->create_buffer(provider, numBufs*bufSize);
+ pool->buffer = provider->create_buffer(provider, numBufs*bufSize, desc);
if (!pool->buffer)
goto failure;