mesa: add new FRAG_ATTRIB_FACE and FRAG_ATTRIB_PNTC fragment program inputs
authorBrian Paul <brianp@vmware.com>
Thu, 30 Jul 2009 02:07:41 +0000 (20:07 -0600)
committerBrian Paul <brianp@vmware.com>
Thu, 30 Jul 2009 02:07:41 +0000 (20:07 -0600)
Previously, the FOGC attribute contained the fragment fog coord, front/back-
face flag and the gl_PointCoord.xy values.  Now each of those things are
separate fragment program attributes.  This simplifies quite a few things in
Mesa and gallium.

Need to test i965 driver and fix up point coord handling in the gallium/draw
module...

src/mesa/drivers/dri/i965/brw_wm_fp.c
src/mesa/main/mtypes.h
src/mesa/shader/arbprogparse.c
src/mesa/shader/programopt.c
src/mesa/shader/slang/slang_codegen.c
src/mesa/shader/slang/slang_link.c
src/mesa/state_tracker/st_atom_shader.c
src/mesa/state_tracker/st_mesa_to_tgsi.c
src/mesa/state_tracker/st_program.c
src/mesa/swrast/s_fragprog.c
src/mesa/swrast/s_points.c

index b9e8dd2e96e6ea0172b1276bb2393031aab2e653..606baab96754301491441e24009b076e348108b0 100644 (file)
@@ -376,14 +376,6 @@ static void emit_interp( struct brw_wm_compile *c,
       }
       break;
    case FRAG_ATTRIB_FOGC:
-      /* The FOGC input is really special.  When a program uses glFogFragCoord,
-       * the results returned are supposed to be (f,0,0,1).  But for Mesa GLSL,
-       * the glFrontFacing and glPointCoord values are also stashed in FOGC.
-       * So, write the interpolated fog value to X, then either 0, 1, or the
-       * stashed values to Y, Z, W.  Note that this means that
-       * glFogFragCoord.yzw can be wrong in those cases!
-       */
-
       /* Interpolate the fog coordinate */
       emit_op(c,
              WM_PINTERP,
@@ -393,26 +385,40 @@ static void emit_interp( struct brw_wm_compile *c,
              deltas,
              get_pixel_w(c));
 
-      /* Move the front facing value into FOGC.y if it's needed. */
-      if (c->fp->program.UsesFrontFacing) {
-        emit_op(c,
-                WM_FRONTFACING,
-                dst_mask(dst, WRITEMASK_Y),
-                0,
-                src_undef(),
-                src_undef(),
-                src_undef());
-      } else {
-        emit_op(c,
-                OPCODE_MOV,
-                dst_mask(dst, WRITEMASK_Y),
-                0,
-                src_swizzle1(interp, SWIZZLE_ZERO),
-                src_undef(),
-                src_undef());
-      }
+      emit_op(c,
+             OPCODE_MOV,
+             dst_mask(dst, WRITEMASK_YZW),
+             0,
+             src_swizzle(interp,
+                         SWIZZLE_ZERO,
+                         SWIZZLE_ZERO,
+                         SWIZZLE_ZERO,
+                         SWIZZLE_ONE),
+             src_undef(),
+             src_undef());
+      break;
+
+   case FRAG_ATTRIB_FACE:
+      /* XXX review/test this case */
+      emit_op(c,
+              WM_FRONTFACING,
+              dst_mask(dst, WRITEMASK_X),
+              0,
+              src_undef(),
+              src_undef(),
+              src_undef());
+      break;
+
+   case FRAG_ATTRIB_PNTC:
+      /* XXX review/test this case */
+      emit_op(c,
+             WM_PINTERP,
+             dst_mask(dst, WRITEMASK_XY),
+             0,
+             interp,
+             deltas,
+             get_pixel_w(c));
 
-      /* Should do the PointCoord thing here. */
       emit_op(c,
              OPCODE_MOV,
              dst_mask(dst, WRITEMASK_ZW),
@@ -425,6 +431,7 @@ static void emit_interp( struct brw_wm_compile *c,
              src_undef(),
              src_undef());
       break;
+
    default:
       emit_op(c,
              WM_PINTERP,
index d0309f5e90dbd7ff92bb224f312a9d45335021f9..da01c58c2d805899f521fc3fa4ddf3f3a98d1fe4 100644 (file)
@@ -227,7 +227,9 @@ typedef enum
    FRAG_ATTRIB_TEX5 = 9,
    FRAG_ATTRIB_TEX6 = 10,
    FRAG_ATTRIB_TEX7 = 11,
-   FRAG_ATTRIB_VAR0 = 12,  /**< shader varying */
+   FRAG_ATTRIB_FACE = 12,  /**< front/back face */
+   FRAG_ATTRIB_PNTC = 13,  /**< sprite/point coord */
+   FRAG_ATTRIB_VAR0 = 14,  /**< shader varying */
    FRAG_ATTRIB_MAX = (FRAG_ATTRIB_VAR0 + MAX_VARYING)
 } gl_frag_attrib;
 
@@ -239,6 +241,8 @@ typedef enum
 #define FRAG_BIT_COL0  (1 << FRAG_ATTRIB_COL0)
 #define FRAG_BIT_COL1  (1 << FRAG_ATTRIB_COL1)
 #define FRAG_BIT_FOGC  (1 << FRAG_ATTRIB_FOGC)
+#define FRAG_BIT_FACE  (1 << FRAG_ATTRIB_FACE)
+#define FRAG_BIT_PNTC  (1 << FRAG_ATTRIB_PNTC)
 #define FRAG_BIT_TEX0  (1 << FRAG_ATTRIB_TEX0)
 #define FRAG_BIT_TEX1  (1 << FRAG_ATTRIB_TEX1)
 #define FRAG_BIT_TEX2  (1 << FRAG_ATTRIB_TEX2)
@@ -1834,9 +1838,6 @@ struct gl_fragment_program
    struct gl_program Base;   /**< base class */
    GLenum FogOption;
    GLboolean UsesKill;          /**< shader uses KIL instruction */
-   GLboolean UsesPointCoord;    /**< shader uses gl_PointCoord */
-   GLboolean UsesFrontFacing;   /**< shader used gl_FrontFacing */
-   GLboolean UsesFogFragCoord;  /**< shader used gl_FogFragCoord */
 };
 
 
index bc65aba39a1209b90711dd8df24fb3af41c440ea..f428ee541b502ac6d95e78d258e39e58ba4bff7c 100644 (file)
@@ -3974,13 +3974,6 @@ _mesa_parse_arb_fragment_program(GLcontext* ctx, GLenum target,
    if (program->FogOption)
       program->Base.InputsRead |= FRAG_BIT_FOGC;
 
-   /* XXX: assume that ARB fragment programs don't have access to the
-    * FrontFacing and PointCoord values stuffed into the fog
-    * coordinate in GLSL shaders.
-    */
-   if (program->Base.InputsRead & FRAG_BIT_FOGC)
-      program->UsesFogFragCoord = GL_TRUE;
-      
    if (program->Base.Instructions)
       _mesa_free(program->Base.Instructions);
    program->Base.Instructions = ap.Base.Instructions;
index ac5fe0f691fadb460c03a4c84e32a062abca3652..f70c75cec8e3c4a6e74777a8ed436723bae1da36 100644 (file)
@@ -396,7 +396,6 @@ _mesa_append_fog_code(GLcontext *ctx, struct gl_fragment_program *fprog)
    fprog->Base.Instructions = newInst;
    fprog->Base.NumInstructions = inst - newInst;
    fprog->Base.InputsRead |= FRAG_BIT_FOGC;
-   fprog->UsesFogFragCoord = GL_TRUE;
    /* XXX do this?  fprog->FogOption = GL_NONE; */
 }
 
index 2b7e781f98445c5c32fe82634bce205fd1e8113d..4fe68eafa7f6dcb06acf5f04b0c692868dbf9dee 100644 (file)
@@ -381,8 +381,8 @@ _slang_input_index(const char *name, GLenum target, GLuint *swizzleOut)
       { "gl_TexCoord", FRAG_ATTRIB_TEX0, SWIZZLE_NOOP },
       /* note: we're packing several quantities into the fogcoord vector */
       { "gl_FogFragCoord", FRAG_ATTRIB_FOGC, SWIZZLE_XXXX },
-      { "gl_FrontFacing", FRAG_ATTRIB_FOGC, SWIZZLE_YYYY }, /*XXX*/
-      { "gl_PointCoord", FRAG_ATTRIB_FOGC, SWIZZLE_ZWWW },
+      { "gl_PointCoord", FRAG_ATTRIB_PNTC, SWIZZLE_XYZW },
+      { "gl_FrontFacing", FRAG_ATTRIB_FACE, SWIZZLE_XXXX },
       { NULL, 0, SWIZZLE_NOOP }
    };
    GLuint i;
index f6032d1e9adedb51970e33d8bdc460b7f495ae57..6c19fc895b3994dfed2661e83358c490ab7315d2 100644 (file)
@@ -484,20 +484,6 @@ _slang_update_inputs_outputs(struct gl_program *prog)
       for (j = 0; j < numSrc; j++) {
          if (inst->SrcReg[j].File == PROGRAM_INPUT) {
             prog->InputsRead |= 1 << inst->SrcReg[j].Index;
-            if (prog->Target == GL_FRAGMENT_PROGRAM_ARB &&
-                inst->SrcReg[j].Index == FRAG_ATTRIB_FOGC) {
-               /* The fragment shader FOGC input is used for fog,
-                * front-facing and sprite/point coord.
-                */
-               struct gl_fragment_program *fp = fragment_program(prog);
-               const GLint swz = GET_SWZ(inst->SrcReg[j].Swizzle, 0);
-               if (swz == SWIZZLE_X)
-                  fp->UsesFogFragCoord = GL_TRUE;
-               else if (swz == SWIZZLE_Y)
-                  fp->UsesFrontFacing = GL_TRUE;
-               else if (swz == SWIZZLE_Z || swz == SWIZZLE_W)
-                  fp->UsesPointCoord = GL_TRUE;
-            }
          }
          else if (inst->SrcReg[j].File == PROGRAM_ADDRESS) {
             maxAddrReg = MAX2(maxAddrReg, (GLuint) (inst->SrcReg[j].Index + 1));
index 8b3bb5cc0330b5c9ca3b79d7fc1952a5db92302d..ee649be885e2fa882ea5e80685796eb93a00c2cd 100644 (file)
@@ -139,23 +139,6 @@ find_translated_vp(struct st_context *st,
          if (fragInputsRead & (1 << inAttr)) {
             stfp->input_to_slot[inAttr] = numIn;
             numIn++;
-            if (((1 << inAttr) & FRAG_BIT_FOGC)) {
-               /* leave placeholders for the
-                * extra registers we extract from fog */
-               if (stfp->Base.UsesFrontFacing) {
-                  if (!stfp->Base.UsesFogFragCoord)
-                     --stfp->input_to_slot[inAttr];
-                  else
-                     ++numIn;
-               }
-               if (stfp->Base.UsesPointCoord) {
-                  if (!stfp->Base.UsesFrontFacing &&
-                      !stfp->Base.UsesFogFragCoord)
-                     stfp->input_to_slot[inAttr] -= 2;
-                  else
-                     ++numIn;
-               }
-            }
          }
          else {
             stfp->input_to_slot[inAttr] = UNUSED;
index 6380cd6b2a8e8cceb5607f9f01f8b216a18a1296..210ca82c42e9247e5413a2e2d837cfbf8904c269 100644 (file)
@@ -112,27 +112,6 @@ map_register_file_index(
 {
    switch( file ) {
    case TGSI_FILE_INPUT:
-      if (procType == TGSI_PROCESSOR_FRAGMENT &&
-          index == FRAG_ATTRIB_FOGC) {
-         if (GET_SWZ(*swizzle, 0) == SWIZZLE_X) {
-            /* do nothing we're, ok */
-         } else if (GET_SWZ(*swizzle, 0) == SWIZZLE_Y) {
-            /* replace the swizzle with xxxx */
-            *swizzle = MAKE_SWIZZLE4(SWIZZLE_X,
-                                     SWIZZLE_X,
-                                     SWIZZLE_X,
-                                     SWIZZLE_X);
-            /* register after fog */
-            return inputMapping[index] + 1;
-         } else {
-            *swizzle = MAKE_SWIZZLE4(SWIZZLE_Z,
-                                     SWIZZLE_W,
-                                     SWIZZLE_Z,
-                                     SWIZZLE_W);
-            /* register after frontface */
-            return inputMapping[index] + 2;
-         }
-      }
       /* inputs are mapped according to the user-defined map */
       return inputMapping[index];
 
index 806e0ca8f658125c565ee6d8b31e6ef91df91c84..d2da20ae424710f01e238b8e1916ca85537f2a8d 100644 (file)
@@ -458,34 +458,20 @@ st_translate_fragment_program(struct st_context *st,
             stfp->input_semantic_index[slot] = 1;
             interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
             break;
-         case FRAG_ATTRIB_FOGC: {
-            int extra_decls = 0;
-            if (stfp->Base.UsesFogFragCoord) {
-               stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
-               stfp->input_semantic_index[slot] = 0;
-               interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
-               input_flags[slot] = stfp->Base.Base.InputFlags[attr];
-               ++extra_decls;
-           }
-            if (stfp->Base.UsesFrontFacing) {
-               GLint idx = slot + extra_decls;
-               stfp->input_semantic_name[idx] = TGSI_SEMANTIC_FACE;
-               stfp->input_semantic_index[idx] = 0;
-               interpMode[idx] = TGSI_INTERPOLATE_CONSTANT;
-               input_flags[idx] = stfp->Base.Base.InputFlags[attr];
-               ++extra_decls;
-            }
-            if (stfp->Base.UsesPointCoord) {
-               GLint idx = slot + extra_decls;
-               stfp->input_semantic_name[idx] = TGSI_SEMANTIC_GENERIC;
-               stfp->input_semantic_index[idx] = num_generic++;
-               interpMode[idx] = TGSI_INTERPOLATE_PERSPECTIVE;
-               input_flags[idx] = stfp->Base.Base.InputFlags[attr];
-               ++extra_decls;
-            }
-            fs_num_inputs += extra_decls - 1;
-            continue;
-         }
+         case FRAG_ATTRIB_FOGC:
+            stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
+            stfp->input_semantic_index[slot] = 0;
+            interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+            break;
+         case FRAG_ATTRIB_FACE:
+            stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
+            stfp->input_semantic_index[slot] = num_generic++;
+            interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
+            break;
+         case FRAG_ATTRIB_PNTC:
+            stfp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
+            stfp->input_semantic_index[slot] = num_generic++;
+            interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
             break;
          case FRAG_ATTRIB_TEX0:
          case FRAG_ATTRIB_TEX1:
index b71fb9eae97c123e6fff76377ad38f99b7e0cb99..613a91b0ecd19c7b59cd7b0657ffc3b86ae3e4a9 100644 (file)
@@ -157,9 +157,8 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine,
 
    /* if running a GLSL program (not ARB_fragment_program) */
    if (ctx->Shader.CurrentProgram) {
-      /* Store front/back facing value in register FOGC.Y */
-      machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = 1.0 - span->facing;
-      /* Note FOGC.ZW is gl_PointCoord if drawing a sprite */
+      /* Store front/back facing value */
+      machine->Attribs[FRAG_ATTRIB_FACE][col][0] = 1.0 - span->facing;
    }
 
    machine->CurElement = col;
index 0a3ad97a71b34d966220ce7607160976f5fed93b..64c9cda5165430a20696be2586fb5c711f64f4bf 100644 (file)
@@ -139,7 +139,8 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
       }
 
       ATTRIB_LOOP_BEGIN
-         if (attr >= FRAG_ATTRIB_TEX0 && attr < FRAG_ATTRIB_VAR0) {
+         if ((attr >= FRAG_ATTRIB_TEX0 && attr <= FRAG_ATTRIB_TEX7) ||
+            attr >= FRAG_ATTRIB_VAR0) {
             const GLuint u = attr - FRAG_ATTRIB_TEX0;
             /* a texcoord */
             if (ctx->Point.CoordReplace[u]) {
@@ -170,15 +171,15 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
                continue;
             }
          }
-         else if (attr == FRAG_ATTRIB_FOGC) {
-            /* GLSL gl_PointCoord is stored in fog.zw */
-            span.attrStart[FRAG_ATTRIB_FOGC][2] = 0.0;
-            span.attrStart[FRAG_ATTRIB_FOGC][3] = 0.0; /* t0 set below */
-            span.attrStepX[FRAG_ATTRIB_FOGC][2] = dsdx;
-            span.attrStepX[FRAG_ATTRIB_FOGC][3] = 0.0;
-            span.attrStepY[FRAG_ATTRIB_FOGC][2] = 0.0;
-            span.attrStepY[FRAG_ATTRIB_FOGC][3] = dtdy;
-            tCoords[numTcoords++] = FRAG_ATTRIB_FOGC;
+         else if (attr == FRAG_ATTRIB_PNTC) {
+            /* GLSL gl_PointCoord.xy (.zw undefined) */
+            span.attrStart[FRAG_ATTRIB_PNTC][0] = 0.0;
+            span.attrStart[FRAG_ATTRIB_PNTC][1] = 0.0; /* t0 set below */
+            span.attrStepX[FRAG_ATTRIB_PNTC][0] = dsdx;
+            span.attrStepX[FRAG_ATTRIB_PNTC][1] = 0.0;
+            span.attrStepY[FRAG_ATTRIB_PNTC][0] = 0.0;
+            span.attrStepY[FRAG_ATTRIB_PNTC][1] = dtdy;
+            tCoords[numTcoords++] = FRAG_ATTRIB_PNTC;
             continue;
          }
          /* use vertex's texcoord/attrib */
@@ -221,10 +222,7 @@ sprite_point(GLcontext *ctx, const SWvertex *vert)
          GLuint i;
          /* setup texcoord T for this row */
          for (i = 0; i < numTcoords; i++) {
-            if (tCoords[i] == FRAG_ATTRIB_FOGC)
-               span.attrStart[FRAG_ATTRIB_FOGC][3] = tcoord;
-            else
-               span.attrStart[tCoords[i]][1] = tcoord;
+            span.attrStart[tCoords[i]][1] = tcoord;
          }
 
          /* these might get changed by span clipping */