Some code comments below:

Oliver McFadden wrote:
 >  src/mesa/drivers/dri/r300/r300_fragprog.c   |   91 
++++++++++++++++++++++++++++
 >  src/mesa/drivers/dri/r300/r300_state.c      |   14 ++--
 >  src/mesa/drivers/dri/r300/r300_state.h      |    1 
src/mesa/drivers/dri/r300/r300_vertexprog.c |   67 +-------------------
 >  4 files changed, 103 insertions(+), 70 deletions(-)
 >
 > New commits:
 > diff-tree 4e4ab2a62bf33a582420cff85775a6580167b5a9 (from 
4d2eb637a20e4fdf5d5f6c0ea4d4627894594661)
 > Author: Oliver McFadden <[EMAIL PROTECTED]>
 > Date:   Thu Mar 15 17:35:34 2007 +0000
 >
 >     Committed Rune Petersen's fragment.position patch (Bug #10024) 
plus a few small
 >     corrections.
 >
 > diff --git a/src/mesa/drivers/dri/r300/r300_fragprog.c 
b/src/mesa/drivers/dri/r300/r300_fragprog.c
 > index a1c634a..d3062a4 100644
 > --- a/src/mesa/drivers/dri/r300/r300_fragprog.c
 > +++ b/src/mesa/drivers/dri/r300/r300_fragprog.c
 > @@ -49,6 +49,7 @@
 >  #include "r300_context.h"
 >  #include "r300_fragprog.h"
 >  #include "r300_reg.h"
 > +#include "r300_state.h"
 >
 >  /*
 >   * Usefull macros and values
 > @@ -1787,6 +1788,94 @@ static GLboolean parse_program(struct r3
 >      return GL_TRUE;
 >  }
 >
 > +static void insert_wpos(struct gl_program *prog)
 > +{
 > +    GLint tokens[6] = { STATE_INTERNAL, STATE_R300_WINDOW_DIMENSION, 
0, 0, 0, 0 };
 > +    struct prog_instruction *fpi;
 > +    GLuint window_index;
 > +    int i = 0;
 > +    GLuint tempregi = prog->NumTemporaries;
 > +    /* should do something else if no temps left... */
 > +    prog->NumTemporaries++;
 > +
 > +
 > +    fpi = malloc((prog->NumInstructions + 3) * sizeof(struct 
prog_instruction));

Using the _mesa_alloc_instructions(GLuint numInst) function here would 
be cleaner.


 > +    /* all including END */
 > +    memcpy(&fpi[3], prog->Instructions, prog->NumInstructions * 
sizeof(struct prog_instruction));
 > +    memset(fpi, 0, 3 * sizeof(struct prog_instruction));
 > +

The _mesa_init_instructions() function should be used here.  It'll set 
most instruction fields to expected defaults, saving you from doing some 
of that here:


 > +    /* perspective divide */
 > +    fpi[i].Opcode = OPCODE_RCP;
 > +
 > +    fpi[i].DstReg.File = PROGRAM_TEMPORARY;
 > +    fpi[i].DstReg.Index = tempregi;
 > +    fpi[i].DstReg.WriteMask = WRITEMASK_W;
 > +    fpi[i].DstReg.CondMask = COND_TR;
 > +
 > +    fpi[i].SrcReg[0].File = PROGRAM_INPUT;
 > +    fpi[i].SrcReg[0].Index = FRAG_ATTRIB_WPOS;
 > +    fpi[i].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_W, SWIZZLE_W, 
SWIZZLE_W, SWIZZLE_W);
 > +    i++;
 > +
 > +    fpi[i].Opcode = OPCODE_MUL;
 > +
 > +    fpi[i].DstReg.File = PROGRAM_TEMPORARY;
 > +    fpi[i].DstReg.Index = tempregi;
 > +    fpi[i].DstReg.WriteMask = WRITEMASK_XYZ;
 > +    fpi[i].DstReg.CondMask = COND_TR;
 > +
 > +    fpi[i].SrcReg[0].File = PROGRAM_INPUT;
 > +    fpi[i].SrcReg[0].Index = FRAG_ATTRIB_WPOS;
 > +    fpi[i].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, 
SWIZZLE_Z, SWIZZLE_W);

SWIZZLE_NOOP can be used there.


 > +    fpi[i].SrcReg[1].File = PROGRAM_TEMPORARY;
 > +    fpi[i].SrcReg[1].Index = tempregi;
 > +    fpi[i].SrcReg[1].Swizzle = MAKE_SWIZZLE4(SWIZZLE_W, SWIZZLE_W, 
SWIZZLE_W, SWIZZLE_W);
 > +    i++;

The glsl-compiler-branch has new SWIZZLE_XXXX, SWIZZLE_YYYY, etc. macros 
that can shorten the above code a bit.  I've just commited them to the 
mainline.


 > +    /* viewport transformation */
 > +    window_index = _mesa_add_state_reference(prog->Parameters, tokens);
 > +
 > +    fpi[i].Opcode = OPCODE_MAD;
 > +
 > +    fpi[i].DstReg.File = PROGRAM_TEMPORARY;
 > +    fpi[i].DstReg.Index = tempregi;
 > +    fpi[i].DstReg.WriteMask = WRITEMASK_XYZ;
 > +    fpi[i].DstReg.CondMask = COND_TR;
 > +
 > +    fpi[i].SrcReg[0].File = PROGRAM_TEMPORARY;
 > +    fpi[i].SrcReg[0].Index = tempregi;
 > +    fpi[i].SrcReg[0].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, 
SWIZZLE_Z, SWIZZLE_ZERO);
 > +
 > +    fpi[i].SrcReg[1].File = PROGRAM_STATE_VAR;
 > +    fpi[i].SrcReg[1].Index = window_index;
 > +    fpi[i].SrcReg[1].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, 
SWIZZLE_Z, SWIZZLE_ZERO);
 > +
 > +    fpi[i].SrcReg[2].File = PROGRAM_STATE_VAR;
 > +    fpi[i].SrcReg[2].Index = window_index;
 > +    fpi[i].SrcReg[2].Swizzle = MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, 
SWIZZLE_Z, SWIZZLE_ZERO);
 > +    i++;
 > +
 > +    free(prog->Instructions);
 > +
 > +    prog->Instructions = fpi;
 > +
 > +    prog->NumInstructions += i;
 > +    fpi = &prog->Instructions[prog->NumInstructions-1];
 > +
 > +    assert(fpi->Opcode == OPCODE_END);
 > +
 > +    for(fpi = &prog->Instructions[3]; fpi->Opcode != OPCODE_END; fpi++){
 > +        for(i=0; i<3; i++)
 > +            if( fpi->SrcReg[i].File == PROGRAM_INPUT &&
 > +            fpi->SrcReg[i].Index == FRAG_ATTRIB_WPOS ){
 > +                fpi->SrcReg[i].File = PROGRAM_TEMPORARY;
 > +                fpi->SrcReg[i].Index = tempregi;
 > +                }
 > +    }
 > +}
 > +
 >  /* - Init structures
 >   * - Determine what hwregs each input corresponds to
 >   */
 > @@ -1844,6 +1933,7 @@ static void init_program(r300ContextPtr      if 
(InputsRead & FRAG_BIT_WPOS) {
 >          cs->inputs[FRAG_ATTRIB_WPOS].refcount = 0;
 >          cs->inputs[FRAG_ATTRIB_WPOS].reg = get_hw_temp(rp);
 > +        insert_wpos(&mp->Base);
 >      }
 >      InputsRead &= ~FRAG_BIT_WPOS;
 >
 > @@ -1956,6 +2046,7 @@ void r300_translate_fragment_shader(r300
 >
 >          rp->translated = GL_TRUE;
 >          if (0) dump_program(rp);
 > +        r300UpdateStateParameters(rp->ctx, _NEW_PROGRAM);
 >      }
 >
 >      update_params(rp);
 > diff --git a/src/mesa/drivers/dri/r300/r300_state.c 
b/src/mesa/drivers/dri/r300/r300_state.c
 > index 895c2ff..fcb61a2 100644
 > --- a/src/mesa/drivers/dri/r300/r300_state.c
 > +++ b/src/mesa/drivers/dri/r300/r300_state.c
 > @@ -1066,8 +1066,8 @@ static void r300FetchStateParameter(GLco
 >          switch(state[1])
 >      {
 >      case STATE_R300_WINDOW_DIMENSION:
 > -        value[0] = r300->radeon.dri.drawable->w;    /* width */
 > -            value[1] = r300->radeon.dri.drawable->h;    /* height */
 > +        value[0] = r300->radeon.dri.drawable->w*0.5f;/* width*0.5 */
 > +            value[1] = r300->radeon.dri.drawable->h*0.5f;/* 
height*0.5 */
 >          value[2] = 0.5F;                 /* for moving range [-1 1] 
-> [0 1] */
 >              value[3] = 1.0F;                 /* not used */
 >          break;
 > @@ -1081,20 +1081,20 @@ static void r300FetchStateParameter(GLco
 >   * Update R300's own internal state parameters.
 >   * For now just STATE_R300_WINDOW_DIMENSION
 >   */
 > -static void r300UpdateStateParameters(GLcontext * ctx, GLuint new_state)
 > +void r300UpdateStateParameters(GLcontext * ctx, GLuint new_state)
 >  {
 > -    struct r300_vertex_program_cont *vpc;
 > +    struct r300_fragment_program *fp;
 >      struct gl_program_parameter_list *paramList;
 >      GLuint i;
 >
 >      if(!(new_state & (_NEW_BUFFERS|_NEW_PROGRAM)))
 >          return;
 >
 > -    vpc = (struct r300_vertex_program_cont 
*)ctx->VertexProgram._Current;
 > -    if (!vpc)
 > +    fp = (struct r300_fragment_program *)ctx->FragmentProgram._Current;
 > +    if (!fp)
 >          return;
 >
 > -    paramList = vpc->mesa_program.Base.Parameters;
 > +    paramList = fp->mesa_program.Base.Parameters;
 >
 >      if (!paramList)
 >          return;
 > diff --git a/src/mesa/drivers/dri/r300/r300_state.h 
b/src/mesa/drivers/dri/r300/r300_state.h
 > index f6a5065..52e606f 100644
 > --- a/src/mesa/drivers/dri/r300/r300_state.h
 > +++ b/src/mesa/drivers/dri/r300/r300_state.h
 > @@ -61,6 +61,7 @@ do {                            \
 >
 >  extern void r300ResetHwState(r300ContextPtr r300);
 >
 > +extern void r300UpdateStateParameters(GLcontext * ctx, GLuint 
new_state);
 >  extern void r300InitState(r300ContextPtr r300);
 >  extern void r300InitStateFuncs(struct dd_function_table* functions);
 >  extern void r300UpdateViewportOffset( GLcontext *ctx );
 > diff --git a/src/mesa/drivers/dri/r300/r300_vertexprog.c 
b/src/mesa/drivers/dri/r300/r300_vertexprog.c
 > index 2ff92e1..68a11a4 100644
 > --- a/src/mesa/drivers/dri/r300/r300_vertexprog.c
 > +++ b/src/mesa/drivers/dri/r300/r300_vertexprog.c
 > @@ -962,22 +962,19 @@ static void insert_wpos(struct r300_vert
 >                 struct gl_program *prog,
 >                 GLuint temp_index)
 >  {
 > -
 > -    GLint tokens[6] = { STATE_INTERNAL, STATE_R300_WINDOW_DIMENSION, 
0, 0, 0, 0 };
 >      struct prog_instruction *vpi;
 >      struct prog_instruction *vpi_insert;
 > -    GLuint window_index;
 >      int i = 0;
 >
 > -    vpi = malloc((prog->NumInstructions + 5) * sizeof(struct 
prog_instruction));
 > +    vpi = malloc((prog->NumInstructions + 2) * sizeof(struct 
prog_instruction));
 >      /* all but END */
 >      memcpy(vpi, prog->Instructions, (prog->NumInstructions - 1) * 
sizeof(struct prog_instruction));
 >      /* END */
 > -    memcpy(&vpi[prog->NumInstructions + 4], 
&prog->Instructions[prog->NumInstructions - 1],
 > +    memcpy(&vpi[prog->NumInstructions + 1], 
&prog->Instructions[prog->NumInstructions - 1],
 >          sizeof(struct prog_instruction));
 >
 >      vpi_insert = &vpi[prog->NumInstructions - 1];
 > -    memset(vpi_insert, 0, 5 * sizeof(struct prog_instruction));
 > +    memset(vpi_insert, 0, 2 * sizeof(struct prog_instruction));

Again, _mesa_alloc_instructions() and/or _mesa_realloc_instructions() 
might be useful there.

[...]

-Brian



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to