Merge remote branch 'origin/master' into nv50-compiler
[mesa.git] / src / gallium / drivers / nv50 / nv50_push.c
index 96a1f32d304f7af0aee5cfae50166f011b43269d..380f69406a27d8925d3be34e4fdda4bd89ac06b0 100644 (file)
@@ -2,9 +2,10 @@
 #include "pipe/p_state.h"
 #include "util/u_inlines.h"
 #include "util/u_format.h"
+#include "util/u_split_prim.h"
 
-#include "nouveau/nouveau_util.h"
 #include "nv50_context.h"
+#include "nv50_resource.h"
 
 struct push_context {
    struct nv50_context *nv50;
@@ -12,6 +13,7 @@ struct push_context {
    unsigned vtx_size;
 
    void *idxbuf;
+   int32_t idxbias;
    unsigned idxsize;
 
    float edgeflag;
@@ -106,8 +108,9 @@ emit_vertex(struct push_context *ctx, unsigned n)
    int i;
 
    if (ctx->edgeflag_attr < 16) {
-      float *edgeflag = ctx->attr[ctx->edgeflag_attr].map +
-                        ctx->attr[ctx->edgeflag_attr].stride * n;
+      float *edgeflag = (float *)
+         ((uint8_t *)ctx->attr[ctx->edgeflag_attr].map +
+          ctx->attr[ctx->edgeflag_attr].stride * n);
 
       if (*edgeflag != ctx->edgeflag) {
          BEGIN_RING(chan, tesla, NV50TCL_EDGEFLAG_ENABLE, 1);
@@ -118,7 +121,8 @@ emit_vertex(struct push_context *ctx, unsigned n)
 
    BEGIN_RING_NI(chan, tesla, NV50TCL_VERTEX_DATA, ctx->vtx_size);
    for (i = 0; i < ctx->attr_nr; i++)
-      ctx->attr[i].push(chan, ctx->attr[i].map + ctx->attr[i].stride * n);
+      ctx->attr[i].push(chan,
+                       (uint8_t *)ctx->attr[i].map + ctx->attr[i].stride * n);
 }
 
 static void
@@ -142,6 +146,16 @@ emit_elt08(void *priv, unsigned start, unsigned count)
       emit_vertex(ctx, idxbuf[start++]);
 }
 
+static void
+emit_elt08_biased(void *priv, unsigned start, unsigned count)
+{
+   struct push_context *ctx = priv;
+   uint8_t *idxbuf = ctx->idxbuf;
+
+   while (count--)
+      emit_vertex(ctx, idxbuf[start++] + ctx->idxbias);
+}
+
 static void
 emit_elt16(void *priv, unsigned start, unsigned count)
 {
@@ -152,6 +166,16 @@ emit_elt16(void *priv, unsigned start, unsigned count)
       emit_vertex(ctx, idxbuf[start++]);
 }
 
+static void
+emit_elt16_biased(void *priv, unsigned start, unsigned count)
+{
+   struct push_context *ctx = priv;
+   uint16_t *idxbuf = ctx->idxbuf;
+
+   while (count--)
+      emit_vertex(ctx, idxbuf[start++] + ctx->idxbias);
+}
+
 static void
 emit_elt32(void *priv, unsigned start, unsigned count)
 {
@@ -162,6 +186,16 @@ emit_elt32(void *priv, unsigned start, unsigned count)
       emit_vertex(ctx, idxbuf[start++]);
 }
 
+static void
+emit_elt32_biased(void *priv, unsigned start, unsigned count)
+{
+   struct push_context *ctx = priv;
+   uint32_t *idxbuf = ctx->idxbuf;
+
+   while (count--)
+      emit_vertex(ctx, idxbuf[start++] + ctx->idxbias);
+}
+
 static void
 emit_verts(void *priv, unsigned start, unsigned count)
 {
@@ -171,7 +205,8 @@ emit_verts(void *priv, unsigned start, unsigned count)
 
 void
 nv50_push_elements_instanced(struct pipe_context *pipe,
-                             struct pipe_buffer *idxbuf, unsigned idxsize,
+                             struct pipe_resource *idxbuf,
+                             unsigned idxsize, int idxbias,
                              unsigned mode, unsigned start, unsigned count,
                              unsigned i_start, unsigned i_count)
 {
@@ -183,7 +218,7 @@ nv50_push_elements_instanced(struct pipe_context *pipe,
                                4; /* potential edgeflag enable/disable */
    const unsigned v_overhead = 1 + /* VERTEX_DATA packet header */
                                2; /* potential edgeflag modification */
-   struct u_split_prim s;
+   struct util_split_prim s;
    unsigned vtx_size;
    boolean nzi = FALSE;
    int i;
@@ -193,13 +228,13 @@ nv50_push_elements_instanced(struct pipe_context *pipe,
    ctx.idxbuf = NULL;
    ctx.vtx_size = 0;
    ctx.edgeflag = 0.5f;
-   ctx.edgeflag_attr = nv50->vertprog->cfg.edgeflag_in;
+   ctx.edgeflag_attr = nv50->vertprog->vp.edgeflag;
 
    /* map vertex buffers, determine vertex size */
    for (i = 0; i < nv50->vtxelt->num_elements; i++) {
       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;
       unsigned size, nr_components, n;
 
       if (!(nv50->vbo_fifo & (1 << i)))
@@ -210,14 +245,14 @@ nv50_push_elements_instanced(struct pipe_context *pipe,
          assert(bo->map);
          return;
       }
-      ctx.attr[n].map = bo->map + vb->buffer_offset + ve->src_offset;
+      ctx.attr[n].map = (uint8_t *)bo->map + vb->buffer_offset + ve->src_offset;
       nouveau_bo_unmap(bo);
 
       ctx.attr[n].stride = vb->stride;
       ctx.attr[n].divisor = ve->instance_divisor;
       if (ctx.attr[n].divisor) {
          ctx.attr[n].step = i_start % ve->instance_divisor;
-         ctx.attr[n].map += i_start * vb->stride;
+         ctx.attr[n].map = (uint8_t *)ctx.attr[n].map + i_start * vb->stride;
       }
 
       size = util_format_get_component_bits(ve->src_format,
@@ -260,13 +295,14 @@ nv50_push_elements_instanced(struct pipe_context *pipe,
 
    /* map index buffer, if present */
    if (idxbuf) {
-      struct nouveau_bo *bo = nouveau_bo(idxbuf);
+      struct nouveau_bo *bo = nv50_resource(idxbuf)->bo;
 
       if (nouveau_bo_map(bo, NOUVEAU_BO_RD)) {
          assert(bo->map);
          return;
       }
       ctx.idxbuf = bo->map;
+      ctx.idxbias = idxbias;
       ctx.idxsize = idxsize;
       nouveau_bo_unmap(bo);
    }
@@ -275,12 +311,12 @@ nv50_push_elements_instanced(struct pipe_context *pipe,
    s.edge = emit_edgeflag;
    if (idxbuf) {
       if (idxsize == 1)
-         s.emit = emit_elt08;
+         s.emit = idxbias ? emit_elt08_biased : emit_elt08;
       else
       if (idxsize == 2)
-         s.emit = emit_elt16;
+         s.emit = idxbias ? emit_elt16_biased : emit_elt16;
       else
-         s.emit = emit_elt32;
+         s.emit = idxbias ? emit_elt32_biased : emit_elt32;
    } else
       s.emit = emit_verts;
 
@@ -297,10 +333,10 @@ nv50_push_elements_instanced(struct pipe_context *pipe,
               ctx.attr[i].divisor != ++ctx.attr[i].step)
             continue;
          ctx.attr[i].step = 0;
-         ctx.attr[i].map += ctx.attr[i].stride;
+         ctx.attr[i].map = (uint8_t *)ctx.attr[i].map + ctx.attr[i].stride;
       }
 
-      u_split_prim_init(&s, mode, start, count);
+      util_split_prim_init(&s, mode, start, count);
       do {
          if (AVAIL_RING(chan) < p_overhead + (6 * vtx_size)) {
             FIRE_RING(chan);
@@ -316,7 +352,7 @@ nv50_push_elements_instanced(struct pipe_context *pipe,
 
          BEGIN_RING(chan, tesla, NV50TCL_VERTEX_BEGIN, 1);
          OUT_RING  (chan, nv50_prim(s.mode) | (nzi ? (1 << 28) : 0));
-         done = u_split_prim_next(&s, max_verts);
+         done = util_split_prim_next(&s, max_verts);
          BEGIN_RING(chan, tesla, NV50TCL_VERTEX_END, 1);
          OUT_RING  (chan, 0);
       } while (!done);