+static void
+st_indirect_draw_vbo(struct gl_context *ctx,
+ GLuint mode,
+ struct gl_buffer_object *indirect_data,
+ GLsizeiptr indirect_offset,
+ unsigned draw_count,
+ unsigned stride,
+ struct gl_buffer_object *indirect_params,
+ GLsizeiptr indirect_params_offset,
+ const struct _mesa_index_buffer *ib)
+{
+ struct st_context *st = st_context(ctx);
+ struct pipe_index_buffer ibuffer = {0};
+ struct pipe_draw_info info;
+
+ /* Mesa core state should have been validated already */
+ assert(ctx->NewState == 0x0);
+ assert(stride);
+
+ /* Validate state. */
+ if (st->dirty.st || st->dirty.mesa || ctx->NewDriverState) {
+ st_validate_state(st, ST_PIPELINE_RENDER);
+ }
+
+ if (st->vertex_array_out_of_memory) {
+ return;
+ }
+
+ util_draw_init_info(&info);
+
+ if (ib) {
+ if (!setup_index_buffer(st, ib, &ibuffer)) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "gl%sDrawElementsIndirect%s",
+ (draw_count > 1) ? "Multi" : "",
+ indirect_params ? "CountARB" : "");
+ return;
+ }
+
+ info.indexed = TRUE;
+ }
+
+ info.mode = translate_prim(ctx, mode);
+ info.vertices_per_patch = ctx->TessCtrlProgram.patch_vertices;
+ info.indirect = st_buffer_object(indirect_data)->buffer;
+ info.indirect_offset = indirect_offset;
+
+ /* Primitive restart is not handled by the VBO module in this case. */
+ info.primitive_restart = ctx->Array._PrimitiveRestart;
+ info.restart_index = ctx->Array.RestartIndex;
+
+ if (ST_DEBUG & DEBUG_DRAW) {
+ debug_printf("st/draw indirect: mode %s drawcount %d indexed %d\n",
+ u_prim_name(info.mode),
+ draw_count,
+ info.indexed);
+ }
+
+ if (!st->has_multi_draw_indirect) {
+ int i;
+
+ assert(!indirect_params);
+ info.indirect_count = 1;
+ for (i = 0; i < draw_count; i++) {
+ info.drawid = i;
+ cso_draw_vbo(st->cso_context, &info);
+ info.indirect_offset += stride;
+ }
+ } else {
+ info.indirect_count = draw_count;
+ info.indirect_stride = stride;
+ if (indirect_params) {
+ info.indirect_params = st_buffer_object(indirect_params)->buffer;
+ info.indirect_params_offset = indirect_params_offset;
+ }
+ cso_draw_vbo(st->cso_context, &info);
+ }
+}
+