Mesa (master): etnaviv: implement texture comparator

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Oct 5 20:32:02 UTC 2019


Module: Mesa
Branch: master
Commit: c877142fcaf947f4d27d975b1c7f6ae6af58ce4b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c877142fcaf947f4d27d975b1c7f6ae6af58ce4b

Author: Jonathan Marek <jonathan at marek.ca>
Date:   Thu Sep 12 16:46:02 2019 -0400

etnaviv: implement texture comparator

Signed-off-by: Jonathan Marek <jonathan at marek.ca>
Reviewed-by: Christian Gmeiner <christian.gmeiner at gmail.com>

---

 src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c |  7 +++++-
 .../drivers/etnaviv/etnaviv_compiler_nir_emit.h    |  9 +++++---
 src/gallium/drivers/etnaviv/etnaviv_screen.c       |  2 +-
 .../drivers/etnaviv/etnaviv_texture_state.c        | 12 +++++++++++
 .../drivers/etnaviv/etnaviv_texture_state.h        |  1 +
 src/gallium/drivers/etnaviv/etnaviv_translate.h    | 25 ++++++++++++++++++++++
 6 files changed, 51 insertions(+), 5 deletions(-)

diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
index bc8aac03c46..4d0466a1f4e 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c
@@ -152,6 +152,8 @@ etna_lower_io(nir_shader *shader, struct etna_shader_variant *v)
                   lod_bias = &tex->src[i].src;
                   lod_bias_idx = i;
                   break;
+               case nir_tex_src_comparator:
+                  break;
                default:
                   assert(0);
                   break;
@@ -493,7 +495,7 @@ etna_emit_alu(struct etna_compile *c, nir_op op, struct etna_inst_dst dst,
 static void
 etna_emit_tex(struct etna_compile *c, nir_texop op, unsigned texid, unsigned dst_swiz,
               struct etna_inst_dst dst, struct etna_inst_src coord,
-              struct etna_inst_src lod_bias)
+              struct etna_inst_src lod_bias, struct etna_inst_src compare)
 {
    struct etna_inst inst = {
       .dst = dst,
@@ -505,6 +507,9 @@ etna_emit_tex(struct etna_compile *c, nir_texop op, unsigned texid, unsigned dst
    if (lod_bias.use)
       inst.src[1] = lod_bias;
 
+   if (compare.use)
+      inst.src[2] = compare;
+
    switch (op) {
    case nir_texop_tex: inst.opcode = INST_OPCODE_TEXLD; break;
    case nir_texop_txb: inst.opcode = INST_OPCODE_TEXLDB; break;
diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir_emit.h b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir_emit.h
index 93e7c5170c7..9af9e4909e0 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir_emit.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir_emit.h
@@ -1054,8 +1054,7 @@ emit_tex(struct state *state, nir_tex_instr * tex)
 {
    unsigned dst_swiz;
    hw_dst dst = ra_dest(state, &tex->dest, &dst_swiz);
-   nir_src *coord = NULL;
-   nir_src *lod_bias = NULL;
+   nir_src *coord = NULL, *lod_bias = NULL, *compare = NULL;
 
    for (unsigned i = 0; i < tex->num_srcs; i++) {
       switch (tex->src[i].src_type) {
@@ -1067,6 +1066,9 @@ emit_tex(struct state *state, nir_tex_instr * tex)
          assert(!lod_bias);
          lod_bias = &tex->src[i].src;
          break;
+      case nir_tex_src_comparator:
+         compare = &tex->src[i].src;
+         break;
       default:
          assert(0);
          break;
@@ -1074,7 +1076,8 @@ emit_tex(struct state *state, nir_tex_instr * tex)
    }
 
    emit(tex, tex->op, tex->sampler_index, dst_swiz, dst, get_src(state, coord),
-        lod_bias ? get_src(state, lod_bias) : SRC_DISABLE);
+        lod_bias ? get_src(state, lod_bias) : SRC_DISABLE,
+        compare ? get_src(state, compare) : SRC_DISABLE);
 }
 
 static void
diff --git a/src/gallium/drivers/etnaviv/etnaviv_screen.c b/src/gallium/drivers/etnaviv/etnaviv_screen.c
index 9dc5ffd43c2..0e5a949ba4d 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_screen.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_screen.c
@@ -194,7 +194,7 @@ etna_screen_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
 
    /* Texturing. */
    case PIPE_CAP_TEXTURE_SHADOW_MAP:
-      return 0;
+      return DBG_ENABLED(ETNA_DBG_NIR) && screen->specs.halti >= 2;
    case PIPE_CAP_MAX_TEXTURE_2D_SIZE:
    case PIPE_CAP_MAX_TEXTURE_ARRAY_LAYERS: /* TODO: verify */
       return screen->specs.max_texture_size;
diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture_state.c b/src/gallium/drivers/etnaviv/etnaviv_texture_state.c
index 3937560b721..13cd9879a4d 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_texture_state.c
+++ b/src/gallium/drivers/etnaviv/etnaviv_texture_state.c
@@ -86,6 +86,10 @@ etna_create_sampler_state_state(struct pipe_context *pipe,
     */
    cs->max_lod_min = (ss->min_img_filter != ss->mag_img_filter) ? 1 : 0;
 
+   cs->NTE_SAMPLER_BASELOD =
+      COND(ss->compare_mode, VIVS_NTE_SAMPLER_BASELOD_COMPARE_ENABLE) |
+      VIVS_NTE_SAMPLER_BASELOD_COMPARE_FUNC(translate_texture_compare(ss->compare_func));
+
    return cs;
 }
 
@@ -365,6 +369,14 @@ etna_emit_texture_state(struct etna_context *ctx)
          }
       }
    }
+   if (unlikely(ctx->specs.halti >= 1 && (dirty & (ETNA_DIRTY_SAMPLER_VIEWS)))) {
+      for (int x = 0; x < VIVS_TE_SAMPLER__LEN; ++x) {
+         if ((1 << x) & active_samplers) {
+            struct etna_sampler_state *ss = etna_sampler_state(ctx->sampler[x]);
+            /*10700*/ EMIT_STATE(NTE_SAMPLER_BASELOD(x), ss->NTE_SAMPLER_BASELOD);
+         }
+      }
+   }
    etna_coalesce_end(stream, &coalesce);
 }
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_texture_state.h b/src/gallium/drivers/etnaviv/etnaviv_texture_state.h
index 879983b8093..df40f12ca8f 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_texture_state.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_texture_state.h
@@ -44,6 +44,7 @@ struct etna_sampler_state {
    uint32_t TE_SAMPLER_CONFIG1;
    uint32_t TE_SAMPLER_LOD_CONFIG;
    uint32_t TE_SAMPLER_3D_CONFIG;
+   uint32_t NTE_SAMPLER_BASELOD;
    unsigned min_lod, max_lod, max_lod_min;
 };
 
diff --git a/src/gallium/drivers/etnaviv/etnaviv_translate.h b/src/gallium/drivers/etnaviv/etnaviv_translate.h
index fd48c60a123..4e9b2d5249a 100644
--- a/src/gallium/drivers/etnaviv/etnaviv_translate.h
+++ b/src/gallium/drivers/etnaviv/etnaviv_translate.h
@@ -497,4 +497,29 @@ translate_texture_target(unsigned target)
    }
 }
 
+static inline uint32_t
+translate_texture_compare(enum pipe_compare_func compare_func)
+{
+   switch (compare_func) {
+   case PIPE_FUNC_NEVER:
+      return TEXTURE_COMPARE_FUNC_NEVER;
+   case PIPE_FUNC_LESS:
+      return TEXTURE_COMPARE_FUNC_LESS;
+   case PIPE_FUNC_EQUAL:
+      return TEXTURE_COMPARE_FUNC_EQUAL;
+   case PIPE_FUNC_LEQUAL:
+      return TEXTURE_COMPARE_FUNC_LEQUAL;
+   case PIPE_FUNC_GREATER:
+      return TEXTURE_COMPARE_FUNC_GREATER;
+   case PIPE_FUNC_NOTEQUAL:
+      return TEXTURE_COMPARE_FUNC_NOTEQUAL;
+   case PIPE_FUNC_GEQUAL:
+      return TEXTURE_COMPARE_FUNC_GEQUAL;
+   case PIPE_FUNC_ALWAYS:
+      return TEXTURE_COMPARE_FUNC_ALWAYS;
+   default:
+      unreachable("Invalid compare func");
+   }
+}
+
 #endif




More information about the mesa-commit mailing list