From c5e473fbe25b20cb27aac44ff6e269701abd33a8 Mon Sep 17 00:00:00 2001 From: Marek Olšák Date: Mon, 16 Apr 2012 04:56:12 +0200 Subject: mesa: add gl_context::NewDriverState and use it for vertex arrays 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 (the flags are defined by the driver and opaque to core Mesa) 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. Reviewed-by: Brian Paul --- 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 d75351c8598..7e2ac98b9a0 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 9f1a2263f54..06ca0d5df16 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3257,6 +3257,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 sets the flags at context creation and + * the meaning of the bits set is opaque to core Mesa. + */ +struct gl_driver_flags +{ + GLbitfield NewArray; /**< Vertex array state */ +}; /** * Mesa rendering context. @@ -3416,6 +3427,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 7fef031f013..8337f462418 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._DrawArrays = 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 19d9da131f3..ce7dbb3f39a 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 3ec98ada196..4786ed22fe9 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 01ba09d6567..42dc3757615 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._DrawArrays; 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 93c48cd029b..1c49de0ca2f 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 d39324d12bc..cc94e761bc1 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 6e8bb15d1e2..77db8ec7f3e 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 9a98ef7d449..fff9df0c29d 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._DrawArrays = 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._DrawArrays = 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 bb5961549ef..c6425ab1b79 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 9665c4fcd2f..528fcfd7f80 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._DrawArrays = 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._DrawArrays = 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 7c2cc3ece5a..00464049ddd 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._DrawArrays = 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._DrawArrays = saved_arrays; + ctx->NewDriverState |= ctx->DriverFlags.NewArray; split->dstprim_nr = 0; split->min_index = ~0; -- cgit v1.2.3