OSDN Git Service

Vertex shader outputs are now tightly packed into the output slots.
authorBrian <brian.paul@tungstengraphics.com>
Fri, 24 Aug 2007 01:03:42 +0000 (19:03 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Fri, 24 Aug 2007 01:03:42 +0000 (19:03 -0600)
Fix softpipe vertex attribute setup.
Also, update vs constants when the projection matrix changes (fixes samples/prim.c)

src/mesa/pipe/draw/draw_prim.c
src/mesa/pipe/softpipe/sp_state_derived.c
src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
src/mesa/state_tracker/st_atom_vs.c

index 2ba3cb3..76c2a82 100644 (file)
@@ -200,7 +200,7 @@ run_vertex_program(struct draw_context *draw,
             machine.Inputs[attr].xyzw[2].f[j] = p[2]; /*Z*/
             machine.Inputs[attr].xyzw[3].f[j] = p[3]; /*W*/
 #if 0
-            if (1/*attr == 0*/) {
+            if (1) {
                fprintf(file, "Input vertex %d: attr %d:  %f %f %f %f\n",
                        j, attr, p[0], p[1], p[2], p[3]);
                fflush( file );
@@ -212,12 +212,15 @@ run_vertex_program(struct draw_context *draw,
 
 #if 0
    printf("Consts:\n");
-   for (i = 0; i < 4; i++) {
-      printf(" %d: %f %f %f %f\n", i,
-             machine.Consts[i][0],
-             machine.Consts[i][1],
-             machine.Consts[i][2],
-             machine.Consts[i][3]);
+   {
+      int i;
+      for (i = 0; i < 4; i++) {
+         printf(" %d: %f %f %f %f\n", i,
+                machine.Consts[i][0],
+                machine.Consts[i][1],
+                machine.Consts[i][2],
+                machine.Consts[i][3]);
+      }
    }
 #endif
 
@@ -238,7 +241,7 @@ run_vertex_program(struct draw_context *draw,
    /* store machine results */
    assert(draw->vertex_shader.outputs_written & (1 << TGSI_ATTRIB_POS));
    for (j = 0; j < count; j++) {
-      unsigned attr, slot;
+      unsigned /**attr,**/ slot;
       float x, y, z, w;
 
       /* Handle attr[0] (position) specially: */
@@ -247,7 +250,7 @@ run_vertex_program(struct draw_context *draw,
       z = vOut[j]->clip[2] = machine.Outputs[0].xyzw[2].f[j];
       w = vOut[j]->clip[3] = machine.Outputs[0].xyzw[3].f[j];
 
-      vOut[j]->clipmask = compute_clipmask(x, y, z, w);
+      vOut[j]->clipmask = 0;/*compute_clipmask(x, y, z, w);*/
       vOut[j]->edgeflag = 1;
 
       /* divide by w */
@@ -273,33 +276,47 @@ run_vertex_program(struct draw_context *draw,
 
       /* remaining attributes: */
       /* pack into sequential post-transform attrib slots */
+#if 0
       slot = 1;
       for (attr = 1; attr < TGSI_ATTRIB_MAX; attr++) {
          if (draw->vertex_shader.outputs_written & (1 << attr)) {
             assert(slot < draw->vertex_info.num_attribs);
-            vOut[j]->data[slot][0] = machine.Outputs[attr].xyzw[0].f[j];
-            vOut[j]->data[slot][1] = machine.Outputs[attr].xyzw[1].f[j];
-            vOut[j]->data[slot][2] = machine.Outputs[attr].xyzw[2].f[j];
-            vOut[j]->data[slot][3] = machine.Outputs[attr].xyzw[3].f[j];
+            vOut[j]->data[slot][0] = machine.Outputs[/*attr*/slot].xyzw[0].f[j];
+            vOut[j]->data[slot][1] = machine.Outputs[/*attr*/slot].xyzw[1].f[j];
+            vOut[j]->data[slot][2] = machine.Outputs[/*attr*/slot].xyzw[2].f[j];
+            vOut[j]->data[slot][3] = machine.Outputs[/*attr*/slot].xyzw[3].f[j];
 #if 0
-            fprintf(file, "output attrib %d slot %d: %f %f %f %f\n",
+            fprintf(file, "output attrib %d slot %d: %f %f %f %f  vert %p\n",
                     attr, slot,
                     vOut[j]->data[slot][0],
                     vOut[j]->data[slot][1],
                     vOut[j]->data[slot][2],
-                    vOut[j]->data[slot][3]);
+                    vOut[j]->data[slot][3], vOut[j]);
 #endif
             slot++;
          }
       }
-   }
 
+#else
+
+      for (slot = 1; slot < draw->vertex_info.num_attribs; 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];
 #if 0
-   memcpy(
-      quad->outputs.color,
-      &machine.Outputs[1].xyzw[0].f[0],
-      sizeof( quad->outputs.color ) );
+         fprintf(file, "output attrib slot %d: %f %f %f %f  vert %p\n",
+                 slot,
+                 vOut[j]->data[slot][0],
+                 vOut[j]->data[slot][1],
+                 vOut[j]->data[slot][2],
+                 vOut[j]->data[slot][3], vOut[j]);
 #endif
+      }
+
+#endif
+
+   } /* loop over vertices */
 }
 
 
index 5c119ec..a880e23 100644 (file)
@@ -48,31 +48,6 @@ do {                                                         \
 } while (0)
 
 
-static const unsigned frag_to_vf[PIPE_ATTRIB_MAX] = 
-{
-   TGSI_ATTRIB_POS,
-   TGSI_ATTRIB_COLOR0,
-   TGSI_ATTRIB_COLOR1,
-   TGSI_ATTRIB_FOG,
-   TGSI_ATTRIB_TEX0,
-   TGSI_ATTRIB_TEX1,
-   TGSI_ATTRIB_TEX2,
-   TGSI_ATTRIB_TEX3,
-   TGSI_ATTRIB_TEX4,
-   TGSI_ATTRIB_TEX5,
-   TGSI_ATTRIB_TEX6,
-   TGSI_ATTRIB_TEX7,
-   TGSI_ATTRIB_VAR0,
-   TGSI_ATTRIB_VAR1,
-   TGSI_ATTRIB_VAR2,
-   TGSI_ATTRIB_VAR3,
-   TGSI_ATTRIB_VAR4,
-   TGSI_ATTRIB_VAR5,
-   TGSI_ATTRIB_VAR6,
-   TGSI_ATTRIB_VAR7,
-};
-
-
 /**
  * Determine which post-transform / pre-rasterization vertex attributes
  * we need.
@@ -119,19 +94,17 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe )
     */
    for (i = 1; i < TGSI_ATTRIB_TEX0; i++) {
       if (inputsRead & (1 << i)) {
-         assert(i < sizeof(frag_to_vf) / sizeof(frag_to_vf[0]));
          if (softpipe->setup.flatshade
              && (i == TGSI_ATTRIB_COLOR0 || i == TGSI_ATTRIB_COLOR1))
-            EMIT_ATTR(frag_to_vf[i], i, INTERP_CONSTANT);
+            EMIT_ATTR(i, i, INTERP_CONSTANT);
          else
-            EMIT_ATTR(frag_to_vf[i], i, INTERP_LINEAR);
+            EMIT_ATTR(i, i, INTERP_LINEAR);
       }
    }
 
    for (i = TGSI_ATTRIB_TEX0; i < TGSI_ATTRIB_MAX; i++) {
       if (inputsRead & (1 << i)) {
-         assert(i < sizeof(frag_to_vf) / sizeof(frag_to_vf[0]));
-         EMIT_ATTR(frag_to_vf[i], i, INTERP_PERSPECTIVE);
+         EMIT_ATTR(i, i, INTERP_PERSPECTIVE);
          softpipe->need_w = TRUE;
       }
    }
index 993d220..f33a702 100644 (file)
@@ -348,7 +348,9 @@ map_register_file_index(
       break;\r
 \r
    case TGSI_FILE_OUTPUT:\r
+      /*\r
       assert( usage_bitmask == 0x0 );\r
+      */\r
       if( processor == TGSI_PROCESSOR_FRAGMENT ) {\r
          /* depth result  -> index 0\r
           * color results -> index 1, 2, ...\r
@@ -362,8 +364,14 @@ map_register_file_index(
          }\r
       }\r
       else {\r
+         /* vertex output slots are tightly packed, find mapped pos */\r
          /* mapped_index = VERT_RESULT_x */\r
-         mapped_index = index;\r
+         mapped_index = 0;\r
+         for( i = 0; i < index; i++ ) {\r
+            if( usage_bitmask & (1 << i) ) {\r
+               mapped_index++;\r
+            }\r
+         }\r
       }\r
       break;\r
 \r
@@ -434,6 +442,7 @@ compile_instruction(
    const struct prog_instruction *inst,\r
    struct tgsi_full_instruction *fullinst,\r
    GLuint inputs_read,\r
+   GLuint outputs_written,\r
    GLuint preamble_size,\r
    GLuint processor )\r
 {\r
@@ -453,7 +462,8 @@ compile_instruction(
       processor,\r
       fulldst->DstRegister.File,\r
       inst->DstReg.Index,\r
-      0x0 );\r
+      outputs_written\r
+      );\r
    fulldst->DstRegister.WriteMask = convert_writemask( inst->DstReg.WriteMask );\r
 \r
    for( i = 0; i < fullinst->Instruction.NumSrcRegs; i++ ) {\r
@@ -921,6 +931,7 @@ tgsi_mesa_compile_fp_program(
             &program->Base.Instructions[i],\r
             &fullinst,\r
             inputs_read,\r
+            ~0, /*outputs_written*/\r
             preamble_size,\r
             TGSI_PROCESSOR_FRAGMENT ) ) {\r
          assert( i == program->Base.NumInstructions - 1 );\r
@@ -952,6 +963,9 @@ tgsi_mesa_compile_vp_program(
    struct tgsi_processor *processor;\r
    struct tgsi_full_instruction fullinst;\r
    GLuint inputs_read = ~0;\r
+   GLuint outputs_written;\r
+\r
+   outputs_written = program->Base.OutputsWritten;\r
 \r
    *(struct tgsi_version *) &tokens[0] = tgsi_build_version();\r
 \r
@@ -968,6 +982,7 @@ tgsi_mesa_compile_vp_program(
             &program->Base.Instructions[i],\r
             &fullinst,\r
             inputs_read,\r
+            outputs_written,\r
             0,\r
             TGSI_PROCESSOR_VERTEX ) ) {\r
          assert( i == program->Base.NumInstructions - 1 );\r
index 8a38020..f16fe2a 100644 (file)
@@ -113,8 +113,10 @@ static void update_vs( struct st_context *st )
 
    /* update pipe state */
    memset( &vs, 0, sizeof(vs) );
-   vs.outputs_written = vp->Base.Base.OutputsWritten;
-   vs.inputs_read = vp->Base.Base.InputsRead;
+   vs.inputs_read
+      = tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead);
+   vs.outputs_written
+      = tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten);
    vs.tokens = &vp->tokens[0];
 
    if (memcmp(&vs, &st->state.vs, sizeof(vs)) != 0 ||
@@ -129,7 +131,7 @@ static void update_vs( struct st_context *st )
 
 const struct st_tracked_state st_update_vs = {
    .dirty = {
-      .mesa  = _NEW_PROGRAM | _NEW_MODELVIEW,
+      .mesa  = _NEW_PROGRAM | _NEW_MODELVIEW | _NEW_PROJECTION, /*XXX MORE*/
       .st   = ST_NEW_VERTEX_PROGRAM,
    },
    .update = update_vs