summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/draw.c
diff options
context:
space:
mode:
authorMathias Fröhlich <[email protected]>2018-10-29 06:13:20 +0100
committerMathias Fröhlich <[email protected]>2018-11-01 06:08:49 +0100
commit3d64f3c79564f562cc56add8b8ba9659fd19a97d (patch)
treea11cb435f96be45cd84414666e32cf1c53227a8b /src/mesa/main/draw.c
parentf726c61cc1b2b845d19dc2b348219c73713adf93 (diff)
mesa/vbo: Move _vbo_draw_indirect -> _mesa_draw_indirect
Reviewed-by: Brian Paul <[email protected]> Signed-off-by: Mathias Fröhlich <[email protected]>
Diffstat (limited to 'src/mesa/main/draw.c')
-rw-r--r--src/mesa/main/draw.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/mesa/main/draw.c b/src/mesa/main/draw.c
index 7729a860d02..85a9eedbc32 100644
--- a/src/mesa/main/draw.c
+++ b/src/mesa/main/draw.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include "arrayobj.h"
#include "glheader.h"
+#include "c99_alloca.h"
#include "context.h"
#include "state.h"
#include "draw.h"
@@ -2143,3 +2144,76 @@ _mesa_DrawTransformFeedback(GLenum mode, GLuint name)
{
_mesa_exec_DrawTransformFeedback(mode, name);
}
+
+
+/*
+ * Helper function for _mesa_draw_indirect below that additionally takes a zero
+ * initialized array of _mesa_prim scratch space memory as the last argument.
+ */
+static void
+draw_indirect(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_draw_count_buffer,
+ GLsizeiptr indirect_draw_count_offset,
+ const struct _mesa_index_buffer *ib,
+ struct _mesa_prim *prim)
+{
+ prim[0].begin = 1;
+ prim[draw_count - 1].end = 1;
+ for (unsigned i = 0; i < draw_count; ++i, indirect_offset += stride) {
+ prim[i].mode = mode;
+ prim[i].indexed = !!ib;
+ prim[i].indirect_offset = indirect_offset;
+ prim[i].is_indirect = 1;
+ prim[i].draw_id = i;
+ }
+
+ /* This should always be true at this time */
+ assert(indirect_data == ctx->DrawIndirectBuffer);
+
+ ctx->Driver.Draw(ctx, prim, draw_count, ib, false, 0u, ~0u,
+ NULL, 0, indirect_data);
+}
+
+
+/*
+ * Function to be put into dd_function_table::DrawIndirect as fallback.
+ * Calls into dd_function_table::Draw past adapting call arguments.
+ * See dd_function_table::DrawIndirect for call argument documentation.
+ */
+void
+_mesa_draw_indirect(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_draw_count_buffer,
+ GLsizeiptr indirect_draw_count_offset,
+ const struct _mesa_index_buffer *ib)
+{
+ /* Use alloca for the prim space if we are somehow in bounds. */
+ if (draw_count*sizeof(struct _mesa_prim) < 1024) {
+ struct _mesa_prim *space = alloca(draw_count*sizeof(struct _mesa_prim));
+ memset(space, 0, draw_count*sizeof(struct _mesa_prim));
+
+ draw_indirect(ctx, mode, indirect_data, indirect_offset, draw_count,
+ stride, indirect_draw_count_buffer,
+ indirect_draw_count_offset, ib, space);
+ } else {
+ struct _mesa_prim *space = calloc(draw_count, sizeof(struct _mesa_prim));
+ if (space == NULL) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "gl%sDraw%sIndirect%s",
+ (draw_count > 1) ? "Multi" : "",
+ ib ? "Elements" : "Arrays",
+ indirect_data ? "CountARB" : "");
+ return;
+ }
+
+ draw_indirect(ctx, mode, indirect_data, indirect_offset, draw_count,
+ stride, indirect_draw_count_buffer,
+ indirect_draw_count_offset, ib, space);
+
+ free(space);
+ }
+}