diff options
author | James Park <jpark37@lagfreegames.com> | 2020-11-30 02:00:48 -0800 |
---|---|---|
committer | Marge Bot <eric+marge@anholt.net> | 2020-12-01 07:48:08 +0000 |
commit | f86668f487b32c185388a39e2200c17c298b877a (patch) | |
tree | 97c48ac8340292de82eff90720c894e89955fae1 | |
parent | 116b6d135dad7f45d018a2d715a614b35143f385 (diff) |
vulkan/util: Consolidate typed_memcpy
Collapse typed_memcpy definitions into one header.
Use do/while(0) pattern to fix MSVC compilation.
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7830>
-rw-r--r-- | src/amd/vulkan/radv_meta.c | 2 | ||||
-rw-r--r-- | src/amd/vulkan/radv_private.h | 5 | ||||
-rw-r--r-- | src/broadcom/vulkan/v3dv_cmd_buffer.c | 1 | ||||
-rw-r--r-- | src/broadcom/vulkan/v3dv_private.h | 5 | ||||
-rw-r--r-- | src/gallium/frontends/lavapipe/lvp_private.h | 4 | ||||
-rw-r--r-- | src/intel/vulkan/anv_private.h | 5 | ||||
-rw-r--r-- | src/vulkan/util/vk_util.h | 8 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_display.h | 5 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_wayland.c | 5 | ||||
-rw-r--r-- | src/vulkan/wsi/wsi_common_x11.c | 5 |
10 files changed, 11 insertions, 34 deletions
diff --git a/src/amd/vulkan/radv_meta.c b/src/amd/vulkan/radv_meta.c index 0213826783c..bdd06c2ebd9 100644 --- a/src/amd/vulkan/radv_meta.c +++ b/src/amd/vulkan/radv_meta.c @@ -25,6 +25,8 @@ #include "radv_meta.h" +#include "vk_util.h" + #include <fcntl.h> #include <limits.h> #include <pwd.h> diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index ab7d797fbf5..b425a16903a 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -183,11 +183,6 @@ radv_clear_mask(uint32_t *inout_mask, uint32_t clear_mask) (b) = __builtin_ffs(__dword) - 1, __dword; \ __dword &= ~(1 << (b))) -#define typed_memcpy(dest, src, count) ({ \ - STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \ - memcpy((dest), (src), (count) * sizeof(*(src))); \ - }) - /* Whenever we generate an error, pass it through this function. Useful for * debugging, where we can break on it. Only call at error site, not when * propagating errors. Might be useful to plug in a stack trace here. diff --git a/src/broadcom/vulkan/v3dv_cmd_buffer.c b/src/broadcom/vulkan/v3dv_cmd_buffer.c index 8a8727bf6da..e1edb75266e 100644 --- a/src/broadcom/vulkan/v3dv_cmd_buffer.c +++ b/src/broadcom/vulkan/v3dv_cmd_buffer.c @@ -26,6 +26,7 @@ #include "util/half_float.h" #include "util/u_pack_color.h" #include "vk_format_info.h" +#include "vk_util.h" const struct v3dv_dynamic_state default_dynamic_state = { .viewport = { diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index be63f684567..a5cb135b42a 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -114,11 +114,6 @@ pack_emit_reloc(void *cl, const void *reloc) {} for (uint32_t __dword = (dword); \ (b) = __builtin_ffs(__dword) - 1, __dword; __dword &= ~(1 << (b))) -#define typed_memcpy(dest, src, count) ({ \ - STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \ - memcpy((dest), (src), (count) * sizeof(*(src))); \ - }) - struct v3dv_instance; #ifdef USE_V3D_SIMULATOR diff --git a/src/gallium/frontends/lavapipe/lvp_private.h b/src/gallium/frontends/lavapipe/lvp_private.h index 700875292d0..1d00af7d6a3 100644 --- a/src/gallium/frontends/lavapipe/lvp_private.h +++ b/src/gallium/frontends/lavapipe/lvp_private.h @@ -66,10 +66,6 @@ extern "C" { #define lvp_printflike(a, b) __attribute__((__format__(__printf__, a, b))) -#define typed_memcpy(dest, src, count) ({ \ - memcpy((dest), (src), (count) * sizeof(*(src))); \ -}) - int lvp_get_instance_entrypoint_index(const char *name); int lvp_get_device_entrypoint_index(const char *name); int lvp_get_physical_device_entrypoint_index(const char *name); diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index f4abf6bfb82..fd67f744ab2 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -355,11 +355,6 @@ static inline uintptr_t anv_pack_ptr(void *ptr, int bits, int flags) (b) = __builtin_ffs(__dword) - 1, __dword; \ __dword &= ~(1 << (b))) -#define typed_memcpy(dest, src, count) ({ \ - STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \ - memcpy((dest), (src), (count) * sizeof(*(src))); \ -}) - /* Mapping from anv object to VkDebugReportObjectTypeEXT. New types need * to be added here in order to utilize mapping in debug/error/perf macros. */ diff --git a/src/vulkan/util/vk_util.h b/src/vulkan/util/vk_util.h index 17c5fb88f53..6e1dc7c1cc9 100644 --- a/src/vulkan/util/vk_util.h +++ b/src/vulkan/util/vk_util.h @@ -23,6 +23,9 @@ #ifndef VK_UTIL_H #define VK_UTIL_H +#include "util/macros.h" +#include <string.h> + #ifdef __cplusplus extern "C" { #endif @@ -232,6 +235,11 @@ struct vk_pipeline_cache_header { #define VK_ENUM_OFFSET(__enum) \ ((__enum) >= VK_EXT_OFFSET ? ((__enum) % 1000) : (__enum)) +#define typed_memcpy(dest, src, count) do { \ + STATIC_ASSERT(sizeof(*(src)) == sizeof(*(dest))); \ + memcpy((dest), (src), (count) * sizeof(*(src))); \ +} while (0) + #ifdef __cplusplus } #endif diff --git a/src/vulkan/wsi/wsi_common_display.h b/src/vulkan/wsi/wsi_common_display.h index fb045982cf8..d65517ab941 100644 --- a/src/vulkan/wsi/wsi_common_display.h +++ b/src/vulkan/wsi/wsi_common_display.h @@ -27,11 +27,6 @@ #include <xf86drm.h> #include <xf86drmMode.h> -#define typed_memcpy(dest, src, count) ({ \ - STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \ - memcpy((dest), (src), (count) * sizeof(*(src))); \ -}) - VkResult wsi_display_get_physical_device_display_properties( VkPhysicalDevice physical_device, diff --git a/src/vulkan/wsi/wsi_common_wayland.c b/src/vulkan/wsi/wsi_common_wayland.c index e219b263fc5..7b8154bf616 100644 --- a/src/vulkan/wsi/wsi_common_wayland.c +++ b/src/vulkan/wsi/wsi_common_wayland.c @@ -44,11 +44,6 @@ #include <util/timespec.h> #include <util/u_vector.h> -#define typed_memcpy(dest, src, count) ({ \ - STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \ - memcpy((dest), (src), (count) * sizeof(*(src))); \ -}) - struct wsi_wayland; struct wsi_wl_display_drm { diff --git a/src/vulkan/wsi/wsi_common_x11.c b/src/vulkan/wsi/wsi_common_x11.c index ff7e90ac92f..329723736f7 100644 --- a/src/vulkan/wsi/wsi_common_x11.c +++ b/src/vulkan/wsi/wsi_common_x11.c @@ -46,11 +46,6 @@ #include "wsi_common_x11.h" #include "wsi_common_queue.h" -#define typed_memcpy(dest, src, count) ({ \ - STATIC_ASSERT(sizeof(*src) == sizeof(*dest)); \ - memcpy((dest), (src), (count) * sizeof(*(src))); \ -}) - struct wsi_x11_connection { bool has_dri3; bool has_dri3_modifiers; |