aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c')
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c95
1 files changed, 59 insertions, 36 deletions
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
index ad6e5bd805a..e60b91f64be 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_bufferobj.c
@@ -30,6 +30,23 @@
#include "main/bufferobj.h"
+static inline char *
+get_bufferobj_map(struct gl_buffer_object *obj, unsigned flags)
+{
+ struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
+ void *map = NULL;
+
+ if (nbo->sys) {
+ map = nbo->sys;
+ } else if (nbo->bo) {
+ nouveau_bo_map(nbo->bo, flags);
+ map = nbo->bo->map;
+ nouveau_bo_unmap(nbo->bo);
+ }
+
+ return map;
+}
+
static struct gl_buffer_object *
nouveau_bufferobj_new(struct gl_context *ctx, GLuint buffer, GLenum target)
{
@@ -50,6 +67,7 @@ nouveau_bufferobj_del(struct gl_context *ctx, struct gl_buffer_object *obj)
struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
nouveau_bo_ref(NULL, &nbo->bo);
+ FREE(nbo->sys);
FREE(nbo);
}
@@ -64,18 +82,27 @@ nouveau_bufferobj_data(struct gl_context *ctx, GLenum target, GLsizeiptrARB size
obj->Size = size;
obj->Usage = usage;
+ /* Free previous storage */
nouveau_bo_ref(NULL, &nbo->bo);
- ret = nouveau_bo_new(context_dev(ctx),
- NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0,
- size, &nbo->bo);
- assert(!ret);
-
- if (data) {
- nouveau_bo_map(nbo->bo, NOUVEAU_BO_WR);
- memcpy(nbo->bo->map, data, size);
- nouveau_bo_unmap(nbo->bo);
+ FREE(nbo->sys);
+
+ if (target == GL_ELEMENT_ARRAY_BUFFER_ARB ||
+ (size < 512 && usage == GL_DYNAMIC_DRAW_ARB) ||
+ context_chipset(ctx) < 0x10) {
+ /* Heuristic: keep it in system ram */
+ nbo->sys = MALLOC(size);
+
+ } else {
+ /* Get a hardware BO */
+ ret = nouveau_bo_new(context_dev(ctx),
+ NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0,
+ size, &nbo->bo);
+ assert(!ret);
}
+ if (data)
+ memcpy(get_bufferobj_map(obj, NOUVEAU_BO_WR), data, size);
+
return GL_TRUE;
}
@@ -84,11 +111,7 @@ nouveau_bufferobj_subdata(struct gl_context *ctx, GLenum target, GLintptrARB off
GLsizeiptrARB size, const GLvoid *data,
struct gl_buffer_object *obj)
{
- struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
-
- nouveau_bo_map(nbo->bo, NOUVEAU_BO_WR);
- memcpy(nbo->bo->map + offset, data, size);
- nouveau_bo_unmap(nbo->bo);
+ memcpy(get_bufferobj_map(obj, NOUVEAU_BO_WR) + offset, data, size);
}
static void
@@ -96,44 +119,48 @@ nouveau_bufferobj_get_subdata(struct gl_context *ctx, GLenum target, GLintptrARB
GLsizeiptrARB size, GLvoid *data,
struct gl_buffer_object *obj)
{
- struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
-
- nouveau_bo_map(nbo->bo, NOUVEAU_BO_RD);
- memcpy(data, nbo->bo->map + offset, size);
- nouveau_bo_unmap(nbo->bo);
+ memcpy(data, get_bufferobj_map(obj, NOUVEAU_BO_RD) + offset, size);
}
static void *
nouveau_bufferobj_map(struct gl_context *ctx, GLenum target, GLenum access,
struct gl_buffer_object *obj)
{
- return ctx->Driver.MapBufferRange(ctx, target, 0, obj->Size, access,
+ unsigned flags = 0;
+
+ if (access == GL_READ_ONLY_ARB ||
+ access == GL_READ_WRITE_ARB)
+ flags |= GL_MAP_READ_BIT;
+ if (access == GL_WRITE_ONLY_ARB ||
+ access == GL_READ_WRITE_ARB)
+ flags |= GL_MAP_WRITE_BIT;
+
+ return ctx->Driver.MapBufferRange(ctx, target, 0, obj->Size, flags,
obj);
}
static void *
nouveau_bufferobj_map_range(struct gl_context *ctx, GLenum target, GLintptr offset,
- GLsizeiptr length, GLenum access,
+ GLsizeiptr length, GLbitfield access,
struct gl_buffer_object *obj)
{
- struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
- uint32_t flags = 0;
+ unsigned flags = 0;
+ char *map;
assert(!obj->Pointer);
- if (!nbo->bo)
- return NULL;
-
- if (access == GL_READ_ONLY_ARB ||
- access == GL_READ_WRITE_ARB)
+ if (access & GL_MAP_READ_BIT)
flags |= NOUVEAU_BO_RD;
- if (access == GL_WRITE_ONLY_ARB ||
- access == GL_READ_WRITE_ARB)
+ if (access & GL_MAP_WRITE_BIT)
flags |= NOUVEAU_BO_WR;
+ if (access & GL_MAP_UNSYNCHRONIZED_BIT)
+ flags |= NOUVEAU_BO_NOSYNC;
- nouveau_bo_map_range(nbo->bo, offset, length, flags);
+ map = get_bufferobj_map(obj, flags);
+ if (!map)
+ return NULL;
- obj->Pointer = nbo->bo->map;
+ obj->Pointer = map + offset;
obj->Offset = offset;
obj->Length = length;
obj->AccessFlags = access;
@@ -144,12 +171,8 @@ nouveau_bufferobj_map_range(struct gl_context *ctx, GLenum target, GLintptr offs
static GLboolean
nouveau_bufferobj_unmap(struct gl_context *ctx, GLenum target, struct gl_buffer_object *obj)
{
- struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
-
assert(obj->Pointer);
- nouveau_bo_unmap(nbo->bo);
-
obj->Pointer = NULL;
obj->Offset = 0;
obj->Length = 0;