panfrost: Move early-z decision earlier
authorAlyssa Rosenzweig <alyssa@collabora.com>
Fri, 14 May 2021 22:50:23 +0000 (18:50 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 18 May 2021 22:51:56 +0000 (22:51 +0000)
These were already grouped nicely, just never got used. I also added
coverage writes to the list of reasons not to use early-z for
completeness. At the moment this doesn't do anything since this is a
Midgard flag and we haven't hooked up coverage writes on Midgard.

Signed-off-by: Alyssa Rosenzweig <alyssa@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10869>

src/gallium/drivers/panfrost/pan_cmdstream.c
src/panfrost/lib/pan_shader.c
src/panfrost/util/pan_ir.h

index 459dc49..7577bd2 100644 (file)
@@ -514,10 +514,9 @@ panfrost_prepare_midgard_fs_state(struct panfrost_context *ctx,
                 state->properties.depth_source = MALI_DEPTH_SOURCE_FIXED_FUNCTION;
                 state->properties.midgard.force_early_z = true;
         } else {
-                /* Reasons to disable early-Z from a shader perspective */
-                bool late_z = fs->info.fs.can_discard || fs->info.writes_global ||
-                              fs->info.fs.writes_depth || fs->info.fs.writes_stencil ||
-                              ((enum mali_func) zsa->base.alpha_func != MALI_FUNC_ALWAYS);
+                state->properties.midgard.force_early_z =
+                        fs->info.fs.can_early_z && !alpha_to_coverage &&
+                        ((enum mali_func) zsa->base.alpha_func == MALI_FUNC_ALWAYS);
 
                 bool has_blend_shader = false;
 
@@ -530,8 +529,6 @@ panfrost_prepare_midgard_fs_state(struct panfrost_context *ctx,
                 else
                         state->properties.midgard.work_register_count = fs->info.work_reg_count;
 
-                state->properties.midgard.force_early_z = !(late_z || alpha_to_coverage);
-
                 /* Workaround a hardware errata where early-z cannot be enabled
                  * when discarding even when the depth buffer is read-only, by
                  * lying to the hardware about the discard and setting the
index c210417..f84c345 100644 (file)
@@ -218,6 +218,14 @@ pan_shader_compile(const struct panfrost_device *dev,
                 info->fs.sidefx = s->info.writes_memory ||
                                   s->info.fs.uses_discard ||
                                   s->info.fs.uses_demote;
+
+                /* With suitable ZSA/blend, is early-z possible? */
+                info->fs.can_early_z =
+                        !info->fs.sidefx &&
+                        !info->fs.writes_depth &&
+                        !info->fs.writes_stencil &&
+                        !info->fs.writes_coverage;
+
                 info->fs.reads_frag_coord =
                         (s->info.inputs_read & (1 << VARYING_SLOT_POS)) ||
                         BITSET_TEST(s->info.system_values_read, SYSTEM_VALUE_FRAG_COORD);
index 3f20e3f..1f4c650 100644 (file)
@@ -180,6 +180,7 @@ struct pan_shader_info {
                         bool reads_helper_invocation;
                         bool sample_shading;
                         bool early_fragment_tests;
+                        bool can_early_z;
                         BITSET_WORD outputs_read;
                         BITSET_WORD outputs_written;
                 } fs;