Mesa (master): pan/mdg: Do the pan_lower_framebuffer pass later

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jul 13 14:04:06 UTC 2020


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

Author: Icecream95 <ixn at keemail.me>
Date:   Mon Jul  6 19:30:37 2020 +1200

pan/mdg: Do the pan_lower_framebuffer pass later

The pass is useful for EXT_shader_framebuffer_fetch, not just blend
shaders, so we should do it with the other lowering passes in
midgard_compile_shader_nir.

Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig at collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5755>

---

 src/gallium/drivers/panfrost/pan_blend_shaders.c |  6 +++--
 src/panfrost/midgard/midgard_compile.c           |  7 +++++
 src/panfrost/util/pan_lower_framebuffer.c        | 34 +++++++++++++++---------
 src/panfrost/util/pan_lower_framebuffer.h        |  6 ++---
 4 files changed, 35 insertions(+), 18 deletions(-)

diff --git a/src/gallium/drivers/panfrost/pan_blend_shaders.c b/src/gallium/drivers/panfrost/pan_blend_shaders.c
index 1e9d7d474cb..32132e22ecd 100644
--- a/src/gallium/drivers/panfrost/pan_blend_shaders.c
+++ b/src/gallium/drivers/panfrost/pan_blend_shaders.c
@@ -203,11 +203,13 @@ panfrost_compile_blend_shader(
                 options.half = true;
 
         NIR_PASS_V(shader, nir_lower_blend, options);
-        NIR_PASS_V(shader, pan_lower_framebuffer, format_desc, dev->quirks);
 
         /* Compile the built shader */
 
-        panfrost_program program;
+        panfrost_program program = {
+           .rt_formats = {format}
+        };
+
         midgard_compile_shader_nir(shader, &program, true, rt, dev->gpu_id, false);
 
         /* Allow us to patch later */
diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
index 7da75d63f19..c312fcc5e49 100644
--- a/src/panfrost/midgard/midgard_compile.c
+++ b/src/panfrost/midgard/midgard_compile.c
@@ -48,6 +48,8 @@
 #include "helpers.h"
 #include "compiler.h"
 #include "midgard_quirks.h"
+#include "panfrost-quirks.h"
+#include "panfrost/util/pan_lower_framebuffer.h"
 
 #include "disassemble.h"
 
@@ -2755,6 +2757,11 @@ midgard_compile_shader_nir(nir_shader *nir, panfrost_program *program, bool is_b
         NIR_PASS_V(nir, nir_lower_var_copies);
         NIR_PASS_V(nir, nir_lower_vars_to_ssa);
 
+        unsigned pan_quirks = panfrost_get_quirks(gpu_id);
+        if (is_blend)
+        NIR_PASS_V(nir, pan_lower_framebuffer,
+                   program->rt_formats, pan_quirks);
+
         NIR_PASS_V(nir, nir_lower_io, nir_var_shader_in | nir_var_shader_out,
                         glsl_type_size, 0);
         NIR_PASS_V(nir, nir_lower_ssbo);
diff --git a/src/panfrost/util/pan_lower_framebuffer.c b/src/panfrost/util/pan_lower_framebuffer.c
index 76adcfbcaa3..86205956702 100644
--- a/src/panfrost/util/pan_lower_framebuffer.c
+++ b/src/panfrost/util/pan_lower_framebuffer.c
@@ -660,13 +660,14 @@ pan_lower_fb_load(nir_shader *shader,
         nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, rewritten, &intr->instr);
 }
 
-void
-pan_lower_framebuffer(nir_shader *shader,
-                const struct util_format_description *desc,
-                unsigned quirks)
+bool
+pan_lower_framebuffer(nir_shader *shader, enum pipe_format *rt_fmts,
+                      unsigned quirks)
 {
-        /* Blend shaders are represented as special fragment shaders */
-        assert(shader->info.stage == MESA_SHADER_FRAGMENT);
+        if (shader->info.stage != MESA_SHADER_FRAGMENT)
+               return false;
+
+        bool progress = false;
 
         nir_foreach_function(func, shader) {
                 nir_foreach_block(block, func->impl) {
@@ -682,6 +683,17 @@ pan_lower_framebuffer(nir_shader *shader,
                                 if (!(is_load || is_store))
                                         continue;
 
+                                nir_variable *var = nir_intrinsic_get_var(intr, 0);
+
+                                if (var->data.mode != nir_var_shader_out)
+                                        continue;
+
+                                if (var->data.location != FRAG_RESULT_COLOR)
+                                        continue;
+
+                                const struct util_format_description *desc =
+                                   util_format_description(rt_fmts[0]);
+
                                 enum pan_format_class fmt_class =
                                         pan_format_class(desc, quirks, is_store);
 
@@ -689,12 +701,6 @@ pan_lower_framebuffer(nir_shader *shader,
                                 if (fmt_class == PAN_FORMAT_NATIVE)
                                         continue;
 
-                                /* Don't worry about MRT */
-                                nir_variable *var = nir_intrinsic_get_var(intr, 0);
-
-                                if (var->data.location != FRAG_RESULT_COLOR)
-                                        continue;
-
                                 nir_builder b;
                                 nir_builder_init(&b, func->impl);
 
@@ -707,10 +713,14 @@ pan_lower_framebuffer(nir_shader *shader,
                                 }
 
                                 nir_instr_remove(instr);
+
+                                progress = true;
                         }
                 }
 
                 nir_metadata_preserve(func->impl, nir_metadata_block_index |
                                 nir_metadata_dominance);
         }
+
+        return progress;
 }
diff --git a/src/panfrost/util/pan_lower_framebuffer.h b/src/panfrost/util/pan_lower_framebuffer.h
index 5629bf8d725..09c1dddd617 100644
--- a/src/panfrost/util/pan_lower_framebuffer.h
+++ b/src/panfrost/util/pan_lower_framebuffer.h
@@ -43,9 +43,7 @@ nir_alu_type pan_unpacked_type_for_format(const struct util_format_description *
 enum pan_format_class pan_format_class_load(const struct util_format_description *desc, unsigned quirks);
 enum pan_format_class pan_format_class_store(const struct util_format_description *desc, unsigned quirks);
 
-void
-pan_lower_framebuffer(nir_shader *shader,
-                const struct util_format_description *desc,
-                unsigned quirks);
+bool pan_lower_framebuffer(nir_shader *shader, enum pipe_format *rt_fmts,
+                           unsigned quirks);
 
 #endif



More information about the mesa-commit mailing list