Mesa (main): pan/bi: Unit test message preloading optimization

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Feb 24 20:12:34 UTC 2022


Module: Mesa
Branch: main
Commit: cd2a4cc47c341576e131e26117d9caef2f9b4f62
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=cd2a4cc47c341576e131e26117d9caef2f9b4f62

Author: Alyssa Rosenzweig <alyssa at collabora.com>
Date:   Thu Feb 24 13:36:24 2022 -0500

pan/bi: Unit test message preloading optimization

To make sure it is applied in the cases we expect it to be, to avoid code
generation regressions. Functional regressions are expected to be caught by
integration-testing, so that is not focused on here.

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

---

 src/panfrost/bifrost/meson.build                   |   1 +
 src/panfrost/bifrost/test/test-message-preload.cpp | 178 +++++++++++++++++++++
 2 files changed, 179 insertions(+)

diff --git a/src/panfrost/bifrost/meson.build b/src/panfrost/bifrost/meson.build
index eda61e8421a..97d39575ec5 100644
--- a/src/panfrost/bifrost/meson.build
+++ b/src/panfrost/bifrost/meson.build
@@ -151,6 +151,7 @@ if with_tests
       files(
         'test/test-constant-fold.cpp',
         'test/test-dual-texture.cpp',
+        'test/test-message-preload.cpp',
 	'test/test-optimizer.cpp',
 	'test/test-pack-formats.cpp',
 	'test/test-packing.cpp',
diff --git a/src/panfrost/bifrost/test/test-message-preload.cpp b/src/panfrost/bifrost/test/test-message-preload.cpp
new file mode 100644
index 00000000000..8e2a45b9400
--- /dev/null
+++ b/src/panfrost/bifrost/test/test-message-preload.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#include "compiler.h"
+#include "bi_test.h"
+#include "bi_builder.h"
+
+#include <gtest/gtest.h>
+
+#define CASE(instr, expected) do { \
+   bi_builder *A = bit_builder(mem_ctx); \
+   bi_builder *B = bit_builder(mem_ctx); \
+   A->shader->info.bifrost = rzalloc(mem_ctx, struct bifrost_shader_info); \
+   B->shader->info.bifrost = rzalloc(mem_ctx, struct bifrost_shader_info); \
+   { \
+      bi_builder *b = A; \
+      bi_index u = bi_temp(b->shader); \
+      UNUSED bi_index v = bi_temp(b->shader); \
+      UNUSED bi_index w = bi_temp(b->shader); \
+      instr; \
+   } \
+   { \
+      bi_builder *b = B; \
+      bi_index u = bi_temp(b->shader); \
+      UNUSED bi_index v = bi_temp(b->shader); \
+      UNUSED bi_index w = bi_temp(b->shader); \
+      expected; \
+   } \
+   bi_opt_message_preload(A->shader); \
+   if (!bit_shader_equal(A->shader, B->shader)) { \
+      ADD_FAILURE(); \
+      fprintf(stderr, "Optimization produce unexpected result"); \
+      fprintf(stderr, "  Actual:\n"); \
+      bi_print_shader(A->shader, stderr); \
+      fprintf(stderr, "Expected:\n"); \
+      bi_print_shader(B->shader, stderr); \
+      fprintf(stderr, "\n"); \
+   } \
+} while(0)
+
+#define NEGCASE(instr) CASE(instr, instr)
+
+class MessagePreload : public testing::Test {
+protected:
+   MessagePreload() {
+      mem_ctx = ralloc_context(NULL);
+
+      x       = bi_register(16);
+      y       = bi_register(32);
+
+   }
+
+   ~MessagePreload() {
+      ralloc_free(mem_ctx);
+   }
+
+   void *mem_ctx;
+
+   bi_index reg, x, y;
+
+   static void preload_moves(bi_builder *b, bi_index dest, int count, int idx)
+   {
+      for (int i = 0; i < count; ++i)
+         bi_mov_i32_to(b, bi_word(dest, i), bi_register(idx*4 + i));
+   }
+};
+
+
+TEST_F(MessagePreload, PreloadLdVarSample)
+{
+   CASE({
+         bi_ld_var_imm_to(b, u, bi_register(61), BI_REGISTER_FORMAT_F32,
+                          BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 0);
+   }, {
+         preload_moves(b, u, 4, 0);
+   });
+}
+
+TEST_F(MessagePreload, PreloadLdVarLdVar)
+{
+   CASE({
+         bi_ld_var_imm_to(b, u, bi_register(61), BI_REGISTER_FORMAT_F32,
+                          BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 2);
+         bi_ld_var_imm_to(b, v, bi_register(61), BI_REGISTER_FORMAT_F32,
+                          BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 1);
+   }, {
+         preload_moves(b, u, 4, 0);
+         preload_moves(b, v, 4, 1);
+   });
+}
+
+TEST_F(MessagePreload, MaxTwoMessages)
+{
+   CASE({
+         bi_ld_var_imm_to(b, u, bi_register(61), BI_REGISTER_FORMAT_F32,
+                          BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 2);
+         bi_ld_var_imm_to(b, v, bi_register(61), BI_REGISTER_FORMAT_F32,
+                          BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 1);
+         bi_ld_var_imm_to(b, w, bi_register(61), BI_REGISTER_FORMAT_F32,
+                          BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 0);
+   },
+   {
+         preload_moves(b, u, 4, 0);
+         preload_moves(b, v, 4, 1);
+         bi_ld_var_imm_to(b, w, bi_register(61), BI_REGISTER_FORMAT_F32,
+                          BI_SAMPLE_SAMPLE, BI_UPDATE_STORE, BI_VECSIZE_V4, 0);
+   });
+
+   CASE({
+         bi_var_tex_f32_to(b, u, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
+         bi_var_tex_f16_to(b, v, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 1, 2);
+         bi_var_tex_f16_to(b, w, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 3, 3);
+   }, {
+         preload_moves(b, u, 4, 0);
+         preload_moves(b, v, 2, 1);
+         bi_var_tex_f16_to(b, w, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 3, 3);
+   });
+}
+
+TEST_F(MessagePreload, PreloadVartexF16)
+{
+   CASE({
+         bi_var_tex_f16_to(b, u, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
+   }, {
+         preload_moves(b, u, 2, 0);
+   });
+}
+
+TEST_F(MessagePreload, PreloadVartexF32)
+{
+   CASE({
+         bi_var_tex_f32_to(b, u, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
+   }, {
+         preload_moves(b, u, 4, 0);
+   });
+}
+
+TEST_F(MessagePreload, PreloadVartexF32VartexF16)
+{
+   CASE({
+         bi_var_tex_f32_to(b, u, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
+         bi_var_tex_f16_to(b, v, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 1, 2);
+   }, {
+         preload_moves(b, u, 4, 0);
+         preload_moves(b, v, 2, 1);
+   });
+}
+
+TEST_F(MessagePreload, PreloadVartexLodModes)
+{
+   CASE({
+         bi_var_tex_f32_to(b, u, true, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
+         bi_var_tex_f32_to(b, v, false, BI_SAMPLE_CENTER, BI_UPDATE_STORE, 0, 0);
+   }, {
+         preload_moves(b, u, 4, 0);
+         preload_moves(b, v, 4, 1);
+   });
+}



More information about the mesa-commit mailing list