From 14c534386742b44bc02349684b0a0e3972fec91d Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 1 Apr 2020 14:40:33 -0400 Subject: [PATCH] pan/bit: Add packing test framework 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 Part-of: --- src/panfrost/bifrost/test/bi_submit.c | 2 +- src/panfrost/bifrost/test/bi_test_pack.c | 147 +++++++++++++++++++++++ src/panfrost/bifrost/test/bit.h | 8 ++ src/panfrost/meson.build | 1 + 4 files changed, 157 insertions(+), 1 deletion(-) create mode 100644 src/panfrost/bifrost/test/bi_test_pack.c diff --git a/src/panfrost/bifrost/test/bi_submit.c b/src/panfrost/bifrost/test/bi_submit.c index 685fca2cb6b..c9c9c90e8b7 100644 --- a/src/panfrost/bifrost/test/bi_submit.c +++ b/src/panfrost/bifrost/test/bi_submit.c @@ -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 index 00000000000..bd20252c20f --- /dev/null +++ b/src/panfrost/bifrost/test/bi_test_pack.c @@ -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 + */ + +#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); +} diff --git a/src/panfrost/bifrost/test/bit.h b/src/panfrost/bifrost/test/bit.h index 3a6d9e4336f..a45d18af44b 100644 --- a/src/panfrost/bifrost/test/bit.h +++ b/src/panfrost/bifrost/test/bit.h @@ -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 diff --git a/src/panfrost/meson.build b/src/panfrost/meson.build index eb2fb932f4f..68442fd3790 100644 --- a/src/panfrost/meson.build +++ b/src/panfrost/meson.build @@ -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( -- 2.30.2