draw: inject frontface info into wireframe outputs
[mesa.git] / src / gallium / drivers / i915 / i915_state_derived.c
index 392ba1911403a7a0d310374edede4dade8bd8a1f..e1d18403d5d0105548b05c7c919a15605db0f37d 100644 (file)
@@ -33,6 +33,7 @@
 #include "i915_context.h"
 #include "i915_state.h"
 #include "i915_debug.h"
+#include "i915_fpc.h"
 #include "i915_reg.h"
 
 static uint find_mapping(const struct i915_fragment_shader* fs, int unit)
@@ -58,20 +59,26 @@ static void calculate_vertex_layout(struct i915_context *i915)
    const struct i915_fragment_shader *fs = i915->fs;
    const enum interp_mode colorInterp = i915->rasterizer->color_interp;
    struct vertex_info vinfo;
-   boolean texCoords[I915_TEX_UNITS], colors[2], fog, needW;
+   boolean texCoords[I915_TEX_UNITS], colors[2], fog, needW, face;
    uint i;
    int src;
 
    memset(texCoords, 0, sizeof(texCoords));
-   colors[0] = colors[1] = fog = needW = FALSE;
+   colors[0] = colors[1] = fog = needW = face = FALSE;
    memset(&vinfo, 0, sizeof(vinfo));
 
+   draw_prepare_shader_outputs(i915->draw);
+
    /* Determine which fragment program inputs are needed.  Setup HW vertex
     * layout below, in the HW-specific attribute order.
     */
    for (i = 0; i < fs->info.num_inputs; i++) {
       switch (fs->info.input_semantic_name[i]) {
       case TGSI_SEMANTIC_POSITION:
+         {
+            uint unit = I915_SEMANTIC_POS;
+            texCoords[find_mapping(fs, unit)] = TRUE;
+         }
          break;
       case TGSI_SEMANTIC_COLOR:
          assert(fs->info.input_semantic_index[i] < 2);
@@ -80,7 +87,6 @@ static void calculate_vertex_layout(struct i915_context *i915)
       case TGSI_SEMANTIC_GENERIC:
          {
             /* texcoords/varyings/other generic */
-            /* XXX handle back/front face and point size */
             uint unit = fs->info.input_semantic_index[i];
 
             texCoords[find_mapping(fs, unit)] = TRUE;
@@ -90,7 +96,11 @@ static void calculate_vertex_layout(struct i915_context *i915)
       case TGSI_SEMANTIC_FOG:
          fog = TRUE;
          break;
+      case TGSI_SEMANTIC_FACE:
+         face = TRUE;
+         break;
       default:
+         debug_printf("Unknown input type %d\n", fs->info.input_semantic_name[i]);
          assert(0);
       }
    }
@@ -147,6 +157,20 @@ static void calculate_vertex_layout(struct i915_context *i915)
       vinfo.hwfmt[1] |= hwtc << (i * 4);
    }
 
+   /* front/back face */
+   if (face) {
+      uint slot = find_mapping(fs, I915_SEMANTIC_FACE);
+      debug_printf("Front/back face is broken\n");
+      /* XXX Because of limitations in the draw module, currently src will be 0
+       * for SEMANTIC_FACE, so this aliases to POS. We need to fix in the draw
+       * module by adding an extra shader output.
+       */
+      src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_FACE, 0);
+      draw_emit_vertex_attr(&vinfo, EMIT_1F, INTERP_CONSTANT, src);
+      vinfo.hwfmt[1] &= ~(TEXCOORDFMT_NOT_PRESENT << (slot * 4));
+      vinfo.hwfmt[1] |= TEXCOORDFMT_1D << (slot * 4);
+   }
+
    draw_compute_vertex_size(&vinfo);
 
    if (memcmp(&i915->current.vertex_info, &vinfo, sizeof(vinfo))) {