pan/mdg: Support MRT in output load lowering
authorIcecream95 <ixn@keemail.me>
Mon, 6 Jul 2020 07:54:56 +0000 (19:54 +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

index 5d5ffe50ce67eae555e89c6a5a332427e9049237..dc878c65f4406de691aa81e26566b2322bca7399 100644 (file)
@@ -1614,6 +1614,29 @@ mir_get_branch_cond(nir_src *src, bool *invert)
         return nir_src_index(NULL, &alu.src);
 }
 
+static uint8_t
+output_load_rt_addr(nir_shader *nir, nir_intrinsic_instr *instr)
+{
+        const nir_variable *var;
+        var = search_var(&nir->outputs, nir_intrinsic_base(instr));
+        assert(var);
+
+        unsigned loc = var->data.location;
+
+        if (loc == FRAG_RESULT_COLOR)
+                loc = FRAG_RESULT_DATA0;
+
+        if (loc >= FRAG_RESULT_DATA0)
+                return loc - FRAG_RESULT_DATA0;
+
+        if (loc == FRAG_RESULT_DEPTH)
+                return 0x1F;
+        if (loc == FRAG_RESULT_STENCIL)
+                return 0x1E;
+
+        assert(0);
+}
+
 static void
 emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
 {
@@ -1726,6 +1749,8 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
 
                 midgard_instruction ld = m_ld_color_buffer_32u(reg, 0);
 
+                ld.load_store.arg_2 = output_load_rt_addr(ctx->nir, instr);
+
                 if (ctx->quirks & MIDGARD_OLD_BLEND) {
                         ld.load_store.op = midgard_op_ld_color_buffer_32u_old;
                         ld.load_store.address = 16;
@@ -1741,6 +1766,8 @@ emit_intrinsic(compiler_context *ctx, nir_intrinsic_instr *instr)
 
                 midgard_instruction ld = m_ld_color_buffer_as_fp16(reg, 0);
 
+                ld.load_store.arg_2 = output_load_rt_addr(ctx->nir, instr);
+
                 for (unsigned c = 4; c < 16; ++c)
                         ld.swizzle[0][c] = 0;
 
index 5955cf024e269993f62d91faa72aad1a4eb25feb..6fdb9695b371481c050ac76574072bc3c7aefd02 100644 (file)
@@ -646,6 +646,8 @@ pan_lower_fb_load(nir_shader *shader,
                        nir_intrinsic_load_raw_output_pan);
         new->num_components = 4;
 
+        nir_intrinsic_set_base(new, base);
+
         nir_ssa_dest_init(&new->instr, &new->dest, 4, 32, NULL);
         nir_builder_instr_insert(b, &new->instr);
 
@@ -714,11 +716,18 @@ pan_lower_framebuffer(nir_shader *shader, enum pipe_format *rt_fmts,
                                 if (var->data.mode != nir_var_shader_out)
                                         continue;
 
-                                if (var->data.location != FRAG_RESULT_COLOR)
+                                unsigned base = var->data.driver_location;
+
+                                unsigned rt;
+                                if (var->data.location == FRAG_RESULT_COLOR)
+                                        rt = 0;
+                                else if (var->data.location >= FRAG_RESULT_DATA0)
+                                        rt = var->data.location - FRAG_RESULT_DATA0;
+                                else
                                         continue;
 
                                 const struct util_format_description *desc =
-                                   util_format_description(rt_fmts[0]);
+                                   util_format_description(rt_fmts[rt]);
 
                                 enum pan_format_class fmt_class =
                                         pan_format_class(desc, quirks, is_store);