pan/bit: Add packing test framework
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Wed, 1 Apr 2020 18:40:33 +0000 (14:40 -0400)
committerMarge Bot <eric+marge@anholt.net>
Sun, 5 Apr 2020 23:26:04 +0000 (23:26 +0000)
Given an instruction, we'd like to wrap it in a clause with some I/O on
each end so we can pack it up and send it to the hardware to compare
against the simulator.

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

src/panfrost/bifrost/test/bi_submit.c
src/panfrost/bifrost/test/bi_test_pack.c [new file with mode: 0644]
src/panfrost/bifrost/test/bit.h
src/panfrost/meson.build

index 685fca2cb6b993eb527f175eeff3014045443e9f..c9c9c90e8b72d6ce080ae44ce84fa8a0d8aee0ea 100644 (file)
@@ -141,7 +141,7 @@ bit_vertex(struct panfrost_device *dev, panfrost_program prog,
 
         struct mali_attr_meta vmeta = {
                 .index = 0,
-                .format = MALI_RGBA32F
+                .format = MALI_RGBA32UI
         };
 
         union mali_attr vary = {
diff --git a/src/panfrost/bifrost/test/bi_test_pack.c b/src/panfrost/bifrost/test/bi_test_pack.c
new file mode 100644 (file)
index 0000000..bd20252
--- /dev/null
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2020 Collabora Ltd.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Authors (Collabora):
+ *      Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
+ */
+
+#include "bit.h"
+#include "bi_print.h"
+
+/* Instruction packing tests */
+
+static bool
+bit_test_single(struct panfrost_device *dev,
+                bi_instruction *ins, 
+                uint32_t input[4],
+                bool fma, enum bit_debug debug)
+{
+        /* First, simulate the instruction */
+        struct bit_state s = { 0 };
+        memcpy(s.r, input, 16);
+        bit_step(&s, ins, fma);
+
+        /* Next, wrap it up and pack it */
+
+        bi_instruction ldubo = {
+                .type = BI_LOAD_UNIFORM,
+                .src = {
+                        BIR_INDEX_CONSTANT,
+                        BIR_INDEX_ZERO
+                },
+                .src_types = {
+                        nir_type_uint32,
+                        nir_type_uint32,
+                },
+                .dest = BIR_INDEX_REGISTER | 0,
+                .dest_type = nir_type_uint32,
+                .writemask = 0xFFFF
+        };
+
+        bi_instruction ldva = {
+                .type = BI_LOAD_VAR_ADDRESS,
+                .writemask = (1 << 12) - 1,
+                .dest = BIR_INDEX_REGISTER | 32,
+                .dest_type = nir_type_uint32,
+                .src = {
+                        BIR_INDEX_CONSTANT,
+                        BIR_INDEX_REGISTER | 61,
+                        BIR_INDEX_REGISTER | 62,
+                        0,
+                },
+                .src_types = {
+                        nir_type_uint32,
+                        nir_type_uint32,
+                        nir_type_uint32,
+                        nir_type_uint32,
+                }
+        };
+
+        bi_instruction st = {
+                .type = BI_STORE_VAR,
+                .src = {
+                        BIR_INDEX_REGISTER | 0,
+                        ldva.dest, ldva.dest + 1, ldva.dest + 2,
+                },
+                .src_types = {
+                        nir_type_uint32,
+                        nir_type_uint32, nir_type_uint32, nir_type_uint32,
+                },
+                .store_channels = 4
+        };
+
+        bi_context *ctx = rzalloc(NULL, bi_context);
+        ctx->stage = MESA_SHADER_VERTEX;
+
+        bi_block *blk = rzalloc(ctx, bi_block);
+        blk->scheduled = true;
+
+        blk->base.predecessors = _mesa_set_create(blk,
+                        _mesa_hash_pointer,
+                        _mesa_key_pointer_equal);
+
+        list_inithead(&ctx->blocks);
+        list_addtail(&blk->base.link, &ctx->blocks);
+        list_inithead(&blk->clauses);
+
+        bi_clause *clauses[4] = {
+                rzalloc(ctx, bi_clause),
+                rzalloc(ctx, bi_clause),
+                rzalloc(ctx, bi_clause),
+                rzalloc(ctx, bi_clause)
+        };
+
+        for (unsigned i = 0; i < 4; ++i) {
+                clauses[i]->bundle_count = 1;
+                list_addtail(&clauses[i]->link, &blk->clauses);
+                clauses[i]->scoreboard_id = (i & 1);
+
+                if (i) {
+                        clauses[i]->dependencies = 1 << (~i & 1);
+                        clauses[i]->data_register_write_barrier = true;
+                }
+        }
+
+        clauses[0]->bundles[0].add = &ldubo;
+        clauses[0]->clause_type = BIFROST_CLAUSE_UBO;
+
+        if (fma)
+                clauses[1]->bundles[0].fma = ins;
+        else
+                clauses[1]->bundles[0].add = ins;
+
+        clauses[0]->constant_count = 1;
+        clauses[1]->constant_count = 1;
+        clauses[1]->constants[0] = ins->constant.u64;
+
+        clauses[2]->bundles[0].add = &ldva;
+        clauses[3]->bundles[0].add = &st;
+
+        clauses[2]->clause_type = BIFROST_CLAUSE_UBO;
+        clauses[3]->clause_type = BIFROST_CLAUSE_SSBO_STORE;
+
+        panfrost_program prog;
+        bi_pack(ctx, &prog.compiled);
+
+        return bit_vertex(dev, prog, input, 16, NULL, 0,
+                        s.r, 16, BIT_DEBUG_ALL);
+}
index 3a6d9e4336f1e746c177e40033f9d012c9553b03..a45d18af44b51a0080ee0942d0d4f062a19433a8 100644 (file)
@@ -67,6 +67,14 @@ struct bit_state {
 void
 bit_step(struct bit_state *s, bi_instruction *ins, bool FMA);
 
+/* Packing tests */
+
+bool
+bit_test_single(struct panfrost_device *dev,
+                bi_instruction *ins, 
+                uint32_t input[4],
+                bool fma);
+
 #endif
 
 
index eb2fb932f4f282508b692183b9b3a954dd455a03..68442fd37906452ac446b80cfc50decf50a48de8 100644 (file)
@@ -38,6 +38,7 @@ files_bifrost = files(
   'bifrost/cmdline.c',
   'bifrost/test/bi_submit.c',
   'bifrost/test/bi_interpret.c',
+  'bifrost/test/bi_test_pack.c',
 )
 
 bifrost_compiler = executable(