vulkan/util: Consolidate typed_memcpy
authorJames Park <jpark37@lagfreegames.com>
Mon, 30 Nov 2020 10:00:48 +0000 (02:00 -0800)
committerMarge Bot <eric+marge@anholt.net>
Tue, 1 Dec 2020 07:48:08 +0000 (07:48 +0000)
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>

src/amd/vulkan/radv_meta.c
src/amd/vulkan/radv_private.h
src/broadcom/vulkan/v3dv_cmd_buffer.c
src/broadcom/vulkan/v3dv_private.h
src/gallium/frontends/lavapipe/lvp_private.h
src/intel/vulkan/anv_private.h
src/vulkan/util/vk_util.h
src/vulkan/wsi/wsi_common_display.h
src/vulkan/wsi/wsi_common_wayland.c
src/vulkan/wsi/wsi_common_x11.c

index 0213826783c13a1adef10d4e526acc5d0d899a1f..bdd06c2ebd96b008b91c57556fd59631c52d139a 100644 (file)
@@ -25,6 +25,8 @@
 
 #include "radv_meta.h"
 
+#include "vk_util.h"
+
 #include <fcntl.h>
 #include <limits.h>
 #include <pwd.h>
index ab7d797fbf5b51a6de73a0d1d2cad290c5e235a0..b425a16903abd976de24de58fd06a2e75c68c62a 100644 (file)
@@ -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.
index 8a8727bf6da7537735262f6c57f586aed1cce55a..e1edb75266ef75b81a4f50696581e71fbfcd0eb4 100644 (file)
@@ -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 = {
index be63f684567dae5dfbc86259718297f4e0150270..a5cb135b42a6fa1ed14cec43b3f4352f3d7f84ac 100644 (file)
@@ -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
index 700875292d0c645faf6bee7c8aaf54bcf270058f..1d00af7d6a346ed38a57cc3594708a95b36ecf52 100644 (file)
@@ -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);
index f4abf6bfb82562367a4bfa519c0d0ee94b16b3f6..fd67f744ab25aea68757aab2bfb738bb7679d522 100644 (file)
@@ -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.
  */
index 17c5fb88f5371e1c9164c27d8119c63a272adc08..6e1dc7c1cc9cbd7f33877ed031953443f887196a 100644 (file)
@@ -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
index fb045982cf81feb66509e55545b1060a3512b8f7..d65517ab941d2642430762433f89938ec7d204d6 100644 (file)
 #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,
index e219b263fc5541c449d2744206409d4d05fac188..7b8154bf616033b1db967c156810b384006f1c06 100644 (file)
 #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 {
index ff7e90ac92fefe901a20e424acb205d8f5c6a466..329723736f783b15e863a3cba67c9a8fc0e358fa 100644 (file)
 #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;