gallium: fix the front face semantics
authorZack Rusin <zack@kde.org>
Wed, 1 Jul 2009 14:42:58 +0000 (10:42 -0400)
committerZack Rusin <zack@kde.org>
Wed, 1 Jul 2009 14:45:55 +0000 (10:45 -0400)
mesa allocates both frontface and pointcoord registers within the fog
coordinate register, by using swizzling. to make it cleaner and easier
for drivers we want each of them in its own register. so when doing
compilation from the mesa IR to tgsi allocate new registers for both
and add new semantics to the respective declarations.

src/gallium/drivers/softpipe/sp_setup.c
src/gallium/drivers/softpipe/sp_state_derived.c
src/gallium/include/pipe/p_shader_tokens.h
src/mesa/state_tracker/st_atom_shader.c
src/mesa/state_tracker/st_mesa_to_tgsi.c
src/mesa/state_tracker/st_program.c

index e5be65242d6e8b4d35b486b89a50d5fa850d5a62..1eb23cd6b6ffd131b5d3d4f5369774e294a5a013 100644 (file)
@@ -785,11 +785,10 @@ static void setup_tri_coefficients( struct setup_context *setup )
          assert(0);
       }
 
-      if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FOG) {
-         /* FOG.y = front/back facing  XXX fix this */
-         setup->coef[fragSlot].a0[1] = 1.0f - setup->quad.input.facing;
-         setup->coef[fragSlot].dadx[1] = 0.0;
-         setup->coef[fragSlot].dady[1] = 0.0;
+      if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) {
+         setup->coef[fragSlot].a0[0] = 1.0f - setup->quad.input.facing;
+         setup->coef[fragSlot].dadx[0] = 0.0;
+         setup->coef[fragSlot].dady[0] = 0.0;
       }
    }
 }
@@ -1096,11 +1095,10 @@ setup_line_coefficients(struct setup_context *setup,
          assert(0);
       }
 
-      if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FOG) {
-         /* FOG.y = front/back facing  XXX fix this */
-         setup->coef[fragSlot].a0[1] = 1.0f - setup->quad.input.facing;
-         setup->coef[fragSlot].dadx[1] = 0.0;
-         setup->coef[fragSlot].dady[1] = 0.0;
+      if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) {
+         setup->coef[fragSlot].a0[0] = 1.0f - setup->quad.input.facing;
+         setup->coef[fragSlot].dadx[0] = 0.0;
+         setup->coef[fragSlot].dady[0] = 0.0;
       }
    }
    return TRUE;
@@ -1342,11 +1340,10 @@ setup_point( struct setup_context *setup,
          assert(0);
       }
 
-      if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FOG) {
-         /* FOG.y = front/back facing  XXX fix this */
-         setup->coef[fragSlot].a0[1] = 1.0f - setup->quad.input.facing;
-         setup->coef[fragSlot].dadx[1] = 0.0;
-         setup->coef[fragSlot].dady[1] = 0.0;
+      if (spfs->info.input_semantic_name[fragSlot] == TGSI_SEMANTIC_FACE) {
+         setup->coef[fragSlot].a0[0] = 1.0f - setup->quad.input.facing;
+         setup->coef[fragSlot].dadx[0] = 0.0;
+         setup->coef[fragSlot].dady[0] = 0.0;
       }
    }
 
index 6b6a4c3ff3487a4fd9ab6becbafae0d959c80a5f..75551000c9bed8fb699225de267146ccb75a9c7b 100644 (file)
@@ -110,6 +110,7 @@ softpipe_get_vertex_info(struct softpipe_context *softpipe)
             break;
 
          case TGSI_SEMANTIC_GENERIC:
+         case TGSI_SEMANTIC_FACE:
             /* this includes texcoords and varying vars */
             src = draw_find_vs_output(softpipe->draw, TGSI_SEMANTIC_GENERIC,
                                       spfs->info.input_semantic_index[i]);
index 4dafdd6f0a9f43b176e2ba321b6faf5837ba1592..b00cfe3423c733e250820b780d50417a113a7d35 100644 (file)
@@ -131,7 +131,8 @@ struct tgsi_declaration_range
 #define TGSI_SEMANTIC_PSIZE    4
 #define TGSI_SEMANTIC_GENERIC  5
 #define TGSI_SEMANTIC_NORMAL   6
-#define TGSI_SEMANTIC_COUNT    7 /**< number of semantic values */
+#define TGSI_SEMANTIC_FACE     7
+#define TGSI_SEMANTIC_COUNT    8 /**< number of semantic values */
 
 struct tgsi_declaration_semantic
 {
index ee649be885e2fa882ea5e80685796eb93a00c2cd..c02ccc3528302aca00ee4cb11252a2574cc7e258 100644 (file)
@@ -137,8 +137,23 @@ find_translated_vp(struct st_context *st,
 
       for (inAttr = 0; inAttr < FRAG_ATTRIB_MAX; inAttr++) {
          if (fragInputsRead & (1 << inAttr)) {
-            stfp->input_to_slot[inAttr] = numIn;
-            numIn++;
+            if ((fragInputsRead & FRAG_BIT_FOGC)) {
+               if (stfp->Base.UsesPointCoord) {
+                  stfp->input_to_slot[inAttr] = numIn;
+                  numIn++;
+               }
+               if (stfp->Base.UsesFrontFacing) {
+                  stfp->input_to_slot[inAttr] = numIn;
+                  numIn++;
+               }
+               if (stfp->Base.UsesFogFragCoord) {
+                  stfp->input_to_slot[inAttr] = numIn;
+                  numIn++;
+               }
+            } else {
+               stfp->input_to_slot[inAttr] = numIn;
+               numIn++;
+            }
          }
          else {
             stfp->input_to_slot[inAttr] = UNUSED;
index 43c9afccc3b355bd7124758fada492783d93ffc1..3140ebe04adb09cd91baf05dd38d2e9e35dc87dd 100644 (file)
@@ -101,8 +101,10 @@ map_register_file(
  */
 static GLuint
 map_register_file_index(
+   GLuint procType,
    GLuint file,
    GLuint index,
+   GLuint *swizzle,
    const GLuint inputMapping[],
    const GLuint outputMapping[],
    const GLuint immediateMapping[],
@@ -110,6 +112,20 @@ 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);
+         } else {
+            /* fixme: point coord */
+         }
+      }
       /* inputs are mapped according to the user-defined map */
       return inputMapping[index];
 
@@ -236,8 +252,10 @@ compile_instruction(
    fulldst = &fullinst->FullDstRegisters[0];
    fulldst->DstRegister.File = map_register_file( inst->DstReg.File, 0, NULL, GL_FALSE );
    fulldst->DstRegister.Index = map_register_file_index(
+      procType,
       fulldst->DstRegister.File,
       inst->DstReg.Index,
+      NULL,
       inputMapping,
       outputMapping,
       NULL,
@@ -246,6 +264,7 @@ compile_instruction(
 
    for (i = 0; i < fullinst->Instruction.NumSrcRegs; i++) {
       GLuint j;
+      GLuint swizzle = inst->SrcReg[i].Swizzle;
 
       fullsrc = &fullinst->FullSrcRegisters[i];
 
@@ -264,8 +283,10 @@ compile_instruction(
             immediateMapping,
             indirectAccess );
          fullsrc->SrcRegister.Index = map_register_file_index(
+            procType,
             fullsrc->SrcRegister.File,
             inst->SrcReg[i].Index,
+            &swizzle,
             inputMapping,
             outputMapping,
             immediateMapping,
@@ -278,7 +299,7 @@ compile_instruction(
          GLboolean extended = (inst->SrcReg[i].Negate != NEGATE_NONE &&
                                inst->SrcReg[i].Negate != NEGATE_XYZW);
          for( j = 0; j < 4; j++ ) {
-            swz[j] = GET_SWZ( inst->SrcReg[i].Swizzle, j );
+            swz[j] = GET_SWZ( swizzle, j );
             if (swz[j] > SWIZZLE_W)
                extended = GL_TRUE;
          }
index 72ca85245829cecd213ef6959e15d60c1b4e044d..9a346fbde0c7d05217bd4ce765c5c3dda71d7a44 100644 (file)
@@ -437,11 +437,16 @@ st_translate_fragment_program(struct st_context *st,
             if (stfp->Base.UsesPointCoord) {
                stfp->input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
                stfp->input_semantic_index[slot] = num_generic++;
+               interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+            } else if (stfp->Base.UsesFrontFacing) {
+               stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FACE;
+               stfp->input_semantic_index[slot] = 0;
+               interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
             } else {
                stfp->input_semantic_name[slot] = TGSI_SEMANTIC_FOG;
                stfp->input_semantic_index[slot] = 0;
+               interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
            }
-            interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
             break;
          case FRAG_ATTRIB_TEX0:
          case FRAG_ATTRIB_TEX1: