Mesa (main): panfrost: Always use a fragment shader when alpha test is enabled

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jul 9 23:14:31 UTC 2021


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

Author: Icecream95 <ixn at disroot.org>
Date:   Sat Jul 10 00:31:02 2021 +1200

panfrost: Always use a fragment shader when alpha test is enabled

Fixes incorrect rendering with OpenSCAD.

Fixes: 275277a2b48 ("panfrost: Implement alpha testing natively")
Reported-by: Urja Rannikko <urjaman at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11812>

---

 src/gallium/drivers/panfrost/pan_cmdstream.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_cmdstream.c b/src/gallium/drivers/panfrost/pan_cmdstream.c
index 4ad73280320..43ba5f9031e 100644
--- a/src/gallium/drivers/panfrost/pan_cmdstream.c
+++ b/src/gallium/drivers/panfrost/pan_cmdstream.c
@@ -284,13 +284,19 @@ static bool
 panfrost_fs_required(
                 struct panfrost_shader_state *fs,
                 struct panfrost_blend_state *blend,
-                struct pipe_framebuffer_state *state)
+                struct pipe_framebuffer_state *state,
+                const struct panfrost_zsa_state *zsa)
 {
         /* If we generally have side effects. This inclues use of discard,
          * which can affect the results of an occlusion query. */
         if (fs->info.fs.sidefx)
                 return true;
 
+        /* Using an empty FS requires early-z to be enabled, but alpha test
+         * needs it disabled */
+        if ((enum mali_func) zsa->base.alpha_func != MALI_FUNC_ALWAYS)
+                return true;
+
         /* If colour is written we need to execute */
         for (unsigned i = 0; i < state->nr_cbufs; ++i) {
                 if (state->cbufs[i] && !blend->info[i].no_colour)
@@ -518,7 +524,7 @@ panfrost_prepare_fs_state(struct panfrost_context *ctx,
         bool msaa = rast->multisample;
 
         pan_pack(rsd, RENDERER_STATE, cfg) {
-                if (pan_is_bifrost(dev) && panfrost_fs_required(fs, so, &ctx->pipe_framebuffer)) {
+                if (pan_is_bifrost(dev) && panfrost_fs_required(fs, so, &ctx->pipe_framebuffer, zsa)) {
                         /* Track if any colour buffer is reused across draws, either
                          * from reading it directly, or from failing to write it */
                         unsigned rt_mask = ctx->fb_rt_mask;
@@ -532,7 +538,7 @@ panfrost_prepare_fs_state(struct panfrost_context *ctx,
                 } else if (!pan_is_bifrost(dev)) {
                         unsigned rt_count = ctx->pipe_framebuffer.nr_cbufs;
 
-                        if (panfrost_fs_required(fs, ctx->blend, &ctx->pipe_framebuffer)) {
+                        if (panfrost_fs_required(fs, ctx->blend, &ctx->pipe_framebuffer, zsa)) {
                                 cfg.properties.midgard.force_early_z =
                                         fs->info.fs.can_early_z && !alpha_to_coverage &&
                                         ((enum mali_func) zsa->base.alpha_func == MALI_FUNC_ALWAYS);
@@ -637,7 +643,7 @@ panfrost_emit_frag_shader(struct panfrost_context *ctx,
         }
 
         /* Merge with CSO state and upload */
-        if (panfrost_fs_required(fs, ctx->blend, &ctx->pipe_framebuffer))
+        if (panfrost_fs_required(fs, ctx->blend, &ctx->pipe_framebuffer, zsa))
                 pan_merge(rsd, fs->partial_rsd, RENDERER_STATE);
         else
                 pan_merge_empty_fs(&rsd, pan_is_bifrost(dev));



More information about the mesa-commit mailing list