From bb611c5f1f6aec7ac51d4fa3301422b47f6de795 Mon Sep 17 00:00:00 2001 From: Brian Date: Tue, 18 Sep 2007 19:37:36 -0600 Subject: Checkpoint: rework shader input/output register mapping. This is a step toward removing TGSI_ATTRIB_ tokens. Basically, when translating Mesa programs to TGSI programs, pass in input and output register re-maps, plus interpolation info. There's some known breakage (cubemap.c) so more to be done... --- src/mesa/pipe/draw/draw_vertex_fetch.c | 39 +++++------ src/mesa/pipe/draw/draw_vertex_shader.c | 14 +++- src/mesa/pipe/p_state.h | 3 + src/mesa/pipe/softpipe/sp_prim_setup.c | 8 +++ src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c | 72 +++++++++++++++------ src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h | 5 ++ src/mesa/state_tracker/st_atom_fs.c | 23 ++++++- src/mesa/state_tracker/st_atom_vs.c | 46 +++++++++++-- src/mesa/state_tracker/st_cb_clear.c | 21 +++++- src/mesa/state_tracker/st_cb_drawpixels.c | 15 ++++- src/mesa/state_tracker/st_draw.c | 103 ++++++++++++++++-------------- src/mesa/state_tracker/st_program.h | 17 +++-- 12 files changed, 260 insertions(+), 106 deletions(-) diff --git a/src/mesa/pipe/draw/draw_vertex_fetch.c b/src/mesa/pipe/draw/draw_vertex_fetch.c index 0dbbdf17f2f..ce402d681f0 100644 --- a/src/mesa/pipe/draw/draw_vertex_fetch.c +++ b/src/mesa/pipe/draw/draw_vertex_fetch.c @@ -67,6 +67,10 @@ fetch_attrib4(const void *ptr, unsigned format, float attrib[4]) } } + +/** + * Fetch vertex attributes for 'count' vertices. + */ void draw_vertex_fetch( struct draw_context *draw, struct tgsi_exec_machine *machine, const unsigned *elts, @@ -74,27 +78,26 @@ void draw_vertex_fetch( struct draw_context *draw, { unsigned j; - - /* load machine inputs */ + /* loop over vertices */ for (j = 0; j < count; j++) { - unsigned attr; - for (attr = 0; attr < 16; attr++) { - if (draw->vertex_shader.inputs_read & (1 << attr)) { - unsigned buf = draw->vertex_element[attr].vertex_buffer_index; - const void *src - = (const void *) ((const ubyte *) draw->mapped_vbuffer[buf] - + draw->vertex_buffer[buf].buffer_offset - + draw->vertex_element[attr].src_offset - + elts[j] * draw->vertex_buffer[buf].pitch); - float p[4]; + uint attr; + /* loop over vertex attributes (vertex shader inputs) */ + for (attr = 0; attr < draw->vertex_shader.num_inputs; attr++) { + + unsigned buf = draw->vertex_element[attr].vertex_buffer_index; + const void *src + = (const void *) ((const ubyte *) draw->mapped_vbuffer[buf] + + draw->vertex_buffer[buf].buffer_offset + + draw->vertex_element[attr].src_offset + + elts[j] * draw->vertex_buffer[buf].pitch); + float p[4]; - fetch_attrib4(src, draw->vertex_element[attr].src_format, p); + fetch_attrib4(src, draw->vertex_element[attr].src_format, p); - machine->Inputs[attr].xyzw[0].f[j] = p[0]; /*X*/ - machine->Inputs[attr].xyzw[1].f[j] = p[1]; /*Y*/ - machine->Inputs[attr].xyzw[2].f[j] = p[2]; /*Z*/ - machine->Inputs[attr].xyzw[3].f[j] = p[3]; /*W*/ - } + machine->Inputs[attr].xyzw[0].f[j] = p[0]; /*X*/ + machine->Inputs[attr].xyzw[1].f[j] = p[1]; /*Y*/ + machine->Inputs[attr].xyzw[2].f[j] = p[2]; /*Z*/ + machine->Inputs[attr].xyzw[3].f[j] = p[3]; /*W*/ } } } diff --git a/src/mesa/pipe/draw/draw_vertex_shader.c b/src/mesa/pipe/draw/draw_vertex_shader.c index 8effc74cbee..cb6c605b8db 100644 --- a/src/mesa/pipe/draw/draw_vertex_shader.c +++ b/src/mesa/pipe/draw/draw_vertex_shader.c @@ -114,7 +114,6 @@ run_vertex_program(struct draw_context *draw, draw_vertex_fetch( draw, &machine, elts, count ); - /* run shader */ if( draw->vertex_shader.executable != NULL ) { #if defined(USE_X86_ASM) || defined(SLANG_X86) @@ -159,14 +158,23 @@ run_vertex_program(struct draw_context *draw, vOut[j]->data[0][2] = z * scale[2] + trans[2]; vOut[j]->data[0][3] = w; - /* remaining attributes are packed into sequential post-transform + /* Remaining attributes are packed into sequential post-transform * vertex attrib slots. + * Skip 0 since we just did it above. + * Subtract two because of the VERTEX_HEADER, CLIP_POS attribs. */ - for (slot = 1; slot < draw->vertex_info.num_attribs; slot++) { + for (slot = 1; slot < draw->vertex_info.num_attribs - 2; slot++) { vOut[j]->data[slot][0] = machine.Outputs[slot].xyzw[0].f[j]; vOut[j]->data[slot][1] = machine.Outputs[slot].xyzw[1].f[j]; vOut[j]->data[slot][2] = machine.Outputs[slot].xyzw[2].f[j]; vOut[j]->data[slot][3] = machine.Outputs[slot].xyzw[3].f[j]; + /* + printf("output %d: %f %f %f %f\n", slot, + vOut[j]->data[slot][0], + vOut[j]->data[slot][1], + vOut[j]->data[slot][2], + vOut[j]->data[slot][3]); + */ } } /* loop over vertices */ } diff --git a/src/mesa/pipe/p_state.h b/src/mesa/pipe/p_state.h index 048feede3ba..d2cc76a59b2 100644 --- a/src/mesa/pipe/p_state.h +++ b/src/mesa/pipe/p_state.h @@ -144,6 +144,9 @@ struct pipe_shader_state { unsigned outputs_written; /**< TGSI_ATTRIB_ bits */ const struct tgsi_token *tokens; void *executable; + + uint num_inputs; + uint num_outputs; }; struct pipe_depth_stencil_state diff --git a/src/mesa/pipe/softpipe/sp_prim_setup.c b/src/mesa/pipe/softpipe/sp_prim_setup.c index d0baf0734b0..8a4be79d114 100644 --- a/src/mesa/pipe/softpipe/sp_prim_setup.c +++ b/src/mesa/pipe/softpipe/sp_prim_setup.c @@ -448,6 +448,14 @@ static void tri_persp_coeff( struct setup_stage *setup, float a = setup->ebot.dy * majda - botda * setup->emaj.dy; float b = setup->emaj.dx * botda - majda * setup->ebot.dx; + /* + printf("tri persp %d,%d: %f %f %f\n", slot, i, + setup->vmin->data[slot][i], + setup->vmid->data[slot][i], + setup->vmax->data[slot][i] + ); + */ + assert(slot < TGSI_ATTRIB_MAX); assert(i <= 3); diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c index 28207065372..1f8d937bc6b 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c @@ -211,6 +211,7 @@ tgsi_mesa_translate_fragment_output(GLuint attrib) } +#if 01 uint tgsi_mesa_translate_vertex_input_mask(GLbitfield mask) { @@ -224,7 +225,7 @@ tgsi_mesa_translate_vertex_input_mask(GLbitfield mask) } return tgsiMask; } - +#endif uint tgsi_mesa_translate_vertex_output_mask(GLbitfield mask) @@ -318,7 +319,9 @@ map_register_file_index( GLuint processor, GLuint file, GLuint index, - GLbitfield usage_bitmask ) + GLbitfield usage_bitmask, + const GLuint inputMapping[], + const GLuint outputMapping[]) { GLuint mapped_index; GLuint i; @@ -337,6 +340,12 @@ map_register_file_index( * etc. */ assert( index < 32 ); + if (inputMapping) { + printf("New map %d input %d to %d\n", processor, index, + inputMapping[index]); + return inputMapping[index]; + } + assert( usage_bitmask & (1 << index) ); mapped_index = 0; for( i = 0; i < index; i++ ) { @@ -344,7 +353,7 @@ map_register_file_index( mapped_index++; } } - printf("Map input %d to %d\n", index, mapped_index); + printf("Map %d input %d to %d\n", processor, index, mapped_index); break; case TGSI_FILE_OUTPUT: @@ -372,6 +381,8 @@ map_register_file_index( mapped_index++; } } + printf("Map VP output from %d to %d\n", index, mapped_index); + assert(outputMapping[index] == mapped_index); } break; @@ -443,6 +454,8 @@ compile_instruction( struct tgsi_full_instruction *fullinst, GLuint inputs_read, GLuint outputs_written, + const GLuint inputMapping[], + const GLuint outputMapping[], GLuint preamble_size, GLuint processor ) { @@ -462,7 +475,9 @@ compile_instruction( processor, fulldst->DstRegister.File, inst->DstReg.Index, - outputs_written + outputs_written, + NULL, + outputMapping ); fulldst->DstRegister.WriteMask = convert_writemask( inst->DstReg.WriteMask ); @@ -475,7 +490,9 @@ compile_instruction( processor, fullsrc->SrcRegister.File, inst->SrcReg[i].Index, - inputs_read ); + inputs_read, + inputMapping, + outputMapping ); for( j = 0; j < 4; j++ ) { GLuint swz; @@ -789,9 +806,20 @@ make_frag_output_decl( return decl; } + +/** + * Convert Mesa fragment program to TGSI format. + * \param inputMapping array to map original Mesa fragment program inputs + * registers to TGSI generic input indexes + * \param interpMode array[FRAG_ATTRIB_x] of TGSI_INTERPOLATE_LINEAR/PERSP. + * + */ GLboolean tgsi_mesa_compile_fp_program( const struct gl_fragment_program *program, + const GLuint inputMapping[], + const GLuint interpMode[], + const GLuint outputMapping[], struct tgsi_token *tokens, GLuint maxTokens ) { @@ -800,8 +828,10 @@ tgsi_mesa_compile_fp_program( struct tgsi_processor *processor; struct tgsi_full_declaration fulldecl; struct tgsi_full_instruction fullinst; + /* struct tgsi_full_dst_register *fulldst; struct tgsi_full_src_register *fullsrc; + */ GLuint inputs_read; GLboolean reads_wpos; GLuint preamble_size = 0; @@ -822,7 +852,7 @@ tgsi_mesa_compile_fp_program( /* * Declare input attributes. Note that we do not interpolate fragment position. */ - + reads_wpos = 1; /* Fragment position. */ if( reads_wpos ) { fulldecl = make_frag_input_decl( @@ -853,20 +883,16 @@ tgsi_mesa_compile_fp_program( for( i = 1; i < 32; i++ ) { if( inputs_read & (1 << i) ) { count++; + fulldecl = make_frag_input_decl(count, + count, + interpMode[i], + TGSI_WRITEMASK_XYZW ); + ti += tgsi_build_full_declaration(&fulldecl, + &tokens[ti], + header, + maxTokens - ti ); } - } - if( count > 0 ) { - fulldecl = make_frag_input_decl( - 1, - 1 + count - 1, - TGSI_INTERPOLATE_PERSPECTIVE, - TGSI_WRITEMASK_XYZW ); - ti += tgsi_build_full_declaration( - &fulldecl, - &tokens[ti], - header, - maxTokens - ti ); - } + } /* * Declare output attributes. @@ -932,6 +958,8 @@ tgsi_mesa_compile_fp_program( &fullinst, inputs_read, ~0, /*outputs_written*/ + inputMapping, + outputMapping, preamble_size, TGSI_PROCESSOR_FRAGMENT ) ) { assert( i == program->Base.NumInstructions - 1 ); @@ -955,8 +983,10 @@ tgsi_mesa_compile_fp_program( GLboolean tgsi_mesa_compile_vp_program( const struct gl_vertex_program *program, + const GLuint inputMapping[], + const GLuint outputMapping[], struct tgsi_token *tokens, - GLuint maxTokens ) + GLuint maxTokens) { GLuint i, ti; struct tgsi_header *header; @@ -983,6 +1013,8 @@ tgsi_mesa_compile_vp_program( &fullinst, inputs_read, outputs_written, + inputMapping, + outputMapping, 0, TGSI_PROCESSOR_VERTEX ) ) { assert( i == program->Base.NumInstructions - 1 ); diff --git a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h index fda3fa397f8..017cfce72ea 100644 --- a/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h +++ b/src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h @@ -10,12 +10,17 @@ struct tgsi_token; GLboolean tgsi_mesa_compile_fp_program( const struct gl_fragment_program *program, + const GLuint inputMapping[], + const GLuint interpMode[], + const GLuint outputMapping[], struct tgsi_token *tokens, GLuint maxTokens ); GLboolean tgsi_mesa_compile_vp_program( const struct gl_vertex_program *program, + const GLuint inputMapping[], + const GLuint outputMapping[], struct tgsi_token *tokens, GLuint maxTokens ); diff --git a/src/mesa/state_tracker/st_atom_fs.c b/src/mesa/state_tracker/st_atom_fs.c index dc3e5258d82..3df2c6750ab 100644 --- a/src/mesa/state_tracker/st_atom_fs.c +++ b/src/mesa/state_tracker/st_atom_fs.c @@ -42,17 +42,34 @@ #include "st_atom.h" #include "st_program.h" -#define TGSI_DEBUG 0 +#define TGSI_DEBUG 1 static void compile_fs( struct st_context *st ) { + /* Map FRAG_RESULT_COLR to output 1, map FRAG_RESULT_DEPR to output 0 */ + static const GLuint outputMapping[2] = {1, 0}; struct st_fragment_program *fp = st->fp; struct pipe_shader_state fs; struct pipe_shader_state *cached; + GLuint interpMode[16]; /* XXX size? */ + GLuint i; + + for (i = 0; i < 16; i++) { + if (fp->Base.Base.InputsRead & (1 << i)) { + if (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1) { + interpMode[i] = TGSI_INTERPOLATE_LINEAR; + } + else { + interpMode[i] = TGSI_INTERPOLATE_PERSPECTIVE; + } + } + } /* XXX: fix static allocation of tokens: */ - tgsi_mesa_compile_fp_program( &fp->Base, fp->tokens, ST_FP_MAX_TOKENS ); + tgsi_mesa_compile_fp_program( &fp->Base, NULL, interpMode, + outputMapping, + fp->tokens, ST_FP_MAX_TOKENS ); memset(&fs, 0, sizeof(fs)); fs.inputs_read @@ -64,7 +81,7 @@ static void compile_fs( struct st_context *st ) fp->fsx = cached; if (TGSI_DEBUG) - tgsi_dump( fp->tokens, TGSI_DUMP_VERBOSE ); + tgsi_dump( fp->tokens, 0/*TGSI_DUMP_VERBOSE*/ ); fp->dirty = 0; } diff --git a/src/mesa/state_tracker/st_atom_vs.c b/src/mesa/state_tracker/st_atom_vs.c index 8f1df80a7f7..8de19e41eeb 100644 --- a/src/mesa/state_tracker/st_atom_vs.c +++ b/src/mesa/state_tracker/st_atom_vs.c @@ -51,25 +51,61 @@ -/* translate shader to TGSI format -*/ +/** + * Translate Mesa shader to TGSI format + */ static void compile_vs( struct st_context *st ) { struct st_vertex_program *vp = st->vp; struct pipe_shader_state vs; struct pipe_shader_state *cached; + GLuint i; + + memset(&vs, 0, sizeof(vs)); + + /* + * Determine how many inputs there are. + * Also, compute two look-up tables that map between Mesa VERT_ATTRIB_x + * values and TGSI generic input indexes. + */ + for (i = 0; i < MAX_VERTEX_PROGRAM_ATTRIBS; i++) { + if (vp->Base.Base.InputsRead & (1 << i)) { + vp->input_to_index[i] = vs.num_inputs; + vp->index_to_input[vs.num_inputs] = i; + vs.num_inputs++; + } + } + + /* + * Determine output register mapping. + */ + for (i = 0; i < VERT_RESULT_MAX; i++) { + if (vp->Base.Base.OutputsWritten & (1 << i)) { + vp->output_to_index[i] = vs.num_outputs; + vp->index_to_output[vs.num_outputs] = i; + vs.num_outputs++; + } + } + + /* XXX: fix static allocation of tokens: */ - tgsi_mesa_compile_vp_program( &vp->Base, vp->tokens, ST_FP_MAX_TOKENS ); + tgsi_mesa_compile_vp_program( &vp->Base, + vp->input_to_index, + vp->output_to_index, + vp->tokens, ST_FP_MAX_TOKENS ); - memset(&vs, 0, sizeof(vs)); +#if 01 vs.inputs_read = tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead); +#endif vs.outputs_written = tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten); + vs.tokens = &vp->tokens[0]; cached = st_cached_shader_state(st, &vs); + vp->vs = cached; if (TGSI_DEBUG) @@ -121,7 +157,7 @@ static void update_vs( struct st_context *st ) const struct st_tracked_state st_update_vs = { .name = "st_update_vs", .dirty = { - .mesa = 0, + .mesa = _NEW_PROGRAM, .st = ST_NEW_VERTEX_PROGRAM, }, .update = update_vs diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c index 2ea498663b1..65cac9dbde8 100644 --- a/src/mesa/state_tracker/st_cb_clear.c +++ b/src/mesa/state_tracker/st_cb_clear.c @@ -119,12 +119,19 @@ is_depth_stencil_format(GLuint pipeFormat) * Create a simple fragment shader that just passes through the fragment color. */ static struct st_fragment_program * -make_color_shader(struct st_context *st) +make_frag_shader(struct st_context *st) { + static const GLuint outputMapping[] = { 1, 0 }; GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; struct gl_program *p; GLboolean b; + GLuint interpMode[16]; + GLuint i; + + /* XXX temporary */ + for (i = 0; i < 16; i++) + interpMode[i] = TGSI_INTERPOLATE_LINEAR; p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); if (!p) @@ -151,7 +158,8 @@ make_color_shader(struct st_context *st) stfp = (struct st_fragment_program *) p; /* compile into tgsi format */ - b = tgsi_mesa_compile_fp_program(&stfp->Base, + b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode, + outputMapping, stfp->tokens, ST_FP_MAX_TOKENS); assert(b); @@ -166,6 +174,11 @@ make_color_shader(struct st_context *st) static struct st_vertex_program * make_vertex_shader(struct st_context *st) { + /* Map VERT_ATTRIB_POS to 0, VERT_ATTRIB_COLOR0 to 1 */ + static const GLuint inputMapping[4] = { 0, 0, 0, 1 }; + /* Map VERT_RESULT_HPOS to 0, VERT_RESULT_COL0 to 1 */ + static const GLuint outputMapping[2] = { 0, 1 }; + GLcontext *ctx = st->ctx; struct st_vertex_program *stvp; struct gl_program *p; @@ -204,6 +217,8 @@ make_vertex_shader(struct st_context *st) stvp = (struct st_vertex_program *) p; /* compile into tgsi format */ b = tgsi_mesa_compile_vp_program(&stvp->Base, + inputMapping, + outputMapping, stvp->tokens, ST_FP_MAX_TOKENS); assert(b); @@ -349,7 +364,7 @@ clear_with_quad(GLcontext *ctx, struct pipe_shader_state fs; const struct pipe_shader_state *cached; if (!stfp) { - stfp = make_color_shader(st); + stfp = make_frag_shader(st); } memset(&fs, 0, sizeof(fs)); fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead); diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c index 37e40636f61..731c060c11d 100644 --- a/src/mesa/state_tracker/st_cb_drawpixels.c +++ b/src/mesa/state_tracker/st_cb_drawpixels.c @@ -56,10 +56,17 @@ static struct st_fragment_program * make_fragment_shader(struct st_context *st) { + static const GLuint outputMapping[2] = { 1, 0 }; GLcontext *ctx = st->ctx; struct st_fragment_program *stfp; struct gl_program *p; GLboolean b; + GLuint interpMode[16]; + GLuint i; + + /* XXX temporary */ + for (i = 0; i < 16; i++) + interpMode[i] = TGSI_INTERPOLATE_LINEAR; p = ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 0); if (!p) @@ -88,7 +95,8 @@ make_fragment_shader(struct st_context *st) stfp = (struct st_fragment_program *) p; /* compile into tgsi format */ - b = tgsi_mesa_compile_fp_program(&stfp->Base, + b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode, + outputMapping, stfp->tokens, ST_FP_MAX_TOKENS); assert(b); @@ -103,6 +111,8 @@ make_fragment_shader(struct st_context *st) static struct st_vertex_program * make_vertex_shader(struct st_context *st) { + /* Map VERT_RESULT_HPOS to 0, VERT_RESULT_TEX0 to 1 */ + static const GLuint outputMapping[] = { 0, 0, 0, 0, 1 }; GLcontext *ctx = st->ctx; struct st_vertex_program *stvp; struct gl_program *p; @@ -140,7 +150,8 @@ make_vertex_shader(struct st_context *st) stvp = (struct st_vertex_program *) p; /* compile into tgsi format */ - b = tgsi_mesa_compile_vp_program(&stvp->Base, + b = tgsi_mesa_compile_vp_program(&stvp->Base, NULL, + outputMapping, stvp->tokens, ST_FP_MAX_TOKENS); assert(b); diff --git a/src/mesa/state_tracker/st_draw.c b/src/mesa/state_tracker/st_draw.c index ac63a387205..bff0ad7ef7a 100644 --- a/src/mesa/state_tracker/st_draw.c +++ b/src/mesa/state_tracker/st_draw.c @@ -37,10 +37,12 @@ #include "tnl/t_vp_build.h" -#include "st_context.h" #include "st_atom.h" -#include "st_draw.h" +#include "st_context.h" #include "st_cb_bufferobjects.h" +#include "st_draw.h" +#include "st_program.h" + #include "pipe/p_context.h" #include "pipe/p_defines.h" #include "pipe/p_winsys.h" @@ -185,18 +187,22 @@ st_draw_vbo(GLcontext *ctx, GLuint max_index) { struct pipe_context *pipe = ctx->st->pipe; - GLuint attr, i; - GLbitfield attrsNeeded; + const struct st_vertex_program *vp = ctx->st->vp; + const struct pipe_shader_state *vs; const unsigned attr0_offset = (unsigned) arrays[0]->Ptr; + GLboolean needDefaultAttribs = GL_FALSE; + GLuint attr; st_validate_state(ctx->st); - update_default_attribs_buffer(ctx); - /* this must be after state validation */ - attrsNeeded = ctx->st->state.vs->inputs_read; + /* must do this after state validation! */ + vs = ctx->st->state.vs; + + /* loop over TGSI shader inputs */ + for (attr = 0; attr < vs->num_inputs; attr++) { + const GLuint mesaAttr = vp->index_to_input[attr]; + struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj; - /* tell pipe about the vertex array element/attributes */ - for (attr = 0; attr < 16; attr++) { struct pipe_vertex_buffer vbuffer; struct pipe_vertex_element velement; @@ -206,43 +212,40 @@ st_draw_vbo(GLcontext *ctx, velement.vertex_buffer_index = 0; velement.src_format = 0; - if (attrsNeeded & (1 << attr)) { - const GLuint mesaAttr = tgsi_attrib_to_mesa_attrib(attr); - struct gl_buffer_object *bufobj = arrays[mesaAttr]->BufferObj; - - if (bufobj && bufobj->Name) { - struct st_buffer_object *stobj = st_buffer_object(bufobj); - /* Recall that for VBOs, the gl_client_array->Ptr field is - * really an offset from the start of the VBO, not a pointer. - */ - unsigned offset = (unsigned) arrays[mesaAttr]->Ptr; - - assert(stobj->buffer); - - vbuffer.buffer = stobj->buffer; - vbuffer.buffer_offset = attr0_offset; /* in bytes */ - vbuffer.pitch = arrays[mesaAttr]->StrideB; /* in bytes */ - vbuffer.max_index = 0; /* need this? */ - - velement.src_offset = offset - attr0_offset; /* bytes */ - velement.vertex_buffer_index = attr; - velement.dst_offset = 0; /* need this? */ - velement.src_format = pipe_vertex_format(arrays[mesaAttr]->Type, - arrays[mesaAttr]->Size); - assert(velement.src_format); - } - else { - /* use the default attribute buffer */ - vbuffer.buffer = ctx->st->default_attrib_buffer; - vbuffer.buffer_offset = 0; - vbuffer.pitch = 0; /* must be zero! */ - vbuffer.max_index = 1; - - velement.src_offset = attr * 4 * sizeof(GLfloat); - velement.vertex_buffer_index = attr; - velement.dst_offset = 0; - velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; - } + if (bufobj && bufobj->Name) { + struct st_buffer_object *stobj = st_buffer_object(bufobj); + /* Recall that for VBOs, the gl_client_array->Ptr field is + * really an offset from the start of the VBO, not a pointer. + */ + unsigned offset = (unsigned) arrays[mesaAttr]->Ptr; + + assert(stobj->buffer); + + vbuffer.buffer = stobj->buffer; + vbuffer.buffer_offset = attr0_offset; /* in bytes */ + vbuffer.pitch = arrays[mesaAttr]->StrideB; /* in bytes */ + vbuffer.max_index = 0; /* need this? */ + + velement.src_offset = offset - attr0_offset; /* bytes */ + velement.vertex_buffer_index = attr; + velement.dst_offset = 0; /* need this? */ + velement.src_format = pipe_vertex_format(arrays[mesaAttr]->Type, + arrays[mesaAttr]->Size); + assert(velement.src_format); + } + else { + /* use the default attribute buffer */ + needDefaultAttribs = GL_TRUE; + + vbuffer.buffer = ctx->st->default_attrib_buffer; + vbuffer.buffer_offset = 0; + vbuffer.pitch = 0; /* must be zero! */ + vbuffer.max_index = 1; + + velement.src_offset = mesaAttr * 4 * sizeof(GLfloat); + velement.vertex_buffer_index = attr; + velement.dst_offset = 0; + velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT; } if (attr == 0) @@ -252,12 +255,17 @@ st_draw_vbo(GLcontext *ctx, pipe->set_vertex_element(pipe, attr, &velement); } + if (needDefaultAttribs) { + update_default_attribs_buffer(ctx); + } + + /* do actual drawing */ if (ib) { /* indexed primitive */ struct gl_buffer_object *bufobj = ib->obj; struct pipe_buffer_handle *bh = NULL; - unsigned indexSize; + unsigned indexSize, i; if (bufobj && bufobj->Name) { /* elements/indexes are in a real VBO */ @@ -285,6 +293,7 @@ st_draw_vbo(GLcontext *ctx, } else { /* non-indexed */ + GLuint i; for (i = 0; i < nr_prims; i++) { pipe->draw_arrays(pipe, prims[i].mode, prims[i].start, prims[i].count); } diff --git a/src/mesa/state_tracker/st_program.h b/src/mesa/state_tracker/st_program.h index a2f114b1bab..68ceba4d787 100644 --- a/src/mesa/state_tracker/st_program.h +++ b/src/mesa/state_tracker/st_program.h @@ -61,13 +61,20 @@ struct st_fragment_program struct st_vertex_program { - struct gl_vertex_program Base; - GLboolean error; /* If program is malformed for any reason. */ + struct gl_vertex_program Base; /**< The Mesa vertex program */ + GLboolean error; /**< Set if program is malformed for any reason. */ - GLuint id; /* String id, for tracking - * ProgramStringNotify changes. - */ + GLuint id; /**< String id, for tracking ProgramStringNotify changes. */ + + /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */ + GLuint input_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; + /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */ + GLuint index_to_input[MAX_VERTEX_PROGRAM_ATTRIBS]; + + GLuint output_to_index[MAX_VERTEX_PROGRAM_ATTRIBS]; + GLuint index_to_output[MAX_VERTEX_PROGRAM_ATTRIBS]; + /** The program in TGSI format */ struct tgsi_token tokens[ST_FP_MAX_TOKENS]; GLboolean dirty; -- cgit v1.2.3