Mesa (main): svga: add need_texcoord_semantic to tgsi_add_point_sprite & tgsi_add_aa_point

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu May 19 17:56:40 UTC 2022


Module: Mesa
Branch: main
Commit: 8cbcdb4f10a4146123c8bbb8cf16fbb2a3f794a7
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=8cbcdb4f10a4146123c8bbb8cf16fbb2a3f794a7

Author: Charmaine Lee <charmainel at vmware.com>
Date:   Tue May 17 17:20:53 2022 -0700

svga: add need_texcoord_semantic to tgsi_add_point_sprite & tgsi_add_aa_point

Since PIPE_CAP_TGSI_TEXCOORD is now set in SVGA vgpu10 driver,
we need to add a new parameter need_texcoord_semantic to
tgsi_add_point_sprite and tgsi_add_aa_point
to allow setting texcoords using tgsi texcoord semantic.

Reviewed-by: Neha Bhende <bhenden at vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16598>

---

 src/gallium/auxiliary/tgsi/tgsi_aa_point.c         | 16 ++++++--
 src/gallium/auxiliary/tgsi/tgsi_aa_point.h         |  3 +-
 src/gallium/auxiliary/tgsi/tgsi_point_sprite.c     | 43 ++++++++++++++++------
 src/gallium/auxiliary/tgsi/tgsi_point_sprite.h     |  1 +
 src/gallium/drivers/svga/svga_link.c               |  5 +++
 .../drivers/svga/svga_state_tgsi_transform.c       |  6 +++
 src/gallium/drivers/svga/svga_tgsi_vgpu10.c        | 11 ++++--
 7 files changed, 67 insertions(+), 18 deletions(-)

diff --git a/src/gallium/auxiliary/tgsi/tgsi_aa_point.c b/src/gallium/auxiliary/tgsi/tgsi_aa_point.c
index 58f610fc485..ace4d9a104b 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_aa_point.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_aa_point.c
@@ -47,6 +47,7 @@ struct aa_transform_context
    unsigned num_imm;       // number of immediates
    unsigned num_input;     // number of inputs
    unsigned aa_point_coord_index;
+   bool need_texcoord_semantic;
 };
 
 static inline struct aa_transform_context *
@@ -113,8 +114,15 @@ aa_prolog(struct tgsi_transform_context *ctx)
 
    /* Declare new generic input/texcoord */
    texIn = ts->num_input++;
-   tgsi_transform_input_decl(ctx, texIn, TGSI_SEMANTIC_GENERIC,
-                             ts->aa_point_coord_index, TGSI_INTERPOLATE_LINEAR);
+   if (ts->need_texcoord_semantic) {
+      tgsi_transform_input_decl(ctx, texIn, TGSI_SEMANTIC_TEXCOORD,
+                                ts->aa_point_coord_index,
+                                TGSI_INTERPOLATE_LINEAR);
+   } else {
+      tgsi_transform_input_decl(ctx, texIn, TGSI_SEMANTIC_GENERIC,
+                                ts->aa_point_coord_index,
+                                TGSI_INTERPOLATE_LINEAR);
+   }
 
    /* Declare extra immediates */
    imm = ts->num_imm++;
@@ -271,7 +279,8 @@ aa_epilog(struct tgsi_transform_context *ctx)
  */
 struct tgsi_token *
 tgsi_add_aa_point(const struct tgsi_token *tokens_in,
-                  const int aa_point_coord_index)
+                  const int aa_point_coord_index,
+                  const bool need_texcoord_semantic)
 {
    struct aa_transform_context transform;
    const uint num_new_tokens = 200; /* should be enough */
@@ -291,6 +300,7 @@ tgsi_add_aa_point(const struct tgsi_token *tokens_in,
 
    assert(aa_point_coord_index != -1);
    transform.aa_point_coord_index = (unsigned)aa_point_coord_index;
+   transform.need_texcoord_semantic = need_texcoord_semantic;
 
    transform.num_tmp = 0;
    transform.num_imm = 0;
diff --git a/src/gallium/auxiliary/tgsi/tgsi_aa_point.h b/src/gallium/auxiliary/tgsi/tgsi_aa_point.h
index d89f40cc389..160bc037530 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_aa_point.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_aa_point.h
@@ -30,6 +30,7 @@ struct tgsi_token;
 
 struct tgsi_token *
 tgsi_add_aa_point(const struct tgsi_token *tokens_in,
-                  const int aa_point_coord_index);
+                  const int aa_point_coord_index,
+                  const bool need_texcoord_semantic);
 
 #endif /* TGSI_AA_POINT_H */
diff --git a/src/gallium/auxiliary/tgsi/tgsi_point_sprite.c b/src/gallium/auxiliary/tgsi/tgsi_point_sprite.c
index 432a137fcd7..eb17a1be07d 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_point_sprite.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_point_sprite.c
@@ -95,6 +95,7 @@ struct psprite_transform_context
    unsigned point_coord_k;          // aa point coord threshold distance
    unsigned stream_out_point_pos:1; // set if to stream out original point pos
    unsigned aa_point:1;             // set if doing aa point
+   unsigned need_texcoord_semantic:1;   // set if need texcoord semantic
    unsigned out_tmp_index[PIPE_MAX_SHADER_OUTPUTS];
    int max_generic;                 // max generic semantic index
 };
@@ -131,11 +132,16 @@ psprite_decl(struct tgsi_transform_context *ctx,
       else if (decl->Semantic.Name == TGSI_SEMANTIC_POSITION) {
          ts->point_pos_out = decl->Range.First;
       }
-      else if (decl->Semantic.Name == TGSI_SEMANTIC_GENERIC &&
+      else if (!ts->need_texcoord_semantic &&
+	       decl->Semantic.Name == TGSI_SEMANTIC_GENERIC &&
                decl->Semantic.Index < 32) {
          ts->point_coord_decl |= 1 << decl->Semantic.Index;
          ts->max_generic = MAX2(ts->max_generic, (int)decl->Semantic.Index);
       }
+      else if (ts->need_texcoord_semantic &&
+               decl->Semantic.Name == TGSI_SEMANTIC_TEXCOORD) {
+         ts->point_coord_decl |= 1 << decl->Semantic.Index;
+      }
       ts->num_out = MAX2(ts->num_out, range_end);
    }
    else if (decl->Declaration.File == TGSI_FILE_TEMPORARY) {
@@ -213,22 +219,35 @@ psprite_prolog(struct tgsi_transform_context *ctx)
     */
    ts->point_coord_out = ts->num_out;
    if (point_coord_enable) {
-      for (i = 0, en = point_coord_enable; en; en>>=1, i++) {
-         if (en & 0x1) {
-            tgsi_transform_output_decl(ctx, ts->num_out++,
-                                       TGSI_SEMANTIC_GENERIC, i, 0);
-            ts->max_generic = MAX2(ts->max_generic, (int)i);
+      if (ts->need_texcoord_semantic) {
+         for (i = 0, en = point_coord_enable; en; en>>=1, i++) {
+            if (en & 0x1) {
+               tgsi_transform_output_decl(ctx, ts->num_out++,
+                                          TGSI_SEMANTIC_TEXCOORD, i, 0);
+            }
+         }
+      } else {
+         for (i = 0, en = point_coord_enable; en; en>>=1, i++) {
+            if (en & 0x1) {
+               tgsi_transform_output_decl(ctx, ts->num_out++,
+                                          TGSI_SEMANTIC_GENERIC, i, 0);
+               ts->max_generic = MAX2(ts->max_generic, (int)i);
+            }
          }
       }
    }
 
    /* add an extra generic output for aa point texcoord */
    if (ts->aa_point) {
-      ts->point_coord_aa = ts->max_generic + 1;
-      assert((ts->point_coord_enable & (1 << ts->point_coord_aa)) == 0);
-      ts->point_coord_enable |= 1 << (ts->point_coord_aa);
-      tgsi_transform_output_decl(ctx, ts->num_out++, TGSI_SEMANTIC_GENERIC,
-                                 ts->point_coord_aa, 0);
+      if (ts->need_texcoord_semantic) {
+         ts->point_coord_aa = 0;
+      } else {
+         ts->point_coord_aa = ts->max_generic + 1;
+         assert((ts->point_coord_enable & (1 << ts->point_coord_aa)) == 0);
+         ts->point_coord_enable |= 1 << (ts->point_coord_aa);
+         tgsi_transform_output_decl(ctx, ts->num_out++, TGSI_SEMANTIC_GENERIC,
+                                    ts->point_coord_aa, 0);
+      }
    }
 
    /* Declare extra immediates */
@@ -503,6 +522,7 @@ tgsi_add_point_sprite(const struct tgsi_token *tokens_in,
                       const unsigned point_coord_enable,
                       const bool sprite_origin_lower_left,
                       const bool stream_out_point_pos,
+		      const bool need_texcoord_semantic,
                       int *aa_point_coord_index)
 {
    struct psprite_transform_context transform;
@@ -533,6 +553,7 @@ tgsi_add_point_sprite(const struct tgsi_token *tokens_in,
    transform.stream_out_point_pos = stream_out_point_pos;
    transform.point_coord_enable = point_coord_enable;
    transform.aa_point = aa_point_coord_index != NULL;
+   transform.need_texcoord_semantic = need_texcoord_semantic;
    transform.max_generic = -1;
 
    /* point sprite directions based on the immediates (0, 1, 0.5, -1) */
diff --git a/src/gallium/auxiliary/tgsi/tgsi_point_sprite.h b/src/gallium/auxiliary/tgsi/tgsi_point_sprite.h
index d1958914bc3..46e769c0c12 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_point_sprite.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_point_sprite.h
@@ -33,6 +33,7 @@ tgsi_add_point_sprite(const struct tgsi_token *tokens_in,
                       const unsigned point_coord_enable,
                       const bool sprite_origin_lower_left,
                       const bool stream_out_point_pos,
+                      const bool need_texcoord_semantic,
                       int *aa_point_coord_index);
 
 #endif /* TGSI_POINT_SPRITE_H */
diff --git a/src/gallium/drivers/svga/svga_link.c b/src/gallium/drivers/svga/svga_link.c
index 394040d9303..588f1c23113 100644
--- a/src/gallium/drivers/svga/svga_link.c
+++ b/src/gallium/drivers/svga/svga_link.c
@@ -71,6 +71,11 @@ svga_link_shaders(const struct tgsi_shader_info *outshader_info,
       unsigned j;
       unsigned out_index;
 
+      if (sem_name == TGSI_SEMANTIC_PCOORD) {
+         sem_name = TGSI_SEMANTIC_TEXCOORD;
+         sem_index = 0;
+      }
+
       /* search output shader outputs for same item */
       for (j = 0; j < outshader_info->num_outputs; j++) {
          assert(j < ARRAY_SIZE(outshader_info->output_semantic_name));
diff --git a/src/gallium/drivers/svga/svga_state_tgsi_transform.c b/src/gallium/drivers/svga/svga_state_tgsi_transform.c
index 5e7069fe152..8974cd93bb1 100644
--- a/src/gallium/drivers/svga/svga_state_tgsi_transform.c
+++ b/src/gallium/drivers/svga/svga_state_tgsi_transform.c
@@ -241,6 +241,9 @@ emulate_point_sprite(struct svga_context *svga,
    struct svga_stream_output *streamout = NULL;
    int pos_out_index = -1;
    int aa_point_coord_index = -1;
+   struct pipe_screen *screen = svga->pipe.screen;
+   bool has_texcoord_semantic =
+      screen->get_param(screen, PIPE_CAP_TGSI_TEXCOORD);
 
    assert(tokens != NULL);
 
@@ -250,6 +253,8 @@ emulate_point_sprite(struct svga_context *svga,
    memset(&key, 0, sizeof key);
    key.gs.writes_psize = 1;
    key.gs.sprite_coord_enable = svga->curr.rast->templ.sprite_coord_enable;
+   if (has_texcoord_semantic)
+      key.gs.sprite_coord_enable |= 0x1;   /* For TGSI_SEMANTIC_PCOORD */
 
    key.gs.sprite_origin_upper_left =
       !(svga->curr.rast->templ.sprite_coord_mode == PIPE_SPRITE_COORD_LOWER_LEFT);
@@ -284,6 +289,7 @@ emulate_point_sprite(struct svga_context *svga,
                                          key.gs.sprite_coord_enable,
                                          key.gs.sprite_origin_upper_left,
                                          key.gs.point_pos_stream_out,
+					 has_texcoord_semantic,
                                          key.gs.aa_point ?
                                             &aa_point_coord_index : NULL);
 
diff --git a/src/gallium/drivers/svga/svga_tgsi_vgpu10.c b/src/gallium/drivers/svga/svga_tgsi_vgpu10.c
index b8499df59e4..07f2857dd47 100644
--- a/src/gallium/drivers/svga/svga_tgsi_vgpu10.c
+++ b/src/gallium/drivers/svga/svga_tgsi_vgpu10.c
@@ -12694,14 +12694,18 @@ transform_fs_pstipple(struct svga_shader_emitter_v10 *emit,
  * Modify the FS to support anti-aliasing point.
  */
 static const struct tgsi_token *
-transform_fs_aapoint(const struct tgsi_token *tokens,
+transform_fs_aapoint(struct svga_context *svga,
+		     const struct tgsi_token *tokens,
                      int aa_coord_index)
 {
+   bool need_texcoord_semantic =
+      svga->pipe.screen->get_param(svga->pipe.screen, PIPE_CAP_TGSI_TEXCOORD);
+
    if (0) {
       debug_printf("Before tgsi_add_aa_point ------------------\n");
       tgsi_dump(tokens,0);
    }
-   tokens = tgsi_add_aa_point(tokens, aa_coord_index);
+   tokens = tgsi_add_aa_point(tokens, aa_coord_index, need_texcoord_semantic);
    if (0) {
       debug_printf("After tgsi_add_aa_point ------------------\n");
       tgsi_dump(tokens, 0);
@@ -12961,7 +12965,8 @@ svga_tgsi_vgpu10_translate(struct svga_context *svga,
          tokens = new_tokens;
       }
       if (key->fs.aa_point) {
-         tokens = transform_fs_aapoint(tokens, key->fs.aa_point_coord_index);
+         tokens = transform_fs_aapoint(svga, tokens,
+			               key->fs.aa_point_coord_index);
       }
    }
 



More information about the mesa-commit mailing list