Merge branch 'llvm-cliptest-viewport'
[mesa.git] / src / mesa / state_tracker / st_program.c
index 172d7dfe90563e795ffb30fc9254d7e6942e86d2..95e6bd7dac2e78a5ef917a894358c3b5faea3646 100644 (file)
@@ -41,6 +41,7 @@
 #include "pipe/p_shader_tokens.h"
 #include "draw/draw_context.h"
 #include "tgsi/tgsi_dump.h"
+#include "tgsi/tgsi_ureg.h"
 
 #include "st_debug.h"
 #include "st_context.h"
@@ -206,6 +207,9 @@ st_translate_vertex_program(struct st_context *st,
    enum pipe_error error;
    unsigned num_outputs;
 
+   _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_OUTPUT);
+   _mesa_remove_output_reads(&stvp->Base.Base, PROGRAM_VARYING);
+
    ureg = ureg_create( TGSI_PROCESSOR_VERTEX );
    if (ureg == NULL) {
       FREE(vpv);
@@ -297,6 +301,8 @@ st_translate_fragment_program(struct st_context *st,
    ubyte fs_output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
    uint fs_num_outputs = 0;
 
+   _mesa_remove_output_reads(&stfp->Base.Base, PROGRAM_OUTPUT);
+
    /*
     * Convert Mesa program inputs to TGSI input register semantics.
     */
@@ -332,17 +338,6 @@ st_translate_fragment_program(struct st_context *st,
             input_semantic_index[slot] = 0;
             interpMode[slot] = TGSI_INTERPOLATE_CONSTANT;
             break;
-         case FRAG_ATTRIB_PNTC:
-            /* This is a hack.  We really need a new semantic label for
-             * point coord.  The draw module needs to know which fragment
-             * shader input is the point coord attribute so that it can set
-             * up the right vertex attribute values.
-             */
-            input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
-            input_semantic_index[slot] = 0;
-            interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
-            break;
-
             /* In most cases, there is nothing special about these
              * inputs, so adopt a convention to use the generic
              * semantic name and the mesa FRAG_ATTRIB_ number as the
@@ -358,6 +353,7 @@ st_translate_fragment_program(struct st_context *st,
              * zero or be restricted to a particular range -- nobody
              * should be building tables based on semantic index.
              */
+         case FRAG_ATTRIB_PNTC:
          case FRAG_ATTRIB_TEX0:
          case FRAG_ATTRIB_TEX1:
          case FRAG_ATTRIB_TEX2:
@@ -374,7 +370,10 @@ st_translate_fragment_program(struct st_context *st,
             assert(attr >= FRAG_ATTRIB_TEX0);
             input_semantic_index[slot] = (attr - FRAG_ATTRIB_TEX0);
             input_semantic_name[slot] = TGSI_SEMANTIC_GENERIC;
-            interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+            if (attr == FRAG_ATTRIB_PNTC)
+               interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
+            else
+               interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
             break;
          }
       }
@@ -399,11 +398,20 @@ st_translate_fragment_program(struct st_context *st,
          outputsWritten &= ~(1 << FRAG_RESULT_DEPTH);
       }
 
+      if (outputsWritten & BITFIELD64_BIT(FRAG_RESULT_STENCIL)) {
+         fs_output_semantic_name[fs_num_outputs] = TGSI_SEMANTIC_STENCIL;
+         fs_output_semantic_index[fs_num_outputs] = 0;
+         outputMapping[FRAG_RESULT_STENCIL] = fs_num_outputs;
+         fs_num_outputs++;
+         outputsWritten &= ~(1 << FRAG_RESULT_STENCIL);
+      }
+
       /* handle remaning outputs (color) */
       for (attr = 0; attr < FRAG_RESULT_MAX; attr++) {
          if (outputsWritten & BITFIELD64_BIT(attr)) {
             switch (attr) {
             case FRAG_RESULT_DEPTH:
+            case FRAG_RESULT_STENCIL:
                /* handled above */
                assert(0);
                break;
@@ -484,16 +492,19 @@ st_translate_geometry_program(struct st_context *st,
    GLuint maxSlot = 0;
    struct ureg_program *ureg;
 
+   _mesa_remove_output_reads(&stgp->Base.Base, PROGRAM_OUTPUT);
+   _mesa_remove_output_reads(&stgp->Base.Base, PROGRAM_VARYING);
+
    ureg = ureg_create( TGSI_PROCESSOR_GEOMETRY );
    if (ureg == NULL) {
       return;
    }
 
    /* which vertex output goes to the first geometry input */
-   if (inputsRead & GEOM_BIT_VERTICES)
-      vslot = 0;
-   else
-      vslot = 1;
+   vslot = 0;
+
+   memset(inputMapping, 0, sizeof(inputMapping));
+   memset(outputMapping, 0, sizeof(outputMapping));
 
    /*
     * Convert Mesa program inputs to TGSI input register semantics.
@@ -511,8 +522,7 @@ st_translate_geometry_program(struct st_context *st,
          stgp->index_to_input[vslot] = attr;
          ++vslot;
 
-         if (attr != GEOM_ATTRIB_VERTICES &&
-             attr != GEOM_ATTRIB_PRIMITIVE_ID) {
+         if (attr != GEOM_ATTRIB_PRIMITIVE_ID) {
             gs_array_offset += 2;
          } else
             ++gs_builtin_inputs;
@@ -523,9 +533,6 @@ st_translate_geometry_program(struct st_context *st,
 #endif
 
          switch (attr) {
-         case GEOM_ATTRIB_VERTICES:
-            debug_assert(0);
-            break;
          case GEOM_ATTRIB_PRIMITIVE_ID:
             stgp->input_semantic_name[slot] = TGSI_SEMANTIC_PRIMID;
             stgp->input_semantic_index[slot] = 0;
@@ -709,7 +716,7 @@ st_translate_geometry_program(struct st_context *st,
  * Debug- print current shader text
  */
 void
-st_print_shaders(GLcontext *ctx)
+st_print_shaders(struct gl_context *ctx)
 {
    struct gl_shader_program *shProg = ctx->Shader.CurrentProgram;
    if (shProg) {