diff options
Diffstat (limited to 'src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c')
-rw-r--r-- | src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c | 73 |
1 files changed, 59 insertions, 14 deletions
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c index 02c8580760..a365b977f2 100644 --- a/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c +++ b/src/mesa/drivers/dri/nouveau/nouveau_vbo_t.c @@ -24,8 +24,11 @@ * */ -#include "main/bufferobj.h" #include "nouveau_bufferobj.h" +#include "nouveau_util.h" + +#include "main/bufferobj.h" +#include "main/image.h" /* Arbitrary pushbuf length we can assume we can get with a single * WAIT_RING. */ @@ -58,7 +61,11 @@ vbo_init_array(struct nouveau_array_state *a, int attr, int stride, } else { nouveau_bo_ref(NULL, &a->bo); a->offset = 0; - a->buf = ptr; + + if (map) + a->buf = ptr; + else + a->buf = NULL; } if (a->buf) @@ -94,11 +101,20 @@ vbo_init_arrays(GLcontext *ctx, const struct _mesa_index_buffer *ib, if (attr >= 0) { const struct gl_client_array *array = arrays[attr]; + int stride; + + if (render->mode == VBO && + !_mesa_is_bufferobj(array->BufferObj)) + /* Pack client buffers. */ + stride = align(_mesa_sizeof_type(array->Type) + * array->Size, 4); + else + stride = array->StrideB; vbo_init_array(&render->attrs[attr], attr, - array->StrideB, array->Size, - array->Type, array->BufferObj, - array->Ptr, render->mode == IMM); + stride, array->Size, array->Type, + array->BufferObj, array->Ptr, + render->mode == IMM); } } } @@ -227,6 +243,23 @@ vbo_choose_attrs(GLcontext *ctx, const struct gl_client_array **arrays) vbo_emit_attr(ctx, arrays, VERT_ATTRIB_POS); } +static unsigned +get_max_client_stride(GLcontext *ctx) +{ + struct nouveau_render_state *render = to_render_state(ctx); + int i, s = 0; + + for (i = 0; i < render->attr_count; i++) { + int attr = render->map[i]; + struct nouveau_array_state *a = &render->attrs[attr]; + + if (attr >= 0 && !a->bo) + s = MAX2(a->stride, s); + } + + return s; +} + static void TAG(vbo_render_prims)(GLcontext *ctx, const struct gl_client_array **arrays, const struct _mesa_prim *prims, GLuint nr_prims, @@ -241,12 +274,20 @@ vbo_maybe_split(GLcontext *ctx, const struct gl_client_array **arrays, GLuint min_index, GLuint max_index) { struct nouveau_context *nctx = to_nouveau_context(ctx); + struct nouveau_render_state *render = to_render_state(ctx); unsigned pushbuf_avail = PUSHBUF_DWORDS - 2 * nctx->bo.count, vert_avail = get_max_vertices(ctx, NULL, pushbuf_avail), idx_avail = get_max_vertices(ctx, ib, pushbuf_avail); + int stride; - if ((ib && ib->count > idx_avail) || - (!ib && max_index - min_index > vert_avail)) { + /* Try to keep client buffers smaller than the scratch BOs. */ + if (render->mode == VBO && + (stride = get_max_client_stride(ctx))) + vert_avail = MIN2(vert_avail, + RENDER_SCRATCH_SIZE / stride); + + if (max_index - min_index > vert_avail || + (ib && ib->count > idx_avail)) { struct split_limits limits = { .max_verts = vert_avail, .max_indices = idx_avail, @@ -276,17 +317,21 @@ vbo_bind_vertices(GLcontext *ctx, const struct gl_client_array **arrays, if (attr >= 0) { const struct gl_client_array *array = arrays[attr]; struct nouveau_array_state *a = &render->attrs[attr]; - unsigned delta = (basevertex + min_index) * a->stride, - size = (max_index - min_index + 1) * a->stride; + unsigned delta = (basevertex + min_index) + * array->StrideB; if (a->bo) { a->offset = (intptr_t)array->Ptr + delta; } else { - void *scratch = get_scratch_vbo(ctx, size, - &a->bo, - &a->offset); - - memcpy(scratch, a->buf + delta, size); + int j, n = max_index - min_index + 1; + char *sp = (char *)array->Ptr + delta; + char *dp = get_scratch_vbo(ctx, n * a->stride, + &a->bo, &a->offset); + + for (j = 0; j < n; j++) + memcpy(dp + j * a->stride, + sp + j * array->StrideB, + a->stride); } } } |