gallium: add start_slot parameter to set_vertex_buffers
[mesa.git] / src / gallium / drivers / nv30 / nv30_state.c
index 3b4cc99887721248f81bbeb4bb865894c4c33c67..af8bb449fceaa535a3ba722a51ac19b8ce6983b2 100644 (file)
@@ -23,6 +23,7 @@
  *
  */
 
+#include "util/u_helpers.h"
 #include "util/u_inlines.h"
 
 #include "nouveau/nouveau_gldefs.h"
@@ -323,6 +324,12 @@ nv30_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
    struct pipe_resource *buf = cb ? cb->buffer : NULL;
    unsigned size;
 
+   if (cb && cb->user_buffer) {
+      buf = nouveau_user_buffer_create(pipe->screen, (void*)cb->user_buffer,
+                                       cb->buffer_size,
+                                       PIPE_BIND_CONSTANT_BUFFER);
+   }
+
    size = 0;
    if (buf)
       size = buf->width0 / (4 * sizeof(float));
@@ -337,6 +344,10 @@ nv30_set_constant_buffer(struct pipe_context *pipe, uint shader, uint index,
       nv30->fragprog.constbuf_nr = size;
       nv30->dirty |= NV30_NEW_FRAGCONST;
    }
+
+   if (cb && cb->user_buffer) {
+      pipe_resource_reference(&buf, NULL);
+   }
 }
 
 static void
@@ -383,21 +394,15 @@ nv30_set_viewport_state(struct pipe_context *pipe,
 
 static void
 nv30_set_vertex_buffers(struct pipe_context *pipe,
-                        unsigned count,
+                        unsigned start_slot, unsigned count,
                         const struct pipe_vertex_buffer *vb)
 {
     struct nv30_context *nv30 = nv30_context(pipe);
-    unsigned i;
 
     nouveau_bufctx_reset(nv30->bufctx, BUFCTX_VTXBUF);
 
-    for (i = 0; i < count; ++i)
-       pipe_resource_reference(&nv30->vtxbuf[i].buffer, vb[i].buffer);
-    for (; i < nv30->num_vtxbufs; ++i)
-       pipe_resource_reference(&nv30->vtxbuf[i].buffer, NULL);
-
-    memcpy(nv30->vtxbuf, vb, sizeof(*vb) * count);
-    nv30->num_vtxbufs = count;
+    util_set_vertex_buffers_count(nv30->vtxbuf, &nv30->num_vtxbufs,
+                                  vb, start_slot, count);
 
     nv30->dirty |= NV30_NEW_ARRAYS;
 }
@@ -410,9 +415,12 @@ nv30_set_index_buffer(struct pipe_context *pipe,
 
     if (ib) {
        pipe_resource_reference(&nv30->idxbuf.buffer, ib->buffer);
-       memcpy(&nv30->idxbuf, ib, sizeof(nv30->idxbuf));
+       nv30->idxbuf.index_size = ib->index_size;
+       nv30->idxbuf.offset = ib->offset;
+       nv30->idxbuf.user_buffer = ib->user_buffer;
     } else {
        pipe_resource_reference(&nv30->idxbuf.buffer, NULL);
+       nv30->idxbuf.user_buffer = NULL;
     }
 }