Squashed commit of the following:
[mesa.git] / src / gallium / drivers / nv50 / nv50_vbo.c
index 9d49ad6db24f30cffefe1b84b4689ee1727b0987..609145db88afaa36ecbc9243cf58c8e52aa7fba2 100644 (file)
 
 #include "nouveau/nouveau_util.h"
 #include "nv50_context.h"
-
-#define NV50_USING_LOATHED_EDGEFLAG(ctx) ((ctx)->vertprog->cfg.edgeflag_in < 16)
-
-static INLINE unsigned
-nv50_prim(unsigned mode)
-{
-       switch (mode) {
-       case PIPE_PRIM_POINTS: return NV50TCL_VERTEX_BEGIN_POINTS;
-       case PIPE_PRIM_LINES: return NV50TCL_VERTEX_BEGIN_LINES;
-       case PIPE_PRIM_LINE_LOOP: return NV50TCL_VERTEX_BEGIN_LINE_LOOP;
-       case PIPE_PRIM_LINE_STRIP: return NV50TCL_VERTEX_BEGIN_LINE_STRIP;
-       case PIPE_PRIM_TRIANGLES: return NV50TCL_VERTEX_BEGIN_TRIANGLES;
-       case PIPE_PRIM_TRIANGLE_STRIP:
-               return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP;
-       case PIPE_PRIM_TRIANGLE_FAN: return NV50TCL_VERTEX_BEGIN_TRIANGLE_FAN;
-       case PIPE_PRIM_QUADS: return NV50TCL_VERTEX_BEGIN_QUADS;
-       case PIPE_PRIM_QUAD_STRIP: return NV50TCL_VERTEX_BEGIN_QUAD_STRIP;
-       case PIPE_PRIM_POLYGON: return NV50TCL_VERTEX_BEGIN_POLYGON;
-       case PIPE_PRIM_LINES_ADJACENCY:
-               return NV50TCL_VERTEX_BEGIN_LINES_ADJACENCY;
-       case PIPE_PRIM_LINE_STRIP_ADJACENCY:
-               return NV50TCL_VERTEX_BEGIN_LINE_STRIP_ADJACENCY;
-       case PIPE_PRIM_TRIANGLES_ADJACENCY:
-               return NV50TCL_VERTEX_BEGIN_TRIANGLES_ADJACENCY;
-       case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:
-               return NV50TCL_VERTEX_BEGIN_TRIANGLE_STRIP_ADJACENCY;
-       default:
-               break;
-       }
-
-       NOUVEAU_ERR("invalid primitive type %d\n", mode);
-       return NV50TCL_VERTEX_BEGIN_POINTS;
-}
+#include "nv50_resource.h"
 
 static INLINE uint32_t
 nv50_vbo_type_to_hw(enum pipe_format format)
@@ -172,7 +140,7 @@ instance_init(struct nv50_context *nv50, struct instance *a, unsigned first)
                if (a[i].divisor) {
                        vb = &nv50->vtxbuf[ve->vertex_buffer_index];
 
-                       a[i].bo = nouveau_bo(vb->buffer);
+                       a[i].bo = nv50_resource(vb->buffer)->bo;
                        a[i].stride = vb->stride;
                        a[i].step = first % a[i].divisor;
                        a[i].delta = vb->buffer_offset + ve->src_offset +
@@ -340,14 +308,14 @@ inline_edgeflag(void *priv, boolean enabled)
 
 static void
 nv50_draw_elements_inline(struct pipe_context *pipe,
-                         struct pipe_buffer *indexBuffer, unsigned indexSize,
+                         struct pipe_resource *indexBuffer, unsigned indexSize,
                          unsigned mode, unsigned start, unsigned count,
                          unsigned startInstance, unsigned instanceCount)
 {
-       struct pipe_screen *pscreen = pipe->screen;
        struct nv50_context *nv50 = nv50_context(pipe);
        struct nouveau_channel *chan = nv50->screen->tesla->channel;
        struct nouveau_grobj *tesla = nv50->screen->tesla;
+       struct pipe_transfer *transfer;
        struct instance a[16];
        struct inline_ctx ctx;
        struct u_split_prim s;
@@ -370,7 +338,7 @@ nv50_draw_elements_inline(struct pipe_context *pipe,
        s.edge = inline_edgeflag;
 
        ctx.nv50 = nv50;
-       ctx.map = pipe_buffer_map(pscreen, indexBuffer, PIPE_BUFFER_USAGE_CPU_READ);
+       ctx.map = pipe_buffer_map(pipe, indexBuffer, PIPE_TRANSFER_READ, &transfer);
        assert(ctx.map);
        if (!ctx.map)
                return;
@@ -413,12 +381,12 @@ nv50_draw_elements_inline(struct pipe_context *pipe,
                nzi = TRUE;
        }
 
-       pipe_buffer_unmap(pscreen, indexBuffer);
+       pipe_buffer_unmap(pipe, indexBuffer, transfer);
 }
 
 void
 nv50_draw_elements_instanced(struct pipe_context *pipe,
-                            struct pipe_buffer *indexBuffer,
+                            struct pipe_resource *indexBuffer,
                             unsigned indexSize,
                             unsigned mode, unsigned start, unsigned count,
                             unsigned startInstance, unsigned instanceCount)
@@ -439,7 +407,7 @@ nv50_draw_elements_instanced(struct pipe_context *pipe,
                                             instanceCount);
                return;
        } else
-       if (!(indexBuffer->usage & PIPE_BUFFER_USAGE_INDEX) || indexSize == 1) {
+       if (!(indexBuffer->bind & PIPE_BIND_INDEX_BUFFER) || indexSize == 1) {
                nv50_draw_elements_inline(pipe, indexBuffer, indexSize,
                                          mode, start, count, startInstance,
                                          instanceCount);
@@ -464,7 +432,8 @@ nv50_draw_elements_instanced(struct pipe_context *pipe,
                if (indexSize == 4) {
                        BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U32 | 0x30000, 0);
                        OUT_RING  (chan, count);
-                       nouveau_pushbuf_submit(chan, nouveau_bo(indexBuffer),
+                       nouveau_pushbuf_submit(chan, 
+                                              nv50_resource(indexBuffer)->bo,
                                               start << 2, count << 2);
                } else
                if (indexSize == 2) {
@@ -476,7 +445,8 @@ nv50_draw_elements_instanced(struct pipe_context *pipe,
                        OUT_RING  (chan, ((start & 1) << 31) | count);
                        BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U16 | 0x30000, 0);
                        OUT_RING  (chan, dwords);
-                       nouveau_pushbuf_submit(chan, nouveau_bo(indexBuffer),
+                       nouveau_pushbuf_submit(chan,
+                                              nv50_resource(indexBuffer)->bo,
                                               vb_start << 1, dwords << 2);
                        BEGIN_RING(chan, tesla, NV50TCL_VB_ELEMENT_U16_SETUP, 1);
                        OUT_RING  (chan, 0);
@@ -490,7 +460,7 @@ nv50_draw_elements_instanced(struct pipe_context *pipe,
 
 void
 nv50_draw_elements(struct pipe_context *pipe,
-                  struct pipe_buffer *indexBuffer, unsigned indexSize,
+                  struct pipe_resource *indexBuffer, unsigned indexSize,
                   unsigned mode, unsigned start, unsigned count)
 {
        nv50_draw_elements_instanced(pipe, indexBuffer, indexSize,
@@ -506,7 +476,7 @@ nv50_vbo_static_attrib(struct nv50_context *nv50, unsigned attrib,
 {
        struct nouveau_stateobj *so;
        struct nouveau_grobj *tesla = nv50->screen->tesla;
-       struct nouveau_bo *bo = nouveau_bo(vb->buffer);
+       struct nouveau_bo *bo = nv50_resource(vb->buffer)->bo;
        float v[4];
        int ret;
        unsigned nr_components = util_format_get_nr_components(ve->src_format);
@@ -582,9 +552,16 @@ nv50_vbo_validate(struct nv50_context *nv50)
        if (nv50->vtxbuf_nr == 0)
                return NULL;
 
-       if (NV50_USING_LOATHED_EDGEFLAG(nv50))
+       nv50->vbo_fifo = 0;
+       if (nv50->screen->force_push ||
+           nv50->vertprog->cfg.edgeflag_in < 16)
                nv50->vbo_fifo = 0xffff;
-       nv50->vbo_fifo = 0xffff;
+
+       for (i = 0; i < nv50->vtxbuf_nr; i++) {
+               if (nv50->vtxbuf[i].stride &&
+                   !(nv50->vtxbuf[i].buffer->bind & PIPE_BIND_VERTEX_BUFFER))
+                       nv50->vbo_fifo = 0xffff;
+       }
 
        n_ve = MAX2(nv50->vtxelt->num_elements, nv50->state.vtxelt_nr);
 
@@ -597,7 +574,7 @@ nv50_vbo_validate(struct nv50_context *nv50)
                struct pipe_vertex_element *ve = &nv50->vtxelt->pipe[i];
                struct pipe_vertex_buffer *vb =
                        &nv50->vtxbuf[ve->vertex_buffer_index];
-               struct nouveau_bo *bo = nouveau_bo(vb->buffer);
+               struct nouveau_bo *bo = nv50_resource(vb->buffer)->bo;
                uint32_t hw = nv50->vtxelt->hw[i];
 
                if (!vb->stride &&
@@ -634,10 +611,10 @@ nv50_vbo_validate(struct nv50_context *nv50)
 
                /* vertex array limits */
                so_method(vtxbuf, tesla, NV50TCL_VERTEX_ARRAY_LIMIT_HIGH(i), 2);
-               so_reloc (vtxbuf, bo, vb->buffer->size - 1,
+               so_reloc (vtxbuf, bo, vb->buffer->width0 - 1,
                          NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD |
                          NOUVEAU_BO_HIGH, 0, 0);
-               so_reloc (vtxbuf, bo, vb->buffer->size - 1,
+               so_reloc (vtxbuf, bo, vb->buffer->width0 - 1,
                          NOUVEAU_BO_VRAM | NOUVEAU_BO_GART | NOUVEAU_BO_RD |
                          NOUVEAU_BO_LOW, 0, 0);
        }