OSDN Git Service

Checkpoint: replacement of TGSI_ATTRIB_x tokens with input/output semantics.
authorBrian <brian.paul@tungstengraphics.com>
Thu, 20 Sep 2007 00:53:36 +0000 (18:53 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Thu, 20 Sep 2007 00:53:59 +0000 (18:53 -0600)
TGSI_ATTRIB_x tokens still present and used in a few places.
Expanded set of TGSI_SEMANTIC_x tokens for describing the meaning
of inputs/outputs.  These tokens are in a crude state ATM.
Lots of #if 0 / disabled code to be removed yet, etc...
Softpipe and i915 drivers should be in working condition but not heavily tested.

22 files changed:
src/mesa/pipe/draw/draw_vertex_shader.c
src/mesa/pipe/i915simple/i915_context.c
src/mesa/pipe/i915simple/i915_fpc.h
src/mesa/pipe/i915simple/i915_fpc_translate.c
src/mesa/pipe/i915simple/i915_state_derived.c
src/mesa/pipe/p_context.h
src/mesa/pipe/p_defines.h
src/mesa/pipe/p_state.h
src/mesa/pipe/softpipe/sp_context.c
src/mesa/pipe/softpipe/sp_state_derived.c
src/mesa/pipe/tgsi/exec/tgsi_build.c
src/mesa/pipe/tgsi/exec/tgsi_dump.c
src/mesa/pipe/tgsi/exec/tgsi_token.h
src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.c
src/mesa/pipe/tgsi/mesa/mesa_to_tgsi.h
src/mesa/state_tracker/st_atom_fs.c
src/mesa/state_tracker/st_atom_vs.c
src/mesa/state_tracker/st_cb_clear.c
src/mesa/state_tracker/st_cb_drawpixels.c
src/mesa/state_tracker/st_cb_rasterpos.c
src/mesa/state_tracker/st_draw.c
src/mesa/state_tracker/st_program.h

index cb6c605..2d42463 100644 (file)
@@ -94,7 +94,11 @@ run_vertex_program(struct draw_context *draw,
    const float *trans = draw->viewport.translate;
 
    assert(count <= 4);
+#if 0
    assert(draw->vertex_shader.outputs_written & (1 << TGSI_ATTRIB_POS));
+#else
+   assert(draw->vertex_shader.output_semantics[0] == TGSI_SEMANTIC_POSITION);
+#endif
 
 #ifdef DEBUG
    memset( &machine, 0, sizeof( machine ) );
index 3637289..715e1ef 100644 (file)
@@ -138,6 +138,18 @@ i915_max_texture_size(struct pipe_context *pipe, unsigned textureType,
 }
 
 
+static int
+i915_get_param(struct pipe_context *pipe, uint param)
+{
+   switch (param) {
+   case PIPE_PARAM_FS_NEEDS_POS:
+      return 0;
+   default:
+      return 0;
+   }
+}
+
+
 static void i915_destroy( struct pipe_context *pipe )
 {
    struct i915_context *i915 = i915_context( pipe );
@@ -272,6 +284,8 @@ struct pipe_context *i915_create( struct pipe_winsys *pipe_winsys,
    i915->pipe.destroy = i915_destroy;
    i915->pipe.supported_formats = i915_supported_formats;
    i915->pipe.max_texture_size = i915_max_texture_size;
+   i915->pipe.get_param = i915_get_param;
+
    i915->pipe.clear = i915_clear;
 
    i915->pipe.begin_query = i915_begin_query;
index 84e4c5a..5c4f2f9 100644 (file)
@@ -51,6 +51,8 @@ struct i915_fp_compile {
    uint declarations[I915_PROGRAM_SIZE];
    uint program[I915_PROGRAM_SIZE];
 
+   uint input_semantic[PIPE_MAX_SHADER_INPUTS];
+
    /** points into the i915->current.constants array: */
    float (*constants)[4];
    uint num_constants;
index 32c5600..df8859b 100644 (file)
@@ -128,7 +128,7 @@ src_vector(struct i915_fp_compile *p,
            const struct tgsi_full_src_register *source)
 {
    uint index = source->SrcRegister.Index;
-   uint src;
+   uint src, sem;
 
    switch (source->SrcRegister.File) {
    case TGSI_FILE_TEMPORARY:
@@ -151,6 +151,46 @@ src_vector(struct i915_fp_compile *p,
 
       /* use vertex format info to map a slot number to a VF attrib */
       assert(index < p->vertex_info->num_attribs);
+
+      sem = p->input_semantic[index];
+
+#if 1
+      switch (sem) {
+      case TGSI_SEMANTIC_POSITION:
+         printf("SKIP SEM POS\n");
+         /*
+         assert(p->wpos_tex != -1);
+         src = i915_emit_decl(p, REG_TYPE_T, p->wpos_tex, D0_CHANNEL_ALL);
+         */
+         break;
+      case TGSI_SEMANTIC_COLOR0:
+         src = i915_emit_decl(p, REG_TYPE_T, T_DIFFUSE, D0_CHANNEL_ALL);
+         break;
+      case TGSI_SEMANTIC_COLOR1:
+         src = i915_emit_decl(p, REG_TYPE_T, T_SPECULAR, D0_CHANNEL_XYZ);
+         src = swizzle(src, X, Y, Z, ONE);
+         break;
+      case TGSI_SEMANTIC_FOG:
+         src = i915_emit_decl(p, REG_TYPE_T, T_FOG_W, D0_CHANNEL_W);
+         src = swizzle(src, W, W, W, W);
+         break;
+      case TGSI_SEMANTIC_TEX0:
+      case TGSI_SEMANTIC_TEX1:
+      case TGSI_SEMANTIC_TEX2:
+      case TGSI_SEMANTIC_TEX3:
+      case TGSI_SEMANTIC_TEX4:
+      case TGSI_SEMANTIC_TEX5:
+      case TGSI_SEMANTIC_TEX6:
+      case TGSI_SEMANTIC_TEX7:
+         src = i915_emit_decl(p, REG_TYPE_T,
+                              T_TEX0 + (sem - TGSI_SEMANTIC_TEX0),
+                              D0_CHANNEL_ALL);
+         break;
+      default:
+         i915_program_error(p, "Bad source->Index");
+         return 0;
+      }
+#else
       index = p->vertex_info->slot_to_attrib[index];
 
       switch (index) {
@@ -185,6 +225,7 @@ src_vector(struct i915_fp_compile *p,
          i915_program_error(p, "Bad source->Index");
          return 0;
       }
+#endif
       break;
 
    case TGSI_FILE_CONSTANT:
@@ -220,9 +261,12 @@ src_vector(struct i915_fp_compile *p,
    }
 
    /* no abs() or post-abs negation */
+#if 0
+   /* XXX assertions disabled to allow arbfplight.c to run */
+   /* XXX enable these assertions, or fix things */
    assert(!source->SrcRegisterExtMod.Absolute);
    assert(!source->SrcRegisterExtMod.Negate);
-
+#endif
    return src;
 }
 
@@ -848,7 +892,15 @@ i915_translate_instructions(struct i915_fp_compile *p,
 
       switch( parse.FullToken.Token.Type ) {
       case TGSI_TOKEN_TYPE_DECLARATION:
-         /* XXX no-op? */
+         if (parse.FullToken.FullDeclaration.Declaration.File
+             == TGSI_FILE_INPUT) {
+            /* save input register info for use in src_vector() */
+            uint ind, sem;
+            ind = parse.FullToken.FullDeclaration.u.DeclarationRange.First;
+            sem = parse.FullToken.FullDeclaration.Semantic.SemanticName;
+            /*printf("FS Input DECL [%u] sem %u\n", ind, sem);*/
+            p->input_semantic[ind] = sem;
+         }
          break;
 
       case TGSI_TOKEN_TYPE_IMMEDIATE:
@@ -989,6 +1041,7 @@ i915_fini_compile(struct i915_context *i915, struct i915_fp_compile *p)
 static void
 i915_find_wpos_space(struct i915_fp_compile *p)
 {
+#if 0
    const uint inputs
       = p->shader->inputs_read | (1 << TGSI_ATTRIB_POS); /*XXX hack*/
    uint i;
@@ -1005,6 +1058,14 @@ i915_find_wpos_space(struct i915_fp_compile *p)
 
       i915_program_error(p, "No free texcoord for wpos value");
    }
+#else
+   if (p->shader->input_semantics[0] == TGSI_SEMANTIC_POSITION) {
+      /* frag shader using the fragment position input */
+#if 0
+      assert(0);
+#endif
+   }
+#endif
 }
 
 
@@ -1018,13 +1079,17 @@ i915_find_wpos_space(struct i915_fp_compile *p)
 static void
 i915_fixup_depth_write(struct i915_fp_compile *p)
 {
-   if (p->shader->outputs_written & (1 << TGSI_ATTRIB_POS)) {
-      uint depth = UREG(REG_TYPE_OD, 0);
+   /* XXX assuming depth is always in output[0] */
+   if (p->shader->output_semantics[0] == TGSI_SEMANTIC_DEPTH) {
+      const uint depth = UREG(REG_TYPE_OD, 0);
 
       i915_emit_arith(p,
-                      A0_MOV,
-                      depth, A0_DEST_CHANNEL_W, 0,
-                      swizzle(depth, X, Y, Z, Z), 0, 0);
+                      A0_MOV,                     /* opcode */
+                      depth,                      /* dest reg */
+                      A0_DEST_CHANNEL_W,          /* write mask */
+                      0,                          /* saturate? */
+                      swizzle(depth, X, Y, Z, Z), /* src0 */
+                      0, 0 /* src1, src2 */);
    }
 }
 
index 8d404c5..dece697 100644 (file)
@@ -33,6 +33,7 @@
 #include "i915_state.h"
 #include "i915_reg.h"
 #include "i915_fpc.h"
+#include "pipe/tgsi/exec/tgsi_token.h"
 
 
 /**
  */
 static void calculate_vertex_layout( struct i915_context *i915 )
 {
-   const uint inputsRead = i915->fs->inputs_read;
+   const struct pipe_shader_state *fs = i915->fs;
    const interp_mode colorInterp
       = i915->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
    struct vertex_info *vinfo = &i915->current.vertex_info;
    uint front0 = 0, back0 = 0, front1 = 0, back1 = 0;
    boolean needW = 0;
+   uint i;
+   boolean texCoords[8];
 
+   memset(texCoords, 0, sizeof(texCoords));
    memset(vinfo, 0, sizeof(*vinfo));
 
    /* pos */
    draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_POS, FORMAT_3F, INTERP_LINEAR);
    /* Note: we'll set the S4_VFMT_XYZ[W] bits below */
 
+   for (i = 0; i < fs->num_inputs; i++) {
+      switch (fs->input_semantics[i]) {
+      case TGSI_SEMANTIC_POSITION:
+         break;
+      case TGSI_SEMANTIC_COLOR0:
+         front0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0,
+                                        FORMAT_4UB, colorInterp);
+         vinfo->hwfmt[0] |= S4_VFMT_COLOR;
+         break;
+      case TGSI_SEMANTIC_COLOR1:
+         assert(0); /* untested */
+         front1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1,
+                                        FORMAT_4UB, colorInterp);
+         vinfo->hwfmt[0] |= S4_VFMT_SPEC_FOG;
+         break;
+      case TGSI_SEMANTIC_TEX0:
+      case TGSI_SEMANTIC_TEX1:
+      case TGSI_SEMANTIC_TEX2:
+      case TGSI_SEMANTIC_TEX3:
+      case TGSI_SEMANTIC_TEX4:
+      case TGSI_SEMANTIC_TEX5:
+      case TGSI_SEMANTIC_TEX6:
+      case TGSI_SEMANTIC_TEX7:
+         {
+            const uint unit = fs->input_semantics[i] - TGSI_SEMANTIC_TEX0;
+            uint hwtc;
+            texCoords[unit] = TRUE;
+            draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_TEX0 + i,
+                               FORMAT_4F, INTERP_PERSPECTIVE);
+            hwtc = TEXCOORDFMT_4D;
+            needW = TRUE;
+            vinfo->hwfmt[1] |= hwtc << (unit * 4);
+         }
+         break;
+      default:
+         assert(0);
+      }
+
+   }
+
+   /* finish up texcoord fields */
+   for (i = 0; i < 8; i++) {
+      if (!texCoords[i]) {
+         const uint hwtc = TEXCOORDFMT_NOT_PRESENT;
+         vinfo->hwfmt[1] |= hwtc << (i* 4);
+      }
+   }
+
+#if 0
    /* color0 */
    if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) {
       front0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0,
@@ -88,6 +141,7 @@ static void calculate_vertex_layout( struct i915_context *i915 )
          vinfo->hwfmt[1] |= hwtc << ((i - TGSI_ATTRIB_TEX0) * 4);
       }
    }
+#endif
 
    /* go back and fill in the vertex position info now that we have needW */
    if (needW) {
@@ -104,11 +158,11 @@ static void calculate_vertex_layout( struct i915_context *i915 )
     * the vertex header.
     */
    if (i915->rasterizer->light_twoside) {
-      if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) {
+      if (front0) {
          back0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0,
                                        FORMAT_OMIT, colorInterp);
       }            
-      if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) {
+      if (back0) {
          back1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC1,
                                        FORMAT_OMIT, colorInterp);
       }
index 1c0ab79..65001df 100644 (file)
@@ -57,7 +57,8 @@ struct pipe_context {
 
    const char *(*get_vendor)( struct pipe_context *pipe );
 
-   
+   int (*get_param)( struct pipe_context *pipe, int param );
+
 
    /*
     * Drawing.  
index b3ee890..2a8109b 100644 (file)
 #define PIPE_QUERY_PRIMITIVES_EMITTED    2
 #define PIPE_QUERY_TYPES                 3
 
+
+/**
+ * Pipe capabilities/queries
+ */
+#define PIPE_PARAM_FS_NEEDS_POS  1
+
+
 #endif
index d2cc76a..6396d49 100644 (file)
@@ -50,6 +50,8 @@
 #define PIPE_MAX_COLOR_BUFS   8
 #define PIPE_MAX_TEXTURE_LEVELS  16
 #define PIPE_MAX_FEEDBACK_ATTRIBS 16
+#define PIPE_MAX_SHADER_INPUTS 16
+#define PIPE_MAX_SHADER_OUTPUTS 16
 
 
 /* fwd decl */
@@ -140,13 +142,14 @@ struct pipe_constant_buffer {
 
 
 struct pipe_shader_state {
-   unsigned inputs_read;                   /**< TGSI_ATTRIB_ bits */
-   unsigned outputs_written;               /**< TGSI_ATTRIB_ bits */
    const struct tgsi_token *tokens;
    void *executable;
 
-   uint num_inputs;
-   uint num_outputs;
+   /** These fields somewhat constitute the shader "signature" */
+   ubyte num_inputs;
+   ubyte num_outputs;
+   ubyte input_semantics[PIPE_MAX_SHADER_INPUTS];
+   ubyte output_semantics[PIPE_MAX_SHADER_OUTPUTS];
 };
 
 struct pipe_depth_stencil_state
index a56793d..ebd5530 100644 (file)
@@ -236,6 +236,15 @@ static const char *softpipe_get_vendor( struct pipe_context *pipe )
    return "Tungsten Graphics, Inc.";
 }
 
+static int softpipe_get_param(struct pipe_context *pipe, uint param)
+{
+   switch (param) {
+   case PIPE_PARAM_FS_NEEDS_POS:
+      return 1;
+   default:
+      return 0;
+   }
+}
 
 struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
                                      struct softpipe_winsys *softpipe_winsys )
@@ -248,6 +257,7 @@ struct pipe_context *softpipe_create( struct pipe_winsys *pipe_winsys,
    /* queries */
    softpipe->pipe.supported_formats = softpipe_supported_formats;
    softpipe->pipe.max_texture_size = softpipe_max_texture_size;
+   softpipe->pipe.get_param = softpipe_get_param;
 
    /* state setters */
    softpipe->pipe.create_blend_state = softpipe_create_blend_state;
index 9611a2a..0dd0eea 100644 (file)
@@ -34,6 +34,7 @@
 #include "sp_state.h"
 
 #include "pipe/tgsi/exec/tgsi_attribs.h"
+#include "pipe/tgsi/exec/tgsi_token.h"
 
 
 /**
@@ -43,7 +44,7 @@
  */
 static void calculate_vertex_layout( struct softpipe_context *softpipe )
 {
-   const uint inputsRead = softpipe->fs->inputs_read;
+   const struct pipe_shader_state *fs = softpipe->fs;
    const interp_mode colorInterp
       = softpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
    struct vertex_info *vinfo = &softpipe->vertex_info;
@@ -52,57 +53,59 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe )
 
    memset(vinfo, 0, sizeof(*vinfo));
 
-   /* Need Z if depth test is enabled or the fragment program uses the
-    * fragment position (XYZW).
-    */
-   if (softpipe->depth_stencil->depth.enabled ||
-       (inputsRead & (1 << TGSI_ATTRIB_POS)))
+   if (softpipe->depth_stencil->depth.enabled)
       softpipe->need_z = TRUE;
    else
       softpipe->need_z = FALSE;
+   softpipe->need_w = FALSE;
 
-   /* Need W if we do any perspective-corrected interpolation or the
-    * fragment program uses the fragment position.
-    */
-   if (inputsRead & (1 << TGSI_ATTRIB_POS))
-      softpipe->need_w = TRUE;
-   else
-      softpipe->need_w = FALSE;
-
-   /* position */
+   /* always emit vertex pos */
    /* TODO - Figure out if we need to do perspective divide, etc. */
    draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_POS, FORMAT_4F, INTERP_LINEAR);
-   /* color0 */
-   if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) {
-      front0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0,
-                                     FORMAT_4F, colorInterp);
-   }
-
-   /* color1 */
-   if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) {
-      front1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1,
-                                     FORMAT_4F, colorInterp);
-   }
 
-   /* fog */
-   if (inputsRead & (1 << TGSI_ATTRIB_FOG)) {
-      draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_FOG,
-                            FORMAT_1F, INTERP_PERSPECTIVE);
-   }
-
-   /* point size */
+   for (i = 0; i < fs->num_inputs; i++) {
+      switch (fs->input_semantics[i]) {
+      case TGSI_SEMANTIC_POSITION:
+         /* Need Z if depth test is enabled or the fragment program uses the
+          * fragment position (XYZW).
+          */
+         softpipe->need_z = TRUE;
+         softpipe->need_w = TRUE;
+         break;
+      case TGSI_SEMANTIC_COLOR0:
+         front0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR0,
+                                        FORMAT_4F, colorInterp);
+         break;
+      case TGSI_SEMANTIC_COLOR1:
+         front1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_COLOR1,
+                                        FORMAT_4F, colorInterp);
+         break;
+      case TGSI_SEMANTIC_FOG:
+         draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_FOG,
+                               FORMAT_1F, INTERP_PERSPECTIVE);
+         break;
 #if 0
-   /* XXX only emit if drawing points or front/back polygon mode is point mode */
-   draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_POINTSIZE,
-                         FORMAT_4F, INTERP_CONSTANT);
+      case TGSI_SEMANTIC_PSIZE:
+         /* XXX only emit if drawing points or front/back polygon mode
+          * is point mode
+          */
+         draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_POINTSIZE,
+                               FORMAT_4F, INTERP_CONSTANT);
+         break;
 #endif
-
-   /* texcoords and varying vars */
-   for (i = TGSI_ATTRIB_TEX0; i < TGSI_ATTRIB_VAR7; i++) {
-      if (inputsRead & (1 << i)) {
+         /*case TGSI_SEMANTIC_TEXCOORD:*/
+      case TGSI_SEMANTIC_TEX0:
+         draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_TEX0,
+                               FORMAT_4F, INTERP_PERSPECTIVE);
+         softpipe->need_w = TRUE;
+         break;
+      case TGSI_SEMANTIC_OTHER:
          draw_emit_vertex_attr(vinfo, i, FORMAT_4F, INTERP_PERSPECTIVE);
          softpipe->need_w = TRUE;
+         break;
+
+      default:
+         assert(0);
       }
    }
 
@@ -113,12 +116,11 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe )
     * the vertex header.
     */
    if (softpipe->rasterizer->light_twoside) {
-      if (inputsRead & (1 << TGSI_ATTRIB_COLOR0)) {
+      if (front0) {
          back0 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC0,
                                        FORMAT_OMIT, colorInterp);
       }
-           
-      if (inputsRead & (1 << TGSI_ATTRIB_COLOR1)) {
+      if (back0) {
          back1 = draw_emit_vertex_attr(vinfo, TGSI_ATTRIB_BFC1,
                                        FORMAT_OMIT, colorInterp);
       }
index 20e4cf1..1320872 100755 (executable)
@@ -325,7 +325,7 @@ tgsi_build_declaration_semantic(
 {
    struct tgsi_declaration_semantic ds;
 
-   assert( semantic_name <= TGSI_SEMANTIC_COLOR );
+   assert( semantic_name <= TGSI_SEMANTIC_COUNT );
    assert( semantic_index <= 0xFFFF );
 
    ds = tgsi_default_declaration_semantic();
index e6e99d9..0a47ad2 100755 (executable)
@@ -202,13 +202,27 @@ static const char *TGSI_INTERPOLATES_SHORT[] =
 static const char *TGSI_SEMANTICS[] =
 {
    "SEMANTIC_DEPTH",
-   "SEMANTIC_COLOR"
+   "SEMANTIC_COLOR0",
+   "SEMANTIC_COLOR1",
+   "SEMANTIC_COLOR0B",
+   "SEMANTIC_COLOR1B",
+   "SEMANTIC_POSITION",
+   "SEMANTIC_FOG",
+   "SEMANTIC_OTHER,"
+   "SEMANTIC_TEX0",
 };
 
 static const char *TGSI_SEMANTICS_SHORT[] =
 {
    "DEPTH",
-   "COLOR"
+   "COLOR0",
+   "COLOR1",
+   "COLOR0B",
+   "COLOR1B",
+   "POSITION",
+   "FOG",
+   "OTHER",
+   "TEX0"
 };
 
 static const char *TGSI_IMMS[] =
index ca53071..a642ba1 100644 (file)
@@ -73,11 +73,11 @@ struct tgsi_declaration
 {
    unsigned Type        : 4;  /* TGSI_TOKEN_TYPE_DECLARATION */
    unsigned Size        : 8;  /* UINT */
-   unsigned File        : 4;  /* TGSI_FILE_ */
-   unsigned Declare     : 4;  /* TGSI_DECLARE_ */
-   unsigned UsageMask   : 4;  /* TGSI_WRITEMASK_ */
-   unsigned Interpolate : 1;  /* BOOL */
-   unsigned Semantic    : 1;  /* BOOL */
+   unsigned File        : 4;  /* one of TGSI_FILE_x */
+   unsigned Declare     : 4;  /* one of TGSI_DECLARE_x */
+   unsigned UsageMask   : 4;  /* bitmask of TGSI_WRITEMASK_x flags */
+   unsigned Interpolate : 1;  /* BOOL, any interpolation info? */
+   unsigned Semantic    : 1;  /* BOOL, any semantic info? */
    unsigned Padding     : 5;
    unsigned Extended    : 1;  /* BOOL */
 };
@@ -103,12 +103,27 @@ struct tgsi_declaration_interpolation
    unsigned Padding       : 28;
 };
 
-#define TGSI_SEMANTIC_DEPTH   0
-#define TGSI_SEMANTIC_COLOR   1
+#define TGSI_SEMANTIC_DEPTH    0
+#define TGSI_SEMANTIC_COLOR0   1
+#define TGSI_SEMANTIC_COLOR1   2
+#define TGSI_SEMANTIC_COLOR0B  3 /**< back-face primary color */
+#define TGSI_SEMANTIC_COLOR1B  4 /**< back-face secondary color */
+#define TGSI_SEMANTIC_POSITION 5
+#define TGSI_SEMANTIC_FOG      6
+#define TGSI_SEMANTIC_OTHER    7 /* XXX temp */
+#define TGSI_SEMANTIC_TEX0     8
+#define TGSI_SEMANTIC_TEX1     9
+#define TGSI_SEMANTIC_TEX2    10
+#define TGSI_SEMANTIC_TEX3    11
+#define TGSI_SEMANTIC_TEX4    12
+#define TGSI_SEMANTIC_TEX5    13
+#define TGSI_SEMANTIC_TEX6    14
+#define TGSI_SEMANTIC_TEX7    15
+#define TGSI_SEMANTIC_COUNT   16 /**< number of semantic values */
 
 struct tgsi_declaration_semantic
 {
-   unsigned SemanticName   : 8;  /* TGSI_SEMANTIC_ */
+   unsigned SemanticName   : 8;  /* one of TGSI_SEMANTIC_ */
    unsigned SemanticIndex  : 16; /* UINT */
    unsigned Padding        : 8;
 };
index 1f8d937..fb8365a 100644 (file)
@@ -3,9 +3,9 @@
 #include "pipe/tgsi/exec/tgsi_attribs.h"\r
 #include "pipe/tgsi/mesa/mesa_to_tgsi.h"\r
 \r
-#define TGSI_DEBUG 1\r
-\r
+#define TGSI_DEBUG 0\r
 \r
+#if 0\r
 /**\r
  * Convert a VERT_ATTRIB_x to a TGSI_ATTRIB_y\r
  */\r
@@ -209,9 +209,10 @@ tgsi_mesa_translate_fragment_output(GLuint attrib)
       return 0;\r
    }\r
 }\r
+#endif\r
 \r
 \r
-#if 01\r
+#if 0\r
 uint\r
 tgsi_mesa_translate_vertex_input_mask(GLbitfield mask)\r
 {\r
@@ -225,7 +226,6 @@ tgsi_mesa_translate_vertex_input_mask(GLbitfield mask)
    }\r
    return tgsiMask;\r
 }\r
-#endif\r
 \r
 uint\r
 tgsi_mesa_translate_vertex_output_mask(GLbitfield mask)\r
@@ -271,6 +271,7 @@ tgsi_mesa_translate_fragment_output_mask(GLbitfield mask)
 }\r
 \r
 \r
+#endif\r
 \r
 \r
 \r
@@ -319,12 +320,16 @@ map_register_file_index(
    GLuint processor,\r
    GLuint file,\r
    GLuint index,\r
+#if 0\r
    GLbitfield usage_bitmask,\r
+#endif\r
    const GLuint inputMapping[],\r
    const GLuint outputMapping[])\r
 {\r
    GLuint mapped_index;\r
+#if 0\r
    GLuint i;\r
+#endif\r
 \r
    assert(processor == TGSI_PROCESSOR_FRAGMENT\r
           || processor == TGSI_PROCESSOR_VERTEX);\r
@@ -345,7 +350,8 @@ map_register_file_index(
                 inputMapping[index]);\r
          return inputMapping[index];\r
       }\r
-\r
+      assert(0);\r
+#if 0\r
       assert( usage_bitmask & (1 << index) );\r
       mapped_index = 0;\r
       for( i = 0; i < index; i++ ) {\r
@@ -354,6 +360,7 @@ map_register_file_index(
          }\r
       }\r
       printf("Map %d input %d to %d\n", processor, index, mapped_index);\r
+#endif\r
       break;\r
 \r
    case TGSI_FILE_OUTPUT:\r
@@ -375,14 +382,17 @@ map_register_file_index(
       else {\r
          /* vertex output slots are tightly packed, find mapped pos */\r
          /* mapped_index = VERT_RESULT_x */\r
+#if 0\r
          mapped_index = 0;\r
          for( i = 0; i < index; i++ ) {\r
             if( usage_bitmask & (1 << i) ) {\r
                mapped_index++;\r
             }\r
          }\r
-         printf("Map VP output from %d to %d\n", index, mapped_index);\r
          assert(outputMapping[index] == mapped_index);\r
+#endif\r
+         mapped_index = outputMapping[index];\r
+         printf("Map VP output from %d to %d\n", index, mapped_index);\r
       }\r
       break;\r
 \r
@@ -452,8 +462,10 @@ static GLboolean
 compile_instruction(\r
    const struct prog_instruction *inst,\r
    struct tgsi_full_instruction *fullinst,\r
+#if 0\r
    GLuint inputs_read,\r
    GLuint outputs_written,\r
+#endif\r
    const GLuint inputMapping[],\r
    const GLuint outputMapping[],\r
    GLuint preamble_size,\r
@@ -475,8 +487,14 @@ compile_instruction(
       processor,\r
       fulldst->DstRegister.File,\r
       inst->DstReg.Index,\r
+#if 0\r
       outputs_written,\r
+#endif\r
+#if 0\r
       NULL,\r
+#else\r
+      inputMapping,\r
+#endif\r
       outputMapping\r
       );\r
    fulldst->DstRegister.WriteMask = convert_writemask( inst->DstReg.WriteMask );\r
@@ -490,7 +508,9 @@ compile_instruction(
          processor,\r
          fullsrc->SrcRegister.File,\r
          inst->SrcReg[i].Index,\r
+#if 0\r
          inputs_read,\r
+#endif\r
          inputMapping,\r
          outputMapping );\r
 \r
@@ -766,10 +786,10 @@ compile_instruction(
 \r
 static struct tgsi_full_declaration\r
 make_frag_input_decl(\r
-   GLuint first,\r
-   GLuint last,\r
+   GLuint index,\r
    GLuint interpolate,\r
-   GLuint usage_mask )\r
+   GLuint usage_mask,\r
+   GLuint semantic_name )\r
 {\r
    struct tgsi_full_declaration decl;\r
 \r
@@ -777,9 +797,11 @@ make_frag_input_decl(
    decl.Declaration.File = TGSI_FILE_INPUT;\r
    decl.Declaration.Declare = TGSI_DECLARE_RANGE;\r
    decl.Declaration.UsageMask = usage_mask;\r
+   decl.Declaration.Semantic = 1;\r
    decl.Declaration.Interpolate = 1;\r
-   decl.u.DeclarationRange.First = first;\r
-   decl.u.DeclarationRange.Last = last;\r
+   decl.u.DeclarationRange.First = index;\r
+   decl.u.DeclarationRange.Last = index;\r
+   decl.Semantic.SemanticName = semantic_name;\r
    decl.Interpolation.Interpolate = interpolate;\r
 \r
    return decl;\r
@@ -809,15 +831,20 @@ make_frag_output_decl(
 \r
 /**\r
  * Convert Mesa fragment program to TGSI format.\r
- * \param inputMapping  array to map original Mesa fragment program inputs\r
- *                      registers to TGSI generic input indexes\r
- * \param interpMode  array[FRAG_ATTRIB_x] of TGSI_INTERPOLATE_LINEAR/PERSP.\r
+ * \param inputMapping  maps Mesa fragment program inputs to TGSI generic\r
+ *                      input indexes\r
+ * \param inputSemantic  the TGSI_SEMANTIC flag for each input\r
+ * \param interpMode  the TGSI_INTERPOLATE_LINEAR/PERSP mode for each input\r
+ * \param outputMapping  maps Mesa fragment program outputs to TGSI\r
+ *                       generic outputs\r
  *\r
  */\r
 GLboolean\r
 tgsi_mesa_compile_fp_program(\r
    const struct gl_fragment_program *program,\r
+   GLuint numInputs,\r
    const GLuint inputMapping[],\r
+   const ubyte inputSemantic[],\r
    const GLuint interpMode[],\r
    const GLuint outputMapping[],\r
    struct tgsi_token *tokens,\r
@@ -831,9 +858,9 @@ tgsi_mesa_compile_fp_program(
    /*\r
    struct tgsi_full_dst_register *fulldst;\r
    struct tgsi_full_src_register *fullsrc;\r
-   */\r
    GLuint inputs_read;\r
    GLboolean reads_wpos;\r
+   */\r
    GLuint preamble_size = 0;\r
 \r
    *(struct tgsi_version *) &tokens[0] = tgsi_build_version();\r
@@ -846,6 +873,7 @@ tgsi_mesa_compile_fp_program(
 \r
    ti = 3;\r
 \r
+#if 0\r
    reads_wpos = program->Base.InputsRead & (1 << FRAG_ATTRIB_WPOS);\r
    inputs_read = program->Base.InputsRead | (1 << FRAG_ATTRIB_WPOS);\r
 \r
@@ -857,9 +885,9 @@ tgsi_mesa_compile_fp_program(
    if( reads_wpos ) {\r
       fulldecl = make_frag_input_decl(\r
          0,\r
-         0,\r
          TGSI_INTERPOLATE_CONSTANT,\r
-         TGSI_WRITEMASK_XY );\r
+         TGSI_WRITEMASK_XY,\r
+         TGSI_SEMANTIC_POSITION );\r
       ti += tgsi_build_full_declaration(\r
          &fulldecl,\r
          &tokens[ti],\r
@@ -870,9 +898,9 @@ tgsi_mesa_compile_fp_program(
    /* Fragment zw. */\r
    fulldecl = make_frag_input_decl(\r
       0,\r
-      0,\r
       TGSI_INTERPOLATE_LINEAR,\r
-      reads_wpos ? TGSI_WRITEMASK_ZW : TGSI_WRITEMASK_Z );\r
+      reads_wpos ? TGSI_WRITEMASK_ZW : TGSI_WRITEMASK_Z,\r
+      TGSI_SEMANTIC_POSITION );\r
    ti += tgsi_build_full_declaration(\r
       &fulldecl,\r
       &tokens[ti],\r
@@ -884,15 +912,55 @@ tgsi_mesa_compile_fp_program(
       if( inputs_read & (1 << i) ) {\r
          count++;\r
          fulldecl = make_frag_input_decl(count,\r
-                                         count,\r
                                          interpMode[i],\r
-                                         TGSI_WRITEMASK_XYZW );\r
+                                         TGSI_WRITEMASK_XYZW,\r
+                                         inputSemantic[count] );\r
          ti += tgsi_build_full_declaration(&fulldecl,\r
                                            &tokens[ti],\r
                                            header,\r
                                            maxTokens - ti );\r
       }\r
    }         \r
+#else\r
+\r
+   for (i = 0; i < numInputs; i++) {\r
+      switch (inputSemantic[i]) {\r
+      case TGSI_SEMANTIC_POSITION:\r
+         /* Fragment XY pos */\r
+         fulldecl = make_frag_input_decl(i,\r
+                                         TGSI_INTERPOLATE_CONSTANT,\r
+                                         TGSI_WRITEMASK_XY,\r
+                                         TGSI_SEMANTIC_POSITION );\r
+         ti += tgsi_build_full_declaration(\r
+                                           &fulldecl,\r
+                                           &tokens[ti],\r
+                                           header,\r
+                                           maxTokens - ti );\r
+         /* Fragment ZW pos */\r
+         fulldecl = make_frag_input_decl(i,\r
+                                         TGSI_INTERPOLATE_LINEAR,\r
+                                         TGSI_WRITEMASK_ZW,\r
+                                         TGSI_SEMANTIC_POSITION );\r
+         ti += tgsi_build_full_declaration(\r
+                                           &fulldecl,\r
+                                           &tokens[ti],\r
+                                           header,\r
+                                           maxTokens - ti );\r
+         break;\r
+      default:\r
+         fulldecl = make_frag_input_decl(i,\r
+                                         interpMode[i],\r
+                                         TGSI_WRITEMASK_XYZW,\r
+                                         inputSemantic[i] );\r
+         ti += tgsi_build_full_declaration(&fulldecl,\r
+                                           &tokens[ti],\r
+                                           header,\r
+                                           maxTokens - ti );\r
+         break;\r
+      }\r
+   }\r
+#endif\r
+\r
 \r
    /*\r
     * Declare output attributes.\r
@@ -914,7 +982,7 @@ tgsi_mesa_compile_fp_program(
    if( program->Base.OutputsWritten & (1 << FRAG_RESULT_COLR) ) {\r
       fulldecl = make_frag_output_decl(\r
          1,\r
-         TGSI_SEMANTIC_COLOR,\r
+         TGSI_SEMANTIC_COLOR0,\r
          TGSI_WRITEMASK_XYZW );\r
       ti += tgsi_build_full_declaration(\r
          &fulldecl,\r
@@ -956,8 +1024,10 @@ tgsi_mesa_compile_fp_program(
       if( compile_instruction(\r
             &program->Base.Instructions[i],\r
             &fullinst,\r
+#if 0\r
             inputs_read,\r
             ~0, /*outputs_written*/\r
+#endif\r
             inputMapping,\r
             outputMapping,\r
             preamble_size,\r
@@ -992,10 +1062,12 @@ tgsi_mesa_compile_vp_program(
    struct tgsi_header *header;\r
    struct tgsi_processor *processor;\r
    struct tgsi_full_instruction fullinst;\r
+#if 0\r
    GLuint inputs_read = ~0;\r
    GLuint outputs_written;\r
 \r
    outputs_written = program->Base.OutputsWritten;\r
+#endif\r
 \r
    *(struct tgsi_version *) &tokens[0] = tgsi_build_version();\r
 \r
@@ -1011,8 +1083,10 @@ tgsi_mesa_compile_vp_program(
       if( compile_instruction(\r
             &program->Base.Instructions[i],\r
             &fullinst,\r
+#if 0\r
             inputs_read,\r
             outputs_written,\r
+#endif\r
             inputMapping,\r
             outputMapping,\r
             0,\r
index 017cfce..8105e9e 100644 (file)
@@ -10,7 +10,9 @@ struct tgsi_token;
 GLboolean\r
 tgsi_mesa_compile_fp_program(\r
    const struct gl_fragment_program *program,\r
+   GLuint numInputs,\r
    const GLuint inputMapping[],\r
+   const ubyte inputSemantic[],\r
    const GLuint interpMode[],\r
    const GLuint outputMapping[],\r
    struct tgsi_token *tokens,\r
index 6dd576a..94b69c8 100644 (file)
@@ -27,6 +27,7 @@
  /*
   * Authors:
   *   Keith Whitwell <keith@tungstengraphics.com>
+  *   Brian Paul
   */
 
 #include "shader/prog_parameter.h"
 #include "st_atom.h"
 #include "st_program.h"
 
+
 #define TGSI_DEBUG 1
 
-static void compile_fs( struct st_context *st )
+
+/**
+ * Translate a Mesa fragment shader into a TGSI shader.
+ * \return  pointer to cached pipe_shader object.
+ */
+struct pipe_shader_state *
+st_translate_fragment_shader(struct st_context *st,
+                           struct st_fragment_program *stfp)
 {
-   /* Map FRAG_RESULT_COLR to output 1, map FRAG_RESULT_DEPR to output 0 */
-   static const GLuint outputMapping[2] = {1, 0};
-   struct st_fragment_program *fp = st->fp;
+   GLuint outputMapping[FRAG_RESULT_MAX];
+   GLuint inputMapping[PIPE_MAX_SHADER_INPUTS];
    struct pipe_shader_state fs;
    struct pipe_shader_state *cached;
    GLuint interpMode[16];  /* XXX size? */
    GLuint i;
+   GLbitfield inputsRead = stfp->Base.Base.InputsRead;
+
+   /* Check if all fragment programs need the fragment position (in order
+    * to do perspective-corrected interpolation).
+    */
+   if (st->pipe->get_param(st->pipe, PIPE_PARAM_FS_NEEDS_POS))
+      inputsRead |= FRAG_BIT_WPOS;
+
+   memset(&fs, 0, sizeof(fs));
 
    for (i = 0; i < 16; i++) {
-      if (fp->Base.Base.InputsRead & (1 << i)) {
-         if (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1) {
-            interpMode[i] = TGSI_INTERPOLATE_LINEAR;
+      if (inputsRead & (1 << i)) {
+         inputMapping[i] = fs.num_inputs;
+
+         switch (i) {
+         case FRAG_ATTRIB_WPOS:
+            fs.input_semantics[fs.num_inputs] = TGSI_SEMANTIC_POSITION;
+            interpMode[fs.num_inputs] = TGSI_INTERPOLATE_CONSTANT;
+            break;
+         case FRAG_ATTRIB_COL0:
+            fs.input_semantics[fs.num_inputs] = TGSI_SEMANTIC_COLOR0;
+            interpMode[fs.num_inputs] = TGSI_INTERPOLATE_LINEAR;
+            break;
+         case FRAG_ATTRIB_COL1:
+            fs.input_semantics[fs.num_inputs] = TGSI_SEMANTIC_COLOR1;
+            interpMode[fs.num_inputs] = TGSI_INTERPOLATE_LINEAR;
+            break;
+         case FRAG_ATTRIB_TEX0:
+            fs.input_semantics[fs.num_inputs] = TGSI_SEMANTIC_TEX0;
+            interpMode[fs.num_inputs] = TGSI_INTERPOLATE_PERSPECTIVE;
+            break;
+         default:
+            assert(0);
          }
-         else {
-            interpMode[i] = TGSI_INTERPOLATE_PERSPECTIVE;
+
+         fs.num_inputs++;
+      }
+   }
+
+   /*
+    * Outputs
+    */
+   for (i = 0; i < FRAG_RESULT_MAX; i++) {
+      if (stfp->Base.Base.OutputsWritten & (1 << i)) {
+         switch (i) {
+         case FRAG_RESULT_DEPR:
+            fs.output_semantics[fs.num_outputs] = TGSI_SEMANTIC_DEPTH;
+            outputMapping[i] = fs.num_outputs;
+            break;
+         case FRAG_RESULT_COLR:
+            fs.output_semantics[fs.num_outputs] = TGSI_SEMANTIC_COLOR0;
+            outputMapping[i] = fs.num_outputs;
+            break;
+         default:
+            assert(0);
          }
+         fs.num_outputs++;
       }
    }
 
    /* XXX: fix static allocation of tokens:
     */
-   tgsi_mesa_compile_fp_program( &fp->Base, NULL, interpMode,
+   tgsi_mesa_compile_fp_program( &stfp->Base,
+                                 fs.num_inputs,
+                                 inputMapping,
+                                 fs.input_semantics,
+                                 interpMode,
                                  outputMapping,
-                                 fp->tokens, ST_FP_MAX_TOKENS );
+                                 stfp->tokens, ST_FP_MAX_TOKENS );
 
-   memset(&fs, 0, sizeof(fs));
+#if 0
    fs.inputs_read
-      = tgsi_mesa_translate_fragment_input_mask(fp->Base.Base.InputsRead);
+      = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead);
+#endif
+#if 0
    fs.outputs_written
-      = tgsi_mesa_translate_fragment_output_mask(fp->Base.Base.OutputsWritten);
-   fs.tokens = &fp->tokens[0];
+      = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten);
+#endif
+
+   fs.tokens = &stfp->tokens[0];
+
    cached = st_cached_fs_state(st, &fs);
-   fp->fsx = cached;
+   stfp->fs = cached;
 
    if (TGSI_DEBUG)
-      tgsi_dump( fp->tokens, 0/*TGSI_DUMP_VERBOSE*/ );
+      tgsi_dump( stfp->tokens, 0/*TGSI_DUMP_VERBOSE*/ );
+
+   stfp->dirty = 0;
 
-   fp->dirty = 0;
+   return cached;
 }
 
 
 
 static void update_fs( struct st_context *st )
 {
-   struct st_fragment_program *fp = NULL;
+   struct st_fragment_program *stfp = NULL;
 
    /* find active shader and params.  Changes to this Mesa state
     * should be covered by ST_NEW_FRAGMENT_PROGRAM, thanks to the
@@ -101,21 +168,21 @@ static void update_fs( struct st_context *st )
        st->ctx->Shader.CurrentProgram->FragmentProgram) {
       struct gl_fragment_program *f
          = st->ctx->Shader.CurrentProgram->FragmentProgram;
-      fp = st_fragment_program(f);
+      stfp = st_fragment_program(f);
    }
    else {
       assert(st->ctx->FragmentProgram._Current);
-      fp = st_fragment_program(st->ctx->FragmentProgram._Current);
+      stfp = st_fragment_program(st->ctx->FragmentProgram._Current);
    }
 
-   /* translate shader to TGSI format */
-   if (st->fp != fp || fp->dirty) {
-      st->fp = fp;
+   /* if new binding, or shader has changed */
+   if (st->fp != stfp || stfp->dirty) {
+      /* Bind the program */
+      st->fp = stfp;
 
-      if (fp->dirty)
-        compile_fs( st );
+      if (stfp->dirty)
+        st->state.fs = st_translate_fragment_shader( st, st->fp );
 
-      st->state.fs = fp->fsx;
       st->pipe->bind_fs_state(st->pipe, st->state.fs);
    }
 }
index 322fabc..cf9dd81 100644 (file)
 #define TGSI_DEBUG 1
 
 
-
-
 /**
- * Translate Mesa shader to TGSI format 
+ * Translate a Mesa vertex shader into a TGSI shader.
+ * \return  pointer to cached pipe_shader object.
  */
-static void compile_vs( struct st_context *st )
+struct pipe_shader_state *
+st_translate_vertex_shader(struct st_context *st,
+                           struct st_vertex_program *stvp)
 {
-   struct st_vertex_program *vp = st->vp;
+   GLuint outputMapping[PIPE_MAX_SHADER_INPUTS];
    struct pipe_shader_state vs;
    struct pipe_shader_state *cached;
    GLuint i;
@@ -69,20 +70,56 @@ static void compile_vs( struct st_context *st )
     * values and TGSI generic input indexes.
     */
    for (i = 0; i < MAX_VERTEX_PROGRAM_ATTRIBS; i++) {
-      if (vp->Base.Base.InputsRead & (1 << i)) {
-         vp->input_to_index[i] = vs.num_inputs;
-         vp->index_to_input[vs.num_inputs] = i;
+      if (stvp->Base.Base.InputsRead & (1 << i)) {
+         stvp->input_to_index[i] = vs.num_inputs;
+         stvp->index_to_input[vs.num_inputs] = i;
+         switch (i) {
+         case VERT_ATTRIB_POS:
+            vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_POSITION;
+            break;
+         case VERT_ATTRIB_COLOR0:
+            vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR0;
+            break;
+         case VERT_ATTRIB_COLOR1:
+            vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR1;
+            break;
+         default:
+            vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_OTHER;
+         }
          vs.num_inputs++;
       }
    }
 
    /*
-    * Determine output register mapping.
+    * Determine number of outputs and the register mapping.
     */
    for (i = 0; i < VERT_RESULT_MAX; i++) {
-      if (vp->Base.Base.OutputsWritten & (1 << i)) {
-         vp->output_to_index[i] = vs.num_outputs;
-         vp->index_to_output[vs.num_outputs] = i;
+      if (stvp->Base.Base.OutputsWritten & (1 << i)) {
+#if 0
+         stvp->output_to_index[i] = vs.num_outputs;
+         stvp->index_to_output[vs.num_outputs] = i;
+#endif
+         outputMapping[i] = vs.num_outputs;
+
+         switch (i) {
+         case VERT_RESULT_HPOS:
+            vs.output_semantics[vs.num_outputs] = TGSI_SEMANTIC_POSITION;
+            break;
+         case VERT_RESULT_COL0:
+            vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR0;
+            break;
+         case VERT_RESULT_COL1:
+            vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR1;
+            break;
+         case VERT_RESULT_BFC0:
+            vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR0B;
+            break;
+         case VERT_RESULT_BFC1:
+            vs.input_semantics[vs.num_inputs] = TGSI_SEMANTIC_COLOR1B;
+            break;
+         default:
+            vs.output_semantics[vs.num_outputs] = TGSI_SEMANTIC_OTHER;
+         }
          vs.num_outputs++;
       }
    }
@@ -90,43 +127,50 @@ static void compile_vs( struct st_context *st )
 
    /* XXX: fix static allocation of tokens:
     */
-   tgsi_mesa_compile_vp_program( &vp->Base,
-                                 vp->input_to_index,
-                                 vp->output_to_index,
-                                 vp->tokens, ST_FP_MAX_TOKENS );
+   tgsi_mesa_compile_vp_program( &stvp->Base,
+                                 stvp->input_to_index,
+#if 0
+                                 stvp->output_to_index,
+#else
+                                 outputMapping,
+#endif
+                                 stvp->tokens, ST_FP_MAX_TOKENS );
 
-#if 01
+#if 0
    vs.inputs_read
-      = tgsi_mesa_translate_vertex_input_mask(vp->Base.Base.InputsRead);
+      = tgsi_mesa_translate_vertex_input_mask(stvp->Base.Base.InputsRead);
 #endif
+#if 0
    vs.outputs_written
-      = tgsi_mesa_translate_vertex_output_mask(vp->Base.Base.OutputsWritten);
+      = tgsi_mesa_translate_vertex_output_mask(stvp->Base.Base.OutputsWritten);
+#endif
 
-   vs.tokens = &vp->tokens[0];
+   vs.tokens = &stvp->tokens[0];
 
    cached = st_cached_vs_state(st, &vs);
-
-   vp->vs = cached;
+   stvp->vs = cached;
 
    if (TGSI_DEBUG)
-      tgsi_dump( vp->tokens, 0 );
+      tgsi_dump( stvp->tokens, 0 );
 
 #if defined(USE_X86_ASM) || defined(SLANG_X86)
-   if (vp->sse2_program.csr == vp->sse2_program.store)
-      tgsi_emit_sse2( vp->tokens, &vp->sse2_program );
+   if (stvp->sse2_program.csr == stvp->sse2_program.store)
+      tgsi_emit_sse2( stvp->tokens, &stvp->sse2_program );
 
    if (!cached->executable)
-      cached->executable = (void *) x86_get_func( &vp->sse2_program );
+      cached->executable = (void *) x86_get_func( &stvp->sse2_program );
 #endif
 
-   vp->dirty = 0;
+   stvp->dirty = 0;
+
+   return cached;
 }
 
 
 
 static void update_vs( struct st_context *st )
 {
-   struct st_vertex_program *vp;
+   struct st_vertex_program *stvp;
 
    /* find active shader and params -- Should be covered by
     * ST_NEW_VERTEX_PROGRAM
@@ -136,20 +180,20 @@ static void update_vs( struct st_context *st )
        st->ctx->Shader.CurrentProgram->VertexProgram) {
       struct gl_vertex_program *f
          = st->ctx->Shader.CurrentProgram->VertexProgram;
-      vp = st_vertex_program(f);
+      stvp = st_vertex_program(f);
    }
    else {
       assert(st->ctx->VertexProgram._Current);
-      vp = st_vertex_program(st->ctx->VertexProgram._Current);
+      stvp = st_vertex_program(st->ctx->VertexProgram._Current);
    }
 
-   if (st->vp != vp || vp->dirty) {
-      st->vp = vp;
+   if (st->vp != stvp || stvp->dirty) {
+      /* Bind the vertex program */
+      st->vp = stvp;
 
-      if (vp->dirty) 
-        compile_vs( st );
+      if (stvp->dirty) 
+        st->state.vs = st_translate_vertex_shader( st, st->vp );
 
-      st->state.vs = st->vp->vs;
       st->pipe->bind_vs_state(st->pipe, st->state.vs);
    }
 }
index 5d5efd9..ee70ce3 100644 (file)
@@ -121,11 +121,9 @@ is_depth_stencil_format(GLuint pipeFormat)
 static struct st_fragment_program *
 make_frag_shader(struct st_context *st)
 {
-   static const GLuint outputMapping[] = { 1, 0 };
    GLcontext *ctx = st->ctx;
    struct st_fragment_program *stfp;
    struct gl_program *p;
-   GLboolean b;
    GLuint interpMode[16];
    GLuint i;
 
@@ -157,11 +155,7 @@ make_frag_shader(struct st_context *st)
    p->OutputsWritten = (1 << FRAG_RESULT_COLR);
 
    stfp = (struct st_fragment_program *) p;
-   /* compile into tgsi format */
-   b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode,
-                                    outputMapping,
-                                    stfp->tokens, ST_FP_MAX_TOKENS);
-   assert(b);
+   st_translate_fragment_shader(st, stfp);
 
    return stfp;
 }
@@ -174,15 +168,9 @@ make_frag_shader(struct st_context *st)
 static struct st_vertex_program *
 make_vertex_shader(struct st_context *st)
 {
-   /* Map VERT_ATTRIB_POS to 0, VERT_ATTRIB_COLOR0 to 1 */
-   static const GLuint inputMapping[4] = { 0, 0, 0, 1 };
-   /* Map VERT_RESULT_HPOS to 0, VERT_RESULT_COL0 to 1 */
-   static const GLuint outputMapping[2] = { 0, 1 };
-
    GLcontext *ctx = st->ctx;
    struct st_vertex_program *stvp;
    struct gl_program *p;
-   GLboolean b;
 
    p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
    if (!p)
@@ -215,12 +203,8 @@ make_vertex_shader(struct st_context *st)
                         (1 << VERT_RESULT_HPOS));
 
    stvp = (struct st_vertex_program *) p;
-   /* compile into tgsi format */
-   b = tgsi_mesa_compile_vp_program(&stvp->Base,
-                                    inputMapping,
-                                    outputMapping,
-                                    stvp->tokens, ST_FP_MAX_TOKENS);
-   assert(b);
+   st_translate_vertex_shader(st, stvp);
+   assert(stvp->vs);
 
    return stvp;
 }
@@ -361,33 +345,19 @@ clear_with_quad(GLcontext *ctx,
    /* fragment shader state: color pass-through program */
    {
       static struct st_fragment_program *stfp = NULL;
-      struct pipe_shader_state fs;
-      const struct pipe_shader_state *cached;
       if (!stfp) {
          stfp = make_frag_shader(st);
       }
-      memset(&fs, 0, sizeof(fs));
-      fs.inputs_read = tgsi_mesa_translate_fragment_input_mask(stfp->Base.Base.InputsRead);
-      fs.outputs_written = tgsi_mesa_translate_fragment_output_mask(stfp->Base.Base.OutputsWritten);
-      fs.tokens = &stfp->tokens[0];
-      cached = st_cached_fs_state(st, &fs);
-      pipe->bind_fs_state(pipe, cached);
+      pipe->bind_fs_state(pipe, stfp->fs);
    }
 
    /* vertex shader state: color/position pass-through */
    {
       static struct st_vertex_program *stvp = NULL;
-      struct pipe_shader_state vs;
-      const struct pipe_shader_state *cached;
       if (!stvp) {
          stvp = make_vertex_shader(st);
       }
-      memset(&vs, 0, sizeof(vs));
-      vs.inputs_read = stvp->Base.Base.InputsRead;
-      vs.outputs_written = stvp->Base.Base.OutputsWritten;
-      vs.tokens = &stvp->tokens[0];
-      cached = st_cached_vs_state(st, &vs);
-      pipe->bind_vs_state(pipe, cached);
+      pipe->bind_vs_state(pipe, stvp->vs);
    }
 
    /* viewport state: viewport matching window dims */
@@ -522,12 +492,15 @@ clear_depth_buffer(GLcontext *ctx, struct gl_renderbuffer *rb)
 
    assert(strb->surface->format);
 
+#if 01
    if (ctx->Scissor.Enabled ||
        (isDS && ctx->DrawBuffer->Visual.stencilBits > 0)) {
       /* scissoring or we have a combined depth/stencil buffer */
       clear_with_quad(ctx, GL_FALSE, GL_TRUE, GL_FALSE);
    }
-   else {
+   else
+#endif
+ {
       /* simple clear of whole buffer */
       GLuint clearValue = depth_value(strb->surface->format, ctx->Depth.Clear);
       ctx->st->pipe->clear(ctx->st->pipe, strb->surface, clearValue);
index 0fd728c..d4f260e 100644 (file)
 static struct st_fragment_program *
 make_fragment_shader(struct st_context *st)
 {
-   static const GLuint outputMapping[2] = { 1, 0 };
    GLcontext *ctx = st->ctx;
    struct st_fragment_program *stfp;
    struct gl_program *p;
-   GLboolean b;
    GLuint interpMode[16];
    GLuint i;
 
@@ -94,11 +92,7 @@ make_fragment_shader(struct st_context *st)
    p->OutputsWritten = (1 << FRAG_RESULT_COLR);
 
    stfp = (struct st_fragment_program *) p;
-   /* compile into tgsi format */
-   b = tgsi_mesa_compile_fp_program(&stfp->Base, NULL, interpMode,
-                                    outputMapping,
-                                    stfp->tokens, ST_FP_MAX_TOKENS);
-   assert(b);
+   st_translate_fragment_shader(st, stfp);
 
    return stfp;
 }
@@ -112,11 +106,9 @@ static struct st_vertex_program *
 make_vertex_shader(struct st_context *st)
 {
    /* Map VERT_RESULT_HPOS to 0, VERT_RESULT_TEX0 to 1 */
-   static const GLuint outputMapping[] = { 0, 0, 0, 0, 1 };
    GLcontext *ctx = st->ctx;
    struct st_vertex_program *stvp;
    struct gl_program *p;
-   GLboolean b;
 
    p = ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 0);
    if (!p)
@@ -149,11 +141,7 @@ make_vertex_shader(struct st_context *st)
                         (1 << VERT_RESULT_HPOS));
 
    stvp = (struct st_vertex_program *) p;
-   /* compile into tgsi format */
-   b = tgsi_mesa_compile_vp_program(&stvp->Base, NULL,
-                                    outputMapping,
-                                    stvp->tokens, ST_FP_MAX_TOKENS);
-   assert(b);
+   st_translate_vertex_shader(st, stvp);
 
    return stvp;
 }
@@ -339,32 +327,19 @@ draw_textured_quad(GLcontext *ctx, GLint x, GLint y, GLfloat z,
    /* fragment shader state: TEX lookup program */
    {
       static struct st_fragment_program *stfp = NULL;
-      struct pipe_shader_state fs;
-      struct pipe_shader_state *cached;
       if (!stfp) {
          stfp = make_fragment_shader(ctx->st);
       }
-      memset(&fs, 0, sizeof(fs));
-      fs.inputs_read = stfp->Base.Base.InputsRead;
-      fs.tokens = &stfp->tokens[0];
-      cached = st_cached_fs_state(ctx->st, &fs);
-      pipe->bind_fs_state(pipe, cached);
+      pipe->bind_fs_state(pipe, stfp->fs);
    }
 
    /* vertex shader state: position + texcoord pass-through */
    {
       static struct st_vertex_program *stvp = NULL;
-      struct pipe_shader_state vs;
-      struct pipe_shader_state *cached;
       if (!stvp) {
          stvp = make_vertex_shader(ctx->st);
       }
-      memset(&vs, 0, sizeof(vs));
-      vs.inputs_read = stvp->Base.Base.InputsRead;
-      vs.outputs_written = stvp->Base.Base.OutputsWritten;
-      vs.tokens = &stvp->tokens[0];
-      cached = st_cached_vs_state(ctx->st, &vs);
-      pipe->bind_vs_state(pipe, cached);
+      pipe->bind_vs_state(pipe, stvp->vs);
    }
 
    /* texture sampling state: */
index 98efe1a..5245535 100644 (file)
@@ -53,6 +53,7 @@ static void
 setup_vertex_attribs(GLcontext *ctx)
 {
    struct pipe_context *pipe = ctx->st->pipe;
+#if 0
    const uint inputAttrs = ctx->st->state.vs->inputs_read;
    uint attr;
 
@@ -77,6 +78,9 @@ setup_vertex_attribs(GLcontext *ctx)
          pipe->set_vertex_element(pipe, attr, &velement);
       }
    }
+#else
+   assert(0);
+#endif
 }
 
 
@@ -84,7 +88,7 @@ static void
 setup_feedback(GLcontext *ctx)
 {
    struct pipe_context *pipe = ctx->st->pipe;
-   const uint outputAttrs = ctx->st->state.vs->outputs_written;
+   const struct pipe_shader_state *vs = ctx->st->state.vs;
    struct pipe_feedback_state feedback;
    uint i;
 
@@ -94,8 +98,8 @@ setup_feedback(GLcontext *ctx)
    feedback.discard = 1;
    feedback.num_attribs = 0;
 
-   for (i = 0; i < TGSI_ATTRIB_VAR0; i++) {
-      if ((1 << i) & outputAttrs) {
+   for (i = 0; i < vs->num_outputs; i++) {
+      if (1/***(1 << i) & outputAttrs***/) {
          feedback.attrib[feedback.num_attribs] = i;
          feedback.size[feedback.num_attribs] = 4;
          feedback.num_attribs++;
@@ -306,6 +310,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
                                                 PIPE_BUFFER_FLAG_READ);
 
    /* extract values and update rasterpos state */
+#if 0 /* XXX update */
    {
       const uint outputAttrs = ctx->st->state.vs->outputs_written;
       const float *pos, *color0, *color1, *tex0;
@@ -333,7 +338,7 @@ st_RasterPos(GLcontext *ctx, const GLfloat v[4])
 
       update_rasterpos(ctx, pos, color0, color1, tex0);
    }
-
+#endif
 
    /* free vertex feedback buffer */
    pipe->winsys->buffer_unmap(pipe->winsys, fb_buf.buffer);
index 7075db8..238ade0 100644 (file)
@@ -356,7 +356,7 @@ st_draw_vertices(GLcontext *ctx, unsigned prim,
       velement.vertex_buffer_index = 0;
       velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
       velement.dst_offset = 0;
-      pipe->set_vertex_element(pipe, attribs[i], &velement);
+      pipe->set_vertex_element(pipe, i/**attribs[i]**/, &velement);
    }
 
    /* draw */
@@ -411,7 +411,7 @@ st_feedback_draw_vbo(GLcontext *ctx,
 
 
    update_default_attribs_buffer(ctx);
-
+#if 0
    /* this must be after state validation */
    attrsNeeded = ctx->st->state.vs->inputs_read;
 
@@ -480,7 +480,9 @@ st_feedback_draw_vbo(GLcontext *ctx,
          draw_set_mapped_vertex_buffer(draw, attr, map);
       }
    }
-
+#else
+   assert(0);
+#endif
 
    if (ib) {
       unsigned indexSize;
index 68ceba4..4945141 100644 (file)
@@ -45,16 +45,15 @@ struct st_fragment_program
 {
    struct gl_fragment_program Base;
    GLboolean error;             /* If program is malformed for any reason. */
-
-   GLuint    id;               /* String id, for tracking
-                                * ProgramStringNotify changes.
-                                */
+   GLuint id; /**< String id, for tracking ProgramStringNotify changes. */
 
 
    struct tgsi_token tokens[ST_FP_MAX_TOKENS];
    GLboolean dirty;
 
-   const struct pipe_shader_state *fsx;
+   /** Pointer to the corresponding cached shader */
+   const struct pipe_shader_state *fs;
+
    GLuint param_state;
 };
 
@@ -63,16 +62,17 @@ struct st_vertex_program
 {
    struct gl_vertex_program Base;  /**< The Mesa vertex program */
    GLboolean error;        /**< Set if program is malformed for any reason. */
-
-   GLuint    id; /**< String id, for tracking ProgramStringNotify changes. */
+   GLuint id; /**< String id, for tracking ProgramStringNotify changes. */
 
    /** maps a Mesa VERT_ATTRIB_x to a packed TGSI input index */
    GLuint input_to_index[MAX_VERTEX_PROGRAM_ATTRIBS];
    /** maps a TGSI input index back to a Mesa VERT_ATTRIB_x */
    GLuint index_to_input[MAX_VERTEX_PROGRAM_ATTRIBS];
 
+#if 0
    GLuint output_to_index[MAX_VERTEX_PROGRAM_ATTRIBS];
    GLuint index_to_output[MAX_VERTEX_PROGRAM_ATTRIBS];
+#endif
 
    /** The program in TGSI format */
    struct tgsi_token tokens[ST_FP_MAX_TOKENS];
@@ -82,7 +82,9 @@ struct st_vertex_program
    struct x86_function  sse2_program;
 #endif
 
+   /** Pointer to the corresponding cached shader */
    const struct pipe_shader_state *vs;
+
    GLuint param_state;
 };
 
@@ -102,4 +104,15 @@ st_vertex_program( struct gl_vertex_program *vp )
    return (struct st_vertex_program *)vp;
 }
 
+
+extern struct pipe_shader_state *
+st_translate_fragment_shader(struct st_context *st,
+                             struct st_fragment_program *fp);
+
+
+extern struct pipe_shader_state *
+st_translate_vertex_shader(struct st_context *st,
+                           struct st_vertex_program *vp);
+
+
 #endif