diff options
author | Brian <[email protected]> | 2007-10-11 09:10:19 -0600 |
---|---|---|
committer | Brian <[email protected]> | 2007-10-11 09:10:19 -0600 |
commit | cdc156d52f4ac33898b4a0e4930a1a9ebe3c81cf (patch) | |
tree | 723c177f943a27fd0383aeba2b6ac297f74cff17 /src/mesa/drivers | |
parent | 453ac4b1ebc70aeabb182f2b336c6abb3324323e (diff) |
Initial support for user-space buffer objects.
Basically, add userBuffer/Data/Size fields to _DriBufferObject, check those
fields in driBOMap/Unmap().
New driGenUserBuffer() function.
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r-- | src/mesa/drivers/dri/common/dri_bufmgr.c | 54 | ||||
-rw-r--r-- | src/mesa/drivers/dri/common/dri_bufmgr.h | 4 |
2 files changed, 49 insertions, 9 deletions
diff --git a/src/mesa/drivers/dri/common/dri_bufmgr.c b/src/mesa/drivers/dri/common/dri_bufmgr.c index eaa4fb09c70..5747307f3b6 100644 --- a/src/mesa/drivers/dri/common/dri_bufmgr.c +++ b/src/mesa/drivers/dri/common/dri_bufmgr.c @@ -67,6 +67,10 @@ typedef struct _DriBufferObject unsigned hint; unsigned alignment; void *private; + /* user-space buffer: */ + unsigned userBuffer; + void *userData; + unsigned userSize; } DriBufferObject; @@ -205,22 +209,29 @@ driBOWaitIdle(struct _DriBufferObject *buf, int lazy) void * driBOMap(struct _DriBufferObject *buf, unsigned flags, unsigned hint) { - void *virtual; + if (buf->userBuffer) { + return buf->userData; + } + else { + void *virtual; - assert(buf->private != NULL); + assert(buf->private != NULL); - _glthread_LOCK_MUTEX(buf->mutex); - BM_CKFATAL(buf->pool->map(buf->pool, buf->private, flags, hint, &virtual)); - _glthread_UNLOCK_MUTEX(buf->mutex); - return virtual; + _glthread_LOCK_MUTEX(buf->mutex); + BM_CKFATAL(buf->pool->map(buf->pool, buf->private, flags, hint, &virtual)); + _glthread_UNLOCK_MUTEX(buf->mutex); + return virtual; + } } void driBOUnmap(struct _DriBufferObject *buf) { - assert(buf->private != NULL); + if (!buf->userBuffer) { + assert(buf->private != NULL); - buf->pool->unmap(buf->pool, buf->private); + buf->pool->unmap(buf->pool, buf->private); + } } unsigned long @@ -272,7 +283,8 @@ driBOUnReference(struct _DriBufferObject *buf) tmp = --buf->refCount; _glthread_UNLOCK_MUTEX(bmMutex); if (!tmp) { - buf->pool->destroy(buf->pool, buf->private); + if (buf->private) + buf->pool->destroy(buf->pool, buf->private); free(buf); } } @@ -285,6 +297,8 @@ driBOData(struct _DriBufferObject *buf, int newBuffer; struct _DriBufferPool *pool; + assert(!buf->userBuffer); /* XXX just do a memcpy? */ + _glthread_LOCK_MUTEX(buf->mutex); pool = buf->pool; if (!pool->create) { @@ -323,6 +337,8 @@ driBOSubData(struct _DriBufferObject *buf, { void *virtual; + assert(!buf->userBuffer); /* XXX just do a memcpy? */ + _glthread_LOCK_MUTEX(buf->mutex); if (size && data) { BM_CKFATAL(buf->pool->map(buf->pool, buf->private, @@ -339,6 +355,8 @@ driBOGetSubData(struct _DriBufferObject *buf, { void *virtual; + assert(!buf->userBuffer); /* XXX just do a memcpy? */ + _glthread_LOCK_MUTEX(buf->mutex); if (size && data) { BM_CKFATAL(buf->pool->map(buf->pool, buf->private, @@ -354,6 +372,8 @@ driBOSetStatic(struct _DriBufferObject *buf, unsigned long offset, unsigned long size, void *virtual, unsigned flags) { + assert(!buf->userBuffer); /* XXX what to do? */ + _glthread_LOCK_MUTEX(buf->mutex); if (buf->private != NULL) { _mesa_error(NULL, GL_INVALID_OPERATION, @@ -416,6 +436,22 @@ driGenBuffers(struct _DriBufferPool *pool, } void +driGenUserBuffer(struct _DriBufferPool *pool, + const char *name, + struct _DriBufferObject **buffers, + void *ptr, unsigned bytes) +{ + const unsigned alignment = 1, flags = 0, hint = 0; + + driGenBuffers(pool, name, 1, buffers, alignment, flags, hint); + + (*buffers)->userBuffer = 1; + (*buffers)->userData = ptr; + (*buffers)->userSize = bytes; +} + + +void driDeleteBuffers(unsigned n, struct _DriBufferObject *buffers[]) { int i; diff --git a/src/mesa/drivers/dri/common/dri_bufmgr.h b/src/mesa/drivers/dri/common/dri_bufmgr.h index 01f149ae4ed..ee4ce2cbdef 100644 --- a/src/mesa/drivers/dri/common/dri_bufmgr.h +++ b/src/mesa/drivers/dri/common/dri_bufmgr.h @@ -78,6 +78,10 @@ extern void driGenBuffers(struct _DriBufferPool *pool, unsigned n, struct _DriBufferObject *buffers[], unsigned alignment, unsigned flags, unsigned hint); +extern void driGenUserBuffer(struct _DriBufferPool *pool, + const char *name, + struct _DriBufferObject *buffers[], + void *ptr, unsigned bytes); extern void driDeleteBuffers(unsigned n, struct _DriBufferObject *buffers[]); extern void driInitBufMgr(int fd); extern void driBOCreateList(int target, drmBOList * list); |