draw: move some state into a new 'vs' area

This commit is contained in:
Keith Whitwell 2008-05-13 13:40:22 +01:00
parent b23706454b
commit 2f0d1396e4
15 changed files with 76 additions and 48 deletions

View file

@ -56,12 +56,6 @@ struct draw_context *draw_create( void )
draw->reduced_prim = ~0; /* != any of PIPE_PRIM_x */
tgsi_exec_machine_init(&draw->machine);
/* FIXME: give this machine thing a proper constructor:
*/
draw->machine.Inputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16);
draw->machine.Outputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16);
if (!draw_pipeline_init( draw ))
goto fail;
@ -69,6 +63,9 @@ struct draw_context *draw_create( void )
if (!draw_pt_init( draw ))
goto fail;
if (!draw_vs_init( draw ))
goto fail;
return draw;
fail:
@ -83,13 +80,6 @@ void draw_destroy( struct draw_context *draw )
return;
if (draw->machine.Inputs)
align_free(draw->machine.Inputs);
if (draw->machine.Outputs)
align_free(draw->machine.Outputs);
tgsi_exec_machine_free_data(&draw->machine);
/* Not so fast -- we're just borrowing this at the moment.
*
@ -99,6 +89,7 @@ void draw_destroy( struct draw_context *draw )
draw_pipeline_destroy( draw );
draw_pt_destroy( draw );
draw_vs_destroy( draw );
FREE( draw );
}
@ -295,7 +286,7 @@ int
draw_find_vs_output(struct draw_context *draw,
uint semantic_name, uint semantic_index)
{
const struct draw_vertex_shader *vs = draw->vertex_shader;
const struct draw_vertex_shader *vs = draw->vs.vertex_shader;
uint i;
for (i = 0; i < vs->info.num_outputs; i++) {
if (vs->info.output_semantic_name[i] == semantic_name &&
@ -320,7 +311,7 @@ draw_find_vs_output(struct draw_context *draw,
uint
draw_num_vs_outputs(struct draw_context *draw)
{
uint count = draw->vertex_shader->info.num_outputs;
uint count = draw->vs.vertex_shader->info.num_outputs;
if (draw->extra_vp_outputs.slot > 0)
count++;
return count;

View file

@ -116,7 +116,7 @@ dup_vert( struct draw_stage *stage,
{
struct vertex_header *tmp = stage->tmp[idx];
const uint vsize = sizeof(struct vertex_header)
+ stage->draw->num_vs_outputs * 4 * sizeof(float);
+ stage->draw->vs.num_vs_outputs * 4 * sizeof(float);
memcpy(tmp, vert, vsize);
tmp->vertex_id = UNDEFINED_VERTEX_ID;
return tmp;

View file

@ -651,7 +651,7 @@ aaline_first_line(struct draw_stage *stage, struct prim_header *header)
}
/* update vertex attrib info */
aaline->tex_slot = draw->num_vs_outputs;
aaline->tex_slot = draw->vs.num_vs_outputs;
assert(aaline->tex_slot > 0); /* output[0] is vertex pos */
/* advertise the extra post-transformed vertex attribute */

View file

@ -681,7 +681,7 @@ aapoint_first_point(struct draw_stage *stage, struct prim_header *header)
bind_aapoint_fragment_shader(aapoint);
/* update vertex attrib info */
aapoint->tex_slot = draw->num_vs_outputs;
aapoint->tex_slot = draw->vs.num_vs_outputs;
assert(aapoint->tex_slot > 0); /* output[0] is vertex pos */
draw->extra_vp_outputs.semantic_name = TGSI_SEMANTIC_GENERIC;
@ -692,7 +692,7 @@ aapoint_first_point(struct draw_stage *stage, struct prim_header *header)
aapoint->psize_slot = -1;
if (draw->rasterizer->point_size_per_vertex) {
/* find PSIZ vertex output */
const struct draw_vertex_shader *vs = draw->vertex_shader;
const struct draw_vertex_shader *vs = draw->vs.vertex_shader;
uint i;
for (i = 0; i < vs->info.num_outputs; i++) {
if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_PSIZE) {

View file

@ -112,7 +112,7 @@ static void interp( const struct clipper *clip,
const struct vertex_header *out,
const struct vertex_header *in )
{
const unsigned nr_attrs = clip->stage.draw->num_vs_outputs;
const unsigned nr_attrs = clip->stage.draw->vs.num_vs_outputs;
unsigned j;
/* Vertex header.
@ -180,7 +180,7 @@ static void emit_poly( struct draw_stage *stage,
header.flags |= edge_last;
if (0) {
const struct draw_vertex_shader *vs = stage->draw->vertex_shader;
const struct draw_vertex_shader *vs = stage->draw->vs.vertex_shader;
uint j, k;
debug_printf("Clipped tri:\n");
for (j = 0; j < 3; j++) {
@ -425,7 +425,7 @@ clip_init_state( struct draw_stage *stage )
clipper->flat = stage->draw->rasterizer->flatshade ? TRUE : FALSE;
if (clipper->flat) {
const struct draw_vertex_shader *vs = stage->draw->vertex_shader;
const struct draw_vertex_shader *vs = stage->draw->vs.vertex_shader;
uint i;
clipper->num_color_attribs = 0;

View file

@ -159,7 +159,7 @@ static void flatshade_line_1( struct draw_stage *stage,
static void flatshade_init_state( struct draw_stage *stage )
{
struct flat_stage *flat = flat_stage(stage);
const struct draw_vertex_shader *vs = stage->draw->vertex_shader;
const struct draw_vertex_shader *vs = stage->draw->vs.vertex_shader;
uint i;
/* Find which vertex shader outputs are colors, make a list */

View file

@ -71,7 +71,7 @@ screen_interp( struct draw_context *draw,
const struct vertex_header *v1 )
{
uint attr;
for (attr = 0; attr < draw->num_vs_outputs; attr++) {
for (attr = 0; attr < draw->vs.num_vs_outputs; attr++) {
const float *val0 = v0->data[attr];
const float *val1 = v1->data[attr];
float *newv = dst->data[attr];

View file

@ -105,7 +105,7 @@ static void twoside_first_tri( struct draw_stage *stage,
struct prim_header *header )
{
struct twoside_stage *twoside = twoside_stage(stage);
const struct draw_vertex_shader *vs = stage->draw->vertex_shader;
const struct draw_vertex_shader *vs = stage->draw->vs.vertex_shader;
uint i;
twoside->attrib_front0 = 0;

View file

@ -197,7 +197,7 @@ static void widepoint_first_point( struct draw_stage *stage,
if (draw->rasterizer->point_sprite) {
/* find vertex shader texcoord outputs */
const struct draw_vertex_shader *vs = draw->vertex_shader;
const struct draw_vertex_shader *vs = draw->vs.vertex_shader;
uint i, j = 0;
for (i = 0; i < vs->info.num_outputs; i++) {
if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_GENERIC) {
@ -212,7 +212,7 @@ static void widepoint_first_point( struct draw_stage *stage,
wide->psize_slot = -1;
if (draw->rasterizer->point_size_per_vertex) {
/* find PSIZ vertex output */
const struct draw_vertex_shader *vs = draw->vertex_shader;
const struct draw_vertex_shader *vs = draw->vs.vertex_shader;
uint i;
for (i = 0; i < vs->info.num_outputs; i++) {
if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_PSIZE) {

View file

@ -169,14 +169,25 @@ struct draw_context
/* pipe state that we need: */
const struct pipe_rasterizer_state *rasterizer;
struct pipe_viewport_state viewport;
struct draw_vertex_shader *vertex_shader;
boolean identity_viewport;
uint num_vs_outputs; /**< convenience, from vertex_shader */
struct {
struct draw_vertex_shader *vertex_shader;
uint num_vs_outputs; /**< convenience, from vertex_shader */
/** TGSI program interpreter runtime state */
struct tgsi_exec_machine machine;
/* This (and the tgsi_exec_machine struct) probably need to be moved somewhere private.
*/
struct gallivm_cpu_engine *engine;
struct translate_cache *fetch_cache;
struct translate_cache *emit_cache;
} vs;
/* Clip derived state:
*/
float plane[12][4];
@ -192,16 +203,15 @@ struct draw_context
unsigned reduced_prim;
/** TGSI program interpreter runtime state */
struct tgsi_exec_machine machine;
/* This (and the tgsi_exec_machine struct) probably need to be moved somewhere private.
*/
struct gallivm_cpu_engine *engine;
void *driver_private;
};
/*******************************************************************************
* Vertex shader code:
*/
boolean draw_vs_init( struct draw_context *draw );
void draw_vs_destroy( struct draw_context *draw );

View file

@ -55,7 +55,7 @@ static void fetch_pipeline_prepare( struct draw_pt_middle_end *middle,
{
struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle;
struct draw_context *draw = fpme->draw;
struct draw_vertex_shader *vs = draw->vertex_shader;
struct draw_vertex_shader *vs = draw->vs.vertex_shader;
/* Add one to num_outputs because the pipeline occasionally tags on
* an additional texcoord, eg for AA lines.
@ -107,7 +107,7 @@ static void fetch_pipeline_run( struct draw_pt_middle_end *middle,
{
struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle;
struct draw_context *draw = fpme->draw;
struct draw_vertex_shader *shader = draw->vertex_shader;
struct draw_vertex_shader *shader = draw->vs.vertex_shader;
unsigned opt = fpme->opt;
unsigned alloc_count = align_int( fetch_count, 4 );
@ -183,7 +183,7 @@ static void fetch_pipeline_linear_run( struct draw_pt_middle_end *middle,
{
struct fetch_pipeline_middle_end *fpme = (struct fetch_pipeline_middle_end *)middle;
struct draw_context *draw = fpme->draw;
struct draw_vertex_shader *shader = draw->vertex_shader;
struct draw_vertex_shader *shader = draw->vs.vertex_shader;
unsigned opt = fpme->opt;
unsigned alloc_count = align_int( count, 4 );

View file

@ -368,8 +368,8 @@ static void fse_prepare( struct draw_pt_middle_end *middle,
{
struct fetch_shade_emit *fse = (struct fetch_shade_emit *)middle;
struct draw_context *draw = fse->draw;
unsigned num_vs_inputs = draw->vertex_shader->info.num_inputs;
unsigned num_vs_outputs = draw->vertex_shader->info.num_outputs;
unsigned num_vs_inputs = draw->vs.vertex_shader->info.num_inputs;
unsigned num_vs_outputs = draw->vs.vertex_shader->info.num_outputs;
const struct vertex_info *vinfo;
unsigned i;
boolean need_psize = 0;

View file

@ -66,13 +66,13 @@ draw_bind_vertex_shader(struct draw_context *draw,
if (dvs)
{
draw->vertex_shader = dvs;
draw->num_vs_outputs = dvs->info.num_outputs;
draw->vs.vertex_shader = dvs;
draw->vs.num_vs_outputs = dvs->info.num_outputs;
dvs->prepare( dvs, draw );
}
else {
draw->vertex_shader = NULL;
draw->num_vs_outputs = 0;
draw->vs.vertex_shader = NULL;
draw->vs.num_vs_outputs = 0;
}
}
@ -83,3 +83,30 @@ draw_delete_vertex_shader(struct draw_context *draw,
{
dvs->delete( dvs );
}
boolean
draw_vs_init( struct draw_context *draw )
{
tgsi_exec_machine_init(&draw->vs.machine);
/* FIXME: give this machine thing a proper constructor:
*/
draw->vs.machine.Inputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16);
draw->vs.machine.Outputs = align_malloc(PIPE_MAX_ATTRIBS * sizeof(struct tgsi_exec_vector), 16);
return TRUE;
}
void
draw_vs_destroy( struct draw_context *draw )
{
if (draw->vs.machine.Inputs)
align_free(draw->vs.machine.Inputs);
if (draw->vs.machine.Outputs)
align_free(draw->vs.machine.Outputs);
tgsi_exec_machine_free_data(&draw->vs.machine);
}

View file

@ -182,7 +182,7 @@ draw_create_vs_exec(struct draw_context *draw,
vs->base.prepare = vs_exec_prepare;
vs->base.run_linear = vs_exec_run_linear;
vs->base.delete = vs_exec_delete;
vs->machine = &draw->machine;
vs->machine = &draw->vs.machine;
return &vs->base;
}

View file

@ -158,7 +158,7 @@ draw_create_vs_sse(struct draw_context *draw,
vs->base.prepare = vs_sse_prepare;
vs->base.run_linear = vs_sse_run_linear;
vs->base.delete = vs_sse_delete;
vs->machine = &draw->machine;
vs->machine = &draw->vs.machine;
x86_init_func( &vs->sse2_program );