Mesa (master): pan/mdg: Handle non-blend framebuffer lowering

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


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

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

pan/mdg: Handle non-blend framebuffer lowering

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

---

 src/panfrost/midgard/midgard_compile.c    |  5 +----
 src/panfrost/util/pan_lower_framebuffer.c | 34 +++++++++++++++++++++++++++----
 src/panfrost/util/pan_lower_framebuffer.h |  2 +-
 3 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/src/panfrost/midgard/midgard_compile.c b/src/panfrost/midgard/midgard_compile.c
index a432fabc1aa..5d5ffe50ce6 100644
--- a/src/panfrost/midgard/midgard_compile.c
+++ b/src/panfrost/midgard/midgard_compile.c
@@ -1720,7 +1720,6 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
 
         case nir_intrinsic_load_raw_output_pan: {
                 reg = nir_dest_index(&instr->dest);
-                assert(ctx->is_blend);
 
                 /* T720 and below use different blend opcodes with slightly
                  * different semantics than T760 and up */
@@ -1739,7 +1738,6 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
 
         case nir_intrinsic_load_output: {
                 reg = nir_dest_index(&instr->dest);
-                assert(ctx->is_blend);
 
                 midgard_instruction ld = m_ld_color_buffer_as_fp16(reg, 0);
 
@@ -2766,9 +2764,8 @@ midgard_compile_shader_nir(nir_shader *nir, panfrost_program *program, bool is_b
         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);
+                   program->rt_formats, is_blend, pan_quirks);
 
         NIR_PASS_V(nir, nir_lower_io, nir_var_shader_in | nir_var_shader_out,
                         glsl_type_size, 0);
diff --git a/src/panfrost/util/pan_lower_framebuffer.c b/src/panfrost/util/pan_lower_framebuffer.c
index 86205956702..5955cf024e2 100644
--- a/src/panfrost/util/pan_lower_framebuffer.c
+++ b/src/panfrost/util/pan_lower_framebuffer.c
@@ -640,7 +640,7 @@ pan_lower_fb_load(nir_shader *shader,
                 nir_builder *b,
                 nir_intrinsic_instr *intr,
                 const struct util_format_description *desc,
-                unsigned quirks)
+                unsigned base, unsigned quirks)
 {
         nir_intrinsic_instr *new = nir_intrinsic_instr_create(shader,
                        nir_intrinsic_load_raw_output_pan);
@@ -656,13 +656,39 @@ pan_lower_fb_load(nir_shader *shader,
         if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
                 unpacked = pan_srgb_to_linear(b, unpacked);
 
+        /* Convert to the size of the load intrinsic.
+         *
+         * We can assume that the type will match with the framebuffer format:
+         *
+         * Page 170 of the PDF of the OpenGL ES 3.0.6 spec says:
+         *
+         * If [UNORM or SNORM, convert to fixed-point]; otherwise no type
+         * conversion is applied. If the values written by the fragment shader
+         * do not match the format(s) of the corresponding color buffer(s),
+         * the result is undefined.
+         */
+
+        unsigned bits = nir_dest_bit_size(intr->dest);
+
+        nir_alu_type src_type;
+        if (desc->channel[0].pure_integer) {
+                if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED)
+                        src_type = nir_type_int;
+                else
+                        src_type = nir_type_uint;
+        } else {
+                src_type = nir_type_float;
+        }
+
+        unpacked = nir_convert_to_bit_size(b, unpacked, src_type, bits);
+
         nir_src rewritten = nir_src_for_ssa(unpacked);
         nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, rewritten, &intr->instr);
 }
 
 bool
 pan_lower_framebuffer(nir_shader *shader, enum pipe_format *rt_fmts,
-                      unsigned quirks)
+                      bool lower_store, unsigned quirks)
 {
         if (shader->info.stage != MESA_SHADER_FRAGMENT)
                return false;
@@ -680,7 +706,7 @@ pan_lower_framebuffer(nir_shader *shader, enum pipe_format *rt_fmts,
                                 bool is_load = intr->intrinsic == nir_intrinsic_load_deref;
                                 bool is_store = intr->intrinsic == nir_intrinsic_store_deref;
 
-                                if (!(is_load || is_store))
+                                if (!(is_load || (is_store && lower_store)))
                                         continue;
 
                                 nir_variable *var = nir_intrinsic_get_var(intr, 0);
@@ -709,7 +735,7 @@ pan_lower_framebuffer(nir_shader *shader, enum pipe_format *rt_fmts,
                                         pan_lower_fb_store(shader, &b, intr, desc, quirks);
                                 } else {
                                         b.cursor = nir_after_instr(instr);
-                                        pan_lower_fb_load(shader, &b, intr, desc, quirks);
+                                        pan_lower_fb_load(shader, &b, intr, desc, base, quirks);
                                 }
 
                                 nir_instr_remove(instr);
diff --git a/src/panfrost/util/pan_lower_framebuffer.h b/src/panfrost/util/pan_lower_framebuffer.h
index 09c1dddd617..990368bfd94 100644
--- a/src/panfrost/util/pan_lower_framebuffer.h
+++ b/src/panfrost/util/pan_lower_framebuffer.h
@@ -44,6 +44,6 @@ enum pan_format_class pan_format_class_load(const struct util_format_description
 enum pan_format_class pan_format_class_store(const struct util_format_description *desc, unsigned quirks);
 
 bool pan_lower_framebuffer(nir_shader *shader, enum pipe_format *rt_fmts,
-                           unsigned quirks);
+                           bool is_blend, unsigned quirks);
 
 #endif



More information about the mesa-commit mailing list