[Mesa-dev] [PATCH 3/3] mesa: add gl_context::NewDriverState and use it for vertex arrays
Marek Olšák
maraeo at gmail.com
Tue Apr 24 15:00:23 PDT 2012
The vbo module recomputes its states if _NEW_ARRAY is set, so it shouldn't use
the same flag to notify the driver. Since we've run out of bits in NewState
and NewState is for core Mesa anyway, we need to find another way.
This patch is the first to start decoupling the state flags meant only
for core Mesa and those only for drivers.
The idea is to have two flag sets:
- gl_context::NewState - used by core Mesa only
- gl_context::NewDriverState - used by drivers only
It makes perfect sense to use NewState|=_NEW_ARRAY to notify the vbo module
that the user changed vertex arrays, and the vbo module in turn sets
a driver-specific flag to notify the driver that it should update its vertex
array bindings.
The driver decides which bits of NewDriverState should be set and stores them
in gl_context::DriverFlags. Then, Core Mesa can do this:
ctx->NewDriverState |= ctx->DriverFlags.NewArray;
This patch implements this behavior and adapts st/mesa.
DriverFlags.NewArray is set to ST_NEW_VERTEX_ARRAYS.
Core Mesa only sets NewDriverState. It's the driver's responsibility to read
it whenever it wants and reset it to 0.
---
src/mesa/main/context.c | 2 ++
src/mesa/main/mtypes.h | 14 ++++++++++++++
src/mesa/state_tracker/st_cb_rasterpos.c | 5 ++++-
src/mesa/state_tracker/st_context.c | 6 ++++++
src/mesa/state_tracker/st_context.h | 1 +
src/mesa/state_tracker/st_draw.c | 12 +++++++++---
src/mesa/vbo/vbo_context.h | 2 +-
src/mesa/vbo/vbo_exec_array.c | 2 +-
src/mesa/vbo/vbo_exec_draw.c | 2 +-
src/mesa/vbo/vbo_rebase.c | 2 ++
src/mesa/vbo/vbo_save_draw.c | 2 +-
src/mesa/vbo/vbo_split_copy.c | 2 ++
src/mesa/vbo/vbo_split_inplace.c | 2 ++
13 files changed, 46 insertions(+), 8 deletions(-)
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index d75351c..7e2ac98 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -792,6 +792,7 @@ init_attrib_groups(struct gl_context *ctx)
/* Miscellaneous */
ctx->NewState = _NEW_ALL;
+ ctx->NewDriverState = ~0;
ctx->ErrorValue = (GLenum) GL_NO_ERROR;
ctx->ResetStatus = (GLenum) GL_NO_ERROR;
ctx->varying_vp_inputs = VERT_BIT_ALL;
@@ -1290,6 +1291,7 @@ _mesa_copy_context( const struct gl_context *src, struct gl_context *dst,
/* XXX FIXME: Call callbacks?
*/
dst->NewState = _NEW_ALL;
+ dst->NewDriverState = ~0;
}
#endif
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index eb103ad..7f01514 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -3255,6 +3255,17 @@ typedef enum
API_OPENGLES2
} gl_api;
+/**
+ * Driver-specific state flags.
+ *
+ * These are or'd with gl_context::NewDriverState to notify a driver about
+ * a state change. The driver gets to decide what bits should be set through
+ * this structure.
+ */
+struct gl_driver_flags
+{
+ GLbitfield NewArray; /**< Vertex array state */
+};
/**
* Mesa rendering context.
@@ -3414,6 +3425,9 @@ struct gl_context
GLenum RenderMode; /**< either GL_RENDER, GL_SELECT, GL_FEEDBACK */
GLbitfield NewState; /**< bitwise-or of _NEW_* flags */
+ GLbitfield NewDriverState;/**< bitwise-or of flags from DriverFlags */
+
+ struct gl_driver_flags DriverFlags;
GLboolean ViewportInitialized; /**< has viewport size been initialized? */
diff --git a/src/mesa/state_tracker/st_cb_rasterpos.c b/src/mesa/state_tracker/st_cb_rasterpos.c
index 35ca5d7..253ce31 100644
--- a/src/mesa/state_tracker/st_cb_rasterpos.c
+++ b/src/mesa/state_tracker/st_cb_rasterpos.c
@@ -251,7 +251,10 @@ st_RasterPos(struct gl_context *ctx, const GLfloat v[4])
*/
rs->array[0].Ptr = (GLubyte *) v;
- /* draw the point */
+ /* Draw the point.
+ *
+ * Don't set DriverFlags.NewArray.
+ * st_feedback_draw_vbo doesn't check for that flag. */
ctx->Array.Arrays = rs->arrays;
st_feedback_draw_vbo(ctx, &rs->prim, 1, NULL, GL_TRUE, 0, 1,
NULL);
diff --git a/src/mesa/state_tracker/st_context.c b/src/mesa/state_tracker/st_context.c
index 84aae81..0419968 100644
--- a/src/mesa/state_tracker/st_context.c
+++ b/src/mesa/state_tracker/st_context.c
@@ -203,6 +203,10 @@ st_create_context_priv( struct gl_context *ctx, struct pipe_context *pipe )
return st;
}
+static void st_init_driver_flags(struct gl_driver_flags *f)
+{
+ f->NewArray = ST_NEW_VERTEX_ARRAYS;
+}
struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
const struct gl_config *visual,
@@ -225,6 +229,8 @@ struct st_context *st_create_context(gl_api api, struct pipe_context *pipe,
return NULL;
}
+ st_init_driver_flags(&ctx->DriverFlags);
+
/* XXX: need a capability bit in gallium to query if the pipe
* driver prefers DP4 or MUL/MAD for vertex transformation.
*/
diff --git a/src/mesa/state_tracker/st_context.h b/src/mesa/state_tracker/st_context.h
index 3ec98ad..4786ed2 100644
--- a/src/mesa/state_tracker/st_context.h
+++ b/src/mesa/state_tracker/st_context.h
@@ -50,6 +50,7 @@ struct u_vbuf;
#define ST_NEW_FRAMEBUFFER (1 << 3)
#define ST_NEW_EDGEFLAGS_DATA (1 << 4)
#define ST_NEW_GEOMETRY_PROGRAM (1 << 5)
+#define ST_NEW_VERTEX_ARRAYS (1 << 6)
struct st_state_flags {
diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c
index 59ca5e9..97227e6 100644
--- a/src/mesa/state_tracker/st_draw.c
+++ b/src/mesa/state_tracker/st_draw.c
@@ -981,13 +981,19 @@ st_draw_vbo(struct gl_context *ctx,
const struct gl_client_array **arrays = ctx->Array.Arrays;
unsigned i, num_instances = 1;
unsigned max_index_plus_base;
- GLboolean new_array =
- st->dirty.st &&
- (st->dirty.mesa & (_NEW_ARRAY | _NEW_PROGRAM | _NEW_BUFFER_OBJECT)) != 0;
+ GLboolean new_array;
/* Mesa core state should have been validated already */
assert(ctx->NewState == 0x0);
+ /* Get Mesa driver state. */
+ st->dirty.st |= ctx->NewDriverState;
+ ctx->NewDriverState = 0;
+
+ new_array =
+ (st->dirty.st & (ST_NEW_VERTEX_ARRAYS | ST_NEW_VERTEX_PROGRAM)) ||
+ (st->dirty.mesa & (_NEW_PROGRAM | _NEW_BUFFER_OBJECT)) != 0;
+
if (ib) {
int max_base_vertex = 0;
diff --git a/src/mesa/vbo/vbo_context.h b/src/mesa/vbo/vbo_context.h
index 257f514..940835a 100644
--- a/src/mesa/vbo/vbo_context.h
+++ b/src/mesa/vbo/vbo_context.h
@@ -146,7 +146,7 @@ vbo_draw_method(struct vbo_context *vbo, enum draw_method method)
ASSERT(0);
}
- ctx->Driver.UpdateState(ctx, _NEW_ARRAY);
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
vbo->last_draw_method = method;
}
}
diff --git a/src/mesa/vbo/vbo_exec_array.c b/src/mesa/vbo/vbo_exec_array.c
index d39324d..cc94e76 100644
--- a/src/mesa/vbo/vbo_exec_array.c
+++ b/src/mesa/vbo/vbo_exec_array.c
@@ -506,7 +506,7 @@ recalculate_input_bindings(struct gl_context *ctx)
}
_mesa_set_varying_vp_inputs( ctx, VERT_BIT_ALL & (~const_inputs) );
- ctx->Driver.UpdateState(ctx, _NEW_ARRAY);
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
}
diff --git a/src/mesa/vbo/vbo_exec_draw.c b/src/mesa/vbo/vbo_exec_draw.c
index 6e8bb15..77db8ec 100644
--- a/src/mesa/vbo/vbo_exec_draw.c
+++ b/src/mesa/vbo/vbo_exec_draw.c
@@ -257,7 +257,7 @@ vbo_exec_bind_arrays( struct gl_context *ctx )
}
_mesa_set_varying_vp_inputs( ctx, varying_inputs );
- ctx->Driver.UpdateState(ctx, _NEW_ARRAY);
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
}
diff --git a/src/mesa/vbo/vbo_rebase.c b/src/mesa/vbo/vbo_rebase.c
index b36595e..3dd92fe 100644
--- a/src/mesa/vbo/vbo_rebase.c
+++ b/src/mesa/vbo/vbo_rebase.c
@@ -228,6 +228,7 @@ void vbo_rebase_prims( struct gl_context *ctx,
/* Re-issue the draw call.
*/
ctx->Array.Arrays = tmp_array_pointers;
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
draw( ctx,
prim,
@@ -239,6 +240,7 @@ void vbo_rebase_prims( struct gl_context *ctx,
NULL );
ctx->Array.Arrays = saved_arrays;
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
if (tmp_indices)
free(tmp_indices);
diff --git a/src/mesa/vbo/vbo_save_draw.c b/src/mesa/vbo/vbo_save_draw.c
index bb59615..c6425ab 100644
--- a/src/mesa/vbo/vbo_save_draw.c
+++ b/src/mesa/vbo/vbo_save_draw.c
@@ -213,7 +213,7 @@ static void vbo_bind_vertex_list(struct gl_context *ctx,
}
_mesa_set_varying_vp_inputs( ctx, varying_inputs );
- ctx->Driver.UpdateState(ctx, _NEW_ARRAY);
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
}
diff --git a/src/mesa/vbo/vbo_split_copy.c b/src/mesa/vbo/vbo_split_copy.c
index 89284be..d9b9c0d 100644
--- a/src/mesa/vbo/vbo_split_copy.c
+++ b/src/mesa/vbo/vbo_split_copy.c
@@ -192,6 +192,7 @@ flush( struct copy_context *copy )
#endif
ctx->Array.Arrays = copy->dstarray_ptr;
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
copy->draw( ctx,
copy->dstprim,
@@ -203,6 +204,7 @@ flush( struct copy_context *copy )
NULL );
ctx->Array.Arrays = saved_arrays;
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
/* Reset all pointers:
*/
diff --git a/src/mesa/vbo/vbo_split_inplace.c b/src/mesa/vbo/vbo_split_inplace.c
index 4572422..6faa8c1 100644
--- a/src/mesa/vbo/vbo_split_inplace.c
+++ b/src/mesa/vbo/vbo_split_inplace.c
@@ -85,6 +85,7 @@ static void flush_vertex( struct split_context *split )
assert(split->max_index >= split->min_index);
ctx->Array.Arrays = split->array;
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
split->draw(ctx,
split->dstprim,
@@ -96,6 +97,7 @@ static void flush_vertex( struct split_context *split )
NULL);
ctx->Array.Arrays = saved_arrays;
+ ctx->NewDriverState |= ctx->DriverFlags.NewArray;
split->dstprim_nr = 0;
split->min_index = ~0;
--
1.7.5.4
More information about the mesa-dev
mailing list