panfrost: Set the MALI_WRITES_{Z,S} flags when needed
authorBoris Brezillon <boris.brezillon@collabora.com>
Fri, 31 Jan 2020 09:55:49 +0000 (10:55 +0100)
committerMarge Bot <eric+marge@anholt.net>
Wed, 5 Feb 2020 15:41:55 +0000 (15:41 +0000)
In order to make Z/S writes from fragment shaders effective, we need
to set the MALI_WRITES_{Z,S} flags when the shader has a
FRAG_RESULT_{DEPTH,STENCIL} output variable.

Now that shaders can change the S value, we can expose the
STENCIL_EXPORT cap.

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

src/gallium/drivers/panfrost/pan_assemble.c
src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_context.h
src/gallium/drivers/panfrost/pan_screen.c

index fb5cb4cb7e2ac45c8b70fd2ae8bab5f8cf53c459..03ca63ccc3262526008ee07c1748a74386bf346a 100644 (file)
@@ -114,6 +114,10 @@ panfrost_shader_compile(
         case MESA_SHADER_FRAGMENT:
                 meta->attribute_count = 0;
                 meta->varying_count = util_bitcount64(s->info.inputs_read);
+                if (s->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DEPTH))
+                        state->writes_depth = true;
+                if (s->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_STENCIL))
+                        state->writes_stencil = true;
                 break;
         case MESA_SHADER_COMPUTE:
                 /* TODO: images */
index faa56ee33ffcba0c7cf560e1ae33aa16007f0e24..417c900c961a2b23010e6d66aa35220aa0017ff0 100644 (file)
@@ -961,7 +961,14 @@ panfrost_emit_for_draw(struct panfrost_context *ctx, bool with_vertex_data)
                 /* Depending on whether it's legal to in the given shader, we
                  * try to enable early-z testing (or forward-pixel kill?) */
 
-                SET_BIT(ctx->fragment_shader_core.midgard1.flags_lo, MALI_EARLY_Z, !variant->can_discard);
+                SET_BIT(ctx->fragment_shader_core.midgard1.flags_lo, MALI_EARLY_Z,
+                        !variant->can_discard && !variant->writes_depth);
+
+                /* Add the writes Z/S flags if needed. */
+                SET_BIT(ctx->fragment_shader_core.midgard1.flags_lo,
+                        MALI_WRITES_Z, variant->writes_depth);
+                SET_BIT(ctx->fragment_shader_core.midgard1.flags_hi,
+                        MALI_WRITES_S, variant->writes_stencil);
 
                 /* Any time texturing is used, derivatives are implicitly
                  * calculated, so we need to enable helper invocations */
index 98d327cfde499f30b8e8f256771d1e5cf2d004ad..79d082da11f818c8a5cae9f54f2a684ddd908d00 100644 (file)
@@ -210,6 +210,8 @@ struct panfrost_shader_state {
         int uniform_count;
         bool can_discard;
         bool writes_point_size;
+        bool writes_depth;
+        bool writes_stencil;
         bool reads_point_coord;
         bool reads_face;
         bool reads_frag_coord;
index 0fe6062df917e13bb5e5ba975edfe0846d74e9db..19d646bf7e7c52946d6ab4c7e22d385be7273a18 100644 (file)
@@ -245,6 +245,9 @@ panfrost_get_param(struct pipe_screen *screen, enum pipe_cap param)
                 return (int)(system_memory >> 20);
         }
 
+        case PIPE_CAP_SHADER_STENCIL_EXPORT:
+                return 1;
+
         case PIPE_CAP_SHADER_BUFFER_OFFSET_ALIGNMENT:
                 return 4;