From e331efd4fe5b3af0740f3ade4df6f6652ce40ea4 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 26 Feb 2025 11:13:42 -0500 Subject: [PATCH] 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 Reviewed-by: Lionel Landwerlin Reviewed-by: Samuel Pitoiset Part-of: --- src/vulkan/util/vk_util.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h index b4bc3270d30..e86d72ff379 100644 --- a/src/vulkan/util/vk_util.h +++ b/src/vulkan/util/vk_util.h @@ -399,6 +399,19 @@ vk_descriptor_type_is_dynamic(VkDescriptorType type) } } +#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