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>
This commit is contained in:
Alyssa Rosenzweig 2025-02-26 11:13:42 -05:00 committed by Marge Bot
parent 7ce8f1ebb0
commit e331efd4fe

View file

@ -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