pan/bi: Add validation for nr_srcs/nr_dests
authorAlyssa Rosenzweig <alyssa@collabora.com>
Thu, 21 Jul 2022 15:53:23 +0000 (11:53 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 2 Sep 2022 16:03:23 +0000 (16:03 +0000)
Now that we set nr_srcs/nr_dests accurately, assert as much in the validator.
This pass will be deleted later in the series, but having it here is expected to
be useful for bisection, in case there are cases missed. Certainly running the
CTS at this point in the series is helpful to prove completeness of the
beginning of this series.

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

src/panfrost/bifrost/bi_validate.c

index 7786897..8e7c077 100644 (file)
@@ -149,6 +149,43 @@ bi_validate_width(bi_context *ctx)
         return succ;
 }
 
+/*
+ * Temporary stopgap to check that source/destination counts are correct. This
+ * validation pass will go away later this series when we dynamically allocate
+ * sources and destinations.
+ */
+static bool
+bi_validate_src_dest_count(bi_context *ctx)
+{
+        bool succ = true;
+
+        bi_foreach_instr_global(ctx, I) {
+                for (unsigned s = I->nr_srcs; s < ARRAY_SIZE(I->src); ++s) {
+                        if (!bi_is_null(I->src[s])) {
+                                succ = false;
+                                fprintf(stderr,
+                                        "unexpected source %u, expected %u sources\n",
+                                        s, I->nr_srcs);
+                                bi_print_instr(I, stderr);
+                                fprintf(stderr, "\n");
+                        }
+                }
+
+                for (unsigned d = I->nr_dests; d < ARRAY_SIZE(I->dest); ++d) {
+                        if (!bi_is_null(I->dest[d])) {
+                                succ = false;
+                                fprintf(stderr,
+                                        "unexpected dest %u, expected %u sources\n",
+                                        d, I->nr_dests);
+                                bi_print_instr(I, stderr);
+                                fprintf(stderr, "\n");
+                        }
+                }
+        }
+
+        return succ;
+}
+
 void
 bi_validate(bi_context *ctx, const char *after)
 {
@@ -172,6 +209,11 @@ bi_validate(bi_context *ctx, const char *after)
                 fail = true;
         }
 
+        if (!bi_validate_src_dest_count(ctx)) {
+                fprintf(stderr, "Unexpected source/dest count after %s\n", after);
+                fail = true;
+        }
+
         if (fail) {
                 bi_print_shader(ctx, stderr);
                 exit(1);