Pack fragment program outputs to be consistant with vertex programs.
authorBrian <brian.paul@tungstengraphics.com>
Tue, 9 Oct 2007 20:55:22 +0000 (14:55 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Tue, 9 Oct 2007 20:55:22 +0000 (14:55 -0600)
Previously, output[0] was always Z and output[1] was color.  Now output[0]
will be color if Z is not written.
In shade_quad() use the semantic info to determine which quantity is in
which output slot.

src/mesa/pipe/p_state.h
src/mesa/pipe/softpipe/sp_quad_fs.c
src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
src/mesa/state_tracker/st_program.c

index 64c5f13..99ec574 100644 (file)
@@ -152,7 +152,6 @@ struct pipe_shader_state {
 
    ubyte num_inputs;
    ubyte num_outputs;
-   uint outputs_written;  /**< bitmask */
    ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */
    ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
    ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */
index 2b0c436..b6005c6 100755 (executable)
@@ -78,6 +78,7 @@ shade_quad(
    const float fx = (float) quad->x0;
    const float fy = (float) quad->y0;
    struct tgsi_exec_machine *machine = &qss->machine;
+   uint colorOut;
 
    /* Consts does not require 16 byte alignment. */
    machine->Consts = softpipe->mapped_constants[PIPE_SHADER_FRAGMENT];
@@ -109,28 +110,32 @@ shade_quad(
       quad->mask &= tgsi_exec_machine_run( machine );
    }
 
-   /* store result color (always in output[1]) */
-   memcpy(
-      quad->outputs.color,
-      &machine->Outputs[1].xyzw[0].f[0],
-      sizeof( quad->outputs.color ) );
-
-   /* Z */
-   if (qss->stage.softpipe->fs->outputs_written & 0x1) {
+   if (qss->stage.softpipe->fs->output_semantic_name[0] == TGSI_SEMANTIC_POSITION) {
       /* output[0] is new Z */
       uint i;
       for (i = 0; i < 4; i++) {
          quad->outputs.depth[i] = machine->Outputs[0].xyzw[2].f[i];
       }
+      colorOut = 1;
    }
    else {
-      /* pass input Z to output Z */
+      /* pass input Z (which was interpolated by the executor) to output Z */
       uint i;
       for (i = 0; i < 4; i++) {
          quad->outputs.depth[i] = machine->Inputs[0].xyzw[2].f[i];
       }
+      colorOut = 0;
    }
 
+   /* store result color */
+   /* XXX need to handle multiple color outputs someday */
+   assert(qss->stage.softpipe->fs->output_semantic_name[colorOut]
+          == TGSI_SEMANTIC_COLOR);
+   memcpy(
+      quad->outputs.color,
+      &machine->Outputs[colorOut].xyzw[0].f[0],
+      sizeof( quad->outputs.color ) );
+
    /* shader may cull fragments */
    if( quad->mask ) {
       qs->next->run( qs->next, quad );
index 88de859..5a1ec35 100644 (file)
@@ -46,47 +46,22 @@ map_register_file(
  */\r
 static GLuint\r
 map_register_file_index(\r
-   GLuint processor,\r
    GLuint file,\r
    GLuint index,\r
    const GLuint inputMapping[],\r
    const GLuint outputMapping[])\r
 {\r
-   GLuint mapped_index;\r
-\r
-   assert(processor == TGSI_PROCESSOR_FRAGMENT\r
-          || processor == TGSI_PROCESSOR_VERTEX);\r
-\r
    switch( file ) {\r
    case TGSI_FILE_INPUT:\r
       /* inputs are mapped according to the user-defined map */\r
       return inputMapping[index];\r
 \r
    case TGSI_FILE_OUTPUT:\r
-      if( processor == TGSI_PROCESSOR_FRAGMENT ) {\r
-         /* fragment program outputs are hard-coded:\r
-          * depth result  -> index 0\r
-          * color results -> index 1, 2, ...\r
-          */\r
-        if( index == FRAG_RESULT_DEPR ) {\r
-            mapped_index = 0; /**TGSI_ATTRIB_POS;**/\r
-         }\r
-         else {\r
-            assert( index == FRAG_RESULT_COLR );\r
-            mapped_index = 1; /**TGSI_ATTRIB_COLOR0;**/\r
-         }\r
-      }\r
-      else {\r
-         /* vertex outputs are mapped according to the user-defined map */\r
-         mapped_index = outputMapping[index];\r
-      }\r
-      break;\r
+      return outputMapping[index];\r
 \r
    default:\r
-      mapped_index = index;\r
+      return index;\r
    }\r
-\r
-   return mapped_index;\r
 }\r
 \r
 /*\r
@@ -166,7 +141,6 @@ compile_instruction(
    fulldst = &fullinst->FullDstRegisters[0];\r
    fulldst->DstRegister.File = map_register_file( inst->DstReg.File );\r
    fulldst->DstRegister.Index = map_register_file_index(\r
-      processor,\r
       fulldst->DstRegister.File,\r
       inst->DstReg.Index,\r
       inputMapping,\r
@@ -180,7 +154,6 @@ compile_instruction(
       fullsrc = &fullinst->FullSrcRegisters[i];\r
       fullsrc->SrcRegister.File = map_register_file( inst->SrcReg[i].File );\r
       fullsrc->SrcRegister.Index = map_register_file_index(\r
-         processor,\r
          fullsrc->SrcRegister.File,\r
          inst->SrcReg[i].Index,\r
          inputMapping,\r
index 86aaaad..0b14830 100644 (file)
@@ -160,8 +160,6 @@ st_translate_vertex_program(struct st_context *st,
             defaultOutputMapping[attr] = slot;
          }
 
-         vs.outputs_written |= (1 << slot);
-
          /*
          printf("Output %u -> slot %u\n", attr, slot);
          */
@@ -346,35 +344,33 @@ st_translate_fragment_program(struct st_context *st,
    }
 
    /*
-    * Semantics for outputs
+    * Semantics and mapping for outputs
     */
    {
       uint numColors = 0;
       GLbitfield outputsWritten = stfp->Base.Base.OutputsWritten;
 
-      /* output[0] is always Z, but may not really be written */
-      fs.output_semantic_name[fs.num_outputs] = TGSI_SEMANTIC_POSITION;
-      fs.output_semantic_index[fs.num_outputs] = 0;
-      outputMapping[FRAG_RESULT_DEPR] = fs.num_outputs;
-      fs.num_outputs++;
-
+      /* if z is written, emit that first */
       if (outputsWritten & (1 << FRAG_RESULT_DEPR)) {
-         fs.outputs_written |= 0x1;
+         fs.output_semantic_name[fs.num_outputs] = TGSI_SEMANTIC_POSITION;
+         fs.output_semantic_index[fs.num_outputs] = 0;
+         outputMapping[FRAG_RESULT_DEPR] = fs.num_outputs;
+         fs.num_outputs++;
          outputsWritten &= ~(1 << FRAG_RESULT_DEPR);
       }
 
-      /* color outputs begin at output [1] */
+      /* handle remaning outputs (color) */
       for (attr = 0; attr < FRAG_RESULT_MAX; attr++) {
          if (outputsWritten & (1 << attr)) {
             switch (attr) {
             case FRAG_RESULT_DEPR:
+               /* handled above */
                assert(0);
                break;
             case FRAG_RESULT_COLR:
                fs.output_semantic_name[fs.num_outputs] = TGSI_SEMANTIC_COLOR;
                fs.output_semantic_index[fs.num_outputs] = numColors;
                outputMapping[attr] = fs.num_outputs;
-               fs.outputs_written |= (0x2 << numColors);
                numColors++;
                break;
             default: