pan/mdg: Handle non-blend framebuffer lowering
authorIcecream95 <ixn@keemail.me>
Mon, 6 Jul 2020 07:34:49 +0000 (19:34 +1200)
committerMarge Bot <eric+marge@anholt.net>
Mon, 13 Jul 2020 13:35:10 +0000 (13:35 +0000)
Reviewed-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5755>

src/panfrost/midgard/midgard_compile.c
src/panfrost/util/pan_lower_framebuffer.c
src/panfrost/util/pan_lower_framebuffer.h

index a432fabc1aa2c07d36c21becf48f9e280f9a0532..5d5ffe50ce67eae555e89c6a5a332427e9049237 100644 (file)
@@ -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);
index 862059567027bece4518296194fa67f1f5be9027..5955cf024e269993f62d91faa72aad1a4eb25feb 100644 (file)
@@ -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);
index 09c1dddd617917ed90d31fbe93d55ef1f28bda00..990368bfd946026c6bbd96b68637e1d400610648 100644 (file)
@@ -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