Mesa (master): zink: add format test

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Dec 16 21:03:51 UTC 2020


Module: Mesa
Branch: master
Commit: 74132b761cd064d7a059571772befb7266a6f7f5
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=74132b761cd064d7a059571772befb7266a6f7f5

Author: Erik Faye-Lund <erik.faye-lund at collabora.com>
Date:   Mon Dec  7 20:53:31 2020 +0100

zink: add format test

This will help avoid future mistakes when mapping formats.

Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7982>

---

 src/gallium/drivers/zink/meson.build        | 13 +++++++++++++
 src/gallium/drivers/zink/zink_format_test.c | 27 +++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/src/gallium/drivers/zink/meson.build b/src/gallium/drivers/zink/meson.build
index 61f157a9a27..252261b9da2 100644
--- a/src/gallium/drivers/zink/meson.build
+++ b/src/gallium/drivers/zink/meson.build
@@ -82,3 +82,16 @@ driver_zink = declare_dependency(
   compile_args : '-DGALLIUM_ZINK',
   link_with : [libzink],
 )
+
+if with_tests
+  test(
+    'zink_format_test',
+    executable(
+      'zink_format_test',
+      ['zink_format_test.c', 'zink_format.c'],
+      dependencies : [idep_mesautil, idep_vulkan_util],
+      include_directories : [inc_gallium, inc_gallium_aux, inc_include, inc_src],
+    ),
+    suite : ['zink'],
+  )
+endif
diff --git a/src/gallium/drivers/zink/zink_format_test.c b/src/gallium/drivers/zink/zink_format_test.c
new file mode 100644
index 00000000000..502a2cbb661
--- /dev/null
+++ b/src/gallium/drivers/zink/zink_format_test.c
@@ -0,0 +1,27 @@
+#include "zink_format.h"
+#include "vk_format.h"
+
+int
+main(int argc, char *argv[])
+{
+   int ret = 0;
+   for (int i = 0; i < PIPE_FORMAT_COUNT; ++i) {
+      enum pipe_format pipe_fmt = i;
+      VkFormat vk_fmt = zink_pipe_format_to_vk_format(i);
+
+      /* skip unsupported formats */
+      if (vk_fmt == VK_FORMAT_UNDEFINED)
+         continue;
+
+      enum pipe_format roundtrip = vk_format_to_pipe_format(vk_fmt);
+      if (roundtrip != pipe_fmt) {
+         fprintf(stderr, "Format does not roundtrip\n"
+                         "\tgot: %s\n"
+                         "\texpected: %s\n",
+                         util_format_name(roundtrip),
+                         util_format_name(pipe_fmt));
+         ret = 1;
+      }
+   }
+   return ret;
+}



More information about the mesa-commit mailing list