Mesa (main): intel/fs: Use compare_func for wm_prog_key::alpha_test_func

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jan 14 15:34:29 UTC 2022


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

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Thu Dec  9 18:21:14 2021 -0600

intel/fs: Use compare_func for wm_prog_key::alpha_test_func

Because 0 is no longer a recognizable value (it's NEVER, which isn't a
good default), we add an emit_alpha_test bool to tell the back-end when
to bother alpha testing.  This lets us only touch crocus with the
change.

Reviewed-by: Caio Oliveira <caio.oliveira at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14157>

---

 src/gallium/drivers/crocus/crocus_state.c | 19 ++---------------
 src/intel/compiler/brw_compiler.h         |  3 ++-
 src/intel/compiler/brw_fs.cpp             |  4 ++--
 src/intel/compiler/brw_fs_visitor.cpp     | 34 +++++++++++++++----------------
 4 files changed, 23 insertions(+), 37 deletions(-)

diff --git a/src/gallium/drivers/crocus/crocus_state.c b/src/gallium/drivers/crocus/crocus_state.c
index 5d5034db447..f8b6fdcfe09 100644
--- a/src/gallium/drivers/crocus/crocus_state.c
+++ b/src/gallium/drivers/crocus/crocus_state.c
@@ -4751,22 +4751,6 @@ crocus_populate_gs_key(const struct crocus_context *ice,
       key->nr_userclip_plane_consts = cso_rast->num_clip_plane_consts;
 }
 
-static inline GLenum
-compare_func_to_gl(enum pipe_compare_func pipe_func)
-{
-   static const unsigned map[] = {
-      [PIPE_FUNC_NEVER]    = GL_NEVER,
-      [PIPE_FUNC_LESS]     = GL_LESS,
-      [PIPE_FUNC_EQUAL]    = GL_EQUAL,
-      [PIPE_FUNC_LEQUAL]   = GL_LEQUAL,
-      [PIPE_FUNC_GREATER]  = GL_GREATER,
-      [PIPE_FUNC_NOTEQUAL] = GL_NOTEQUAL,
-      [PIPE_FUNC_GEQUAL]   = GL_GEQUAL,
-      [PIPE_FUNC_ALWAYS]   = GL_ALWAYS,
-   };
-   return map[pipe_func];
-}
-
 /**
  * Populate FS program key fields based on the current state.
  */
@@ -4851,7 +4835,8 @@ crocus_populate_fs_key(const struct crocus_context *ice,
 
 #if GFX_VER <= 5
    if (fb->nr_cbufs > 1 && zsa->cso.alpha_enabled) {
-      key->alpha_test_func = compare_func_to_gl(zsa->cso.alpha_func);
+      key->emit_alpha_test = true;
+      key->alpha_test_func = zsa->cso.alpha_func;
       key->alpha_test_ref = zsa->cso.alpha_ref_value;
    }
 #endif
diff --git a/src/intel/compiler/brw_compiler.h b/src/intel/compiler/brw_compiler.h
index 73290976f3b..481c5d80ba1 100644
--- a/src/intel/compiler/brw_compiler.h
+++ b/src/intel/compiler/brw_compiler.h
@@ -486,6 +486,8 @@ struct brw_wm_prog_key {
    bool stats_wm:1;
    bool flat_shade:1;
    unsigned nr_color_regions:5;
+   bool emit_alpha_test:1;
+   enum compare_func alpha_test_func:3; /* < For Gfx4/5 MRT alpha test */
    bool alpha_test_replicate_alpha:1;
    bool alpha_to_coverage:1;
    bool clamp_fragment_color:1;
@@ -499,7 +501,6 @@ struct brw_wm_prog_key {
 
    uint8_t color_outputs_valid;
    uint64_t input_slots_valid;
-   GLenum alpha_test_func;          /* < For Gfx4/5 MRT alpha test */
    float alpha_test_ref;
 };
 
diff --git a/src/intel/compiler/brw_fs.cpp b/src/intel/compiler/brw_fs.cpp
index f49bf8f35fd..340fcd6203f 100644
--- a/src/intel/compiler/brw_fs.cpp
+++ b/src/intel/compiler/brw_fs.cpp
@@ -9081,7 +9081,7 @@ fs_visitor::run_fs(bool allow_spilling, bool do_rep_send)
       if (failed)
 	 return false;
 
-      if (wm_key->alpha_test_func)
+      if (wm_key->emit_alpha_test)
          emit_alpha_test();
 
       emit_fb_writes();
@@ -9506,7 +9506,7 @@ brw_nir_populate_wm_prog_data(const nir_shader *shader,
     * so the shader definitely kills pixels.
     */
    prog_data->uses_kill = shader->info.fs.uses_discard ||
-      key->alpha_test_func;
+      key->emit_alpha_test;
    prog_data->uses_omask = !key->ignore_sample_mask_out &&
       (shader->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK));
    prog_data->computed_depth_mode = computed_depth_mode(shader);
diff --git a/src/intel/compiler/brw_fs_visitor.cpp b/src/intel/compiler/brw_fs_visitor.cpp
index 9405eec6871..e19f487a7ce 100644
--- a/src/intel/compiler/brw_fs_visitor.cpp
+++ b/src/intel/compiler/brw_fs_visitor.cpp
@@ -559,23 +559,23 @@ fs_visitor::emit_interpolation_setup_gfx6()
 }
 
 static enum brw_conditional_mod
-cond_for_alpha_func(GLenum func)
+cond_for_alpha_func(enum compare_func func)
 {
    switch(func) {
-      case GL_GREATER:
-         return BRW_CONDITIONAL_G;
-      case GL_GEQUAL:
-         return BRW_CONDITIONAL_GE;
-      case GL_LESS:
-         return BRW_CONDITIONAL_L;
-      case GL_LEQUAL:
-         return BRW_CONDITIONAL_LE;
-      case GL_EQUAL:
-         return BRW_CONDITIONAL_EQ;
-      case GL_NOTEQUAL:
-         return BRW_CONDITIONAL_NEQ;
-      default:
-         unreachable("Not reached");
+   case COMPARE_FUNC_GREATER:
+      return BRW_CONDITIONAL_G;
+   case COMPARE_FUNC_GEQUAL:
+      return BRW_CONDITIONAL_GE;
+   case COMPARE_FUNC_LESS:
+      return BRW_CONDITIONAL_L;
+   case COMPARE_FUNC_LEQUAL:
+      return BRW_CONDITIONAL_LE;
+   case COMPARE_FUNC_EQUAL:
+      return BRW_CONDITIONAL_EQ;
+   case COMPARE_FUNC_NOTEQUAL:
+      return BRW_CONDITIONAL_NEQ;
+   default:
+      unreachable("Not reached");
    }
 }
 
@@ -591,10 +591,10 @@ fs_visitor::emit_alpha_test()
    const fs_builder abld = bld.annotate("Alpha test");
 
    fs_inst *cmp;
-   if (key->alpha_test_func == GL_ALWAYS)
+   if (key->alpha_test_func == COMPARE_FUNC_ALWAYS)
       return;
 
-   if (key->alpha_test_func == GL_NEVER) {
+   if (key->alpha_test_func == COMPARE_FUNC_NEVER) {
       /* f0.1 = 0 */
       fs_reg some_reg = fs_reg(retype(brw_vec8_grf(0, 0),
                                       BRW_REGISTER_TYPE_UW));



More information about the mesa-commit mailing list