From: Brian Paul Date: Sat, 12 Nov 2005 17:53:14 +0000 (+0000) Subject: Move stuff common to vertex/fragment_program into the base class, including: X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=de99760bf3511d05185799c4fb4347f9e5f420f4;p=mesa.git Move stuff common to vertex/fragment_program into the base class, including: Instructions, InputsRead, OutputsWritten, and Parameters. Also, added debug functions: _mesa_print_instruction(), _mesa_print_program_parameters() and revamp _mesa_print_program(). --- diff --git a/src/mesa/drivers/dri/i915/i915_fragprog.c b/src/mesa/drivers/dri/i915/i915_fragprog.c index 20424b1da43..a96b373a217 100644 --- a/src/mesa/drivers/dri/i915/i915_fragprog.c +++ b/src/mesa/drivers/dri/i915/i915_fragprog.c @@ -130,7 +130,7 @@ static GLuint src_vector( struct i915_fragment_program *p, case PROGRAM_STATE_VAR: case PROGRAM_NAMED_PARAM: src = i915_emit_param4fv( - p, program->Parameters->ParameterValues[source->Index] ); + p, program->Base.Parameters->ParameterValues[source->Index] ); break; default: @@ -250,7 +250,7 @@ do { \ static void upload_program( struct i915_fragment_program *p ) { const struct fragment_program *program = p->ctx->FragmentProgram._Current; - const struct prog_instruction *inst = program->Instructions; + const struct prog_instruction *inst = program->Base.Instructions; /* _mesa_debug_fp_inst(program->Base.NumInstructions, inst); */ @@ -789,7 +789,7 @@ static void fixup_depth_write( struct i915_fragment_program *p ) static void check_wpos( struct i915_fragment_program *p ) { - GLuint inputs = p->FragProg.InputsRead; + GLuint inputs = p->FragProg.Base.InputsRead; GLint i; p->wpos_tex = -1; @@ -828,7 +828,7 @@ static void track_params( struct i915_fragment_program *p ) GLint i; if (p->nr_params) - _mesa_load_state_parameters(p->ctx, p->FragProg.Parameters); + _mesa_load_state_parameters(p->ctx, p->FragProg.Base.Parameters); for (i = 0; i < p->nr_params; i++) { GLint reg = p->param[i].reg; @@ -955,7 +955,7 @@ void i915ValidateFragmentProgram( i915ContextPtr i915 ) struct i915_fragment_program *p = (struct i915_fragment_program *)ctx->FragmentProgram._Current; - GLuint inputsRead = p->FragProg.InputsRead; + const GLuint inputsRead = p->FragProg.Base.InputsRead; GLuint s4 = i915->state.Ctx[I915_CTXREG_LIS4] & ~S4_VFMT_MASK; GLuint s2 = S2_TEXCOORD_NONE; int i, offset = 0; diff --git a/src/mesa/drivers/dri/i915/intel_tris.c b/src/mesa/drivers/dri/i915/intel_tris.c index bb0a7713e60..cef6db7a195 100644 --- a/src/mesa/drivers/dri/i915/intel_tris.c +++ b/src/mesa/drivers/dri/i915/intel_tris.c @@ -642,8 +642,8 @@ void intelChooseRenderState(GLcontext *ctx) TNLcontext *tnl = TNL_CONTEXT(ctx); intelContextPtr intel = INTEL_CONTEXT(ctx); GLuint flags = ctx->_TriangleCaps; - struct fragment_program *program = ctx->FragmentProgram._Current; - GLboolean have_wpos = (program && (program->InputsRead & FRAG_BIT_WPOS)); + struct fragment_program *fprog = ctx->FragmentProgram._Current; + GLboolean have_wpos = (fprog && (fprog->Base.InputsRead & FRAG_BIT_WPOS)); GLuint index = 0; if (INTEL_DEBUG & DEBUG_STATE) diff --git a/src/mesa/drivers/dri/r300/r300_context.h b/src/mesa/drivers/dri/r300/r300_context.h index c35fd1e634b..5d6ebe27aad 100644 --- a/src/mesa/drivers/dri/r300/r300_context.h +++ b/src/mesa/drivers/dri/r300/r300_context.h @@ -598,7 +598,7 @@ struct r300_vertex_program { struct r300_vertex_shader_fragment params; int pos_end; - unsigned long num_temporaries; /* Number of temp vars used by program */ + int num_temporaries; /* Number of temp vars used by program */ int inputs[VERT_ATTRIB_MAX]; int outputs[VERT_RESULT_MAX]; }; diff --git a/src/mesa/drivers/dri/r300/r300_fragprog.c b/src/mesa/drivers/dri/r300/r300_fragprog.c index e86904c622b..547a099fed8 100644 --- a/src/mesa/drivers/dri/r300/r300_fragprog.c +++ b/src/mesa/drivers/dri/r300/r300_fragprog.c @@ -421,7 +421,7 @@ static pfs_reg_t t_src(struct r300_fragment_program *rp, break; case PROGRAM_STATE_VAR: case PROGRAM_NAMED_PARAM: - r = emit_param4fv(rp, rp->mesa_program.Parameters->ParameterValues[fpsrc.Index]); + r = emit_param4fv(rp, rp->mesa_program.Base.Parameters->ParameterValues[fpsrc.Index]); break; default: ERROR("unknown SrcReg->File %x\n", fpsrc.File); @@ -747,7 +747,7 @@ static void emit_arith(struct r300_fragment_program *rp, int op, static GLboolean parse_program(struct r300_fragment_program *rp) { struct fragment_program *mp = &rp->mesa_program; - const struct prog_instruction *inst = mp->Instructions; + const struct prog_instruction *inst = mp->Base.Instructions; struct prog_instruction *fpi; pfs_reg_t src0, src1, src2, dest, temp; int flags = 0; @@ -757,7 +757,7 @@ static GLboolean parse_program(struct r300_fragment_program *rp) return GL_FALSE; } - for (fpi=mp->Instructions; fpi->Opcode != OPCODE_END; fpi++) { + for (fpi=mp->Base.Instructions; fpi->Opcode != OPCODE_END; fpi++) { if (fpi->Saturate) { flags = PFS_FLAG_SAT; } @@ -910,7 +910,7 @@ static void init_program(struct r300_fragment_program *rp) { struct fragment_program *mp = &rp->mesa_program; struct prog_instruction *fpi; - GLuint InputsRead = mp->InputsRead; + GLuint InputsRead = mp->Base.InputsRead; GLuint temps_used = 0; /* for rp->temps[] */ int i; @@ -979,11 +979,11 @@ static void init_program(struct r300_fragment_program *rp) * Possibly not too bad actually, as we could add to this later and * find out when inputs are last used so we can reuse them as temps. */ - if (!mp->Instructions) { + if (!mp->Base.Instructions) { ERROR("No instructions found in program\n"); return; } - for (fpi=mp->Instructions;fpi->Opcode != OPCODE_END; fpi++) { + for (fpi=mp->Base.Instructions;fpi->Opcode != OPCODE_END; fpi++) { for (i=0;i<3;i++) { if (fpi->SrcReg[i].File == PROGRAM_TEMPORARY) { if (!(temps_used & (1 << fpi->SrcReg[i].Index))) { @@ -1009,7 +1009,7 @@ static void update_params(struct r300_fragment_program *rp) { /* Ask Mesa nicely to fill in ParameterValues for us */ if (rp->param_nr) - _mesa_load_state_parameters(rp->ctx, mp->Parameters); + _mesa_load_state_parameters(rp->ctx, mp->Base.Parameters); for (i=0;iparam_nr;i++) COPY_4V(rp->constant[rp->param[i].idx], rp->param[i].values); @@ -1054,9 +1054,7 @@ static void dump_program(struct r300_fragment_program *rp) fprintf(stderr, "Mesa program:\n"); fprintf(stderr, "-------------\n"); - _mesa_print_program(rp->mesa_program.NumTexInstructions + - rp->mesa_program.NumAluInstructions, - rp->mesa_program.Instructions); + _mesa_print_program(&rp->mesa_program.Base); fflush(stdout); fprintf(stderr, "Hardware program\n"); diff --git a/src/mesa/drivers/dri/r300/r300_maos.c b/src/mesa/drivers/dri/r300/r300_maos.c index 52827c2d5dc..6de0fb14f0f 100644 --- a/src/mesa/drivers/dri/r300/r300_maos.c +++ b/src/mesa/drivers/dri/r300/r300_maos.c @@ -296,7 +296,7 @@ void r300EmitArrays(GLcontext * ctx, GLboolean immd) } if (hw_tcl_on) { - GLuint InputsRead = CURRENT_VERTEX_SHADER(ctx)->InputsRead; + GLuint InputsRead = CURRENT_VERTEX_SHADER(ctx)->Base.InputsRead; struct r300_vertex_program *prog=(struct r300_vertex_program *)CURRENT_VERTEX_SHADER(ctx); if (InputsRead & (1<hw.vof.cmd[R300_VOF_CNTL_0]=0; r300->hw.vof.cmd[R300_VOF_CNTL_1]=0; if (hw_tcl_on){ - GLuint OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten; + GLuint OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->Base.OutputsWritten; if(OutputsWritten & (1<hw.vof.cmd[R300_VOF_CNTL_0] |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT; diff --git a/src/mesa/drivers/dri/r300/r300_program.h b/src/mesa/drivers/dri/r300/r300_program.h index d1754c06653..3defe106c2d 100644 --- a/src/mesa/drivers/dri/r300/r300_program.h +++ b/src/mesa/drivers/dri/r300/r300_program.h @@ -146,6 +146,5 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ((arg2) << R300_FPI2_ARG2A_SHIFT)) extern void debug_vp(GLcontext *ctx, struct vertex_program *vp); -extern void dump_program_params(GLcontext *ctx, struct vertex_program *vp); #endif /* __R300_PROGRAM_H__ */ diff --git a/src/mesa/drivers/dri/r300/r300_state.c b/src/mesa/drivers/dri/r300/r300_state.c index 4422a233367..cc60785aac1 100644 --- a/src/mesa/drivers/dri/r300/r300_state.c +++ b/src/mesa/drivers/dri/r300/r300_state.c @@ -1012,7 +1012,7 @@ void r300_setup_textures(GLcontext *ctx) GLuint OutputsWritten; if(hw_tcl_on) - OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten; + OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->Base.OutputsWritten; R300_STATECHANGE(r300, txe); R300_STATECHANGE(r300, tex.filter); @@ -1110,12 +1110,12 @@ void r300_setup_rs_unit(GLcontext *ctx) int i; if(hw_tcl_on) - OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten; + OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->Base.OutputsWritten; else OutputsWritten = r300->state.render_inputs; if (ctx->FragmentProgram._Current) - InputsRead = ctx->FragmentProgram._Current->InputsRead; + InputsRead = ctx->FragmentProgram._Current->Base.InputsRead; else { fprintf(stderr, "No ctx->FragmentProgram._Current!!\n"); return; /* This should only ever happen once.. */ @@ -1213,7 +1213,7 @@ void r300_setup_rs_unit(GLcontext *ctx) GLuint OutputsWritten; if(hw_tcl_on) - OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->OutputsWritten; + OutputsWritten = CURRENT_VERTEX_SHADER(ctx)->Base.OutputsWritten; /* This needs to be rewritten - it is a hack at best */ diff --git a/src/mesa/drivers/dri/r300/r300_vertexprog.c b/src/mesa/drivers/dri/r300/r300_vertexprog.c index 2462ac8d7cb..f6c9db9fdc1 100644 --- a/src/mesa/drivers/dri/r300/r300_vertexprog.c +++ b/src/mesa/drivers/dri/r300/r300_vertexprog.c @@ -132,67 +132,18 @@ static char *dst_mask_names[4]={ "X", "Y", "Z", "W" }; XPD v,v v cross product */ -void dump_program_params(GLcontext *ctx, struct vertex_program *vp) -{ - int i; - int pi; - - fprintf(stderr, "NumInstructions=%d\n", vp->Base.NumInstructions); - fprintf(stderr, "NumTemporaries=%d\n", vp->Base.NumTemporaries); - fprintf(stderr, "NumParameters=%d\n", vp->Base.NumParameters); - fprintf(stderr, "NumAttributes=%d\n", vp->Base.NumAttributes); - fprintf(stderr, "NumAddressRegs=%d\n", vp->Base.NumAddressRegs); - - _mesa_load_state_parameters(ctx, vp->Parameters); - -#if 0 - for(pi=0; pi < vp->Base.NumParameters; pi++){ - fprintf(stderr, "{ "); - for(i=0; i < 4; i++) - fprintf(stderr, "%f ", vp->Base.LocalParams[pi][i]); - fprintf(stderr, "}\n"); - } -#endif - for(pi=0; pi < vp->Parameters->NumParameters; pi++){ - fprintf(stderr, "param %02d:", pi); - - switch(vp->Parameters->Parameters[pi].Type){ - - case PROGRAM_NAMED_PARAM: - fprintf(stderr, "%s", vp->Parameters->Parameters[pi].Name); - fprintf(stderr, "(NAMED_PARAMETER)"); - break; - - case PROGRAM_CONSTANT: - fprintf(stderr, "(CONSTANT)"); - break; - - case PROGRAM_STATE_VAR: - fprintf(stderr, "(STATE)\n"); - break; - - default: - fprintf(stderr, "(UNK)\n"); - break; - } - - fprintf(stderr, "{ "); - for(i=0; i < 4; i++) - fprintf(stderr, "%f ", vp->Parameters->ParameterValues[pi][i]); - fprintf(stderr, "}\n"); - - } -} - +/* + * XXX get rid of this function. Use _mesa_print_program() instead. + */ void debug_vp(GLcontext *ctx, struct vertex_program *vp) { struct prog_instruction *vpi; int i, operand_index; int operator_index; - dump_program_params(ctx, vp); + _mesa_print_program_parameters(ctx, &vp->Base); - vpi=vp->Instructions; + vpi=vp->Base.Instructions; for(;; vpi++){ if(vpi->Opcode == OPCODE_END) @@ -250,26 +201,28 @@ int r300VertexProgUpdateParams(GLcontext *ctx, struct r300_vertex_program *vp, f int pi; struct vertex_program *mesa_vp=(void *)vp; float *dst_o=dst; + struct program_parameter_list *paramList; - _mesa_load_state_parameters(ctx, mesa_vp->Parameters); + _mesa_load_state_parameters(ctx, mesa_vp->Base.Parameters); //debug_vp(ctx, mesa_vp); - if(mesa_vp->Parameters->NumParameters * 4 > VSF_MAX_FRAGMENT_LENGTH){ + if(mesa_vp->Base.Parameters->NumParameters * 4 > VSF_MAX_FRAGMENT_LENGTH){ fprintf(stderr, "%s:Params exhausted\n", __FUNCTION__); exit(-1); } - for(pi=0; pi < mesa_vp->Parameters->NumParameters; pi++){ - switch(mesa_vp->Parameters->Parameters[pi].Type){ + paramList = mesa_vp->Base.Parameters; + for(pi=0; pi < paramList->NumParameters; pi++){ + switch(paramList->Parameters[pi].Type){ case PROGRAM_STATE_VAR: case PROGRAM_NAMED_PARAM: //fprintf(stderr, "%s", vp->Parameters->Parameters[pi].Name); case PROGRAM_CONSTANT: - *dst++=mesa_vp->Parameters->ParameterValues[pi][0]; - *dst++=mesa_vp->Parameters->ParameterValues[pi][1]; - *dst++=mesa_vp->Parameters->ParameterValues[pi][2]; - *dst++=mesa_vp->Parameters->ParameterValues[pi][3]; + *dst++=paramList->ParameterValues[pi][0]; + *dst++=paramList->ParameterValues[pi][1]; + *dst++=paramList->ParameterValues[pi][2]; + *dst++=paramList->ParameterValues[pi][3]; break; default: _mesa_problem(NULL, "Bad param type in %s", __FUNCTION__); @@ -509,39 +462,39 @@ void translate_vertex_shader(struct r300_vertex_program *vp) for(i=0; i < VERT_RESULT_MAX; i++) vp->outputs[i] = -1; - assert(mesa_vp->OutputsWritten & (1 << VERT_RESULT_HPOS)); - assert(mesa_vp->OutputsWritten & (1 << VERT_RESULT_COL0)); + assert(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_HPOS)); + assert(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_COL0)); /* Assign outputs */ - if(mesa_vp->OutputsWritten & (1 << VERT_RESULT_HPOS)) + if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_HPOS)) vp->outputs[VERT_RESULT_HPOS] = cur_reg++; - if(mesa_vp->OutputsWritten & (1 << VERT_RESULT_PSIZ)) + if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_PSIZ)) vp->outputs[VERT_RESULT_PSIZ] = cur_reg++; - if(mesa_vp->OutputsWritten & (1 << VERT_RESULT_COL0)) + if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_COL0)) vp->outputs[VERT_RESULT_COL0] = cur_reg++; #if 0 /* Not supported yet */ - if(mesa_vp->OutputsWritten & (1 << VERT_RESULT_BFC0)) + if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_BFC0)) vp->outputs[VERT_RESULT_BFC0] = cur_reg++; - if(mesa_vp->OutputsWritten & (1 << VERT_RESULT_COL1)) + if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_COL1)) vp->outputs[VERT_RESULT_COL1] = cur_reg++; - if(mesa_vp->OutputsWritten & (1 << VERT_RESULT_BFC1)) + if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_BFC1)) vp->outputs[VERT_RESULT_BFC1] = cur_reg++; - if(mesa_vp->OutputsWritten & (1 << VERT_RESULT_FOGC)) + if(mesa_vp->Base.OutputsWritten & (1 << VERT_RESULT_FOGC)) vp->outputs[VERT_RESULT_FOGC] = cur_reg++; #endif for(i=VERT_RESULT_TEX0; i <= VERT_RESULT_TEX7; i++) - if(mesa_vp->OutputsWritten & (1 << i)) + if(mesa_vp->Base.OutputsWritten & (1 << i)) vp->outputs[i] = cur_reg++; o_inst=vp->program.body.i; - for(vpi=mesa_vp->Instructions; vpi->Opcode != OPCODE_END; vpi++, o_inst++){ + for(vpi=mesa_vp->Base.Instructions; vpi->Opcode != OPCODE_END; vpi++, o_inst++){ operands=op_operands(vpi->Opcode); are_srcs_scalar=operands & SCALAR_FLAG; diff --git a/src/mesa/main/context.h b/src/mesa/main/context.h index 8b7e7c9952b..9c6ef520792 100644 --- a/src/mesa/main/context.h +++ b/src/mesa/main/context.h @@ -321,9 +321,9 @@ do { \ (CTX)->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR) \ || (CTX)->Fog.ColorSumEnabled \ || ((CTX)->VertexProgram._Enabled && \ - ((CTX)->VertexProgram.Current->InputsRead & VERT_BIT_COLOR1)) \ + ((CTX)->VertexProgram.Current->Base.InputsRead & VERT_BIT_COLOR1)) \ || ((CTX)->FragmentProgram._Enabled && \ - ((CTX)->FragmentProgram.Current->InputsRead & FRAG_BIT_COL1)) \ + ((CTX)->FragmentProgram.Current->Base.InputsRead & FRAG_BIT_COL1)) \ ) diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index ba0d1c27dc2..1a90583295c 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -1761,18 +1761,33 @@ struct program GLenum Target; GLenum Format; /**< String encoding format */ GLboolean Resident; + + struct prog_instruction *Instructions; + + GLbitfield InputsRead; /* Bitmask of which input regs are read */ + GLbitfield OutputsWritten; /* Bitmask of which output regs are written to */ + + /** Named parameters, constants, etc. from program text */ + struct program_parameter_list *Parameters; + /** Numbered local parameters */ GLfloat LocalParams[MAX_PROGRAM_LOCAL_PARAMS][4]; - GLuint NumInstructions; /* GL_ARB_vertex/fragment_program */ + + /** Logical counts */ + /*@{*/ + GLuint NumInstructions; GLuint NumTemporaries; GLuint NumParameters; GLuint NumAttributes; GLuint NumAddressRegs; - /* native, h/w counts */ + /*@}*/ + /** Native, actual h/w counts */ + /*@{*/ GLuint NumNativeInstructions; GLuint NumNativeTemporaries; GLuint NumNativeParameters; GLuint NumNativeAttributes; GLuint NumNativeAddressRegs; + /*@}*/ }; @@ -1780,12 +1795,8 @@ struct program struct vertex_program { struct program Base; /* base class */ - struct prog_instruction *Instructions; /* Compiled instructions */ GLboolean IsNVProgram; /* GL_NV_vertex_program ? */ GLboolean IsPositionInvariant; /* GL_NV_vertex_program1_1 */ - GLbitfield InputsRead; /* Bitmask of which input regs are read */ - GLbitfield OutputsWritten; /* Bitmask of which output regs are written to */ - struct program_parameter_list *Parameters; /**< array [NumParameters] */ void *TnlData; /* should probably use Base.DriverData */ }; @@ -1794,10 +1805,7 @@ struct vertex_program struct fragment_program { struct program Base; /**< base class */ - struct prog_instruction *Instructions; /**< Compiled instructions */ - GLbitfield InputsRead; /**< Bitmask of which input regs are read */ - GLbitfield OutputsWritten; /**< Bitmask of which output regs are written to */ - GLbitfield TexturesUsed[MAX_TEXTURE_IMAGE_UNITS]; /**< TEXTURE_x_INDEX bitmask */ + GLbitfield TexturesUsed[MAX_TEXTURE_IMAGE_UNITS]; /**< TEXTURE_x_BIT bitmask */ GLuint NumAluInstructions; /**< GL_ARB_fragment_program */ GLuint NumTexInstructions; GLuint NumTexIndirections; @@ -1805,7 +1813,6 @@ struct fragment_program GLuint NumNativeTexInstructions; GLuint NumNativeTexIndirections; GLenum FogOption; - struct program_parameter_list *Parameters; /**< array [NumParameters] */ GLboolean UsesKill; }; diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c index 1d8bc18f244..7eb68db845a 100644 --- a/src/mesa/main/state.c +++ b/src/mesa/main/state.c @@ -930,11 +930,11 @@ update_program(GLcontext *ctx) * have a runable program or shader. */ ctx->VertexProgram._Enabled = ctx->VertexProgram.Enabled - && ctx->VertexProgram.Current->Instructions; + && ctx->VertexProgram.Current->Base.Instructions; ctx->FragmentProgram._Enabled = ctx->FragmentProgram.Enabled - && ctx->FragmentProgram.Current->Instructions; + && ctx->FragmentProgram.Current->Base.Instructions; ctx->ATIFragmentShader._Enabled = ctx->ATIFragmentShader.Enabled - && ctx->ATIFragmentShader.Current->Instructions; + && ctx->ATIFragmentShader.Current->Base.Instructions; ctx->FragmentProgram._Current = ctx->FragmentProgram.Current; ctx->FragmentProgram._Active = ctx->FragmentProgram._Enabled; diff --git a/src/mesa/main/texenvprogram.c b/src/mesa/main/texenvprogram.c index 8cd8a8630eb..9e041811475 100644 --- a/src/mesa/main/texenvprogram.c +++ b/src/mesa/main/texenvprogram.c @@ -428,7 +428,7 @@ static struct ureg register_param6( struct texenv_fragment_program *p, tokens[3] = s3; tokens[4] = s4; tokens[5] = s5; - idx = _mesa_add_state_reference( p->program->Parameters, tokens ); + idx = _mesa_add_state_reference( p->program->Base.Parameters, tokens ); return make_ureg(PROGRAM_STATE_VAR, idx); } @@ -441,7 +441,7 @@ static struct ureg register_param6( struct texenv_fragment_program *p, static struct ureg register_input( struct texenv_fragment_program *p, GLuint input ) { - p->program->InputsRead |= (1<program->Base.InputsRead |= (1 << input); return make_ureg(PROGRAM_INPUT, input); } @@ -478,7 +478,7 @@ emit_op(struct texenv_fragment_program *p, struct ureg src2 ) { GLuint nr = p->program->Base.NumInstructions++; - struct prog_instruction *inst = &p->program->Instructions[nr]; + struct prog_instruction *inst = &p->program->Base.Instructions[nr]; _mesa_memset(inst, 0, sizeof(*inst)); inst->Opcode = op; @@ -577,7 +577,7 @@ static struct ureg register_const4f( struct texenv_fragment_program *p, values[1] = s1; values[2] = s2; values[3] = s3; - idx = _mesa_add_unnamed_constant( p->program->Parameters, values ); + idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values ); return make_ureg(PROGRAM_STATE_VAR, idx); } @@ -986,7 +986,7 @@ static void create_new_program(struct state_key *key, GLcontext *ctx, p.state = key; p.program = program; - p.program->Instructions = MALLOC(sizeof(struct prog_instruction) * 100); + p.program->Base.Instructions = MALLOC(sizeof(struct prog_instruction) * 100); p.program->Base.NumInstructions = 0; p.program->Base.Target = GL_FRAGMENT_PROGRAM_ARB; p.program->NumTexIndirections = 1; /* correct? */ @@ -997,10 +997,10 @@ static void create_new_program(struct state_key *key, GLcontext *ctx, p.program->Base.NumTemporaries = p.program->Base.NumParameters = p.program->Base.NumAttributes = p.program->Base.NumAddressRegs = 0; - p.program->Parameters = _mesa_new_parameter_list(); + p.program->Base.Parameters = _mesa_new_parameter_list(); - p.program->InputsRead = 0; - p.program->OutputsWritten = 1 << FRAG_RESULT_COLR; + p.program->Base.InputsRead = 0; + p.program->Base.OutputsWritten = 1 << FRAG_RESULT_COLR; for (unit = 0; unit < MAX_TEXTURE_UNITS; unit++) p.src_texture[unit] = undef; @@ -1076,8 +1076,7 @@ static void create_new_program(struct state_key *key, GLcontext *ctx, &p.program->Base ); if (DISASSEM) { - _mesa_print_program(p.program->NumTexInstructions + p.program->NumAluInstructions, - p.program->Instructions); + _mesa_print_program(&p.program->Base); _mesa_printf("\n"); } diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index 043ca3bac38..b352d1a5ad6 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -3072,7 +3072,7 @@ update_texture_state( GLcontext *ctx ) */ if (ctx->FragmentProgram._Enabled) { ctx->Texture._EnabledCoordUnits |= - (ctx->FragmentProgram.Current->InputsRead >> FRAG_ATTRIB_TEX0); + (ctx->FragmentProgram.Current->Base.InputsRead >> FRAG_ATTRIB_TEX0); } } diff --git a/src/mesa/shader/arbfragparse.c b/src/mesa/shader/arbfragparse.c index 31223cc4737..e6470be9fe7 100644 --- a/src/mesa/shader/arbfragparse.c +++ b/src/mesa/shader/arbfragparse.c @@ -67,31 +67,31 @@ _mesa_parse_arb_fragment_program(GLcontext * ctx, GLenum target, } _mesa_memcpy(newInstructions, ap.FPInstructions, ap.Base.NumInstructions * sizeof(struct prog_instruction)); - if (program->Instructions) - _mesa_free(program->Instructions); - program->Instructions = newInstructions; + if (program->Base.Instructions) + _mesa_free(program->Base.Instructions); + program->Base.Instructions = newInstructions; program->Base.String = ap.Base.String; program->Base.NumInstructions = ap.Base.NumInstructions; program->Base.NumTemporaries = ap.Base.NumTemporaries; program->Base.NumParameters = ap.Base.NumParameters; program->Base.NumAttributes = ap.Base.NumAttributes; program->Base.NumAddressRegs = ap.Base.NumAddressRegs; - program->NumAluInstructions = ap.NumAluInstructions; - program->NumTexInstructions = ap.NumTexInstructions; - program->NumTexIndirections = ap.NumTexIndirections; - program->InputsRead = ap.InputsRead; - program->OutputsWritten = ap.OutputsWritten; + program->NumAluInstructions = ap.NumAluInstructions; + program->NumTexInstructions = ap.NumTexInstructions; + program->NumTexIndirections = ap.NumTexIndirections; + program->Base.InputsRead = ap.Base.InputsRead; + program->Base.OutputsWritten = ap.Base.OutputsWritten; for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++) program->TexturesUsed[i] = ap.TexturesUsed[i]; - if (program->Parameters) { + if (program->Base.Parameters) { /* free previous program's parameters */ - _mesa_free_parameter_list(program->Parameters); + _mesa_free_parameter_list(program->Base.Parameters); } - program->Parameters = ap.Parameters; + program->Base.Parameters = ap.Base.Parameters; program->FogOption = ap.FogOption; #if DEBUG_FP - _mesa_print_program(ap.Base.NumInstructions, ap.FPInstructions); + _mesa_print_program(&program.Base); #endif } diff --git a/src/mesa/shader/arbprogparse.c b/src/mesa/shader/arbprogparse.c index 5f039170c3b..e1a42e2dd9d 100644 --- a/src/mesa/shader/arbprogparse.c +++ b/src/mesa/shader/arbprogparse.c @@ -1518,7 +1518,7 @@ parse_attrib_binding(GLcontext * ctx, GLubyte ** inst, _mesa_error(ctx, GL_INVALID_OPERATION, msg); } - Program->InputsRead |= (1 << *inputReg); + Program->Base.InputsRead |= (1 << *inputReg); return err; } @@ -1609,7 +1609,7 @@ parse_result_binding(GLcontext *ctx, GLubyte **inst, break; } - Program->OutputsWritten |= (1 << *outputReg); + Program->Base.OutputsWritten |= (1 << *outputReg); return 0; } @@ -1698,9 +1698,8 @@ parse_param_elements (GLcontext * ctx, GLubyte ** inst, for (row = first_row; row <= last_row; row++) { state_tokens[3] = state_tokens[4] = row; - idx = - _mesa_add_state_reference (Program->Parameters, - state_tokens); + idx = _mesa_add_state_reference(Program->Base.Parameters, + state_tokens); if (param_var->param_binding_begin == ~0U) param_var->param_binding_begin = idx; param_var->param_binding_length++; @@ -1708,8 +1707,8 @@ parse_param_elements (GLcontext * ctx, GLubyte ** inst, } } else { - idx = - _mesa_add_state_reference (Program->Parameters, state_tokens); + idx = _mesa_add_state_reference(Program->Base.Parameters, + state_tokens); if (param_var->param_binding_begin == ~0U) param_var->param_binding_begin = idx; param_var->param_binding_length++; @@ -1720,7 +1719,7 @@ parse_param_elements (GLcontext * ctx, GLubyte ** inst, case PARAM_PROGRAM_ELEMENT: if (parse_program_single_item (ctx, inst, Program, state_tokens)) return 1; - idx = _mesa_add_state_reference (Program->Parameters, state_tokens); + idx = _mesa_add_state_reference (Program->Base.Parameters, state_tokens); if (param_var->param_binding_begin == ~0U) param_var->param_binding_begin = idx; param_var->param_binding_length++; @@ -1759,9 +1758,8 @@ parse_param_elements (GLcontext * ctx, GLubyte ** inst, for (new_idx = start_idx; new_idx <= end_idx; new_idx++) { state_tokens[2] = new_idx; - idx = - _mesa_add_state_reference (Program->Parameters, - state_tokens); + idx = _mesa_add_state_reference(Program->Base.Parameters, + state_tokens); param_var->param_binding_length++; Program->Base.NumParameters++; } @@ -1773,9 +1771,9 @@ parse_param_elements (GLcontext * ctx, GLubyte ** inst, case PARAM_CONSTANT: parse_constant (inst, const_values, Program, use); - idx = - _mesa_add_named_constant (Program->Parameters, - (char *) param_var->name, const_values); + idx = _mesa_add_named_constant(Program->Base.Parameters, + (char *) param_var->name, + const_values); if (param_var->param_binding_begin == ~0U) param_var->param_binding_begin = idx; param_var->param_binding_length++; @@ -3949,9 +3947,9 @@ _mesa_parse_arb_program (GLcontext * ctx, const GLubyte * str, GLsizei len, program->Base.NumTemporaries = program->Base.NumParameters = program->Base.NumAttributes = program->Base.NumAddressRegs = 0; - program->Parameters = _mesa_new_parameter_list (); - program->InputsRead = 0x0; - program->OutputsWritten = 0x0; + program->Base.Parameters = _mesa_new_parameter_list (); + program->Base.InputsRead = 0x0; + program->Base.OutputsWritten = 0x0; program->Position = 0; program->MajorVersion = program->MinorVersion = 0; program->PrecisionOption = GL_DONT_CARE; diff --git a/src/mesa/shader/arbprogparse.h b/src/mesa/shader/arbprogparse.h index 5dbf31a2b15..b8498ff281d 100644 --- a/src/mesa/shader/arbprogparse.h +++ b/src/mesa/shader/arbprogparse.h @@ -43,9 +43,11 @@ struct arb_program { struct program Base; +#if 0 struct program_parameter_list *Parameters; GLbitfield InputsRead; GLbitfield OutputsWritten; +#endif GLuint Position; /* Just used for error reporting while parsing */ GLuint MajorVersion; diff --git a/src/mesa/shader/arbvertparse.c b/src/mesa/shader/arbvertparse.c index bb18a2ea473..253f2937edf 100644 --- a/src/mesa/shader/arbvertparse.c +++ b/src/mesa/shader/arbvertparse.c @@ -71,9 +71,9 @@ _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target, } _mesa_memcpy(newInstructions, ap.VPInstructions, ap.Base.NumInstructions * sizeof(struct prog_instruction)); - if (program->Instructions) - _mesa_free(program->Instructions); - program->Instructions = newInstructions; + if (program->Base.Instructions) + _mesa_free(program->Base.Instructions); + program->Base.Instructions = newInstructions; program->Base.String = ap.Base.String; program->Base.NumInstructions = ap.Base.NumInstructions; program->Base.NumTemporaries = ap.Base.NumTemporaries; @@ -81,16 +81,16 @@ _mesa_parse_arb_vertex_program(GLcontext * ctx, GLenum target, program->Base.NumAttributes = ap.Base.NumAttributes; program->Base.NumAddressRegs = ap.Base.NumAddressRegs; program->IsPositionInvariant = ap.HintPositionInvariant; - program->InputsRead = ap.InputsRead; - program->OutputsWritten = ap.OutputsWritten; + program->Base.InputsRead = ap.Base.InputsRead; + program->Base.OutputsWritten = ap.Base.OutputsWritten; - if (program->Parameters) { + if (program->Base.Parameters) { /* free previous program's parameters */ - _mesa_free_parameter_list(program->Parameters); + _mesa_free_parameter_list(program->Base.Parameters); } - program->Parameters = ap.Parameters; + program->Base.Parameters = ap.Base.Parameters; #if DEBUG_VP - _mesa_print_program(ap.Base.NumInstructions, ap.VPInstructions); + _mesa_print_program(&program->Base); #endif } diff --git a/src/mesa/shader/nvfragparse.c b/src/mesa/shader/nvfragparse.c index 3a480058440..6a8d250d7eb 100644 --- a/src/mesa/shader/nvfragparse.c +++ b/src/mesa/shader/nvfragparse.c @@ -1535,17 +1535,17 @@ _mesa_parse_nv_fragment_program(GLcontext *ctx, GLenum dstTarget, } program->Base.String = programString; program->Base.Format = GL_PROGRAM_FORMAT_ASCII_ARB; - if (program->Instructions) { - FREE(program->Instructions); + if (program->Base.Instructions) { + _mesa_free(program->Base.Instructions); } - program->Instructions = newInst; - program->InputsRead = parseState.inputsRead; - program->OutputsWritten = parseState.outputsWritten; + program->Base.Instructions = newInst; + program->Base.InputsRead = parseState.inputsRead; + program->Base.OutputsWritten = parseState.outputsWritten; for (u = 0; u < ctx->Const.MaxTextureImageUnits; u++) program->TexturesUsed[u] = parseState.texturesUsed[u]; /* save program parameters */ - program->Parameters = parseState.parameters; + program->Base.Parameters = parseState.parameters; /* allocate registers for declared program parameters */ #if 00 @@ -1582,17 +1582,16 @@ PrintSrcReg(const struct fragment_program *program, _mesa_printf("-"); } if (src->File == PROGRAM_NAMED_PARAM) { - if (program->Parameters->Parameters[src->Index].Type == PROGRAM_CONSTANT) { - _mesa_printf("{%g, %g, %g, %g}", - program->Parameters->ParameterValues[src->Index][0], - program->Parameters->ParameterValues[src->Index][1], - program->Parameters->ParameterValues[src->Index][2], - program->Parameters->ParameterValues[src->Index][3]); + if (program->Base.Parameters->Parameters[src->Index].Type + == PROGRAM_CONSTANT) { + const GLfloat *v; + v = program->Base.Parameters->ParameterValues[src->Index]; + _mesa_printf("{%g, %g, %g, %g}", v[0], v[1], v[2], v[3]); } else { ASSERT(program->Parameters->Parameters[src->Index].Type == PROGRAM_NAMED_PARAM); - _mesa_printf("%s", program->Parameters->Parameters[src->Index].Name); + _mesa_printf("%s", program->Base.Parameters->Parameters[src->Index].Name); } } else if (src->File == PROGRAM_OUTPUT) { @@ -1734,7 +1733,7 @@ _mesa_print_nv_fragment_program(const struct fragment_program *program) { const struct prog_instruction *inst; - for (inst = program->Instructions; inst->Opcode != OPCODE_END; inst++) { + for (inst = program->Base.Instructions; inst->Opcode != OPCODE_END; inst++) { int i; for (i = 0; Instructions[i].name; i++) { if (inst->Opcode == Instructions[i].opcode) { diff --git a/src/mesa/shader/nvprogram.c b/src/mesa/shader/nvprogram.c index c85e7c00bd0..fadb5be2ade 100644 --- a/src/mesa/shader/nvprogram.c +++ b/src/mesa/shader/nvprogram.c @@ -780,7 +780,8 @@ _mesa_ProgramNamedParameter4fNV(GLuint id, GLsizei len, const GLubyte *name, } fragProg = (struct fragment_program *) prog; - v = _mesa_lookup_parameter_value(fragProg->Parameters, len, (char *) name); + v = _mesa_lookup_parameter_value(fragProg->Base.Parameters, len, + (char *) name); if (v) { v[0] = x; v[1] = y; @@ -845,7 +846,8 @@ _mesa_GetProgramNamedParameterfvNV(GLuint id, GLsizei len, const GLubyte *name, } fragProg = (struct fragment_program *) prog; - v = _mesa_lookup_parameter_value(fragProg->Parameters, len, (char *) name); + v = _mesa_lookup_parameter_value(fragProg->Base.Parameters, + len, (char *) name); if (v) { params[0] = v[0]; params[1] = v[1]; diff --git a/src/mesa/shader/nvvertexec.c b/src/mesa/shader/nvvertexec.c index 5bb40d881e0..a413dcbc291 100644 --- a/src/mesa/shader/nvvertexec.c +++ b/src/mesa/shader/nvvertexec.c @@ -162,10 +162,10 @@ _mesa_init_vp_per_primitive_registers(GLcontext *ctx) } else { /* Using and ARB vertex program */ - if (ctx->VertexProgram.Current->Parameters) { + if (ctx->VertexProgram.Current->Base.Parameters) { /* Grab the state GL state and put into registers */ _mesa_load_state_parameters(ctx, - ctx->VertexProgram.Current->Parameters); + ctx->VertexProgram.Current->Base.Parameters); } } } @@ -239,7 +239,7 @@ get_register_pointer( const struct prog_src_register *source, else if (source->File == PROGRAM_ENV_PARAM) return state->Parameters[reg]; else - return state->Current->Parameters->ParameterValues[reg]; + return state->Current->Base.Parameters->ParameterValues[reg]; } else { switch (source->File) { @@ -261,7 +261,7 @@ get_register_pointer( const struct prog_src_register *source, return state->Parameters[source->Index]; case PROGRAM_STATE_VAR: ASSERT(source->Index < state->Current->Parameters->NumParameters); - return state->Current->Parameters->ParameterValues[source->Index]; + return state->Current->Base.Parameters->ParameterValues[source->Index]; default: _mesa_problem(NULL, "Bad source register file in get_register_pointer"); @@ -395,9 +395,10 @@ _mesa_exec_vertex_program(GLcontext *ctx, const struct vertex_program *program) ctx->VertexProgram.Inputs[VERT_ATTRIB_POS]); /* XXX: This could go elsewhere */ - ctx->VertexProgram.Current->OutputsWritten |= VERT_BIT_POS; + ctx->VertexProgram.Current->Base.OutputsWritten |= VERT_BIT_POS; } - for (inst = program->Instructions; ; inst++) { + + for (inst = program->Base.Instructions; ; inst++) { if (ctx->VertexProgram.CallbackEnabled && ctx->VertexProgram.Callback) { diff --git a/src/mesa/shader/nvvertparse.c b/src/mesa/shader/nvvertparse.c index fd880dc007d..e2c14b99185 100644 --- a/src/mesa/shader/nvvertparse.c +++ b/src/mesa/shader/nvvertparse.c @@ -1367,28 +1367,28 @@ _mesa_parse_nv_vertex_program(GLcontext *ctx, GLenum dstTarget, /* copy the compiled instructions */ assert(parseState.numInst <= MAX_NV_VERTEX_PROGRAM_INSTRUCTIONS); newInst = (struct prog_instruction *) - MALLOC(parseState.numInst * sizeof(struct prog_instruction)); + _mesa_malloc(parseState.numInst * sizeof(struct prog_instruction)); if (!newInst) { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glLoadProgramNV"); - FREE(programString); + _mesa_free(programString); return; /* out of memory */ } - MEMCPY(newInst, instBuffer, - parseState.numInst * sizeof(struct prog_instruction)); + _mesa_memcpy(newInst, instBuffer, + parseState.numInst * sizeof(struct prog_instruction)); /* install the program */ program->Base.Target = target; if (program->Base.String) { - FREE(program->Base.String); + _mesa_free(program->Base.String); } program->Base.String = programString; program->Base.Format = GL_PROGRAM_FORMAT_ASCII_ARB; - if (program->Instructions) { - FREE(program->Instructions); + if (program->Base.Instructions) { + _mesa_free(program->Base.Instructions); } - program->Instructions = newInst; - program->InputsRead = parseState.inputsRead; - program->OutputsWritten = parseState.outputsWritten; + program->Base.Instructions = newInst; + program->Base.InputsRead = parseState.inputsRead; + program->Base.OutputsWritten = parseState.outputsWritten; program->IsPositionInvariant = parseState.isPositionInvariant; program->IsNVProgram = GL_TRUE; @@ -1531,7 +1531,7 @@ _mesa_print_nv_vertex_instruction(const struct prog_instruction *inst) break; case OPCODE_PRINT: _mesa_printf("PRINT '%s'", inst->Data); - if (inst->SrcReg[0].File) { + if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) { _mesa_printf(", "); PrintSrcReg(&inst->SrcReg[0]); _mesa_printf(";\n"); @@ -1557,7 +1557,7 @@ _mesa_print_nv_vertex_program(const struct vertex_program *program) { const struct prog_instruction *inst; - for (inst = program->Instructions; ; inst++) { + for (inst = program->Base.Instructions; ; inst++) { _mesa_print_nv_vertex_instruction(inst); if (inst->Opcode == OPCODE_END) return; diff --git a/src/mesa/shader/program.c b/src/mesa/shader/program.c index d46fadefcab..a9b84fc754e 100644 --- a/src/mesa/shader/program.c +++ b/src/mesa/shader/program.c @@ -294,35 +294,20 @@ _mesa_delete_program(GLcontext *ctx, struct program *prog) if (prog->String) _mesa_free(prog->String); - if (prog->Target == GL_VERTEX_PROGRAM_NV || - prog->Target == GL_VERTEX_STATE_PROGRAM_NV) { - struct vertex_program *vprog = (struct vertex_program *) prog; - if (vprog->Instructions) { - GLuint i; - for (i = 0; i < vprog->Base.NumInstructions; i++) { - if (vprog->Instructions[i].Data) - _mesa_free(vprog->Instructions[i].Data); - } - _mesa_free(vprog->Instructions); - } - if (vprog->Parameters) - _mesa_free_parameter_list(vprog->Parameters); - } - else if (prog->Target == GL_FRAGMENT_PROGRAM_NV || - prog->Target == GL_FRAGMENT_PROGRAM_ARB) { - struct fragment_program *fprog = (struct fragment_program *) prog; - if (fprog->Instructions) { - GLuint i; - for (i = 0; i < fprog->Base.NumInstructions; i++) { - if (fprog->Instructions[i].Data) - _mesa_free(fprog->Instructions[i].Data); - } - _mesa_free(fprog->Instructions); + + if (prog->Instructions) { + GLuint i; + for (i = 0; i < prog->NumInstructions; i++) { + if (prog->Instructions[i].Data) + _mesa_free(prog->Instructions[i].Data); } - if (fprog->Parameters) - _mesa_free_parameter_list(fprog->Parameters); + _mesa_free(prog->Instructions); } - else if (prog->Target == GL_FRAGMENT_SHADER_ATI) { + + if (prog->Parameters) + _mesa_free_parameter_list(prog->Parameters); + + if (prog->Target == GL_FRAGMENT_SHADER_ATI) { struct ati_fragment_shader *atifs = (struct ati_fragment_shader *)prog; GLuint i; for (i = 0; i < MAX_NUM_PASSES_ATI; i++) { @@ -1175,73 +1160,128 @@ writemask_string(GLuint writeMask) /** - * Print a vertx/fragment program to stdout. - * XXX this function could be greatly improved. + * Print a single vertex/fragment program instruction. */ void -_mesa_print_program(GLuint count, const struct prog_instruction *inst) +_mesa_print_instruction(const struct prog_instruction *inst) { - GLuint i; + switch (inst->Opcode) { + case OPCODE_PRINT: + _mesa_printf("PRINT '%s'", inst->Data); + if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) { + _mesa_printf(", "); + _mesa_printf("%s[%d]%s", + program_file_string(inst->SrcReg[0].File), + inst->SrcReg[0].Index, + swizzle_string(inst->SrcReg[0].Swizzle, + inst->SrcReg[0].NegateBase)); + } + _mesa_printf(";\n"); + break; + /* XXX check for a bunch of other special-case instructions */ + default: + /* typical alu instruction */ + { + const GLuint numRegs = _mesa_num_inst_src_regs(inst->Opcode); + GLuint j; - for (i = 0; i < count; i++) { - /* inst number */ - _mesa_printf("%3d: ", i); + _mesa_printf("%s", _mesa_opcode_string(inst->Opcode)); + + /* frag prog only */ + if (inst->Saturate) + _mesa_printf("_SAT"); + + if (inst->DstReg.File != PROGRAM_UNDEFINED) { + _mesa_printf(" %s[%d]%s", + program_file_string(inst->DstReg.File), + inst->DstReg.Index, + writemask_string(inst->DstReg.WriteMask)); + } - switch (inst[i].Opcode) { - case OPCODE_PRINT: - _mesa_printf("PRINT '%s'", inst[i].Data); - if (inst->SrcReg[0].File != PROGRAM_UNDEFINED) { + if (numRegs > 0) _mesa_printf(", "); + + for (j = 0; j < numRegs; j++) { _mesa_printf("%s[%d]%s", - program_file_string(inst[i].SrcReg[0].File), - inst[i].SrcReg[0].Index, - swizzle_string(inst[i].SrcReg[0].Swizzle, - inst[i].SrcReg[0].NegateBase)); + program_file_string(inst->SrcReg[j].File), + inst->SrcReg[j].Index, + swizzle_string(inst->SrcReg[j].Swizzle, + inst->SrcReg[j].NegateBase)); + if (j + 1 < numRegs) + _mesa_printf(", "); } + _mesa_printf(";\n"); - break; - /* XXX check for a bunch of other special-case instructions */ - default: - /* typical alu instruction */ - { - const GLuint numRegs = _mesa_num_inst_src_regs(inst[i].Opcode); - GLuint j; - - _mesa_printf("%s", _mesa_opcode_string(inst[i].Opcode)); - - /* frag prog only */ - if (inst[i].Saturate) - _mesa_printf("_SAT"); - - if (inst[i].DstReg.File != PROGRAM_UNDEFINED) { - _mesa_printf(" %s[%d]%s", - program_file_string(inst[i].DstReg.File), - inst[i].DstReg.Index, - writemask_string(inst[i].DstReg.WriteMask)); - } + } + } +} - if (numRegs > 0) - _mesa_printf(", "); - for (j = 0; j < numRegs; j++) { - _mesa_printf("%s[%d]%s", - program_file_string(inst[i].SrcReg[j].File), - inst[i].SrcReg[j].Index, - swizzle_string(inst[i].SrcReg[j].Swizzle, - inst[i].SrcReg[j].NegateBase)); - if (j + 1 < numRegs) - _mesa_printf(", "); - } +/** + * Print a vertx/fragment program to stdout. + * XXX this function could be greatly improved. + */ +void +_mesa_print_program(const struct program *prog) +{ + GLuint i; + for (i = 0; i < prog->NumInstructions; i++) { + _mesa_printf("%3d: ", i); + _mesa_print_instruction(prog->Instructions + i); + } +} - _mesa_printf(";\n"); - } + +/** + * Print all of a program's parameters. + */ +void +_mesa_print_program_parameters(GLcontext *ctx, const struct program *prog) +{ + GLint i; + + _mesa_printf("NumInstructions=%d\n", prog->NumInstructions); + _mesa_printf("NumTemporaries=%d\n", prog->NumTemporaries); + _mesa_printf("NumParameters=%d\n", prog->NumParameters); + _mesa_printf("NumAttributes=%d\n", prog->NumAttributes); + _mesa_printf("NumAddressRegs=%d\n", prog->NumAddressRegs); + + _mesa_load_state_parameters(ctx, prog->Parameters); + +#if 0 + _mesa_printf("Local Params:\n"); + for (i = 0; i < MAX_PROGRAM_LOCAL_PARAMS; i++){ + const GLfloat *p = prog->LocalParams[i]; + _mesa_printf("%2d: %f, %f, %f, %f\n", i, p[0], p[1], p[2], p[3]); + } +#endif + + for (i = 0; i < prog->Parameters->NumParameters; i++){ + const GLfloat *p = prog->Parameters->ParameterValues[i]; + _mesa_printf("param %02d:", i); + + switch (prog->Parameters->Parameters[i].Type) { + case PROGRAM_NAMED_PARAM: + _mesa_printf("%s", prog->Parameters->Parameters[i].Name); + _mesa_printf("(NAMED_PARAMETER)"); + break; + case PROGRAM_CONSTANT: + _mesa_printf("(CONSTANT)"); + break; + case PROGRAM_STATE_VAR: + _mesa_printf("(STATE)\n"); + break; + default: + _mesa_printf("(UNK)\n"); + break; } + + _mesa_printf("{ %f, %f, %f, %f }\n", p[0], p[1], p[2], p[3]); } } - /**********************************************************************/ /* API functions */ /**********************************************************************/ @@ -1674,7 +1714,7 @@ _mesa_GetProgramRegisterfvMESA(GLenum target, else { /* try user-defined identifiers */ const GLfloat *value = _mesa_lookup_parameter_value( - ctx->FragmentProgram.Current->Parameters, -1, reg); + ctx->FragmentProgram.Current->Base.Parameters, -1, reg); if (value) { COPY_4V(v, value); } diff --git a/src/mesa/shader/program.h b/src/mesa/shader/program.h index 373a046da78..ab72f457eeb 100644 --- a/src/mesa/shader/program.h +++ b/src/mesa/shader/program.h @@ -256,7 +256,13 @@ _mesa_load_state_parameters(GLcontext *ctx, extern void -_mesa_print_program(GLuint count, const struct prog_instruction *inst); +_mesa_print_instruction(const struct prog_instruction *inst); + +extern void +_mesa_print_program(const struct program *prog); + +extern void +_mesa_print_program_parameters(GLcontext *ctx, const struct program *prog); /* diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index 358a9f9128e..186fda0949f 100644 --- a/src/mesa/swrast/s_context.c +++ b/src/mesa/swrast/s_context.c @@ -221,7 +221,7 @@ _swrast_update_fragment_program( GLcontext *ctx ) { if (ctx->FragmentProgram._Active) { struct fragment_program *program = ctx->FragmentProgram._Current; - _mesa_load_state_parameters(ctx, program->Parameters); + _mesa_load_state_parameters(ctx, program->Base.Parameters); } } diff --git a/src/mesa/swrast/s_nvfragprog.c b/src/mesa/swrast/s_nvfragprog.c index e042f55d230..feb7939081b 100644 --- a/src/mesa/swrast/s_nvfragprog.c +++ b/src/mesa/swrast/s_nvfragprog.c @@ -135,7 +135,7 @@ get_register_pointer( GLcontext *ctx, /* Fallthrough */ case PROGRAM_NAMED_PARAM: ASSERT(source->Index < (GLint) program->Parameters->NumParameters); - src = program->Parameters->ParameterValues[source->Index]; + src = program->Base.Parameters->ParameterValues[source->Index]; break; default: _mesa_problem(ctx, "Invalid input register file %d in fetch_vector4", source->File); @@ -495,7 +495,7 @@ init_machine_deriv( GLcontext *ctx, } /* Add derivatives */ - if (program->InputsRead & (1 << FRAG_ATTRIB_WPOS)) { + if (program->Base.InputsRead & (1 << FRAG_ATTRIB_WPOS)) { GLfloat *wpos = (GLfloat*) machine->Inputs[FRAG_ATTRIB_WPOS]; if (xOrY == 'X') { wpos[0] += 1.0F; @@ -510,7 +510,7 @@ init_machine_deriv( GLcontext *ctx, wpos[3] += span->dwdy; } } - if (program->InputsRead & (1 << FRAG_ATTRIB_COL0)) { + if (program->Base.InputsRead & (1 << FRAG_ATTRIB_COL0)) { GLfloat *col0 = (GLfloat*) machine->Inputs[FRAG_ATTRIB_COL0]; if (xOrY == 'X') { col0[0] += span->drdx * (1.0F / CHAN_MAXF); @@ -525,7 +525,7 @@ init_machine_deriv( GLcontext *ctx, col0[3] += span->dady * (1.0F / CHAN_MAXF); } } - if (program->InputsRead & (1 << FRAG_ATTRIB_COL1)) { + if (program->Base.InputsRead & (1 << FRAG_ATTRIB_COL1)) { GLfloat *col1 = (GLfloat*) machine->Inputs[FRAG_ATTRIB_COL1]; if (xOrY == 'X') { col1[0] += span->dsrdx * (1.0F / CHAN_MAXF); @@ -540,7 +540,7 @@ init_machine_deriv( GLcontext *ctx, col1[3] += 0.0; /*XXX fix */ } } - if (program->InputsRead & (1 << FRAG_ATTRIB_FOGC)) { + if (program->Base.InputsRead & (1 << FRAG_ATTRIB_FOGC)) { GLfloat *fogc = (GLfloat*) machine->Inputs[FRAG_ATTRIB_FOGC]; if (xOrY == 'X') { fogc[0] += span->dfogdx; @@ -550,7 +550,7 @@ init_machine_deriv( GLcontext *ctx, } } for (u = 0; u < ctx->Const.MaxTextureCoordUnits; u++) { - if (program->InputsRead & (1 << (FRAG_ATTRIB_TEX0 + u))) { + if (program->Base.InputsRead & (1 << (FRAG_ATTRIB_TEX0 + u))) { GLfloat *tex = (GLfloat*) machine->Inputs[FRAG_ATTRIB_TEX0 + u]; /* XXX perspective-correct interpolation */ if (xOrY == 'X') { @@ -599,7 +599,7 @@ execute_program( GLcontext *ctx, #endif for (pc = 0; pc < maxInst; pc++) { - const struct prog_instruction *inst = program->Instructions + pc; + const struct prog_instruction *inst = program->Base.Instructions + pc; if (ctx->FragmentProgram.CallbackEnabled && ctx->FragmentProgram.Callback) { @@ -1384,7 +1384,7 @@ init_machine( GLcontext *ctx, struct fp_machine *machine, const struct fragment_program *program, const struct sw_span *span, GLuint col ) { - GLuint inputsRead = program->InputsRead; + GLuint inputsRead = program->Base.InputsRead; GLuint u; if (ctx->FragmentProgram.CallbackEnabled) @@ -1457,8 +1457,8 @@ _swrast_exec_fragment_program( GLcontext *ctx, struct sw_span *span ) ctx->_CurrentProgram = GL_FRAGMENT_PROGRAM_ARB; /* or NV, doesn't matter */ - if (program->Parameters) { - _mesa_load_state_parameters(ctx, program->Parameters); + if (program->Base.Parameters) { + _mesa_load_state_parameters(ctx, program->Base.Parameters); } for (i = 0; i < span->end; i++) { @@ -1482,7 +1482,7 @@ _swrast_exec_fragment_program( GLcontext *ctx, struct sw_span *span ) UNCLAMPED_FLOAT_TO_CHAN(span->array->rgba[i][ACOMP], colOut[3]); } /* depth value */ - if (program->OutputsWritten & (1 << FRAG_RESULT_DEPR)) { + if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) { const GLfloat depth = ctx->FragmentProgram.Machine.Outputs[FRAG_RESULT_DEPR][2]; span->array->z[i] = IROUND(depth * ctx->DrawBuffer->_DepthMaxF); @@ -1490,7 +1490,7 @@ _swrast_exec_fragment_program( GLcontext *ctx, struct sw_span *span ) } } - if (program->OutputsWritten & (1 << FRAG_RESULT_DEPR)) { + if (program->Base.OutputsWritten & (1 << FRAG_RESULT_DEPR)) { span->interpMask &= ~SPAN_Z; span->arrayMask |= SPAN_Z; } diff --git a/src/mesa/tnl/t_vb_arbprogram.c b/src/mesa/tnl/t_vb_arbprogram.c index 27ff50932c7..bf784446cdf 100644 --- a/src/mesa/tnl/t_vb_arbprogram.c +++ b/src/mesa/tnl/t_vb_arbprogram.c @@ -1109,7 +1109,7 @@ static void compile_vertex_program( struct vertex_program *program, /* Compile instructions: */ for (i = 0; i < program->Base.NumInstructions; i++) { - cvp_emit_inst(&cp, &program->Instructions[i]); + cvp_emit_inst(&cp, &program->Base.Instructions[i]); } /* Finish up: @@ -1269,8 +1269,8 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage) if (!program || program->IsNVProgram) return GL_TRUE; - if (program->Parameters) { - _mesa_load_state_parameters(ctx, program->Parameters); + if (program->Base.Parameters) { + _mesa_load_state_parameters(ctx, program->Base.Parameters); } p = (struct tnl_compiled_program *)program->TnlData; @@ -1280,7 +1280,7 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage) m->nr_inputs = m->nr_outputs = 0; for (i = 0; i < _TNL_ATTRIB_MAX; i++) { - if (program->InputsRead & (1<Base.InputsRead & (1<nr_inputs++; m->input[j].idx = i; m->input[j].data = (GLfloat *)m->VB->AttribPtr[i]->data; @@ -1291,7 +1291,7 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage) } for (i = 0; i < VERT_RESULT_MAX; i++) { - if (program->OutputsWritten & (1<Base.OutputsWritten & (1 << i)) { GLuint j = m->nr_outputs++; m->output[j].idx = i; m->output[j].data = (GLfloat *)m->attribs[i].data; @@ -1347,7 +1347,7 @@ run_arb_vertex_program(GLcontext *ctx, struct tnl_pipeline_stage *stage) VB->ClipPtr = &m->attribs[VERT_RESULT_HPOS]; VB->ClipPtr->count = VB->Count; - outputs = program->OutputsWritten; + outputs = program->Base.OutputsWritten; if (outputs & (1<ColorPtr[0] = &m->attribs[VERT_RESULT_COL0]; @@ -1424,8 +1424,8 @@ validate_vertex_program( GLcontext *ctx, struct tnl_pipeline_stage *stage ) m->File[FILE_LOCAL_PARAM] = program->Base.LocalParams; m->File[FILE_ENV_PARAM] = ctx->VertexProgram.Parameters; /* GL_NV_vertex_programs can't reference GL state */ - if (program->Parameters) - m->File[FILE_STATE_PARAM] = program->Parameters->ParameterValues; + if (program->Base.Parameters) + m->File[FILE_STATE_PARAM] = program->Base.Parameters->ParameterValues; else m->File[FILE_STATE_PARAM] = NULL; } diff --git a/src/mesa/tnl/t_vb_program.c b/src/mesa/tnl/t_vb_program.c index 0f53657183b..297b731b1dd 100644 --- a/src/mesa/tnl/t_vb_program.c +++ b/src/mesa/tnl/t_vb_program.c @@ -112,7 +112,7 @@ run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage ) /* the vertex array case */ for (attr = 0; attr < VERT_ATTRIB_MAX; attr++) { - if (program->InputsRead & (1 << attr)) { + if (program->Base.InputsRead & (1 << attr)) { const GLubyte *ptr = (const GLubyte*) VB->AttribPtr[attr]->data; const GLuint size = VB->AttribPtr[attr]->size; const GLuint stride = VB->AttribPtr[attr]->stride; @@ -127,12 +127,12 @@ run_vp( GLcontext *ctx, struct tnl_pipeline_stage *stage ) /* Fixup fog an point size results if needed */ if (ctx->Fog.Enabled && - (program->OutputsWritten & (1 << VERT_RESULT_FOGC)) == 0) { + (program->Base.OutputsWritten & (1 << VERT_RESULT_FOGC)) == 0) { ctx->VertexProgram.Outputs[VERT_RESULT_FOGC][0] = 1.0; } if (ctx->VertexProgram.PointSizeEnabled && - (program->OutputsWritten & (1 << VERT_RESULT_PSIZ)) == 0) { + (program->Base.OutputsWritten & (1 << VERT_RESULT_PSIZ)) == 0) { ctx->VertexProgram.Outputs[VERT_RESULT_PSIZ][0] = ctx->Point.Size; } diff --git a/src/mesa/tnl/t_vp_build.c b/src/mesa/tnl/t_vp_build.c index 4ff70cd6edd..0f1f303be28 100644 --- a/src/mesa/tnl/t_vp_build.c +++ b/src/mesa/tnl/t_vp_build.c @@ -1,6 +1,6 @@ /* * Mesa 3-D graphics library - * Version: 6.3.1 + * Version: 6.5 * * Copyright (C) 2005 Tungsten Graphics All Rights Reserved. * @@ -124,7 +124,7 @@ static struct state_key *make_state_key( GLcontext *ctx ) */ assert(fp); - key->fragprog_inputs_read = fp->InputsRead; + key->fragprog_inputs_read = fp->Base.InputsRead; key->separate_specular = (ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR); @@ -365,13 +365,13 @@ static void release_temps( struct tnl_program *p ) static struct ureg register_input( struct tnl_program *p, GLuint input ) { - p->program->InputsRead |= (1<program->Base.InputsRead |= (1<program->OutputsWritten |= (1<program->Base.OutputsWritten |= (1<program->Parameters, values ); + idx = _mesa_add_unnamed_constant( p->program->Base.Parameters, values ); return make_ureg(PROGRAM_STATE_VAR, idx); } @@ -425,7 +425,7 @@ static struct ureg register_param6( struct tnl_program *p, tokens[3] = s3; tokens[4] = s4; tokens[5] = s5; - idx = _mesa_add_state_reference( p->program->Parameters, tokens ); + idx = _mesa_add_state_reference( p->program->Base.Parameters, tokens ); return make_ureg(PROGRAM_STATE_VAR, idx); } @@ -492,7 +492,7 @@ static void debug_insn( struct prog_instruction *inst, const char *fn, } _mesa_printf("%d:\t", line); - _mesa_print_program(1, inst); + _mesa_print_instruction(inst); } } @@ -508,7 +508,7 @@ static void emit_op3fn(struct tnl_program *p, GLuint line) { GLuint nr = p->program->Base.NumInstructions++; - struct prog_instruction *inst = &p->program->Instructions[nr]; + struct prog_instruction *inst = &p->program->Base.Instructions[nr]; if (p->program->Base.NumInstructions > MAX_INSN) { _mesa_problem(0, "Out of instructions in emit_op3fn\n"); @@ -1406,15 +1406,16 @@ create_new_program( const struct state_key *key, else p.temp_reserved = ~((1<Instructions = MALLOC(sizeof(struct prog_instruction) * MAX_INSN); + p.program->Base.Instructions + = MALLOC(sizeof(struct prog_instruction) * MAX_INSN); p.program->Base.String = 0; p.program->Base.NumInstructions = p.program->Base.NumTemporaries = p.program->Base.NumParameters = p.program->Base.NumAttributes = p.program->Base.NumAddressRegs = 0; - p.program->Parameters = _mesa_new_parameter_list(); - p.program->InputsRead = 0; - p.program->OutputsWritten = 0; + p.program->Base.Parameters = _mesa_new_parameter_list(); + p.program->Base.InputsRead = 0; + p.program->Base.OutputsWritten = 0; build_tnl_program( &p ); }