struct pb_vtbl;
+/**
+ * Buffer description.
+ *
+ * Used when allocating the buffer.
+ */
+struct pb_desc
+{
+ unsigned alignment;
+ unsigned usage;
+};
+
+
/**
* Base class for all pb_* buffers.
*/
* 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 *
static void
malloc_buffer_destroy(struct pb_buffer *buf)
{
- FREE(malloc_buffer(buf)->data);
+ align_free(malloc_buffer(buf)->data);
FREE(buf);
}
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;
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;
#include <stddef.h>
+struct pb_desc;
struct pipe_buffer;
struct pipe_winsys;
/* 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 );
*/
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);
/**
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;
/* 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;
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);
{
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;
_glthread_Mutex mutex;
size_t bufSize;
+ size_t bufAlign;
size_t numFree;
size_t numTot;
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);
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;
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;