panfrost: Stub out lowering boilerplate
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 13 May 2020 18:43:50 +0000 (14:43 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 1 Jun 2020 15:46:23 +0000 (15:46 +0000)
Structure ourselves as a NIR pass replacing loads/stores with
unpacked/packed versions as necessary. Not actually functional yet.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5265>

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

index 6ceb2e47a8ac09fcc916c6e22a577ac8a729632e..bc7b779748bdafaf9256befdcaab1d23d883cea4 100644 (file)
@@ -125,3 +125,111 @@ pan_format_class_store(const struct util_format_description *desc, unsigned quir
 
         return PAN_FORMAT_NATIVE;
 }
+
+/* Generic dispatches for un/pack regardless of format */
+
+static nir_ssa_def *
+pan_unpack(nir_builder *b,
+                const struct util_format_description *desc,
+                nir_ssa_def *packed)
+{
+        /* Stub */
+        return packed;
+}
+
+static nir_ssa_def *
+pan_pack(nir_builder *b,
+                const struct util_format_description *desc,
+                nir_ssa_def *unpacked)
+{
+        /* Stub */
+        return unpacked;
+}
+
+static void
+pan_lower_fb_store(nir_shader *shader,
+                nir_builder *b,
+                nir_intrinsic_instr *intr,
+                const struct util_format_description *desc,
+                unsigned quirks)
+{
+        /* For stores, add conversion before */
+        nir_ssa_def *unpacked = nir_ssa_for_src(b, intr->src[1], 4);
+        nir_ssa_def *packed = pan_pack(b, desc, unpacked);
+
+        nir_intrinsic_instr *new =
+                nir_intrinsic_instr_create(shader, nir_intrinsic_store_raw_output_pan);
+        new->src[0] = nir_src_for_ssa(packed);
+        new->num_components = 4;
+        nir_builder_instr_insert(b, &new->instr);
+}
+
+static void
+pan_lower_fb_load(nir_shader *shader,
+                nir_builder *b,
+                nir_intrinsic_instr *intr,
+                const struct util_format_description *desc,
+                unsigned quirks)
+{
+        nir_intrinsic_instr *new = nir_intrinsic_instr_create(shader,
+                       nir_intrinsic_load_raw_output_pan);
+        new->num_components = 4;
+
+        nir_ssa_dest_init(&new->instr, &new->dest, 4, 32, NULL);
+        nir_builder_instr_insert(b, &new->instr);
+
+        /* Convert the raw value */
+        nir_ssa_def *packed = &new->dest.ssa;
+        nir_ssa_def *unpacked = pan_unpack(b, desc, packed);
+
+        nir_src rewritten = nir_src_for_ssa(unpacked);
+        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)
+{
+        /* Blend shaders are represented as special fragment shaders */
+        assert(shader->info.stage == MESA_SHADER_FRAGMENT);
+
+        nir_foreach_function(func, shader) {
+                nir_foreach_block(block, func->impl) {
+                        nir_foreach_instr_safe(instr, block) {
+                                if (instr->type != nir_instr_type_intrinsic)
+                                        continue;
+
+                                nir_intrinsic_instr *intr = nir_instr_as_intrinsic(instr);
+
+                                bool is_load = intr->intrinsic == nir_intrinsic_load_deref;
+                                bool is_store = intr->intrinsic == nir_intrinsic_store_deref;
+
+                                if (!(is_load || is_store))
+                                        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);
+
+                                if (is_store) {
+                                        b.cursor = nir_before_instr(instr);
+                                        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);
+                                }
+
+                                nir_instr_remove(instr);
+                        }
+                }
+
+                nir_metadata_preserve(func->impl, nir_metadata_block_index |
+                                nir_metadata_dominance);
+        }
+}
index 3804ff4beb9bf6e60a8854ec25812fc090e993c4..5629bf8d725bc01e299335d91fab3fcd7f8a1c7f 100644 (file)
@@ -43,4 +43,9 @@ 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);
+
 #endif