gallium: separate out floating-point CAPs into its own enum
[mesa.git] / src / gallium / drivers / nvc0 / nvc0_vbo.c
index 19fd85273c105ae5a5388d8d123960937d247d4f..50e99ac5df3476b97f10662895a7be9737bf42d4 100644 (file)
@@ -51,8 +51,6 @@ nvc0_vertex_state_create(struct pipe_context *pipe,
     struct translate_key transkey;
     unsigned i;
 
-    assert(num_elements);
-
     so = MALLOC(sizeof(*so) +
                 num_elements * sizeof(struct nvc0_vertex_element));
     if (!so)
@@ -131,13 +129,13 @@ nvc0_emit_vtxattr(struct nvc0_context *nvc0, struct pipe_vertex_buffer *vb,
 {
    const void *data;
    struct nouveau_channel *chan = nvc0->screen->base.channel;
-   struct nvc0_resource *res = nvc0_resource(vb->buffer);
+   struct nv04_resource *res = nv04_resource(vb->buffer);
    float v[4];
    int i;
    const unsigned nc = util_format_get_nr_components(ve->src_format);
 
-   data = nvc0_resource_map_offset(nvc0, res, vb->buffer_offset +
-                                   ve->src_offset, NOUVEAU_BO_RD);
+   data = nouveau_resource_map_offset(&nvc0->base, res, vb->buffer_offset +
+                                      ve->src_offset, NOUVEAU_BO_RD);
 
    util_format_read_4f(ve->src_format, v, 0, data, 0, 0, 0, 1, 1);
 
@@ -167,7 +165,7 @@ static void
 nvc0_prevalidate_vbufs(struct nvc0_context *nvc0)
 {
    struct pipe_vertex_buffer *vb;
-   struct nvc0_resource *buf;
+   struct nv04_resource *buf;
    int i;
    uint32_t base, size;
 
@@ -179,27 +177,27 @@ nvc0_prevalidate_vbufs(struct nvc0_context *nvc0)
       vb = &nvc0->vtxbuf[i];
       if (!vb->stride)
          continue;
-      buf = nvc0_resource(vb->buffer);
+      buf = nv04_resource(vb->buffer);
 
       /* NOTE: user buffers with temporary storage count as mapped by GPU */
-      if (!nvc0_resource_mapped_by_gpu(vb->buffer)) {
+      if (!nouveau_resource_mapped_by_gpu(vb->buffer)) {
          if (nvc0->vbo_push_hint) {
             nvc0->vbo_fifo = ~0;
             continue;
          } else {
-            if (buf->status & NVC0_BUFFER_STATUS_USER_MEMORY) {
+            if (buf->status & NOUVEAU_BUFFER_STATUS_USER_MEMORY) {
                nvc0->vbo_user |= 1 << i;
                assert(vb->stride > vb->buffer_offset);
                nvc0_vbuf_range(nvc0, i, &base, &size);
-               nvc0_user_buffer_upload(buf, base, size);
+               nouveau_user_buffer_upload(buf, base, size);
             } else {
-               nvc0_buffer_migrate(nvc0, buf, NOUVEAU_BO_GART);
+               nouveau_buffer_migrate(&nvc0->base, buf, NOUVEAU_BO_GART);
             }
-            nvc0->vbo_dirty = TRUE;
+            nvc0->base.vbo_dirty = TRUE;
          }
       }
       nvc0_bufctx_add_resident(nvc0, NVC0_BUFCTX_VERTEX, buf, NOUVEAU_BO_RD);
-      nvc0_buffer_adjust_score(nvc0, buf, 1);
+      nouveau_buffer_adjust_score(&nvc0->base, buf, 1);
    }
 }
 
@@ -215,7 +213,7 @@ nvc0_update_user_vbufs(struct nvc0_context *nvc0)
       struct pipe_vertex_element *ve = &nvc0->vertex->element[i].pipe;
       const int b = ve->vertex_buffer_index;
       struct pipe_vertex_buffer *vb = &nvc0->vtxbuf[b];
-      struct nvc0_resource *buf = nvc0_resource(vb->buffer);
+      struct nv04_resource *buf = nv04_resource(vb->buffer);
 
       if (!(nvc0->vbo_user & (1 << b)))
          continue;
@@ -228,7 +226,7 @@ nvc0_update_user_vbufs(struct nvc0_context *nvc0)
 
       if (!(written & (1 << b))) {
          written |= 1 << b;
-         nvc0_user_buffer_upload(buf, base, size);
+         nouveau_user_buffer_upload(buf, base, size);
       }
       offset = vb->buffer_offset + ve->src_offset;
 
@@ -240,7 +238,7 @@ nvc0_update_user_vbufs(struct nvc0_context *nvc0)
       OUT_RESRCh(chan, buf, offset, NOUVEAU_BO_RD);
       OUT_RESRCl(chan, buf, offset, NOUVEAU_BO_RD);
    }
-   nvc0->vbo_dirty = TRUE;
+   nvc0->base.vbo_dirty = TRUE;
 }
 
 static INLINE void
@@ -252,7 +250,7 @@ nvc0_release_user_vbufs(struct nvc0_context *nvc0)
       int i = ffs(vbo_user) - 1;
       vbo_user &= ~(1 << i);
 
-      nvc0_buffer_release_gpu_storage(nvc0_resource(nvc0->vtxbuf[i].buffer));
+      nouveau_buffer_release_gpu_storage(nv04_resource(nvc0->vtxbuf[i].buffer));
    }
 }
 
@@ -265,7 +263,7 @@ nvc0_vertex_arrays_validate(struct nvc0_context *nvc0)
    struct nvc0_vertex_element *ve;
    unsigned i;
 
-   if (unlikely(vertex->need_conversion)) {
+   if (unlikely(vertex->need_conversion || NVC0_USING_EDGEFLAG(nvc0))) {
       nvc0->vbo_fifo = ~0;
       nvc0->vbo_user = 0;
    } else {
@@ -286,7 +284,7 @@ nvc0_vertex_arrays_validate(struct nvc0_context *nvc0)
    }
 
    for (i = 0; i < vertex->num_elements; ++i) {
-      struct nvc0_resource *res;
+      struct nv04_resource *res;
       unsigned size, offset;
       
       ve = &vertex->element[i];
@@ -303,7 +301,7 @@ nvc0_vertex_arrays_validate(struct nvc0_context *nvc0)
          IMMED_RING(chan, RING_3D(VERTEX_ARRAY_PER_INSTANCE(i)), 0);
       }
 
-      res = nvc0_resource(vb->buffer);
+      res = nv04_resource(vb->buffer);
 
       if (nvc0->vbo_fifo || unlikely(vb->stride == 0)) {
          if (!nvc0->vbo_fifo)
@@ -329,6 +327,8 @@ nvc0_vertex_arrays_validate(struct nvc0_context *nvc0)
    for (; i < nvc0->state.num_vtxelts; ++i) {
       BEGIN_RING(chan, RING_3D(VERTEX_ATTRIB_FORMAT(i)), 1);
       OUT_RING  (chan, NVC0_3D_VERTEX_ATTRIB_INACTIVE);
+      if (unlikely(nvc0->state.instance_elts & (1 << i)))
+         IMMED_RING(chan, RING_3D(VERTEX_ARRAY_PER_INSTANCE(i)), 0);
       BEGIN_RING(chan, RING_3D(VERTEX_ARRAY_FETCH(i)), 1);
       OUT_RING  (chan, 0);
    }
@@ -369,9 +369,11 @@ nvc0_prim_gl(unsigned prim)
 static void
 nvc0_draw_vbo_flush_notify(struct nouveau_channel *chan)
 {
-   struct nvc0_context *nvc0 = chan->user_private;
+   struct nvc0_screen *screen = chan->user_private;
+
+   nouveau_fence_update(&screen->base, TRUE);
 
-   nvc0_bufctx_emit_relocs(nvc0);
+   nvc0_bufctx_emit_relocs(screen->cur_ctx);
 }
 
 static void
@@ -382,8 +384,10 @@ nvc0_draw_arrays(struct nvc0_context *nvc0,
    struct nouveau_channel *chan = nvc0->screen->base.channel;
    unsigned prim;
 
-   chan->flush_notify = nvc0_draw_vbo_flush_notify;
-   chan->user_private = nvc0;
+   if (nvc0->state.index_bias) {
+      IMMED_RING(chan, RING_3D(VB_ELEMENT_BASE), 0);
+      nvc0->state.index_bias = 0;
+   }
 
    prim = nvc0_prim_gl(mode);
 
@@ -397,8 +401,6 @@ nvc0_draw_arrays(struct nvc0_context *nvc0,
 
       prim |= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT;
    }
-
-   chan->flush_notify = NULL;
 }
 
 static void
@@ -500,9 +502,6 @@ nvc0_draw_elements(struct nvc0_context *nvc0, boolean shorten,
    unsigned prim;
    const unsigned index_size = nvc0->idxbuf.index_size;
 
-   chan->flush_notify = nvc0_draw_vbo_flush_notify;
-   chan->user_private = nvc0;
-
    prim = nvc0_prim_gl(mode);
 
    if (index_bias != nvc0->state.index_bias) {
@@ -511,12 +510,12 @@ nvc0_draw_elements(struct nvc0_context *nvc0, boolean shorten,
       nvc0->state.index_bias = index_bias;
    }
 
-   if (nvc0_resource_mapped_by_gpu(nvc0->idxbuf.buffer)) {
-      struct nvc0_resource *res = nvc0_resource(nvc0->idxbuf.buffer);
+   if (nouveau_resource_mapped_by_gpu(nvc0->idxbuf.buffer)) {
+      struct nv04_resource *res = nv04_resource(nvc0->idxbuf.buffer);
       unsigned offset = nvc0->idxbuf.offset;
       unsigned limit = nvc0->idxbuf.buffer->width0 - 1;
 
-      nvc0_buffer_adjust_score(nvc0, res, 1);
+      nouveau_buffer_adjust_score(&nvc0->base, res, 1);
 
       while (instance_count--) {
          MARK_RING (chan, 11, 4);
@@ -537,8 +536,9 @@ nvc0_draw_elements(struct nvc0_context *nvc0, boolean shorten,
          mode |= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT;
       }
    } else {
-      data = nvc0_resource_map_offset(nvc0, nvc0_resource(nvc0->idxbuf.buffer),
-                                      nvc0->idxbuf.offset, NOUVEAU_BO_RD);
+      data = nouveau_resource_map_offset(&nvc0->base,
+                                         nv04_resource(nvc0->idxbuf.buffer),
+                                         nvc0->idxbuf.offset, NOUVEAU_BO_RD);
       if (!data)
          return;
 
@@ -567,8 +567,6 @@ nvc0_draw_elements(struct nvc0_context *nvc0, boolean shorten,
          prim |= NVC0_3D_VERTEX_BEGIN_GL_INSTANCE_NEXT;
       }
    }
-
-   chan->flush_notify = NULL;
 }
 
 void
@@ -593,10 +591,14 @@ nvc0_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
    if (nvc0->vbo_user && !(nvc0->dirty & (NVC0_NEW_VERTEX | NVC0_NEW_ARRAYS)))
       nvc0_update_user_vbufs(nvc0);
 
-   nvc0_state_validate(nvc0);
+   /* 8 as minimum to avoid immediate double validation of new buffers */
+   nvc0_state_validate(nvc0, ~0, 8);
+
+   chan->flush_notify = nvc0_draw_vbo_flush_notify;
 
    if (nvc0->vbo_fifo) {
       nvc0_push_vbo(nvc0, info);
+      chan->flush_notify = nvc0_default_flush_notify;
       return;
    }
 
@@ -607,10 +609,10 @@ nvc0_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
       OUT_RING  (chan, info->start_instance);
    }
 
-   if (nvc0->vbo_dirty) {
+   if (nvc0->base.vbo_dirty) {
       BEGIN_RING(chan, RING_3D(VERTEX_ARRAY_FLUSH), 1);
       OUT_RING  (chan, 0);
-      nvc0->vbo_dirty = FALSE;
+      nvc0->base.vbo_dirty = FALSE;
    }
 
    if (!info->indexed) {
@@ -647,6 +649,7 @@ nvc0_draw_vbo(struct pipe_context *pipe, const struct pipe_draw_info *info)
                          info->mode, info->start, info->count,
                          info->instance_count, info->index_bias);
    }
+   chan->flush_notify = nvc0_default_flush_notify;
 
    nvc0_release_user_vbufs(nvc0);
 }