vulkan: add common VK_PRINT_STR/VK_COPY_STR macros

every vk driver wants these macros for executable statistics, so make them
common. there are two variants floating in-tree, a pure copy (radv) and a
formatted print (everyone else). we add both variants and then convert most
prints to copies where formatting isn't actually used. that has the benefit of
cleaning up trivial "%s" format strings in a bunch of places.

I didn't bother cleaning up the formatting in non-automatic-formatted drivers
because it's tedious and I'm planning to delete a lot of this driver code with
upcoming runtime work anyway. This is a step towards those runtime improvements.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33826>
diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h
index b4bc327..e86d72f 100644
--- a/src/vulkan/util/vk_util.h
+++ b/src/vulkan/util/vk_util.h
@@ -399,6 +399,19 @@
    }
 }
 
+#define VK_PRINT_STR(field, ...) do {                          \
+   memset(field, 0, sizeof(field));                            \
+   UNUSED int i = snprintf(field, sizeof(field), __VA_ARGS__); \
+   assert(i > 0 && i < sizeof(field));                         \
+} while(0)
+
+#define VK_COPY_STR(field, str) do {                           \
+   int len = strlen(str);                                      \
+   assert(len > 0 && len < sizeof(field));                     \
+   memcpy(field, str, len);                                    \
+   memset(field + len, 0, sizeof(field) - len);                \
+} while(0)
+
 #ifdef __cplusplus
 }
 #endif