a->buf = NULL;
if (obj) {
- if (_mesa_is_bufferobj(obj)) {
+ if (nouveau_bufferobj_hw(obj)) {
struct nouveau_bufferobj *nbo =
to_nouveau_bufferobj(obj);
a->offset = 0;
if (map)
- a->buf = ptr;
+ a->buf = ADD_POINTERS(
+ nouveau_bufferobj_sys(obj), ptr);
}
}
struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
void *map = NULL;
- if (nbo->bo) {
+ 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);
struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj);
nouveau_bo_ref(NULL, &nbo->bo);
+ FREE(nbo->sys);
FREE(nbo);
}
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);
+ 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);
struct nouveau_bufferobj {
struct gl_buffer_object base;
struct nouveau_bo *bo;
+ void *sys;
};
#define to_nouveau_bufferobj(x) ((struct nouveau_bufferobj *)(x))
+#define nouveau_bufferobj_hw(x) \
+ (_mesa_is_bufferobj(x) ? to_nouveau_bufferobj(x)->bo : NULL)
+
+#define nouveau_bufferobj_sys(x) \
+ (_mesa_is_bufferobj(x) ? to_nouveau_bufferobj(x)->sys : NULL)
+
void
nouveau_bufferobj_functions_init(struct dd_function_table *functions);
FOR_EACH_BOUND_ATTR(render, i, attr) {
const struct gl_client_array *array = arrays[attr];
+ struct gl_buffer_object *obj = array->BufferObj;
struct nouveau_array *a = &render->attrs[attr];
unsigned delta = (base + min_index) * array->StrideB;
bo[i] = NULL;
- if (_mesa_is_bufferobj(array->BufferObj)) {
- struct nouveau_bufferobj *nbo =
- to_nouveau_bufferobj(array->BufferObj);
-
+ if (nouveau_bufferobj_hw(obj)) {
/* Array in a buffer obj. */
- nouveau_bo_ref(nbo->bo, &bo[i]);
+ nouveau_bo_ref(to_nouveau_bufferobj(obj)->bo, &bo[i]);
offset[i] = delta + (intptr_t)array->Ptr;
} else {
int n = max_index - min_index + 1;
- char *sp = (char *)array->Ptr + delta;
+ char *sp = (char *)ADD_POINTERS(
+ nouveau_bufferobj_sys(obj), array->Ptr) + delta;
char *dp = nouveau_get_scratch(ctx, n * a->stride,
&bo[i], &offset[i]);