mesa: remove _mesa_index_buffer::index_size in favor of index_size_shift
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_vbo_t.c
index 4533069692c1235a2a10a49523776fed7a808720..f516bd3e4ab8519c4c5a77d21e365440d0deea87 100644 (file)
@@ -41,7 +41,7 @@
  * structures. */
 
 static int
-get_array_stride(struct gl_context *ctx, const struct gl_vertex_array *a)
+get_array_stride(struct gl_context *ctx, const struct tnl_vertex_array *a)
 {
        struct nouveau_render_state *render = to_render_state(ctx);
        const struct gl_vertex_buffer_binding *binding = a->BufferBinding;
@@ -49,7 +49,7 @@ get_array_stride(struct gl_context *ctx, const struct gl_vertex_array *a)
        if (render->mode == VBO && !_mesa_is_bufferobj(binding->BufferObj)) {
                const struct gl_array_attributes *attrib = a->VertexAttrib;
                /* Pack client buffers. */
-               return align(_mesa_sizeof_type(attrib->Type) * attrib->Size, 4);
+               return align(attrib->Format._ElementSize, 4);
        } else {
                return binding->Stride;
        }
@@ -57,7 +57,7 @@ get_array_stride(struct gl_context *ctx, const struct gl_vertex_array *a)
 
 static void
 vbo_init_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
-               const struct gl_vertex_array *arrays)
+               const struct tnl_vertex_array *arrays)
 {
        struct nouveau_render_state *render = to_render_state(ctx);
        GLboolean imm = (render->mode == IMM);
@@ -66,9 +66,9 @@ vbo_init_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
        if (ib) {
                GLenum ib_type;
 
-               if (ib->index_size == 4)
+               if (ib->index_size_shift == 2)
                        ib_type = GL_UNSIGNED_INT;
-               else if (ib->index_size == 2)
+               else if (ib->index_size_shift == 1)
                        ib_type = GL_UNSIGNED_SHORT;
                else
                        ib_type = GL_UNSIGNED_BYTE;
@@ -78,7 +78,7 @@ vbo_init_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
        }
 
        FOR_EACH_BOUND_ATTR(render, i, attr) {
-               const struct gl_vertex_array *array = &arrays[attr];
+               const struct tnl_vertex_array *array = &arrays[attr];
                const struct gl_vertex_buffer_binding *binding =
                        array->BufferBinding;
                const struct gl_array_attributes *attrib = array->VertexAttrib;
@@ -86,7 +86,7 @@ vbo_init_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
 
                nouveau_init_array(&render->attrs[attr], attr,
                                   get_array_stride(ctx, array),
-                                  attrib->Size, attrib->Type,
+                                  attrib->Format.Size, attrib->Format.Type,
                                   imm ? binding->BufferObj : NULL,
                                   p, imm, ctx);
        }
@@ -94,7 +94,7 @@ vbo_init_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
 
 static void
 vbo_deinit_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
-                 const struct gl_vertex_array *arrays)
+                 const struct tnl_vertex_array *arrays)
 {
        struct nouveau_render_state *render = to_render_state(ctx);
        int i, attr;
@@ -118,7 +118,7 @@ vbo_deinit_arrays(struct gl_context *ctx, const struct _mesa_index_buffer *ib,
 /* Make some rendering decisions from the GL context. */
 
 static void
-vbo_choose_render_mode(struct gl_context *ctx, const struct gl_vertex_array *arrays)
+vbo_choose_render_mode(struct gl_context *ctx, const struct tnl_vertex_array *arrays)
 {
        struct nouveau_render_state *render = to_render_state(ctx);
        int i;
@@ -136,12 +136,12 @@ vbo_choose_render_mode(struct gl_context *ctx, const struct gl_vertex_array *arr
 }
 
 static void
-vbo_emit_attr(struct gl_context *ctx, const struct gl_vertex_array *arrays,
+vbo_emit_attr(struct gl_context *ctx, const struct tnl_vertex_array *arrays,
              int attr)
 {
        struct nouveau_pushbuf *push = context_push(ctx);
        struct nouveau_render_state *render = to_render_state(ctx);
-       const struct gl_vertex_array *array = &arrays[attr];
+       const struct tnl_vertex_array *array = &arrays[attr];
        const struct gl_vertex_buffer_binding *binding = array->BufferBinding;
        const struct gl_array_attributes *attrib = array->VertexAttrib;
        const GLubyte *p = _mesa_vertex_attrib_address(attrib, binding);
@@ -154,8 +154,8 @@ vbo_emit_attr(struct gl_context *ctx, const struct gl_vertex_array *arrays,
                        return;
 
                /* Constant attribute. */
-               nouveau_init_array(a, attr, binding->Stride, attrib->Size,
-                                  attrib->Type, binding->BufferObj, p,
+               nouveau_init_array(a, attr, binding->Stride, attrib->Format.Size,
+                                  attrib->Format.Type, binding->BufferObj, p,
                                   GL_TRUE, ctx);
                EMIT_IMM(ctx, a, 0);
                nouveau_deinit_array(a);
@@ -166,7 +166,7 @@ vbo_emit_attr(struct gl_context *ctx, const struct gl_vertex_array *arrays,
 
                if (render->mode == VBO) {
                        render->map[info->vbo_index] = attr;
-                       render->vertex_size += attrib->_ElementSize;
+                       render->vertex_size += attrib->Format._ElementSize;
                        render->attr_count = MAX2(render->attr_count,
                                                  info->vbo_index + 1);
                } else {
@@ -179,7 +179,7 @@ vbo_emit_attr(struct gl_context *ctx, const struct gl_vertex_array *arrays,
 #define MAT(a) VERT_ATTRIB_MAT(MAT_ATTRIB_##a)
 
 static void
-vbo_choose_attrs(struct gl_context *ctx, const struct gl_vertex_array *arrays)
+vbo_choose_attrs(struct gl_context *ctx, const struct tnl_vertex_array *arrays)
 {
        struct nouveau_render_state *render = to_render_state(ctx);
        int i;
@@ -222,13 +222,13 @@ vbo_choose_attrs(struct gl_context *ctx, const struct gl_vertex_array *arrays)
 }
 
 static int
-get_max_client_stride(struct gl_context *ctx, const struct gl_vertex_array *arrays)
+get_max_client_stride(struct gl_context *ctx, const struct tnl_vertex_array *arrays)
 {
        struct nouveau_render_state *render = to_render_state(ctx);
        int i, attr, s = 0;
 
        FOR_EACH_BOUND_ATTR(render, i, attr) {
-               const struct gl_vertex_array *a = &arrays[attr];
+               const struct tnl_vertex_array *a = &arrays[attr];
 
                if (!_mesa_is_bufferobj(a->BufferBinding->BufferObj))
                        s = MAX2(s, get_array_stride(ctx, a));
@@ -239,20 +239,21 @@ get_max_client_stride(struct gl_context *ctx, const struct gl_vertex_array *arra
 
 static void
 TAG(vbo_render_prims)(struct gl_context *ctx,
-                     const struct gl_vertex_array *arrays,
+                     const struct tnl_vertex_array *arrays,
                      const struct _mesa_prim *prims, GLuint nr_prims,
                      const struct _mesa_index_buffer *ib,
                      GLboolean index_bounds_valid,
                      GLuint min_index, GLuint max_index,
+                      GLuint num_instances, GLuint base_instance,
                      struct gl_transform_feedback_object *tfb_vertcount,
-                      unsigned stream,
-                     struct gl_buffer_object *indirect);
+                      unsigned stream);
 
 static GLboolean
-vbo_maybe_split(struct gl_context *ctx, const struct gl_vertex_array *arrays,
+vbo_maybe_split(struct gl_context *ctx, const struct tnl_vertex_array *arrays,
            const struct _mesa_prim *prims, GLuint nr_prims,
            const struct _mesa_index_buffer *ib,
-           GLuint min_index, GLuint max_index)
+           GLuint min_index, GLuint max_index,
+            GLuint num_instances, GLuint base_instance)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
        struct nouveau_render_state *render = to_render_state(ctx);
@@ -277,8 +278,9 @@ vbo_maybe_split(struct gl_context *ctx, const struct gl_vertex_array *arrays,
                        .max_vb_size = ~0,
                };
 
-               vbo_split_prims(ctx, arrays, prims, nr_prims, ib, min_index,
-                               max_index, TAG(vbo_render_prims), &limits);
+               _tnl_split_prims(ctx, arrays, prims, nr_prims, ib, min_index,
+                                max_index, num_instances, base_instance,
+                                 TAG(vbo_render_prims), &limits);
                return GL_TRUE;
        }
 
@@ -309,7 +311,7 @@ check_update_array(struct nouveau_array *a, unsigned offset,
 }
 
 static void
-vbo_bind_vertices(struct gl_context *ctx, const struct gl_vertex_array *arrays,
+vbo_bind_vertices(struct gl_context *ctx, const struct tnl_vertex_array *arrays,
                  int base, unsigned min_index, unsigned max_index, int *pdelta)
 {
        struct nouveau_render_state *render = to_render_state(ctx);
@@ -323,7 +325,7 @@ vbo_bind_vertices(struct gl_context *ctx, const struct gl_vertex_array *arrays,
        *pdelta = -1;
 
        FOR_EACH_BOUND_ATTR(render, i, attr) {
-               const struct gl_vertex_array *array = &arrays[attr];
+               const struct tnl_vertex_array *array = &arrays[attr];
                const struct gl_vertex_buffer_binding *binding =
                        array->BufferBinding;
                const struct gl_array_attributes *attrib = array->VertexAttrib;
@@ -381,7 +383,7 @@ vbo_bind_vertices(struct gl_context *ctx, const struct gl_vertex_array *arrays,
 }
 
 static void
-vbo_draw_vbo(struct gl_context *ctx, const struct gl_vertex_array *arrays,
+vbo_draw_vbo(struct gl_context *ctx, const struct tnl_vertex_array *arrays,
             const struct _mesa_prim *prims, GLuint nr_prims,
             const struct _mesa_index_buffer *ib, GLuint min_index,
             GLuint max_index)
@@ -431,7 +433,7 @@ extract_id(struct nouveau_array *a, int i, int j)
 }
 
 static void
-vbo_draw_imm(struct gl_context *ctx, const struct gl_vertex_array *arrays,
+vbo_draw_imm(struct gl_context *ctx, const struct tnl_vertex_array *arrays,
             const struct _mesa_prim *prims, GLuint nr_prims,
             const struct _mesa_index_buffer *ib, GLuint min_index,
             GLuint max_index)
@@ -477,14 +479,14 @@ vbo_draw_imm(struct gl_context *ctx, const struct gl_vertex_array *arrays,
 
 static void
 TAG(vbo_render_prims)(struct gl_context *ctx,
-                     const struct gl_vertex_array *arrays,
+                     const struct tnl_vertex_array *arrays,
                      const struct _mesa_prim *prims, GLuint nr_prims,
                      const struct _mesa_index_buffer *ib,
                      GLboolean index_bounds_valid,
                      GLuint min_index, GLuint max_index,
+                      GLuint num_instances, GLuint base_instance,
                      struct gl_transform_feedback_object *tfb_vertcount,
-                      unsigned stream,
-                     struct gl_buffer_object *indirect)
+                      unsigned stream)
 {
        struct nouveau_render_state *render = to_render_state(ctx);
 
@@ -496,7 +498,7 @@ TAG(vbo_render_prims)(struct gl_context *ctx,
        vbo_choose_attrs(ctx, arrays);
 
        if (vbo_maybe_split(ctx, arrays, prims, nr_prims, ib, min_index,
-                           max_index))
+                           max_index, num_instances, base_instance))
                return;
 
        vbo_init_arrays(ctx, ib, arrays);
@@ -515,14 +517,14 @@ TAG(vbo_render_prims)(struct gl_context *ctx,
 
 static void
 TAG(vbo_check_render_prims)(struct gl_context *ctx,
-                           const struct gl_vertex_array *arrays,
+                           const struct tnl_vertex_array *arrays,
                            const struct _mesa_prim *prims, GLuint nr_prims,
                            const struct _mesa_index_buffer *ib,
                            GLboolean index_bounds_valid,
                            GLuint min_index, GLuint max_index,
+                            GLuint num_instances, GLuint base_instance,
                            struct gl_transform_feedback_object *tfb_vertcount,
-                            unsigned stream,
-                           struct gl_buffer_object *indirect)
+                            unsigned stream)
 {
        struct nouveau_context *nctx = to_nouveau_context(ctx);
 
@@ -531,12 +533,14 @@ TAG(vbo_check_render_prims)(struct gl_context *ctx,
        if (nctx->fallback == HWTNL)
                TAG(vbo_render_prims)(ctx, arrays, prims, nr_prims, ib,
                                      index_bounds_valid, min_index, max_index,
-                                     tfb_vertcount, stream, indirect);
+                                     num_instances, base_instance,
+                                      tfb_vertcount, stream);
 
        if (nctx->fallback == SWTNL)
                _tnl_draw_prims(ctx, arrays, prims, nr_prims, ib,
                                index_bounds_valid, min_index, max_index,
-                               tfb_vertcount, stream, indirect);
+                                num_instances, base_instance,
+                               tfb_vertcount, stream);
 }
 
 static void
@@ -545,17 +549,18 @@ TAG(vbo_draw)(struct gl_context *ctx,
              const struct _mesa_index_buffer *ib,
              GLboolean index_bounds_valid,
              GLuint min_index, GLuint max_index,
+              GLuint num_instances, GLuint base_instance,
              struct gl_transform_feedback_object *tfb_vertcount,
-             unsigned stream,
-             struct gl_buffer_object *indirect)
+             unsigned stream)
 {
        /* Borrow and update the inputs list from the tnl context */
-       _tnl_bind_inputs(ctx);
+       const struct tnl_vertex_array* arrays = _tnl_bind_inputs(ctx);
 
-       TAG(vbo_check_render_prims)(ctx, ctx->Array._DrawArrays,
+       TAG(vbo_check_render_prims)(ctx, arrays,
                                    prims, nr_prims, ib,
                                    index_bounds_valid, min_index, max_index,
-                                   tfb_vertcount, stream, indirect);
+                                    num_instances, base_instance,
+                                   tfb_vertcount, stream);
 }
 
 void
@@ -569,7 +574,6 @@ TAG(vbo_init)(struct gl_context *ctx)
 
        /* Overwrite our draw function */
        ctx->Driver.Draw = TAG(vbo_draw);
-       vbo_use_buffer_objects(ctx);
 }
 
 void