Mesa (master): panfrost: Implement alpha testing natively

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jan 13 16:13:06 UTC 2021


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

Author: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Date:   Tue Jan 12 11:44:43 2021 -0500

panfrost: Implement alpha testing natively

On Midgard, we still have to lower on v6+. Passes Piglit
./fbo-mrt-alphatest (saving a cycle in the fragment shader to
compare/discard).

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8447>

---

 src/gallium/drivers/panfrost/pan_cmdstream.c | 6 +++++-
 src/gallium/drivers/panfrost/pan_context.c   | 5 +++--
 src/gallium/drivers/panfrost/pan_context.h   | 1 +
 src/gallium/drivers/panfrost/pan_screen.c    | 3 +++
 4 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c
index a4b90332171..9922c76e29d 100644
--- a/src/gallium/drivers/panfrost/pan_cmdstream.c
+++ b/src/gallium/drivers/panfrost/pan_cmdstream.c
@@ -542,7 +542,7 @@ panfrost_prepare_fs_state(struct panfrost_context *ctx,
         state->stencil_mask_misc.stencil_mask_back = zsa->stencil_mask_back;
         state->stencil_mask_misc.stencil_enable = zsa->base.stencil[0].enabled;
         state->stencil_mask_misc.alpha_to_coverage = alpha_to_coverage;
-        state->stencil_mask_misc.alpha_test_compare_function = MALI_FUNC_ALWAYS;
+        state->stencil_mask_misc.alpha_test_compare_function = zsa->alpha_func;
         state->stencil_mask_misc.depth_range_1 = rast->offset_tri;
         state->stencil_mask_misc.depth_range_2 = rast->offset_tri;
         state->stencil_mask_misc.single_sampled_lines = !rast->multisample;
@@ -554,6 +554,10 @@ panfrost_prepare_fs_state(struct panfrost_context *ctx,
         state->stencil_back = zsa->stencil_back;
         state->stencil_front.reference_value = ctx->stencil_ref.ref_value[0];
         state->stencil_back.reference_value = ctx->stencil_ref.ref_value[back_enab ? 1 : 0];
+
+        /* v6+ fits register preload here, no alpha testing */
+        if (dev->arch <= 5)
+                state->alpha_reference = zsa->base.alpha_ref_value;
 }
 
 
diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c
index 03988f05d3f..54a279ec35d 100644
--- a/src/gallium/drivers/panfrost/pan_context.c
+++ b/src/gallium/drivers/panfrost/pan_context.c
@@ -1240,8 +1240,9 @@ panfrost_create_depth_stencil_state(struct pipe_context *pipe,
                 so->stencil_mask_back = so->stencil_mask_front;
         }
 
-        /* Alpha lowered by frontend */
-        assert(!zsa->alpha_enabled);
+        so->alpha_func = zsa->alpha_enabled ?
+                panfrost_translate_compare_func(zsa->alpha_func) :
+                MALI_FUNC_ALWAYS;
 
         /* TODO: Bounds test should be easy */
         assert(!zsa->depth_bounds_test);
diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h
index 7d2f26a2809..a65442a88bb 100644
--- a/src/gallium/drivers/panfrost/pan_context.h
+++ b/src/gallium/drivers/panfrost/pan_context.h
@@ -282,6 +282,7 @@ struct panfrost_vertex_state {
 
 struct panfrost_zsa_state {
         struct pipe_depth_stencil_alpha_state base;
+        enum mali_func alpha_func;
 
         /* Precomputed stencil state */
         struct MALI_STENCIL stencil_front;
diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c
index 4aea02e3566..e94534abb64 100644
--- a/src/gallium/drivers/panfrost/pan_screen.c
+++ b/src/gallium/drivers/panfrost/pan_screen.c
@@ -267,7 +267,10 @@ panfrost_get_param(struct pipe_screen *screen, enum pipe_cap param)
         case PIPE_CAP_MAX_VARYINGS:
                 return 16;
 
+        /* Removed in v6 (Bifrost) */
         case PIPE_CAP_ALPHA_TEST:
+                return dev->arch <= 5;
+
         case PIPE_CAP_FLATSHADE:
         case PIPE_CAP_TWO_SIDED_COLOR:
         case PIPE_CAP_CLIP_PLANES:



More information about the mesa-commit mailing list