[PATCH 1/2] gallium: add TGSI_SEMANTIC_PNTCOORD

Christoph Bumiller e0425955 at student.tuwien.ac.at
Thu Mar 10 12:13:43 PST 2011


This semantic should be used to identify the PointCoord system
value which is unconditionally replaced by sprite coordinates if
point quad rasterization is enabled.

Coordinate replacement of normal texture coordinates as done with
GL_COORD_REPLACE still uses the bitfield in the rasterizer state.

Actually this is supposed to be used with TGSI_FILE_SYSTEM_VALUE
only, but that will require mesa changes as well, just like with
the FACE attribute.
---
 src/gallium/auxiliary/tgsi/tgsi_dump.c        |    3 ++-
 src/gallium/drivers/llvmpipe/lp_setup_point.c |   25 +++++++++++++++++--------
 src/gallium/drivers/nv50/nv50_shader_state.c  |   12 +++++++-----
 src/gallium/drivers/nvc0/nvc0_program.c       |    6 +-----
 src/gallium/drivers/r600/r600_state_common.c  |   17 ++++++++++++++---
 src/gallium/include/pipe/p_shader_tokens.h    |    3 ++-
 src/mesa/state_tracker/st_atom_rasterizer.c   |    4 ----
 src/mesa/state_tracker/st_program.c           |    9 +++++----
 8 files changed, 48 insertions(+), 31 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c
index c126620..95c947e 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_dump.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c
@@ -128,7 +128,8 @@ static const char *semantic_names[] =
    "EDGEFLAG",
    "PRIM_ID",
    "INSTANCEID",
-   "STENCIL"
+   "STENCIL",
+   "PNTCOORD"
 };
 
 static const char *immediate_type_names[] =
diff --git a/src/gallium/drivers/llvmpipe/lp_setup_point.c b/src/gallium/drivers/llvmpipe/lp_setup_point.c
index 146f1bd..4b81374 100644
--- a/src/gallium/drivers/llvmpipe/lp_setup_point.c
+++ b/src/gallium/drivers/llvmpipe/lp_setup_point.c
@@ -218,6 +218,7 @@ setup_point_coefficients( struct lp_setup_context *setup,
       unsigned usage_mask = key->inputs[slot].usage_mask;
       enum lp_interp interp = key->inputs[slot].interp;
       boolean perspective = !!(interp == LP_INTERP_PERSPECTIVE);
+      boolean sprite_coord;
       unsigned i;
 
       if (perspective & usage_mask) {
@@ -241,22 +242,30 @@ setup_point_coefficients( struct lp_setup_context *setup,
          /* check if the sprite coord flag is set for this attribute.
           * If so, set it up so it up so x and y vary from 0 to 1.
           */
+         if (shader->info.base.input_semantic_name[slot] == TGSI_SEMANTIC_PNTCOORD) {
+            sprite_coord = TRUE;
+         } else
          if (shader->info.base.input_semantic_name[slot] == TGSI_SEMANTIC_GENERIC) {
             unsigned semantic_index = shader->info.base.input_semantic_index[slot];
             /* Note that sprite_coord enable is a bitfield of
              * PIPE_MAX_SHADER_OUTPUTS bits.
              */
             if (semantic_index < PIPE_MAX_SHADER_OUTPUTS &&
-                (setup->sprite_coord_enable & (1 << semantic_index))) {
-               for (i = 0; i < NUM_CHANNELS; i++) {
-                  if (usage_mask & (1 << i)) {
-                     texcoord_coef(setup, info, slot + 1, i,
-                                   setup->sprite_coord_origin,
-                                   perspective);
-                  }
+                (setup->sprite_coord_enable & (1 << semantic_index)))
+               sprite_coord = TRUE;
+         } else {
+            sprite_coord = FALSE;
+         }
+
+         if (sprite_coord) {
+            for (i = 0; i < NUM_CHANNELS; i++) {
+               if (usage_mask & (1 << i)) {
+                  texcoord_coef(setup, info, slot + 1, i,
+                                setup->sprite_coord_origin,
+                                perspective);
                }
-               break;
             }
+            break;
          }
          /* fall-through */
       case LP_INTERP_CONSTANT:
diff --git a/src/gallium/drivers/nv50/nv50_shader_state.c b/src/gallium/drivers/nv50/nv50_shader_state.c
index bea9c09..ce0b3ad 100644
--- a/src/gallium/drivers/nv50/nv50_shader_state.c
+++ b/src/gallium/drivers/nv50/nv50_shader_state.c
@@ -253,11 +253,13 @@ nv50_sprite_coords_validate(struct nv50_context *nv50)
    for (i = 0; i < fp->in_nr; i++) {
       unsigned n = util_bitcount(fp->in[i].mask);
 
-      if (fp->in[i].sn != TGSI_SEMANTIC_GENERIC) {
-         m += n;
-         continue;
-      }
-      if (!(nv50->rast->pipe.sprite_coord_enable & (1 << fp->in[i].si))) {
+      if (fp->in[i].sn == TGSI_SEMANTIC_GENERIC) {
+         if (!(nv50->rast->pipe.sprite_coord_enable & (1 << fp->in[i].si))) {
+            m += n;
+            continue;
+         }
+      } else
+      if (fp->in[i].sn != TGSI_SEMANTIC_PNTCOORD) {
          m += n;
          continue;
       }
diff --git a/src/gallium/drivers/nvc0/nvc0_program.c b/src/gallium/drivers/nvc0/nvc0_program.c
index 975745a..3cee2ce 100644
--- a/src/gallium/drivers/nvc0/nvc0_program.c
+++ b/src/gallium/drivers/nvc0/nvc0_program.c
@@ -180,10 +180,8 @@ nvc0_varying_location(unsigned sn, unsigned si)
       return 0x270;
    case TGSI_SEMANTIC_PSIZE:
       return 0x6c;
-      /*
-   case TGSI_SEMANTIC_PNTC:
+   case TGSI_SEMANTIC_PNTCOORD:
       return 0x2e0;
-      */
    case TGSI_SEMANTIC_GENERIC:
       /* We'd really like to distinguish between TEXCOORD and GENERIC here,
        * since only 0x300 to 0x37c can be replaced by sprite coordinates.
@@ -193,8 +191,6 @@ nvc0_varying_location(unsigned sn, unsigned si)
       assert(si < 31);
       if (si <= 7)
          return 0x300 + si * 16;
-      if (si == 9)
-         return 0x2e0;
       return 0x80 + ((si - 8) * 16);
    case TGSI_SEMANTIC_NORMAL:
       return 0x360;
diff --git a/src/gallium/drivers/r600/r600_state_common.c b/src/gallium/drivers/r600/r600_state_common.c
index 43dad0c..231aea7 100644
--- a/src/gallium/drivers/r600/r600_state_common.c
+++ b/src/gallium/drivers/r600/r600_state_common.c
@@ -276,6 +276,19 @@ void r600_delete_vs_shader(struct pipe_context *ctx, void *state)
 	free(shader);
 }
 
+static INLINE boolean
+r600_ps_input_is_sprite_coord(struct r600_pipe_context *rctx,
+			      unsigned i)
+{
+	struct r600_shader *rshader = &rctx->ps_shader->shader;
+
+	if (rshader->input[i].name == TGSI_SEMANTIC_GENERIC)
+		return (rctx->sprite_coord_enable &
+			(1 << rshader->input[i].sid)) ? TRUE : FALSE;
+
+	return rshader->input[i].name == TGSI_SEMANTIC_PNTCOORD;
+}
+
 /* FIXME optimize away spi update when it's not needed */
 void r600_spi_update(struct r600_pipe_context *rctx)
 {
@@ -294,10 +307,8 @@ void r600_spi_update(struct r600_pipe_context *rctx)
 			tmp |= S_028644_FLAT_SHADE(rctx->flatshade);
 		}
 
-		if (rshader->input[i].name == TGSI_SEMANTIC_GENERIC &&
-		    rctx->sprite_coord_enable & (1 << rshader->input[i].sid)) {
+		if (r600_ps_input_is_sprite_coord(rctx, i))
 			tmp |= S_028644_PT_SPRITE_TEX(1);
-		}
 
 		if (rctx->family < CHIP_CEDAR) {
 			if (rshader->input[i].centroid)
diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h
index d3a3632..af2e8e1 100644
--- a/src/gallium/include/pipe/p_shader_tokens.h
+++ b/src/gallium/include/pipe/p_shader_tokens.h
@@ -145,7 +145,8 @@ struct tgsi_declaration_dimension
 #define TGSI_SEMANTIC_PRIMID     9
 #define TGSI_SEMANTIC_INSTANCEID 10
 #define TGSI_SEMANTIC_STENCIL    11
-#define TGSI_SEMANTIC_COUNT      12 /**< number of semantic values */
+#define TGSI_SEMANTIC_PNTCOORD   12
+#define TGSI_SEMANTIC_COUNT      13 /**< number of semantic values */
 
 struct tgsi_declaration_semantic
 {
diff --git a/src/mesa/state_tracker/st_atom_rasterizer.c b/src/mesa/state_tracker/st_atom_rasterizer.c
index 8bcccee..2747b6d 100644
--- a/src/mesa/state_tracker/st_atom_rasterizer.c
+++ b/src/mesa/state_tracker/st_atom_rasterizer.c
@@ -196,10 +196,6 @@ static void update_raster_state( struct st_context *st )
             raster->sprite_coord_enable |= 1 << i;
          }
       }
-      if (fragProg->Base.InputsRead & FRAG_BIT_PNTC) {
-         raster->sprite_coord_enable |=
-            1 << (FRAG_ATTRIB_PNTC - FRAG_ATTRIB_TEX0);
-      }
 
       raster->point_quad_rasterization = 1;
    }
diff --git a/src/mesa/state_tracker/st_program.c b/src/mesa/state_tracker/st_program.c
index fc1dfb3..2b2448f 100644
--- a/src/mesa/state_tracker/st_program.c
+++ b/src/mesa/state_tracker/st_program.c
@@ -516,6 +516,10 @@ st_translate_fragment_program(struct st_context *st,
                 * should be building tables based on semantic index.
                 */
             case FRAG_ATTRIB_PNTC:
+               input_semantic_name[slot] = TGSI_SEMANTIC_PNTCOORD;
+               input_semantic_index[slot] = 0;
+               interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
+               break;
             case FRAG_ATTRIB_TEX0:
             case FRAG_ATTRIB_TEX1:
             case FRAG_ATTRIB_TEX2:
@@ -532,10 +536,7 @@ 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;
-               if (attr == FRAG_ATTRIB_PNTC)
-                  interpMode[slot] = TGSI_INTERPOLATE_LINEAR;
-               else
-                  interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
+               interpMode[slot] = TGSI_INTERPOLATE_PERSPECTIVE;
                break;
             }
          }
-- 
1.7.3.4


--------------010003000105040609030407--


More information about the mesa-dev mailing list