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 <brianp@vmware.com>
This commit is contained in:
Marek Olšák
2012-04-16 04:56:12 +02:00
parent 50f7e75f9e
commit c5e473fbe2
13 changed files with 46 additions and 8 deletions

View File

@@ -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

View File

@@ -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? */

View File

@@ -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);

View File

@@ -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.
*/

View File

@@ -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 {

View File

@@ -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;

View File

@@ -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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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:
*/

View File

@@ -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;