[Mesa-dev] [PATCH 2/3] draw: add code to reset instance dependent data
Zack Rusin
zackr at vmware.com
Sat Apr 20 00:04:29 PDT 2013
We want to be able to reset certain parts of the pipeline,
in particular the input primitive index, but only either with
seperate invocations of the draw_vbo or new instances. In all
other cases (e.g. new invocations due to primitive restart)
that data needs to be preserved. Add a function through which
we can reset instance dependent data.
Signed-off-by: Zack Rusin <zackr at vmware.com>
---
src/gallium/auxiliary/draw/draw_context.c | 13 +++++++++++++
src/gallium/auxiliary/draw/draw_gs.c | 14 +++++++++++++-
src/gallium/auxiliary/draw/draw_gs.h | 2 ++
src/gallium/auxiliary/draw/draw_private.h | 1 +
src/gallium/auxiliary/draw/draw_pt.c | 2 ++
5 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index 5272951..25f79ae 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -156,6 +156,19 @@ boolean draw_init(struct draw_context *draw)
return TRUE;
}
+/*
+ * Called whenever we're starting to draw a new instance.
+ * Some internal structures don't want to have to reset internal
+ * members on each invocation (because their state might have to persist
+ * between multiple primitive restart rendering call) but might have to
+ * for each new instance.
+ * This is particularly the case for primitive id's in geometry shader.
+ */
+void draw_new_instance(struct draw_context *draw)
+{
+ draw_geometry_shader_new_instance(draw->gs.geometry_shader);
+}
+
void draw_destroy( struct draw_context *draw )
{
diff --git a/src/gallium/auxiliary/draw/draw_gs.c b/src/gallium/auxiliary/draw/draw_gs.c
index 2f94eae..fbb01b4 100644
--- a/src/gallium/auxiliary/draw/draw_gs.c
+++ b/src/gallium/auxiliary/draw/draw_gs.c
@@ -560,7 +560,6 @@ int draw_geometry_shader_run(struct draw_geometry_shader *shader,
shader->emitted_primitives = 0;
shader->vertex_size = vertex_size;
shader->tmp_output = (float (*)[4])output_verts->verts->data;
- shader->in_prim_idx = 0;
shader->fetched_prim_count = 0;
shader->input_vertex_stride = input_stride;
shader->input = input;
@@ -869,3 +868,16 @@ void draw_gs_set_current_variant(struct draw_geometry_shader *shader,
shader->current_variant = variant;
}
#endif
+
+/*
+ * Called at the very begin of the draw call with a new instance
+ * Used to reset state that should persist between primitive restart.
+ */
+void
+draw_geometry_shader_new_instance(struct draw_geometry_shader *gs)
+{
+ if (!gs)
+ return;
+
+ gs->in_prim_idx = 0;
+}
diff --git a/src/gallium/auxiliary/draw/draw_gs.h b/src/gallium/auxiliary/draw/draw_gs.h
index ca744ce..46d2d61 100644
--- a/src/gallium/auxiliary/draw/draw_gs.h
+++ b/src/gallium/auxiliary/draw/draw_gs.h
@@ -114,6 +114,8 @@ struct draw_geometry_shader {
unsigned input_primitives);
};
+void draw_geometry_shader_new_instance(struct draw_geometry_shader *gs);
+
/*
* Returns the number of vertices emitted.
* The vertex shader can emit any number of vertices as long as it's
diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
index d6a3e7c..25a8ae6 100644
--- a/src/gallium/auxiliary/draw/draw_private.h
+++ b/src/gallium/auxiliary/draw/draw_private.h
@@ -355,6 +355,7 @@ struct draw_prim_info {
* Draw common initialization code
*/
boolean draw_init(struct draw_context *draw);
+void draw_new_instance(struct draw_context *draw);
/*******************************************************************************
* Vertex shader code:
diff --git a/src/gallium/auxiliary/draw/draw_pt.c b/src/gallium/auxiliary/draw/draw_pt.c
index 10f32fd..602d076 100644
--- a/src/gallium/auxiliary/draw/draw_pt.c
+++ b/src/gallium/auxiliary/draw/draw_pt.c
@@ -561,6 +561,8 @@ draw_vbo(struct draw_context *draw,
for (instance = 0; instance < info->instance_count; instance++) {
draw->instance_id = instance + info->start_instance;
+ draw_new_instance(draw);
+
if (info->primitive_restart) {
draw_pt_arrays_restart(draw, info);
}
--
1.7.10.4
More information about the mesa-dev
mailing list